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 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_s *htbl, uint32_t key)
  23. {
  24. unsigned currentbit;
  25. unsigned keysize = 32;
  26. starpu_htbl32_node_t *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_s **htbl, uint32_t key, void *entry)
  52. {
  53. unsigned currentbit;
  54. unsigned keysize = 32;
  55. starpu_htbl32_node_t **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. /* TODO pad to change that 1 into 16 ? */
  63. *current_htbl_ptr = (starpu_htbl32_node_t*)calloc(sizeof(starpu_htbl32_node_t), 1);
  64. assert(*current_htbl_ptr);
  65. }
  66. /* 0000000000001111
  67. * | currentbit
  68. * 0000111100000000 = offloaded_mask
  69. * |last_currentbit
  70. * */
  71. unsigned last_currentbit =
  72. keysize - (currentbit + STARPU_HTBL32_NODE_SIZE);
  73. uint32_t offloaded_mask = mask << last_currentbit;
  74. unsigned current_index =
  75. (key & (offloaded_mask)) >> (last_currentbit);
  76. current_htbl_ptr =
  77. &((*current_htbl_ptr)->children[current_index]);
  78. }
  79. /* current_htbl either contains NULL or a previous entry
  80. * we overwrite it anyway */
  81. void *old_entry = *current_htbl_ptr;
  82. *current_htbl_ptr = (starpu_htbl32_node_t *) entry;
  83. return old_entry;
  84. }