Statistics
| Branch: | Tag: | Revision:

root / volk / lib / volk_rank_archs.c @ ccfac187

History | View | Annotate | Download (1.3 kB)

1
#include <volk_rank_archs.h>
2
#include <volk/volk_prefs.h>
3
#include <stdio.h>
4
#include <stdlib.h>
5
#include <string.h>
6
7
unsigned int get_index(const char *indices[], unsigned int n_archs, const char *arch_name) {
8
    unsigned int i;
9
    for(i=0; i<n_archs; i++) {
10
        if(!strncmp(indices[i], arch_name, 20)) {
11
            return i;
12
        }
13
    }
14
    //something terrible should happen here
15
    printf("Volk warning: no arch found, returning generic impl\n");
16
    return get_index(indices, n_archs, "generic"); //but we'll fake it for now
17
}
18
19
unsigned int volk_rank_archs(const char *indices[], const int* arch_defs, unsigned int n_archs, const char* name, unsigned int arch) {
20
  unsigned int i;
21
  unsigned int best_val = 0;
22
  static struct volk_arch_pref *volk_arch_prefs;
23
  static unsigned int n_arch_prefs = 0;
24
  static int prefs_loaded = 0;
25
  if(!prefs_loaded) {
26
      n_arch_prefs = load_preferences(&volk_arch_prefs);
27
      prefs_loaded = 1;
28
  }
29
  
30
  //now look for the function name in the prefs list
31
  for(i=0; i < n_arch_prefs; i++) {
32
      if(!strncmp(name, volk_arch_prefs[i].name, 128)) { //found it
33
        return get_index(indices, n_archs, volk_arch_prefs[i].arch);
34
      }
35
  }
36
  
37
  for(i=1; i < n_archs; ++i) {
38
    if((arch_defs[i]&(!arch)) == 0) {
39
      best_val = (arch_defs[i] > arch_defs[best_val + 1]) ? i-1 : best_val;
40
    }
41
  }
42
  return best_val;
43
}