Vectorization of usubBorrow and umulExtended, simplified vector relational code

This commit is contained in:
Christophe Riccio 2014-10-21 01:32:45 +02:00
parent c23cb8cd59
commit fcfc56d5e3
4 changed files with 46 additions and 150 deletions

View File

@ -69,11 +69,11 @@ namespace glm
/// ///
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/usubBorrow.xml">GLSL usubBorrow man page</a> /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/usubBorrow.xml">GLSL usubBorrow man page</a>
/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.8 Integer Functions</a> /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.8 Integer Functions</a>
template <typename genUType> template <precision P, template <typename, precision> class vecType>
GLM_FUNC_DECL genUType usubBorrow( GLM_FUNC_DECL vecType<uint, P> usubBorrow(
genUType const & x, vecType<uint, P> const & x,
genUType const & y, vecType<uint, P> const & y,
genUType & borrow); vecType<uint, P> & borrow);
/// Multiplies 32-bit integers x and y, producing a 64-bit /// Multiplies 32-bit integers x and y, producing a 64-bit
/// result. The 32 least-significant bits are returned in lsb. /// result. The 32 least-significant bits are returned in lsb.
@ -83,12 +83,12 @@ namespace glm
/// ///
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/umulExtended.xml">GLSL umulExtended man page</a> /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/umulExtended.xml">GLSL umulExtended man page</a>
/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.8 Integer Functions</a> /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.8 Integer Functions</a>
template <typename genUType> template <precision P, template <typename, precision> class vecType>
GLM_FUNC_DECL void umulExtended( GLM_FUNC_DECL void umulExtended(
genUType const & x, vecType<uint, P> const & x,
genUType const & y, vecType<uint, P> const & y,
genUType & msb, vecType<uint, P> & msb,
genUType & lsb); vecType<uint, P> & lsb);
/// Multiplies 32-bit integers x and y, producing a 64-bit /// Multiplies 32-bit integers x and y, producing a 64-bit
/// result. The 32 least-significant bits are returned in lsb. /// result. The 32 least-significant bits are returned in lsb.

View File

@ -99,13 +99,7 @@ namespace glm
} }
// usubBorrow // usubBorrow
template <> GLM_FUNC_QUALIFIER uint usubBorrow(uint const & x, uint const & y, uint & Borrow)
GLM_FUNC_QUALIFIER uint usubBorrow
(
uint const & x,
uint const & y,
uint & Borrow
)
{ {
GLM_STATIC_ASSERT(sizeof(uint) == sizeof(uint32), "uint and uint32 size mismatch"); GLM_STATIC_ASSERT(sizeof(uint) == sizeof(uint32), "uint and uint32 size mismatch");
@ -116,57 +110,17 @@ namespace glm
return static_cast<uint32>((static_cast<int64>(1) << static_cast<int64>(32)) + (static_cast<int64>(y) - static_cast<int64>(x))); return static_cast<uint32>((static_cast<int64>(1) << static_cast<int64>(32)) + (static_cast<int64>(y) - static_cast<int64>(x)));
} }
template <> template <precision P, template <typename, precision> class vecType>
GLM_FUNC_QUALIFIER uvec2 usubBorrow GLM_FUNC_QUALIFIER vecType<uint, P> usubBorrow(vecType<uint, P> const & x, vecType<uint, P> const & y, vecType<uint, P> & Borrow)
(
uvec2 const & x,
uvec2 const & y,
uvec2 & Borrow
)
{ {
return uvec2( Borrow = mix(vecType<uint, P>(1), vecType<uint, P>(0), greaterThanEqual(x, y));
usubBorrow(x[0], y[0], Borrow[0]), vecType<uint, P> const YgeX(y - x);
usubBorrow(x[1], y[1], Borrow[1])); vecType<uint, P> const XgeY(vecType<uint32, P>((static_cast<int64>(1) << static_cast<int64>(32)) + (vecType<int64, P>(y) - vecType<int64, P>(x))));
} return mix(XgeY, YgeX, y >= x);
template <>
GLM_FUNC_QUALIFIER uvec3 usubBorrow
(
uvec3 const & x,
uvec3 const & y,
uvec3 & Borrow
)
{
return uvec3(
usubBorrow(x[0], y[0], Borrow[0]),
usubBorrow(x[1], y[1], Borrow[1]),
usubBorrow(x[2], y[2], Borrow[2]));
}
template <>
GLM_FUNC_QUALIFIER uvec4 usubBorrow
(
uvec4 const & x,
uvec4 const & y,
uvec4 & Borrow
)
{
return uvec4(
usubBorrow(x[0], y[0], Borrow[0]),
usubBorrow(x[1], y[1], Borrow[1]),
usubBorrow(x[2], y[2], Borrow[2]),
usubBorrow(x[3], y[3], Borrow[3]));
} }
// umulExtended // umulExtended
template <> GLM_FUNC_QUALIFIER void umulExtended(uint const & x, uint const & y, uint & msb, uint & lsb)
GLM_FUNC_QUALIFIER void umulExtended
(
uint const & x,
uint const & y,
uint & msb,
uint & lsb
)
{ {
GLM_STATIC_ASSERT(sizeof(uint) == sizeof(uint32), "uint and uint32 size mismatch"); GLM_STATIC_ASSERT(sizeof(uint) == sizeof(uint32), "uint and uint32 size mismatch");
@ -177,46 +131,14 @@ namespace glm
lsb = *PointerLSB; lsb = *PointerLSB;
} }
template <> template <precision P, template <typename, precision> class vecType>
GLM_FUNC_QUALIFIER void umulExtended GLM_FUNC_QUALIFIER void umulExtended(vecType<uint, P> const & x, vecType<uint, P> const & y, vecType<uint, P> & msb, vecType<uint, P> & lsb)
(
uvec2 const & x,
uvec2 const & y,
uvec2 & msb,
uvec2 & lsb
)
{ {
umulExtended(x[0], y[0], msb[0], lsb[0]); GLM_STATIC_ASSERT(sizeof(uint) == sizeof(uint32), "uint and uint32 size mismatch");
umulExtended(x[1], y[1], msb[1], lsb[1]);
}
template <> vecType<uint64, P> Value64(vecType<uint64, P>(x) * vecType<uint64, P>(y));
GLM_FUNC_QUALIFIER void umulExtended msb = vecType<uint32, P>(Value64 >> static_cast<uint64>(32));
( lsb = vecType<uint32, P>(Value64);
uvec3 const & x,
uvec3 const & y,
uvec3 & msb,
uvec3 & lsb
)
{
umulExtended(x[0], y[0], msb[0], lsb[0]);
umulExtended(x[1], y[1], msb[1], lsb[1]);
umulExtended(x[2], y[2], msb[2], lsb[2]);
}
template <>
GLM_FUNC_QUALIFIER void umulExtended
(
uvec4 const & x,
uvec4 const & y,
uvec4 & msb,
uvec4 & lsb
)
{
umulExtended(x[0], y[0], msb[0], lsb[0]);
umulExtended(x[1], y[1], msb[1], lsb[1]);
umulExtended(x[2], y[2], msb[2], lsb[2]);
umulExtended(x[3], y[3], msb[3], lsb[3]);
} }
// imulExtended // imulExtended

View File

@ -56,9 +56,8 @@ namespace glm
/// ///
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/lessThan.xml">GLSL lessThan man page</a> /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/lessThan.xml">GLSL lessThan man page</a>
/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.7 Vector Relational Functions</a> /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.7 Vector Relational Functions</a>
// TODO: Mismatched template <typename T, precision P, template <typename, precision> class vecType>
//template <typename T, precision P, template <typename, precision> class vecType> GLM_FUNC_DECL vecType<bool, P> lessThan(vecType<T, P> const & x, vecType<T, P> const & y);
//GLM_FUNC_DECL typename vecType<T, P>::bool_type lessThan(vecType<T, P> const & x, vecType<T, P> const & y);
/// Returns the component-wise comparison of result x <= y. /// Returns the component-wise comparison of result x <= y.
/// ///
@ -67,7 +66,7 @@ namespace glm
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/lessThanEqual.xml">GLSL lessThanEqual man page</a> /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/lessThanEqual.xml">GLSL lessThanEqual man page</a>
/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.7 Vector Relational Functions</a> /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.7 Vector Relational Functions</a>
template <typename T, precision P, template <typename, precision> class vecType> template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_DECL typename vecType<T, P>::bool_type lessThanEqual(vecType<T, P> const & x, vecType<T, P> const & y); GLM_FUNC_DECL vecType<bool, P> lessThanEqual(vecType<T, P> const & x, vecType<T, P> const & y);
/// Returns the component-wise comparison of result x > y. /// Returns the component-wise comparison of result x > y.
/// ///
@ -76,7 +75,7 @@ namespace glm
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/greaterThan.xml">GLSL greaterThan man page</a> /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/greaterThan.xml">GLSL greaterThan man page</a>
/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.7 Vector Relational Functions</a> /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.7 Vector Relational Functions</a>
template <typename T, precision P, template <typename, precision> class vecType> template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_DECL typename vecType<T, P>::bool_type greaterThan(vecType<T, P> const & x, vecType<T, P> const & y); GLM_FUNC_DECL vecType<bool, P> greaterThan(vecType<T, P> const & x, vecType<T, P> const & y);
/// Returns the component-wise comparison of result x >= y. /// Returns the component-wise comparison of result x >= y.
/// ///
@ -85,7 +84,7 @@ namespace glm
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/greaterThanEqual.xml">GLSL greaterThanEqual man page</a> /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/greaterThanEqual.xml">GLSL greaterThanEqual man page</a>
/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.7 Vector Relational Functions</a> /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.7 Vector Relational Functions</a>
template <typename T, precision P, template <typename, precision> class vecType> template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_DECL typename vecType<T, P>::bool_type greaterThanEqual(vecType<T, P> const & x, vecType<T, P> const & y); GLM_FUNC_DECL vecType<bool, P> greaterThanEqual(vecType<T, P> const & x, vecType<T, P> const & y);
/// Returns the component-wise comparison of result x == y. /// Returns the component-wise comparison of result x == y.
/// ///
@ -93,9 +92,8 @@ namespace glm
/// ///
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/equal.xml">GLSL equal man page</a> /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/equal.xml">GLSL equal man page</a>
/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.7 Vector Relational Functions</a> /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.7 Vector Relational Functions</a>
//TODO: conflicts with definision template <typename T, precision P, template <typename, precision> class vecType>
//template <typename T, precision P, template <typename, precision> class vecType> GLM_FUNC_DECL vecType<bool, P> equal(vecType<T, P> const & x, vecType<T, P> const & y);
//GLM_FUNC_DECL typename vecType<T, P>::bool_type equal(vecType<T, P> const & x, vecType<T, P> const & y);
/// Returns the component-wise comparison of result x != y. /// Returns the component-wise comparison of result x != y.
/// ///
@ -104,7 +102,7 @@ namespace glm
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/notEqual.xml">GLSL notEqual man page</a> /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/notEqual.xml">GLSL notEqual man page</a>
/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.7 Vector Relational Functions</a> /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.7 Vector Relational Functions</a>
template <typename T, precision P, template <typename, precision> class vecType> template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_DECL typename vecType<T, P>::bool_type notEqual(vecType<T, P> const & x, vecType<T, P> const & y); GLM_FUNC_DECL vecType<bool, P> notEqual(vecType<T, P> const & x, vecType<T, P> const & y);
/// Returns true if any component of x is true. /// Returns true if any component of x is true.
/// ///

View File

@ -31,17 +31,13 @@
namespace glm namespace glm
{ {
template <typename T, precision P, template <typename, precision> class vecType> template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_QUALIFIER typename vecType<T, P>::bool_type lessThan GLM_FUNC_QUALIFIER vecType<bool, P> lessThan(vecType<T, P> const & x, vecType<T, P> const & y)
(
vecType<T, P> const & x,
vecType<T, P> const & y
)
{ {
GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559 || std::numeric_limits<T>::is_integer, GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559 || std::numeric_limits<T>::is_integer,
"Invalid template instantiation of 'lessThan', GLM vector types required floating-point or integer value types vectors"); "Invalid template instantiation of 'lessThan', GLM vector types required floating-point or integer value types vectors");
assert(detail::component_count(x) == detail::component_count(y)); assert(detail::component_count(x) == detail::component_count(y));
typename vecType<bool, P>::bool_type Result(uninitialize); vecType<bool, P> Result(uninitialize);
for(detail::component_count_t i = 0; i < detail::component_count(x); ++i) for(detail::component_count_t i = 0; i < detail::component_count(x); ++i)
Result[i] = x[i] < y[i]; Result[i] = x[i] < y[i];
@ -49,81 +45,61 @@ namespace glm
} }
template <typename T, precision P, template <typename, precision> class vecType> template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_QUALIFIER typename vecType<T, P>::bool_type lessThanEqual GLM_FUNC_QUALIFIER vecType<bool, P> lessThanEqual(vecType<T, P> const & x, vecType<T, P> const & y)
(
vecType<T, P> const & x,
vecType<T, P> const & y
)
{ {
GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559 || std::numeric_limits<T>::is_integer, GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559 || std::numeric_limits<T>::is_integer,
"Invalid template instantiation of 'lessThanEqual', GLM vector types required floating-point or integer value types vectors"); "Invalid template instantiation of 'lessThanEqual', GLM vector types required floating-point or integer value types vectors");
assert(detail::component_count(x) == detail::component_count(y)); assert(detail::component_count(x) == detail::component_count(y));
typename vecType<bool, P>::bool_type Result(uninitialize); vecType<bool, P> Result(uninitialize);
for(detail::component_count_t i = 0; i < detail::component_count(x); ++i) for(detail::component_count_t i = 0; i < detail::component_count(x); ++i)
Result[i] = x[i] <= y[i]; Result[i] = x[i] <= y[i];
return Result; return Result;
} }
template <typename T, precision P, template <typename, precision> class vecType> template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_QUALIFIER typename vecType<T, P>::bool_type greaterThan GLM_FUNC_QUALIFIER vecType<bool, P> greaterThan(vecType<T, P> const & x, vecType<T, P> const & y)
(
vecType<T, P> const & x,
vecType<T, P> const & y
)
{ {
GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559 || std::numeric_limits<T>::is_integer, GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559 || std::numeric_limits<T>::is_integer,
"Invalid template instantiation of 'greaterThan', GLM vector types required floating-point or integer value types vectors"); "Invalid template instantiation of 'greaterThan', GLM vector types required floating-point or integer value types vectors");
assert(detail::component_count(x) == detail::component_count(y)); assert(detail::component_count(x) == detail::component_count(y));
typename vecType<bool, P>::bool_type Result(uninitialize); vecType<bool, P> Result(uninitialize);
for(detail::component_count_t i = 0; i < detail::component_count(x); ++i) for(detail::component_count_t i = 0; i < detail::component_count(x); ++i)
Result[i] = x[i] > y[i]; Result[i] = x[i] > y[i];
return Result; return Result;
} }
template <typename T, precision P, template <typename, precision> class vecType> template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_QUALIFIER typename vecType<T, P>::bool_type greaterThanEqual GLM_FUNC_QUALIFIER vecType<bool, P> greaterThanEqual(vecType<T, P> const & x, vecType<T, P> const & y)
(
vecType<T, P> const & x,
vecType<T, P> const & y
)
{ {
GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559 || std::numeric_limits<T>::is_integer, GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559 || std::numeric_limits<T>::is_integer,
"Invalid template instantiation of 'greaterThanEqual', GLM vector types required floating-point or integer value types vectors"); "Invalid template instantiation of 'greaterThanEqual', GLM vector types required floating-point or integer value types vectors");
assert(detail::component_count(x) == detail::component_count(y)); assert(detail::component_count(x) == detail::component_count(y));
typename vecType<bool, P>::bool_type Result(uninitialize); vecType<bool, P> Result(uninitialize);
for(detail::component_count_t i = 0; i < detail::component_count(x); ++i) for(detail::component_count_t i = 0; i < detail::component_count(x); ++i)
Result[i] = x[i] >= y[i]; Result[i] = x[i] >= y[i];
return Result; return Result;
} }
template <typename T, precision P, template <typename, precision> class vecType> template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_QUALIFIER typename vecType<T, P>::bool_type equal GLM_FUNC_QUALIFIER vecType<bool, P> equal(vecType<T, P> const & x, vecType<T, P> const & y)
(
vecType<T, P> const & x,
vecType<T, P> const & y
)
{ {
assert(detail::component_count(x) == detail::component_count(y)); assert(detail::component_count(x) == detail::component_count(y));
typename vecType<bool, P>::bool_type Result(uninitialize); vecType<bool, P> Result(uninitialize);
for(detail::component_count_t i = 0; i < detail::component_count(x); ++i) for(detail::component_count_t i = 0; i < detail::component_count(x); ++i)
Result[i] = x[i] == y[i]; Result[i] = x[i] == y[i];
return Result; return Result;
} }
template <typename T, precision P, template <typename, precision> class vecType> template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_QUALIFIER typename vecType<T, P>::bool_type notEqual GLM_FUNC_QUALIFIER vecType<bool, P> notEqual(vecType<T, P> const & x, vecType<T, P> const & y)
(
vecType<T, P> const & x,
vecType<T, P> const & y
)
{ {
assert(detail::component_count(x) == detail::component_count(y)); assert(detail::component_count(x) == detail::component_count(y));
typename vecType<bool, P>::bool_type Result(uninitialize); vecType<bool, P> Result(uninitialize);
for(detail::component_count_t i = 0; i < detail::component_count(x); ++i) for(detail::component_count_t i = 0; i < detail::component_count(x); ++i)
Result[i] = x[i] != y[i]; Result[i] = x[i] != y[i];
return Result; return Result;
@ -150,7 +126,7 @@ namespace glm
template <precision P, template <typename, precision> class vecType> template <precision P, template <typename, precision> class vecType>
GLM_FUNC_QUALIFIER vecType<bool, P> not_(vecType<bool, P> const & v) GLM_FUNC_QUALIFIER vecType<bool, P> not_(vecType<bool, P> const & v)
{ {
typename vecType<bool, P>::bool_type Result(uninitialize); vecType<bool, P> Result(uninitialize);
for(detail::component_count_t i = 0; i < detail::component_count(v); ++i) for(detail::component_count_t i = 0; i < detail::component_count(v); ++i)
Result[i] = !v[i]; Result[i] = !v[i];
return Result; return Result;