commit ebdca9b30a2f5c41e88818d36877d4848adf6118
parent 352360726ec7dab09b4b0cb2ba245bba0bf303ef
Author: vaplv <vaplv@free.fr>
Date: Fri, 17 Mar 2023 11:24:40 +0100
Making the Sleef library a purely internal dependency
Move the sleef library calls from the API headers to the C files. This
makes sleef an internal dependency that the rsimd library user does not
have to worry about.
Diffstat:
5 files changed, 260 insertions(+), 106 deletions(-)
diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt
@@ -57,10 +57,13 @@ string(REGEX MATCH "[ \t\r\n]+sse4_1[ \t\r\n]+" SSE4_1 ${CPUINFO_OUT})
string(REGEX MATCH "[ \t\r\n]+avx[ \t\r\n]+" AVX ${CPUINFO_OUT})
string(REGEX MATCH "[ \t\r\n]+fma[ \t\r\n]+" FMA ${CPUINFO_OUT})
+set(CFLAGS)
+
if(SSE2)
unset(SSE2)
CHECK_C_COMPILER_FLAG("-msse2" SSE2)
message(STATUS "Use the SSE2 instruction set ")
+ set(CFLAGS "${CFLAGS} -msse2")
else()
message(FATAL_ERROR "The SSE2 instruction set must be supported.")
endif()
@@ -68,16 +71,19 @@ if(SSE4_1)
unset(SSE4_1)
CHECK_C_COMPILER_FLAG("-msse4.1" SSE4_1)
message(STATUS "Use the SSE4.1 instruction set")
+ set(CFLAGS "${CFLAGS} -msse4.1")
endif()
if(AVX)
unset(AVX)
CHECK_C_COMPILER_FLAG("-mavx" AVX)
message(STATUS "Use the AVX instruction set")
+ set(CFLAGS "${CFLAGS} -mavx")
endif()
if(FMA)
unset(FMA)
CHECK_C_COMPILER_FLAG("-mfma" FMA)
message(STATUS "Use the FMA instruction set")
+ set(CFLAGS "${CFLAGS} -mfma")
endif()
################################################################################
@@ -133,8 +139,12 @@ set(RSIMD_FILES_INC_AVX
avx/avxf.h
avx/avxi.h)
set(RSIMD_FILES_SRC
+ math4.c
aosf44.c
aosq.c)
+if(AVX)
+ set(RSIMD_FILES_SRC ${RSIMD_FILES_SRC} math8.c)
+endif()
set(RSIMD_FILES_DOC COPYING README.md)
set(RSIMD_FILES_CMAKE
RSIMDConfig.cmake
@@ -152,7 +162,8 @@ set(RSIMD_FILES_INC
add_library(rsimd SHARED ${RSIMD_FILES_INC} ${RSIMD_FILES_SRC})
target_link_libraries(rsimd Sleef)
-set_target_properties(rsimd PROPERTIES DEFINE_SYMBOL RSIMD_SHARED_BUILD)
+set_target_properties(rsimd PROPERTIES DEFINE_SYMBOL RSIMD_SHARED_BUILD)
+set_target_properties(rsimd PROPERTIES COMPILE_FLAGS "${CFLAGS}")
set_target_properties(rsimd PROPERTIES
VERSION ${VERSION}
SOVERSION ${VERSION_MAJOR})
diff --git a/src/math4.c b/src/math4.c
@@ -0,0 +1,26 @@
+/* Copyright (C) 2014-2021 Vincent Forest (vaplv@free.fr)
+ *
+ * The RSIMD library is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published
+ * by the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * The RSIMD library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the RSIMD library. If not, see <http://www.gnu.org/licenses/>. */
+
+#include "math4.h"
+#include <rsys/rsys.h>
+
+#ifndef SIMD_SSE2
+ #error "Missing SIMD instruction set"
+#endif
+
+#define RSIMD_WIDTH__ 4
+#include "vXf_begin.h"
+#include "mathX_c.h"
+#include "vXf_end.h"
diff --git a/src/math8.c b/src/math8.c
@@ -0,0 +1,26 @@
+/* Copyright (C) 2014-2021 Vincent Forest (vaplv@free.fr)
+ *
+ * The RSIMD library is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published
+ * by the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * The RSIMD library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the RSIMD library. If not, see <http://www.gnu.org/licenses/>. */
+
+#include "math8.h"
+#include <rsys/rsys.h>
+
+#ifndef SIMD_AVX
+ #error "Missing SIMD instruction set"
+#endif
+
+#define RSIMD_WIDTH__ 8
+#include "vXf_begin.h"
+#include "mathX_c.h"
+#include "vXf_end.h"
diff --git a/src/mathX.h b/src/mathX.h
@@ -15,123 +15,79 @@
#include "rsimd.h"
-#ifdef COMPILER_GCC
- #pragma GCC diagnostic push
- #pragma GCC diagnostic ignored "-Wignored-qualifiers"
-#endif
-
-#include <sleef.h>
-
-#ifdef COMPILER_GCC
- #pragma GCC diagnostic pop
-#endif
-
-static FINLINE RSIMD_vXf_T__
-RSIMD_vXf__(copysign)(const RSIMD_vXf_T__ x, const RSIMD_vXf_T__ y)
-{
- return RSIMD_Sleef__(copysignf)(x, y);
-}
-
-static INLINE RSIMD_vXf_T__
-RSIMD_vXf__(floor)(const RSIMD_vXf_T__ x)
-{
- return RSIMD_Sleef__(floorf)(x);
-}
-
-static INLINE RSIMD_vXf_T__
-RSIMD_vXf__(pow)(const RSIMD_vXf_T__ x, const RSIMD_vXf_T__ y)
-{
- return RSIMD_Sleef_ULP__(powf, u10)(x, y);
-}
+RSIMD_API RSIMD_vXf_T__
+RSIMD_vXf__(copysign)
+ (const RSIMD_vXf_T__ x,
+ const RSIMD_vXf_T__ y);
+
+RSIMD_API RSIMD_vXf_T__
+RSIMD_vXf__(floor)
+ (const RSIMD_vXf_T__ x);
+
+RSIMD_API RSIMD_vXf_T__
+RSIMD_vXf__(pow)
+ (const RSIMD_vXf_T__ x,
+ const RSIMD_vXf_T__ y);
/*******************************************************************************
* Exponentatial functions
******************************************************************************/
-static INLINE RSIMD_vXf_T__
-RSIMD_vXf__(exp2)(const RSIMD_vXf_T__ x)
-{
- return RSIMD_Sleef_ULP__(exp2f, u10)(x);
-}
-
-static INLINE RSIMD_vXf_T__
-RSIMD_vXf__(exp)(const RSIMD_vXf_T__ x)
-{
- return RSIMD_Sleef_ULP__(expf, u10)(x);
-}
-
-static INLINE RSIMD_vXf_T__
-RSIMD_vXf__(exp10)(const RSIMD_vXf_T__ x)
-{
- return RSIMD_Sleef_ULP__(exp10f, u10)(x);
-}
+RSIMD_API RSIMD_vXf_T__
+RSIMD_vXf__(exp2)
+ (const RSIMD_vXf_T__ x);
+
+RSIMD_API RSIMD_vXf_T__
+RSIMD_vXf__(exp)
+ (const RSIMD_vXf_T__ x);
+
+RSIMD_API RSIMD_vXf_T__
+RSIMD_vXf__(exp10)
+ (const RSIMD_vXf_T__ x);
/*******************************************************************************
* Log functions
******************************************************************************/
-static INLINE RSIMD_vXf_T__
-RSIMD_vXf__(log2)(const RSIMD_vXf_T__ x)
-{
- return RSIMD_Sleef_ULP__(log2f, u10)(x);
-}
-
-static INLINE RSIMD_vXf_T__
-RSIMD_vXf__(log)(const RSIMD_vXf_T__ x)
-{
- return RSIMD_Sleef_ULP__(logf, u10)(x);
-}
-
-static INLINE RSIMD_vXf_T__
-RSIMD_vXf__(log10)(const RSIMD_vXf_T__ x)
-{
- return RSIMD_Sleef_ULP__(log10f, u10)(x);
-}
+RSIMD_API RSIMD_vXf_T__
+RSIMD_vXf__(log2)
+ (const RSIMD_vXf_T__ x);
+
+RSIMD_API RSIMD_vXf_T__
+RSIMD_vXf__(log)
+ (const RSIMD_vXf_T__ x);
+
+RSIMD_API RSIMD_vXf_T__
+RSIMD_vXf__(log10)
+ (const RSIMD_vXf_T__ x);
/*******************************************************************************
* Trigonometric functions
******************************************************************************/
-static INLINE RSIMD_vXf_T__
-RSIMD_vXf__(sin)(const RSIMD_vXf_T__ v)
-{
- return RSIMD_Sleef_ULP__(sinf, u10)(v);
-}
-
-static INLINE RSIMD_vXf_T__
-RSIMD_vXf__(asin)(const RSIMD_vXf_T__ v)
-{
- return RSIMD_Sleef_ULP__(asinf, u10)(v);
-}
-
-static INLINE RSIMD_vXf_T__
-RSIMD_vXf__(cos)(const RSIMD_vXf_T__ v)
-{
- return RSIMD_Sleef_ULP__(cosf, u10)(v);
-}
-
-static INLINE RSIMD_vXf_T__
-RSIMD_vXf__(acos)(const RSIMD_vXf_T__ v)
-{
- return RSIMD_Sleef_ULP__(acosf, u10)(v);
-}
-
-static INLINE void
+RSIMD_API RSIMD_vXf_T__
+RSIMD_vXf__(sin)
+ (const RSIMD_vXf_T__ v);
+
+RSIMD_API RSIMD_vXf_T__
+RSIMD_vXf__(asin)
+ (const RSIMD_vXf_T__ v);
+
+RSIMD_API RSIMD_vXf_T__
+RSIMD_vXf__(cos)
+ (const RSIMD_vXf_T__ v);
+
+RSIMD_API RSIMD_vXf_T__
+RSIMD_vXf__(acos)
+ (const RSIMD_vXf_T__ v);
+
+RSIMD_API void
RSIMD_vXf__(sincos)
- (const RSIMD_vXf_T__ v, RSIMD_vXf_T__* RESTRICT s, RSIMD_vXf_T__* RESTRICT c)
-{
- const RSIMD_Sleef_vecf__(2) r = RSIMD_Sleef_ULP__(sincosf, u10)(v);
- *s = r.x;
- *c = r.y;
-}
-
-static INLINE RSIMD_vXf_T__
-RSIMD_vXf__(tan)(const RSIMD_vXf_T__ v)
-{
- return RSIMD_Sleef_ULP__(tanf, u10)(v);
-}
-
-static INLINE RSIMD_vXf_T__
-RSIMD_vXf__(atan)(const RSIMD_vXf_T__ v)
-{
- return RSIMD_Sleef_ULP__(atanf, u10)(v);
-}
+ (const RSIMD_vXf_T__ v,
+ RSIMD_vXf_T__* RESTRICT s,
+ RSIMD_vXf_T__* RESTRICT c);
+RSIMD_API RSIMD_vXf_T__
+RSIMD_vXf__(tan)
+ (const RSIMD_vXf_T__ v);
+RSIMD_API RSIMD_vXf_T__
+RSIMD_vXf__(atan)
+ (const RSIMD_vXf_T__ v);
diff --git a/src/mathX_c.h b/src/mathX_c.h
@@ -0,0 +1,135 @@
+/* Copyright (C) 2014-2021 Vincent Forest (vaplv@free.fr)
+ *
+ * The RSIMD library is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published
+ * by the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * The RSIMD library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the RSIMD library. If not, see <http://www.gnu.org/licenses/>. */
+
+#include "rsimd.h"
+
+#ifdef COMPILER_GCC
+ #pragma GCC diagnostic push
+ #pragma GCC diagnostic ignored "-Wignored-qualifiers"
+#endif
+
+#include <sleef.h>
+
+#ifdef COMPILER_GCC
+ #pragma GCC diagnostic pop
+#endif
+
+RSIMD_vXf_T__
+RSIMD_vXf__(copysign)(const RSIMD_vXf_T__ x, const RSIMD_vXf_T__ y)
+{
+ return RSIMD_Sleef__(copysignf)(x, y);
+}
+
+RSIMD_vXf_T__
+RSIMD_vXf__(floor)(const RSIMD_vXf_T__ x)
+{
+ return RSIMD_Sleef__(floorf)(x);
+}
+
+RSIMD_vXf_T__
+RSIMD_vXf__(pow)(const RSIMD_vXf_T__ x, const RSIMD_vXf_T__ y)
+{
+ return RSIMD_Sleef_ULP__(powf, u10)(x, y);
+}
+
+/*******************************************************************************
+ * Exponentatial functions
+ ******************************************************************************/
+RSIMD_vXf_T__
+RSIMD_vXf__(exp2)(const RSIMD_vXf_T__ x)
+{
+ return RSIMD_Sleef_ULP__(exp2f, u10)(x);
+}
+
+RSIMD_vXf_T__
+RSIMD_vXf__(exp)(const RSIMD_vXf_T__ x)
+{
+ return RSIMD_Sleef_ULP__(expf, u10)(x);
+}
+
+RSIMD_vXf_T__
+RSIMD_vXf__(exp10)(const RSIMD_vXf_T__ x)
+{
+ return RSIMD_Sleef_ULP__(exp10f, u10)(x);
+}
+
+/*******************************************************************************
+ * Log functions
+ ******************************************************************************/
+RSIMD_vXf_T__
+RSIMD_vXf__(log2)(const RSIMD_vXf_T__ x)
+{
+ return RSIMD_Sleef_ULP__(log2f, u10)(x);
+}
+
+RSIMD_vXf_T__
+RSIMD_vXf__(log)(const RSIMD_vXf_T__ x)
+{
+ return RSIMD_Sleef_ULP__(logf, u10)(x);
+}
+
+RSIMD_vXf_T__
+RSIMD_vXf__(log10)(const RSIMD_vXf_T__ x)
+{
+ return RSIMD_Sleef_ULP__(log10f, u10)(x);
+}
+
+/*******************************************************************************
+ * Trigonometric functions
+ ******************************************************************************/
+RSIMD_vXf_T__
+RSIMD_vXf__(sin)(const RSIMD_vXf_T__ v)
+{
+ return RSIMD_Sleef_ULP__(sinf, u10)(v);
+}
+
+RSIMD_vXf_T__
+RSIMD_vXf__(asin)(const RSIMD_vXf_T__ v)
+{
+ return RSIMD_Sleef_ULP__(asinf, u10)(v);
+}
+
+RSIMD_vXf_T__
+RSIMD_vXf__(cos)(const RSIMD_vXf_T__ v)
+{
+ return RSIMD_Sleef_ULP__(cosf, u10)(v);
+}
+
+RSIMD_vXf_T__
+RSIMD_vXf__(acos)(const RSIMD_vXf_T__ v)
+{
+ return RSIMD_Sleef_ULP__(acosf, u10)(v);
+}
+
+void
+RSIMD_vXf__(sincos)
+ (const RSIMD_vXf_T__ v, RSIMD_vXf_T__* RESTRICT s, RSIMD_vXf_T__* RESTRICT c)
+{
+ const RSIMD_Sleef_vecf__(2) r = RSIMD_Sleef_ULP__(sincosf, u10)(v);
+ *s = r.x;
+ *c = r.y;
+}
+
+RSIMD_vXf_T__
+RSIMD_vXf__(tan)(const RSIMD_vXf_T__ v)
+{
+ return RSIMD_Sleef_ULP__(tanf, u10)(v);
+}
+
+RSIMD_vXf_T__
+RSIMD_vXf__(atan)(const RSIMD_vXf_T__ v)
+{
+ return RSIMD_Sleef_ULP__(atanf, u10)(v);
+}