diskann-wide 0.50.1

DiskANN is a fast approximate nearest neighbor search library for high dimensional data
Documentation
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
/*
 * Copyright (c) Microsoft Corporation. All rights reserved.
 * Licensed under the MIT license.
 */

use crate::SIMDVector;

macro_rules! aarch64_define_register {
    ($type:ident, $impl:ty, $mask:ty, $scalar:ty, $lanes:literal, $arch:ty) => {
        #[derive(Debug, Clone, Copy)]
        #[allow(non_camel_case_types)]
        #[repr(transparent)]
        pub struct $type(pub $impl);

        impl $type {
            /// Convert `self` to its corresponding [`crate::Emulated`] type.
            #[inline(always)]
            pub fn emulated(self) -> $crate::Emulated<$scalar, $lanes> {
                $crate::Emulated::from_array($crate::arch::Scalar, self.to_array())
            }
        }

        impl $crate::AsSIMD<$type> for $crate::Emulated<$scalar, $lanes> {
            #[inline(always)]
            fn as_simd(self, arch: $arch) -> $type {
                $type::from_array(arch, self.to_array())
            }
        }

        impl SIMDVector for $type {
            type Arch = $arch;
            type Scalar = $scalar;
            type Underlying = $impl;

            type Mask = $mask;
            type ConstLanes = Const<$lanes>;
            const LANES: usize = $lanes;
            const EMULATED: bool = false;

            #[inline(always)]
            fn arch(self) -> $arch {
                // SAFETY: The existence of `self` provides a witness that it is safe to
                // instantiate its architecture.
                unsafe { <$arch>::new() }
            }

            #[inline(always)]
            fn default(arch: $arch) -> Self {
                <Self as AArchSplat>::aarch_default(arch)
            }

            fn to_underlying(self) -> Self::Underlying {
                self.0
            }

            fn from_underlying(_: $arch, repr: Self::Underlying) -> Self {
                Self(repr)
            }

            fn to_array(self) -> [$scalar; $lanes] {
                // SAFETY: Provided the scalar type is an integer or floating point,
                // then all bit patterns are valid between source and destination types.
                // (provided a neon intrinsic is one of the transmuted types).
                //
                // The source argument is taken by value (no reference conversion) and
                // as long as `T` is `[repr(C)]`, then `[T; N]` will be `[repr(C)]`.
                //
                // The intrinsic types are `[repr(simd)]` which amounts to `[repr(C)]` and
                // change.
                unsafe { std::mem::transmute::<Self, [$scalar; $lanes]>(self) }
            }

            fn from_array(_: $arch, x: [$scalar; $lanes]) -> Self {
                // SAFETY: Provided the scalar type is an integer or floating point,
                // then all bit patterns are valid between source and destination types.
                // (provided an x86 intrinsic is one of the transmuted types).
                //
                // The source argument is taken by value (no reference conversion) and
                // as long as `T` is `[repr(C)]`, then `[T; N]` will be `[repr(C)]`.
                //
                // The intrinsic types are `[repr(simd)]` which amounts to `[repr(C)]` and
                // change.
                unsafe { std::mem::transmute::<[$scalar; $lanes], Self>(x) }
            }

            #[inline(always)]
            fn splat(arch: $arch, value: Self::Scalar) -> Self {
                <Self as AArchSplat>::aarch_splat(arch, value)
            }

            #[inline(always)]
            unsafe fn load_simd(arch: $arch, ptr: *const $scalar) -> Self {
                // SAFETY: Inherited from caller.
                unsafe { <Self as AArchLoadStore>::load_simd(arch, ptr) }
            }

            #[inline(always)]
            unsafe fn load_simd_masked_logical(
                arch: $arch,
                ptr: *const $scalar,
                mask: $mask,
            ) -> Self {
                // SAFETY: Inherited from caller.
                unsafe { <Self as AArchLoadStore>::load_simd_masked_logical(arch, ptr, mask) }
            }

            #[inline(always)]
            unsafe fn load_simd_first(arch: $arch, ptr: *const $scalar, first: usize) -> Self {
                // SAFETY: Inherited from caller.
                unsafe { <Self as AArchLoadStore>::load_simd_first(arch, ptr, first) }
            }

            #[inline(always)]
            unsafe fn store_simd(self, ptr: *mut $scalar) {
                // SAFETY: Inherited from caller.
                unsafe { <Self as AArchLoadStore>::store_simd(self, ptr) }
            }

            #[inline(always)]
            unsafe fn store_simd_masked_logical(self, ptr: *mut $scalar, mask: $mask) {
                // SAFETY: Inherited from caller.
                unsafe { <Self as AArchLoadStore>::store_simd_masked_logical(self, ptr, mask) }
            }

            #[inline(always)]
            unsafe fn store_simd_first(self, ptr: *mut $scalar, first: usize) {
                // SAFETY: Inherited from caller.
                unsafe { <Self as AArchLoadStore>::store_simd_first(self, ptr, first) }
            }
        }
    };
}

pub(super) trait AArchSplat: SIMDVector {
    fn aarch_splat(arch: <Self as SIMDVector>::Arch, value: <Self as SIMDVector>::Scalar) -> Self;

    fn aarch_default(arch: <Self as SIMDVector>::Arch) -> Self;
}

pub(super) trait AArchLoadStore: SIMDVector {
    unsafe fn load_simd(
        arch: <Self as SIMDVector>::Arch,
        ptr: *const <Self as SIMDVector>::Scalar,
    ) -> Self;
    unsafe fn load_simd_masked_logical(
        arch: <Self as SIMDVector>::Arch,
        ptr: *const <Self as SIMDVector>::Scalar,
        mask: Self::Mask,
    ) -> Self;
    unsafe fn load_simd_first(
        arch: <Self as SIMDVector>::Arch,
        ptr: *const <Self as SIMDVector>::Scalar,
        first: usize,
    ) -> Self;

    unsafe fn store_simd(self, ptr: *mut <Self as SIMDVector>::Scalar);
    unsafe fn store_simd_masked_logical(
        self,
        ptr: *mut <Self as SIMDVector>::Scalar,
        mask: Self::Mask,
    );
    unsafe fn store_simd_first(self, ptr: *mut <Self as SIMDVector>::Scalar, first: usize);
}

/// Utility macro for defining `AArchSplat`.
///
/// SAFETY: It is the invoker's responsibility to ensure that the intrinsic is safe to call.
macro_rules! aarch64_define_splat {
    ($type:ty, $intrinsic:expr) => {
        impl AArchSplat for $type {
            #[inline(always)]
            fn aarch_splat(
                _arch: <Self as SIMDVector>::Arch,
                value: <Self as SIMDVector>::Scalar,
            ) -> Self {
                // SAFETY: Instantiator asserts that `$intrinsic` is allowed by `Arch`.
                Self(unsafe { $intrinsic(value) })
            }

            #[inline(always)]
            fn aarch_default(arch: <Self as SIMDVector>::Arch) -> Self {
                Self::aarch_splat(arch, <Self as SIMDVector>::Scalar::default())
            }
        }
    };
}

macro_rules! aarch64_define_loadstore {
    ($type:ty, $load:expr, $load_first:expr, $store:expr, $lanes:literal) => {
        impl AArchLoadStore for $type {
            #[inline(always)]
            unsafe fn load_simd(
                _arch: <Self as SIMDVector>::Arch,
                ptr: *const <Self as SIMDVector>::Scalar,
            ) -> Self {
                // SAFETY: Instantiator asserts that `$load` is allowed by `Arch`.
                Self(unsafe { $load(ptr) })
            }

            #[inline(always)]
            unsafe fn load_simd_masked_logical(
                arch: <Self as SIMDVector>::Arch,
                ptr: *const <Self as SIMDVector>::Scalar,
                mask: Self::Mask,
            ) -> Self {
                // SAFETY: Inherited from caller.
                let e = unsafe {
                    Emulated::<_, $lanes>::load_simd_masked_logical(
                        $crate::arch::Scalar,
                        ptr,
                        mask.bitmask().as_scalar(),
                    )
                };

                Self::from_array(arch, e.to_array())
            }

            #[inline(always)]
            unsafe fn load_simd_first(
                arch: <Self as SIMDVector>::Arch,
                ptr: *const <Self as SIMDVector>::Scalar,
                first: usize,
            ) -> Self {
                // SAFETY: Inherited from caller.
                Self(unsafe { ($load_first)(arch, ptr, first) })
            }

            #[inline(always)]
            unsafe fn store_simd(self, ptr: *mut <Self as SIMDVector>::Scalar) {
                // SAFETY: Instantiator asserts that `$store` is allowed by `Arch`.
                unsafe { $store(ptr, self.0) }
            }

            unsafe fn store_simd_masked_logical(
                self,
                ptr: *mut <Self as SIMDVector>::Scalar,
                mask: Self::Mask,
            ) {
                let e = Emulated::<_, $lanes>::from_array($crate::arch::Scalar, self.to_array());

                // SAFETY: Inherited from caller.
                unsafe { e.store_simd_masked_logical(ptr, mask.bitmask().as_scalar()) }
            }

            #[inline(always)]
            unsafe fn store_simd_first(self, ptr: *mut <Self as SIMDVector>::Scalar, first: usize) {
                let e = Emulated::<_, $lanes>::from_array($crate::arch::Scalar, self.to_array());

                // SAFETY: Inherited from caller.
                unsafe { e.store_simd_first(ptr, first) }
            }
        }
    };
}

macro_rules! aarch64_define_cmp {
    ($type:ty, $eq:ident, ($not:expr), $lt:ident, $le:ident, $gt:ident, $ge:ident) => {
        impl SIMDPartialEq for $type {
            #[inline(always)]
            fn eq_simd(self, other: Self) -> Self::Mask {
                // SAFETY: The presence of `Neon` enables the use of "neon" intrinsics.
                //
                // It is the caller's responsibility to instantiate the macro with an
                // intrinsics also gated by "neon".
                Self::Mask::from_underlying(self.arch(), unsafe { $eq(self.0, other.0) })
            }

            #[inline(always)]
            fn ne_simd(self, other: Self) -> Self::Mask {
                // SAFETY: The presence of `Neon` enables the use of "neon" intrinsics.
                //
                // It is the caller's responsibility to instantiate the macro with an
                // intrinsics also gated by "neon".
                Self::Mask::from_underlying(self.arch(), unsafe { $not($eq(self.0, other.0)) })
            }
        }

        impl SIMDPartialOrd for $type {
            #[inline(always)]
            fn lt_simd(self, other: Self) -> Self::Mask {
                // SAFETY: The presence of `Neon` enables the use of "neon" intrinsics.
                //
                // It is the caller's responsibility to instantiate the macro with an
                // intrinsics also gated by "neon".
                Self::Mask::from_underlying(self.arch(), unsafe { $lt(self.0, other.0) })
            }

            #[inline(always)]
            fn le_simd(self, other: Self) -> Self::Mask {
                // SAFETY: The presence of `Neon` enables the use of "neon" intrinsics.
                //
                // It is the caller's responsibility to instantiate the macro with an
                // intrinsics also gated by "neon".
                Self::Mask::from_underlying(self.arch(), unsafe { $le(self.0, other.0) })
            }

            #[inline(always)]
            fn gt_simd(self, other: Self) -> Self::Mask {
                // SAFETY: The presence of `Neon` enables the use of "neon" intrinsics.
                //
                // It is the caller's responsibility to instantiate the macro with an
                // intrinsics also gated by "neon".
                Self::Mask::from_underlying(self.arch(), unsafe { $gt(self.0, other.0) })
            }

            #[inline(always)]
            fn ge_simd(self, other: Self) -> Self::Mask {
                // SAFETY: The presence of `Neon` enables the use of "neon" intrinsics.
                //
                // It is the caller's responsibility to instantiate the macro with an
                // intrinsics also gated by "neon".
                Self::Mask::from_underlying(self.arch(), unsafe { $ge(self.0, other.0) })
            }
        }
    };
}

/// Utility macro for defining simple operations that lower to a single intrinsic.
///
/// SAFETY: It is the invoker's responsibility to ensure that the intrinsic is safe to call
macro_rules! aarch64_define_fma {
    ($type:ty, integer) => {
        impl SIMDMulAdd for $type {
            #[inline(always)]
            fn mul_add_simd(self, rhs: Self, accumulator: Self) -> $type {
                self * rhs + accumulator
            }
        }
    };
    // This variant maps the implementation to an intrinsic.
    ($type:ty, $intrinsic:expr) => {
        impl SIMDMulAdd for $type {
            #[inline(always)]
            fn mul_add_simd(self, rhs: Self, accumulator: Self) -> $type {
                // SAFETY: The invoker of this macro must pass the `target_feature`
                // requirement of the intrinsic.
                //
                // That way, if the intrinsic is not available, we get a compile-time error.
                Self(unsafe { $intrinsic(accumulator.0, self.0, rhs.0) })
            }
        }
    };
}

/// # Notes on vector shifts.
///
/// Neon only has the `vector`x`vector` left shift function. However, it takes signed
/// arguments for the shift amount. Right shifts are achieved by using negative left-shifts.
///
/// To maintain consistency in `Wide`, we only allow positive left shifts and positive right
/// shifts.
///
/// * Left shifts: We need to clamp the shift amount between 0 and the maximum shift
///   (inclusive). This is done by first reinterpreting the shift vector as unsigned
///   (`cvtpre`), taking the unsigned `min` with the maximal shift, and then reinterpret
///   to signed (`cvtpost`).
///
///   If the shift vector is already unsigned, then `cvtpre` can be the identity.
///
/// * Right shifts: Right shifts follow the same logic as left shifts, just with a final
///   negative before invoking the left-shift intrinsic.
///
/// # Shifts by a Scalar
///
/// LLVM is not smart enough to constant propagate properly though a `splat` followed by
/// a vector shift if we do the range-limitation after the `splat`. So, the scalar shift
/// operations perform the "cast-to-positive + min + cast-to-signed" in the scalar space
/// before splatting. LLVM optimizes this correctly.
macro_rules! aarch64_define_bitops {
    ($type:ty,
     $not:ident,
     $and:ident,
     $or:ident,
     $xor:ident,
     ($shlv:ident, $mask:literal, $neg:ident, $min:ident, $cvtpost:path, $cvtpre:path),
     ($unsigned:ty, $signed:ty, $broadcast_signed:ident),
    ) => {
        impl std::ops::Not for $type {
            type Output = Self;
            #[inline(always)]
            fn not(self) -> Self {
                // SAFETY: The presence of `Neon` enables the use of "neon" intrinsics.
                //
                // It is the caller's responsibility to instantiate the macro with an
                // intrinsics also gated by "neon".
                Self(unsafe { $not(self.0) })
            }
        }

        impl std::ops::BitAnd for $type {
            type Output = Self;
            #[inline(always)]
            fn bitand(self, rhs: Self) -> Self {
                // SAFETY: The presence of `Neon` enables the use of "neon" intrinsics.
                //
                // It is the caller's responsibility to instantiate the macro with an
                // intrinsics also gated by "neon".
                Self(unsafe { $and(self.0, rhs.0) })
            }
        }

        impl std::ops::BitOr for $type {
            type Output = Self;
            #[inline(always)]
            fn bitor(self, rhs: Self) -> Self {
                // SAFETY: The presence of `Neon` enables the use of "neon" intrinsics.
                //
                // It is the caller's responsibility to instantiate the macro with an
                // intrinsics also gated by "neon".
                Self(unsafe { $or(self.0, rhs.0) })
            }
        }

        impl std::ops::BitXor for $type {
            type Output = Self;
            #[inline(always)]
            fn bitxor(self, rhs: Self) -> Self {
                // SAFETY: The presence of `Neon` enables the use of "neon" intrinsics.
                //
                // It is the caller's responsibility to instantiate the macro with an
                // intrinsics also gated by "neon".
                Self(unsafe { $xor(self.0, rhs.0) })
            }
        }

        ///////////////////
        // vector shifts //
        ///////////////////

        impl std::ops::Shr for $type {
            type Output = Self;
            #[inline(always)]
            fn shr(self, rhs: Self) -> Self {
                use $crate::AsSIMD;
                if cfg!(miri) {
                    self.emulated().shr(rhs.emulated()).as_simd(self.arch())
                } else {
                    // SAFETY: The presence of `Neon` enables the use of "neon" intrinsics.
                    //
                    // It is the caller's responsibility to instantiate the macro with an
                    // intrinsics also gated by "neon".
                    Self(unsafe {
                        $shlv(
                            self.0,
                            $neg($cvtpost($min(
                                $cvtpre(rhs.0),
                                $cvtpre(<$type as SIMDVector>::splat(self.arch(), $mask).0),
                            ))),
                        )
                    })
                }
            }
        }

        impl std::ops::Shl for $type {
            type Output = Self;
            #[inline(always)]
            fn shl(self, rhs: Self) -> Self {
                use $crate::AsSIMD;
                if cfg!(miri) {
                    self.emulated().shl(rhs.emulated()).as_simd(self.arch())
                } else {
                    // SAFETY: The presence of `Neon` enables the use of "neon" intrinsics.
                    //
                    // It is the caller's responsibility to instantiate the macro with an
                    // intrinsics also gated by "neon".
                    Self(unsafe {
                        $shlv(
                            self.0,
                            $cvtpost($min(
                                $cvtpre(rhs.0),
                                $cvtpre(<$type as SIMDVector>::splat(self.arch(), $mask).0),
                            )),
                        )
                    })
                }
            }
        }

        ///////////////////
        // scalar shifts //
        ///////////////////

        impl std::ops::Shr<<$type as SIMDVector>::Scalar> for $type {
            type Output = Self;
            #[inline(always)]
            fn shr(self, rhs: <$type as SIMDVector>::Scalar) -> Self {
                use $crate::AsSIMD;
                if cfg!(miri) {
                    self.emulated().shr(rhs).as_simd(self.arch())
                } else {
                    // SAFETY: The presence of `Neon` enables the use of "neon" intrinsics.
                    //
                    // It is the caller's responsibility to instantiate the macro with an
                    // intrinsics also gated by "neon".
                    Self(unsafe {
                        $shlv(
                            self.0,
                            $broadcast_signed(-((rhs as $unsigned).min($mask) as $signed)),
                        )
                    })
                }
            }
        }

        impl std::ops::Shl<<$type as SIMDVector>::Scalar> for $type {
            type Output = Self;
            #[inline(always)]
            fn shl(self, rhs: <$type as SIMDVector>::Scalar) -> Self {
                use $crate::AsSIMD;
                if cfg!(miri) {
                    self.emulated().shl(rhs).as_simd(self.arch())
                } else {
                    // SAFETY: The presence of `Neon` enables the use of "neon" intrinsics.
                    //
                    // It is the caller's responsibility to instantiate the macro with an
                    // intrinsics also gated by "neon".
                    Self(unsafe {
                        $shlv(
                            self.0,
                            $broadcast_signed((rhs as $unsigned).min($mask) as $signed),
                        )
                    })
                }
            }
        }
    };
}

/// SAFETY: It is the invoker's responsibility to ensure that the provided intrinsics are
/// safe to call. That is - any intrinsics invoked must be compatible with `$type`'s
/// associated architecture.
macro_rules! aarch64_splitjoin {
    ($type:path, $half:path, $getlo:ident, $gethi:ident, $join:ident) => {
        impl $crate::SplitJoin for $type {
            type Halved = $half;

            #[inline(always)]
            fn split(self) -> $crate::LoHi<Self::Halved> {
                // SAFETY: This should only be instantiated for types where the associated
                // architecture provides a license to use it.
                unsafe {
                    $crate::LoHi::new(
                        Self::Halved::from_underlying(self.arch(), $getlo(self.to_underlying())),
                        Self::Halved::from_underlying(self.arch(), $gethi(self.to_underlying())),
                    )
                }
            }

            #[inline(always)]
            fn join(lohi: $crate::LoHi<Self::Halved>) -> Self {
                // SAFETY: This should only be instantiated for types where the associated
                // architecture provides a license to use it.
                unsafe {
                    Self::from_underlying(
                        lohi.lo.arch(),
                        $join(lohi.lo.to_underlying(), lohi.hi.to_underlying()),
                    )
                }
            }
        }
    };
}

pub(crate) use aarch64_define_bitops;
pub(crate) use aarch64_define_cmp;
pub(crate) use aarch64_define_fma;
pub(crate) use aarch64_define_loadstore;
pub(crate) use aarch64_define_register;
pub(crate) use aarch64_define_splat;
pub(crate) use aarch64_splitjoin;

/// Implement [`ZipUnzip`] for a [`Doubled`] type using Neon zip/unzip intrinsics.
///
/// ## Parameters
///
/// * `$half`   — the native 128-bit Neon type (e.g. `i8x16`)
/// * `$zip1`   — `vzip1q_*` intrinsic (interleave lower halves)
/// * `$zip2`   — `vzip2q_*` intrinsic (interleave upper halves)
/// * `$uzp1`   — `vuzp1q_*` intrinsic (collect even-indexed elements)
/// * `$uzp2`   — `vuzp2q_*` intrinsic (collect odd-indexed elements)
///
/// ## Safety
///
/// The caller must ensure the provided intrinsics match the element type of `$half`.
macro_rules! aarch64_zipunzip {
    ($half:path, $zip1:ident, $zip2:ident, $uzp1:ident, $uzp2:ident) => {
        impl $crate::ZipUnzip for $crate::doubled::Doubled<$half> {
            #[inline(always)]
            fn zip(halves: $crate::LoHi<<Self as $crate::SplitJoin>::Halved>) -> Self {
                use $crate::SIMDVector;
                // SAFETY: Caller asserts that these intrinsics match the element type.
                unsafe {
                    let lo_raw = halves.lo.to_underlying();
                    let hi_raw = halves.hi.to_underlying();
                    $crate::doubled::Doubled(
                        <$half>::from_underlying(halves.lo.arch(), $zip1(lo_raw, hi_raw)),
                        <$half>::from_underlying(halves.lo.arch(), $zip2(lo_raw, hi_raw)),
                    )
                }
            }

            #[inline(always)]
            fn unzip(self) -> $crate::LoHi<<Self as $crate::SplitJoin>::Halved> {
                use $crate::SIMDVector;
                // SAFETY: Caller asserts that these intrinsics match the element type.
                unsafe {
                    let lo_raw = self.0.to_underlying();
                    let hi_raw = self.1.to_underlying();
                    $crate::LoHi::new(
                        <$half>::from_underlying(self.0.arch(), $uzp1(lo_raw, hi_raw)),
                        <$half>::from_underlying(self.0.arch(), $uzp2(lo_raw, hi_raw)),
                    )
                }
            }
        }
    };
}
pub(crate) use aarch64_zipunzip;