1
0

vec4-ext.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  1. /*
  2. * Copyright (c), Recep Aslantas.
  3. *
  4. * MIT License (MIT), http://opensource.org/licenses/MIT
  5. * Full license can be found in the LICENSE file
  6. */
  7. /*!
  8. * @brief SIMD like functions
  9. */
  10. /*
  11. Functions:
  12. CGLM_INLINE vec4s glms_vec4_broadcast(float val);
  13. CGLM_INLINE vec4s glms_vec4_fill(float val);
  14. CGLM_INLINE bool glms_vec4_eq(vec4s v, float val);
  15. CGLM_INLINE bool glms_vec4_eq_eps(vec4s v, float val);
  16. CGLM_INLINE bool glms_vec4_eq_all(vec4s v);
  17. CGLM_INLINE bool glms_vec4_eqv(vec4s a, vec4s b);
  18. CGLM_INLINE bool glms_vec4_eqv_eps(vec4s a, vec4s b);
  19. CGLM_INLINE float glms_vec4_max(vec4s v);
  20. CGLM_INLINE float glms_vec4_min(vec4s v);
  21. CGLM_INLINE bool glms_vec4_isnan(vec4s v);
  22. CGLM_INLINE bool glms_vec4_isinf(vec4s v);
  23. CGLM_INLINE bool glms_vec4_isvalid(vec4s v);
  24. CGLM_INLINE vec4s glms_vec4_sign(vec4s v);
  25. CGLM_INLINE vec4s glms_vec4_abs(vec4s v);
  26. CGLM_INLINE vec4s glms_vec4_fract(vec4s v);
  27. CGLM_INLINE float glms_vec4_floor(vec4s v);
  28. CGLM_INLINE float glms_vec4_mods(vec4s v, float s);
  29. CGLM_INLINE float glms_vec4_steps(float edge, vec4s v);
  30. CGLM_INLINE void glms_vec4_stepr(vec4s edge, float v);
  31. CGLM_INLINE float glms_vec4_hadd(vec4s v);
  32. CGLM_INLINE vec4s glms_vec4_sqrt(vec4s v);
  33. */
  34. #ifndef cglms_vec4s_ext_h
  35. #define cglms_vec4s_ext_h
  36. #include "../common.h"
  37. #include "../types-struct.h"
  38. #include "../util.h"
  39. #include "../vec4-ext.h"
  40. /* api definition */
  41. #define glms_vec4_(NAME) CGLM_STRUCTAPI(vec4, NAME)
  42. /*!
  43. * @brief fill a vector with specified value
  44. *
  45. * @param val value
  46. * @returns dest
  47. */
  48. CGLM_INLINE
  49. vec4s
  50. glms_vec4_(broadcast)(float val) {
  51. vec4s r;
  52. glm_vec4_broadcast(val, r.raw);
  53. return r;
  54. }
  55. /*!
  56. * @brief fill a vector with specified value
  57. *
  58. * @param val value
  59. * @returns dest
  60. */
  61. CGLM_INLINE
  62. vec4s
  63. glms_vec4_(fill)(float val) {
  64. vec4s r;
  65. glm_vec4_fill(r.raw, val);
  66. return r;
  67. }
  68. /*!
  69. * @brief check if vector is equal to value (without epsilon)
  70. *
  71. * @param v vector
  72. * @param val value
  73. */
  74. CGLM_INLINE
  75. bool
  76. glms_vec4_(eq)(vec4s v, float val) {
  77. return glm_vec4_eq(v.raw, val);
  78. }
  79. /*!
  80. * @brief check if vector is equal to value (with epsilon)
  81. *
  82. * @param v vector
  83. * @param val value
  84. */
  85. CGLM_INLINE
  86. bool
  87. glms_vec4_(eq_eps)(vec4s v, float val) {
  88. return glm_vec4_eq_eps(v.raw, val);
  89. }
  90. /*!
  91. * @brief check if vector members are equal (without epsilon)
  92. *
  93. * @param v vector
  94. */
  95. CGLM_INLINE
  96. bool
  97. glms_vec4_(eq_all)(vec4s v) {
  98. return glm_vec4_eq_all(v.raw);
  99. }
  100. /*!
  101. * @brief check if vector is equal to another (without epsilon)
  102. *
  103. * @param a vector
  104. * @param b vector
  105. */
  106. CGLM_INLINE
  107. bool
  108. glms_vec4_(eqv)(vec4s a, vec4s b) {
  109. return glm_vec4_eqv(a.raw, b.raw);
  110. }
  111. /*!
  112. * @brief check if vector is equal to another (with epsilon)
  113. *
  114. * @param a vector
  115. * @param b vector
  116. */
  117. CGLM_INLINE
  118. bool
  119. glms_vec4_(eqv_eps)(vec4s a, vec4s b) {
  120. return glm_vec4_eqv_eps(a.raw, b.raw);
  121. }
  122. /*!
  123. * @brief max value of vector
  124. *
  125. * @param v vector
  126. */
  127. CGLM_INLINE
  128. float
  129. glms_vec4_(max)(vec4s v) {
  130. return glm_vec4_max(v.raw);
  131. }
  132. /*!
  133. * @brief min value of vector
  134. *
  135. * @param v vector
  136. */
  137. CGLM_INLINE
  138. float
  139. glms_vec4_(min)(vec4s v) {
  140. return glm_vec4_min(v.raw);
  141. }
  142. /*!
  143. * @brief check if one of items is NaN (not a number)
  144. * you should only use this in DEBUG mode or very critical asserts
  145. *
  146. * @param[in] v vector
  147. */
  148. CGLM_INLINE
  149. bool
  150. glms_vec4_(isnan)(vec4s v) {
  151. return glm_vec4_isnan(v.raw);
  152. }
  153. /*!
  154. * @brief check if one of items is INFINITY
  155. * you should only use this in DEBUG mode or very critical asserts
  156. *
  157. * @param[in] v vector
  158. */
  159. CGLM_INLINE
  160. bool
  161. glms_vec4_(isinf)(vec4s v) {
  162. return glm_vec4_isinf(v.raw);
  163. }
  164. /*!
  165. * @brief check if all items are valid number
  166. * you should only use this in DEBUG mode or very critical asserts
  167. *
  168. * @param[in] v vector
  169. */
  170. CGLM_INLINE
  171. bool
  172. glms_vec4_(isvalid)(vec4s v) {
  173. return glm_vec4_isvalid(v.raw);
  174. }
  175. /*!
  176. * @brief get sign of 32 bit float as +1, -1, 0
  177. *
  178. * Important: It returns 0 for zero/NaN input
  179. *
  180. * @param v vector
  181. * @returns sign vector
  182. */
  183. CGLM_INLINE
  184. vec4s
  185. glms_vec4_(sign)(vec4s v) {
  186. vec4s r;
  187. glm_vec4_sign(v.raw, r.raw);
  188. return r;
  189. }
  190. /*!
  191. * @brief absolute value of each vector item
  192. *
  193. * @param[in] v vector
  194. * @returns destination vector
  195. */
  196. CGLM_INLINE
  197. vec4s
  198. glms_vec4_(abs)(vec4s v) {
  199. vec4s r;
  200. glm_vec4_abs(v.raw, r.raw);
  201. return r;
  202. }
  203. /*!
  204. * @brief fractional part of each vector item
  205. *
  206. * @param[in] v vector
  207. * @returns dest destination vector
  208. */
  209. CGLM_INLINE
  210. vec4s
  211. glms_vec4_(fract)(vec4s v) {
  212. vec4s r;
  213. glm_vec4_fract(v.raw, r.raw);
  214. return r;
  215. }
  216. /*!
  217. * @brief floor of each vector item
  218. *
  219. * @param[in] v vector
  220. * @returns dest destination vector
  221. */
  222. CGLM_INLINE
  223. vec4s
  224. glms_vec4_(floor)(vec4s v) {
  225. vec4s r;
  226. glm_vec4_floor(v.raw, r.raw);
  227. return r;
  228. }
  229. /*!
  230. * @brief mod of each vector item by scalar
  231. *
  232. * @param[in] v vector
  233. * @param[in] s scalar
  234. * @returns destination vector
  235. */
  236. CGLM_INLINE
  237. vec4s
  238. glms_vec4_(mods)(vec4s v, float s) {
  239. vec4s r;
  240. glm_vec4_mods(v.raw, s, r.raw);
  241. return r;
  242. }
  243. /*!
  244. * @brief threshold each vector item with scalar
  245. * condition is: (x[i] < edge) ? 0.0 : 1.0
  246. *
  247. * @param[in] edge threshold
  248. * @param[in] x vector to test against threshold
  249. * @returns destination
  250. */
  251. CGLM_INLINE
  252. vec4s
  253. glms_vec4_(steps)(float edge, vec4s x) {
  254. vec4s r;
  255. glm_vec4_steps(edge, x.raw, r.raw);
  256. return r;
  257. }
  258. /*!
  259. * @brief threshold a value with *vector* as the threshold
  260. * condition is: (x < edge[i]) ? 0.0 : 1.0
  261. *
  262. * @param[in] edge threshold vector
  263. * @param[in] x value to test against threshold
  264. * @returns destination
  265. */
  266. CGLM_INLINE
  267. vec4s
  268. glms_vec4_(stepr)(vec4s edge, float x) {
  269. vec4s r;
  270. glm_vec4_stepr(edge.raw, x, r.raw);
  271. return r;
  272. }
  273. /*!
  274. * @brief vector reduction by summation
  275. * @warning could overflow
  276. *
  277. * @param[in] v vector
  278. * @return sum of all vector's elements
  279. */
  280. CGLM_INLINE
  281. float
  282. glms_vec4_(hadd)(vec4s v) {
  283. return glm_vec4_hadd(v.raw);
  284. }
  285. /*!
  286. * @brief square root of each vector item
  287. *
  288. * @param[in] v vector
  289. * @returns destination vector
  290. */
  291. CGLM_INLINE
  292. vec4s
  293. glms_vec4_(sqrt)(vec4s v) {
  294. vec4s r;
  295. glm_vec4_sqrt(v.raw, r.raw);
  296. return r;
  297. }
  298. #endif /* cglms_vec4s_ext_h */