commit 871b4275beb53ab1e019aee28875aeec9bd3d25d
parent c22b4dfa5b911e705fc8873dac53e26d93962544
Author: vaplv <vaplv@free.fr>
Date: Mon, 12 May 2025 16:27:56 +0200
Correct API headers
The math.h and rsimd.h headers conditionally included files relating to
the SIMD instruction sets activated when the rsimd-based program was
compiled. However, this program could be compiled with SIMD instruction
sets that had not been activated when rsimd was compiled. As a result,
files to be included could be missing, because the instruction set had
not been installed when the library was compiled and installed.
From now on, API headers are generated when rsimd is compiled, so as not
to include files that depend on compilation options that may change as
they are included. They include the only include files compatible with
the options used at rsimd compilation time. They are therefore
independent of the user's compilation options.
Diffstat:
6 files changed, 75 insertions(+), 65 deletions(-)
diff --git a/.gitignore b/.gitignore
@@ -11,3 +11,5 @@ test*
.simd
.config
rsimd*.pc
+src/math.h
+src/rsimd.h
diff --git a/Makefile b/Makefile
@@ -41,6 +41,22 @@ build_library__: .config $(DEP)
echo "$(LIBNAME_SHARED)";\
fi)
+src/rsimd.h: src/rsimd.h.in config.mk
+ if [ "$(SIMD_WIDTH)" = "128" ]; then \
+ sed '/#include[[:space:]]\{0,\}"avx\/avx\.h"/d' src/rsimd.h.in > $@; \
+ fi
+ if [ "$(SIMD_WIDTH)" = "256" ]; then \
+ cp src/rsimd.h.in $@; \
+ fi
+
+src/math.h: src/math.h.in config.mk
+ if [ "$(SIMD_WIDTH)" = "128" ]; then \
+ sed '/#include[[:space:]]\{0,\}"math8\.h"/d' src/math.h.in > $@; \
+ fi
+ if [ "$(SIMD_WIDTH)" = "256" ]; then \
+ cp src/math.h.in $@; \
+ fi
+
$(DEP) $(OBJ): config.mk
$(LIBNAME_SHARED): $(OBJ)
@@ -79,6 +95,7 @@ all: build_library build_tests
clean__: clean_test
rm -f $(OBJ) $(TEST_OBJ) $(LIBNAME)
rm -f .config .simd .test librsimd.o rsimd.pc rsimd-local.pc
+ rm -f src/math.h src/rsimd.h
distclean__: clean__
rm -f $(DEP) $(TEST_DEP) .test
diff --git a/src/math.h b/src/math.h
@@ -1,29 +0,0 @@
-/* Copyright (C) 2014-2019, 2021, 2023 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/>. */
-
-#ifndef RSIMD_MATH_H
-#define RSIMD_MATH_H
-
-#include <rsys/rsys.h>
-
-#ifdef SIMD_SSE2
- #include "math4.h"
-#endif
-#ifdef SIMD_AVX
- #include "math8.h"
-#endif
-
-#endif /* RSIMD_MATH_H */
-
diff --git a/src/math.h.in b/src/math.h.in
@@ -0,0 +1,24 @@
+/* Copyright (C) 2014-2019, 2021, 2023 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/>. */
+
+#ifndef RSIMD_MATH_H
+#define RSIMD_MATH_H
+
+#include <rsys/rsys.h>
+
+#include "math4.h"
+#include "math8.h"
+
+#endif /* RSIMD_MATH_H */
diff --git a/src/rsimd.h b/src/rsimd.h
@@ -1,36 +0,0 @@
-/* Copyright (C) 2014-2019, 2021, 2023 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/>. */
-
-#ifndef RSIMD_H
-#define RSIMD_H
-
-#include <rsys/rsys.h>
-
-#if defined(RSIMD_SHARED_BUILD)
- #define RSIMD_API extern EXPORT_SYM
-#elif defined(RSIMD_STATIC_BUILD)
- #define RSIMD_API extern LOCAL_SYM
-#else
- #define RSIMD_API extern IMPORT_SYM
-#endif
-
-#ifdef SIMD_SSE2
- #include "sse/sse.h"
-#endif
-#ifdef SIMD_AVX
- #include "avx/avx.h"
-#endif
-
-#endif /* RSIMD_H */
diff --git a/src/rsimd.h.in b/src/rsimd.h.in
@@ -0,0 +1,32 @@
+/* Copyright (C) 2014-2019, 2021, 2023 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/>. */
+
+#ifndef RSIMD_H
+#define RSIMD_H
+
+#include <rsys/rsys.h>
+
+#if defined(RSIMD_SHARED_BUILD)
+ #define RSIMD_API extern EXPORT_SYM
+#elif defined(RSIMD_STATIC_BUILD)
+ #define RSIMD_API extern LOCAL_SYM
+#else
+ #define RSIMD_API extern IMPORT_SYM
+#endif
+
+#include "sse/sse.h"
+#include "avx/avx.h"
+
+#endif /* RSIMD_H */