GCC Code Coverage Report


Directory: ./
File: lib/volk_rank_archs.c
Date: 2023-10-23 23:10:04
Exec Total Coverage
Lines: 26 34 76.5%
Functions: 2 2 100.0%
Branches: 20 28 71.4%

Line Branch Exec Source
1 /* -*- c++ -*- */
2 /*
3 * Copyright 2011-2012 Free Software Foundation, Inc.
4 *
5 * This file is part of VOLK
6 *
7 * SPDX-License-Identifier: LGPL-3.0-or-later
8 */
9
10
11 #include <stdio.h>
12 #include <stdlib.h>
13 #include <string.h>
14
15 #include <volk/volk_prefs.h>
16 #include <volk_rank_archs.h>
17
18 1334 int volk_get_index(const char* impl_names[], // list of implementations by name
19 const size_t n_impls, // number of implementations available
20 const char* impl_name // the implementation name to find
21 )
22 {
23 unsigned int i;
24
1/2
✓ Branch 0 taken 4832 times.
✗ Branch 1 not taken.
4832 for (i = 0; i < n_impls; i++) {
25
2/2
✓ Branch 0 taken 1334 times.
✓ Branch 1 taken 3498 times.
4832 if (!strncmp(impl_names[i], impl_name, 20)) {
26 1334 return i;
27 }
28 }
29 // TODO return -1;
30 // something terrible should happen here
31 fprintf(stderr, "Volk warning: no arch found, returning generic impl\n");
32 return volk_get_index(impl_names, n_impls, "generic"); // but we'll fake it for now
33 }
34
35 16 int volk_rank_archs(const char* kern_name, // name of the kernel to rank
36 const char* impl_names[], // list of implementations by name
37 const int* impl_deps, // requirement mask per implementation
38 const bool* alignment, // alignment status of each implementation
39 size_t n_impls, // number of implementations available
40 const bool align // if false, filter aligned implementations
41 )
42 {
43 size_t i;
44 static volk_arch_pref_t* volk_arch_prefs;
45 static size_t n_arch_prefs = 0;
46 static int prefs_loaded = 0;
47
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 12 times.
16 if (!prefs_loaded) {
48 4 n_arch_prefs = volk_load_preferences(&volk_arch_prefs);
49 4 prefs_loaded = 1;
50 }
51
52 // If we've defined VOLK_GENERIC to be anything, always return the
53 // 'generic' kernel. Used in GR's QA code.
54 16 char* gen_env = getenv("VOLK_GENERIC");
55
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
16 if (gen_env) {
56 return volk_get_index(impl_names, n_impls, "generic");
57 }
58
59 // now look for the function name in the prefs list
60
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
16 for (i = 0; i < n_arch_prefs; i++) {
61 if (!strncmp(kern_name,
62 volk_arch_prefs[i].name,
63 sizeof(volk_arch_prefs[i].name))) // found it
64 {
65 const char* impl_name =
66 align ? volk_arch_prefs[i].impl_a : volk_arch_prefs[i].impl_u;
67 return volk_get_index(impl_names, n_impls, impl_name);
68 }
69 }
70
71 // return the best index with the largest deps
72 16 size_t best_index_a = 0;
73 16 size_t best_index_u = 0;
74 16 int best_value_a = -1;
75 16 int best_value_u = -1;
76
2/2
✓ Branch 0 taken 100 times.
✓ Branch 1 taken 16 times.
116 for (i = 0; i < n_impls; i++) {
77 100 const signed val = impl_deps[i];
78
4/4
✓ Branch 0 taken 44 times.
✓ Branch 1 taken 56 times.
✓ Branch 2 taken 20 times.
✓ Branch 3 taken 24 times.
100 if (alignment[i] && val > best_value_a) {
79 20 best_index_a = i;
80 20 best_value_a = val;
81 }
82
4/4
✓ Branch 0 taken 56 times.
✓ Branch 1 taken 44 times.
✓ Branch 2 taken 28 times.
✓ Branch 3 taken 28 times.
100 if (!alignment[i] && val > best_value_u) {
83 28 best_index_u = i;
84 28 best_value_u = val;
85 }
86 }
87
88 // when align and we found a best aligned, use it
89
3/4
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 8 times.
✓ Branch 2 taken 8 times.
✗ Branch 3 not taken.
16 if (align && best_value_a != -1)
90 8 return best_index_a;
91
92 // otherwise return the best unaligned
93 8 return best_index_u;
94 }
95