-
Notifications
You must be signed in to change notification settings - Fork 233
Expand file tree
/
Copy pathsse2neon.h
More file actions
11744 lines (10741 loc) · 490 KB
/
sse2neon.h
File metadata and controls
11744 lines (10741 loc) · 490 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#ifndef SSE2NEON_H
#define SSE2NEON_H
/*
* sse2neon is freely redistributable under the MIT License.
*
* Copyright (c) 2015-2026 SSE2NEON Contributors.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
// This header file provides a simple API translation layer
// between SSE intrinsics to their corresponding Arm/Aarch64 NEON versions
//
// Contributors to this work are:
// John W. Ratcliff <jratcliffscarab@gmail.com>
// Brandon Rowlett <browlett@nvidia.com>
// Ken Fast <kfast@gdeb.com>
// Eric van Beurden <evanbeurden@nvidia.com>
// Alexander Potylitsin <apotylitsin@nvidia.com>
// Hasindu Gamaarachchi <hasindu2008@gmail.com>
// Jim Huang <jserv@ccns.ncku.edu.tw>
// Mark Cheng <marktwtn@gmail.com>
// Malcolm James MacLeod <malcolm@gulden.com>
// Devin Hussey (easyaspi314) <husseydevin@gmail.com>
// Sebastian Pop <spop@amazon.com>
// Developer Ecosystem Engineering <DeveloperEcosystemEngineering@apple.com>
// Danila Kutenin <danilak@google.com>
// François Turban (JishinMaster) <francois.turban@gmail.com>
// Pei-Hsuan Hung <afcidk@gmail.com>
// Yang-Hao Yuan <yuanyanghau@gmail.com>
// Syoyo Fujita <syoyo@lighttransport.com>
// Brecht Van Lommel <brecht@blender.org>
// Jonathan Hue <jhue@adobe.com>
// Cuda Chen <clh960524@gmail.com>
// Aymen Qader <aymen.qader@arm.com>
// Anthony Roberts <anthony.roberts@linaro.org>
// Sean Luchen <seanluchen@google.com>
// Marcin Serwin <marcin@serwin.dev>
// Ben Niu <beniu@microsoft.com>
// Even Rouault <even.rouault@spatialys.com>
// Marcus Buretorp <marcus.buretorp@machinegames.com>
/* Tunable configurations */
/* PRECISION FLAGS
*
* These flags control the precision/performance trade-off for operations where
* NEON behavior diverges from x86 SSE. Default is 0 (performance over
* precision). Set to 1 before including this header for x86-compatible
* behavior.
*
* Example:
* #define SSE2NEON_PRECISE_MINMAX 1 // Enable before include
* #include "sse2neon.h"
*
* Recommended configurations:
* - Performance: No flags (default)
* - Balanced: SSE2NEON_PRECISE_MINMAX=1, SSE2NEON_PRECISE_SQRT=1
* (ARMv7: also consider SSE2NEON_PRECISE_DIV=1 for division)
* - Exact: All flags set to 1
*/
/* SSE2NEON_PRECISE_MINMAX
* Affects: _mm_min_ps, _mm_max_ps, _mm_min_ss, _mm_max_ss,
* _mm_min_pd, _mm_max_pd, _mm_min_sd, _mm_max_sd
*
* Issue: NEON fmin/fmax propagate NaN differently than SSE. When one operand
* is NaN, SSE returns the second operand while NEON may return NaN.
*
* Default (0): Fast NEON min/max, potential NaN divergence
* Enabled (1): Additional comparison to match x86 NaN handling
*
* Symptoms when disabled: NaN "holes" in rendered images, unexpected NaN
* propagation in signal processing
*/
#ifndef SSE2NEON_PRECISE_MINMAX
#define SSE2NEON_PRECISE_MINMAX (0)
#endif
/* SSE2NEON_PRECISE_DIV
* Affects: _mm_rcp_ps, _mm_rcp_ss (all architectures)
* _mm_div_ps, _mm_div_ss (ARMv7 only, ARMv8 uses native vdivq_f32)
*
* Issue: NEON reciprocal estimate (vrecpe) has ~11-bit precision. SSE's rcpps
* provides ~12-bit precision. For division on ARMv7, we use reciprocal
* approximation since there's no native divide instruction.
*
* Default (0): Single Newton-Raphson refinement (~12-bit precision)
* Enabled (1): Two N-R refinements (~24-bit precision)
*
* Note on reciprocals: Enabling this flag makes _mm_rcp_ps MORE accurate than
* SSE's specified ~12-bit precision. This improves ARMv7 division accuracy but
* may differ from code expecting SSE's coarser reciprocal approximation.
*
* WARNING: This flag improves numerical precision only. It does NOT fix
* IEEE-754 corner-case divergence (NaN propagation, signed zero, infinity
* handling). ARMv7 division behavior will still differ from x86 SSE for these
* edge cases.
*
* Symptoms when disabled: Slight precision differences in division-heavy code
*/
#ifndef SSE2NEON_PRECISE_DIV
#define SSE2NEON_PRECISE_DIV (0)
#endif
/* SSE2NEON_PRECISE_SQRT
* Affects: _mm_sqrt_ps, _mm_sqrt_ss, _mm_rsqrt_ps, _mm_rsqrt_ss
*
* Issue: NEON reciprocal square root estimate (vrsqrte) has lower precision
* than x86 SSE's rsqrtps/sqrtps.
*
* Default (0): Single Newton-Raphson refinement
* Enabled (1): Two N-R refinements for improved precision
*
* Symptoms when disabled: Precision loss in physics simulations, graphics
* normalization, or iterative algorithms
*/
#ifndef SSE2NEON_PRECISE_SQRT
#define SSE2NEON_PRECISE_SQRT (0)
#endif
/* SSE2NEON_PRECISE_DP
* Affects: _mm_dp_ps, _mm_dp_pd
*
* Issue: The dot product mask parameter controls which elements participate.
* When an element is masked out, x86 multiplies by 0.0 while NEON
* skips the multiply entirely.
*
* Default (0): Skip masked elements (faster, but 0.0 * NaN = NaN divergence)
* Enabled (1): Multiply masked elements by 0.0 (matches x86 NaN propagation)
*
* Symptoms when disabled: Different results when dot product inputs contain
* NaN in masked-out lanes
*/
#ifndef SSE2NEON_PRECISE_DP
#define SSE2NEON_PRECISE_DP (0)
#endif
/* SSE2NEON_UNDEFINED_ZERO
* Affects: _mm_undefined_ps, _mm_undefined_si128, _mm_undefined_pd
*
* Issue: These intrinsics return vectors with "undefined" contents per Intel
* spec. On x86, this means truly uninitialized memory (garbage values).
*
* MSVC Semantic Drift: MSVC on ARM forces zero-initialization for these
* intrinsics, which differs from x86 behavior where garbage is returned.
* GCC/Clang on ARM match x86 by returning uninitialized memory.
*
* This macro provides explicit control over the behavior:
* Default (0): Compiler-dependent (MSVC=zero, GCC/Clang=undefined)
* Enabled (1): Force zero-initialization on all compilers (safer, portable)
*
* When to enable:
* - Deterministic behavior across compilers is required
* - Debugging memory-related issues where undefined values cause problems
* - Security-sensitive code where uninitialized memory is a concern
*
* Note: Using undefined values without first writing to them is undefined
* behavior. Well-formed code should not depend on either behavior.
*/
#ifndef SSE2NEON_UNDEFINED_ZERO
#define SSE2NEON_UNDEFINED_ZERO (0)
#endif
/* SSE2NEON_MWAIT_POLICY
* Affects: _mm_mwait
*
* Issue: x86 MONITOR/MWAIT allows a thread to sleep until a write occurs to a
* monitored address range. ARM has no userspace equivalent for address-
* range monitoring. _mm_monitor is a no-op; _mm_mwait can only provide
* low-power wait hints without true "wake on store" semantics.
*
* Note: The x86 extensions/hints parameters (C-state hints) are ignored on ARM
* as there is no architectural equivalent. No memory ordering is provided
* beyond what the hint instruction itself offers.
*
* WARNING: Policies 1 and 2 (WFE/WFI) may cause issues:
* - WFE: May sleep until event/interrupt; can wake spuriously. Always check
* your condition in a loop. May trap in EL0 (SCTLR_EL1.nTWE).
* - WFI: May trap (SIGILL) in EL0 on Linux, iOS, macOS (SCTLR_EL1.nTWI).
* - Neither provides "wake on address write" semantics.
*
* Policy values:
* 0 (default): yield - Safe everywhere, never blocks, just a hint
* 1: wfe - Event wait, may sleep until event/interrupt
* 2: wfi - Interrupt wait, may trap in EL0 on many platforms
*
* Recommended usage:
* - Policy 0: General-purpose code, spin-wait loops (safe default)
* - Policy 1: Only if you control both reader/writer and use SEV/SEVL
* - Policy 2: Only for bare-metal or kernel code with known OS support
*
* Migration note: Code relying on x86 MONITOR/MWAIT for lock-free waiting
* should migrate to proper atomics + OS wait primitives (futex, condition
* variables) for correct cross-platform behavior.
*/
#ifndef SSE2NEON_MWAIT_POLICY
#define SSE2NEON_MWAIT_POLICY (0)
#endif
/* Enable inclusion of windows.h on MSVC platforms
* This makes _mm_clflush functional on windows, as there is no builtin.
*/
#ifndef SSE2NEON_INCLUDE_WINDOWS_H
#define SSE2NEON_INCLUDE_WINDOWS_H (0)
#endif
/* Consolidated Platform Detection
*
* These macros simplify platform-specific code throughout the header by
* providing single-point definitions for architecture and compiler detection.
* This reduces the 147+ verbose architecture checks to simple macro usage.
*
* Architecture:
* SSE2NEON_ARCH_AARCH64 - 64-bit ARM (AArch64, including Apple Silicon)
* Encompasses: __aarch64__, __arm64__, _M_ARM64, _M_ARM64EC
*
* Compiler:
* SSE2NEON_COMPILER_GCC_COMPAT - GCC or Clang (supports GNU extensions)
* SSE2NEON_COMPILER_MSVC - Microsoft Visual C++
* SSE2NEON_COMPILER_CLANG - Clang specifically (subset of GCC_COMPAT)
*/
/* Compiler detection
*
* Check Clang first: it defines __GNUC__ for compatibility.
* Clang-CL also defines _MSC_VER for MSVC ABI compatibility.
*
* Compiler matrix:
* Compiler | GCC_COMPAT | CLANG | MSVC
* -----------+------------+-------+------
* GCC | 1 | 0 | 0
* Clang | 1 | 1 | 0
* Clang-CL | 1 | 1 | 1
* MSVC | 0 | 0 | 1
*/
#if defined(__clang__)
/* Clang compiler detected (including Apple Clang) */
#define SSE2NEON_COMPILER_CLANG 1
#define SSE2NEON_COMPILER_GCC_COMPAT 1 /* Clang supports GCC extensions */
#if defined(_MSC_VER)
#define SSE2NEON_COMPILER_MSVC 1 /* Clang-CL: Clang with MSVC on Windows */
#else
#define SSE2NEON_COMPILER_MSVC 0
#endif
/* Clang < 11 has known NEON codegen bugs (issue #622) */
#if __clang_major__ < 11
#error "Clang versions earlier than 11 are not supported."
#endif
#elif defined(__GNUC__)
/* GCC compiler (only reached if not Clang, since Clang also defines __GNUC__)
*/
#define SSE2NEON_COMPILER_CLANG 0
#define SSE2NEON_COMPILER_GCC_COMPAT 1
#define SSE2NEON_COMPILER_MSVC 0
/* GCC < 10 has incomplete ARM intrinsics support */
#if __GNUC__ < 10
#error "GCC versions earlier than 10 are not supported."
#endif
#elif defined(_MSC_VER)
/* Microsoft Visual C++ (native, not Clang-CL) */
#define SSE2NEON_COMPILER_CLANG 0
#define SSE2NEON_COMPILER_GCC_COMPAT 0 /* No GCC extensions available */
#define SSE2NEON_COMPILER_MSVC 1
#else
#error "Unsupported compiler. SSE2NEON requires GCC 10+, Clang 11+, or MSVC."
#endif
/* Architecture detection */
#if defined(__aarch64__) || defined(__arm64__) || defined(_M_ARM64) || \
defined(_M_ARM64EC)
#define SSE2NEON_ARCH_AARCH64 1
#else
#define SSE2NEON_ARCH_AARCH64 0
#endif
/* ARM64EC Support - EXPERIMENTAL with known limitations
*
* ARM64EC is Microsoft's hybrid ABI bridging x64 and ARM64 within a single
* Windows process, enabling incremental migration of x64 applications to ARM64.
* Compiler support remains incomplete (limited LLVM/GCC coverage).
*
* Compiler behavior:
* - MSVC defines both _M_AMD64 and _M_ARM64EC (but NOT _M_ARM64)
* - Requires arm64_neon.h instead of arm_neon.h
*
* Known limitations:
* 1. Windows headers: SSE2NEON_INCLUDE_WINDOWS_H must be 0 (default).
* Include sse2neon.h BEFORE any Windows headers to avoid type conflicts.
* 2. Include order: sse2neon.h must be included BEFORE <intrin.h> or any C++
* standard headers that pull it in (e.g., <cmath>, <algorithm>).
* 3. ABI boundary: __m128/SSE types must NOT cross x64/ARM64EC module
* boundaries (exports/imports) as layouts differ between ABIs.
* Users needing cross-ABI SIMD interop should use MSVC's softintrin.
* 4. CRC32 hardware intrinsics are disabled; software fallback is used.
*
* SSE2NEON_ARM64EC is 1 when compiling for ARM64EC with MSVC, 0 otherwise.
* Note: clang-cl ARM64EC builds are not currently detected by this macro.
*
* Recommendation: Use native ARM64 compilation when possible.
*/
#if SSE2NEON_COMPILER_MSVC && defined(_M_ARM64EC)
#define SSE2NEON_ARM64EC 1
#else
#define SSE2NEON_ARM64EC 0
#endif
/* Early ARM64EC + SSE2NEON_INCLUDE_WINDOWS_H check.
* This must come BEFORE any standard includes because <intrin.h> and other
* headers can trigger winnt.h, which fails with "Must define a target
* architecture" on ARM64EC before we could emit our own error.
*/
#if SSE2NEON_ARM64EC && SSE2NEON_INCLUDE_WINDOWS_H
#error \
"SSE2NEON_INCLUDE_WINDOWS_H=1 is not supported on ARM64EC. " \
"Include <windows.h> separately AFTER sse2neon.h instead."
#endif
/* Endianness check
*
* SSE2NEON assumes little-endian byte ordering for lane-to-memory mappings.
* Big-endian ARM targets would produce silently incorrect results because
* SSE intrinsics define lane ordering relative to little-endian memory layout.
*
* GCC/Clang define __BYTE_ORDER__. For compilers that don't (e.g., MSVC),
* we check for explicit big-endian ARM macros. MSVC only targets little-endian
* ARM, so no additional check is needed there.
*/
#if defined(__BYTE_ORDER__) && (__BYTE_ORDER__ != __ORDER_LITTLE_ENDIAN__)
#error "sse2neon requires little-endian target; big-endian is not supported"
#elif defined(__ARMEB__) || defined(__AARCH64EB__) || defined(__BIG_ENDIAN__)
#error "sse2neon requires little-endian target; big-endian is not supported"
#endif
/* compiler specific definitions */
#if SSE2NEON_COMPILER_GCC_COMPAT
#pragma push_macro("FORCE_INLINE")
#pragma push_macro("ALIGN_STRUCT")
#define FORCE_INLINE static inline __attribute__((always_inline))
#define ALIGN_STRUCT(x) __attribute__((aligned(x)))
#define _sse2neon_likely(x) __builtin_expect(!!(x), 1)
#define _sse2neon_unlikely(x) __builtin_expect(!!(x), 0)
#elif SSE2NEON_COMPILER_MSVC
#if _MSVC_TRADITIONAL
#error Using the traditional MSVC preprocessor is not supported! Use /Zc:preprocessor instead.
#endif
#ifndef FORCE_INLINE
#define FORCE_INLINE static inline
#endif
#ifndef ALIGN_STRUCT
#define ALIGN_STRUCT(x) __declspec(align(x))
#endif
#define _sse2neon_likely(x) (x)
#define _sse2neon_unlikely(x) (x)
#endif
/* C language does not allow initializing a variable with a function call. */
#ifdef __cplusplus
#define _sse2neon_const static const
#else
#define _sse2neon_const const
#endif
#if defined(__cplusplus)
#define _sse2neon_reinterpret_cast(t, e) reinterpret_cast<t>(e)
#define _sse2neon_static_cast(t, e) static_cast<t>(e)
#define _sse2neon_const_cast(t, e) const_cast<t>(e)
#else
#define _sse2neon_reinterpret_cast(t, e) ((t) (e))
#define _sse2neon_static_cast(t, e) ((t) (e))
#define _sse2neon_const_cast(t, e) ((t) (e))
#endif
/* ARM64EC winnt.h workaround: define architecture macros before any headers
* that might include winnt.h. Windows SDK 10.0.26100.0+ requires _ARM64EC_ or
* _ARM64_ but MSVC 17.x only defines _M_ARM64EC.
*/
#if SSE2NEON_ARM64EC
/* Warn if winnt.h was already included - the workaround won't help */
#ifdef _WINNT_
#pragma message( \
"warning: sse2neon.h included after winnt.h; ARM64EC workaround may fail")
#endif
/* Define _ARM64EC_ for winnt.h architecture check (kept for user detection) */
#if !defined(_ARM64EC_)
#define _ARM64EC_ 1
#define _SSE2NEON_DEFINED_ARM64EC_
#endif
/* Define _M_ARM64 temporarily for headers that derive _ARM64_ from it */
#if !defined(_M_ARM64)
#define _M_ARM64 1
#define _SSE2NEON_DEFINED_M_ARM64
#endif
#endif /* SSE2NEON_ARM64EC */
#include <fenv.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
FORCE_INLINE double sse2neon_recast_u64_f64(uint64_t val)
{
double tmp;
memcpy(&tmp, &val, sizeof(uint64_t));
return tmp;
}
FORCE_INLINE int64_t sse2neon_recast_f64_s64(double val)
{
int64_t tmp;
memcpy(&tmp, &val, sizeof(uint64_t));
return tmp;
}
/* MSVC provides _mm_{malloc,free} in <malloc.h>; MinGW needs our definitions
* but still uses _aligned_malloc/_aligned_free from <malloc.h>.
*/
#if SSE2NEON_COMPILER_MSVC
#define SSE2NEON_ALLOC_DEFINED
#endif
/* If using MSVC */
#if SSE2NEON_COMPILER_MSVC
/* ARM64EC SSE header blocking: pre-define include guards to prevent MSVC SSE
* headers (mmintrin.h, xmmintrin.h, etc.) and Windows SDK softintrin.h from
* loading, as their __m128 union types conflict with sse2neon's NEON types.
*/
#if SSE2NEON_ARM64EC || defined(_M_ARM64EC)
/* Detect if <intrin.h> was already included - SSE types may have leaked.
* Check both _INTRIN_H_ and _INTRIN_H to cover different MSVC versions. */
#if defined(_INTRIN_H_) || defined(_INTRIN_H)
#error \
"sse2neon.h must be included BEFORE <intrin.h> or C++ headers on ARM64EC. " \
"SSE type definitions from <intrin.h> conflict with sse2neon's NEON types."
#endif
#define _INCLUDED_MM2
#define _MMINTRIN_H_INCLUDED
#define _XMMINTRIN_H_INCLUDED
#define _EMMINTRIN_H_INCLUDED
#define _PMMINTRIN_H_INCLUDED
#define _TMMINTRIN_H_INCLUDED
#define _SMMINTRIN_H_INCLUDED
#define _NMMINTRIN_H_INCLUDED
#define _WMMINTRIN_H_INCLUDED
#define _IMMINTRIN_H_INCLUDED
#define _ZMMINTRIN_H_INCLUDED
#define _AMMINTRIN_H_INCLUDED
/* Block Windows SDK softintrin */
#define _SOFTINTRIN_H_
#define _DISABLE_SOFTINTRIN_ 1
#endif /* SSE2NEON_ARM64EC */
#include <intrin.h>
/* Windows headers inclusion.
* ARM64EC case is blocked by early check near SSE2NEON_ARM64EC definition.
*/
#if SSE2NEON_INCLUDE_WINDOWS_H
#include <processthreadsapi.h>
#include <windows.h>
#endif
/* Clean up _M_ARM64 (could mislead into pure ARM64 paths). Keep _ARM64EC_. */
#ifdef _SSE2NEON_DEFINED_ARM64EC_
#undef _SSE2NEON_DEFINED_ARM64EC_
#endif
#ifdef _SSE2NEON_DEFINED_M_ARM64
#undef _M_ARM64
#undef _SSE2NEON_DEFINED_M_ARM64
#endif
#ifdef SSE2NEON_ALLOC_DEFINED
#include <malloc.h>
#endif
/* 64-bit bit scanning available on x64 and AArch64 (including ARM64EC) */
#if (defined(_M_AMD64) || defined(__x86_64__)) || SSE2NEON_ARCH_AARCH64
#define SSE2NEON_HAS_BITSCAN64
#endif
#endif /* SSE2NEON_COMPILER_MSVC */
/* MinGW uses _aligned_malloc/_aligned_free from <malloc.h> */
#if defined(__MINGW32__)
#include <malloc.h>
#endif
/* Statement expression helpers for macro-based intrinsics.
*
* For GCC/Clang (C and C++): Uses __extension__({}) statement expressions
* which provide local variables and natural access to surrounding scope.
*
* For MSVC C++: Uses immediately-invoked lambdas. The distinction between
* _sse2neon_define0 ([=] capture) and _sse2neon_define1 ([] no capture)
* exists for lambda capture semantics, though in practice both work the same
* since 'imm' parameters are compile-time constants substituted before the
* lambda is created.
*
* For pure C (MSVC C mode): Standard C has no block-expression mechanism, so
* _sse2neon_define0/1/2 are absent. Each intrinsic that requires them provides
* a FORCE_INLINE function fallback guarded by
* #if SSE2NEON_COMPILER_GCC_COMPAT || defined(__cplusplus) ... #else ...
* #endif at its definition site.
*/
#if SSE2NEON_COMPILER_GCC_COMPAT
#define _sse2neon_define0(type, s, body) \
__extension__({ \
type _a = (s); \
body \
})
#define _sse2neon_define1(type, s, body) _sse2neon_define0(type, s, body)
#define _sse2neon_define2(type, a, b, body) \
__extension__({ \
type _a = (a), _b = (b); \
body \
})
#define _sse2neon_return(ret) (ret)
#elif defined(__cplusplus)
/* MSVC in C++ mode: use immediately-invoked lambdas */
#define _sse2neon_define0(type, a, body) [=](type _a) { body }(a)
#define _sse2neon_define1(type, a, body) [](type _a) { body }(a)
#define _sse2neon_define2(type, a, b, body) \
[](type _a, type _b) { body }((a), (b))
#define _sse2neon_return(ret) return ret
#else
/* Pure C (MSVC C mode): _sse2neon_define0/1/2 unavailable; each intrinsic
* provides a FORCE_INLINE function fallback at its own definition site. */
#define _sse2neon_return(ret) (ret)
#endif
#define _sse2neon_init(...) {__VA_ARGS__}
/* Compiler barrier */
#if SSE2NEON_COMPILER_MSVC && !SSE2NEON_COMPILER_CLANG
#define SSE2NEON_BARRIER() _ReadWriteBarrier()
#else
#define SSE2NEON_BARRIER() \
do { \
__asm__ __volatile__("" ::: "memory"); \
(void) 0; \
} while (0)
#endif
/* Memory barriers
* __atomic_thread_fence does not include a compiler barrier; instead,
* the barrier is part of __atomic_load/__atomic_store's "volatile-like"
* semantics.
*/
#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)
#include <stdatomic.h>
#endif
FORCE_INLINE void _sse2neon_smp_mb(void)
{
SSE2NEON_BARRIER();
#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L) && \
!defined(__STDC_NO_ATOMICS__)
atomic_thread_fence(memory_order_seq_cst);
#elif SSE2NEON_COMPILER_GCC_COMPAT
__atomic_thread_fence(__ATOMIC_SEQ_CST);
#else /* MSVC */
__dmb(_ARM64_BARRIER_ISH);
#endif
}
/* Architecture-specific build options.
* #pragma GCC push_options/target are GCC-specific; Clang ignores these.
* MSVC on ARM always has NEON/SIMD available.
*/
#if SSE2NEON_COMPILER_GCC_COMPAT
#if defined(__arm__)
/* 32-bit ARM: ARMv7-A or ARMv8-A in AArch32 mode */
#if !defined(__ARM_NEON) || !defined(__ARM_NEON__)
#error "You must enable NEON instructions (e.g. -mfpu=neon) to use SSE2NEON."
#endif
#if !SSE2NEON_COMPILER_CLANG
#pragma GCC push_options
#if __ARM_ARCH >= 8
#pragma GCC target("fpu=neon-fp-armv8")
#else
#pragma GCC target("fpu=neon")
#endif
#endif
#elif SSE2NEON_ARCH_AARCH64
#if !SSE2NEON_COMPILER_CLANG
#pragma GCC push_options
#pragma GCC target("+simd")
#endif
#else
#error "Unsupported target. Must be ARMv7-A+NEON, ARMv8-A, or AArch64."
#endif
#endif
/* ARM64EC: use arm64_neon.h (arm_neon.h guards with _M_ARM||_M_ARM64) */
#if SSE2NEON_ARM64EC || defined(_M_ARM64EC)
#include <arm64_neon.h>
#else
#include <arm_neon.h>
#endif
/* Include ACLE for CRC32 and other intrinsics on ARMv8+ */
#if SSE2NEON_ARCH_AARCH64 || __ARM_ARCH >= 8
#if defined __has_include && __has_include(<arm_acle.h>)
#include <arm_acle.h>
#define SSE2NEON_HAS_ACLE 1
#else
#define SSE2NEON_HAS_ACLE 0
#endif
#else
#define SSE2NEON_HAS_ACLE 0
#endif
/* Apple Silicon cache lines are double of what is commonly used by Intel, AMD
* and other Arm microarchitectures use.
* From sysctl -a on Apple M1:
* hw.cachelinesize: 128
*/
#if defined(__APPLE__) && (defined(__aarch64__) || defined(__arm64__))
#define SSE2NEON_CACHELINE_SIZE 128
#else
#define SSE2NEON_CACHELINE_SIZE 64
#endif
/* Rounding functions require either Aarch64 instructions or libm fallback */
#if !SSE2NEON_ARCH_AARCH64
#include <math.h>
#endif
/* On ARMv7, some registers, such as PMUSERENR and PMCCNTR, are read-only or
* even not accessible in user mode.
* To write or access to these registers in user mode, we have to perform
* syscall instead.
*/
#if !SSE2NEON_ARCH_AARCH64
#include <sys/time.h>
#endif
/* "__has_builtin" can be used to query support for built-in functions
* provided by gcc/clang and other compilers that support it.
* GCC 10+ and Clang 11+ have native __has_builtin support.
* MSVC does not provide these GCC/Clang builtins.
*/
#ifndef __has_builtin
#if SSE2NEON_COMPILER_MSVC && !SSE2NEON_COMPILER_CLANG
#define __has_builtin(x) 0
#else
#error "Unsupported compiler: __has_builtin not available"
#endif
#endif
/**
* MACRO for shuffle parameter for _mm_shuffle_ps().
* Argument fp3 is a digit[0123] that represents the fp from argument "b"
* of mm_shuffle_ps that will be placed in fp3 of result. fp2 is the same
* for fp2 in result. fp1 is a digit[0123] that represents the fp from
* argument "a" of mm_shuffle_ps that will be places in fp1 of result.
* fp0 is the same for fp0 of result.
*/
#ifndef _MM_SHUFFLE
#define _MM_SHUFFLE(fp3, fp2, fp1, fp0) \
(((fp3) << 6) | ((fp2) << 4) | ((fp1) << 2) | ((fp0)))
#endif
/**
* MACRO for shuffle parameter for _mm_shuffle_pd().
* Argument fp1 is a digit[01] that represents the fp from argument "b"
* of mm_shuffle_pd that will be placed in fp1 of result.
* fp0 is a digit[01] that represents the fp from argument "a" of mm_shuffle_pd
* that will be placed in fp0 of result.
*/
#ifndef _MM_SHUFFLE2
#define _MM_SHUFFLE2(fp1, fp0) (((fp1) << 1) | (fp0))
#endif
#if __has_builtin(__builtin_shufflevector)
#define _sse2neon_shuffle(type, a, b, ...) \
__builtin_shufflevector(a, b, __VA_ARGS__)
#elif __has_builtin(__builtin_shuffle)
#define _sse2neon_shuffle(type, a, b, ...) \
__extension__({ \
type tmp = {__VA_ARGS__}; \
__builtin_shuffle(a, b, tmp); \
})
#endif
#ifdef _sse2neon_shuffle
#define vshuffle_s16(a, b, ...) _sse2neon_shuffle(int16x4_t, a, b, __VA_ARGS__)
#define vshuffleq_s16(a, b, ...) _sse2neon_shuffle(int16x8_t, a, b, __VA_ARGS__)
#define vshuffle_s32(a, b, ...) _sse2neon_shuffle(int32x2_t, a, b, __VA_ARGS__)
#define vshuffleq_s32(a, b, ...) _sse2neon_shuffle(int32x4_t, a, b, __VA_ARGS__)
#define vshuffle_s64(a, b, ...) _sse2neon_shuffle(int64x1_t, a, b, __VA_ARGS__)
#define vshuffleq_s64(a, b, ...) _sse2neon_shuffle(int64x2_t, a, b, __VA_ARGS__)
#endif
/* Rounding mode macros. */
#define _MM_FROUND_TO_NEAREST_INT 0x00
#define _MM_FROUND_TO_NEG_INF 0x01
#define _MM_FROUND_TO_POS_INF 0x02
#define _MM_FROUND_TO_ZERO 0x03
#define _MM_FROUND_CUR_DIRECTION 0x04
#define _MM_FROUND_NO_EXC 0x08
#define _MM_FROUND_RAISE_EXC 0x00
#ifndef _MM_FROUND_NINT
#define _MM_FROUND_NINT (_MM_FROUND_TO_NEAREST_INT | _MM_FROUND_RAISE_EXC)
#endif
#ifndef _MM_FROUND_FLOOR
#define _MM_FROUND_FLOOR (_MM_FROUND_TO_NEG_INF | _MM_FROUND_RAISE_EXC)
#endif
#ifndef _MM_FROUND_CEIL
#define _MM_FROUND_CEIL (_MM_FROUND_TO_POS_INF | _MM_FROUND_RAISE_EXC)
#endif
#ifndef _MM_FROUND_TRUNC
#define _MM_FROUND_TRUNC (_MM_FROUND_TO_ZERO | _MM_FROUND_RAISE_EXC)
#endif
#ifndef _MM_FROUND_RINT
#define _MM_FROUND_RINT (_MM_FROUND_CUR_DIRECTION | _MM_FROUND_RAISE_EXC)
#endif
#ifndef _MM_FROUND_NEARBYINT
#define _MM_FROUND_NEARBYINT (_MM_FROUND_CUR_DIRECTION | _MM_FROUND_NO_EXC)
#endif
#ifndef _MM_ROUND_NEAREST
#define _MM_ROUND_NEAREST 0x0000
#endif
#ifndef _MM_ROUND_DOWN
#define _MM_ROUND_DOWN 0x2000
#endif
#ifndef _MM_ROUND_UP
#define _MM_ROUND_UP 0x4000
#endif
#ifndef _MM_ROUND_TOWARD_ZERO
#define _MM_ROUND_TOWARD_ZERO 0x6000
#endif
#ifndef _MM_ROUND_MASK
#define _MM_ROUND_MASK 0x6000
#endif
/* Flush-to-zero (FTZ) mode macros.
* On x86, FTZ (MXCSR bit 15) flushes denormal outputs to zero.
* On ARM, FPCR/FPSCR bit 24 provides unified FZ+DAZ behavior.
* ARMv7 NEON: Per ARM ARM, Advanced SIMD has "Flush-to-zero mode always
* enabled" - denormals flush regardless of FPSCR.FZ (some impls may vary).
* ARMv8: FPCR.FZ correctly controls denormal handling for NEON ops.
*/
#ifndef _MM_FLUSH_ZERO_MASK
#define _MM_FLUSH_ZERO_MASK 0x8000
#endif
#ifndef _MM_FLUSH_ZERO_ON
#define _MM_FLUSH_ZERO_ON 0x8000
#endif
#ifndef _MM_FLUSH_ZERO_OFF
#define _MM_FLUSH_ZERO_OFF 0x0000
#endif
/* Denormals-are-zero (DAZ) mode macros.
* On x86, DAZ (MXCSR bit 6) treats denormal inputs as zero.
* On ARM, setting DAZ enables the same FPCR/FPSCR bit 24 as FTZ,
* providing unified handling for both input and output denormals.
*/
#ifndef _MM_DENORMALS_ZERO_MASK
#define _MM_DENORMALS_ZERO_MASK 0x0040
#endif
#ifndef _MM_DENORMALS_ZERO_ON
#define _MM_DENORMALS_ZERO_ON 0x0040
#endif
#ifndef _MM_DENORMALS_ZERO_OFF
#define _MM_DENORMALS_ZERO_OFF 0x0000
#endif
/* MXCSR Exception Flags - NOT EMULATED
*
* SSE provides floating-point exception flags in the MXCSR register (bits 0-5)
* that are NOT emulated on ARM NEON. Code relying on _mm_getcsr() to detect
* floating-point exceptions will silently fail to detect them.
*
* MXCSR Exception Flag Layout (x86):
* Bit 0 (IE): Invalid Operation Exception - NOT EMULATED
* Bit 1 (DE): Denormal Exception - NOT EMULATED
* Bit 2 (ZE): Divide-by-Zero Exception - NOT EMULATED
* Bit 3 (OE): Overflow Exception - NOT EMULATED
* Bit 4 (UE): Underflow Exception - NOT EMULATED
* Bit 5 (PE): Precision Exception - NOT EMULATED
*
* MXCSR Exception Mask Layout (x86):
* Bits 7-12: Exception masks (mask = suppress exception) - NOT EMULATED
*
* Why Not Emulated:
* - ARM NEON does not set sticky exception flags like x86 SSE
* - ARM FPSR (Floating-Point Status Register) has different semantics
* - Emulating per-operation exception tracking would require wrapping every
* floating-point intrinsic with software checks, severely impacting
* performance
* - Thread-local exception state tracking would add significant complexity
*
* Impact:
* - Scientific computing code checking for overflow/underflow will miss events
* - Financial applications validating precision will not detect precision loss
* - Numerical code checking for invalid operations (NaN generation) won't
* detect them
*
* Workarounds:
* - Use explicit NaN/Inf checks after critical operations: isnan(), isinf()
* - Implement application-level range validation for overflow detection
* - Use higher precision arithmetic where precision loss is critical
*
* The macros below are defined for API compatibility but provide no
* functionality.
*/
/* Exception flag macros (MXCSR bits 0-5) - defined for API compatibility only
*/
#ifndef _MM_EXCEPT_INVALID
#define _MM_EXCEPT_INVALID 0x0001
#endif
#ifndef _MM_EXCEPT_DENORM
#define _MM_EXCEPT_DENORM 0x0002
#endif
#ifndef _MM_EXCEPT_DIV_ZERO
#define _MM_EXCEPT_DIV_ZERO 0x0004
#endif
#ifndef _MM_EXCEPT_OVERFLOW
#define _MM_EXCEPT_OVERFLOW 0x0008
#endif
#ifndef _MM_EXCEPT_UNDERFLOW
#define _MM_EXCEPT_UNDERFLOW 0x0010
#endif
#ifndef _MM_EXCEPT_INEXACT
#define _MM_EXCEPT_INEXACT 0x0020
#endif
#ifndef _MM_EXCEPT_MASK
#define _MM_EXCEPT_MASK \
(_MM_EXCEPT_INVALID | _MM_EXCEPT_DENORM | _MM_EXCEPT_DIV_ZERO | \
_MM_EXCEPT_OVERFLOW | _MM_EXCEPT_UNDERFLOW | _MM_EXCEPT_INEXACT)
#endif
/* Exception mask macros (MXCSR bits 7-12) - defined for API compatibility only
*/
#ifndef _MM_MASK_INVALID
#define _MM_MASK_INVALID 0x0080
#endif
#ifndef _MM_MASK_DENORM
#define _MM_MASK_DENORM 0x0100
#endif
#ifndef _MM_MASK_DIV_ZERO
#define _MM_MASK_DIV_ZERO 0x0200
#endif
#ifndef _MM_MASK_OVERFLOW
#define _MM_MASK_OVERFLOW 0x0400
#endif
#ifndef _MM_MASK_UNDERFLOW
#define _MM_MASK_UNDERFLOW 0x0800
#endif
#ifndef _MM_MASK_INEXACT
#define _MM_MASK_INEXACT 0x1000
#endif
#ifndef _MM_MASK_MASK
#define _MM_MASK_MASK \
(_MM_MASK_INVALID | _MM_MASK_DENORM | _MM_MASK_DIV_ZERO | \
_MM_MASK_OVERFLOW | _MM_MASK_UNDERFLOW | _MM_MASK_INEXACT)
#endif
/* Exception state accessor macros - silent stubs for API compatibility.
* These macros exist for API compatibility but provide NO functionality.
* On ARM, exception flags are never set by sse2neon intrinsics.
*
* _MM_GET_EXCEPTION_STATE() - Always returns 0 (no exceptions detected)
* _MM_SET_EXCEPTION_STATE() - Silently ignored (cannot clear nonexistent flags)
* _MM_GET_EXCEPTION_MASK() - Always returns all-masked (0x1F80)
* _MM_SET_EXCEPTION_MASK() - Silently ignored (no effect on ARM)
*/
#ifndef _MM_GET_EXCEPTION_STATE
#define _MM_GET_EXCEPTION_STATE() (0)
#endif
#ifndef _MM_SET_EXCEPTION_STATE
#define _MM_SET_EXCEPTION_STATE(x) ((void) (x))
#endif
#ifndef _MM_GET_EXCEPTION_MASK
#define _MM_GET_EXCEPTION_MASK() (_MM_MASK_MASK)
#endif
#ifndef _MM_SET_EXCEPTION_MASK
#define _MM_SET_EXCEPTION_MASK(x) ((void) (x))
#endif
/* Compile-time validation for immediate constant arguments.
* This macro validates that:
* 1. The argument is a compile-time constant (via __builtin_constant_p)
* 2. The argument is within the specified range [min, max]
*
* When validation fails, __builtin_unreachable() is called to trigger
* compiler diagnostics. This pattern follows SIMDe's approach but adapted
* for use within macro bodies rather than as function attributes.
*
* Usage: Place at the beginning of macro bodies that require immediate
* constant arguments. The macro expands to a statement, so use a semicolon:
* SSE2NEON_REQUIRE_CONST_RANGE(imm, 0, 255);
*/
#if defined(__has_builtin)
#if __has_builtin(__builtin_constant_p) && __has_builtin(__builtin_unreachable)
#define SSE2NEON_REQUIRE_CONST_RANGE(arg, min, max) \
(void) ((__builtin_constant_p(arg) && ((arg) < (min) || (arg) > (max))) \
? (__builtin_unreachable(), 0) \
: 0)
#endif
#endif
#if !defined(SSE2NEON_REQUIRE_CONST_RANGE)
/* Fallback: no compile-time validation */
#define SSE2NEON_REQUIRE_CONST_RANGE(arg, min, max) ((void) 0)
#endif
/* Allow users to disable constant validation if needed for testing */
#ifdef SSE2NEON_DISABLE_CONSTANT_VALIDATION
#undef SSE2NEON_REQUIRE_CONST_RANGE
#define SSE2NEON_REQUIRE_CONST_RANGE(arg, min, max) ((void) 0)
#endif
/* A few intrinsics accept traditional data types like ints or floats, but
* most operate on data types that are specific to SSE.
* If a vector type ends in d, it contains doubles, and if it does not have
* a suffix, it contains floats. An integer vector type can contain any type
* of integer, from chars to shorts to unsigned long longs.
*/
typedef int64x1_t __m64;
typedef float32x4_t __m128; /* 128-bit vector containing 4 floats */
// On ARM 32-bit architecture, the float64x2_t is not supported.
// The data type __m128d should be represented in a different way for related
// intrinsic conversion.
#if SSE2NEON_ARCH_AARCH64
typedef float64x2_t __m128d; /* 128-bit vector containing 2 doubles */
#else
typedef float32x4_t __m128d;
#endif
typedef int64x2_t __m128i; /* 128-bit vector containing integers */
// Some intrinsics operate on unaligned data types.
typedef int16_t ALIGN_STRUCT(1) unaligned_int16_t;
typedef int32_t ALIGN_STRUCT(1) unaligned_int32_t;
typedef int64_t ALIGN_STRUCT(1) unaligned_int64_t;
// __int64 is defined in the Intrinsics Guide which maps to different datatype
// in different data model
#if !(defined(_WIN32) || defined(_WIN64) || defined(__int64))
#if (defined(__x86_64__) || defined(__i386__))
#define __int64 long long
#else
#define __int64 int64_t
#endif
#endif
/* type-safe casting between types */
#define vreinterpretq_m128_f16(x) vreinterpretq_f32_f16(x)
#define vreinterpretq_m128_f32(x) (x)
#define vreinterpretq_m128_f64(x) vreinterpretq_f32_f64(x)
#define vreinterpretq_m128_u8(x) vreinterpretq_f32_u8(x)
#define vreinterpretq_m128_u16(x) vreinterpretq_f32_u16(x)
#define vreinterpretq_m128_u32(x) vreinterpretq_f32_u32(x)
#define vreinterpretq_m128_u64(x) vreinterpretq_f32_u64(x)
#define vreinterpretq_m128_s8(x) vreinterpretq_f32_s8(x)
#define vreinterpretq_m128_s16(x) vreinterpretq_f32_s16(x)
#define vreinterpretq_m128_s32(x) vreinterpretq_f32_s32(x)
#define vreinterpretq_m128_s64(x) vreinterpretq_f32_s64(x)
#define vreinterpretq_f16_m128(x) vreinterpretq_f16_f32(x)
#define vreinterpretq_f32_m128(x) (x)
#define vreinterpretq_f64_m128(x) vreinterpretq_f64_f32(x)
#define vreinterpretq_u8_m128(x) vreinterpretq_u8_f32(x)
#define vreinterpretq_u16_m128(x) vreinterpretq_u16_f32(x)
#define vreinterpretq_u32_m128(x) vreinterpretq_u32_f32(x)
#define vreinterpretq_u64_m128(x) vreinterpretq_u64_f32(x)
#define vreinterpretq_s8_m128(x) vreinterpretq_s8_f32(x)
#define vreinterpretq_s16_m128(x) vreinterpretq_s16_f32(x)
#define vreinterpretq_s32_m128(x) vreinterpretq_s32_f32(x)
#define vreinterpretq_s64_m128(x) vreinterpretq_s64_f32(x)
#define vreinterpretq_m128i_s8(x) vreinterpretq_s64_s8(x)
#define vreinterpretq_m128i_s16(x) vreinterpretq_s64_s16(x)
#define vreinterpretq_m128i_s32(x) vreinterpretq_s64_s32(x)
#define vreinterpretq_m128i_s64(x) (x)