myisampack.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. #ifndef MYISAMPACK_INCLUDED
  2. #define MYISAMPACK_INCLUDED
  3. /* Copyright (c) 2000-2002, 2004 MySQL AB, 2009 Sun Microsystems, Inc.
  4. Use is subject to license terms.
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; version 2 of the License.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  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. Storing of values in high byte first order.
  17. integer keys and file pointers are stored with high byte first to get
  18. better compression
  19. */
  20. /* these two are for uniformity */
  21. #define mi_sint1korr(A) ((int8)(*A))
  22. #define mi_uint1korr(A) ((uint8)(*A))
  23. #define mi_sint2korr(A) ((int16) (((int16) (((const uchar*) (A))[1])) +\
  24. ((int16) ((int16) ((const char*) (A))[0]) << 8)))
  25. #define mi_sint3korr(A) ((int32) (((((const uchar*) (A))[0]) & 128) ? \
  26. (((uint32) 255L << 24) | \
  27. (((uint32) ((const uchar*) (A))[0]) << 16) |\
  28. (((uint32) ((const uchar*) (A))[1]) << 8) | \
  29. ((uint32) ((const uchar*) (A))[2])) : \
  30. (((uint32) ((const uchar*) (A))[0]) << 16) |\
  31. (((uint32) ((const uchar*) (A))[1]) << 8) | \
  32. ((uint32) ((const uchar*) (A))[2])))
  33. #define mi_sint4korr(A) ((int32) (((int32) (((const uchar*) (A))[3])) +\
  34. ((int32) (((const uchar*) (A))[2]) << 8) +\
  35. ((int32) (((const uchar*) (A))[1]) << 16) +\
  36. ((int32) ((int16) ((const char*) (A))[0]) << 24)))
  37. #define mi_sint8korr(A) ((longlong) mi_uint8korr(A))
  38. #define mi_uint2korr(A) ((uint16) (((uint16) (((const uchar*) (A))[1])) +\
  39. ((uint16) (((const uchar*) (A))[0]) << 8)))
  40. #define mi_uint3korr(A) ((uint32) (((uint32) (((const uchar*) (A))[2])) +\
  41. (((uint32) (((const uchar*) (A))[1])) << 8) +\
  42. (((uint32) (((const uchar*) (A))[0])) << 16)))
  43. #define mi_uint4korr(A) ((uint32) (((uint32) (((const uchar*) (A))[3])) +\
  44. (((uint32) (((const uchar*) (A))[2])) << 8) +\
  45. (((uint32) (((const uchar*) (A))[1])) << 16) +\
  46. (((uint32) (((const uchar*) (A))[0])) << 24)))
  47. #define mi_uint5korr(A) ((ulonglong)(((uint32) (((const uchar*) (A))[4])) +\
  48. (((uint32) (((const uchar*) (A))[3])) << 8) +\
  49. (((uint32) (((const uchar*) (A))[2])) << 16) +\
  50. (((uint32) (((const uchar*) (A))[1])) << 24)) +\
  51. (((ulonglong) (((const uchar*) (A))[0])) << 32))
  52. #define mi_uint6korr(A) ((ulonglong)(((uint32) (((const uchar*) (A))[5])) +\
  53. (((uint32) (((const uchar*) (A))[4])) << 8) +\
  54. (((uint32) (((const uchar*) (A))[3])) << 16) +\
  55. (((uint32) (((const uchar*) (A))[2])) << 24)) +\
  56. (((ulonglong) (((uint32) (((const uchar*) (A))[1])) +\
  57. (((uint32) (((const uchar*) (A))[0]) << 8)))) <<\
  58. 32))
  59. #define mi_uint7korr(A) ((ulonglong)(((uint32) (((const uchar*) (A))[6])) +\
  60. (((uint32) (((const uchar*) (A))[5])) << 8) +\
  61. (((uint32) (((const uchar*) (A))[4])) << 16) +\
  62. (((uint32) (((const uchar*) (A))[3])) << 24)) +\
  63. (((ulonglong) (((uint32) (((const uchar*) (A))[2])) +\
  64. (((uint32) (((const uchar*) (A))[1])) << 8) +\
  65. (((uint32) (((const uchar*) (A))[0])) << 16))) <<\
  66. 32))
  67. #define mi_uint8korr(A) ((ulonglong)(((uint32) (((const uchar*) (A))[7])) +\
  68. (((uint32) (((const uchar*) (A))[6])) << 8) +\
  69. (((uint32) (((const uchar*) (A))[5])) << 16) +\
  70. (((uint32) (((const uchar*) (A))[4])) << 24)) +\
  71. (((ulonglong) (((uint32) (((const uchar*) (A))[3])) +\
  72. (((uint32) (((const uchar*) (A))[2])) << 8) +\
  73. (((uint32) (((const uchar*) (A))[1])) << 16) +\
  74. (((uint32) (((const uchar*) (A))[0])) << 24))) <<\
  75. 32))
  76. /* This one is for uniformity */
  77. #define mi_int1store(T,A) *((uchar*)(T))= (uchar) (A)
  78. #define mi_int2store(T,A) { uint def_temp= (uint) (A) ;\
  79. ((uchar*) (T))[1]= (uchar) (def_temp);\
  80. ((uchar*) (T))[0]= (uchar) (def_temp >> 8); }
  81. #define mi_int3store(T,A) { /*lint -save -e734 */\
  82. ulong def_temp= (ulong) (A);\
  83. ((uchar*) (T))[2]= (uchar) (def_temp);\
  84. ((uchar*) (T))[1]= (uchar) (def_temp >> 8);\
  85. ((uchar*) (T))[0]= (uchar) (def_temp >> 16);\
  86. /*lint -restore */}
  87. #define mi_int4store(T,A) { ulong def_temp= (ulong) (A);\
  88. ((uchar*) (T))[3]= (uchar) (def_temp);\
  89. ((uchar*) (T))[2]= (uchar) (def_temp >> 8);\
  90. ((uchar*) (T))[1]= (uchar) (def_temp >> 16);\
  91. ((uchar*) (T))[0]= (uchar) (def_temp >> 24); }
  92. #define mi_int5store(T,A) { ulong def_temp= (ulong) (A),\
  93. def_temp2= (ulong) ((A) >> 32);\
  94. ((uchar*) (T))[4]= (uchar) (def_temp);\
  95. ((uchar*) (T))[3]= (uchar) (def_temp >> 8);\
  96. ((uchar*) (T))[2]= (uchar) (def_temp >> 16);\
  97. ((uchar*) (T))[1]= (uchar) (def_temp >> 24);\
  98. ((uchar*) (T))[0]= (uchar) (def_temp2); }
  99. #define mi_int6store(T,A) { ulong def_temp= (ulong) (A),\
  100. def_temp2= (ulong) ((A) >> 32);\
  101. ((uchar*) (T))[5]= (uchar) (def_temp);\
  102. ((uchar*) (T))[4]= (uchar) (def_temp >> 8);\
  103. ((uchar*) (T))[3]= (uchar) (def_temp >> 16);\
  104. ((uchar*) (T))[2]= (uchar) (def_temp >> 24);\
  105. ((uchar*) (T))[1]= (uchar) (def_temp2);\
  106. ((uchar*) (T))[0]= (uchar) (def_temp2 >> 8); }
  107. #define mi_int7store(T,A) { ulong def_temp= (ulong) (A),\
  108. def_temp2= (ulong) ((A) >> 32);\
  109. ((uchar*) (T))[6]= (uchar) (def_temp);\
  110. ((uchar*) (T))[5]= (uchar) (def_temp >> 8);\
  111. ((uchar*) (T))[4]= (uchar) (def_temp >> 16);\
  112. ((uchar*) (T))[3]= (uchar) (def_temp >> 24);\
  113. ((uchar*) (T))[2]= (uchar) (def_temp2);\
  114. ((uchar*) (T))[1]= (uchar) (def_temp2 >> 8);\
  115. ((uchar*) (T))[0]= (uchar) (def_temp2 >> 16); }
  116. #define mi_int8store(T,A) { ulong def_temp3= (ulong) (A),\
  117. def_temp4= (ulong) ((A) >> 32);\
  118. mi_int4store((uchar*) (T) + 0, def_temp4);\
  119. mi_int4store((uchar*) (T) + 4, def_temp3); }
  120. #ifdef WORDS_BIGENDIAN
  121. #define mi_float4store(T,A) { ((uchar*) (T))[0]= ((uchar*) &A)[0];\
  122. ((uchar*) (T))[1]= ((uchar*) &A)[1];\
  123. ((uchar*) (T))[2]= ((uchar*) &A)[2];\
  124. ((uchar*) (T))[3]= ((uchar*) &A)[3]; }
  125. #define mi_float4get(V,M) { float def_temp;\
  126. ((uchar*) &def_temp)[0]= ((const uchar*) (M))[0];\
  127. ((uchar*) &def_temp)[1]= ((const uchar*) (M))[1]; \
  128. ((uchar*) &def_temp)[2]= ((const uchar*) (M))[2];\
  129. ((uchar*) &def_temp)[3]= ((const uchar*) (M))[3];\
  130. (V)= def_temp; }
  131. #define mi_float8store(T,V) { ((uchar*) (T))[0]= ((const uchar*) &V)[0];\
  132. ((uchar*) (T))[1]= ((const uchar*) &V)[1];\
  133. ((uchar*) (T))[2]= ((const uchar*) &V)[2];\
  134. ((uchar*) (T))[3]= ((const uchar*) &V)[3];\
  135. ((uchar*) (T))[4]= ((const uchar*) &V)[4];\
  136. ((uchar*) (T))[5]= ((const uchar*) &V)[5];\
  137. ((uchar*) (T))[6]= ((const uchar*) &V)[6];\
  138. ((uchar*) (T))[7]= ((const uchar*) &V)[7]; }
  139. #define mi_float8get(V,M) { double def_temp;\
  140. ((uchar*) &def_temp)[0]= ((const uchar*) (M))[0];\
  141. ((uchar*) &def_temp)[1]= ((const uchar*) (M))[1];\
  142. ((uchar*) &def_temp)[2]= ((const uchar*) (M))[2];\
  143. ((uchar*) &def_temp)[3]= ((const uchar*) (M))[3];\
  144. ((uchar*) &def_temp)[4]= ((const uchar*) (M))[4];\
  145. ((uchar*) &def_temp)[5]= ((const uchar*) (M))[5];\
  146. ((uchar*) &def_temp)[6]= ((const uchar*) (M))[6];\
  147. ((uchar*) &def_temp)[7]= ((const uchar*) (M))[7]; \
  148. (V)= def_temp; }
  149. #else
  150. #define mi_float4store(T,A) { ((uchar*) (T))[0]= ((const uchar*) &A)[3];\
  151. ((uchar*) (T))[1]= ((const uchar*) &A)[2];\
  152. ((uchar*) (T))[2]= ((const uchar*) &A)[1];\
  153. ((uchar*) (T))[3]= ((const uchar*) &A)[0]; }
  154. #define mi_float4get(V,M) { float def_temp;\
  155. ((uchar*) &def_temp)[0]= ((const uchar*) (M))[3];\
  156. ((uchar*) &def_temp)[1]= ((const uchar*) (M))[2];\
  157. ((uchar*) &def_temp)[2]= ((const uchar*) (M))[1];\
  158. ((uchar*) &def_temp)[3]= ((const uchar*) (M))[0];\
  159. (V)= def_temp; }
  160. #if defined(__FLOAT_WORD_ORDER) && (__FLOAT_WORD_ORDER == __BIG_ENDIAN)
  161. #define mi_float8store(T,V) { ((uchar*) (T))[0]= ((const uchar*) &V)[3];\
  162. ((uchar*) (T))[1]= ((const uchar*) &V)[2];\
  163. ((uchar*) (T))[2]= ((const uchar*) &V)[1];\
  164. ((uchar*) (T))[3]= ((const uchar*) &V)[0];\
  165. ((uchar*) (T))[4]= ((const uchar*) &V)[7];\
  166. ((uchar*) (T))[5]= ((const uchar*) &V)[6];\
  167. ((uchar*) (T))[6]= ((const uchar*) &V)[5];\
  168. ((uchar*) (T))[7]= ((const uchar*) &V)[4];}
  169. #define mi_float8get(V,M) { double def_temp;\
  170. ((uchar*) &def_temp)[0]= ((const uchar*) (M))[3];\
  171. ((uchar*) &def_temp)[1]= ((const uchar*) (M))[2];\
  172. ((uchar*) &def_temp)[2]= ((const uchar*) (M))[1];\
  173. ((uchar*) &def_temp)[3]= ((const uchar*) (M))[0];\
  174. ((uchar*) &def_temp)[4]= ((const uchar*) (M))[7];\
  175. ((uchar*) &def_temp)[5]= ((const uchar*) (M))[6];\
  176. ((uchar*) &def_temp)[6]= ((const uchar*) (M))[5];\
  177. ((uchar*) &def_temp)[7]= ((const uchar*) (M))[4];\
  178. (V)= def_temp; }
  179. #else
  180. #define mi_float8store(T,V) { ((uchar*) (T))[0]= ((const uchar*) &V)[7];\
  181. ((uchar*) (T))[1]= ((const uchar*) &V)[6];\
  182. ((uchar*) (T))[2]= ((const uchar*) &V)[5];\
  183. ((uchar*) (T))[3]= ((const uchar*) &V)[4];\
  184. ((uchar*) (T))[4]= ((const uchar*) &V)[3];\
  185. ((uchar*) (T))[5]= ((const uchar*) &V)[2];\
  186. ((uchar*) (T))[6]= ((const uchar*) &V)[1];\
  187. ((uchar*) (T))[7]= ((const uchar*) &V)[0];}
  188. #define mi_float8get(V,M) { double def_temp;\
  189. ((uchar*) &def_temp)[0]= ((const uchar*) (M))[7];\
  190. ((uchar*) &def_temp)[1]= ((const uchar*) (M))[6];\
  191. ((uchar*) &def_temp)[2]= ((const uchar*) (M))[5];\
  192. ((uchar*) &def_temp)[3]= ((const uchar*) (M))[4];\
  193. ((uchar*) &def_temp)[4]= ((const uchar*) (M))[3];\
  194. ((uchar*) &def_temp)[5]= ((const uchar*) (M))[2];\
  195. ((uchar*) &def_temp)[6]= ((const uchar*) (M))[1];\
  196. ((uchar*) &def_temp)[7]= ((const uchar*) (M))[0];\
  197. (V)= def_temp; }
  198. #endif /* __FLOAT_WORD_ORDER */
  199. #endif /* WORDS_BIGENDIAN */
  200. /* Fix to avoid warnings when sizeof(ha_rows) == sizeof(long) */
  201. #ifdef BIG_TABLES
  202. #define mi_rowstore(T,A) mi_int8store(T, A)
  203. #define mi_rowkorr(T) mi_uint8korr(T)
  204. #else
  205. #define mi_rowstore(T,A) { mi_int4store(T, 0);\
  206. mi_int4store(((uchar*) (T) + 4), A); }
  207. #define mi_rowkorr(T) mi_uint4korr((const uchar*) (T) + 4)
  208. #endif
  209. #if SIZEOF_OFF_T > 4
  210. #define mi_sizestore(T,A) mi_int8store(T, A)
  211. #define mi_sizekorr(T) mi_uint8korr(T)
  212. #else
  213. #define mi_sizestore(T,A) { if ((A) == HA_OFFSET_ERROR)\
  214. bfill((char*) (T), 8, 255);\
  215. else { mi_int4store((T), 0);\
  216. mi_int4store(((T) + 4), A); }}
  217. #define mi_sizekorr(T) mi_uint4korr((const uchar*) (T) + 4)
  218. #endif
  219. #endif /* MYISAMPACK_INCLUDED */