|
|
1 | implement is_constant for c11: https://gustedt.wordpress.com/2013/08/22/testing-compile-time-constness-and-null-pointers-with-c11s-_generic/ |
|
|
2 | |
|
|
3 | #ifdef _MSC_VER |
|
|
4 | |
|
|
5 | #include <stdlib.h> |
|
|
6 | #define bswap_32(x) _byteswap_ulong(x) |
|
|
7 | #define bswap_64(x) _byteswap_uint64(x) |
|
|
8 | |
|
|
9 | #elif defined(__APPLE__) |
|
|
10 | |
|
|
11 | // Mac OS X / Darwin features |
|
|
12 | #include <libkern/OSByteOrder.h> |
|
|
13 | #define bswap_32(x) OSSwapInt32(x) |
|
|
14 | #define bswap_64(x) OSSwapInt64(x) |
|
|
15 | |
|
|
16 | #elif defined(__sun) || defined(sun) |
|
|
17 | |
|
|
18 | #include <sys/byteorder.h> |
|
|
19 | #define bswap_32(x) BSWAP_32(x) |
|
|
20 | #define bswap_64(x) BSWAP_64(x) |
|
|
21 | |
|
|
22 | #elif defined(__FreeBSD__) |
|
|
23 | |
|
|
24 | #include <sys/endian.h> |
|
|
25 | #define bswap_32(x) bswap32(x) |
|
|
26 | #define bswap_64(x) bswap64(x) |
|
|
27 | |
|
|
28 | #elif defined(__OpenBSD__) |
|
|
29 | |
|
|
30 | #include <sys/types.h> |
|
|
31 | #define bswap_32(x) swap32(x) |
|
|
32 | #define bswap_64(x) swap64(x) |
|
|
33 | |
|
|
34 | #elif defined(__NetBSD__) |
|
|
35 | |
|
|
36 | #include <sys/types.h> |
|
|
37 | #include <machine/bswap.h> |
|
|
38 | #if defined(__BSWAP_RENAME) && !defined(__bswap_32) |
|
|
39 | #define bswap_32(x) bswap32(x) |
|
|
40 | #define bswap_64(x) bswap64(x) |
|
|
41 | #endif |
|
|
42 | |
|
|
43 | #else |
|
|
44 | |
|
|
45 | #include <byteswap.h> |
|
|
46 | |
|
|
47 | #endif |
|
|
48 | |
|
|
49 | 0x00010001 |
|
|
50 | - add ecb_is_pot32/64. |
|
|
51 | - add intptr_t/uintptr_t. |
|
|
52 | - add ECB_PTRSIZE. |
|
|
53 | - more macros for C/C++ version checks. |
|
|
54 | - support C11 atomics for memory fences. |
|
|
55 | - support gcc-4.7 atomics for memory fences. |
|
|
56 | - support m68k, m88k and sh (patch by Miod Vallat). |
|
|
57 | - add ecb_binary16_to_float. |
|
|
58 | |
|
|
59 | TODO: ecb_restrict_array etc. http://ue.tst.eu/5093eafd713ec5fda776d8065070aa4c.txt |
1 | TODO: ffs/clz |
60 | TODO: ffs/clz |
2 | 64 bit variants of everything |
61 | 64 bit variants of everything |
3 | TODO: examples from X for clz/ctz |
62 | TODO: examples from X for clz/ctz |
4 | TODO: arithmetic right shift |
63 | TODO: arithmetic right shift |
5 | TODO: bit reversal |
|
|
6 | TODO: template/generic functions for x32/x64 and so on |
64 | TODO: template/generic functions for x32/x64 and so on |
7 | TODO: #define ecb_integer_multiples_of(n,d) ((char (*)[d])(n) - (char (*)[d])0) |
65 | TODO: #define ecb_integer_multiples_of(n,d) ((char (*)[d])(n) - (char (*)[d])0) |
8 | TODO: is_pot |
|
|
9 | TODO: uintptr_t |
|
|
10 | TODO: generalised shift |
66 | TODO: generalised shift |
|
|
67 | TODO: #define ECB_FAST_UNALIGNED_ACCESS |
11 | unsigned long gensh(unsigned long v, int x) { |
68 | unsigned long gensh(unsigned long v, int x) { |
12 | int a, b; |
69 | int a, b; |
13 | a = (v << x) & -(((unsigned int)x) < 32); |
70 | a = (v << x) & -(((unsigned int)x) < 32); |
14 | x = -x; |
71 | x = -x; |
15 | b = (v >> x) & -(((unsigned int)x) < 32); |
72 | b = (v >> x) & -(((unsigned int)x) < 32); |
16 | return a|b; |
73 | return a|b; |
17 | } |
74 | } |
|
|
75 | |
|
|
76 | TODO: read/write unaligned macros |
|
|
77 | TODO: htonl and friends |
|
|
78 | TODO: macro to convetr from unsigned to signed "the natural way" |
|
|
79 | TODO: ecb_deprecated with message |
|
|
80 | TODO: ecb_static_assert, with message (just like boost), or somesuch, using array-declaration |
|
|
81 | TODO: alignof |
|
|
82 | |
|
|
83 | |