summaryrefslogtreecommitdiffstats
path: root/Tests/ISPC/CustomHeaderSuffix
diff options
context:
space:
mode:
authorRobert Maynard <robert.maynard@kitware.com>2020-12-10 21:08:24 (GMT)
committerBrad King <brad.king@kitware.com>2020-12-14 18:13:09 (GMT)
commitc9a50f35565dcc1df8bd82126ecced95e60c29e4 (patch)
treeede35e80def43d76af7378632f05115c0b43bea7 /Tests/ISPC/CustomHeaderSuffix
parent6aff058ab4a2d54a316dbaa536572ad71efb8b51 (diff)
downloadCMake-c9a50f35565dcc1df8bd82126ecced95e60c29e4.zip
CMake-c9a50f35565dcc1df8bd82126ecced95e60c29e4.tar.gz
CMake-c9a50f35565dcc1df8bd82126ecced95e60c29e4.tar.bz2
ISPC: Generated Headers suffix configurable with a better default
The target property `ISPC_HEADER_SUFFIX` and associated global variable now can control the suffix used when generating the C/C++ interoperability ISPC headers. In addition the default suffix is now "_ispc.h" which matches the common convention that the ISPC compiler team uses and recommends.
Diffstat (limited to 'Tests/ISPC/CustomHeaderSuffix')
-rw-r--r--Tests/ISPC/CustomHeaderSuffix/CMakeLists.txt23
-rw-r--r--Tests/ISPC/CustomHeaderSuffix/extra.cxx17
-rw-r--r--Tests/ISPC/CustomHeaderSuffix/extra.ispc12
-rw-r--r--Tests/ISPC/CustomHeaderSuffix/main.cxx15
-rw-r--r--Tests/ISPC/CustomHeaderSuffix/simple.ispc12
5 files changed, 79 insertions, 0 deletions
diff --git a/Tests/ISPC/CustomHeaderSuffix/CMakeLists.txt b/Tests/ISPC/CustomHeaderSuffix/CMakeLists.txt
new file mode 100644
index 0000000..d20f88e
--- /dev/null
+++ b/Tests/ISPC/CustomHeaderSuffix/CMakeLists.txt
@@ -0,0 +1,23 @@
+
+cmake_minimum_required(VERSION 3.18)
+project(ISPCCustomHeaderSuffix CXX ISPC)
+
+if(CMAKE_SIZEOF_VOID_P EQUAL 4)
+ set(CMAKE_ISPC_FLAGS "--arch=x86")
+endif()
+
+set(CMAKE_ISPC_INSTRUCTION_SETS "sse2-i32x4;sse4-i8x16")
+
+set(CMAKE_ISPC_HEADER_SUFFIX ".ispc.h")
+
+add_library(ispc_suffix_1 OBJECT simple.ispc)
+add_library(ispc_suffix_2 OBJECT extra.ispc)
+
+set_target_properties(ispc_suffix_2 PROPERTIES ISPC_HEADER_SUFFIX "___ispc.h")
+
+set_target_properties(ispc_suffix_1 ispc_suffix_2
+ PROPERTIES POSITION_INDEPENDENT_CODE ON
+)
+
+add_executable(ISPCCustomHeaderSuffix main.cxx extra.cxx)
+target_link_libraries(ISPCCustomHeaderSuffix PRIVATE ispc_suffix_1 ispc_suffix_2)
diff --git a/Tests/ISPC/CustomHeaderSuffix/extra.cxx b/Tests/ISPC/CustomHeaderSuffix/extra.cxx
new file mode 100644
index 0000000..0354e2d
--- /dev/null
+++ b/Tests/ISPC/CustomHeaderSuffix/extra.cxx
@@ -0,0 +1,17 @@
+#include <stdio.h>
+
+#include "extra___ispc.h"
+
+int extra()
+{
+ float vin[16], vout[16];
+ for (int i = 0; i < 16; ++i)
+ vin[i] = i;
+
+ ispc::extra(vin, vout, 16);
+
+ for (int i = 0; i < 16; ++i)
+ printf("%d: extra(%f) = %f\n", i, vin[i], vout[i]);
+
+ return 0;
+}
diff --git a/Tests/ISPC/CustomHeaderSuffix/extra.ispc b/Tests/ISPC/CustomHeaderSuffix/extra.ispc
new file mode 100644
index 0000000..5a4a442
--- /dev/null
+++ b/Tests/ISPC/CustomHeaderSuffix/extra.ispc
@@ -0,0 +1,12 @@
+
+export void extra(uniform float vin[], uniform float vout[],
+ uniform int count) {
+ foreach (index = 0 ... count) {
+ float v = vin[index];
+ if (v < 3.)
+ v = v * v;
+ else
+ v = sqrt(v);
+ vout[index] = v;
+ }
+}
diff --git a/Tests/ISPC/CustomHeaderSuffix/main.cxx b/Tests/ISPC/CustomHeaderSuffix/main.cxx
new file mode 100644
index 0000000..4f1c9be
--- /dev/null
+++ b/Tests/ISPC/CustomHeaderSuffix/main.cxx
@@ -0,0 +1,15 @@
+#include <stdio.h>
+
+#include "simple.ispc.h"
+
+int main()
+{
+ float vin[16], vout[16];
+ for (int i = 0; i < 16; ++i)
+ vin[i] = i;
+
+ ispc::simple(vin, vout, 16);
+
+ for (int i = 0; i < 16; ++i)
+ printf("%d: simple(%f) = %f\n", i, vin[i], vout[i]);
+}
diff --git a/Tests/ISPC/CustomHeaderSuffix/simple.ispc b/Tests/ISPC/CustomHeaderSuffix/simple.ispc
new file mode 100644
index 0000000..70cb588
--- /dev/null
+++ b/Tests/ISPC/CustomHeaderSuffix/simple.ispc
@@ -0,0 +1,12 @@
+
+export void simple(uniform float vin[], uniform float vout[],
+ uniform int count) {
+ foreach (index = 0 ... count) {
+ float v = vin[index];
+ if (v < 3.)
+ v = v * v;
+ else
+ v = sqrt(v);
+ vout[index] = v;
+ }
+}