|
1 |
| -/* Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. |
| 1 | +/* Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved. |
2 | 2 |
|
3 | 3 | This program is free software; you can redistribute it and/or modify
|
4 | 4 | it under the terms of the GNU General Public License as published by
|
|
17 | 17 | Data in little-endian format.
|
18 | 18 | */
|
19 | 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)) |
| 20 | +#include <string.h> |
| 21 | + |
| 22 | +static inline void float4get (float *V, const uchar *M) |
| 23 | +{ |
| 24 | + memcpy(V, (M), sizeof(float)); |
| 25 | +} |
| 26 | + |
| 27 | +static inline void float4store(uchar *V, float M) |
| 28 | +{ |
| 29 | + memcpy(V, (&M), sizeof(float)); |
| 30 | +} |
| 31 | + |
| 32 | +static inline void float8get (double *V, const uchar *M) |
| 33 | +{ |
| 34 | + memcpy(V, M, sizeof(double)); |
| 35 | +} |
| 36 | + |
| 37 | +static inline void float8store(uchar *V, double M) |
| 38 | +{ |
| 39 | + memcpy(V, &M, sizeof(double)); |
| 40 | +} |
| 41 | + |
| 42 | +static inline void floatget (float *V, const uchar *M) { float4get(V, M); } |
| 43 | +static inline void floatstore (uchar *V, float M) { float4store(V, M); } |
25 | 44 |
|
26 | 45 | /* Bi-endian hardware.... */
|
27 | 46 | #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 | +static inline void doublestore(uchar *T, double V) |
| 48 | +{ *(((char*)T)+0)=(char) ((uchar *) &V)[4]; |
| 49 | + *(((char*)T)+1)=(char) ((uchar *) &V)[5]; |
| 50 | + *(((char*)T)+2)=(char) ((uchar *) &V)[6]; |
| 51 | + *(((char*)T)+3)=(char) ((uchar *) &V)[7]; |
| 52 | + *(((char*)T)+4)=(char) ((uchar *) &V)[0]; |
| 53 | + *(((char*)T)+5)=(char) ((uchar *) &V)[1]; |
| 54 | + *(((char*)T)+6)=(char) ((uchar *) &V)[2]; |
| 55 | + *(((char*)T)+7)=(char) ((uchar *) &V)[3]; } |
| 56 | +static inline void doubleget(double *V, const uchar *M) |
| 57 | +{ double def_temp; |
| 58 | + ((uchar*) &def_temp)[0]=(M)[4]; |
| 59 | + ((uchar*) &def_temp)[1]=(M)[5]; |
| 60 | + ((uchar*) &def_temp)[2]=(M)[6]; |
| 61 | + ((uchar*) &def_temp)[3]=(M)[7]; |
| 62 | + ((uchar*) &def_temp)[4]=(M)[0]; |
| 63 | + ((uchar*) &def_temp)[5]=(M)[1]; |
| 64 | + ((uchar*) &def_temp)[6]=(M)[2]; |
| 65 | + ((uchar*) &def_temp)[7]=(M)[3]; |
| 66 | + (*V) = def_temp; } |
| 67 | + |
47 | 68 | #else /* Bi-endian hardware.... */
|
48 | 69 |
|
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)) |
| 70 | +static inline void doublestore(uchar *T, double V) { memcpy(T, &V, sizeof(double)); } |
| 71 | +static inline void doubleget (double *V, const uchar *M) { memcpy(V, M, sizeof(double)); } |
52 | 72 |
|
53 | 73 | #endif /* Bi-endian hardware.... */
|
54 | 74 |
|
55 |
| -#endif /* !MY_BYTE_ORDER_ARCH_OPTIMIZED */ |
56 |
| - |
57 | 75 | #define ushortget(V,M) do { uchar *pM= (uchar*)(M);V = uint2korr(pM);} while(0)
|
58 | 76 | #define shortget(V,M) do { uchar *pM= (uchar*)(M);V = sint2korr(pM);} while(0)
|
59 | 77 | #define longget(V,M) do { uchar *pM= (uchar*)(M);V = sint4korr(pM);} while(0)
|
60 | 78 | #define ulongget(V,M) do { uchar *pM= (uchar*)(M);V = uint4korr(pM);} while(0)
|
61 | 79 | #define shortstore(T,V) int2store(T,V)
|
62 | 80 | #define longstore(T,V) int4store(T,V)
|
63 | 81 |
|
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 |
| - |
70 | 82 | #define longlongget(V,M) memcpy(&V, (M), sizeof(ulonglong))
|
71 | 83 | #define longlongstore(T,V) memcpy((T), &V, sizeof(ulonglong))
|
0 commit comments