~drizzle-trunk/drizzle/development

1 by brian
clean slate
1
/* Copyright (C) 2000 MySQL AB
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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
15
16
/*
17
  Storing of values in high byte first order.
18
19
  integer keys and file pointers are stored with high byte first to get
20
  better compression
21
*/
22
23
/* these two are for uniformity */
24
#define mi_sint1korr(A) ((int8)(*A))
25
#define mi_uint1korr(A) ((uint8)(*A))
26
27
#define mi_sint2korr(A) ((int16) (((int16) (((uchar*) (A))[1])) +\
28
                                  ((int16) ((int16) ((char*) (A))[0]) << 8)))
29
#define mi_sint3korr(A) ((int32) (((((uchar*) (A))[0]) & 128) ? \
30
                                  (((uint32) 255L << 24) | \
31
                                   (((uint32) ((uchar*) (A))[0]) << 16) |\
32
                                   (((uint32) ((uchar*) (A))[1]) << 8) | \
33
                                   ((uint32) ((uchar*) (A))[2])) : \
34
                                  (((uint32) ((uchar*) (A))[0]) << 16) |\
35
                                  (((uint32) ((uchar*) (A))[1]) << 8) | \
36
                                  ((uint32) ((uchar*) (A))[2])))
37
#define mi_sint4korr(A) ((int32) (((int32) (((uchar*) (A))[3])) +\
38
                                  ((int32) (((uchar*) (A))[2]) << 8) +\
39
                                  ((int32) (((uchar*) (A))[1]) << 16) +\
40
                                  ((int32) ((int16) ((char*) (A))[0]) << 24)))
41
#define mi_sint8korr(A) ((longlong) mi_uint8korr(A))
42
#define mi_uint2korr(A) ((uint16) (((uint16) (((uchar*) (A))[1])) +\
43
                                   ((uint16) (((uchar*) (A))[0]) << 8)))
44
#define mi_uint3korr(A) ((uint32) (((uint32) (((uchar*) (A))[2])) +\
45
                                   (((uint32) (((uchar*) (A))[1])) << 8) +\
46
                                   (((uint32) (((uchar*) (A))[0])) << 16)))
47
#define mi_uint4korr(A) ((uint32) (((uint32) (((uchar*) (A))[3])) +\
48
                                   (((uint32) (((uchar*) (A))[2])) << 8) +\
49
                                   (((uint32) (((uchar*) (A))[1])) << 16) +\
50
                                   (((uint32) (((uchar*) (A))[0])) << 24)))
51
#define mi_uint5korr(A) ((ulonglong)(((uint32) (((uchar*) (A))[4])) +\
52
                                    (((uint32) (((uchar*) (A))[3])) << 8) +\
53
                                    (((uint32) (((uchar*) (A))[2])) << 16) +\
54
                                    (((uint32) (((uchar*) (A))[1])) << 24)) +\
55
                                    (((ulonglong) (((uchar*) (A))[0])) << 32))
56
#define mi_uint6korr(A) ((ulonglong)(((uint32) (((uchar*) (A))[5])) +\
57
                                    (((uint32) (((uchar*) (A))[4])) << 8) +\
58
                                    (((uint32) (((uchar*) (A))[3])) << 16) +\
59
                                    (((uint32) (((uchar*) (A))[2])) << 24)) +\
60
                        (((ulonglong) (((uint32) (((uchar*) (A))[1])) +\
61
                                    (((uint32) (((uchar*) (A))[0]) << 8)))) <<\
62
                                     32))
63
#define mi_uint7korr(A) ((ulonglong)(((uint32) (((uchar*) (A))[6])) +\
64
                                    (((uint32) (((uchar*) (A))[5])) << 8) +\
65
                                    (((uint32) (((uchar*) (A))[4])) << 16) +\
66
                                    (((uint32) (((uchar*) (A))[3])) << 24)) +\
67
                        (((ulonglong) (((uint32) (((uchar*) (A))[2])) +\
68
                                    (((uint32) (((uchar*) (A))[1])) << 8) +\
69
                                    (((uint32) (((uchar*) (A))[0])) << 16))) <<\
70
                                     32))
71
#define mi_uint8korr(A) ((ulonglong)(((uint32) (((uchar*) (A))[7])) +\
72
                                    (((uint32) (((uchar*) (A))[6])) << 8) +\
73
                                    (((uint32) (((uchar*) (A))[5])) << 16) +\
74
                                    (((uint32) (((uchar*) (A))[4])) << 24)) +\
75
                        (((ulonglong) (((uint32) (((uchar*) (A))[3])) +\
76
                                    (((uint32) (((uchar*) (A))[2])) << 8) +\
77
                                    (((uint32) (((uchar*) (A))[1])) << 16) +\
78
                                    (((uint32) (((uchar*) (A))[0])) << 24))) <<\
79
                                    32))
80
81
/* This one is for uniformity */
82
#define mi_int1store(T,A) *((uchar*)(T))= (uchar) (A)
83
84
#define mi_int2store(T,A)   { uint def_temp= (uint) (A) ;\
85
                              ((uchar*) (T))[1]= (uchar) (def_temp);\
86
                              ((uchar*) (T))[0]= (uchar) (def_temp >> 8); }
87
#define mi_int3store(T,A)   { /*lint -save -e734 */\
88
                              ulong def_temp= (ulong) (A);\
89
                              ((uchar*) (T))[2]= (uchar) (def_temp);\
90
                              ((uchar*) (T))[1]= (uchar) (def_temp >> 8);\
91
                              ((uchar*) (T))[0]= (uchar) (def_temp >> 16);\
92
                              /*lint -restore */}
93
#define mi_int4store(T,A)   { ulong def_temp= (ulong) (A);\
94
                              ((uchar*) (T))[3]= (uchar) (def_temp);\
95
                              ((uchar*) (T))[2]= (uchar) (def_temp >> 8);\
96
                              ((uchar*) (T))[1]= (uchar) (def_temp >> 16);\
97
                              ((uchar*) (T))[0]= (uchar) (def_temp >> 24); }
98
#define mi_int5store(T,A)   { ulong def_temp= (ulong) (A),\
99
                              def_temp2= (ulong) ((A) >> 32);\
100
                              ((uchar*) (T))[4]= (uchar) (def_temp);\
101
                              ((uchar*) (T))[3]= (uchar) (def_temp >> 8);\
102
                              ((uchar*) (T))[2]= (uchar) (def_temp >> 16);\
103
                              ((uchar*) (T))[1]= (uchar) (def_temp >> 24);\
104
                              ((uchar*) (T))[0]= (uchar) (def_temp2); }
105
#define mi_int6store(T,A)   { ulong def_temp= (ulong) (A),\
106
                              def_temp2= (ulong) ((A) >> 32);\
107
                              ((uchar*) (T))[5]= (uchar) (def_temp);\
108
                              ((uchar*) (T))[4]= (uchar) (def_temp >> 8);\
109
                              ((uchar*) (T))[3]= (uchar) (def_temp >> 16);\
110
                              ((uchar*) (T))[2]= (uchar) (def_temp >> 24);\
111
                              ((uchar*) (T))[1]= (uchar) (def_temp2);\
112
                              ((uchar*) (T))[0]= (uchar) (def_temp2 >> 8); }
113
#define mi_int7store(T,A)   { ulong def_temp= (ulong) (A),\
114
                              def_temp2= (ulong) ((A) >> 32);\
115
                              ((uchar*) (T))[6]= (uchar) (def_temp);\
116
                              ((uchar*) (T))[5]= (uchar) (def_temp >> 8);\
117
                              ((uchar*) (T))[4]= (uchar) (def_temp >> 16);\
118
                              ((uchar*) (T))[3]= (uchar) (def_temp >> 24);\
119
                              ((uchar*) (T))[2]= (uchar) (def_temp2);\
120
                              ((uchar*) (T))[1]= (uchar) (def_temp2 >> 8);\
121
                              ((uchar*) (T))[0]= (uchar) (def_temp2 >> 16); }
122
#define mi_int8store(T,A)   { ulong def_temp3= (ulong) (A),\
123
                              def_temp4= (ulong) ((A) >> 32);\
124
                              mi_int4store((uchar*) (T) + 0, def_temp4);\
125
                              mi_int4store((uchar*) (T) + 4, def_temp3); }
126
127
#ifdef WORDS_BIGENDIAN
128
129
#define mi_float4store(T,A) { ((uchar*) (T))[0]= ((uchar*) &A)[0];\
130
                              ((uchar*) (T))[1]= ((uchar*) &A)[1];\
131
                              ((uchar*) (T))[2]= ((uchar*) &A)[2];\
132
                              ((uchar*) (T))[3]= ((uchar*) &A)[3]; }
133
134
#define mi_float4get(V,M)   { float def_temp;\
135
                              ((uchar*) &def_temp)[0]= ((uchar*) (M))[0];\
136
                              ((uchar*) &def_temp)[1]= ((uchar*) (M))[1];\
137
                              ((uchar*) &def_temp)[2]= ((uchar*) (M))[2];\
138
                              ((uchar*) &def_temp)[3]= ((uchar*) (M))[3];\
139
                              (V)= def_temp; }
140
141
#define mi_float8store(T,V) { ((uchar*) (T))[0]= ((uchar*) &V)[0];\
142
                              ((uchar*) (T))[1]= ((uchar*) &V)[1];\
143
                              ((uchar*) (T))[2]= ((uchar*) &V)[2];\
144
                              ((uchar*) (T))[3]= ((uchar*) &V)[3];\
145
                              ((uchar*) (T))[4]= ((uchar*) &V)[4];\
146
                              ((uchar*) (T))[5]= ((uchar*) &V)[5];\
147
                              ((uchar*) (T))[6]= ((uchar*) &V)[6];\
148
                              ((uchar*) (T))[7]= ((uchar*) &V)[7]; }
149
150
#define mi_float8get(V,M)   { double def_temp;\
151
                              ((uchar*) &def_temp)[0]= ((uchar*) (M))[0];\
152
                              ((uchar*) &def_temp)[1]= ((uchar*) (M))[1];\
153
                              ((uchar*) &def_temp)[2]= ((uchar*) (M))[2];\
154
                              ((uchar*) &def_temp)[3]= ((uchar*) (M))[3];\
155
                              ((uchar*) &def_temp)[4]= ((uchar*) (M))[4];\
156
                              ((uchar*) &def_temp)[5]= ((uchar*) (M))[5];\
157
                              ((uchar*) &def_temp)[6]= ((uchar*) (M))[6];\
158
                              ((uchar*) &def_temp)[7]= ((uchar*) (M))[7]; \
159
                              (V)= def_temp; }
160
#else
161
162
#define mi_float4store(T,A) { ((uchar*) (T))[0]= ((uchar*) &A)[3];\
163
                              ((uchar*) (T))[1]= ((uchar*) &A)[2];\
164
                              ((uchar*) (T))[2]= ((uchar*) &A)[1];\
165
                              ((uchar*) (T))[3]= ((uchar*) &A)[0]; }
166
167
#define mi_float4get(V,M)   { float def_temp;\
168
                              ((uchar*) &def_temp)[0]= ((uchar*) (M))[3];\
169
                              ((uchar*) &def_temp)[1]= ((uchar*) (M))[2];\
170
                              ((uchar*) &def_temp)[2]= ((uchar*) (M))[1];\
171
                              ((uchar*) &def_temp)[3]= ((uchar*) (M))[0];\
172
                              (V)= def_temp; }
173
174
#if defined(__FLOAT_WORD_ORDER) && (__FLOAT_WORD_ORDER == __BIG_ENDIAN)
175
#define mi_float8store(T,V) { ((uchar*) (T))[0]= ((uchar*) &V)[3];\
176
                              ((uchar*) (T))[1]= ((uchar*) &V)[2];\
177
                              ((uchar*) (T))[2]= ((uchar*) &V)[1];\
178
                              ((uchar*) (T))[3]= ((uchar*) &V)[0];\
179
                              ((uchar*) (T))[4]= ((uchar*) &V)[7];\
180
                              ((uchar*) (T))[5]= ((uchar*) &V)[6];\
181
                              ((uchar*) (T))[6]= ((uchar*) &V)[5];\
182
                              ((uchar*) (T))[7]= ((uchar*) &V)[4];}
183
184
#define mi_float8get(V,M)   { double def_temp;\
185
                              ((uchar*) &def_temp)[0]= ((uchar*) (M))[3];\
186
                              ((uchar*) &def_temp)[1]= ((uchar*) (M))[2];\
187
                              ((uchar*) &def_temp)[2]= ((uchar*) (M))[1];\
188
                              ((uchar*) &def_temp)[3]= ((uchar*) (M))[0];\
189
                              ((uchar*) &def_temp)[4]= ((uchar*) (M))[7];\
190
                              ((uchar*) &def_temp)[5]= ((uchar*) (M))[6];\
191
                              ((uchar*) &def_temp)[6]= ((uchar*) (M))[5];\
192
                              ((uchar*) &def_temp)[7]= ((uchar*) (M))[4];\
193
                              (V)= def_temp; }
194
195
#else
196
#define mi_float8store(T,V) { ((uchar*) (T))[0]= ((uchar*) &V)[7];\
197
                              ((uchar*) (T))[1]= ((uchar*) &V)[6];\
198
                              ((uchar*) (T))[2]= ((uchar*) &V)[5];\
199
                              ((uchar*) (T))[3]= ((uchar*) &V)[4];\
200
                              ((uchar*) (T))[4]= ((uchar*) &V)[3];\
201
                              ((uchar*) (T))[5]= ((uchar*) &V)[2];\
202
                              ((uchar*) (T))[6]= ((uchar*) &V)[1];\
203
                              ((uchar*) (T))[7]= ((uchar*) &V)[0];}
204
205
#define mi_float8get(V,M)   { double def_temp;\
206
                              ((uchar*) &def_temp)[0]= ((uchar*) (M))[7];\
207
                              ((uchar*) &def_temp)[1]= ((uchar*) (M))[6];\
208
                              ((uchar*) &def_temp)[2]= ((uchar*) (M))[5];\
209
                              ((uchar*) &def_temp)[3]= ((uchar*) (M))[4];\
210
                              ((uchar*) &def_temp)[4]= ((uchar*) (M))[3];\
211
                              ((uchar*) &def_temp)[5]= ((uchar*) (M))[2];\
212
                              ((uchar*) &def_temp)[6]= ((uchar*) (M))[1];\
213
                              ((uchar*) &def_temp)[7]= ((uchar*) (M))[0];\
214
                              (V)= def_temp; }
215
#endif /* __FLOAT_WORD_ORDER */
216
#endif /* WORDS_BIGENDIAN */
217
218
/* Fix to avoid warnings when sizeof(ha_rows) == sizeof(long) */
219
220
#ifdef BIG_TABLES
221
#define mi_rowstore(T,A)    mi_int8store(T, A)
222
#define mi_rowkorr(T)       mi_uint8korr(T)
223
#else
224
#define mi_rowstore(T,A)    { mi_int4store(T, 0);\
225
                              mi_int4store(((uchar*) (T) + 4), A); }
226
#define mi_rowkorr(T)       mi_uint4korr((uchar*) (T) + 4)
227
#endif
228
229
#if SIZEOF_OFF_T > 4
230
#define mi_sizestore(T,A)   mi_int8store(T, A)
231
#define mi_sizekorr(T)      mi_uint8korr(T)
232
#else
233
#define mi_sizestore(T,A)   { if ((A) == HA_OFFSET_ERROR)\
234
                                bfill((char*) (T), 8, 255);\
235
                              else { mi_int4store((T), 0);\
236
                                     mi_int4store(((T) + 4), A); }}
237
#define mi_sizekorr(T)      mi_uint4korr((uchar*) (T) + 4)
238
#endif