From 11ec56f53bf082c20f9a6579890b596008ecb1ee Mon Sep 17 00:00:00 2001 From: Johannes Demel Date: Mon, 9 Aug 2021 14:10:44 +0200 Subject: [PATCH] wip: Add example files --- compile.sh | 3 +++ main.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ main.cc | 34 ++++++++++++++++++++++++++++++++ 3 files changed, 95 insertions(+) create mode 100755 compile.sh create mode 100644 main.c create mode 100644 main.cc diff --git a/compile.sh b/compile.sh new file mode 100755 index 000000000..f9f19bca8 --- /dev/null +++ b/compile.sh @@ -0,0 +1,3 @@ +gcc -std=c17 -I/home/johannes/src/volk/include -x c main.c -o mainvolkgnuc -lm +clang -std=c17 -I/home/johannes/src/volk/include -x c main.c -o mainvolkclangc -lm +g++ -std=c++17 -I/home/johannes/src/volk/include -x c++ main.cc -o mainvolkcpp -lm -lfmt \ No newline at end of file diff --git a/main.c b/main.c new file mode 100644 index 000000000..dd7e9cdf1 --- /dev/null +++ b/main.c @@ -0,0 +1,58 @@ + +#include +#include + +int main(int argc, char* argv[]) +{ + lv_32fc_t fc_cpl[4]; + printf("float=%lu, complex float=%lu, complex float array[4]=%lu\n", + sizeof(float), + sizeof(lv_32fc_t), + sizeof(fc_cpl)); + + for (int i = 0; i < 4; i++) { + fc_cpl[i] = (i + 3) + I * (i + 8); + + fc_cpl[i] = lv_cmake(i + 3, i + 8); + } + for (int i = 0; i < 4; i++) { + lv_32fc_t val = fc_cpl[i]; + lv_32fc_t cval = conj(val); + lv_32fc_t gval = ~val; + lv_32fc_t mult = val * val; + printf("val = %+.1f%+.1fj\n", creal(val), cimag(val)); + printf("conj(val)= %+.1f%+.1fj\n", creal(cval), cimag(cval)); + printf("gcc: ~val= %+.1f%+.1fj\n", creal(gval), cimag(gval)); + printf("val*val = %+.1f%+.1fj\n", creal(mult), cimag(mult)); + } + + lv_8sc_t sc_cpl[4]; + printf("\n\nchar=%lu, complex char=%lu, complex char array[4]=%lu\n", + sizeof(char), + sizeof(lv_8sc_t), + sizeof(sc_cpl)); + + for (int i = 0; i < 4; i++) { + // lv_8sc_t value = (i + 3) + I * (i + 8); + // printf("value=%+hhi%+hhij\n", creal(value), cimag(value)); + // sc_cpl[i] = (i + 3) + I * (i + 8); + sc_cpl[i] = lv_cmake(i + 3, i + 8); + // printf("%i + j %i\n", creal(sc_cpl[i]), cimag(sc_cpl[i])); + } + for (int i = 0; i < 4; i++) { + lv_8sc_t val = sc_cpl[i]; + lv_8sc_t cval = conj(val); + // lv_8sc_t cval = lv_cmake(creal(val), -cimag(val)); + lv_8sc_t gval = ~val; + lv_8sc_t mult = val * val; + printf("val = %+hhi%+hhij\n", __real__ val, __imag__ val); + printf("conj(val)= %+hhi%+hhij\n", __real__ cval, __imag__ cval); + printf("gcc: ~val= %+hhi%+hhij\n", __real__ gval, __imag__ gval); + printf("val*val = %+hhi%+hhij\n", __real__ mult, __imag__ mult); + } + + // char* values = (char*) sc_cpl; + // for (int i = 0; i < 8; i++) { + // printf("%hhi\n", values[i]); + // } +} \ No newline at end of file diff --git a/main.cc b/main.cc new file mode 100644 index 000000000..a72489861 --- /dev/null +++ b/main.cc @@ -0,0 +1,34 @@ +#include +#include +#include +#include +#include + + +#include + + +int main(int argc, char* argv[]) +{ + lv_32fc_t fc_cpl[4]; + fmt::print("float={}, complex float={}, complex float array[4]={}\n", + sizeof(float), + sizeof(lv_32fc_t), + sizeof(fc_cpl)); + + + std::vector vec(4); + for (int i = 0; i < 4; i++) { + auto foo = std::complex( (i + 3), (i + 8) ); + fmt::print("std::complex: ({:+.1f}{:+.1f}j)\n", std::real(foo), std::imag(foo)); + lv_32fc_t bar = lv_32fc_t{5, 6}; + vec.at(i) = bar; + + } + + for(auto &val : vec){ + float r = __real__ val; + float i = __imag__ val; + fmt::print("sizeof(val)={}, {:+.1f}{:+.1f}j\n", sizeof(val), r, i); + } +} \ No newline at end of file