register_set_pair.cc 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <stdint.h>
  4. #include <string.h>
  5. #include "vtv_utils.h"
  6. #include "vtv_rts.h"
  7. /* This configuration will test mostly inserting of elements that are already inserted since
  8. the number of repeats is 200 */
  9. #define NUM_MAPS 4000
  10. #define ELEMENTS_PER_MAP 100
  11. #define NUM_REPEATS 200
  12. #define KEY_TYPE_FIXED_SIZE 8
  13. void *key_buffer = malloc (17);
  14. typedef char * name_string;
  15. name_string fake_names[NUM_MAPS];
  16. /* This variable has to be put in rel.ro */
  17. void * maps[NUM_MAPS] VTV_PROTECTED_VAR;
  18. struct fake_vt {
  19. void * fake_vfp [4];
  20. };
  21. void * fake_vts [NUM_MAPS * ELEMENTS_PER_MAP];
  22. void
  23. generate_names (void)
  24. {
  25. int i;
  26. for (i = 0; i < NUM_MAPS; ++i)
  27. {
  28. fake_names[i] = (char *) malloc (9 * sizeof (char));
  29. snprintf (fake_names[i], 9, "name%d", i);
  30. }
  31. }
  32. static uint32_t
  33. vtv_string_hash(const char *in)
  34. {
  35. const char *s = in;
  36. uint32_t h = 0;
  37. for ( ; *s; ++s)
  38. h = 5 * h + *s;
  39. return h;
  40. }
  41. int main()
  42. {
  43. __VLTChangePermission(__VLTP_READ_WRITE);
  44. generate_names ();
  45. for (int k = 0; k < NUM_REPEATS; k++)
  46. {
  47. int curr_fake_vt = 0;
  48. for (int i = 0; i < NUM_MAPS; i++)
  49. {
  50. uint32_t *value_ptr = (uint32_t *) key_buffer;
  51. uint32_t len1 = strlen (fake_names[i]);
  52. uint32_t hash_value = vtv_string_hash (fake_names[i]);
  53. void *temp_array[ELEMENTS_PER_MAP];
  54. *value_ptr = len1;
  55. value_ptr++;
  56. *value_ptr = hash_value;
  57. memcpy ((char *) key_buffer + KEY_TYPE_FIXED_SIZE, fake_names[i],
  58. len1);
  59. #ifdef VTV_DEBUG
  60. __VLTRegisterPairDebug (&maps[i], (char *) key_buffer, 128,
  61. &fake_vts[curr_fake_vt], "", "");
  62. #else
  63. __VLTRegisterPair (&maps[i], (char *) key_buffer, 128,
  64. &fake_vts[curr_fake_vt]);
  65. #endif
  66. for (int j = 0; j < ELEMENTS_PER_MAP; j++)
  67. {
  68. temp_array[j] = &fake_vts[curr_fake_vt];
  69. curr_fake_vt++;
  70. }
  71. #ifdef VTV_DEBUG
  72. __VLTRegisterSetDebug (&maps[i], (char *) key_buffer, 128, 100,
  73. (void **) &temp_array);
  74. #else
  75. __VLTRegisterSet (&maps[i], (char *) key_buffer, 128, 100,
  76. (void **) &temp_array);
  77. #endif
  78. }
  79. }
  80. __VLTChangePermission(__VLTP_READ_ONLY);
  81. return 0;
  82. }