Skip to content

Commit e6a59f8

Browse files
committed
build avx, sse4 versions of dfloor dceil floor
1 parent 748380c commit e6a59f8

File tree

6 files changed

+29
-6
lines changed

6 files changed

+29
-6
lines changed

runtime/libpgmath/lib/common/CMakeLists.txt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,23 @@ if(${LIBPGMATH_SYSTEM_PROCESSOR} MATCHES "x86_64" AND NOT ${LIBPGMATH_WITH_GENER
391391
endif()
392392
libmath_add_object_library("${TARGET_NAME}.c" "${FLAGS}" "${DEFINITIONS}" "${TARGET_NAME}_build")
393393
add_dependencies("${TARGET_NAME}_build" ${TARGET_NAME})
394+
395+
foreach (FILENAME dceil dfloor floor)
396+
foreach (VARIANT sse4 avx)
397+
set(TARGET_NAME "${FILENAME}_${VARIANT}")
398+
add_custom_command(OUTPUT ${TARGET_NAME}.c DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${FILENAME}.c PRE_BUILD
399+
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/${FILENAME}.c ${TARGET_NAME}.c)
400+
add_custom_target(${TARGET_NAME} ALL DEPENDS "${TARGET_NAME}.c")
401+
if (${VARIANT} STREQUAL "sse4")
402+
set_property(SOURCE ${TARGET_NAME}.c APPEND_STRING PROPERTY COMPILE_FLAGS "-msse4.1 -DBUILD_SSE4")
403+
elseif (${VARIANT} STREQUAL "avx")
404+
set_property(SOURCE ${TARGET_NAME}.c APPEND_STRING PROPERTY COMPILE_FLAGS "-mavx -DBUILD_AVX")
405+
endif()
406+
libmath_add_object_library("${TARGET_NAME}.c" "${FLAGS}" "${DEFINITIONS}" "${TARGET_NAME}_build")
407+
add_dependencies("${TARGET_NAME}_build" ${TARGET_NAME})
408+
endforeach()
409+
endforeach()
410+
394411
elseif(${LIBPGMATH_SYSTEM_PROCESSOR} MATCHES "ppc64le")
395412
# Generate mth_128mask.c
396413
set(TARGET_NAME "mth_128mask")

runtime/libpgmath/lib/common/dceil.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@
1010
#include <immintrin.h>
1111
#endif
1212

13-
#if defined(__AVX__)
13+
#if defined(BUILD_AVX)
1414
double
1515
__mth_i_dceil_avx(double x)
1616
{
1717
return _mm_cvtsd_f64(_mm_ceil_sd(_mm_set1_pd(x), _mm_set1_pd(x)));
1818
}
19-
#elif defined(__SSE4_1__)
19+
#elif defined(BUILD_SSE4)
2020
double
2121
__mth_i_dceil_sse(double x)
2222
{

runtime/libpgmath/lib/common/dfloor.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@
1010
#include <immintrin.h>
1111
#endif
1212

13-
#if defined(__AVX__)
13+
#if defined(BUILD_AVX)
1414
double
1515
__mth_i_dfloor_avx(double x)
1616
{
1717
return _mm_cvtsd_f64(_mm_floor_sd(_mm_set1_pd(x), _mm_set1_pd(x)));
1818
}
19-
#elif defined(__SSE4_1__)
19+
#elif defined(BUILD_SSE4)
2020
double
2121
__mth_i_dfloor_sse(double x)
2222
{

runtime/libpgmath/lib/common/floor.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@
1010
#include <immintrin.h>
1111
#endif
1212

13-
#if defined(__AVX__)
13+
#if defined(BUILD_AVX)
1414
float
1515
__mth_i_floor_avx(float x)
1616
{
1717
return _mm_cvtss_f32(_mm_floor_ss(_mm_set1_ps(x), _mm_set1_ps(x)));
1818
}
19-
#elif defined(__SSE4_1__)
19+
#elif defined(BUILD_SSE4)
2020
float
2121
__mth_i_floor_sse(float x)
2222
{

runtime/libpgmath/lib/x86_64/math_tables/mth_ceildefs.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
MTHINTRIN(ceil , ss , any , __mth_i_ceil , __mth_i_ceil , __mth_i_ceil ,__math_dispatch_error)
99
MTHINTRIN(ceil , ds , any , __mth_i_dceil , __mth_i_dceil , __mth_i_dceil ,__math_dispatch_error)
10+
MTHINTRIN(ceil , ds , sse4 , __mth_i_dceil_sse , __mth_i_dceil_sse , __mth_i_dceil_sse ,__math_dispatch_error)
11+
MTHINTRIN(ceil , ds , avx , __mth_i_dceil_avx , __mth_i_dceil_avx , __mth_i_dceil_avx ,__math_dispatch_error)
1012
MTHINTRIN(ceil , sv4 , any , __gs_ceil_4_f , __gs_ceil_4_r , __gs_ceil_4_p ,__math_dispatch_error)
1113
MTHINTRIN(ceil , dv2 , any , __gd_ceil_2_f , __gd_ceil_2_r , __gd_ceil_2_p ,__math_dispatch_error)
1214
MTHINTRIN(ceil , sv8 , any , __gs_ceil_8_f , __gs_ceil_8_r , __gs_ceil_8_p ,__math_dispatch_error)

runtime/libpgmath/lib/x86_64/math_tables/mth_floordefs.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77

88
MTHINTRIN(floor , ss , any , __mth_i_floor , __mth_i_floor , __mth_i_floor ,__math_dispatch_error)
99
MTHINTRIN(floor , ds , any , __mth_i_dfloor , __mth_i_dfloor , __mth_i_dfloor ,__math_dispatch_error)
10+
MTHINTRIN(floor , ss , sse4 , __mth_i_floor_sse , __mth_i_floor_sse , __mth_i_floor_sse ,__math_dispatch_error)
11+
MTHINTRIN(floor , ds , sse4 , __mth_i_dfloor_sse , __mth_i_dfloor_sse , __mth_i_dfloor_sse ,__math_dispatch_error)
12+
MTHINTRIN(floor , ss , avx , __mth_i_floor_avx , __mth_i_floor_avx , __mth_i_floor_avx ,__math_dispatch_error)
13+
MTHINTRIN(floor , ds , avx , __mth_i_dfloor_avx , __mth_i_dfloor_avx , __mth_i_dfloor_avx ,__math_dispatch_error)
1014
MTHINTRIN(floor , sv4 , any , __gs_floor_4_f , __gs_floor_4_r , __gs_floor_4_p ,__math_dispatch_error)
1115
MTHINTRIN(floor , dv2 , any , __gd_floor_2_f , __gd_floor_2_r , __gd_floor_2_p ,__math_dispatch_error)
1216
MTHINTRIN(floor , sv8 , any , __gs_floor_8_f , __gs_floor_8_r , __gs_floor_8_p ,__math_dispatch_error)

0 commit comments

Comments
 (0)