diff options
Diffstat (limited to 'volk')
-rw-r--r-- | volk/lib/qa_utils.cc | 94 | ||||
-rw-r--r-- | volk/lib/qa_utils.h | 2 | ||||
-rw-r--r-- | volk/orc/volk_32f_normalize_aligned16_orc_impl.orc | 5 | ||||
-rw-r--r-- | volk/orc/volk_32fc_32f_multiply_aligned16_orc_impl.orc | 7 | ||||
-rw-r--r-- | volk/orc/volk_32fc_multiply_aligned16_orc_impl.orc | 6 | ||||
-rw-r--r-- | volk/orc/volk_8s_convert_16s_aligned16_orc_impl.orc | 3 |
6 files changed, 97 insertions, 20 deletions
diff --git a/volk/lib/qa_utils.cc b/volk/lib/qa_utils.cc index 4d93ca62a..fa21db487 100644 --- a/volk/lib/qa_utils.cc +++ b/volk/lib/qa_utils.cc @@ -3,7 +3,7 @@ #include <boost/foreach.hpp> #include <boost/assign/list_of.hpp> #include <boost/tokenizer.hpp> -#include <boost/test/unit_test.hpp> +//#include <boost/test/unit_test.hpp> #include <iostream> #include <vector> #include <time.h> @@ -13,19 +13,39 @@ #include <volk/volk.h> #include <boost/typeof/typeof.hpp> #include <boost/type_traits.hpp> -//#include <boost/test/unit_test.hpp> float uniform() { return 2.0 * ((float) rand() / RAND_MAX - 0.5); // uniformly (-1, 1) } -void -random_floats (float *buf, unsigned n) +void random_floats (float *buf, unsigned n) { for (unsigned i = 0; i < n; i++) buf[i] = uniform (); } +void load_random_data(void *data, std::string sig, unsigned int n) { + if(sig == "32fc") { + random_floats((float *)data, n*2); + } else if(sig == "32f") { + random_floats((float *)data, n); + } else if(sig == "32u") { + for(int i=0; i<n; i++) ((uint32_t *)data)[i] = (uint32_t) ((rand() - (RAND_MAX/2)) / (RAND_MAX/2)); + } else if(sig == "32s") { + for(int i=0; i<n; i++) ((int32_t *)data)[i] = ((int32_t) (rand() - (RAND_MAX/2))); + } else if(sig == "16u") { + for(int i=0; i<n; i++) ((uint16_t *)data)[i] = (uint16_t) ((rand() - (RAND_MAX/2)) / (RAND_MAX/2)); + } else if(sig == "16s") { + for(int i=0; i<n; i++) ((int16_t *)data)[i] = ((int16_t)((((float) (rand() - (RAND_MAX/2))) / static_cast<float>((RAND_MAX/2))) * 32768.0)); + } else if(sig == "16sc") { + for(int i=0; i<n*2; i++) ((int16_t *)data)[i] = ((int16_t)((((float) (rand() - (RAND_MAX/2))) / static_cast<float>((RAND_MAX/2))) * 32768.0)); + } else if(sig == "8u") { + for(int i=0; i<n; i++) ((uint8_t *)data)[i] = ((uint8_t)(((float) (rand() - (RAND_MAX/2))) / static_cast<float>((RAND_MAX/2)) * 256.0)); + } else if(sig == "8s") { + for(int i=0; i<n; i++) ((int8_t *)data)[i] = ((int8_t)(((float) (rand() - (RAND_MAX/2))) / static_cast<float>((RAND_MAX/2)) * 128.0)); + } else std::cout << "load_random_data(): Invalid sig: " << sig << std::endl; +} + template <class t> t *make_aligned_buffer(unsigned int len) { t *buf; @@ -37,11 +57,11 @@ t *make_aligned_buffer(unsigned int len) { void make_buffer_for_signature(std::vector<void *> &buffs, std::vector<std::string> inputsig, unsigned int vlen) { BOOST_FOREACH(std::string sig, inputsig) { - if (sig=="32fc" || sig=="64f") buffs.push_back((void *) make_aligned_buffer<lv_32fc_t>(vlen)); - else if(sig=="32f" || sig=="32u" || sig=="32s" || sig=="16sc") buffs.push_back((void *) make_aligned_buffer<float>(vlen)); - else if(sig=="16s" || sig=="16u") buffs.push_back((void *) make_aligned_buffer<int16_t>(vlen)); - else if(sig=="8s" || sig=="8u") buffs.push_back((void *) make_aligned_buffer<int8_t>(vlen)); - else std::cout << "Invalid type!" << std::endl; + if (sig=="32fc" || sig=="64f" || sig=="64u") buffs.push_back((void *) make_aligned_buffer<uint64_t>(vlen)); + else if(sig=="32f" || sig=="32u" || sig=="32s" || sig=="16sc") buffs.push_back((void *) make_aligned_buffer<uint32_t>(vlen)); + else if(sig=="16s" || sig=="16u" || sig=="8sc") buffs.push_back((void *) make_aligned_buffer<uint16_t>(vlen)); + else if(sig=="8s" || sig=="8u") buffs.push_back((void *) make_aligned_buffer<uint8_t>(vlen)); + else std::cout << "Invalid type: " << sig << std::endl; } } @@ -90,7 +110,7 @@ static std::vector<std::string> get_arch_list(const int archs[]) { } static bool is_valid_type(std::string type) { - std::vector<std::string> valid_types = boost::assign::list_of("32fc")("32f")("32s")("32u")("16sc")("16s")("16u")("8s")("8u"); + std::vector<std::string> valid_types = boost::assign::list_of("64f")("64u")("32fc")("32f")("32s")("32u")("16sc")("16s")("16u")("8s")("8sc")("8u"); BOOST_FOREACH(std::string this_type, valid_types) { if(type == this_type) return true; @@ -120,16 +140,23 @@ static void get_function_signature(std::vector<std::string> &inputsig, } while(!valid_type && pos < toked.size()) { if(is_valid_type(toked[pos])) valid_type = true; - pos++; + else pos++; } while(valid_type && pos < toked.size()) { if(is_valid_type(toked[pos])) outputsig.push_back(toked[pos]); else valid_type = false; pos++; } - - //if there's no explicit output sig then assume the output is the same as the first input - if(outputsig.size() == 0) outputsig.push_back(inputsig[0]); + + //if there's no output sig and only one input sig, assume there are 2 inputs + //this handles conversion fn's (which have a specified output sig) and most of the rest + if(outputsig.size() == 0 && inputsig.size() == 1) { + outputsig.push_back(inputsig[0]); + inputsig.push_back(inputsig[0]); + }//if there's no explicit output sig then assume the output is the same as the first input + else if(outputsig.size() == 0) outputsig.push_back(inputsig[0]); + + assert(inputsig.size() != 0); assert(outputsig.size() != 0); } @@ -168,7 +195,9 @@ bool run_volk_tests(const int archs[], void (*manual_func)(), std::string name, make_buffer_for_signature(inbuffs, inputsig, vlen); //and set the input buffers to something random - //TODO + for(int i=0; i<inputsig.size(); i++) { + load_random_data(inbuffs[i], inputsig[i], vlen); + } //allocate output buffers -- one for each output for each arch std::vector<void *> outbuffs; @@ -204,9 +233,38 @@ bool run_volk_tests(const int archs[], void (*manual_func)(), std::string name, if(arch_list[i] == "generic") generic_offset=i; for(int i=0; i<arch_list.size(); i++) { - if(arch_list[i] != "generic") { - for(int j=0; i<vlen; j++) { - BOOST_CHECK_CLOSE(((float *)(outbuffs[generic_offset]))[j], ((float *)(outbuffs[i]))[j], tol); + if(i != generic_offset) { + if(outputsig[0] == "32fc") { + for(int j=0; j<vlen*2; j++) { + if(fabs(((float *)(outbuffs[generic_offset]))[j] - ((float *)(outbuffs[i]))[j]) > tol) { + std::cout << "Generic: " << ((float *)(outbuffs[generic_offset]))[j] << " " << arch_list[i] << ": " << ((float *)(outbuffs[i]))[j] << std::endl; + return 1; + } + } + } else if(outputsig[0] == "32f") { + for(int j=0; j<vlen; j++) { + if(fabs(((float *)(outbuffs[generic_offset]))[j] - ((float *)(outbuffs[i]))[j]) > tol) { + std::cout << "Generic: " << ((float *)(outbuffs[generic_offset]))[j] << " " << arch_list[i] << ": " << ((float *)(outbuffs[i]))[j] << std::endl; + return 1; + } + } + } else if(outputsig[0] == "32u" || outputsig[0] == "32s" || outputsig[0] == "16sc") { + for(int j=0; j<vlen; j++) { + if(((uint32_t *)(outbuffs[generic_offset]))[j] != ((uint32_t *)(outbuffs[i]))[j]) { + std::cout << "Generic: " << ((uint32_t *)(outbuffs[generic_offset]))[j] << " " << arch_list[i] << ": " << ((uint32_t *)(outbuffs[i]))[j] << std::endl; + return 1; + } + } + } else if(outputsig[0] == "16u" || outputsig[0] == "16s" || outputsig[0] == "8sc") { + for(int j=0; j<vlen; j++) { + if(((uint16_t *)(outbuffs[generic_offset]))[j] != ((uint16_t *)(outbuffs[i]))[j]) { + std::cout << "Generic: " << ((uint16_t *)(outbuffs[generic_offset]))[j] << " " << arch_list[i] << ": " << ((uint16_t *)(outbuffs[i]))[j] << std::endl; + return 1; + } + } + } else { + std::cout << "Error: invalid type " << outputsig[0] << std::endl; + return 1; } } } diff --git a/volk/lib/qa_utils.h b/volk/lib/qa_utils.h index 80323c445..f81d652fb 100644 --- a/volk/lib/qa_utils.h +++ b/volk/lib/qa_utils.h @@ -10,7 +10,7 @@ void random_floats(float *buf, unsigned n); bool run_volk_tests(const int[], void(*)(), std::string, float, int, int); -#define VOLK_RUN_TESTS(func, tol, len, iter) run_volk_tests(func##_arch_defs, (void (*)())func##_manual, std::string(#func), tol, len, iter) +#define VOLK_RUN_TESTS(func, tol, len, iter) BOOST_CHECK_EQUAL(run_volk_tests(func##_arch_defs, (void (*)())func##_manual, std::string(#func), tol, len, iter), 0) typedef void (*volk_fn_2arg)(void *, void *, unsigned int, const char*); typedef void (*volk_fn_3arg)(void *, void *, void *, unsigned int, const char*); diff --git a/volk/orc/volk_32f_normalize_aligned16_orc_impl.orc b/volk/orc/volk_32f_normalize_aligned16_orc_impl.orc new file mode 100644 index 000000000..84d965e7f --- /dev/null +++ b/volk/orc/volk_32f_normalize_aligned16_orc_impl.orc @@ -0,0 +1,5 @@ +.function volk_32f_normalize_aligned16_orc_impl +.source 4 src1 +.floatparam 4 invscalar +.dest 4 dst +mulf dst, src1, invscalar diff --git a/volk/orc/volk_32fc_32f_multiply_aligned16_orc_impl.orc b/volk/orc/volk_32fc_32f_multiply_aligned16_orc_impl.orc new file mode 100644 index 000000000..27c059852 --- /dev/null +++ b/volk/orc/volk_32fc_32f_multiply_aligned16_orc_impl.orc @@ -0,0 +1,7 @@ +.function volk_32fc_32f_multiply_aligned16_orc_impl +.source 8 src1 +.source 4 src2 +.dest 8 dst +.temp 8 tmp +mergelq tmp, src2, src2 +x2 mulf dst, src1, tmp diff --git a/volk/orc/volk_32fc_multiply_aligned16_orc_impl.orc b/volk/orc/volk_32fc_multiply_aligned16_orc_impl.orc new file mode 100644 index 000000000..ffe9cc3ef --- /dev/null +++ b/volk/orc/volk_32fc_multiply_aligned16_orc_impl.orc @@ -0,0 +1,6 @@ +.function volk_32fc_multiply_aligned16_orc_impl +.source 8 src1 +.source 8 src2 +.dest 8 dst +.temp 8 tmp +x2 mulf dst, src1, src2 diff --git a/volk/orc/volk_8s_convert_16s_aligned16_orc_impl.orc b/volk/orc/volk_8s_convert_16s_aligned16_orc_impl.orc index 8322b529a..a089877d1 100644 --- a/volk/orc/volk_8s_convert_16s_aligned16_orc_impl.orc +++ b/volk/orc/volk_8s_convert_16s_aligned16_orc_impl.orc @@ -1,4 +1,5 @@ .function volk_8s_convert_16s_aligned16_orc_impl .source 1 src .dest 2 dst -mulsbw dst, src, 255 +convsbw dst, src +shlw dst, dst, 8 |