PandA-2024.02
perfecthash.c
Go to the documentation of this file.
1 #define ARRAY_SIZE 24000
2 #define NUM_ACCELS 6
3 #define OPS_PER_ACCEL ARRAY_SIZE/NUM_ACCELS
4 
5 typedef unsigned long int ub4; /* unsigned 4-byte quantities */
6 typedef unsigned short int ub2;
7 typedef unsigned char ub1;
8 
9 #include <stdio.h>
10 #include "perfecthash.h"
11 
12 
14 {
15  ub4 a, b, rsl;
16 
17  b = (val >> 5) & 0x1fff;
18  a = ((val << 22) >> 19);
19  rsl = (a^scramble[tab[b]]);
20  return rsl;
21 }
22 
23 int perfect_hash (int *key_input, int *table, ub2 *scramble, ub1 *tab, int max_idx) {
24  int i, hash;
25  int result=0;
26 
27  for (i=0; i<max_idx; i++) {
28  hash=phash(key_input[i], scramble, tab);
29  result +=(table[hash] == key_input[i]);
30  }
31 
32  return result;
33 }
34 
36 
37 int main() {
38 
39  int i, main_result = 0;
40 
41  #pragma omp parallel for num_threads(NUM_ACCELS) private(i)
42  for (i=0; i<NUM_ACCELS; i++) {
44  }
45 
46  //combine results
47  for (i=0; i<NUM_ACCELS; i++) {
48  main_result += result[i];
49  }
50 
51  //check final result
52  printf ("Result: %d\n", main_result);
53  if (main_result == 24000) {
54  printf("RESULT: PASS\n");
55  } else {
56  printf("RESULT: FAIL\n");
57  }
58 }
int result[NUM_ACCELS]
Definition: perfecthash.c:35
#define NUM_ACCELS
Definition: perfecthash.c:2
ub1 tab[]
unsigned short int ub2
Definition: perfecthash.c:6
unsigned char ub1
Definition: perfecthash.c:7
int main_result
Definition: mips.c:38
int key[32]
Definition: aes.h:67
ub4 phash(ub4 val, ub2 *scramble, ub1 *tab)
Definition: perfecthash.c:13
int hash_table[ARRAY_SIZE]
Definition: perfecthash.h:1
#define OPS_PER_ACCEL
Definition: perfecthash.c:3
unsigned long int ub4
Definition: perfecthash.c:5
int perfect_hash(int *key_input, int *table, ub2 *scramble, ub1 *tab, int max_idx)
Definition: perfecthash.c:23
ub2 scramble[]
int main()
Definition: perfecthash.c:37

Generated on Mon Feb 12 2024 13:02:50 for PandA-2024.02 by doxygen 1.8.13