|
33 | 33 |
|
34 | 34 | #include <stdbool.h>
|
35 | 35 | #include <stddef.h>
|
| 36 | +#include "zend_portability.h" |
36 | 37 |
|
37 | 38 | /* This will be 0x01010101 for 32-bit and 0x0101010101010101 for 64-bit */
|
38 | 39 | #define SWAR_ONES (~((size_t) 0) / 0xFF)
|
39 | 40 | /* This repeats a byte `x` into an entire 32/64-bit word.
|
40 | 41 | * Example: SWAR_REPEAT(0xAB) will be 0xABABABAB for 32-bit and 0xABABABABABABABAB for 64-bit. */
|
41 | 42 | #define SWAR_REPEAT(x) (SWAR_ONES * (x))
|
42 | 43 |
|
43 |
| -/* Bytes swap */ |
44 |
| -#ifdef _MSC_VER |
45 |
| -# include <stdlib.h> |
46 |
| -# define BC_BSWAP32(u) _byteswap_ulong(u) |
47 |
| -# define BC_BSWAP64(u) _byteswap_uint64(u) |
48 |
| -#else |
49 |
| -# ifdef __GNUC__ |
50 |
| -# define BC_BSWAP32(u) __builtin_bswap32(u) |
51 |
| -# define BC_BSWAP64(u) __builtin_bswap64(u) |
52 |
| -# elif defined(__has_builtin) |
53 |
| -# if __has_builtin(__builtin_bswap32) |
54 |
| -# define BC_BSWAP32(u) __builtin_bswap32(u) |
55 |
| -# endif // __has_builtin(__builtin_bswap32) |
56 |
| -# if __has_builtin(__builtin_bswap64) |
57 |
| -# define BC_BSWAP64(u) __builtin_bswap64(u) |
58 |
| -# endif // __has_builtin(__builtin_bswap64) |
59 |
| -# endif // __GNUC__ |
60 |
| -#endif // _MSC_VER |
61 |
| -#ifndef BC_BSWAP32 |
62 |
| -static inline uint32_t BC_BSWAP32(uint32_t u) |
63 |
| -{ |
64 |
| - return (((u & 0xff000000) >> 24) |
65 |
| - | ((u & 0x00ff0000) >> 8) |
66 |
| - | ((u & 0x0000ff00) << 8) |
67 |
| - | ((u & 0x000000ff) << 24)); |
68 |
| -} |
69 |
| -#endif |
70 |
| -#ifndef BC_BSWAP64 |
71 |
| -static inline uint64_t BC_BSWAP64(uint64_t u) |
72 |
| -{ |
73 |
| - return (((u & 0xff00000000000000ULL) >> 56) |
74 |
| - | ((u & 0x00ff000000000000ULL) >> 40) |
75 |
| - | ((u & 0x0000ff0000000000ULL) >> 24) |
76 |
| - | ((u & 0x000000ff00000000ULL) >> 8) |
77 |
| - | ((u & 0x00000000ff000000ULL) << 8) |
78 |
| - | ((u & 0x0000000000ff0000ULL) << 24) |
79 |
| - | ((u & 0x000000000000ff00ULL) << 40) |
80 |
| - | ((u & 0x00000000000000ffULL) << 56)); |
81 |
| -} |
82 |
| -#endif |
83 |
| - |
84 | 44 | #if SIZEOF_SIZE_T >= 8
|
85 |
| -# define BC_BSWAP(u) BC_BSWAP64(u) |
| 45 | +# define BC_BSWAP(u) ZEND_BYTES_SWAP64(u) |
86 | 46 | typedef uint64_t BC_VECTOR;
|
87 | 47 | #else
|
88 |
| -# define BC_BSWAP(u) BC_BSWAP32(u) |
| 48 | +# define BC_BSWAP(u) ZEND_BYTES_SWAP32(u) |
89 | 49 | typedef uint32_t BC_VECTOR;
|
90 | 50 | #endif
|
91 | 51 |
|
|
0 commit comments