24 #if defined(OF_APPLE_RUNTIME)
25 # import <objc/runtime.h>
29 # define INTMAX_MAX LONG_LONG_MAX
33 # define OF_INLINE inline __attribute__((always_inline))
34 # define OF_LIKELY(cond) (__builtin_expect(!!(cond), 1))
35 # define OF_UNLIKELY(cond) (__builtin_expect(!!(cond), 0))
36 # define OF_CONST_FUNC __attribute__((const))
38 # define OF_INLINE inline
39 # define OF_LIKELY(cond) cond
40 # define OF_UNLIKELY(cond) cond
41 # define OF_CONST_FUNC
45 #if __BIG_ENDIAN__ || __LITTLE_ENDIAN__
46 # if __BIG_ENDIAN__ && __LITTLE_ENDIAN__
47 # error __BIG_ENDIAN__ and __LITTLE_ENDIAN__ defined!
51 # define OF_BIG_ENDIAN
56 # define OF_BYTE_ORDER_NATIVE OF_BYTE_ORDER_BIG_ENDIAN
58 # define OF_BYTE_ORDER_NATIVE OF_BYTE_ORDER_LITTLE_ENDIAN
62 #ifndef __BIGGEST_ALIGNMENT__
63 # define __BIGGEST_ALIGNMENT__ 16
67 # if defined(__amd64__) || defined(__x86_64__)
69 # elif defined(__i386__)
71 # elif defined(__ppc__) || defined(__PPC__)
73 # elif defined(__arm__) || defined(__ARM__)
75 # ifdef __ARM_ARCH_7__
78 # ifdef __ARM_ARCH_7A__
81 # ifdef __ARM_ARCH_7R__
84 # ifdef __ARM_ARCH_7M__
87 # ifdef __ARM_ARCH_7EM__
90 # ifdef __ARM_ARCH_6__
93 # ifdef __ARM_ARCH_6J__
96 # ifdef __ARM_ARCH_6K__
99 # ifdef __ARM_ARCH_6Z__
100 # define OF_ARMV6_ASM
102 # ifdef __ARM_ARCH_6ZK__
103 # define OF_ARMV6_ASM
105 # ifdef __ARM_ARCH_6T2__
106 # define OF_ARMV6_ASM
109 # define OF_ARMV6_ASM
114 #define OF_ENSURE(cond) \
116 fprintf(stderr, "Failed to ensure condition in " \
117 __FILE__ ":%d:\n" #cond "\n", __LINE__); \
121 #ifdef OF_OBJFW_RUNTIME
122 # define objc_lookUpClass objc_lookup_class
126 # define OF_PATH_DELIMITER '/'
128 # define OF_PATH_DELIMITER '\\'
130 #define OF_PATH_PARENT_DIR @".."
132 extern id objc_getProperty(
id,
SEL, ptrdiff_t, BOOL);
133 extern void objc_setProperty(
id,
SEL, ptrdiff_t,
id, BOOL,
signed char);
135 #define OF_IVAR_OFFSET(ivar) ((intptr_t)&ivar - (intptr_t)self)
136 #define OF_GETTER(ivar, atomic) \
137 return objc_getProperty(self, _cmd, OF_IVAR_OFFSET(ivar), atomic);
138 #define OF_SETTER(ivar, value, atomic, copy) \
139 objc_setProperty(self, _cmd, OF_IVAR_OFFSET(ivar), value, atomic, copy);
141 static OF_INLINE uint16_t OF_CONST_FUNC
142 OF_BSWAP16_CONST(uint16_t i)
144 return (i & UINT16_C(0xFF00)) >> 8 |
145 (i & UINT16_C(0x00FF)) << 8;
148 static OF_INLINE uint32_t OF_CONST_FUNC
149 OF_BSWAP32_CONST(uint32_t i)
151 return (i & UINT32_C(0xFF000000)) >> 24 |
152 (i & UINT32_C(0x00FF0000)) >> 8 |
153 (i & UINT32_C(0x0000FF00)) << 8 |
154 (i & UINT32_C(0x000000FF)) << 24;
157 static OF_INLINE uint64_t OF_CONST_FUNC
158 OF_BSWAP64_CONST(uint64_t i)
160 return (i & UINT64_C(0xFF00000000000000)) >> 56 |
161 (i & UINT64_C(0x00FF000000000000)) >> 40 |
162 (i & UINT64_C(0x0000FF0000000000)) >> 24 |
163 (i & UINT64_C(0x000000FF00000000)) >> 8 |
164 (i & UINT64_C(0x00000000FF000000)) << 8 |
165 (i & UINT64_C(0x0000000000FF0000)) << 24 |
166 (i & UINT64_C(0x000000000000FF00)) << 40 |
167 (i & UINT64_C(0x00000000000000FF)) << 56;
170 static OF_INLINE uint16_t OF_CONST_FUNC
171 OF_BSWAP16_NONCONST(uint16_t i)
173 #if defined(OF_X86_ASM) || defined(OF_AMD64_ASM)
179 #elif defined(OF_PPC_ASM)
185 #elif defined(OF_ARMV6_ASM)
192 i = (i & UINT16_C(0xFF00)) >> 8 |
193 (i & UINT16_C(0x00FF)) << 8;
198 static OF_INLINE uint32_t OF_CONST_FUNC
199 OF_BSWAP32_NONCONST(uint32_t i)
201 #if defined(OF_X86_ASM) || defined(OF_AMD64_ASM)
207 #elif defined(OF_PPC_ASM)
213 #elif defined(OF_ARMV6_ASM)
220 i = (i & UINT32_C(0xFF000000)) >> 24 |
221 (i & UINT32_C(0x00FF0000)) >> 8 |
222 (i & UINT32_C(0x0000FF00)) << 8 |
223 (i & UINT32_C(0x000000FF)) << 24;
228 static OF_INLINE uint64_t OF_CONST_FUNC
229 OF_BSWAP64_NONCONST(uint64_t i)
231 #if defined(OF_AMD64_ASM)
237 #elif defined(OF_X86_ASM)
246 i = (uint64_t)OF_BSWAP32_NONCONST((uint32_t)(i & 0xFFFFFFFF)) << 32 |
247 OF_BSWAP32_NONCONST((uint32_t)(i >> 32));
253 # define OF_BSWAP16(i) \
254 (__builtin_constant_p(i) ? OF_BSWAP16_CONST(i) : OF_BSWAP16_NONCONST(i))
255 # define OF_BSWAP32(i) \
256 (__builtin_constant_p(i) ? OF_BSWAP32_CONST(i) : OF_BSWAP32_NONCONST(i))
257 # define OF_BSWAP64(i) \
258 (__builtin_constant_p(i) ? OF_BSWAP64_CONST(i) : OF_BSWAP64_NONCONST(i))
260 # define OF_BSWAP16(i) OF_BSWAP16_CONST(i)
261 # define OF_BSWAP32(i) OF_BSWAP32_CONST(i)
262 # define OF_BSWAP64(i) OF_BSWAP64_CONST(i)
265 static OF_INLINE
float OF_CONST_FUNC
266 OF_BSWAP_FLOAT(
float f)
274 u.i = OF_BSWAP32(u.i);
279 static OF_INLINE
double OF_CONST_FUNC
280 OF_BSWAP_DOUBLE(
double d)
288 u.i = OF_BSWAP64(u.i);
294 # define OF_BSWAP16_IF_BE(i) OF_BSWAP16(i)
295 # define OF_BSWAP32_IF_BE(i) OF_BSWAP32(i)
296 # define OF_BSWAP64_IF_BE(i) OF_BSWAP64(i)
297 # define OF_BSWAP16_IF_LE(i) (i)
298 # define OF_BSWAP32_IF_LE(i) (i)
299 # define OF_BSWAP64_IF_LE(i) (i)
301 # define OF_BSWAP16_IF_BE(i) (i)
302 # define OF_BSWAP32_IF_BE(i) (i)
303 # define OF_BSWAP64_IF_BE(i) (i)
304 # define OF_BSWAP16_IF_LE(i) OF_BSWAP16(i)
305 # define OF_BSWAP32_IF_LE(i) OF_BSWAP32(i)
306 # define OF_BSWAP64_IF_LE(i) OF_BSWAP64(i)
309 #ifdef OF_FLOAT_BIG_ENDIAN
310 # define OF_BSWAP_FLOAT_IF_BE(i) OF_BSWAP_FLOAT(i)
311 # define OF_BSWAP_DOUBLE_IF_BE(i) OF_BSWAP_DOUBLE(i)
312 # define OF_BSWAP_FLOAT_IF_LE(i) (i)
313 # define OF_BSWAP_DOUBLE_IF_LE(i) (i)
315 # define OF_BSWAP_FLOAT_IF_BE(i) (i)
316 # define OF_BSWAP_DOUBLE_IF_BE(i) (i)
317 # define OF_BSWAP_FLOAT_IF_LE(i) OF_BSWAP_FLOAT(i)
318 # define OF_BSWAP_DOUBLE_IF_LE(i) OF_BSWAP_DOUBLE(i)
325 #if defined(__MACH__) && defined(__arm__)
329 #define OF_ROL(value, bits) \
330 (((value) << ((bits) % (sizeof(value) * 8))) | \
331 (value) >> (sizeof(value) * 8 - ((bits) % (sizeof(value) * 8))))
333 #define OF_HASH_INIT(hash) hash = 0
334 #define OF_HASH_ADD(hash, byte) \
336 hash += (uint8_t)byte; \
337 hash += (hash << 10); \
338 hash ^= (hash >> 6); \
340 #define OF_HASH_FINALIZE(hash) \
342 hash += (hash << 3); \
343 hash ^= (hash >> 11); \
344 hash += (hash << 15); \
346 #define OF_HASH_ADD_HASH(hash, other) \
348 uint32_t otherCopy = other; \
349 OF_HASH_ADD(hash, (otherCopy >> 24) & 0xFF); \
350 OF_HASH_ADD(hash, (otherCopy >> 16) & 0xFF); \
351 OF_HASH_ADD(hash, (otherCopy >> 8) & 0xFF); \
352 OF_HASH_ADD(hash, otherCopy & 0xFF); \
356 of_range(
size_t start,
size_t length)
364 of_point(
float x,
float y)
372 of_dimension(
float width,
float height)
380 of_rectangle(
float x,
float y,
float width,
float height)
384 of_dimension(width, height)