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