This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
hv_func.h, hv_macro.h: Rename compile-once guard
[perl5.git] / hv_macro.h
CommitLineData
b41deab9
KW
1#ifndef PERL_SEEN_HV_MACRO_H_ /* compile once */
2#define PERL_SEEN_HV_MACRO_H_
1c4b2386
YO
3
4#if IVSIZE == 8
5#define CAN64BITHASH
6#endif
7
ed16b18d
YO
8#ifdef CAN64BITHASH
9 #ifndef U64TYPE
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. */
12 #define U64 uint64_t
13 #endif
14#endif
15
16
1c4b2386 17/*-----------------------------------------------------------------------------
e8864dba 18 * Endianess and util macros
1c4b2386
YO
19 *
20 * The following 3 macros are defined in this section. The other macros defined
21 * are only needed to help derive these 3.
22 *
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
30 */
31
e8864dba 32#ifndef U8TO16_LE
cc8ba724 33 #define _shifted_octet(type,ptr,idx,shift) (((type)(((U8*)(ptr))[(idx)]))<<(shift))
ed16b18d
YO
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)))
38 #else
cc8ba724
YO
39 #define U8TO16_LE(ptr) (_shifted_octet(U16,(ptr),0, 0)|\
40 _shifted_octet(U16,(ptr),1, 8))
ed16b18d 41
cc8ba724
YO
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))
ed16b18d 46
cc8ba724
YO
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))
ed16b18d 55 #endif
1c4b2386
YO
56#endif
57
58/* Find best way to ROTL32/ROTL64 */
59#if defined(_MSC_VER)
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)
65#else
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) ) )
71#endif
72
73
74#ifdef UV_IS_QUAD
75#define ROTL_UV(x,r) ROTL64(x,r)
76#define ROTR_UV(x,r) ROTL64(x,r)
77#else
78#define ROTL_UV(x,r) ROTL32(x,r)
79#define ROTR_UV(x,r) ROTR32(x,r)
80#endif
81#if IVSIZE == 8
82#define CAN64BITHASH
83#endif
84
85#endif