summaryrefslogtreecommitdiffstats
path: root/Tests/ISPC/ObjectGenex
diff options
context:
space:
mode:
authorRobert Maynard <robert.maynard@kitware.com>2020-07-28 18:52:36 (GMT)
committerRobert Maynard <robert.maynard@kitware.com>2020-09-04 12:37:07 (GMT)
commita020787a9b7ede3aa490345bd446e469fb1713d2 (patch)
treef96ef2b1d84515fda4288ffaf39e9abfb8c9cc1a /Tests/ISPC/ObjectGenex
parent5a1750017e65727660167ae1953746a3fd3d2c7b (diff)
downloadCMake-a020787a9b7ede3aa490345bd446e469fb1713d2.zip
CMake-a020787a9b7ede3aa490345bd446e469fb1713d2.tar.gz
CMake-a020787a9b7ede3aa490345bd446e469fb1713d2.tar.bz2
ISPC: Support generation for multiple instruction sets
Diffstat (limited to 'Tests/ISPC/ObjectGenex')
-rw-r--r--Tests/ISPC/ObjectGenex/CMakeLists.txt45
-rw-r--r--Tests/ISPC/ObjectGenex/main.cxx87
-rw-r--r--Tests/ISPC/ObjectGenex/simple.ispc12
3 files changed, 144 insertions, 0 deletions
diff --git a/Tests/ISPC/ObjectGenex/CMakeLists.txt b/Tests/ISPC/ObjectGenex/CMakeLists.txt
new file mode 100644
index 0000000..bc0cbf6
--- /dev/null
+++ b/Tests/ISPC/ObjectGenex/CMakeLists.txt
@@ -0,0 +1,45 @@
+cmake_minimum_required(VERSION 3.18)
+project(ISPCObjectGenex CXX ISPC)
+
+set(CMAKE_ISPC_INSTRUCTION_SETS "sse2-i32x4;sse4-i16x8;avx1-i32x16;avx2-i32x4;avx512knl-i32x16;avx512skx-i32x8")
+
+add_library(ispc_objects OBJECT
+ simple.ispc
+ )
+target_compile_definitions(ispc_objects PRIVATE
+ $<$<COMPILE_LANG_AND_ID:ISPC,Intel>:M_PI=3.1415926535f>
+)
+set_target_properties(ispc_objects PROPERTIES POSITION_INDEPENDENT_CODE ON)
+if(CMAKE_SIZEOF_VOID_P EQUAL 4)
+ set_source_files_properties(simple.ispc PROPERTIES COMPILE_OPTIONS "--arch=x86")
+endif()
+
+
+#Test ObjectFiles with file(GENERATE)
+file(GENERATE
+ OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/gen_$<LOWER_CASE:$<CONFIG>/>path_to_objs.h
+ CONTENT [[
+#ifndef path_to_objs
+#define path_to_objs
+
+#include <string>
+
+static std::string obj_paths = "$<TARGET_OBJECTS:ispc_objects>";
+
+#endif
+
+]]
+)
+
+
+add_executable(ISPCObjectGenex main.cxx)
+add_dependencies(ISPCObjectGenex ispc_objects)
+
+list(LENGTH CMAKE_ISPC_INSTRUCTION_SETS numberOfTargets)
+math(EXPR numberOfTargets "${numberOfTargets}+1")
+target_compile_definitions(ISPCObjectGenex PRIVATE
+ "ExpectedISPCObjects=${numberOfTargets}"
+ "CONFIG_TYPE=gen_$<LOWER_CASE:$<CONFIG>>"
+ )
+target_include_directories(ISPCObjectGenex PRIVATE ${CMAKE_CURRENT_BINARY_DIR} )
+target_compile_features(ISPCObjectGenex PRIVATE cxx_std_11)
diff --git a/Tests/ISPC/ObjectGenex/main.cxx b/Tests/ISPC/ObjectGenex/main.cxx
new file mode 100644
index 0000000..143e74e
--- /dev/null
+++ b/Tests/ISPC/ObjectGenex/main.cxx
@@ -0,0 +1,87 @@
+#include <stdio.h>
+
+/*
+ Define GENERATED_HEADER macro to allow c++ files to include headers
+ generated based on different configuration types.
+*/
+
+/* clang-format off */
+#define GENERATED_HEADER(x) GENERATED_HEADER0(CONFIG_TYPE/x)
+/* clang-format on */
+#define GENERATED_HEADER0(x) GENERATED_HEADER1(x)
+#define GENERATED_HEADER1(x) <x>
+
+#include GENERATED_HEADER(path_to_objs.h)
+
+#include <vector>
+std::vector<std::string> expandList(std::string const& arg)
+{
+ std::vector<std::string> output;
+ // If argument is empty or no `;` just copy the current string
+ if (arg.empty() || arg.find(';') == std::string::npos) {
+ output.emplace_back(arg);
+ return output;
+ }
+
+ std::string newArg;
+ // Break the string at non-escaped semicolons not nested in [].
+ int squareNesting = 0;
+ auto last = arg.begin();
+ auto const cend = arg.end();
+ for (auto c = last; c != cend; ++c) {
+ switch (*c) {
+ case '\\': {
+ // We only want to allow escaping of semicolons. Other
+ // escapes should not be processed here.
+ auto cnext = c + 1;
+ if ((cnext != cend) && *cnext == ';') {
+ newArg.append(last, c);
+ // Skip over the escape character
+ last = cnext;
+ c = cnext;
+ }
+ } break;
+ case '[': {
+ ++squareNesting;
+ } break;
+ case ']': {
+ --squareNesting;
+ } break;
+ case ';': {
+ // Break the string here if we are not nested inside square
+ // brackets.
+ if (squareNesting == 0) {
+ newArg.append(last, c);
+ // Skip over the semicolon
+ last = c + 1;
+ if (!newArg.empty()) {
+ // Add the last argument if the string is not empty.
+ output.push_back(newArg);
+ newArg.clear();
+ }
+ }
+ } break;
+ default: {
+ // Just append this character.
+ } break;
+ }
+ }
+ newArg.append(last, cend);
+ if (!newArg.empty()) {
+ // Add the last argument if the string is not empty.
+ output.push_back(std::move(newArg));
+ }
+
+ return output;
+}
+
+int main()
+{
+ // determine that the number of object files specified in obj_paths
+ // is equal to the number of arch's
+
+ std::vector<std::string> paths = expandList(obj_paths);
+ const bool correctSize = (paths.size() == ExpectedISPCObjects);
+
+ return (correctSize) ? 0 : 1;
+}
diff --git a/Tests/ISPC/ObjectGenex/simple.ispc b/Tests/ISPC/ObjectGenex/simple.ispc
new file mode 100644
index 0000000..a76b76c
--- /dev/null
+++ b/Tests/ISPC/ObjectGenex/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 < M_PI)
+ v = v * v;
+ else
+ v = sqrt(v);
+ vout[index] = v;
+ }
+}