From 4fc68ffe4950a80b24c849e4ac6729bb8f818a71 Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Mon, 20 Oct 2014 03:26:59 +0200 Subject: [PATCH] Replace function instanciations with macros by templates --- glm/detail/func_integer.hpp | 45 +++++----- glm/detail/func_integer.inl | 172 +++++++++--------------------------- glm/detail/type_mat2x2.hpp | 2 +- glm/detail/type_mat2x3.hpp | 2 +- glm/detail/type_mat2x4.hpp | 2 +- glm/detail/type_mat3x2.hpp | 2 +- glm/detail/type_mat3x3.hpp | 2 +- glm/detail/type_mat3x4.hpp | 2 +- glm/detail/type_mat4x2.hpp | 2 +- glm/detail/type_mat4x3.hpp | 2 +- glm/detail/type_mat4x4.hpp | 2 +- glm/detail/type_vec1.hpp | 2 +- glm/detail/type_vec2.hpp | 2 +- glm/detail/type_vec3.hpp | 2 +- glm/detail/type_vec4.hpp | 2 +- test/gtx/gtx_integer.cpp | 1 + 16 files changed, 81 insertions(+), 163 deletions(-) diff --git a/glm/detail/func_integer.hpp b/glm/detail/func_integer.hpp index 30544947..4dfcd0bd 100644 --- a/glm/detail/func_integer.hpp +++ b/glm/detail/func_integer.hpp @@ -38,6 +38,9 @@ #pragma once #include "setup.hpp" +#include "precision.hpp" +#include "func_common.hpp" +#include "func_vector_relational.hpp" namespace glm { @@ -113,13 +116,13 @@ namespace glm /// offset and bits is greater than the number of bits used /// to store the operand. /// - /// @tparam genIUType Signed or unsigned integer scalar or vector types. + /// @tparam T Signed or unsigned integer scalar or vector types. /// /// @see GLSL bitfieldExtract man page /// @see GLSL 4.20.8 specification, section 8.8 Integer Functions - template - GLM_FUNC_DECL genIUType bitfieldExtract( - genIUType const & Value, + template class vecType> + GLM_FUNC_DECL vecType bitfieldExtract( + vecType const & Value, int const & Offset, int const & Bits); @@ -133,14 +136,14 @@ namespace glm /// offset and bits is greater than the number of bits used to /// store the operand. /// - /// @tparam genIUType Signed or unsigned integer scalar or vector types. + /// @tparam T Signed or unsigned integer scalar or vector types. /// /// @see GLSL bitfieldInsert man page /// @see GLSL 4.20.8 specification, section 8.8 Integer Functions - template - GLM_FUNC_DECL genIUType bitfieldInsert( - genIUType const & Base, - genIUType const & Insert, + template class vecType> + GLM_FUNC_DECL vecType bitfieldInsert( + vecType const & Base, + vecType const & Insert, int const & Offset, int const & Bits); @@ -148,50 +151,50 @@ namespace glm /// The bit numbered n of the result will be taken from bit (bits - 1) - n of value, /// where bits is the total number of bits used to represent value. /// - /// @tparam genIUType Signed or unsigned integer scalar or vector types. + /// @tparam T Signed or unsigned integer scalar or vector types. /// /// @see GLSL bitfieldReverse man page /// @see GLSL 4.20.8 specification, section 8.8 Integer Functions - template - GLM_FUNC_DECL genIUType bitfieldReverse(genIUType const & Value); + template class vecType> + GLM_FUNC_DECL vecType bitfieldReverse(vecType const & v); /// Returns the number of bits set to 1 in the binary representation of value. /// - /// @tparam genIUType Signed or unsigned integer scalar or vector types. + /// @tparam T Signed or unsigned integer scalar or vector types. /// /// @see GLSL bitCount man page /// @see GLSL 4.20.8 specification, section 8.8 Integer Functions /// /// @todo Clarify the declaration to specify that scalars are suported. - template class genIUType> - GLM_FUNC_DECL typename genIUType::signed_type bitCount(genIUType const & Value); + template class vecType> + GLM_FUNC_DECL vecType bitCount(vecType const & v); /// Returns the bit number of the least significant bit set to /// 1 in the binary representation of value. /// If value is zero, -1 will be returned. /// - /// @tparam genIUType Signed or unsigned integer scalar or vector types. + /// @tparam T Signed or unsigned integer scalar or vector types. /// /// @see GLSL findLSB man page /// @see GLSL 4.20.8 specification, section 8.8 Integer Functions /// /// @todo Clarify the declaration to specify that scalars are suported. - template class genIUType> - GLM_FUNC_DECL typename genIUType::signed_type findLSB(genIUType const & Value); + template class vecType> + GLM_FUNC_DECL vecType findLSB(vecType const & v); /// Returns the bit number of the most significant bit in the binary representation of value. /// For positive integers, the result will be the bit number of the most significant bit set to 1. /// For negative integers, the result will be the bit number of the most significant /// bit set to 0. For a value of zero or negative one, -1 will be returned. /// - /// @tparam genIUType Signed or unsigned integer scalar or vector types. + /// @tparam T Signed or unsigned integer scalar or vector types. /// /// @see GLSL findMSB man page /// @see GLSL 4.20.8 specification, section 8.8 Integer Functions /// /// @todo Clarify the declaration to specify that scalars are suported. - template class genIUType> - GLM_FUNC_DECL typename genIUType::signed_type findMSB(genIUType const & Value); + template class vecType> + GLM_FUNC_DECL vecType findMSB(vecType const & v); /// @} }//namespace glm diff --git a/glm/detail/func_integer.inl b/glm/detail/func_integer.inl index e173b0f6..4b75bbb5 100644 --- a/glm/detail/func_integer.inl +++ b/glm/detail/func_integer.inl @@ -410,78 +410,57 @@ namespace glm } // bitfieldReverse - template - GLM_FUNC_QUALIFIER genIUType bitfieldReverse(genIUType const & Value) + template + GLM_FUNC_QUALIFIER T bitfieldReverse(T v) { - GLM_STATIC_ASSERT(std::numeric_limits::is_integer, "'bitfieldReverse' only accept integer values"); - - genIUType Out = 0; - std::size_t BitSize = sizeof(genIUType) * 8; - for(std::size_t i = 0; i < BitSize; ++i) - if(Value & (genIUType(1) << i)) - Out |= genIUType(1) << (BitSize - 1 - i); - return Out; - } + GLM_STATIC_ASSERT(std::numeric_limits::is_integer, "'bitfieldReverse' only accept integer values"); - VECTORIZE_VEC(bitfieldReverse) + return bitfieldReverse(tvec1(v)).x; + } - // bitCount - template - GLM_FUNC_QUALIFIER int bitCount(genIUType const & Value) + template class vecType> + GLM_FUNC_QUALIFIER vecType bitfieldReverse(vecType const & v) { - GLM_STATIC_ASSERT(std::numeric_limits::is_integer, "'bitCount' only accept integer values"); + GLM_STATIC_ASSERT(std::numeric_limits::is_integer, "'bitfieldReverse' only accept integer values"); - int Count = 0; - for(std::size_t i = 0; i < sizeof(genIUType) * std::size_t(8); ++i) + vecType Result(0); + vecType const Null(0); + T const BitSize = static_cast(sizeof(T) * 8); + for(T i = 0; i < BitSize; ++i) { - if(Value & (1 << i)) - ++Count; + vecType const BitSet(v & (static_cast(1) << i)); + vecType const BitFirst(BitSet >> i); + Result |= BitFirst << (BitSize - 1 - i); } - return Count; + return Result; } - template - GLM_FUNC_QUALIFIER tvec2 bitCount - ( - tvec2 const & value - ) + // bitCount + template + GLM_FUNC_QUALIFIER int bitCount(genIUType x) { - return tvec2( - bitCount(value[0]), - bitCount(value[1])); - } + GLM_STATIC_ASSERT(std::numeric_limits::is_integer, "'bitCount' only accept integer values"); - template - GLM_FUNC_QUALIFIER tvec3 bitCount - ( - tvec3 const & value - ) - { - return tvec3( - bitCount(value[0]), - bitCount(value[1]), - bitCount(value[2])); + return bitCount(tvec1(x)).x; } - template - GLM_FUNC_QUALIFIER tvec4 bitCount - ( - tvec4 const & value - ) + template class vecType> + GLM_FUNC_QUALIFIER vecType bitCount(vecType const & v) { - return tvec4( - bitCount(value[0]), - bitCount(value[1]), - bitCount(value[2]), - bitCount(value[3])); + GLM_STATIC_ASSERT(std::numeric_limits::is_integer, "'bitCount' only accept integer values"); + + vecType Count(0); + for(std::size_t i = 0; i < sizeof(T) * std::size_t(8); ++i) + { + if(v & (static_cast(1) << i)) + ++Count; + } + return Count; } // findLSB template - GLM_FUNC_QUALIFIER int findLSB - ( - genIUType const & Value - ) + GLM_FUNC_QUALIFIER int findLSB(genIUType Value) { GLM_STATIC_ASSERT(std::numeric_limits::is_integer, "'findLSB' only accept integer values"); if(Value == 0) @@ -492,50 +471,19 @@ namespace glm return Bit; } - template - GLM_FUNC_QUALIFIER tvec2 findLSB - ( - tvec2 const & value - ) - { - return tvec2( - findLSB(value[0]), - findLSB(value[1])); - } - - template - GLM_FUNC_QUALIFIER tvec3 findLSB - ( - tvec3 const & value - ) + template class vecType> + GLM_FUNC_QUALIFIER vecType findLSB(vecType const & x) { - return tvec3( - findLSB(value[0]), - findLSB(value[1]), - findLSB(value[2])); - } + GLM_STATIC_ASSERT(std::numeric_limits::is_integer, "'findLSB' only accept integer values"); - template - GLM_FUNC_QUALIFIER tvec4 findLSB - ( - tvec4 const & value - ) - { - return tvec4( - findLSB(value[0]), - findLSB(value[1]), - findLSB(value[2]), - findLSB(value[3])); + return detail::functor1::call(findLSB, x); } // findMSB -#if((GLM_ARCH != GLM_ARCH_PURE) && (GLM_COMPILER & GLM_COMPILER_VC)) +#if (GLM_ARCH != GLM_ARCH_PURE) && (GLM_COMPILER & GLM_COMPILER_VC) template - GLM_FUNC_QUALIFIER int findMSB - ( - genIUType const & Value - ) + GLM_FUNC_QUALIFIER int findMSB(genIUType Value) { GLM_STATIC_ASSERT(std::numeric_limits::is_integer, "'findMSB' only accept integer values"); if(Value == 0) @@ -585,14 +533,10 @@ namespace glm Mmi = _mm_and_si128(Mmi, One); } return Bit; - */ template - GLM_FUNC_QUALIFIER int findMSB - ( - genIUType const & Value - ) + GLM_FUNC_QUALIFIER int findMSB(genIUType Value) { GLM_STATIC_ASSERT(std::numeric_limits::is_integer, "'findMSB' only accept integer values"); @@ -616,39 +560,9 @@ namespace glm } #endif//(GLM_COMPILER) - template - GLM_FUNC_QUALIFIER tvec2 findMSB - ( - tvec2 const & value - ) - { - return tvec2( - findMSB(value[0]), - findMSB(value[1])); - } - - template - GLM_FUNC_QUALIFIER tvec3 findMSB - ( - tvec3 const & value - ) - { - return tvec3( - findMSB(value[0]), - findMSB(value[1]), - findMSB(value[2])); - } - - template - GLM_FUNC_QUALIFIER tvec4 findMSB - ( - tvec4 const & value - ) + template class vecType> + GLM_FUNC_QUALIFIER vecType findMSB(vecType const & x) { - return tvec4( - findMSB(value[0]), - findMSB(value[1]), - findMSB(value[2]), - findMSB(value[3])); + return detail::functor1::call(findMSB, x); } }//namespace glm diff --git a/glm/detail/type_mat2x2.hpp b/glm/detail/type_mat2x2.hpp index d8974644..c17fdc9c 100644 --- a/glm/detail/type_mat2x2.hpp +++ b/glm/detail/type_mat2x2.hpp @@ -36,7 +36,7 @@ namespace glm { - template + template struct tmat2x2 { typedef T value_type; diff --git a/glm/detail/type_mat2x3.hpp b/glm/detail/type_mat2x3.hpp index fb8695e0..f60282d3 100644 --- a/glm/detail/type_mat2x3.hpp +++ b/glm/detail/type_mat2x3.hpp @@ -37,7 +37,7 @@ namespace glm { - template + template struct tmat2x3 { typedef T value_type; diff --git a/glm/detail/type_mat2x4.hpp b/glm/detail/type_mat2x4.hpp index b6ee9abd..28066c04 100644 --- a/glm/detail/type_mat2x4.hpp +++ b/glm/detail/type_mat2x4.hpp @@ -37,7 +37,7 @@ namespace glm { - template + template struct tmat2x4 { typedef T value_type; diff --git a/glm/detail/type_mat3x2.hpp b/glm/detail/type_mat3x2.hpp index a9f3199c..a09dca98 100644 --- a/glm/detail/type_mat3x2.hpp +++ b/glm/detail/type_mat3x2.hpp @@ -37,7 +37,7 @@ namespace glm { - template + template struct tmat3x2 { typedef T value_type; diff --git a/glm/detail/type_mat3x3.hpp b/glm/detail/type_mat3x3.hpp index f5d6d370..d85ea5aa 100644 --- a/glm/detail/type_mat3x3.hpp +++ b/glm/detail/type_mat3x3.hpp @@ -36,7 +36,7 @@ namespace glm { - template + template struct tmat3x3 { typedef T value_type; diff --git a/glm/detail/type_mat3x4.hpp b/glm/detail/type_mat3x4.hpp index 8cf0fd68..c7017704 100644 --- a/glm/detail/type_mat3x4.hpp +++ b/glm/detail/type_mat3x4.hpp @@ -37,7 +37,7 @@ namespace glm { - template + template struct tmat3x4 { typedef T value_type; diff --git a/glm/detail/type_mat4x2.hpp b/glm/detail/type_mat4x2.hpp index 6247cda9..27097298 100644 --- a/glm/detail/type_mat4x2.hpp +++ b/glm/detail/type_mat4x2.hpp @@ -37,7 +37,7 @@ namespace glm { - template + template struct tmat4x2 { typedef T value_type; diff --git a/glm/detail/type_mat4x3.hpp b/glm/detail/type_mat4x3.hpp index 12a47c63..ad7f015f 100644 --- a/glm/detail/type_mat4x3.hpp +++ b/glm/detail/type_mat4x3.hpp @@ -37,7 +37,7 @@ namespace glm { - template + template struct tmat4x3 { typedef T value_type; diff --git a/glm/detail/type_mat4x4.hpp b/glm/detail/type_mat4x4.hpp index 6034f0c7..cdbfd3d4 100644 --- a/glm/detail/type_mat4x4.hpp +++ b/glm/detail/type_mat4x4.hpp @@ -36,7 +36,7 @@ namespace glm { - template + template struct tmat4x4 { typedef T value_type; diff --git a/glm/detail/type_vec1.hpp b/glm/detail/type_vec1.hpp index cbff04fa..ab8db882 100644 --- a/glm/detail/type_vec1.hpp +++ b/glm/detail/type_vec1.hpp @@ -41,7 +41,7 @@ namespace glm { - template + template struct tvec1 { ////////////////////////////////////// diff --git a/glm/detail/type_vec2.hpp b/glm/detail/type_vec2.hpp index d08de1e4..5817a2f6 100644 --- a/glm/detail/type_vec2.hpp +++ b/glm/detail/type_vec2.hpp @@ -41,7 +41,7 @@ namespace glm { - template + template struct tvec2 { ////////////////////////////////////// diff --git a/glm/detail/type_vec3.hpp b/glm/detail/type_vec3.hpp index bc15448e..920d8acb 100644 --- a/glm/detail/type_vec3.hpp +++ b/glm/detail/type_vec3.hpp @@ -41,7 +41,7 @@ namespace glm { - template + template struct tvec3 { ////////////////////////////////////// diff --git a/glm/detail/type_vec4.hpp b/glm/detail/type_vec4.hpp index 01e85328..51082837 100644 --- a/glm/detail/type_vec4.hpp +++ b/glm/detail/type_vec4.hpp @@ -66,7 +66,7 @@ namespace detail # endif }//namespace detail - template + template struct tvec4 { ////////////////////////////////////// diff --git a/test/gtx/gtx_integer.cpp b/test/gtx/gtx_integer.cpp index 9fd9d1e0..fd41c0b6 100644 --- a/test/gtx/gtx_integer.cpp +++ b/test/gtx/gtx_integer.cpp @@ -70,3 +70,4 @@ int main() return Error; } +