1
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2008 Sun Microsystems, Inc.
4
* Copyright (C) 2008 Sun Microsystems
6
6
* This program is free software; you can redistribute it and/or modify
7
7
* it under the terms of the GNU General Public License as published by
42
42
((uint32_t) (unsigned char) (A)[0])))
43
43
#define sint4korr(A) (*((long *) (A)))
44
44
#define uint2korr(A) (*((uint16_t *) (A)))
45
#if defined(HAVE_VALGRIND)
45
#if defined(HAVE_purify)
46
46
#define uint3korr(A) (uint32_t) (((uint32_t) ((unsigned char) (A)[0])) +\
47
47
(((uint32_t) ((unsigned char) (A)[1])) << 8) +\
48
48
(((uint32_t) ((unsigned char) (A)[2])) << 16))
53
53
Please, note, uint3korr reads 4 bytes (not 3) !
54
54
It means, that you have to provide enough allocated space !
56
56
#define uint3korr(A) (long) (*((unsigned int *) (A)) & 0xFFFFFF)
57
#endif /* HAVE_VALGRIND */
57
#endif /* HAVE_purify */
58
58
#define uint4korr(A) (*((uint32_t *) (A)))
59
#define uint5korr(A) ((uint64_t)(((uint32_t) ((unsigned char) (A)[0])) +\
60
(((uint32_t) ((unsigned char) (A)[1])) << 8) +\
61
(((uint32_t) ((unsigned char) (A)[2])) << 16) +\
62
(((uint32_t) ((unsigned char) (A)[3])) << 24)) +\
63
(((uint64_t) ((unsigned char) (A)[4])) << 32))
64
#define uint6korr(A) ((uint64_t)(((uint32_t) ((unsigned char) (A)[0])) + \
65
(((uint32_t) ((unsigned char) (A)[1])) << 8) + \
66
(((uint32_t) ((unsigned char) (A)[2])) << 16) + \
67
(((uint32_t) ((unsigned char) (A)[3])) << 24)) + \
68
(((uint64_t) ((unsigned char) (A)[4])) << 32) + \
69
(((uint64_t) ((unsigned char) (A)[5])) << 40))
59
70
#define uint8korr(A) (*((uint64_t *) (A)))
60
71
#define sint8korr(A) (*((int64_t *) (A)))
61
72
#define int2store(T,A) *((uint16_t*) (T))= (uint16_t) (A)
63
74
*(T+1)=(unsigned char) (((uint32_t) (A) >> 8));\
64
75
*(T+2)=(unsigned char) (((A) >> 16)); } while (0)
65
76
#define int4store(T,A) *((long *) (T))= (long) (A)
77
#define int5store(T,A) do { *(T)= (unsigned char)((A));\
78
*((T)+1)=(unsigned char) (((A) >> 8));\
79
*((T)+2)=(unsigned char) (((A) >> 16));\
80
*((T)+3)=(unsigned char) (((A) >> 24)); \
81
*((T)+4)=(unsigned char) (((A) >> 32)); } while(0)
82
#define int6store(T,A) do { *(T)= (unsigned char)((A)); \
83
*((T)+1)=(unsigned char) (((A) >> 8)); \
84
*((T)+2)=(unsigned char) (((A) >> 16)); \
85
*((T)+3)=(unsigned char) (((A) >> 24)); \
86
*((T)+4)=(unsigned char) (((A) >> 32)); \
87
*((T)+5)=(unsigned char) (((A) >> 40)); } while(0)
66
88
#define int8store(T,A) *((uint64_t *) (T))= (uint64_t) (A)
80
102
#define float4get(V,M) do { *((float *) &(V)) = *((float*) (M)); } while(0)
81
103
#define float8get(V,M) doubleget((V),(M))
104
#define float4store(V,M) memcpy(V, (&M), sizeof(float))
82
105
#define floatstore(T,V) memcpy((T), (&V), sizeof(float))
106
#define floatget(V,M) memcpy(&V, (M), sizeof(float))
83
107
#define float8store(V,M) doublestore((V),(M))
111
135
(((uint32_t) ((unsigned char) (A)[1])) << 8) +\
112
136
(((uint32_t) ((unsigned char) (A)[2])) << 16) +\
113
137
(((uint32_t) ((unsigned char) (A)[3])) << 24))
138
#define uint5korr(A) ((uint64_t)(((uint32_t) ((unsigned char) (A)[0])) +\
139
(((uint32_t) ((unsigned char) (A)[1])) << 8) +\
140
(((uint32_t) ((unsigned char) (A)[2])) << 16) +\
141
(((uint32_t) ((unsigned char) (A)[3])) << 24)) +\
142
(((uint64_t) ((unsigned char) (A)[4])) << 32))
143
#define uint6korr(A) ((uint64_t)(((uint32_t) ((unsigned char) (A)[0])) + \
144
(((uint32_t) ((unsigned char) (A)[1])) << 8) + \
145
(((uint32_t) ((unsigned char) (A)[2])) << 16) + \
146
(((uint32_t) ((unsigned char) (A)[3])) << 24)) + \
147
(((uint64_t) ((unsigned char) (A)[4])) << 32) + \
148
(((uint64_t) ((unsigned char) (A)[5])) << 40))
114
149
#define uint8korr(A) ((uint64_t)(((uint32_t) ((unsigned char) (A)[0])) +\
115
150
(((uint32_t) ((unsigned char) (A)[1])) << 8) +\
116
151
(((uint32_t) ((unsigned char) (A)[2])) << 16) +\
133
168
*(((char *)(T))+1)=(char) (((A) >> 8));\
134
169
*(((char *)(T))+2)=(char) (((A) >> 16));\
135
170
*(((char *)(T))+3)=(char) (((A) >> 24)); } while(0)
171
#define int5store(T,A) do { *((char *)(T))= (char)((A)); \
172
*(((char *)(T))+1)= (char)(((A) >> 8)); \
173
*(((char *)(T))+2)= (char)(((A) >> 16)); \
174
*(((char *)(T))+3)= (char)(((A) >> 24)); \
175
*(((char *)(T))+4)= (char)(((A) >> 32)); \
177
#define int6store(T,A) do { *((char *)(T))= (char)((A)); \
178
*(((char *)(T))+1)= (char)(((A) >> 8)); \
179
*(((char *)(T))+2)= (char)(((A) >> 16)); \
180
*(((char *)(T))+3)= (char)(((A) >> 24)); \
181
*(((char *)(T))+4)= (char)(((A) >> 32)); \
182
*(((char *)(T))+5)= (char)(((A) >> 40)); \
136
184
#define int8store(T,A) do { uint32_t def_temp= (uint32_t) (A), def_temp2= (uint32_t) ((A) >> 32); \
137
185
int4store((T),def_temp); \
138
186
int4store((T+4),def_temp2); } while(0)
139
187
#ifdef WORDS_BIGENDIAN
188
#define float4store(T,A) do { *(T)= ((unsigned char *) &A)[3];\
189
*((T)+1)=(char) ((unsigned char *) &A)[2];\
190
*((T)+2)=(char) ((unsigned char *) &A)[1];\
191
*((T)+3)=(char) ((unsigned char *) &A)[0]; } while(0)
140
193
#define float4get(V,M) do { float def_temp;\
141
194
((unsigned char*) &def_temp)[0]=(M)[3];\
142
195
((unsigned char*) &def_temp)[1]=(M)[2];\
164
217
(V) = def_temp; } while(0)
166
219
#define float4get(V,M) memcpy(&V, (M), sizeof(float))
220
#define float4store(V,M) memcpy(V, (&M), sizeof(float))
168
222
#if defined(__FLOAT_WORD_ORDER) && (__FLOAT_WORD_ORDER == __BIG_ENDIAN)
169
223
#define doublestore(T,V) do { *(((char*)T)+0)=(char) ((unsigned char *) &V)[4];\
194
248
#endif /* __i386__ */
251
Macro for reading 32-bit integer from network byte order (big-endian)
252
from unaligned memory location.
254
#define int4net(A) (int32_t) (((uint32_t) ((unsigned char) (A)[3])) |\
255
(((uint32_t) ((unsigned char) (A)[2])) << 8) |\
256
(((uint32_t) ((unsigned char) (A)[1])) << 16) |\
257
(((uint32_t) ((unsigned char) (A)[0])) << 24))
197
259
Define-funktions for reading and storing in machine format from/to
198
260
short/long to/from some place in memory V should be a (not
199
261
register) variable, M is a pointer to byte
202
264
#ifdef WORDS_BIGENDIAN
266
#define ushortget(V,M) do { V = (uint16_t) (((uint16_t) ((unsigned char) (M)[1]))+\
267
((uint16_t) ((uint16_t) (M)[0]) << 8)); } while(0)
204
268
#define shortget(V,M) do { V = (short) (((short) ((unsigned char) (M)[1]))+\
205
269
((short) ((short) (M)[0]) << 8)); } while(0)
206
270
#define longget(V,M) do { int32_t def_temp;\
209
273
((unsigned char*) &def_temp)[2]=(M)[2];\
210
274
((unsigned char*) &def_temp)[3]=(M)[3];\
211
275
(V)=def_temp; } while(0)
276
#define ulongget(V,M) do { uint32_t def_temp;\
277
((unsigned char*) &def_temp)[0]=(M)[0];\
278
((unsigned char*) &def_temp)[1]=(M)[1];\
279
((unsigned char*) &def_temp)[2]=(M)[2];\
280
((unsigned char*) &def_temp)[3]=(M)[3];\
281
(V)=def_temp; } while(0)
212
282
#define shortstore(T,A) do { uint32_t def_temp=(uint32_t) (A) ;\
213
283
*(((char*)T)+1)=(char)(def_temp); \
214
284
*(((char*)T)+0)=(char)(def_temp >> 8); } while(0)
217
287
*(((char*)T)+1)=(((A) >> 16));\
218
288
*(((char*)T)+0)=(((A) >> 24)); } while(0)
290
#define floatget(V,M) memcpy(&V, (M), sizeof(float))
220
291
#define floatstore(T, V) memcpy((T), (&V), sizeof(float))
221
292
#define doubleget(V, M) memcpy(&V, (M), sizeof(double))
222
293
#define doublestore(T, V) memcpy((T), &V, sizeof(double))
299
#define ushortget(V,M) do { V = uint2korr(M); } while(0)
228
300
#define shortget(V,M) do { V = sint2korr(M); } while(0)
229
301
#define longget(V,M) do { V = sint4korr(M); } while(0)
302
#define ulongget(V,M) do { V = uint4korr(M); } while(0)
230
303
#define shortstore(T,V) int2store(T,V)
231
304
#define longstore(T,V) int4store(T,V)
232
305
#ifndef floatstore
233
306
#define floatstore(T,V) memcpy((T), (&V), sizeof(float))
307
#define floatget(V,M) memcpy(&V, (M), sizeof(float))
235
309
#ifndef doubleget
236
310
#define doubleget(V, M) memcpy(&V, (M), sizeof(double))