diff --git a/cmake/modules/CheckFunctionExists.c b/cmake/modules/CheckFunctionExists.c new file mode 100644 index 000000000..9fdea2866 --- /dev/null +++ b/cmake/modules/CheckFunctionExists.c @@ -0,0 +1,25 @@ +#ifdef CHECK_FUNCTION_EXISTS + +char CHECK_FUNCTION_EXISTS(); +#ifdef __CLASSIC_C__ +int main(){ + int ac; + char*av[]; +#else +int main(int ac, char*av[]){ + +#endif + float ac2 = sqrtf(rand()); + CHECK_FUNCTION_EXISTS(); + if(ac2 * ac > 1000) + { + return *av[0]; + } + return 0; +} + +#else /* CHECK_FUNCTION_EXISTS */ + +# error "CHECK_FUNCTION_EXISTS has to specify the function" + +#endif /* CHECK_FUNCTION_EXISTS */ diff --git a/cmake/modules/CheckFunctionExistsMath.cmake b/cmake/modules/CheckFunctionExistsMath.cmake new file mode 100644 index 000000000..0fbccb836 --- /dev/null +++ b/cmake/modules/CheckFunctionExistsMath.cmake @@ -0,0 +1,57 @@ +# - Check if a C function can be linked +# CHECK_FUNCTION_EXISTS( ) +# +# Check that the is provided by libraries on the system and +# store the result in a . This does not verify that any +# system header file declares the function, only that it can be found +# at link time (considure using CheckSymbolExists). +# +# The following variables may be set before calling this macro to +# modify the way the check is run: +# +# CMAKE_REQUIRED_FLAGS = string of compile command line flags +# CMAKE_REQUIRED_DEFINITIONS = list of macros to define (-DFOO=bar) +# CMAKE_REQUIRED_INCLUDES = list of include directories +# CMAKE_REQUIRED_LIBRARIES = list of libraries to link + + +MACRO(CHECK_FUNCTION_EXISTS_MATH FUNCTION VARIABLE) + IF("${VARIABLE}" MATCHES "^${VARIABLE}$") + SET(MACRO_CHECK_FUNCTION_DEFINITIONS + "-DCHECK_FUNCTION_EXISTS=${FUNCTION} ${CMAKE_REQUIRED_FLAGS}") + MESSAGE(STATUS "Looking for ${FUNCTION}") + IF(CMAKE_REQUIRED_LIBRARIES) + SET(CHECK_FUNCTION_EXISTS_ADD_LIBRARIES + "-DLINK_LIBRARIES:STRING=${CMAKE_REQUIRED_LIBRARIES}") + ELSE(CMAKE_REQUIRED_LIBRARIES) + SET(CHECK_FUNCTION_EXISTS_ADD_LIBRARIES) + ENDIF(CMAKE_REQUIRED_LIBRARIES) + IF(CMAKE_REQUIRED_INCLUDES) + SET(CHECK_FUNCTION_EXISTS_ADD_INCLUDES + "-DINCLUDE_DIRECTORIES:STRING=${CMAKE_REQUIRED_INCLUDES}") + ELSE(CMAKE_REQUIRED_INCLUDES) + SET(CHECK_FUNCTION_EXISTS_ADD_INCLUDES) + ENDIF(CMAKE_REQUIRED_INCLUDES) + TRY_COMPILE(${VARIABLE} + ${CMAKE_BINARY_DIR} + ${CMAKE_SOURCE_DIR}/cmake/modules/CheckFunctionExists.c + COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS} + CMAKE_FLAGS -DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_FUNCTION_DEFINITIONS} + "${CHECK_FUNCTION_EXISTS_ADD_LIBRARIES}" + "${CHECK_FUNCTION_EXISTS_ADD_INCLUDES}" + OUTPUT_VARIABLE OUTPUT) + IF(${VARIABLE}) + SET(${VARIABLE} 1 CACHE INTERNAL "Have function ${FUNCTION}") + MESSAGE(STATUS "Looking for ${FUNCTION} - found") + FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log + "Determining if the function ${FUNCTION} exists passed with the following output:\n" + "${OUTPUT}\n\n") + ELSE(${VARIABLE}) + MESSAGE(STATUS "Looking for ${FUNCTION} - not found") + SET(${VARIABLE} "" CACHE INTERNAL "Have function ${FUNCTION}") + FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log + "Determining if the function ${FUNCTION} exists failed with the following output:\n" + "${OUTPUT}\n\n") + ENDIF(${VARIABLE}) + ENDIF("${VARIABLE}" MATCHES "^${VARIABLE}$") +ENDMACRO(CHECK_FUNCTION_EXISTS_MATH) diff --git a/cmake/modules/FindVolk.cmake b/cmake/modules/FindVolk.cmake index 3da43592d..7a9cb5349 100644 --- a/cmake/modules/FindVolk.cmake +++ b/cmake/modules/FindVolk.cmake @@ -24,6 +24,36 @@ FIND_LIBRARY( /usr/lib64 ) +# Some functions are not defined in old volk versions +SET(CMAKE_REQUIRED_LIBRARIES volk m) +CHECK_FUNCTION_EXISTS_MATH(volk_32f_index_max_16u HAVE_VOLK_MAX_FUNCTION) +CHECK_FUNCTION_EXISTS_MATH(volk_32f_accumulator_s32f HAVE_VOLK_ACC_FUNCTION) +CHECK_FUNCTION_EXISTS_MATH(volk_32fc_s32fc_multiply_32fc HAVE_VOLK_MULT_FUNCTION) +CHECK_FUNCTION_EXISTS_MATH(volk_32fc_conjugate_32fc HAVE_VOLK_CONJ_FUNCTION) +CHECK_FUNCTION_EXISTS_MATH(volk_32fc_x2_multiply_32fc HAVE_VOLK_MULT2_FUNCTION) +CHECK_FUNCTION_EXISTS_MATH(volk_32fc_magnitude_32f HAVE_VOLK_MAG_FUNCTION) + + +SET(VOLK_DEFINITIONS "HAVE_VOLK") +IF(${HAVE_VOLK_MAX_FUNCTION}) + SET(VOLK_DEFINITIONS "${VOLK_DEFINITIONS}; HAVE_VOLK_MAX_FUNCTION") +ENDIF() +IF(${HAVE_VOLK_ACC_FUNCTION}) + SET(VOLK_DEFINITIONS "${VOLK_DEFINITIONS}; HAVE_VOLK_ACC_FUNCTION") +ENDIF() +IF(${HAVE_VOLK_MULT_FUNCTION}) + SET(VOLK_DEFINITIONS "${VOLK_DEFINITIONS}; HAVE_VOLK_MULT_FUNCTION") +ENDIF() +IF(${HAVE_VOLK_CONJ_FUNCTION}) + SET(VOLK_DEFINITIONS "${VOLK_DEFINITIONS}; HAVE_VOLK_CONJ_FUNCTION") +ENDIF() +IF(${HAVE_VOLK_MULT2_FUNCTION}) + SET(VOLK_DEFINITIONS "${VOLK_DEFINITIONS}; HAVE_VOLK_MULT2_FUNCTION") +ENDIF() +IF(${HAVE_VOLK_MAG_FUNCTION}) + SET(VOLK_DEFINITIONS "${VOLK_DEFINITIONS}; HAVE_VOLK_MAG_FUNCTION") +ENDIF() + INCLUDE(FindPackageHandleStandardArgs) FIND_PACKAGE_HANDLE_STANDARD_ARGS(VOLK DEFAULT_MSG VOLK_LIBRARIES VOLK_INCLUDE_DIRS) -MARK_AS_ADVANCED(VOLK_LIBRARIES VOLK_INCLUDE_DIRS) +MARK_AS_ADVANCED(VOLK_LIBRARIES VOLK_INCLUDE_DIRS VOLK_DEFINITIONS) diff --git a/lte/lib/CMakeLists.txt b/lte/lib/CMakeLists.txt index f4d09f9a2..9efebe36f 100644 --- a/lte/lib/CMakeLists.txt +++ b/lte/lib/CMakeLists.txt @@ -23,6 +23,7 @@ ######################################################################## # Find Dependencies ######################################################################## +include(CheckFunctionExistsMath) FIND_PACKAGE(FFTW3F REQUIRED) # TODO: distribute kissfft instead INCLUDE_DIRECTORIES(${FFTW3F_INCLUDE_DIRS}) @@ -57,9 +58,9 @@ LIBLTE_SET_PIC(lte) IF(VOLK_FOUND) INCLUDE_DIRECTORIES(${VOLK_INCLUDE_DIRS}) - SET_TARGET_PROPERTIES(lte PROPERTIES COMPILE_DEFINITIONS "HAVE_VOLK") + SET_TARGET_PROPERTIES(lte PROPERTIES COMPILE_DEFINITIONS "${VOLK_DEFINITIONS}") TARGET_LINK_LIBRARIES(lte ${VOLK_LIBRARIES}) - MESSAGE(STATUS " Compiling with VOLK SIMD library.") + MESSAGE(STATUS " Compiling with VOLK SIMD library.") ELSE(VOLK_FOUND) MESSAGE(STATUS " VOLK SIMD library NOT found. Using generic implementation.") ENDIF(VOLK_FOUND) diff --git a/lte/lib/phch/src/regs.c b/lte/lib/phch/src/regs.c index 0e574d3c2..06b9a0c79 100644 --- a/lte/lib/phch/src/regs.c +++ b/lte/lib/phch/src/regs.c @@ -93,6 +93,9 @@ int regs_phich_init(regs_t *h) { case R_2: ng = 2; break; + default: + ng = 0; + break; } h->ngroups_phich = (int) ceilf(ng * ((float) h->nof_prb/8)); h->phich = malloc(sizeof(regs_ch_t) * h->ngroups_phich); diff --git a/lte/lib/utils/src/vector.c b/lte/lib/utils/src/vector.c index 1fb0c55fe..979d646b2 100644 --- a/lte/lib/utils/src/vector.c +++ b/lte/lib/utils/src/vector.c @@ -45,17 +45,17 @@ int vec_acc_ii(int *x, int len) { } float vec_acc_ff(float *x, int len) { -#ifndef HAVE_VOLK +#ifdef HAVE_VOLK_ACC_FUNCTION + float result; + volk_32f_accumulator_s32f_u(&result,x,(unsigned int) len); + return result; +#else int i; float z=0; for (i=0;i