simde-common.h 47 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231
  1. /* SPDX-License-Identifier: MIT
  2. *
  3. * Permission is hereby granted, free of charge, to any person
  4. * obtaining a copy of this software and associated documentation
  5. * files (the "Software"), to deal in the Software without
  6. * restriction, including without limitation the rights to use, copy,
  7. * modify, merge, publish, distribute, sublicense, and/or sell copies
  8. * of the Software, and to permit persons to whom the Software is
  9. * furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be
  12. * included in all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  15. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  16. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  17. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  18. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  19. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  20. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  21. * SOFTWARE.
  22. *
  23. * Copyright:
  24. * 2017-2020 Evan Nemerson <evan@nemerson.com>
  25. * 2023 Yi-Yen Chung <eric681@andestech.com> (Copyright owned by Andes Technology)
  26. * 2023 Ju-Hung Li <jhlee@pllab.cs.nthu.edu.tw> (Copyright owned by NTHU pllab)
  27. */
  28. #if !defined(SIMDE_COMMON_H)
  29. #define SIMDE_COMMON_H
  30. #include "hedley.h"
  31. #define SIMDE_VERSION_MAJOR 0
  32. #define SIMDE_VERSION_MINOR 8
  33. #define SIMDE_VERSION_MICRO 2
  34. #define SIMDE_VERSION HEDLEY_VERSION_ENCODE(SIMDE_VERSION_MAJOR, SIMDE_VERSION_MINOR, SIMDE_VERSION_MICRO)
  35. // Also update meson.build in the root directory of the repository
  36. #include <stddef.h>
  37. #include <stdint.h>
  38. #include "simde-detect-clang.h"
  39. #include "simde-arch.h"
  40. #include "simde-features.h"
  41. #include "simde-diagnostic.h"
  42. #include "simde-math.h"
  43. #include "simde-constify.h"
  44. #include "simde-align.h"
  45. /* In some situations, SIMDe has to make large performance sacrifices
  46. * for small increases in how faithfully it reproduces an API, but
  47. * only a relatively small number of users will actually need the API
  48. * to be completely accurate. The SIMDE_FAST_* options can be used to
  49. * disable these trade-offs.
  50. *
  51. * They can be enabled by passing -DSIMDE_FAST_MATH to the compiler, or
  52. * the individual defines (e.g., -DSIMDE_FAST_NANS) if you only want to
  53. * enable some optimizations. Using -ffast-math and/or
  54. * -ffinite-math-only will also enable the relevant options. If you
  55. * don't want that you can pass -DSIMDE_NO_FAST_* to disable them. */
  56. /* Most programs avoid NaNs by never passing values which can result in
  57. * a NaN; for example, if you only pass non-negative values to the sqrt
  58. * functions, it won't generate a NaN. On some platforms, similar
  59. * functions handle NaNs differently; for example, the _mm_min_ps SSE
  60. * function will return 0.0 if you pass it (0.0, NaN), but the NEON
  61. * vminq_f32 function will return NaN. Making them behave like one
  62. * another is expensive; it requires generating a mask of all lanes
  63. * with NaNs, then performing the operation (e.g., vminq_f32), then
  64. * blending together the result with another vector using the mask.
  65. *
  66. * If you don't want SIMDe to worry about the differences between how
  67. * NaNs are handled on the two platforms, define this (or pass
  68. * -ffinite-math-only) */
  69. #if !defined(SIMDE_FAST_MATH) && !defined(SIMDE_NO_FAST_MATH) && defined(__FAST_MATH__)
  70. #define SIMDE_FAST_MATH
  71. #endif
  72. #if !defined(SIMDE_FAST_NANS) && !defined(SIMDE_NO_FAST_NANS)
  73. #if defined(SIMDE_FAST_MATH)
  74. #define SIMDE_FAST_NANS
  75. #elif defined(__FINITE_MATH_ONLY__)
  76. #if __FINITE_MATH_ONLY__
  77. #define SIMDE_FAST_NANS
  78. #endif
  79. #endif
  80. #endif
  81. /* Many functions are defined as using the current rounding mode
  82. * (i.e., the SIMD version of fegetround()) when converting to
  83. * an integer. For example, _mm_cvtpd_epi32. Unfortunately,
  84. * on some platforms (such as ARMv8+ where round-to-nearest is
  85. * always used, regardless of the FPSCR register) this means we
  86. * have to first query the current rounding mode, then choose
  87. * the proper function (rounnd
  88. , ceil, floor, etc.) */
  89. #if !defined(SIMDE_FAST_ROUND_MODE) && !defined(SIMDE_NO_FAST_ROUND_MODE) && defined(SIMDE_FAST_MATH)
  90. #define SIMDE_FAST_ROUND_MODE
  91. #endif
  92. /* This controls how ties are rounded. For example, does 10.5 round to
  93. * 10 or 11? IEEE 754 specifies round-towards-even, but ARMv7 (for
  94. * example) doesn't support it and it must be emulated (which is rather
  95. * slow). If you're okay with just using the default for whatever arch
  96. * you're on, you should definitely define this.
  97. *
  98. * Note that we don't use this macro to avoid correct implementations
  99. * in functions which are explicitly about rounding (such as vrnd* on
  100. * NEON, _mm_round_* on x86, etc.); it is only used for code where
  101. * rounding is a component in another function, and even then it isn't
  102. * usually a problem since such functions will use the current rounding
  103. * mode. */
  104. #if !defined(SIMDE_FAST_ROUND_TIES) && !defined(SIMDE_NO_FAST_ROUND_TIES) && defined(SIMDE_FAST_MATH)
  105. #define SIMDE_FAST_ROUND_TIES
  106. #endif
  107. /* For functions which convert from one type to another (mostly from
  108. * floating point to integer types), sometimes we need to do a range
  109. * check and potentially return a different result if the value
  110. * falls outside that range. Skipping this check can provide a
  111. * performance boost, at the expense of faithfulness to the API we're
  112. * emulating. */
  113. #if !defined(SIMDE_FAST_CONVERSION_RANGE) && !defined(SIMDE_NO_FAST_CONVERSION_RANGE) && defined(SIMDE_FAST_MATH)
  114. #define SIMDE_FAST_CONVERSION_RANGE
  115. #endif
  116. /* Due to differences across platforms, sometimes it can be much
  117. * faster for us to allow spurious floating point exceptions,
  118. * or to no generate them when we should. */
  119. #if !defined(SIMDE_FAST_EXCEPTIONS) && !defined(SIMDE_NO_FAST_EXCEPTIONS) && defined(SIMDE_FAST_MATH)
  120. #define SIMDE_FAST_EXCEPTIONS
  121. #endif
  122. #if \
  123. HEDLEY_HAS_BUILTIN(__builtin_constant_p) || \
  124. HEDLEY_GCC_VERSION_CHECK(3,4,0) || \
  125. HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
  126. HEDLEY_TINYC_VERSION_CHECK(0,9,19) || \
  127. HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
  128. HEDLEY_IBM_VERSION_CHECK(13,1,0) || \
  129. HEDLEY_TI_CL6X_VERSION_CHECK(6,1,0) || \
  130. (HEDLEY_SUNPRO_VERSION_CHECK(5,10,0) && !defined(__cplusplus)) || \
  131. HEDLEY_CRAY_VERSION_CHECK(8,1,0) || \
  132. HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
  133. #define SIMDE_CHECK_CONSTANT_(expr) (__builtin_constant_p(expr))
  134. #elif defined(__cplusplus) && (__cplusplus > 201703L)
  135. #include <type_traits>
  136. #define SIMDE_CHECK_CONSTANT_(expr) (std::is_constant_evaluated())
  137. #endif
  138. #if !defined(SIMDE_NO_CHECK_IMMEDIATE_CONSTANT)
  139. #if defined(SIMDE_CHECK_CONSTANT_) && \
  140. SIMDE_DETECT_CLANG_VERSION_CHECK(9,0,0) && \
  141. (!defined(__apple_build_version__) || ((__apple_build_version__ < 11000000) || (__apple_build_version__ >= 12000000)))
  142. #define SIMDE_REQUIRE_CONSTANT(arg) HEDLEY_REQUIRE_MSG(SIMDE_CHECK_CONSTANT_(arg), "`" #arg "' must be constant")
  143. #else
  144. #define SIMDE_REQUIRE_CONSTANT(arg)
  145. #endif
  146. #else
  147. #define SIMDE_REQUIRE_CONSTANT(arg)
  148. #endif
  149. #define SIMDE_REQUIRE_RANGE(arg, min, max) \
  150. HEDLEY_REQUIRE_MSG((((arg) >= (min)) && ((arg) <= (max))), "'" #arg "' must be in [" #min ", " #max "]")
  151. #define SIMDE_REQUIRE_CONSTANT_RANGE(arg, min, max) \
  152. SIMDE_REQUIRE_CONSTANT(arg) \
  153. SIMDE_REQUIRE_RANGE(arg, min, max)
  154. /* A copy of HEDLEY_STATIC_ASSERT, except we don't define an empty
  155. * fallback if we can't find an implementation; instead we have to
  156. * check if SIMDE_STATIC_ASSERT is defined before using it. */
  157. #if \
  158. !defined(__cplusplus) && ( \
  159. (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)) || \
  160. HEDLEY_HAS_FEATURE(c_static_assert) || \
  161. HEDLEY_GCC_VERSION_CHECK(6,0,0) || \
  162. HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
  163. defined(_Static_assert) \
  164. )
  165. /* Sometimes _Static_assert is defined (in cdefs.h) using a symbol which
  166. * starts with a double-underscore. This is a system header so we have no
  167. * control over it, but since it's a macro it will emit a diagnostic which
  168. * prevents compilation with -Werror. */
  169. #if HEDLEY_HAS_WARNING("-Wreserved-identifier")
  170. #define SIMDE_STATIC_ASSERT(expr, message) (__extension__({ \
  171. HEDLEY_DIAGNOSTIC_PUSH \
  172. _Pragma("clang diagnostic ignored \"-Wreserved-identifier\"") \
  173. _Static_assert(expr, message); \
  174. HEDLEY_DIAGNOSTIC_POP \
  175. }))
  176. #else
  177. #define SIMDE_STATIC_ASSERT(expr, message) _Static_assert(expr, message)
  178. #endif
  179. #elif \
  180. (defined(__cplusplus) && (__cplusplus >= 201103L)) || \
  181. HEDLEY_MSVC_VERSION_CHECK(16,0,0)
  182. #define SIMDE_STATIC_ASSERT(expr, message) HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(static_assert(expr, message))
  183. #endif
  184. /* Statement exprs */
  185. #if \
  186. HEDLEY_GNUC_VERSION_CHECK(2,95,0) || \
  187. HEDLEY_TINYC_VERSION_CHECK(0,9,26) || \
  188. HEDLEY_INTEL_VERSION_CHECK(9,0,0) || \
  189. HEDLEY_PGI_VERSION_CHECK(18,10,0) || \
  190. HEDLEY_SUNPRO_VERSION_CHECK(5,12,0) || \
  191. HEDLEY_IBM_VERSION_CHECK(11,1,0) || \
  192. HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
  193. #define SIMDE_STATEMENT_EXPR_(expr) (__extension__ expr)
  194. #endif
  195. /* This is just a convenience macro to make it easy to call a single
  196. * function with a specific diagnostic disabled. */
  197. #if defined(SIMDE_STATEMENT_EXPR_)
  198. #define SIMDE_DISABLE_DIAGNOSTIC_EXPR_(diagnostic, expr) \
  199. SIMDE_STATEMENT_EXPR_(({ \
  200. HEDLEY_DIAGNOSTIC_PUSH \
  201. diagnostic \
  202. (expr); \
  203. HEDLEY_DIAGNOSTIC_POP \
  204. }))
  205. #endif
  206. #if defined(SIMDE_CHECK_CONSTANT_) && defined(SIMDE_STATIC_ASSERT)
  207. #define SIMDE_ASSERT_CONSTANT_(v) SIMDE_STATIC_ASSERT(SIMDE_CHECK_CONSTANT_(v), #v " must be constant.")
  208. #endif
  209. #if \
  210. (HEDLEY_HAS_ATTRIBUTE(may_alias) && !defined(HEDLEY_SUNPRO_VERSION)) || \
  211. HEDLEY_GCC_VERSION_CHECK(3,3,0) || \
  212. HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
  213. HEDLEY_IBM_VERSION_CHECK(13,1,0)
  214. # define SIMDE_MAY_ALIAS __attribute__((__may_alias__))
  215. #else
  216. # define SIMDE_MAY_ALIAS
  217. #endif
  218. /* Lots of compilers support GCC-style vector extensions, but many
  219. don't support all the features. Define different macros depending
  220. on support for
  221. * SIMDE_VECTOR - Declaring a vector.
  222. * SIMDE_VECTOR_OPS - basic operations (binary and unary).
  223. * SIMDE_VECTOR_NEGATE - negating a vector
  224. * SIMDE_VECTOR_SCALAR - For binary operators, the second argument
  225. can be a scalar, in which case the result is as if that scalar
  226. had been broadcast to all lanes of a vector.
  227. * SIMDE_VECTOR_SUBSCRIPT - Supports array subscript notation for
  228. extracting/inserting a single element.=
  229. SIMDE_VECTOR can be assumed if any others are defined, the
  230. others are independent. */
  231. #if !defined(SIMDE_NO_VECTOR)
  232. # if \
  233. HEDLEY_GCC_VERSION_CHECK(4,8,0)
  234. # define SIMDE_VECTOR(size) __attribute__((__vector_size__(size)))
  235. # define SIMDE_VECTOR_OPS
  236. # define SIMDE_VECTOR_NEGATE
  237. # define SIMDE_VECTOR_SCALAR
  238. # define SIMDE_VECTOR_SUBSCRIPT
  239. # elif HEDLEY_INTEL_VERSION_CHECK(16,0,0)
  240. # define SIMDE_VECTOR(size) __attribute__((__vector_size__(size)))
  241. # define SIMDE_VECTOR_OPS
  242. # define SIMDE_VECTOR_NEGATE
  243. /* ICC only supports SIMDE_VECTOR_SCALAR for constants */
  244. # define SIMDE_VECTOR_SUBSCRIPT
  245. # elif \
  246. HEDLEY_GCC_VERSION_CHECK(4,1,0) || \
  247. HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
  248. HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
  249. # define SIMDE_VECTOR(size) __attribute__((__vector_size__(size)))
  250. # define SIMDE_VECTOR_OPS
  251. # elif HEDLEY_SUNPRO_VERSION_CHECK(5,12,0)
  252. # define SIMDE_VECTOR(size) __attribute__((__vector_size__(size)))
  253. # elif HEDLEY_HAS_ATTRIBUTE(vector_size)
  254. # define SIMDE_VECTOR(size) __attribute__((__vector_size__(size)))
  255. # define SIMDE_VECTOR_OPS
  256. # define SIMDE_VECTOR_NEGATE
  257. # define SIMDE_VECTOR_SUBSCRIPT
  258. # if SIMDE_DETECT_CLANG_VERSION_CHECK(5,0,0)
  259. # define SIMDE_VECTOR_SCALAR
  260. # endif
  261. # endif
  262. /* GCC and clang have built-in functions to handle shuffling and
  263. converting of vectors, but the implementations are slightly
  264. different. This macro is just an abstraction over them. Note that
  265. elem_size is in bits but vec_size is in bytes. */
  266. # if !defined(SIMDE_NO_SHUFFLE_VECTOR) && defined(SIMDE_VECTOR_SUBSCRIPT)
  267. HEDLEY_DIAGNOSTIC_PUSH
  268. /* We don't care about -Wvariadic-macros; all compilers that support
  269. * shufflevector/shuffle support them. */
  270. # if HEDLEY_HAS_WARNING("-Wc++98-compat-pedantic")
  271. # pragma clang diagnostic ignored "-Wc++98-compat-pedantic"
  272. # endif
  273. # if HEDLEY_HAS_WARNING("-Wvariadic-macros") || HEDLEY_GCC_VERSION_CHECK(4,0,0)
  274. # pragma GCC diagnostic ignored "-Wvariadic-macros"
  275. # endif
  276. # if HEDLEY_HAS_BUILTIN(__builtin_shufflevector)
  277. # define SIMDE_SHUFFLE_VECTOR_(elem_size, vec_size, a, b, ...) __builtin_shufflevector(a, b, __VA_ARGS__)
  278. # elif HEDLEY_GCC_HAS_BUILTIN(__builtin_shuffle,4,7,0) && !defined(__INTEL_COMPILER)
  279. # define SIMDE_SHUFFLE_VECTOR_(elem_size, vec_size, a, b, ...) (__extension__ ({ \
  280. int##elem_size##_t SIMDE_VECTOR(vec_size) simde_shuffle_ = { __VA_ARGS__ }; \
  281. __builtin_shuffle(a, b, simde_shuffle_); \
  282. }))
  283. # endif
  284. HEDLEY_DIAGNOSTIC_POP
  285. # endif
  286. /* TODO: this actually works on XL C/C++ without SIMDE_VECTOR_SUBSCRIPT
  287. but the code needs to be refactored a bit to take advantage. */
  288. # if !defined(SIMDE_NO_CONVERT_VECTOR) && defined(SIMDE_VECTOR_SUBSCRIPT)
  289. # if HEDLEY_HAS_BUILTIN(__builtin_convertvector) || HEDLEY_GCC_VERSION_CHECK(9,0,0)
  290. # if HEDLEY_GCC_VERSION_CHECK(9,0,0) && !HEDLEY_GCC_VERSION_CHECK(9,3,0)
  291. /* https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93557 */
  292. # define SIMDE_CONVERT_VECTOR_(to, from) ((to) = (__extension__({ \
  293. __typeof__(from) from_ = (from); \
  294. ((void) from_); \
  295. __builtin_convertvector(from_, __typeof__(to)); \
  296. })))
  297. # else
  298. # define SIMDE_CONVERT_VECTOR_(to, from) ((to) = __builtin_convertvector((from), __typeof__(to)))
  299. # endif
  300. # endif
  301. # endif
  302. #endif
  303. /* Since we currently require SUBSCRIPT before using a vector in a
  304. union, we define these as dependencies of SUBSCRIPT. They are
  305. likely to disappear in the future, once SIMDe learns how to make
  306. use of vectors without using the union members. Do not use them
  307. in your code unless you're okay with it breaking when SIMDe
  308. changes. */
  309. #if defined(SIMDE_VECTOR_SUBSCRIPT)
  310. # if defined(SIMDE_VECTOR_OPS)
  311. # define SIMDE_VECTOR_SUBSCRIPT_OPS
  312. # endif
  313. # if defined(SIMDE_VECTOR_SCALAR)
  314. # define SIMDE_VECTOR_SUBSCRIPT_SCALAR
  315. # endif
  316. #endif
  317. #if !defined(SIMDE_DISABLE_OPENMP)
  318. #if !defined(SIMDE_ENABLE_OPENMP) && ((defined(_OPENMP) && (_OPENMP >= 201307L)) || (defined(_OPENMP_SIMD) && (_OPENMP_SIMD >= 201307L))) || defined(HEDLEY_MCST_LCC_VERSION)
  319. #define SIMDE_ENABLE_OPENMP
  320. #endif
  321. #endif
  322. #if !defined(SIMDE_ENABLE_CILKPLUS) && (defined(__cilk) || defined(HEDLEY_INTEL_VERSION))
  323. # define SIMDE_ENABLE_CILKPLUS
  324. #endif
  325. #if defined(SIMDE_ENABLE_OPENMP)
  326. # define SIMDE_VECTORIZE HEDLEY_PRAGMA(omp simd)
  327. # define SIMDE_VECTORIZE_SAFELEN(l) HEDLEY_PRAGMA(omp simd safelen(l))
  328. # if defined(__clang__)
  329. # define SIMDE_VECTORIZE_REDUCTION(r) \
  330. HEDLEY_DIAGNOSTIC_PUSH \
  331. _Pragma("clang diagnostic ignored \"-Wsign-conversion\"") \
  332. HEDLEY_PRAGMA(omp simd reduction(r)) \
  333. HEDLEY_DIAGNOSTIC_POP
  334. # else
  335. # define SIMDE_VECTORIZE_REDUCTION(r) HEDLEY_PRAGMA(omp simd reduction(r))
  336. # endif
  337. # if !defined(HEDLEY_MCST_LCC_VERSION)
  338. # define SIMDE_VECTORIZE_ALIGNED(a) HEDLEY_PRAGMA(omp simd aligned(a))
  339. # else
  340. # define SIMDE_VECTORIZE_ALIGNED(a) HEDLEY_PRAGMA(omp simd)
  341. # endif
  342. #elif defined(SIMDE_ENABLE_CILKPLUS)
  343. # define SIMDE_VECTORIZE HEDLEY_PRAGMA(simd)
  344. # define SIMDE_VECTORIZE_SAFELEN(l) HEDLEY_PRAGMA(simd vectorlength(l))
  345. # define SIMDE_VECTORIZE_REDUCTION(r) HEDLEY_PRAGMA(simd reduction(r))
  346. # define SIMDE_VECTORIZE_ALIGNED(a) HEDLEY_PRAGMA(simd aligned(a))
  347. #elif defined(__clang__) && !defined(HEDLEY_IBM_VERSION)
  348. # define SIMDE_VECTORIZE HEDLEY_PRAGMA(clang loop vectorize(enable))
  349. # define SIMDE_VECTORIZE_SAFELEN(l) HEDLEY_PRAGMA(clang loop vectorize_width(l))
  350. # define SIMDE_VECTORIZE_REDUCTION(r) SIMDE_VECTORIZE
  351. # define SIMDE_VECTORIZE_ALIGNED(a)
  352. #elif HEDLEY_GCC_VERSION_CHECK(4,9,0)
  353. # define SIMDE_VECTORIZE HEDLEY_PRAGMA(GCC ivdep)
  354. # define SIMDE_VECTORIZE_SAFELEN(l) SIMDE_VECTORIZE
  355. # define SIMDE_VECTORIZE_REDUCTION(r) SIMDE_VECTORIZE
  356. # define SIMDE_VECTORIZE_ALIGNED(a)
  357. #elif HEDLEY_CRAY_VERSION_CHECK(5,0,0)
  358. # define SIMDE_VECTORIZE HEDLEY_PRAGMA(_CRI ivdep)
  359. # define SIMDE_VECTORIZE_SAFELEN(l) SIMDE_VECTORIZE
  360. # define SIMDE_VECTORIZE_REDUCTION(r) SIMDE_VECTORIZE
  361. # define SIMDE_VECTORIZE_ALIGNED(a)
  362. #else
  363. # define SIMDE_VECTORIZE
  364. # define SIMDE_VECTORIZE_SAFELEN(l)
  365. # define SIMDE_VECTORIZE_REDUCTION(r)
  366. # define SIMDE_VECTORIZE_ALIGNED(a)
  367. #endif
  368. #define SIMDE_MASK_NZ_(v, mask) (((v) & (mask)) | !((v) & (mask)))
  369. /* Intended for checking coverage, you should never use this in
  370. production. */
  371. #if defined(SIMDE_NO_INLINE)
  372. # define SIMDE_FUNCTION_ATTRIBUTES HEDLEY_NEVER_INLINE static
  373. #else
  374. # define SIMDE_FUNCTION_ATTRIBUTES HEDLEY_ALWAYS_INLINE static
  375. #endif
  376. #if defined(SIMDE_NO_INLINE)
  377. # define SIMDE_HUGE_FUNCTION_ATTRIBUTES HEDLEY_NEVER_INLINE static
  378. #elif defined(SIMDE_CONSTRAINED_COMPILATION)
  379. # define SIMDE_HUGE_FUNCTION_ATTRIBUTES static
  380. #else
  381. # define SIMDE_HUGE_FUNCTION_ATTRIBUTES HEDLEY_ALWAYS_INLINE static
  382. #endif
  383. #if \
  384. HEDLEY_HAS_ATTRIBUTE(unused) || \
  385. HEDLEY_GCC_VERSION_CHECK(2,95,0)
  386. # define SIMDE_FUNCTION_POSSIBLY_UNUSED_ __attribute__((__unused__))
  387. #else
  388. # define SIMDE_FUNCTION_POSSIBLY_UNUSED_
  389. #endif
  390. HEDLEY_DIAGNOSTIC_PUSH
  391. SIMDE_DIAGNOSTIC_DISABLE_USED_BUT_MARKED_UNUSED_
  392. #if defined(_MSC_VER)
  393. # define SIMDE_BEGIN_DECLS_ HEDLEY_DIAGNOSTIC_PUSH __pragma(warning(disable:4996 4204)) HEDLEY_BEGIN_C_DECLS
  394. # define SIMDE_END_DECLS_ HEDLEY_DIAGNOSTIC_POP HEDLEY_END_C_DECLS
  395. #else
  396. # define SIMDE_BEGIN_DECLS_ \
  397. HEDLEY_DIAGNOSTIC_PUSH \
  398. SIMDE_DIAGNOSTIC_DISABLE_USED_BUT_MARKED_UNUSED_ \
  399. HEDLEY_BEGIN_C_DECLS
  400. # define SIMDE_END_DECLS_ \
  401. HEDLEY_END_C_DECLS \
  402. HEDLEY_DIAGNOSTIC_POP
  403. #endif
  404. #if defined(__SIZEOF_INT128__)
  405. # define SIMDE_HAVE_INT128_
  406. HEDLEY_DIAGNOSTIC_PUSH
  407. SIMDE_DIAGNOSTIC_DISABLE_PEDANTIC_
  408. typedef __int128 simde_int128;
  409. typedef unsigned __int128 simde_uint128;
  410. HEDLEY_DIAGNOSTIC_POP
  411. #endif
  412. #if !defined(SIMDE_ENDIAN_LITTLE)
  413. # define SIMDE_ENDIAN_LITTLE 1234
  414. #endif
  415. #if !defined(SIMDE_ENDIAN_BIG)
  416. # define SIMDE_ENDIAN_BIG 4321
  417. #endif
  418. #if !defined(SIMDE_ENDIAN_ORDER)
  419. /* GCC (and compilers masquerading as GCC) define __BYTE_ORDER__. */
  420. # if defined(__BYTE_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) && (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)
  421. # define SIMDE_ENDIAN_ORDER SIMDE_ENDIAN_LITTLE
  422. # elif defined(__BYTE_ORDER__) && defined(__ORDER_BIG_ENDIAN__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
  423. # define SIMDE_ENDIAN_ORDER SIMDE_ENDIAN_BIG
  424. /* TI defines _BIG_ENDIAN or _LITTLE_ENDIAN */
  425. # elif defined(_BIG_ENDIAN)
  426. # define SIMDE_ENDIAN_ORDER SIMDE_ENDIAN_BIG
  427. # elif defined(_LITTLE_ENDIAN)
  428. # define SIMDE_ENDIAN_ORDER SIMDE_ENDIAN_LITTLE
  429. /* We know the endianness of some common architectures. Common
  430. * architectures not listed (ARM, POWER, MIPS, etc.) here are
  431. * bi-endian. */
  432. # elif defined(__amd64) || defined(_M_X64) || defined(__i386) || defined(_M_IX86)
  433. # define SIMDE_ENDIAN_ORDER SIMDE_ENDIAN_LITTLE
  434. # elif defined(__s390x__) || defined(__zarch__)
  435. # define SIMDE_ENDIAN_ORDER SIMDE_ENDIAN_BIG
  436. /* Looks like we'll have to rely on the platform. If we're missing a
  437. * platform, please let us know. */
  438. # elif defined(_WIN32)
  439. # define SIMDE_ENDIAN_ORDER SIMDE_ENDIAN_LITTLE
  440. # elif defined(sun) || defined(__sun) /* Solaris */
  441. # include <sys/byteorder.h>
  442. # if defined(_LITTLE_ENDIAN)
  443. # define SIMDE_ENDIAN_ORDER SIMDE_ENDIAN_LITTLE
  444. # elif defined(_BIG_ENDIAN)
  445. # define SIMDE_ENDIAN_ORDER SIMDE_ENDIAN_BIG
  446. # endif
  447. # elif defined(__APPLE__)
  448. # include <libkern/OSByteOrder.h>
  449. # if defined(__LITTLE_ENDIAN__)
  450. # define SIMDE_ENDIAN_ORDER SIMDE_ENDIAN_LITTLE
  451. # elif defined(__BIG_ENDIAN__)
  452. # define SIMDE_ENDIAN_ORDER SIMDE_ENDIAN_BIG
  453. # endif
  454. # elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__bsdi__) || defined(__DragonFly__) || defined(BSD)
  455. # include <machine/endian.h>
  456. # if defined(__BYTE_ORDER) && (__BYTE_ORDER == __LITTLE_ENDIAN)
  457. # define SIMDE_ENDIAN_ORDER SIMDE_ENDIAN_LITTLE
  458. # elif defined(__BYTE_ORDER) && (__BYTE_ORDER == __BIG_ENDIAN)
  459. # define SIMDE_ENDIAN_ORDER SIMDE_ENDIAN_BIG
  460. # endif
  461. # elif defined(__linux__) || defined(__linux) || defined(__gnu_linux__)
  462. # include <endian.h>
  463. # if defined(__BYTE_ORDER) && defined(__LITTLE_ENDIAN) && (__BYTE_ORDER == __LITTLE_ENDIAN)
  464. # define SIMDE_ENDIAN_ORDER SIMDE_ENDIAN_LITTLE
  465. # elif defined(__BYTE_ORDER) && defined(__BIG_ENDIAN) && (__BYTE_ORDER == __BIG_ENDIAN)
  466. # define SIMDE_ENDIAN_ORDER SIMDE_ENDIAN_BIG
  467. # endif
  468. # endif
  469. #endif
  470. #if \
  471. HEDLEY_HAS_BUILTIN(__builtin_bswap64) || \
  472. HEDLEY_GCC_VERSION_CHECK(4,3,0) || \
  473. HEDLEY_IBM_VERSION_CHECK(13,1,0) || \
  474. HEDLEY_INTEL_VERSION_CHECK(13,0,0)
  475. #define simde_bswap64(v) __builtin_bswap64(v)
  476. #elif HEDLEY_MSVC_VERSION_CHECK(13,10,0)
  477. #define simde_bswap64(v) _byteswap_uint64(v)
  478. #else
  479. SIMDE_FUNCTION_ATTRIBUTES
  480. uint64_t
  481. simde_bswap64(uint64_t v) {
  482. return
  483. ((v & (((uint64_t) 0xff) << 56)) >> 56) |
  484. ((v & (((uint64_t) 0xff) << 48)) >> 40) |
  485. ((v & (((uint64_t) 0xff) << 40)) >> 24) |
  486. ((v & (((uint64_t) 0xff) << 32)) >> 8) |
  487. ((v & (((uint64_t) 0xff) << 24)) << 8) |
  488. ((v & (((uint64_t) 0xff) << 16)) << 24) |
  489. ((v & (((uint64_t) 0xff) << 8)) << 40) |
  490. ((v & (((uint64_t) 0xff) )) << 56);
  491. }
  492. #endif
  493. #if !defined(SIMDE_ENDIAN_ORDER)
  494. # error Unknown byte order; please file a bug
  495. #else
  496. # if SIMDE_ENDIAN_ORDER == SIMDE_ENDIAN_LITTLE
  497. # define simde_endian_bswap64_be(value) simde_bswap64(value)
  498. # define simde_endian_bswap64_le(value) (value)
  499. # elif SIMDE_ENDIAN_ORDER == SIMDE_ENDIAN_BIG
  500. # define simde_endian_bswap64_be(value) (value)
  501. # define simde_endian_bswap64_le(value) simde_bswap64(value)
  502. # endif
  503. #endif
  504. /* TODO: we should at least make an attempt to detect the correct
  505. types for simde_float32/float64 instead of just assuming float and
  506. double. */
  507. #if !defined(SIMDE_FLOAT32_TYPE)
  508. # define SIMDE_FLOAT32_TYPE float
  509. # define SIMDE_FLOAT32_C(value) value##f
  510. #else
  511. # define SIMDE_FLOAT32_C(value) ((SIMDE_FLOAT32_TYPE) value)
  512. #endif
  513. typedef SIMDE_FLOAT32_TYPE simde_float32;
  514. #if !defined(SIMDE_FLOAT64_TYPE)
  515. # define SIMDE_FLOAT64_TYPE double
  516. # define SIMDE_FLOAT64_C(value) value
  517. #else
  518. # define SIMDE_FLOAT64_C(value) ((SIMDE_FLOAT64_TYPE) value)
  519. #endif
  520. typedef SIMDE_FLOAT64_TYPE simde_float64;
  521. #if defined(SIMDE_POLY8_TYPE)
  522. # undef SIMDE_POLY8_TYPE
  523. #endif
  524. #if defined(SIMDE_ARM_NEON_A32V7_NATIVE)
  525. # define SIMDE_POLY8_TYPE poly8_t
  526. # define SIMDE_POLY8_C(value) (HEDLEY_STATIC_CAST(poly8_t, value))
  527. #else
  528. # define SIMDE_POLY8_TYPE uint8_t
  529. # define SIMDE_POLY8_C(value) (HEDLEY_STATIC_CAST(uint8_t, value))
  530. #endif
  531. typedef SIMDE_POLY8_TYPE simde_poly8;
  532. #if defined(SIMDE_POLY16_TYPE)
  533. # undef SIMDE_POLY16_TYPE
  534. #endif
  535. #if defined(SIMDE_ARM_NEON_A32V7_NATIVE)
  536. # define SIMDE_POLY16_TYPE poly16_t
  537. # define SIMDE_POLY16_C(value) (HEDLEY_STATIC_CAST(poly16_t, value))
  538. #else
  539. # define SIMDE_POLY16_TYPE uint16_t
  540. # define SIMDE_POLY16_C(value) (HEDLEY_STATIC_CAST(uint16_t, value))
  541. #endif
  542. typedef SIMDE_POLY16_TYPE simde_poly16;
  543. #if defined(SIMDE_POLY64_TYPE)
  544. # undef SIMDE_POLY64_TYPE
  545. #endif
  546. #if defined(SIMDE_ARM_NEON_A32V8_NATIVE)
  547. # define SIMDE_POLY64_TYPE poly64_t
  548. # define SIMDE_POLY64_C(value) (HEDLEY_STATIC_CAST(poly64_t, value ## ull))
  549. #else
  550. # define SIMDE_POLY64_TYPE uint64_t
  551. # define SIMDE_POLY64_C(value) value ## ull
  552. #endif
  553. typedef SIMDE_POLY64_TYPE simde_poly64;
  554. #if defined(SIMDE_POLY128_TYPE)
  555. # undef SIMDE_POLY128_TYPE
  556. #endif
  557. #if defined(SIMDE_ARM_NEON_A32V8_NATIVE) && defined(SIMDE_ARCH_ARM_CRYPTO)
  558. # define SIMDE_POLY128_TYPE poly128_t
  559. # define SIMDE_POLY128_C(value) value
  560. #elif defined(__SIZEOF_INT128__)
  561. # define SIMDE_POLY128_TYPE __int128
  562. # define SIMDE_POLY128_C(value) (HEDLEY_STATIC_CAST(__int128, value))
  563. #else
  564. # define SIMDE_POLY128_TYPE uint64_t
  565. # define SIMDE_TARGET_NOT_SUPPORT_INT128_TYPE 1
  566. #endif
  567. typedef SIMDE_POLY128_TYPE simde_poly128;
  568. #if defined(__cplusplus)
  569. typedef bool simde_bool;
  570. #elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
  571. typedef _Bool simde_bool;
  572. #elif defined(bool)
  573. typedef bool simde_bool;
  574. #else
  575. #include <stdbool.h>
  576. typedef bool simde_bool;
  577. #endif
  578. #if HEDLEY_HAS_WARNING("-Wbad-function-cast")
  579. # define SIMDE_CONVERT_FTOI(T,v) \
  580. HEDLEY_DIAGNOSTIC_PUSH \
  581. _Pragma("clang diagnostic ignored \"-Wbad-function-cast\"") \
  582. HEDLEY_STATIC_CAST(T, (v)) \
  583. HEDLEY_DIAGNOSTIC_POP
  584. #else
  585. # define SIMDE_CONVERT_FTOI(T,v) ((T) (v))
  586. #endif
  587. /* TODO: detect compilers which support this outside of C11 mode */
  588. #if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)
  589. #define SIMDE_CHECKED_REINTERPRET_CAST(to, from, value) _Generic((value), to: (value), default: (_Generic((value), from: ((to) (value)))))
  590. #define SIMDE_CHECKED_STATIC_CAST(to, from, value) _Generic((value), to: (value), default: (_Generic((value), from: ((to) (value)))))
  591. #else
  592. #define SIMDE_CHECKED_REINTERPRET_CAST(to, from, value) HEDLEY_REINTERPRET_CAST(to, value)
  593. #define SIMDE_CHECKED_STATIC_CAST(to, from, value) HEDLEY_STATIC_CAST(to, value)
  594. #endif
  595. #if HEDLEY_HAS_WARNING("-Wfloat-equal")
  596. # define SIMDE_DIAGNOSTIC_DISABLE_FLOAT_EQUAL _Pragma("clang diagnostic ignored \"-Wfloat-equal\"")
  597. #elif HEDLEY_GCC_VERSION_CHECK(3,0,0)
  598. # define SIMDE_DIAGNOSTIC_DISABLE_FLOAT_EQUAL _Pragma("GCC diagnostic ignored \"-Wfloat-equal\"")
  599. #else
  600. # define SIMDE_DIAGNOSTIC_DISABLE_FLOAT_EQUAL
  601. #endif
  602. /* Some functions can trade accuracy for speed. For those functions
  603. you can control the trade-off using this macro. Possible values:
  604. 0: prefer speed
  605. 1: reasonable trade-offs
  606. 2: prefer accuracy */
  607. #if !defined(SIMDE_ACCURACY_PREFERENCE)
  608. # define SIMDE_ACCURACY_PREFERENCE 1
  609. #endif
  610. #if defined(__STDC_HOSTED__)
  611. # define SIMDE_STDC_HOSTED __STDC_HOSTED__
  612. #else
  613. # if \
  614. defined(HEDLEY_PGI_VERSION) || \
  615. defined(HEDLEY_MSVC_VERSION)
  616. # define SIMDE_STDC_HOSTED 1
  617. # else
  618. # define SIMDE_STDC_HOSTED 0
  619. # endif
  620. #endif
  621. /* Try to deal with environments without a standard library. */
  622. #if !defined(simde_memcpy)
  623. #if HEDLEY_HAS_BUILTIN(__builtin_memcpy)
  624. #define simde_memcpy(dest, src, n) __builtin_memcpy(dest, src, n)
  625. #endif
  626. #endif
  627. #if !defined(simde_memset)
  628. #if HEDLEY_HAS_BUILTIN(__builtin_memset)
  629. #define simde_memset(s, c, n) __builtin_memset(s, c, n)
  630. #endif
  631. #endif
  632. #if !defined(simde_memcmp)
  633. #if HEDLEY_HAS_BUILTIN(__builtin_memcmp)
  634. #define simde_memcmp(s1, s2, n) __builtin_memcmp(s1, s2, n)
  635. #endif
  636. #endif
  637. #if !defined(simde_memcpy) || !defined(simde_memset) || !defined(simde_memcmp)
  638. #if !defined(SIMDE_NO_STRING_H)
  639. #if defined(__has_include)
  640. #if !__has_include(<string.h>)
  641. #define SIMDE_NO_STRING_H
  642. #endif
  643. #elif (SIMDE_STDC_HOSTED == 0)
  644. #define SIMDE_NO_STRING_H
  645. #endif
  646. #endif
  647. #if !defined(SIMDE_NO_STRING_H)
  648. #include <string.h>
  649. #if !defined(simde_memcpy)
  650. #define simde_memcpy(dest, src, n) memcpy(dest, src, n)
  651. #endif
  652. #if !defined(simde_memset)
  653. #define simde_memset(s, c, n) memset(s, c, n)
  654. #endif
  655. #if !defined(simde_memcmp)
  656. #define simde_memcmp(s1, s2, n) memcmp(s1, s2, n)
  657. #endif
  658. #else
  659. /* These are meant to be portable, not fast. If you're hitting them you
  660. * should think about providing your own (by defining the simde_memcpy
  661. * macro prior to including any SIMDe files) or submitting a patch to
  662. * SIMDe so we can detect your system-provided memcpy/memset, like by
  663. * adding your compiler to the checks for __builtin_memcpy and/or
  664. * __builtin_memset. */
  665. #if !defined(simde_memcpy)
  666. SIMDE_FUNCTION_ATTRIBUTES
  667. void
  668. simde_memcpy_(void* dest, const void* src, size_t len) {
  669. char* dest_ = HEDLEY_STATIC_CAST(char*, dest);
  670. char* src_ = HEDLEY_STATIC_CAST(const char*, src);
  671. for (size_t i = 0 ; i < len ; i++) {
  672. dest_[i] = src_[i];
  673. }
  674. }
  675. #define simde_memcpy(dest, src, n) simde_memcpy_(dest, src, n)
  676. #endif
  677. #if !defined(simde_memset)
  678. SIMDE_FUNCTION_ATTRIBUTES
  679. void
  680. simde_memset_(void* s, int c, size_t len) {
  681. char* s_ = HEDLEY_STATIC_CAST(char*, s);
  682. char c_ = HEDLEY_STATIC_CAST(char, c);
  683. for (size_t i = 0 ; i < len ; i++) {
  684. s_[i] = c_[i];
  685. }
  686. }
  687. #define simde_memset(s, c, n) simde_memset_(s, c, n)
  688. #endif
  689. #if !defined(simde_memcmp)
  690. SIMDE_FUCTION_ATTRIBUTES
  691. int
  692. simde_memcmp_(const void *s1, const void *s2, size_t n) {
  693. unsigned char* s1_ = HEDLEY_STATIC_CAST(unsigned char*, s1);
  694. unsigned char* s2_ = HEDLEY_STATIC_CAST(unsigned char*, s2);
  695. for (size_t i = 0 ; i < len ; i++) {
  696. if (s1_[i] != s2_[i]) {
  697. return (int) (s1_[i] - s2_[i]);
  698. }
  699. }
  700. return 0;
  701. }
  702. #define simde_memcmp(s1, s2, n) simde_memcmp_(s1, s2, n)
  703. #endif
  704. #endif
  705. #endif
  706. /*** Functions that quiet a signaling NaN ***/
  707. static HEDLEY_INLINE
  708. double
  709. simde_math_quiet(double x) {
  710. uint64_t tmp, mask;
  711. if (!simde_math_isnan(x)) {
  712. return x;
  713. }
  714. simde_memcpy(&tmp, &x, 8);
  715. mask = 0x7ff80000;
  716. mask <<= 32;
  717. tmp |= mask;
  718. simde_memcpy(&x, &tmp, 8);
  719. return x;
  720. }
  721. static HEDLEY_INLINE
  722. float
  723. simde_math_quietf(float x) {
  724. uint32_t tmp;
  725. if (!simde_math_isnanf(x)) {
  726. return x;
  727. }
  728. simde_memcpy(&tmp, &x, 4);
  729. tmp |= 0x7fc00000lu;
  730. simde_memcpy(&x, &tmp, 4);
  731. return x;
  732. }
  733. #if defined(FE_ALL_EXCEPT)
  734. #define SIMDE_HAVE_FENV_H
  735. #elif defined(__has_include)
  736. #if __has_include(<fenv.h>)
  737. #include <fenv.h>
  738. #define SIMDE_HAVE_FENV_H
  739. #endif
  740. #elif SIMDE_STDC_HOSTED == 1
  741. #include <fenv.h>
  742. #define SIMDE_HAVE_FENV_H
  743. #endif
  744. #if defined(EXIT_FAILURE)
  745. #define SIMDE_HAVE_STDLIB_H
  746. #elif defined(__has_include)
  747. #if __has_include(<stdlib.h>)
  748. #include <stdlib.h>
  749. #define SIMDE_HAVE_STDLIB_H
  750. #endif
  751. #elif SIMDE_STDC_HOSTED == 1
  752. #include <stdlib.h>
  753. #define SIMDE_HAVE_STDLIB_H
  754. #endif
  755. #if defined(__has_include)
  756. # if defined(__cplusplus) && (__cplusplus >= 201103L) && __has_include(<cfenv>)
  757. # include <cfenv>
  758. # elif __has_include(<fenv.h>)
  759. # include <fenv.h>
  760. # endif
  761. # if __has_include(<stdlib.h>)
  762. # include <stdlib.h>
  763. # endif
  764. #elif SIMDE_STDC_HOSTED == 1
  765. # include <stdlib.h>
  766. # include <fenv.h>
  767. #endif
  768. #define SIMDE_DEFINE_CONVERSION_FUNCTION_(Name, T_To, T_From) \
  769. static HEDLEY_ALWAYS_INLINE HEDLEY_CONST SIMDE_FUNCTION_POSSIBLY_UNUSED_ \
  770. T_To \
  771. Name (T_From value) { \
  772. T_To r; \
  773. simde_memcpy(&r, &value, sizeof(r)); \
  774. return r; \
  775. }
  776. SIMDE_DEFINE_CONVERSION_FUNCTION_(simde_float32_as_uint32, uint32_t, simde_float32)
  777. SIMDE_DEFINE_CONVERSION_FUNCTION_(simde_uint32_as_float32, simde_float32, uint32_t)
  778. SIMDE_DEFINE_CONVERSION_FUNCTION_(simde_float64_as_uint64, uint64_t, simde_float64)
  779. SIMDE_DEFINE_CONVERSION_FUNCTION_(simde_uint64_as_float64, simde_float64, uint64_t)
  780. #include "check.h"
  781. /* GCC/clang have a bunch of functionality in builtins which we would
  782. * like to access, but the suffixes indicate whether the operate on
  783. * int, long, or long long, not fixed width types (e.g., int32_t).
  784. * we use these macros to attempt to map from fixed-width to the
  785. * names GCC uses. Note that you should still cast the input(s) and
  786. * return values (to/from SIMDE_BUILTIN_TYPE_*_) since often even if
  787. * types are the same size they may not be compatible according to the
  788. * compiler. For example, on x86 long and long lonsg are generally
  789. * both 64 bits, but platforms vary on whether an int64_t is mapped
  790. * to a long or long long. */
  791. #include <limits.h>
  792. HEDLEY_DIAGNOSTIC_PUSH
  793. SIMDE_DIAGNOSTIC_DISABLE_CPP98_COMPAT_PEDANTIC_
  794. #if (INT8_MAX == INT_MAX) && (INT8_MIN == INT_MIN)
  795. #define SIMDE_BUILTIN_SUFFIX_8_
  796. #define SIMDE_BUILTIN_TYPE_8_ int
  797. #elif (INT8_MAX == LONG_MAX) && (INT8_MIN == LONG_MIN)
  798. #define SIMDE_BUILTIN_SUFFIX_8_ l
  799. #define SIMDE_BUILTIN_TYPE_8_ long
  800. #elif (INT8_MAX == LLONG_MAX) && (INT8_MIN == LLONG_MIN)
  801. #define SIMDE_BUILTIN_SUFFIX_8_ ll
  802. #define SIMDE_BUILTIN_TYPE_8_ long long
  803. #endif
  804. #if (INT16_MAX == INT_MAX) && (INT16_MIN == INT_MIN)
  805. #define SIMDE_BUILTIN_SUFFIX_16_
  806. #define SIMDE_BUILTIN_TYPE_16_ int
  807. #elif (INT16_MAX == LONG_MAX) && (INT16_MIN == LONG_MIN)
  808. #define SIMDE_BUILTIN_SUFFIX_16_ l
  809. #define SIMDE_BUILTIN_TYPE_16_ long
  810. #elif (INT16_MAX == LLONG_MAX) && (INT16_MIN == LLONG_MIN)
  811. #define SIMDE_BUILTIN_SUFFIX_16_ ll
  812. #define SIMDE_BUILTIN_TYPE_16_ long long
  813. #endif
  814. #if (INT32_MAX == INT_MAX) && (INT32_MIN == INT_MIN)
  815. #define SIMDE_BUILTIN_SUFFIX_32_
  816. #define SIMDE_BUILTIN_TYPE_32_ int
  817. #elif (INT32_MAX == LONG_MAX) && (INT32_MIN == LONG_MIN)
  818. #define SIMDE_BUILTIN_SUFFIX_32_ l
  819. #define SIMDE_BUILTIN_TYPE_32_ long
  820. #elif (INT32_MAX == LLONG_MAX) && (INT32_MIN == LLONG_MIN)
  821. #define SIMDE_BUILTIN_SUFFIX_32_ ll
  822. #define SIMDE_BUILTIN_TYPE_32_ long long
  823. #endif
  824. #if (INT64_MAX == INT_MAX) && (INT64_MIN == INT_MIN)
  825. #define SIMDE_BUILTIN_SUFFIX_64_
  826. #define SIMDE_BUILTIN_TYPE_64_ int
  827. #elif (INT64_MAX == LONG_MAX) && (INT64_MIN == LONG_MIN)
  828. #define SIMDE_BUILTIN_SUFFIX_64_ l
  829. #define SIMDE_BUILTIN_TYPE_64_ long
  830. #elif (INT64_MAX == LLONG_MAX) && (INT64_MIN == LLONG_MIN)
  831. #define SIMDE_BUILTIN_SUFFIX_64_ ll
  832. #define SIMDE_BUILTIN_TYPE_64_ long long
  833. #endif
  834. /* SIMDE_DIAGNOSTIC_DISABLE_CPP98_COMPAT_PEDANTIC_ */
  835. HEDLEY_DIAGNOSTIC_POP
  836. #if defined(SIMDE_BUILTIN_SUFFIX_8_)
  837. #define SIMDE_BUILTIN_8_(name) HEDLEY_CONCAT3(__builtin_, name, SIMDE_BUILTIN_SUFFIX_8_)
  838. #define SIMDE_BUILTIN_HAS_8_(name) HEDLEY_HAS_BUILTIN(HEDLEY_CONCAT3(__builtin_, name, SIMDE_BUILTIN_SUFFIX_8_))
  839. #else
  840. #define SIMDE_BUILTIN_HAS_8_(name) 0
  841. #endif
  842. #if defined(SIMDE_BUILTIN_SUFFIX_16_)
  843. #define SIMDE_BUILTIN_16_(name) HEDLEY_CONCAT3(__builtin_, name, SIMDE_BUILTIN_SUFFIX_16_)
  844. #define SIMDE_BUILTIN_HAS_16_(name) HEDLEY_HAS_BUILTIN(HEDLEY_CONCAT3(__builtin_, name, SIMDE_BUILTIN_SUFFIX_16_))
  845. #else
  846. #define SIMDE_BUILTIN_HAS_16_(name) 0
  847. #endif
  848. #if defined(SIMDE_BUILTIN_SUFFIX_32_)
  849. #define SIMDE_BUILTIN_32_(name) HEDLEY_CONCAT3(__builtin_, name, SIMDE_BUILTIN_SUFFIX_32_)
  850. #define SIMDE_BUILTIN_HAS_32_(name) HEDLEY_HAS_BUILTIN(HEDLEY_CONCAT3(__builtin_, name, SIMDE_BUILTIN_SUFFIX_32_))
  851. #else
  852. #define SIMDE_BUILTIN_HAS_32_(name) 0
  853. #endif
  854. #if defined(SIMDE_BUILTIN_SUFFIX_64_)
  855. #define SIMDE_BUILTIN_64_(name) HEDLEY_CONCAT3(__builtin_, name, SIMDE_BUILTIN_SUFFIX_64_)
  856. #define SIMDE_BUILTIN_HAS_64_(name) HEDLEY_HAS_BUILTIN(HEDLEY_CONCAT3(__builtin_, name, SIMDE_BUILTIN_SUFFIX_64_))
  857. #else
  858. #define SIMDE_BUILTIN_HAS_64_(name) 0
  859. #endif
  860. #if !defined(__cplusplus)
  861. #if defined(__clang__)
  862. #if HEDLEY_HAS_WARNING("-Wc11-extensions")
  863. #define SIMDE_GENERIC_(...) (__extension__ ({ \
  864. HEDLEY_DIAGNOSTIC_PUSH \
  865. _Pragma("clang diagnostic ignored \"-Wc11-extensions\"") \
  866. _Generic(__VA_ARGS__); \
  867. HEDLEY_DIAGNOSTIC_POP \
  868. }))
  869. #elif HEDLEY_HAS_WARNING("-Wc1x-extensions")
  870. #define SIMDE_GENERIC_(...) (__extension__ ({ \
  871. HEDLEY_DIAGNOSTIC_PUSH \
  872. _Pragma("clang diagnostic ignored \"-Wc1x-extensions\"") \
  873. _Generic(__VA_ARGS__); \
  874. HEDLEY_DIAGNOSTIC_POP \
  875. }))
  876. #endif
  877. #elif \
  878. defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L) || \
  879. HEDLEY_HAS_EXTENSION(c_generic_selections) || \
  880. HEDLEY_GCC_VERSION_CHECK(4,9,0) || \
  881. HEDLEY_INTEL_VERSION_CHECK(17,0,0) || \
  882. HEDLEY_IBM_VERSION_CHECK(12,1,0) || \
  883. HEDLEY_ARM_VERSION_CHECK(5,3,0)
  884. #define SIMDE_GENERIC_(...) _Generic(__VA_ARGS__)
  885. #endif
  886. #endif
  887. /* Sometimes we run into problems with specific versions of compilers
  888. which make the native versions unusable for us. Often this is due
  889. to missing functions, sometimes buggy implementations, etc. These
  890. macros are how we check for specific bugs. As they are fixed we'll
  891. start only defining them for problematic compiler versions. */
  892. #if !defined(SIMDE_IGNORE_COMPILER_BUGS)
  893. # if defined(HEDLEY_GCC_VERSION)
  894. # if !HEDLEY_GCC_VERSION_CHECK(4,9,0)
  895. # define SIMDE_BUG_GCC_REV_208793
  896. # endif
  897. # if !HEDLEY_GCC_VERSION_CHECK(5,0,0)
  898. # define SIMDE_BUG_GCC_BAD_MM_SRA_EPI32 /* TODO: find relevant bug or commit */
  899. # endif
  900. # if !HEDLEY_GCC_VERSION_CHECK(6,0,0)
  901. # define SIMDE_BUG_GCC_SIZEOF_IMMEDIATE
  902. # endif
  903. # if !HEDLEY_GCC_VERSION_CHECK(4,6,0)
  904. # define SIMDE_BUG_GCC_BAD_MM_EXTRACT_EPI8 /* TODO: find relevant bug or commit */
  905. # endif
  906. # if !HEDLEY_GCC_VERSION_CHECK(7,4,0) || (HEDLEY_GCC_VERSION_CHECK(8,0,0) && !HEDLEY_GCC_VERSION_CHECK(8,3,0))
  907. # define SIMDE_BUG_GCC_87467
  908. # endif
  909. # if !HEDLEY_GCC_VERSION_CHECK(8,0,0)
  910. # define SIMDE_BUG_GCC_REV_247851
  911. # endif
  912. # if !HEDLEY_GCC_VERSION_CHECK(10,0,0)
  913. # define SIMDE_BUG_GCC_REV_274313
  914. # define SIMDE_BUG_GCC_91341
  915. # define SIMDE_BUG_GCC_92035
  916. # endif
  917. # if !HEDLEY_GCC_VERSION_CHECK(9,0,0) && defined(SIMDE_ARCH_AARCH64)
  918. # define SIMDE_BUG_GCC_ARM_SHIFT_SCALAR
  919. # endif
  920. # if !HEDLEY_GCC_VERSION_CHECK(9,0,0) && defined(SIMDE_ARCH_AARCH64)
  921. # define SIMDE_BUG_GCC_BAD_VEXT_REV32
  922. # endif
  923. # if !(HEDLEY_GCC_VERSION_CHECK(9,4,0) \
  924. || (HEDLEY_GCC_VERSION_CHECK(8,5,0) && !HEDLEY_GCC_VERSION_CHECK(9,0,0)) \
  925. ) && defined(SIMDE_ARCH_X86) && !defined(SIMDE_ARCH_AMD64)
  926. # define SIMDE_BUG_GCC_94482
  927. # endif
  928. # if (defined(SIMDE_ARCH_X86) && !defined(SIMDE_ARCH_AMD64)) || defined(SIMDE_ARCH_ZARCH)
  929. # define SIMDE_BUG_GCC_53784
  930. # endif
  931. # if defined(SIMDE_ARCH_X86) || defined(SIMDE_ARCH_AMD64)
  932. # if HEDLEY_GCC_VERSION_CHECK(4,3,0) /* -Wsign-conversion */
  933. # define SIMDE_BUG_GCC_95144
  934. # endif
  935. # if !HEDLEY_GCC_VERSION_CHECK(11,2,0)
  936. # define SIMDE_BUG_GCC_95483
  937. # endif
  938. # if defined(__OPTIMIZE__)
  939. # define SIMDE_BUG_GCC_100927
  940. # endif
  941. # if !(HEDLEY_GCC_VERSION_CHECK(10,3,0))
  942. # define SIMDE_BUG_GCC_98521
  943. # endif
  944. # endif
  945. # if !HEDLEY_GCC_VERSION_CHECK(9,4,0) && defined(SIMDE_ARCH_AARCH64)
  946. # define SIMDE_BUG_GCC_94488
  947. # endif
  948. # if !HEDLEY_GCC_VERSION_CHECK(9,1,0) && defined(SIMDE_ARCH_AARCH64)
  949. # define SIMDE_BUG_GCC_REV_264019
  950. # endif
  951. # if (!HEDLEY_GCC_VERSION_CHECK(9,0,0) && !defined(SIMDE_ARCH_AARCH64)) || (!defined(SIMDE_ARCH_AARCH64) && defined(SIMDE_ARCH_ARM))
  952. # define SIMDE_BUG_GCC_REV_260989
  953. # endif
  954. # if defined(SIMDE_ARCH_ARM) && !defined(SIMDE_ARCH_AARCH64)
  955. # define SIMDE_BUG_GCC_95399
  956. # define SIMDE_BUG_GCC_95471
  957. # define SIMDE_BUG_GCC_111609
  958. # if SIMDE_ARCH_ARM_CHECK(8,0)
  959. # define SIMDE_BUG_GCC_113065
  960. # endif
  961. # endif
  962. # if defined(SIMDE_ARCH_POWER)
  963. # define SIMDE_BUG_GCC_95227
  964. # define SIMDE_BUG_GCC_95782
  965. # if !HEDLEY_GCC_VERSION_CHECK(12,0,0)
  966. # define SIMDE_BUG_VEC_CPSGN_REVERSED_ARGS
  967. # endif
  968. # endif
  969. # if defined(SIMDE_ARCH_X86) || defined(SIMDE_ARCH_AMD64)
  970. # if !HEDLEY_GCC_VERSION_CHECK(10,2,0) && !defined(__OPTIMIZE__)
  971. # define SIMDE_BUG_GCC_96174
  972. # endif
  973. # endif
  974. # if defined(SIMDE_ARCH_ZARCH)
  975. # define SIMDE_BUG_GCC_95782
  976. # if HEDLEY_GCC_VERSION_CHECK(10,0,0)
  977. # define SIMDE_BUG_GCC_101614
  978. # endif
  979. # endif
  980. # if defined(SIMDE_ARCH_MIPS_MSA)
  981. # define SIMDE_BUG_GCC_97248
  982. # if !HEDLEY_GCC_VERSION_CHECK(12,1,0)
  983. # define SIMDE_BUG_GCC_100760
  984. # define SIMDE_BUG_GCC_100761
  985. # define SIMDE_BUG_GCC_100762
  986. # endif
  987. # endif
  988. # if !defined(__OPTIMIZE__) && !(\
  989. HEDLEY_GCC_VERSION_CHECK(11,4,0) \
  990. || (HEDLEY_GCC_VERSION_CHECK(10,4,0) && !(HEDLEY_GCC_VERSION_CHECK(11,0,0))) \
  991. || (HEDLEY_GCC_VERSION_CHECK(9,5,0) && !(HEDLEY_GCC_VERSION_CHECK(10,0,0))))
  992. # define SIMDE_BUG_GCC_105339
  993. # endif
  994. # elif defined(__clang__)
  995. # if defined(SIMDE_ARCH_AARCH64)
  996. # define SIMDE_BUG_CLANG_48257 // https://github.com/llvm/llvm-project/issues/47601
  997. # define SIMDE_BUG_CLANG_71362 // https://github.com/llvm/llvm-project/issues/71362
  998. # define SIMDE_BUG_CLANG_71365 // https://github.com/llvm/llvm-project/issues/71365
  999. # define SIMDE_BUG_CLANG_71751 // https://github.com/llvm/llvm-project/issues/71751
  1000. # if !SIMDE_DETECT_CLANG_VERSION_CHECK(15,0,0)
  1001. # define SIMDE_BUG_CLANG_45541
  1002. # endif
  1003. # if !SIMDE_DETECT_CLANG_VERSION_CHECK(12,0,0)
  1004. # define SIMDE_BUG_CLANG_46840
  1005. # define SIMDE_BUG_CLANG_46844
  1006. # endif
  1007. # if SIMDE_DETECT_CLANG_VERSION_CHECK(10,0,0) && SIMDE_DETECT_CLANG_VERSION_NOT(11,0,0)
  1008. # define SIMDE_BUG_CLANG_BAD_VI64_OPS
  1009. # endif
  1010. # if SIMDE_DETECT_CLANG_VERSION_NOT(9,0,0)
  1011. # define SIMDE_BUG_CLANG_GIT_4EC445B8
  1012. # define SIMDE_BUG_CLANG_REV_365298 /* 0464e07c8f6e3310c28eb210a4513bc2243c2a7e */
  1013. # endif
  1014. # endif
  1015. # if defined(SIMDE_ARCH_ARM)
  1016. # if !SIMDE_DETECT_CLANG_VERSION_CHECK(11,0,0)
  1017. # define SIMDE_BUG_CLANG_BAD_VGET_SET_LANE_TYPES
  1018. # endif
  1019. # if defined(SIMDE_ARM_NEON_A32V7_NATIVE) && !defined(SIMDE_ARM_NEON_A32V8_NATIVE)
  1020. # define SIMDE_BUG_CLANG_71763 // https://github.com/llvm/llvm-project/issues/71763
  1021. # endif
  1022. # endif
  1023. # if defined(SIMDE_ARCH_POWER) && !SIMDE_DETECT_CLANG_VERSION_CHECK(12,0,0)
  1024. # define SIMDE_BUG_CLANG_46770
  1025. # endif
  1026. # if defined(SIMDE_ARCH_POWER) && (SIMDE_ARCH_POWER == 700) && (SIMDE_DETECT_CLANG_VERSION_CHECK(11,0,0))
  1027. # if !SIMDE_DETECT_CLANG_VERSION_CHECK(13,0,0)
  1028. # define SIMDE_BUG_CLANG_50893
  1029. # define SIMDE_BUG_CLANG_50901
  1030. # endif
  1031. # endif
  1032. # if defined(_ARCH_PWR9) && !SIMDE_DETECT_CLANG_VERSION_CHECK(12,0,0) && !defined(__OPTIMIZE__)
  1033. # define SIMDE_BUG_CLANG_POWER9_16x4_BAD_SHIFT
  1034. # endif
  1035. # if defined(SIMDE_ARCH_POWER)
  1036. # if !SIMDE_DETECT_CLANG_VERSION_CHECK(14,0,0)
  1037. # define SIMDE_BUG_CLANG_50932
  1038. # endif
  1039. # if !SIMDE_DETECT_CLANG_VERSION_CHECK(12,0,0)
  1040. # define SIMDE_BUG_VEC_CPSGN_REVERSED_ARGS
  1041. # endif
  1042. # endif
  1043. # if defined(SIMDE_ARCH_X86) || defined(SIMDE_ARCH_AMD64)
  1044. # if SIMDE_DETECT_CLANG_VERSION_NOT(5,0,0)
  1045. # define SIMDE_BUG_CLANG_REV_298042 /* 6afc436a7817a52e78ae7bcdc3faafd460124cac */
  1046. # endif
  1047. # if SIMDE_DETECT_CLANG_VERSION_NOT(3,7,0)
  1048. # define SIMDE_BUG_CLANG_REV_234560 /* b929ad7b1726a32650a8051f69a747fb6836c540 */
  1049. # endif
  1050. # if SIMDE_DETECT_CLANG_VERSION_CHECK(3,8,0) && SIMDE_DETECT_CLANG_VERSION_NOT(5,0,0)
  1051. # define SIMDE_BUG_CLANG_BAD_MADD
  1052. # endif
  1053. # if SIMDE_DETECT_CLANG_VERSION_CHECK(4,0,0) && SIMDE_DETECT_CLANG_VERSION_NOT(5,0,0)
  1054. # define SIMDE_BUG_CLANG_REV_299346 /* ac9959eb533a58482ea4da6c4db1e635a98de384 */
  1055. # endif
  1056. # if SIMDE_DETECT_CLANG_VERSION_NOT(8,0,0)
  1057. # define SIMDE_BUG_CLANG_REV_344862 /* eae26bf73715994c2bd145f9b6dc3836aa4ffd4f */
  1058. # endif
  1059. # if HEDLEY_HAS_WARNING("-Wsign-conversion") && SIMDE_DETECT_CLANG_VERSION_NOT(11,0,0)
  1060. # define SIMDE_BUG_CLANG_45931
  1061. # endif
  1062. # if HEDLEY_HAS_WARNING("-Wvector-conversion") && SIMDE_DETECT_CLANG_VERSION_NOT(11,0,0)
  1063. # define SIMDE_BUG_CLANG_44589
  1064. # endif
  1065. # define SIMDE_BUG_CLANG_48673 // https://github.com/llvm/llvm-project/issues/48017
  1066. # endif
  1067. # define SIMDE_BUG_CLANG_45959 // https://github.com/llvm/llvm-project/issues/45304
  1068. # if defined(SIMDE_ARCH_WASM_SIMD128) && !SIMDE_DETECT_CLANG_VERSION_CHECK(17,0,0)
  1069. # define SIMDE_BUG_CLANG_60655
  1070. # endif
  1071. # elif defined(HEDLEY_MSVC_VERSION)
  1072. # if defined(SIMDE_ARCH_X86)
  1073. # define SIMDE_BUG_MSVC_ROUND_EXTRACT
  1074. # endif
  1075. # elif defined(HEDLEY_INTEL_VERSION)
  1076. # define SIMDE_BUG_INTEL_857088
  1077. # elif defined(HEDLEY_MCST_LCC_VERSION)
  1078. # define SIMDE_BUG_MCST_LCC_MISSING_AVX_LOAD_STORE_M128_FUNCS
  1079. # define SIMDE_BUG_MCST_LCC_MISSING_CMOV_M256
  1080. # define SIMDE_BUG_MCST_LCC_FMA_WRONG_RESULT
  1081. # elif defined(HEDLEY_PGI_VERSION)
  1082. # define SIMDE_BUG_PGI_30104
  1083. # define SIMDE_BUG_PGI_30107
  1084. # define SIMDE_BUG_PGI_30106
  1085. # endif
  1086. #endif
  1087. /* GCC and Clang both have the same issue:
  1088. * https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95144
  1089. * https://bugs.llvm.org/show_bug.cgi?id=45931
  1090. * This is just an easy way to work around it.
  1091. */
  1092. #if \
  1093. (HEDLEY_HAS_WARNING("-Wsign-conversion") && SIMDE_DETECT_CLANG_VERSION_NOT(11,0,0)) || \
  1094. HEDLEY_GCC_VERSION_CHECK(4,3,0)
  1095. # define SIMDE_BUG_IGNORE_SIGN_CONVERSION(expr) (__extension__ ({ \
  1096. HEDLEY_DIAGNOSTIC_PUSH \
  1097. _Pragma("GCC diagnostic ignored \"-Wsign-conversion\"") \
  1098. __typeof__(expr) simde_bug_ignore_sign_conversion_v_= (expr); \
  1099. HEDLEY_DIAGNOSTIC_POP \
  1100. simde_bug_ignore_sign_conversion_v_; \
  1101. }))
  1102. #else
  1103. # define SIMDE_BUG_IGNORE_SIGN_CONVERSION(expr) (expr)
  1104. #endif
  1105. /* Usually the shift count is signed (for example, NEON or SSE).
  1106. * OTOH, unsigned is good for PPC (vec_srl uses unsigned), and the only option for E2K.
  1107. * Further info: https://github.com/simd-everywhere/simde/pull/700
  1108. */
  1109. #if defined(SIMDE_ARCH_E2K) || defined(SIMDE_ARCH_POWER)
  1110. #define SIMDE_CAST_VECTOR_SHIFT_COUNT(width, value) HEDLEY_STATIC_CAST(uint##width##_t, (value))
  1111. #else
  1112. #define SIMDE_CAST_VECTOR_SHIFT_COUNT(width, value) HEDLEY_STATIC_CAST(int##width##_t, (value))
  1113. #endif
  1114. /* Initial support for RISCV V extensions based on ZVE64D. */
  1115. #if defined(SIMDE_ARCH_RISCV_ZVE64D) && SIMDE_NATURAL_VECTOR_SIZE >= 64
  1116. #define RVV_FIXED_TYPE_DEF(name, lmul) \
  1117. typedef vint8##name##_t fixed_vint8##name##_t __attribute__((riscv_rvv_vector_bits(__riscv_v_fixed_vlen * lmul))); \
  1118. typedef vint16##name##_t fixed_vint16##name##_t __attribute__((riscv_rvv_vector_bits(__riscv_v_fixed_vlen * lmul))); \
  1119. typedef vint32##name##_t fixed_vint32##name##_t __attribute__((riscv_rvv_vector_bits(__riscv_v_fixed_vlen * lmul))); \
  1120. typedef vuint8##name##_t fixed_vuint8##name##_t __attribute__((riscv_rvv_vector_bits(__riscv_v_fixed_vlen * lmul))); \
  1121. typedef vuint16##name##_t fixed_vuint16##name##_t __attribute__((riscv_rvv_vector_bits(__riscv_v_fixed_vlen * lmul))); \
  1122. typedef vuint32##name##_t fixed_vuint32##name##_t __attribute__((riscv_rvv_vector_bits(__riscv_v_fixed_vlen * lmul))); \
  1123. typedef vfloat32##name##_t fixed_vfloat32##name##_t __attribute__((riscv_rvv_vector_bits(__riscv_v_fixed_vlen * lmul)));
  1124. RVV_FIXED_TYPE_DEF(mf2, 1/2);
  1125. RVV_FIXED_TYPE_DEF(m1, 1);
  1126. RVV_FIXED_TYPE_DEF(m2, 2);
  1127. #define RVV_FIXED_TYPE_DEF_64B(name, lmul) \
  1128. typedef vint64##name##_t fixed_vint64##name##_t __attribute__((riscv_rvv_vector_bits(__riscv_v_fixed_vlen * lmul))); \
  1129. typedef vuint64##name##_t fixed_vuint64##name##_t __attribute__((riscv_rvv_vector_bits(__riscv_v_fixed_vlen * lmul))); \
  1130. typedef vfloat64##name##_t fixed_vfloat64##name##_t __attribute__((riscv_rvv_vector_bits(__riscv_v_fixed_vlen * lmul)));
  1131. RVV_FIXED_TYPE_DEF_64B(m1, 1);
  1132. RVV_FIXED_TYPE_DEF_64B(m2, 2);
  1133. #if defined(SIMDE_ARCH_RISCV_ZVFH)
  1134. #define RVV_FIXED_TYPE_DEF_16F(name, lmul) \
  1135. typedef vfloat16##name##_t fixed_vfloat16##name##_t __attribute__((riscv_rvv_vector_bits(__riscv_v_fixed_vlen * lmul)));
  1136. RVV_FIXED_TYPE_DEF_16F(mf2, 1/2);
  1137. RVV_FIXED_TYPE_DEF_16F(m1, 1);
  1138. RVV_FIXED_TYPE_DEF_16F(m2, 2);
  1139. #endif
  1140. #endif
  1141. /* SIMDE_DIAGNOSTIC_DISABLE_USED_BUT_MARKED_UNUSED_ */
  1142. HEDLEY_DIAGNOSTIC_POP
  1143. #endif /* !defined(SIMDE_COMMON_H) */