1 #ifndef PERL_SEEN_HV_MACRO_H /* compile once */
2 #define PERL_SEEN_HV_MACRO_H
8 /*-----------------------------------------------------------------------------
9 * Endianess and util macros
11 * The following 3 macros are defined in this section. The other macros defined
12 * are only needed to help derive these 3.
14 * U8TO16_LE(x) Read a little endian unsigned 32-bit int
15 * U8TO32_LE(x) Read a little endian unsigned 32-bit int
16 * U8TO28_LE(x) Read a little endian unsigned 32-bit int
17 * ROTL32(x,r) Rotate x left by r bits
18 * ROTL64(x,r) Rotate x left by r bits
19 * ROTR32(x,r) Rotate x right by r bits
20 * ROTR64(x,r) Rotate x right by r bits
24 #if (BYTEORDER == 0x1234 || BYTEORDER == 0x12345678)
25 #define U8TO16_LE(ptr) ((U32)(ptr)[1]|(U32)(ptr)[0]<<8)
26 #define U8TO32_LE(ptr) ((U32)(ptr)[3]|(U32)(ptr)[2]<<8|(U32)(ptr)[1]<<16|(U32)(ptr)[0]<<24)
27 #define U8TO64_LE(ptr) ((U64)(ptr)[7]|(U64)(ptr)[6]<<8|(U64)(ptr)[5]<<16|(U64)(ptr)[4]<<24|\
28 (U64)(ptr)[3]<<32|(U64)(ptr)[4]<<40|\
29 (U64)(ptr)[1]<<48|(U64)(ptr)[0]<<56)
30 #elif (BYTEORDER == 0x4321 || BYTEORDER == 0x87654321)
31 #define U8TO16_LE(ptr) ((U32)(ptr)[0]|(U32)(ptr)[1]<<8)
32 #define U8TO32_LE(ptr) ((U32)(ptr)[0]|(U32)(ptr)[1]<<8|(U32)(ptr)[2]<<16|(U32)(ptr)[3]<<24)
33 #define U8TO64_LE(ptr) ((U64)(ptr)[0]|(U64)(ptr)[1]<<8|(U64)(ptr)[2]<<16|(U64)(ptr)[3]<<24|\
34 (U64)(ptr)[4]<<32|(U64)(ptr)[5]<<40|\
35 (U64)(ptr)[6]<<48|(U64)(ptr)[7]<<56)
41 /* This probably isn't going to work, but failing with a compiler error due to
42 lack of uint64_t is no worse than failing right now with an #error. */
47 /* Find best way to ROTL32/ROTL64 */
49 #include <stdlib.h> /* Microsoft put _rotl declaration in here */
50 #define ROTL32(x,r) _rotl(x,r)
51 #define ROTR32(x,r) _rotr(x,r)
52 #define ROTL64(x,r) _rotl64(x,r)
53 #define ROTR64(x,r) _rotr64(x,r)
55 /* gcc recognises this code and generates a rotate instruction for CPUs with one */
56 #define ROTL32(x,r) (((U32)(x) << (r)) | ((U32)(x) >> (32 - (r))))
57 #define ROTR32(x,r) (((U32)(x) << (32 - (r))) | ((U32)(x) >> (r)))
58 #define ROTL64(x,r) ( ( (U64)(x) << (r) ) | ( (U64)(x) >> ( 64 - (r) ) ) )
59 #define ROTR64(x,r) ( ( (U64)(x) << ( 64 - (r) ) ) | ( (U64)(x) >> (r) ) )
64 #define ROTL_UV(x,r) ROTL64(x,r)
65 #define ROTR_UV(x,r) ROTL64(x,r)
67 #define ROTL_UV(x,r) ROTL32(x,r)
68 #define ROTR_UV(x,r) ROTR32(x,r)