@@ -79,6 +79,66 @@ typedef struct bc_struct {
79
79
#define LONG_MAX 0x7ffffff
80
80
#endif
81
81
82
+ /* This will be 0x01010101 for 32-bit and 0x0101010101010101 for 64-bit */
83
+ #define SWAR_ONES (~((size_t) 0) / 0xFF)
84
+ /* This repeats a byte `x` into an entire 32/64-bit word.
85
+ * Example: SWAR_REPEAT(0xAB) will be 0xABABABAB for 32-bit and 0xABABABABABABABAB for 64-bit. */
86
+ #define SWAR_REPEAT (x ) (SWAR_ONES * (x))
87
+
88
+ /* Bytes swap */
89
+ #if defined(_MSC_VER )
90
+ # include <stdlib.h>
91
+ # define BSWAP32 (u ) _byteswap_ulong(u)
92
+ # define BSWAP64 (u ) _byteswap_uint64(u)
93
+ #else
94
+ # ifdef __has_builtin
95
+ # if __has_builtin (__builtin_bswap32 )
96
+ # define BSWAP32 (u ) __builtin_bswap32(u)
97
+ # endif // __has_builtin(__builtin_bswap32)
98
+ # if __has_builtin (__builtin_bswap64 )
99
+ # define BSWAP64 (u ) __builtin_bswap64(u)
100
+ # endif // __has_builtin(__builtin_bswap64)
101
+ # elif defined(__GNUC__ )
102
+ # define BSWAP32 (u ) __builtin_bswap32(u)
103
+ # define BSWAP64 (u ) __builtin_bswap64(u)
104
+ # endif // __has_builtin
105
+ #endif // defined(_MSC_VER)
106
+ #ifndef BSWAP32
107
+ inline uint32_t BSWAP32 (uint32_t u )
108
+ {
109
+ return (((u & 0xff000000 ) >> 24 )
110
+ | ((u & 0x00ff0000 ) >> 8 )
111
+ | ((u & 0x0000ff00 ) << 8 )
112
+ | ((u & 0x000000ff ) << 24 ));
113
+ }
114
+ #endif
115
+ #ifndef BSWAP64
116
+ inline uint64_t BSWAP64 (uint64_t u )
117
+ {
118
+ return (((u & 0xff00000000000000ULL ) >> 56 )
119
+ | ((u & 0x00ff000000000000ULL ) >> 40 )
120
+ | ((u & 0x0000ff0000000000ULL ) >> 24 )
121
+ | ((u & 0x000000ff00000000ULL ) >> 8 )
122
+ | ((u & 0x00000000ff000000ULL ) << 8 )
123
+ | ((u & 0x0000000000ff0000ULL ) << 24 )
124
+ | ((u & 0x000000000000ff00ULL ) << 40 )
125
+ | ((u & 0x00000000000000ffULL ) << 56 ));
126
+ }
127
+ #endif
128
+
129
+ #if SIZEOF_SIZE_T >= 8
130
+ #define BC_BSWAP (u ) BSWAP64(u)
131
+ #define BC_UINT_T uint64_t
132
+ #else
133
+ #define BC_BSWAP (u ) BSWAP32(u)
134
+ #define BC_UINT_T uint32_t
135
+ #endif
136
+
137
+ #ifdef WORDS_BIGENDIAN
138
+ #define BC_LITTLE_ENDIAN 0
139
+ #else
140
+ #define BC_LITTLE_ENDIAN 1
141
+ #endif
82
142
83
143
/* Function Prototypes */
84
144
0 commit comments