… | |
… | |
28 | */ |
28 | */ |
29 | |
29 | |
30 | #ifndef ECB_H |
30 | #ifndef ECB_H |
31 | #define ECB_H |
31 | #define ECB_H |
32 | |
32 | |
|
|
33 | /* 16 bits major, 16 bits minor */ |
|
|
34 | #define ECB_VERSION 0x00010001 |
|
|
35 | |
33 | #ifdef _WIN32 |
36 | #ifdef _WIN32 |
34 | typedef signed char int8_t; |
37 | typedef signed char int8_t; |
35 | typedef unsigned char uint8_t; |
38 | typedef unsigned char uint8_t; |
36 | typedef signed short int16_t; |
39 | typedef signed short int16_t; |
37 | typedef unsigned short uint16_t; |
40 | typedef unsigned short uint16_t; |
… | |
… | |
42 | typedef unsigned long long uint64_t; |
45 | typedef unsigned long long uint64_t; |
43 | #else /* _MSC_VER || __BORLANDC__ */ |
46 | #else /* _MSC_VER || __BORLANDC__ */ |
44 | typedef signed __int64 int64_t; |
47 | typedef signed __int64 int64_t; |
45 | typedef unsigned __int64 uint64_t; |
48 | typedef unsigned __int64 uint64_t; |
46 | #endif |
49 | #endif |
|
|
50 | #ifdef _WIN64 |
|
|
51 | #define ECB_PTRSIZE 8 |
|
|
52 | typedef uint64_t uintptr_t; |
|
|
53 | typedef int64_t intptr_t; |
|
|
54 | #else |
|
|
55 | #define ECB_PTRSIZE 4 |
|
|
56 | typedef uint32_t uintptr_t; |
|
|
57 | typedef int32_t intptr_t; |
|
|
58 | #endif |
|
|
59 | typedef intptr_t ptrdiff_t; |
47 | #else |
60 | #else |
48 | #include <inttypes.h> |
61 | #include <inttypes.h> |
|
|
62 | #if UINTMAX_MAX > 0xffffffffU |
|
|
63 | #define ECB_PTRSIZE 8 |
|
|
64 | #else |
|
|
65 | #define ECB_PTRSIZE 4 |
|
|
66 | #endif |
49 | #endif |
67 | #endif |
50 | |
68 | |
51 | /* many compilers define _GNUC_ to some versions but then only implement |
69 | /* many compilers define _GNUC_ to some versions but then only implement |
52 | * what their idiot authors think are the "more important" extensions, |
70 | * what their idiot authors think are the "more important" extensions, |
53 | * causing enormous grief in return for some better fake benchmark numbers. |
71 | * causing enormous grief in return for some better fake benchmark numbers. |
… | |
… | |
310 | |
328 | |
311 | return r + ecb_ld32 (x); |
329 | return r + ecb_ld32 (x); |
312 | } |
330 | } |
313 | #endif |
331 | #endif |
314 | |
332 | |
|
|
333 | ecb_function_ ecb_bool ecb_is_pot32 (uint32_t x) ecb_const; |
|
|
334 | ecb_function_ ecb_bool ecb_is_pot32 (uint32_t x) { return !(x & (x - 1)); } |
|
|
335 | ecb_function_ ecb_bool ecb_is_pot64 (uint64_t x) ecb_const; |
|
|
336 | ecb_function_ ecb_bool ecb_is_pot64 (uint64_t x) { return !(x & (x - 1)); } |
|
|
337 | |
315 | ecb_function_ uint8_t ecb_bitrev8 (uint8_t x) ecb_const; |
338 | ecb_function_ uint8_t ecb_bitrev8 (uint8_t x) ecb_const; |
316 | ecb_function_ uint8_t ecb_bitrev8 (uint8_t x) |
339 | ecb_function_ uint8_t ecb_bitrev8 (uint8_t x) |
317 | { |
340 | { |
318 | return ( (x * 0x0802U & 0x22110U) |
341 | return ( (x * 0x0802U & 0x22110U) |
319 | | (x * 0x8020U & 0x88440U)) * 0x10101U >> 16; |
342 | | (x * 0x8020U & 0x88440U)) * 0x10101U >> 16; |