diff --git a/lib/volk_rank_archs.c b/lib/volk_rank_archs.c index 58bbbc653..6eb4a98e6 100644 --- a/lib/volk_rank_archs.c +++ b/lib/volk_rank_archs.c @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2011-2012 Free Software Foundation, Inc. + * Copyright 2011-2012, 2021 Free Software Foundation, Inc. * * This file is part of VOLK * @@ -15,21 +15,43 @@ #include #include -int volk_get_index(const char* impl_names[], // list of implementations by name - const size_t n_impls, // number of implementations available - const char* impl_name // the implementation name to find -) +// This function is supposed to be private to this compilation unit. +int volk_search_index(const char* impl_names[], + const size_t n_impls, + const char* impl_name) { unsigned int i; for (i = 0; i < n_impls; i++) { - if (!strncmp(impl_names[i], impl_name, 20)) { + if (!strncmp(impl_names[i], impl_name, 42)) { return i; } } - // TODO return -1; - // something terrible should happen here - fprintf(stderr, "Volk warning: no arch found, returning generic impl\n"); - return volk_get_index(impl_names, n_impls, "generic"); // but we'll fake it for now + return -1; // Indicate we couldn't find anything! +} + +int volk_get_index(const char* impl_names[], // list of implementations by name + const size_t n_impls, // number of implementations available + const char* impl_name // the implementation name to find +) +{ + /* + * We follow a 3 step process. + * 1. Search for the requested impl. Return index if found. + * 2. Search for the generic impl. Return as fail-safe. + * 3. Return -1 to indicate an error. Caller needs to handle this case. + */ + int idx = volk_search_index(impl_names, n_impls, impl_name); + if (idx >= 0) { + return idx; + } + + idx = volk_search_index(impl_names, n_impls, "generic"); + if (idx >= 0) { + fprintf(stderr, "Volk warning: no arch found, returning generic impl\n"); + } else { + fprintf(stderr, "Volk ERROR: no arch found. generic impl missing!\n"); + } + return idx; } int volk_rank_archs(const char* kern_name, // name of the kernel to rank