1/* Copyright (c) 2012, 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 02111-1307 USA */
15
16/*
17 Data in little-endian format.
18*/
19
20#ifndef MY_BYTE_ORDER_ARCH_OPTIMIZED
21#define float4get(V,M) memcpy(&V, (M), sizeof(float))
22#define float4store(V,M) memcpy(V, (&M), sizeof(float))
23#define float8get(V,M) doubleget((V),(M))
24#define float8store(V,M) doublestore((V),(M))
25
26/* Bi-endian hardware.... */
27#if defined(__FLOAT_WORD_ORDER) && (__FLOAT_WORD_ORDER == __BIG_ENDIAN)
28#define doublestore(T,V) do { *(((char*)T)+0)=(char) ((uchar *) &V)[4];\
29 *(((char*)T)+1)=(char) ((uchar *) &V)[5];\
30 *(((char*)T)+2)=(char) ((uchar *) &V)[6];\
31 *(((char*)T)+3)=(char) ((uchar *) &V)[7];\
32 *(((char*)T)+4)=(char) ((uchar *) &V)[0];\
33 *(((char*)T)+5)=(char) ((uchar *) &V)[1];\
34 *(((char*)T)+6)=(char) ((uchar *) &V)[2];\
35 *(((char*)T)+7)=(char) ((uchar *) &V)[3]; }\
36 while(0)
37#define doubleget(V,M) do { double def_temp;\
38 ((uchar*) &def_temp)[0]=(M)[4];\
39 ((uchar*) &def_temp)[1]=(M)[5];\
40 ((uchar*) &def_temp)[2]=(M)[6];\
41 ((uchar*) &def_temp)[3]=(M)[7];\
42 ((uchar*) &def_temp)[4]=(M)[0];\
43 ((uchar*) &def_temp)[5]=(M)[1];\
44 ((uchar*) &def_temp)[6]=(M)[2];\
45 ((uchar*) &def_temp)[7]=(M)[3];\
46 (V) = def_temp; } while(0)
47#else /* Bi-endian hardware.... */
48
49/* Cast away type qualifiers (necessary as macro takes argument by value). */
50#define doublestore(T,V) memcpy((T), (void*) &V, sizeof(double))
51#define doubleget(V,M) memcpy(&V, (M), sizeof(double))
52
53#endif /* Bi-endian hardware.... */
54
55#endif /* !MY_BYTE_ORDER_ARCH_OPTIMIZED */
56
57#define ushortget(V,M) do { uchar *pM= (uchar*)(M);V = uint2korr(pM);} while(0)
58#define shortget(V,M) do { uchar *pM= (uchar*)(M);V = sint2korr(pM);} while(0)
59#define longget(V,M) do { uchar *pM= (uchar*)(M);V = sint4korr(pM);} while(0)
60#define ulongget(V,M) do { uchar *pM= (uchar*)(M);V = uint4korr(pM);} while(0)
61#define shortstore(T,V) int2store(T,V)
62#define longstore(T,V) int4store(T,V)
63
64#ifndef floatstore
65/* Cast away type qualifiers (necessary as macro takes argument by value). */
66#define floatstore(T,V) memcpy((T), (void*) (&V), sizeof(float))
67#define floatget(V,M) memcpy(&V, (M), sizeof(float))
68#endif
69#ifndef doubleget
70#define doubleget(V,M) memcpy(&V, (M), sizeof(double))
71#define doublestore(T,V) memcpy((T), (void *) &V, sizeof(double))
72#endif /* doubleget */
73
74#define longlongget(V,M) memcpy(&V, (M), sizeof(ulonglong))
75#define longlongstore(T,V) memcpy((T), &V, sizeof(ulonglong))
76