]>
git.saurik.com Git - wxWidgets.git/blob - utils/Install/incace/portable.h
1 /****************************************************************/
3 /* A collection of routines used in making ACE portable for */
4 /* different computers */
6 /****************************************************************/
13 #ifdef HI_LO_BYTE_ORDER
15 /* All kinds of inplace swap routines, to reverse from LOHI to HILO byte order */
19 #if __SASC && __VERSION__>=6 && __REVISION__>=58
21 #define WORDswap(n) (*(n) = __builtin_rol(*(n), 8, 1))
22 #define LONGswap(n) ( WORDswap(&((WORD *)(n))[0]),\
23 WORDswap(&((WORD *)(n))[1]),\
24 *(n) = __builtin_rol(*(n), 16, 2) )
36 /* With some compilers and processors these work faster then the
37 * regular swap below, for example on a Amiga 68040 using SAS C 6.58.
38 * But using builtin rotates works even faster, see above.
41 #define WORDswap(n) (((BYTE*)(n))[0] ^= ((BYTE*)(n))[1],\
42 ((BYTE*)(n))[1] ^= ((BYTE*)(n))[0],\
43 ((BYTE*)(n))[0] ^= ((BYTE*)(n))[1])
44 #define LONGswap(n) (((BYTE*)(n))[0] ^= ((BYTE*)(n))[3],\
45 ((BYTE*)(n))[3] ^= ((BYTE*)(n))[0],\
46 ((BYTE*)(n))[0] ^= ((BYTE*)(n))[3],\
47 ((BYTE*)(n))[1] ^= ((BYTE*)(n))[2],\
48 ((BYTE*)(n))[2] ^= ((BYTE*)(n))[1],\
49 ((BYTE*)(n))[1] ^= ((BYTE*)(n))[2])
54 /* If not yet defined use the standard swaps */
56 #define WORDswap(n) (*(n) = (*(n) << 8) | (*(n) >> 8))
57 #define LONGswap(n) ( WORDswap(&((WORD *)(n))[0]),\
58 WORDswap(&((WORD *)(n))[1]),\
59 *(n) = (*(n) >> 16) | (*(n) << 16) )
62 #endif /* HI_LO_BYTE_ORDER */
65 /* GENERIC: Convert to LONG or WORD from BYTE-Pointer-to-LOHI-byte-order data,
66 * without worrying if the bytes are word alined in memory.
67 * p is a pointer to char.
70 #ifdef HI_LO_BYTE_ORDER
72 #define BUFP2WORD(p) ((UWORD)*(p)++ | ((*(p)++)<<8))
73 #define BUFP2LONG(p) ((ULONG)*(p)++ | ((*(p)++)<<8) | ((*(p)++)<<16) | ((*(p)++)<<24))
75 #define BUF2WORD(p) ((UWORD)*(p) | (*((p)+1)<<8))
76 #define BUF2LONG(p) ((ULONG)*(p) | (*((p)+1)<<8) | (*((p)+2)<<16) | (*((p)+3)<<24))
78 #else /* HI_LO_BYTE_ORDER */
80 #define BUFP2WORD(p) *(UWORD*)((p+=2)-2)
81 #define BUFP2LONG(p) *(ULONG*)((p+=4)-4)
83 #define BUF2WORD(p) (*(UWORD*)p)
84 #define BUF2LONG(p) (*(ULONG*)p)
86 #endif /* !HI_LO_BYTE_ORDER */
88 /* Timestamp macros */
90 #define get_tx(m,d,h,n) (((ULONG)m<<21)+((ULONG)d<<16)+((ULONG)h<<11)+(n<<5))
91 #define get_tstamp(y,m,d,h,n,s) ((((ULONG)(y-1980))<<25)+get_tx(m,d,h,n)+(s/2))
93 #define ts_year(ts) ((UINT)((ts >> 25) & 0x7f) + 1980)
94 #define ts_month(ts) ((UINT)(ts >> 21) & 0x0f) // 1..12 means Jan..Dec
95 #define ts_day(ts) ((UINT)(ts >> 16) & 0x1f) // 1..31 means 1st..31st
96 #define ts_hour(ts) ((UINT)(ts >> 11) & 0x1f)
97 #define ts_min(ts) ((UINT)(ts >> 5) & 0x3f)
98 #define ts_sec(ts) ((UINT)((ts & 0x1f) * 2))
101 #endif /* __portable_h */