htable32.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2009, 2010 Université de Bordeaux 1
  4. * Copyright (C) 2010, 2011 Centre National de la Recherche Scientifique
  5. *
  6. * StarPU is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU Lesser General Public License as published by
  8. * the Free Software Foundation; either version 2.1 of the License, or (at
  9. * your option) any later version.
  10. *
  11. * StarPU is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  14. *
  15. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  16. */
  17. #include <starpu.h>
  18. #include <common/config.h>
  19. #include <common/htable32.h>
  20. #include <stdint.h>
  21. #include <string.h>
  22. void *_starpu_htbl_search_32(struct starpu_htbl32_node *htbl, uint32_t key)
  23. {
  24. unsigned currentbit;
  25. unsigned keysize = 32;
  26. struct starpu_htbl32_node *current_htbl = htbl;
  27. /* 000000000001111 with HTBL_NODE_SIZE 1's */
  28. uint32_t mask = (1<<_STARPU_HTBL32_NODE_SIZE)-1;
  29. for(currentbit = 0; currentbit < keysize; currentbit+=_STARPU_HTBL32_NODE_SIZE)
  30. {
  31. // printf("search : current bit = %d \n", currentbit);
  32. if (STARPU_UNLIKELY(current_htbl == NULL))
  33. return NULL;
  34. /* 0000000000001111
  35. * | currentbit
  36. * 0000111100000000 = offloaded_mask
  37. * |last_currentbit
  38. * */
  39. unsigned last_currentbit =
  40. keysize - (currentbit + _STARPU_HTBL32_NODE_SIZE);
  41. uint32_t offloaded_mask = mask << last_currentbit;
  42. unsigned current_index =
  43. (key & (offloaded_mask)) >> (last_currentbit);
  44. current_htbl = current_htbl->children[current_index];
  45. }
  46. return current_htbl;
  47. }
  48. /*
  49. * returns the previous value of the tag, or NULL else
  50. */
  51. void *_starpu_htbl_insert_32(struct starpu_htbl32_node **htbl, uint32_t key, void *entry)
  52. {
  53. unsigned currentbit;
  54. unsigned keysize = 32;
  55. struct starpu_htbl32_node **current_htbl_ptr = htbl;
  56. /* 000000000001111 with HTBL_NODE_SIZE 1's */
  57. uint32_t mask = (1<<_STARPU_HTBL32_NODE_SIZE)-1;
  58. for(currentbit = 0; currentbit < keysize; currentbit+=_STARPU_HTBL32_NODE_SIZE)
  59. {
  60. //printf("insert : current bit = %d \n", currentbit);
  61. if (*current_htbl_ptr == NULL)
  62. {
  63. /* TODO pad to change that 1 into 16 ? */
  64. *current_htbl_ptr = (struct starpu_htbl32_node*)calloc(sizeof(struct starpu_htbl32_node), 1);
  65. STARPU_ASSERT(*current_htbl_ptr);
  66. }
  67. /* 0000000000001111
  68. * | currentbit
  69. * 0000111100000000 = offloaded_mask
  70. * |last_currentbit
  71. * */
  72. unsigned last_currentbit =
  73. keysize - (currentbit + _STARPU_HTBL32_NODE_SIZE);
  74. uint32_t offloaded_mask = mask << last_currentbit;
  75. unsigned current_index =
  76. (key & (offloaded_mask)) >> (last_currentbit);
  77. current_htbl_ptr =
  78. &((*current_htbl_ptr)->children[current_index]);
  79. }
  80. /* current_htbl either contains NULL or a previous entry
  81. * we overwrite it anyway */
  82. void *old_entry = *current_htbl_ptr;
  83. *current_htbl_ptr = (struct starpu_htbl32_node *) entry;
  84. return old_entry;
  85. }