From 1d9a9dd1c68d54b66a12875e54517c3b28ade562 Mon Sep 17 00:00:00 2001 From: Robert Maynard Date: Wed, 17 Jan 2018 09:57:51 -0500 Subject: [PATCH] Simplify VTK-m detection of the size of different types. Most of the code was unneeded as the primitive types have a minimum required size that we can rely on. --- CMakeLists.txt | 5 -- vtkm/Math.h | 4 -- vtkm/Math.h.in | 4 -- vtkm/Types.h | 63 ++++--------------- vtkm/internal/Configure.h.in | 38 ----------- .../testing/UnitTestConfigureFor32.cxx | 10 ++- .../testing/UnitTestConfigureFor64.cxx | 10 ++- 7 files changed, 20 insertions(+), 114 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d947668e8..5e84ecaf9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -180,11 +180,6 @@ endif (VTKm_ENABLE_TESTING) # Check basic type sizes. include(CheckTypeSize) -check_type_size(float VTKm_SIZE_FLOAT BUILTIN_TYPES_ONLY) -check_type_size(double VTKm_SIZE_DOUBLE BUILTIN_TYPES_ONLY) -check_type_size(char VTKm_SIZE_CHAR BUILTIN_TYPES_ONLY) -check_type_size(short VTKm_SIZE_SHORT BUILTIN_TYPES_ONLY) -check_type_size(int VTKm_SIZE_INT BUILTIN_TYPES_ONLY) check_type_size(long VTKm_SIZE_LONG BUILTIN_TYPES_ONLY) check_type_size("long long" VTKm_SIZE_LONG_LONG BUILTIN_TYPES_ONLY) diff --git a/vtkm/Math.h b/vtkm/Math.h index 1163a7ae0..330607d24 100644 --- a/vtkm/Math.h +++ b/vtkm/Math.h @@ -2309,11 +2309,7 @@ static inline VTKM_EXEC_CONT vtkm::Float64 ModF(vtkm::Float64 x, vtkm::Float64& /// static inline VTKM_EXEC_CONT vtkm::Int32 Abs(vtkm::Int32 x) { -#if VTKM_SIZE_INT == 4 return abs(x); -#else -#error Unknown size of Int32. -#endif } static inline VTKM_EXEC_CONT vtkm::Int64 Abs(vtkm::Int64 x) { diff --git a/vtkm/Math.h.in b/vtkm/Math.h.in index 245b53580..54a258521 100644 --- a/vtkm/Math.h.in +++ b/vtkm/Math.h.in @@ -964,11 +964,7 @@ static inline VTKM_EXEC_CONT vtkm::Float64 ModF(vtkm::Float64 x, vtkm::Float64& /// static inline VTKM_EXEC_CONT vtkm::Int32 Abs(vtkm::Int32 x) { -#if VTKM_SIZE_INT == 4 return abs(x); -#else -#error Unknown size of Int32. -#endif } static inline VTKM_EXEC_CONT vtkm::Int64 Abs(vtkm::Int64 x) { diff --git a/vtkm/Types.h b/vtkm/Types.h index 684659df8..939a4ef38 100644 --- a/vtkm/Types.h +++ b/vtkm/Types.h @@ -143,39 +143,21 @@ namespace vtkm //***************************************************************************** // Typedefs for basic types. //***************************************************************************** - -#if VTKM_SIZE_FLOAT == 4 using Float32 = float; -#else -#error Could not find a 32-bit float. -#endif - -#if VTKM_SIZE_DOUBLE == 8 using Float64 = double; -#else -#error Could not find a 64-bit float. -#endif - -#if VTKM_SIZE_CHAR == 1 using Int8 = signed char; using UInt8 = unsigned char; -#else -#error Could not find an 8-bit integer. -#endif - -#if VTKM_SIZE_SHORT == 2 using Int16 = short; using UInt16 = unsigned short; -#else -#error Could not find a 16-bit integer. -#endif - -#if VTKM_SIZE_INT == 4 using Int32 = int; using UInt32 = unsigned int; -#else -#error Could not find a 32-bit integer. -#endif + +/// Represents a component ID (index of component in a vector). The number +/// of components, being a value fixed at compile time, is generally assumed +/// to be quite small. However, we are currently using a 32-bit width +/// integer because modern processors tend to access them more efficiently +/// than smaller widths. +using IdComponent = vtkm::Int32; //In this order so that we exactly match the logic that exists in VTK #if VTKM_SIZE_LONG_LONG == 8 @@ -188,40 +170,19 @@ using UInt64 = unsigned long; #error Could not find a 64-bit integer. #endif -//----------------------------------------------------------------------------- - -#if VTKM_SIZE_ID == 4 - /// Represents an ID (index into arrays). -using Id = vtkm::Int32; - -#elif VTKM_SIZE_ID == 8 - -/// Represents an ID. +#ifdef VTKM_USE_64BIT_IDS using Id = vtkm::Int64; - #else -#error Unknown Id Size +using Id = vtkm::Int32; #endif -/// Represents a component ID (index of component in a vector). The number -/// of components, being a value fixed at compile time, is generally assumed -/// to be quite small. However, we are currently using a 32-bit width -/// integer because modern processors tend to access them more efficiently -/// than smaller widths. -using IdComponent = vtkm::Int32; - +/// The floating point type to use when no other precision is specified. #ifdef VTKM_USE_DOUBLE_PRECISION - -/// The floating point type to use when no other precision is specified. using FloatDefault = vtkm::Float64; - -#else //VTKM_USE_DOUBLE_PRECISION - -/// The floating point type to use when no other precision is specified. +#else using FloatDefault = vtkm::Float32; - -#endif //VTKM_USE_DOUBLE_PRECISION +#endif namespace internal { diff --git a/vtkm/internal/Configure.h.in b/vtkm/internal/Configure.h.in index 95b166b63..c8d0618c2 100644 --- a/vtkm/internal/Configure.h.in +++ b/vtkm/internal/Configure.h.in @@ -82,47 +82,9 @@ # error Both VTKM_USE_64BIT_IDS and VTKM_NO_64BIT_IDS defined. Do not know what to do. #endif -#define VTKM_SIZE_FLOAT @VTKm_SIZE_FLOAT@ -#define VTKM_SIZE_DOUBLE @VTKm_SIZE_DOUBLE@ -#define VTKM_SIZE_CHAR @VTKm_SIZE_CHAR@ -#define VTKM_SIZE_SHORT @VTKm_SIZE_SHORT@ -#define VTKM_SIZE_INT @VTKm_SIZE_INT@ #define VTKM_SIZE_LONG @VTKm_SIZE_LONG@ #define VTKM_SIZE_LONG_LONG @VTKm_SIZE_LONG_LONG@ -#ifdef VTKM_USE_DOUBLE_PRECISION -# ifndef VTKM_SIZE_SCALAR -# define VTKM_SIZE_SCALAR VTKM_SIZE_DOUBLE -# endif -# ifndef VTKM_ALIGNMENT_TWO_SCALAR -# define VTKM_ALIGNMENT_TWO_SCALAR 16 -# endif -# ifndef VTKM_ALIGNMENT_FOUR_SCALAR -# define VTKM_ALIGNMENT_FOUR_SCALAR 8 -# endif -#else -# ifndef VTKM_SIZE_SCALAR -# define VTKM_SIZE_SCALAR VTKM_SIZE_FLOAT -# define VTKM_ALIGNMENT_SCALAR VTKM_SIZE_SCALAR -# endif -# ifndef VTKM_ALIGNMENT_TWO_SCALAR -# define VTKM_ALIGNMENT_TWO_SCALAR 8 -# endif -# ifndef VTKM_ALIGNMENT_FOUR_SCALAR -# define VTKM_ALIGNMENT_FOUR_SCALAR 16 -# endif -#endif - -#ifdef VTKM_USE_64BIT_IDS -# ifndef VTKM_SIZE_ID -# define VTKM_SIZE_ID 8 -# endif -#else -# ifndef VTKM_SIZE_ID -# define VTKM_SIZE_ID 4 -# endif -#endif - // Define a pair of macros, VTKM_THIRDPARTY_PRE_INCLUDE and VTKM_THIRDPARTY_POST_INCLUDE, // that should be wrapped around any #include for a tbb or thrust header file. Mostly // this is used to set pragmas that dissable warnings that VTK-m checks for diff --git a/vtkm/internal/testing/UnitTestConfigureFor32.cxx b/vtkm/internal/testing/UnitTestConfigureFor32.cxx index e410a716b..d176031ed 100644 --- a/vtkm/internal/testing/UnitTestConfigureFor32.cxx +++ b/vtkm/internal/testing/UnitTestConfigureFor32.cxx @@ -27,12 +27,12 @@ // Size of 32 bits. #define EXPECTED_SIZE 4 -#if VTKM_SIZE_ID != EXPECTED_SIZE -#error VTKM_SIZE_ID an unexpected size. +#if defined(VTKM_USE_64BIT_IDS) +#error vtkm::Id an unexpected size. #endif -#if VTKM_SIZE_SCALAR != EXPECTED_SIZE -#error VTKM_SIZE_SCALAR an unexpected size. +#if defined(VTKM_USE_DOUBLE_PRECISION) +#error vtkm::FloatDefault an unexpected size. #endif namespace @@ -40,9 +40,7 @@ namespace void TestTypeSizes() { - VTKM_TEST_ASSERT(VTKM_SIZE_ID == EXPECTED_SIZE, "VTKM_SIZE_ID an unexpected size."); VTKM_TEST_ASSERT(sizeof(vtkm::Id) == EXPECTED_SIZE, "vtkm::Id an unexpected size."); - VTKM_TEST_ASSERT(VTKM_SIZE_SCALAR == EXPECTED_SIZE, "VTKM_SIZE_SCALAR an unexpected size."); VTKM_TEST_ASSERT(sizeof(vtkm::FloatDefault) == EXPECTED_SIZE, "vtkm::FloatDefault an unexpected size."); } diff --git a/vtkm/internal/testing/UnitTestConfigureFor64.cxx b/vtkm/internal/testing/UnitTestConfigureFor64.cxx index 9edf0de03..9aaac2120 100644 --- a/vtkm/internal/testing/UnitTestConfigureFor64.cxx +++ b/vtkm/internal/testing/UnitTestConfigureFor64.cxx @@ -27,12 +27,12 @@ // Size of 64 bits. #define EXPECTED_SIZE 8 -#if VTKM_SIZE_ID != EXPECTED_SIZE -#error VTKM_SIZE_ID an unexpected size. +#if defined(VTKM_NO_64BIT_IDS) +#error vtkm::Id an unexpected size. #endif -#if VTKM_SIZE_SCALAR != EXPECTED_SIZE -#error VTKM_SIZE_SCALAR an unexpected size. +#if defined(VTKM_NO_DOUBLE_PRECISION) +#error vtkm::FloatDefault an unexpected size. #endif namespace @@ -40,9 +40,7 @@ namespace void TestTypeSizes() { - VTKM_TEST_ASSERT(VTKM_SIZE_ID == EXPECTED_SIZE, "VTKM_SIZE_ID an unexpected size."); VTKM_TEST_ASSERT(sizeof(vtkm::Id) == EXPECTED_SIZE, "vtkm::Id an unexpected size."); - VTKM_TEST_ASSERT(VTKM_SIZE_SCALAR == EXPECTED_SIZE, "VTKM_SIZE_SCALAR an unexpected size."); VTKM_TEST_ASSERT(sizeof(vtkm::FloatDefault) == EXPECTED_SIZE, "vtkm::FloatDefault an unexpected size."); }