1 /* Copyright (c) 2001, 2012, Oracle and/or its affiliates. All rights reserved.
2    Copyright (c) 2020, MariaDB Corporation.
3 
4    This program is free software; you can redistribute it and/or modify
5    it under the terms of the GNU General Public License as published by
6    the Free Software Foundation; version 2 of the License.
7 
8    This program is distributed in the hope that it will be useful,
9    but WITHOUT ANY WARRANTY; without even the implied warranty of
10    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11    GNU General Public License for more details.
12 
13    You should have received a copy of the GNU General Public License
14    along with this program; if not, write to the Free Software
15    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1335 USA */
16 
17 /*
18   Optimized function-like macros for the x86 architecture (_WIN32 included).
19 */
20 
21 #define sint2korr(A)	(*((const int16 *) (A)))
22 #define sint3korr(A)	((int32) ((((uchar) (A)[2]) & 128) ? \
23 				  (((uint32) 255L << 24) | \
24 				   (((uint32) (uchar) (A)[2]) << 16) |\
25 				   (((uint32) (uchar) (A)[1]) << 8) | \
26 				   ((uint32) (uchar) (A)[0])) : \
27 				  (((uint32) (uchar) (A)[2]) << 16) |\
28 				  (((uint32) (uchar) (A)[1]) << 8) | \
29 				  ((uint32) (uchar) (A)[0])))
30 #define sint4korr(A)	(*((const long *) (A)))
31 #define uint2korr(A)	(*((const uint16 *) (A)))
32 #define uint3korr(A)	(uint32) (((uint32) ((uchar) (A)[0])) |\
33 				  (((uint32) ((uchar) (A)[1])) << 8) |\
34 				  (((uint32) ((uchar) (A)[2])) << 16))
35 #define uint4korr(A)	(*((const uint32 *) (A)))
36 #define uint5korr(A)	((ulonglong)(((uint32) ((uchar) (A)[0])) |\
37 				    (((uint32) ((uchar) (A)[1])) << 8) |\
38 				    (((uint32) ((uchar) (A)[2])) << 16) |\
39 				    (((uint32) ((uchar) (A)[3])) << 24)) |\
40 				    (((ulonglong) ((uchar) (A)[4])) << 32))
41 #define uint6korr(A)	((ulonglong)(((uint32)    ((uchar) (A)[0]))          | \
42                                      (((uint32)    ((uchar) (A)[1])) << 8)   | \
43                                      (((uint32)    ((uchar) (A)[2])) << 16)  | \
44                                      (((uint32)    ((uchar) (A)[3])) << 24)) | \
45                          (((ulonglong) ((uchar) (A)[4])) << 32) |       \
46                          (((ulonglong) ((uchar) (A)[5])) << 40))
47 #define uint8korr(A)	(*((const ulonglong *) (A)))
48 #define sint8korr(A)	(*((const longlong *) (A)))
49 
50 #define int2store(T,A)	*((uint16*) (T))= (uint16) (A)
51 #define int3store(T,A)  do { *(T)=  (uchar) ((A));\
52                             *(T+1)=(uchar) (((uint) (A) >> 8));\
53                             *(T+2)=(uchar) (((A) >> 16));\
54                         } while (0)
55 #define int4store(T,A)	*((long *) (T))= (long) (A)
56 #define int5store(T,A)  do { *(T)= (uchar)((A));\
57                              *((T)+1)=(uchar) (((A) >> 8));\
58                              *((T)+2)=(uchar) (((A) >> 16));\
59                              *((T)+3)=(uchar) (((A) >> 24));\
60                              *((T)+4)=(uchar) (((A) >> 32));\
61                         } while(0)
62 #define int6store(T,A)  do { *(T)=    (uchar)((A));          \
63                              *((T)+1)=(uchar) (((A) >> 8));  \
64                              *((T)+2)=(uchar) (((A) >> 16)); \
65                              *((T)+3)=(uchar) (((A) >> 24)); \
66                              *((T)+4)=(uchar) (((A) >> 32)); \
67                              *((T)+5)=(uchar) (((A) >> 40)); \
68                         } while(0)
69 #define int8store(T,A)	*((ulonglong *) (T))= (ulonglong) (A)
70 typedef union {
71   double v;
72   long m[2];
73 } doubleget_union;
74 #define doubleget(V,M) \
75 do { doubleget_union _tmp; \
76      _tmp.m[0] = *((const long*)(M));      \
77      _tmp.m[1] = *(((const long*) (M))+1); \
78      (V) = _tmp.v; } while(0)
79 #define doublestore(T,V) \
80 do { *((long *) T) = ((const doubleget_union *)&V)->m[0];     \
81      *(((long *) T)+1) = ((const doubleget_union *)&V)->m[1]; \
82    } while (0)
83 #define float4get(V,M) \
84 do { *((float *) &(V)) = *((const float*) (M)); } while(0)
85 #define float8get(V,M)   doubleget((V),(M))
86 #define float4store(V,M) memcpy((uchar*)(V), (uchar*)(&M), sizeof(float))
87 #define floatstore(T,V)  memcpy((uchar*)(T), (uchar*)(&V), sizeof(float))
88 #define floatget(V,M)    memcpy((uchar*)(&V),(uchar*) (M), sizeof(float))
89 #define float8store(V,M) doublestore((V),(M))
90