PageRenderTime 49ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/ExternalLibs/HDF5_1.8.6_x64/include/H5Vprivate.h

#
C++ Header | 434 lines | 210 code | 39 blank | 185 comment | 35 complexity | 79a79c726b20cece749fb3b76d54025f MD5 | raw file
  1. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  2. * Copyright by The HDF Group. *
  3. * Copyright by the Board of Trustees of the University of Illinois. *
  4. * All rights reserved. *
  5. * *
  6. * This file is part of HDF5. The full HDF5 copyright notice, including *
  7. * terms governing use, modification, and redistribution, is contained in *
  8. * the files COPYING and Copyright.html. COPYING can be found at the root *
  9. * of the source code distribution tree; Copyright.html can be found at the *
  10. * root level of an installed copy of the electronic HDF5 document set and *
  11. * is linked from the top-level documents page. It can also be found at *
  12. * http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have *
  13. * access to either file, you may request a copy from help@hdfgroup.org. *
  14. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  15. /*
  16. * Programmer: Robb Matzke <matzke@llnl.gov>
  17. * Friday, October 10, 1997
  18. */
  19. #ifndef H5Vprivate_H
  20. #define H5Vprivate_H
  21. /* Private headers needed by this file */
  22. #include "H5private.h" /* Generic Functions */
  23. #include "H5Eprivate.h" /* Error handling */
  24. /* Vector comparison functions like Fortran66 comparison operators */
  25. #define H5V_vector_eq_s(N,V1,V2) (H5V_vector_cmp_s (N, V1, V2)==0)
  26. #define H5V_vector_lt_s(N,V1,V2) (H5V_vector_cmp_s (N, V1, V2)<0)
  27. #define H5V_vector_gt_s(N,V1,V2) (H5V_vector_cmp_s (N, V1, V2)>0)
  28. #define H5V_vector_le_s(N,V1,V2) (H5V_vector_cmp_s (N, V1, V2)<=0)
  29. #define H5V_vector_ge_s(N,V1,V2) (H5V_vector_cmp_s (N, V1, V2)>=0)
  30. #define H5V_vector_eq_u(N,V1,V2) (H5V_vector_cmp_u (N, V1, V2)==0)
  31. #define H5V_vector_lt_u(N,V1,V2) (H5V_vector_cmp_u (N, V1, V2)<0)
  32. #define H5V_vector_gt_u(N,V1,V2) (H5V_vector_cmp_u (N, V1, V2)>0)
  33. #define H5V_vector_le_u(N,V1,V2) (H5V_vector_cmp_u (N, V1, V2)<=0)
  34. #define H5V_vector_ge_u(N,V1,V2) (H5V_vector_cmp_u (N, V1, V2)>=0)
  35. /* Other functions */
  36. #define H5V_vector_cpy(N,DST,SRC) { \
  37. assert (sizeof(*(DST))==sizeof(*(SRC))); \
  38. if (SRC) HDmemcpy (DST, SRC, (N)*sizeof(*(DST))); \
  39. else HDmemset (DST, 0, (N)*sizeof(*(DST))); \
  40. }
  41. #define H5V_vector_zero(N,DST) HDmemset(DST,0,(N)*sizeof(*(DST)))
  42. /* A null pointer is equivalent to a zero vector */
  43. #define H5V_ZERO NULL
  44. H5_DLL hsize_t H5V_hyper_stride(unsigned n, const hsize_t *size,
  45. const hsize_t *total_size,
  46. const hsize_t *offset,
  47. hsize_t *stride);
  48. H5_DLL htri_t H5V_hyper_disjointp(unsigned n, const hsize_t *offset1,
  49. const uint32_t *size1, const hsize_t *offset2, const uint32_t *size2);
  50. H5_DLL htri_t H5V_hyper_eq(unsigned n, const hsize_t *offset1,
  51. const hsize_t *size1, const hsize_t *offset2,
  52. const hsize_t *size2);
  53. H5_DLL herr_t H5V_hyper_fill(unsigned n, const hsize_t *_size,
  54. const hsize_t *total_size,
  55. const hsize_t *offset, void *_dst,
  56. unsigned fill_value);
  57. H5_DLL herr_t H5V_hyper_copy(unsigned n, const hsize_t *size,
  58. const hsize_t *dst_total_size,
  59. const hsize_t *dst_offset, void *_dst,
  60. const hsize_t *src_total_size,
  61. const hsize_t *src_offset, const void *_src);
  62. H5_DLL herr_t H5V_stride_fill(unsigned n, hsize_t elmt_size, const hsize_t *size,
  63. const hsize_t *stride, void *_dst,
  64. unsigned fill_value);
  65. H5_DLL herr_t H5V_stride_copy(unsigned n, hsize_t elmt_size, const hsize_t *_size,
  66. const hsize_t *dst_stride, void *_dst,
  67. const hsize_t *src_stride, const void *_src);
  68. H5_DLL herr_t H5V_stride_copy_s(unsigned n, hsize_t elmt_size, const hsize_t *_size,
  69. const hssize_t *dst_stride, void *_dst,
  70. const hssize_t *src_stride, const void *_src);
  71. H5_DLL herr_t H5V_array_fill(void *_dst, const void *src, size_t size,
  72. size_t count);
  73. H5_DLL herr_t H5V_array_down(unsigned n, const hsize_t *total_size,
  74. hsize_t *down);
  75. H5_DLL hsize_t H5V_array_offset_pre(unsigned n,
  76. const hsize_t *acc, const hsize_t *offset);
  77. H5_DLL hsize_t H5V_array_offset(unsigned n, const hsize_t *total_size,
  78. const hsize_t *offset);
  79. H5_DLL herr_t H5V_array_calc_pre(hsize_t offset, unsigned n, const hsize_t *total_size,
  80. const hsize_t *down, hsize_t *coords);
  81. H5_DLL herr_t H5V_array_calc(hsize_t offset, unsigned n,
  82. const hsize_t *total_size, hsize_t *coords);
  83. H5_DLL herr_t H5V_chunk_index(unsigned ndims, const hsize_t *coord,
  84. const uint32_t *chunk, const hsize_t *down_nchunks, hsize_t *chunk_idx);
  85. H5_DLL ssize_t H5V_memcpyvv(void *_dst,
  86. size_t dst_max_nseq, size_t *dst_curr_seq, size_t dst_len_arr[], hsize_t dst_off_arr[],
  87. const void *_src,
  88. size_t src_max_nseq, size_t *src_curr_seq, size_t src_len_arr[], hsize_t src_off_arr[]);
  89. /*-------------------------------------------------------------------------
  90. * Function: H5V_vector_reduce_product
  91. *
  92. * Purpose: Product reduction of a vector. Vector elements and return
  93. * value are size_t because we usually want the number of
  94. * elements in an array and array dimensions are always of type
  95. * size_t.
  96. *
  97. * Return: Success: Product of elements
  98. *
  99. * Failure: 1 if N is zero
  100. *
  101. * Programmer: Robb Matzke
  102. * Friday, October 10, 1997
  103. *
  104. * Modifications:
  105. *
  106. *-------------------------------------------------------------------------
  107. */
  108. static H5_inline hsize_t UNUSED
  109. H5V_vector_reduce_product(unsigned n, const hsize_t *v)
  110. {
  111. hsize_t ret_value = 1;
  112. /* Use FUNC_ENTER_NOAPI_NOINIT_NOFUNC here to avoid performance issues */
  113. FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5V_vector_reduce_product)
  114. if (n && !v) HGOTO_DONE(0)
  115. while (n--) ret_value *= *v++;
  116. done:
  117. FUNC_LEAVE_NOAPI(ret_value)
  118. }
  119. /*-------------------------------------------------------------------------
  120. * Function: H5V_vector_zerop_u
  121. *
  122. * Purpose: Determines if all elements of a vector are zero.
  123. *
  124. * Return: Success: TRUE if all elements are zero,
  125. * FALSE otherwise
  126. *
  127. * Failure: TRUE if N is zero
  128. *
  129. * Programmer: Robb Matzke
  130. * Friday, October 10, 1997
  131. *
  132. * Modifications:
  133. *
  134. *-------------------------------------------------------------------------
  135. */
  136. static H5_inline htri_t UNUSED
  137. H5V_vector_zerop_u(int n, const hsize_t *v)
  138. {
  139. htri_t ret_value=TRUE; /* Return value */
  140. /* Use FUNC_ENTER_NOAPI_NOINIT_NOFUNC here to avoid performance issues */
  141. FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5V_vector_zerop_u)
  142. if (!v)
  143. HGOTO_DONE(TRUE)
  144. while (n--)
  145. if (*v++)
  146. HGOTO_DONE(FALSE)
  147. done:
  148. FUNC_LEAVE_NOAPI(ret_value)
  149. }
  150. /*-------------------------------------------------------------------------
  151. * Function: H5V_vector_zerop_s
  152. *
  153. * Purpose: Determines if all elements of a vector are zero.
  154. *
  155. * Return: Success: TRUE if all elements are zero,
  156. * FALSE otherwise
  157. *
  158. * Failure: TRUE if N is zero
  159. *
  160. * Programmer: Robb Matzke
  161. * Friday, October 10, 1997
  162. *
  163. * Modifications:
  164. *
  165. *-------------------------------------------------------------------------
  166. */
  167. static H5_inline htri_t UNUSED
  168. H5V_vector_zerop_s(int n, const hssize_t *v)
  169. {
  170. htri_t ret_value=TRUE; /* Return value */
  171. /* Use FUNC_ENTER_NOAPI_NOINIT_NOFUNC here to avoid performance issues */
  172. FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5V_vector_zerop_s)
  173. if (!v)
  174. HGOTO_DONE(TRUE)
  175. while (n--)
  176. if (*v++)
  177. HGOTO_DONE(FALSE)
  178. done:
  179. FUNC_LEAVE_NOAPI(ret_value)
  180. }
  181. /*-------------------------------------------------------------------------
  182. * Function: H5V_vector_cmp_u
  183. *
  184. * Purpose: Compares two vectors of the same size and determines if V1 is
  185. * lexicographically less than, equal, or greater than V2.
  186. *
  187. * Return: Success: -1 if V1 is less than V2
  188. * 0 if they are equal
  189. * 1 if V1 is greater than V2
  190. *
  191. * Failure: 0 if N is zero
  192. *
  193. * Programmer: Robb Matzke
  194. * Friday, October 10, 1997
  195. *
  196. * Modifications:
  197. *
  198. *-------------------------------------------------------------------------
  199. */
  200. static H5_inline int UNUSED
  201. H5V_vector_cmp_u (unsigned n, const hsize_t *v1, const hsize_t *v2)
  202. {
  203. int ret_value=0; /* Return value */
  204. /* Use FUNC_ENTER_NOAPI_NOINIT_NOFUNC here to avoid performance issues */
  205. FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5V_vector_cmp_u)
  206. if (v1 == v2) HGOTO_DONE(0)
  207. if (v1 == NULL) HGOTO_DONE(-1)
  208. if (v2 == NULL) HGOTO_DONE(1)
  209. while (n--) {
  210. if (*v1 < *v2) HGOTO_DONE(-1)
  211. if (*v1 > *v2) HGOTO_DONE(1)
  212. v1++;
  213. v2++;
  214. }
  215. done:
  216. FUNC_LEAVE_NOAPI(ret_value)
  217. }
  218. /*-------------------------------------------------------------------------
  219. * Function: H5V_vector_cmp_s
  220. *
  221. * Purpose: Compares two vectors of the same size and determines if V1 is
  222. * lexicographically less than, equal, or greater than V2.
  223. *
  224. * Return: Success: -1 if V1 is less than V2
  225. * 0 if they are equal
  226. * 1 if V1 is greater than V2
  227. *
  228. * Failure: 0 if N is zero
  229. *
  230. * Programmer: Robb Matzke
  231. * Wednesday, April 8, 1998
  232. *
  233. * Modifications:
  234. *
  235. *-------------------------------------------------------------------------
  236. */
  237. static H5_inline int UNUSED
  238. H5V_vector_cmp_s (unsigned n, const hssize_t *v1, const hssize_t *v2)
  239. {
  240. int ret_value=0; /* Return value */
  241. /* Use FUNC_ENTER_NOAPI_NOINIT_NOFUNC here to avoid performance issues */
  242. FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5V_vector_cmp_s)
  243. if (v1 == v2) HGOTO_DONE(0)
  244. if (v1 == NULL) HGOTO_DONE(-1)
  245. if (v2 == NULL) HGOTO_DONE(1)
  246. while (n--) {
  247. if (*v1 < *v2) HGOTO_DONE(-1)
  248. if (*v1 > *v2) HGOTO_DONE(1)
  249. v1++;
  250. v2++;
  251. }
  252. done:
  253. FUNC_LEAVE_NOAPI(ret_value)
  254. }
  255. /*-------------------------------------------------------------------------
  256. * Function: H5V_vector_inc
  257. *
  258. * Purpose: Increments V1 by V2
  259. *
  260. * Return: void
  261. *
  262. * Programmer: Robb Matzke
  263. * Monday, October 13, 1997
  264. *
  265. * Modifications:
  266. *
  267. *-------------------------------------------------------------------------
  268. */
  269. static H5_inline void UNUSED
  270. H5V_vector_inc(int n, hsize_t *v1, const hsize_t *v2)
  271. {
  272. while (n--) *v1++ += *v2++;
  273. }
  274. /* Lookup table for general log2(n) routine */
  275. static const unsigned char LogTable256[] =
  276. {
  277. 0, 0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3,
  278. 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
  279. 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
  280. 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
  281. 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
  282. 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
  283. 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
  284. 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
  285. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  286. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  287. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  288. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  289. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  290. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  291. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  292. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7
  293. };
  294. /*-------------------------------------------------------------------------
  295. * Function: H5V_log2_gen
  296. *
  297. * Purpose: Determines the log base two of a number (i.e. log2(n)).
  298. * (i.e. the highest bit set in a number)
  299. *
  300. * Note: This is from the "Bit Twiddling Hacks" at:
  301. * http://graphics.stanford.edu/~seander/bithacks.html#IntegerLogLookup
  302. *
  303. * The version on the web-site is for 32-bit quantities and this
  304. * version has been extended for 64-bit quantities.
  305. *
  306. * Return: log2(n) (always - no failure condition)
  307. *
  308. * Programmer: Quincey Koziol
  309. * Monday, March 6, 2006
  310. *
  311. *-------------------------------------------------------------------------
  312. */
  313. static H5_inline unsigned UNUSED
  314. H5V_log2_gen(uint64_t n)
  315. {
  316. unsigned r; /* r will be log2(n) */
  317. register unsigned int t, tt, ttt; /* temporaries */
  318. #ifdef H5_BAD_LOG2_CODE_GENERATED
  319. if(n > (uint64_t)0x7fffffffffffffff)
  320. r = 63;
  321. else {
  322. n &= (uint64_t)0x7fffffffffffffff;
  323. #endif /* H5_BAD_LOG2_CODE_GENERATED */
  324. if((ttt = (unsigned)(n >> 32)))
  325. if((tt = (unsigned)(n >> 48)))
  326. r = (t = (unsigned)(n >> 56)) ? 56 + (unsigned)LogTable256[t] : 48 + (unsigned)LogTable256[tt & 0xFF];
  327. else
  328. r = (t = (unsigned)(n >> 40)) ? 40 + (unsigned)LogTable256[t] : 32 + (unsigned)LogTable256[ttt & 0xFF];
  329. else
  330. if((tt = (unsigned)(n >> 16)))
  331. r = (t = (unsigned)(n >> 24)) ? 24 + (unsigned)LogTable256[t] : 16 + (unsigned)LogTable256[tt & 0xFF];
  332. else
  333. /* Added 'uint8_t' cast to pacify PGCC compiler */
  334. r = (t = (unsigned)(n >> 8)) ? 8 + (unsigned)LogTable256[t] : (unsigned)LogTable256[(uint8_t)n];
  335. #ifdef H5_BAD_LOG2_CODE_GENERATED
  336. } /* end else */
  337. #endif /* H5_BAD_LOG2_CODE_GENERATED */
  338. return(r);
  339. } /* H5V_log2_gen() */
  340. /* Lookup table for specialized log2(n) of power of two routine */
  341. static const unsigned MultiplyDeBruijnBitPosition[32] =
  342. {
  343. 0, 1, 28, 2, 29, 14, 24, 3, 30, 22, 20, 15, 25, 17, 4, 8,
  344. 31, 27, 13, 23, 21, 19, 16, 7, 26, 12, 18, 6, 11, 5, 10, 9
  345. };
  346. /*-------------------------------------------------------------------------
  347. * Function: H5V_log2_of2
  348. *
  349. * Purpose: Determines the log base two of a number (i.e. log2(n)).
  350. * (i.e. the highest bit set in a number)
  351. *
  352. * Note: **N must be a power of two** and is limited to 32-bit quantities.
  353. *
  354. * This is from the "Bit Twiddling Hacks" at:
  355. * http://graphics.stanford.edu/~seander/bithacks.html#IntegerLogDeBruijn
  356. *
  357. * Return: log2(n) (always - no failure condition)
  358. *
  359. * Programmer: Quincey Koziol
  360. * Monday, Febraury 27, 2006
  361. *
  362. *-------------------------------------------------------------------------
  363. */
  364. static H5_inline unsigned UNUSED
  365. H5V_log2_of2(uint32_t n)
  366. {
  367. #ifndef NDEBUG
  368. HDassert(POWER_OF_TWO(n));
  369. #endif /* NDEBUG */
  370. return(MultiplyDeBruijnBitPosition[(n * (uint32_t)0x077CB531UL) >> 27]);
  371. } /* H5V_log2_of2() */
  372. /*-------------------------------------------------------------------------
  373. * Function: H5V_limit_enc_size
  374. *
  375. * Purpose: Determine the # of bytes needed to encode values within a
  376. * range from 0 to a given limit
  377. *
  378. * Return: Number of bytes needed
  379. *
  380. * Programmer: Quincey Koziol
  381. * Thursday, March 13, 2008
  382. *
  383. *-------------------------------------------------------------------------
  384. */
  385. static H5_inline unsigned UNUSED
  386. H5V_limit_enc_size(uint64_t limit)
  387. {
  388. return (H5V_log2_gen(limit) / 8) + 1;
  389. } /* end H5V_limit_enc_size() */
  390. #endif /* H5Vprivate_H */