1 #ifndef PERL_SEEN_HV_MACRO_H /* compile once */
2 #define PERL_SEEN_HV_MACRO_H
10 /* This probably isn't going to work, but failing with a compiler error due to
11 lack of uint64_t is no worse than failing right now with an #error. */
17 /*-----------------------------------------------------------------------------
18 * Endianess and util macros
20 * The following 3 macros are defined in this section. The other macros defined
21 * are only needed to help derive these 3.
23 * U8TO16_LE(x) Read a little endian unsigned 32-bit int
24 * U8TO32_LE(x) Read a little endian unsigned 32-bit int
25 * U8TO28_LE(x) Read a little endian unsigned 32-bit int
26 * ROTL32(x,r) Rotate x left by r bits
27 * ROTL64(x,r) Rotate x left by r bits
28 * ROTR32(x,r) Rotate x right by r bits
29 * ROTR64(x,r) Rotate x right by r bits
33 #define _shifted_octet(type,ptr,idx,shift) (((type)(((U8*)(ptr))[(idx)]))<<(shift))
34 #ifdef USE_UNALIGNED_PTR_DEREF
35 #define U8TO16_LE(ptr) (*((const U16*)(ptr)))
36 #define U8TO32_LE(ptr) (*((const U32*)(ptr)))
37 #define U8TO64_LE(ptr) (*((const U64*)(ptr)))
39 #define U8TO16_LE(ptr) (_shifted_octet(U16,(ptr),0, 0)|\
40 _shifted_octet(U16,(ptr),1, 8))
42 #define U8TO32_LE(ptr) (_shifted_octet(U32,(ptr),0, 0)|\
43 _shifted_octet(U32,(ptr),1, 8)|\
44 _shifted_octet(U32,(ptr),2,16)|\
45 _shifted_octet(U32,(ptr),3,24))
47 #define U8TO64_LE(ptr) (_shifted_octet(U64,(ptr),0, 0)|\
48 _shifted_octet(U64,(ptr),1, 8)|\
49 _shifted_octet(U64,(ptr),2,16)|\
50 _shifted_octet(U64,(ptr),3,24)|\
51 _shifted_octet(U64,(ptr),4,32)|\
52 _shifted_octet(U64,(ptr),5,40)|\
53 _shifted_octet(U64,(ptr),6,48)|\
54 _shifted_octet(U64,(ptr),7,56))
58 /* Find best way to ROTL32/ROTL64 */
60 #include <stdlib.h> /* Microsoft put _rotl declaration in here */
61 #define ROTL32(x,r) _rotl(x,r)
62 #define ROTR32(x,r) _rotr(x,r)
63 #define ROTL64(x,r) _rotl64(x,r)
64 #define ROTR64(x,r) _rotr64(x,r)
66 /* gcc recognises this code and generates a rotate instruction for CPUs with one */
67 #define ROTL32(x,r) (((U32)(x) << (r)) | ((U32)(x) >> (32 - (r))))
68 #define ROTR32(x,r) (((U32)(x) << (32 - (r))) | ((U32)(x) >> (r)))
69 #define ROTL64(x,r) ( ( (U64)(x) << (r) ) | ( (U64)(x) >> ( 64 - (r) ) ) )
70 #define ROTR64(x,r) ( ( (U64)(x) << ( 64 - (r) ) ) | ( (U64)(x) >> (r) ) )
75 #define ROTL_UV(x,r) ROTL64(x,r)
76 #define ROTR_UV(x,r) ROTL64(x,r)
78 #define ROTL_UV(x,r) ROTL32(x,r)
79 #define ROTR_UV(x,r) ROTR32(x,r)