func_integer.hpp 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. ///////////////////////////////////////////////////////////////////////////////////////////////////
  2. // OpenGL Mathematics Copyright (c) 2005 - 2011 G-Truc Creation (www.g-truc.net)
  3. ///////////////////////////////////////////////////////////////////////////////////////////////////
  4. // Created : 2010-03-17
  5. // Updated : 2010-03-31
  6. // Licence : This source is under MIT License
  7. // File : glm/core/func_integer.hpp
  8. ///////////////////////////////////////////////////////////////////////////////////////////////////
  9. #ifndef glm_core_func_integer
  10. #define glm_core_func_integer
  11. namespace glm
  12. {
  13. namespace test{
  14. void main_core_func_integer();
  15. }//namespace test
  16. namespace core{
  17. namespace function{
  18. //! Define integer functions from Section 8.8 of GLSL 4.00.8 specification.
  19. namespace integer{
  20. /// \addtogroup core_funcs
  21. ///@{
  22. //! Adds 32-bit unsigned integer x and y, returning the sum
  23. //! modulo pow(2, 32). The value carry is set to 0 if the sum was
  24. //! less than pow(2, 32), or to 1 otherwise.
  25. //!
  26. //! \li <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/uaddCarry.xml">GLSL uaddCarry man page</a>
  27. //! \li GLSL 4.00.08 specification, section 8.8
  28. template <typename genUType>
  29. genUType uaddCarry(
  30. genUType const & x,
  31. genUType const & y,
  32. genUType & carry);
  33. //! Subtracts the 32-bit unsigned integer y from x, returning
  34. //! the difference if non-negative, or pow(2, 32) plus the difference
  35. //! otherwise. The value borrow is set to 0 if x >= y, or to 1 otherwise.
  36. //!
  37. //! \li <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/usubBorrow.xml">GLSL usubBorrow man page</a>
  38. //! \li GLSL 4.00.08 specification, section 8.8
  39. template <typename genUType>
  40. genUType usubBorrow(
  41. genUType const & x,
  42. genUType const & y,
  43. genUType & borrow);
  44. //! Multiplies 32-bit integers x and y, producing a 64-bit
  45. //! result. The 32 least-significant bits are returned in lsb.
  46. //! The 32 most-significant bits are returned in msb.
  47. //!
  48. //! \li <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/umulExtended.xml">GLSL umulExtended man page</a>
  49. //! \li GLSL 4.00.08 specification, section 8.8
  50. template <typename genUType>
  51. void umulExtended(
  52. genUType const & x,
  53. genUType const & y,
  54. genUType & msb,
  55. genUType & lsb);
  56. //! Multiplies 32-bit integers x and y, producing a 64-bit
  57. //! result. The 32 least-significant bits are returned in lsb.
  58. //! The 32 most-significant bits are returned in msb.
  59. //!
  60. //! \li <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/imulExtended.xml">GLSL imulExtended man page</a>
  61. //! \li GLSL 4.00.08 specification, section 8.8
  62. template <typename genIType>
  63. void imulExtended(
  64. genIType const & x,
  65. genIType const & y,
  66. genIType & msb,
  67. genIType & lsb);
  68. //! Extracts bits [offset, offset + bits - 1] from value,
  69. //! returning them in the least significant bits of the result.
  70. //! For unsigned data types, the most significant bits of the
  71. //! result will be set to zero. For signed data types, the
  72. //! most significant bits will be set to the value of bit offset + base – 1.
  73. //!
  74. //! If bits is zero, the result will be zero. The result will be
  75. //! undefined if offset or bits is negative, or if the sum of
  76. //! offset and bits is greater than the number of bits used
  77. //! to store the operand.
  78. //!
  79. //! \li <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/bitfieldExtract.xml">GLSL bitfieldExtract man page</a>
  80. //! \li GLSL 4.00.08 specification, section 8.8
  81. template <typename genIUType>
  82. genIUType bitfieldExtract(
  83. genIUType const & Value,
  84. int const & Offset,
  85. int const & Bits);
  86. //! Returns the insertion the bits least-significant bits of insert into base.
  87. //!
  88. //! The result will have bits [offset, offset + bits - 1] taken
  89. //! from bits [0, bits – 1] of insert, and all other bits taken
  90. //! directly from the corresponding bits of base. If bits is
  91. //! zero, the result will simply be base. The result will be
  92. //! undefined if offset or bits is negative, or if the sum of
  93. //! offset and bits is greater than the number of bits used to
  94. //! store the operand.
  95. //!
  96. //! \li <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/bitfieldInsert.xml">GLSL bitfieldInsert man page</a>
  97. //! \li GLSL 4.00.08 specification, section 8.8
  98. template <typename genIUType>
  99. genIUType bitfieldInsert(
  100. genIUType const & Base,
  101. genIUType const & Insert,
  102. int const & Offset,
  103. int const & Bits);
  104. //! Returns the reversal of the bits of value.
  105. //! The bit numbered n of the result will be taken from bit (bits - 1) - n of value,
  106. //! where bits is the total number of bits used to represent value.
  107. //!
  108. //! \li <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/bitfieldReverse.xml">GLSL bitfieldReverse man page</a>
  109. //! \li GLSL 4.00.08 specification, section 8.8
  110. template <typename genIUType>
  111. genIUType bitfieldReverse(genIUType const & value);
  112. //! Returns the number of bits set to 1 in the binary representation of value.
  113. //!
  114. //! \li <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/bitCount.xml">GLSL bitCount man page</a>
  115. //! \li GLSL 4.00.08 specification, section 8.8
  116. template <typename T, template <typename> class C>
  117. typename C<T>::signed_type bitCount(C<T> const & Value);
  118. //! Returns the bit number of the least significant bit set to
  119. //! 1 in the binary representation of value.
  120. //! If value is zero, -1 will be returned.
  121. //!
  122. //! \li <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/findLSB.xml">GLSL findLSB man page</a>
  123. //! \li GLSL 4.00.08 specification, section 8.8
  124. template <typename T, template <typename> class C>
  125. typename C<T>::signed_type findLSB(C<T> const & Value);
  126. //! Returns the bit number of the most significant bit in the binary representation of value.
  127. //! For positive integers, the result will be the bit number of the most significant bit set to 1.
  128. //! For negative integers, the result will be the bit number of the most significant
  129. //! bit set to 0. For a value of zero or negative one, -1 will be returned.
  130. //!
  131. //! \li <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/findMSB.xml">GLSL findMSB man page</a>
  132. //! \li GLSL 4.00.08 specification, section 8.8
  133. template <typename T, template <typename> class C>
  134. typename C<T>::signed_type findMSB(C<T> const & Value);
  135. ///@}
  136. }//namespace integer
  137. }//namespace function
  138. }//namespace core
  139. using namespace core::function::integer;
  140. }//namespace glm
  141. #include "func_integer.inl"
  142. #endif//glm_core_func_integer