| 
 | 1 | +// Most of these tests are copied from https://github.com/japaric/stdsimd/blob/0f4413d01c4f0c3ffbc5a69e9a37fbc7235b31a9/coresimd/arm/neon.rs  | 
 | 2 | + | 
 | 3 | +#![feature(portable_simd)]  | 
 | 4 | + | 
 | 5 | +#[cfg(target_arch = "aarch64")]  | 
 | 6 | +use std::arch::aarch64::*;  | 
 | 7 | +use std::mem::transmute;  | 
 | 8 | +use std::simd::*;  | 
 | 9 | + | 
 | 10 | +#[cfg(target_arch = "aarch64")]  | 
 | 11 | +unsafe fn test_vpmin_s8() {  | 
 | 12 | +    let a = i8x8::from([1, -2, 3, -4, 5, 6, 7, 8]);  | 
 | 13 | +    let b = i8x8::from([0, 3, 2, 5, 4, 7, 6, 9]);  | 
 | 14 | +    let e = i8x8::from([-2, -4, 5, 7, 0, 2, 4, 6]);  | 
 | 15 | +    let r: i8x8 = transmute(vpmin_s8(transmute(a), transmute(b)));  | 
 | 16 | +    assert_eq!(r, e);  | 
 | 17 | +}  | 
 | 18 | + | 
 | 19 | +#[cfg(target_arch = "aarch64")]  | 
 | 20 | +unsafe fn test_vpmin_s16() {  | 
 | 21 | +    let a = i16x4::from([1, 2, 3, -4]);  | 
 | 22 | +    let b = i16x4::from([0, 3, 2, 5]);  | 
 | 23 | +    let e = i16x4::from([1, -4, 0, 2]);  | 
 | 24 | +    let r: i16x4 = transmute(vpmin_s16(transmute(a), transmute(b)));  | 
 | 25 | +    assert_eq!(r, e);  | 
 | 26 | +}  | 
 | 27 | + | 
 | 28 | +#[cfg(target_arch = "aarch64")]  | 
 | 29 | +unsafe fn test_vpmin_s32() {  | 
 | 30 | +    let a = i32x2::from([1, -2]);  | 
 | 31 | +    let b = i32x2::from([0, 3]);  | 
 | 32 | +    let e = i32x2::from([-2, 0]);  | 
 | 33 | +    let r: i32x2 = transmute(vpmin_s32(transmute(a), transmute(b)));  | 
 | 34 | +    assert_eq!(r, e);  | 
 | 35 | +}  | 
 | 36 | + | 
 | 37 | +#[cfg(target_arch = "aarch64")]  | 
 | 38 | +unsafe fn test_vpmin_u8() {  | 
 | 39 | +    let a = u8x8::from([1, 2, 3, 4, 5, 6, 7, 8]);  | 
 | 40 | +    let b = u8x8::from([0, 3, 2, 5, 4, 7, 6, 9]);  | 
 | 41 | +    let e = u8x8::from([1, 3, 5, 7, 0, 2, 4, 6]);  | 
 | 42 | +    let r: u8x8 = transmute(vpmin_u8(transmute(a), transmute(b)));  | 
 | 43 | +    assert_eq!(r, e);  | 
 | 44 | +}  | 
 | 45 | + | 
 | 46 | +#[cfg(target_arch = "aarch64")]  | 
 | 47 | +unsafe fn test_vpmin_u16() {  | 
 | 48 | +    let a = u16x4::from([1, 2, 3, 4]);  | 
 | 49 | +    let b = u16x4::from([0, 3, 2, 5]);  | 
 | 50 | +    let e = u16x4::from([1, 3, 0, 2]);  | 
 | 51 | +    let r: u16x4 = transmute(vpmin_u16(transmute(a), transmute(b)));  | 
 | 52 | +    assert_eq!(r, e);  | 
 | 53 | +}  | 
 | 54 | + | 
 | 55 | +#[cfg(target_arch = "aarch64")]  | 
 | 56 | +unsafe fn test_vpmin_u32() {  | 
 | 57 | +    let a = u32x2::from([1, 2]);  | 
 | 58 | +    let b = u32x2::from([0, 3]);  | 
 | 59 | +    let e = u32x2::from([1, 0]);  | 
 | 60 | +    let r: u32x2 = transmute(vpmin_u32(transmute(a), transmute(b)));  | 
 | 61 | +    assert_eq!(r, e);  | 
 | 62 | +}  | 
 | 63 | + | 
 | 64 | +#[cfg(target_arch = "aarch64")]  | 
 | 65 | +unsafe fn test_vpmin_f32() {  | 
 | 66 | +    let a = f32x2::from([1., -2.]);  | 
 | 67 | +    let b = f32x2::from([0., 3.]);  | 
 | 68 | +    let e = f32x2::from([-2., 0.]);  | 
 | 69 | +    let r: f32x2 = transmute(vpmin_f32(transmute(a), transmute(b)));  | 
 | 70 | +    assert_eq!(r, e);  | 
 | 71 | +}  | 
 | 72 | + | 
 | 73 | +#[cfg(target_arch = "aarch64")]  | 
 | 74 | +unsafe fn test_vpmax_s8() {  | 
 | 75 | +    let a = i8x8::from([1, -2, 3, -4, 5, 6, 7, 8]);  | 
 | 76 | +    let b = i8x8::from([0, 3, 2, 5, 4, 7, 6, 9]);  | 
 | 77 | +    let e = i8x8::from([1, 3, 6, 8, 3, 5, 7, 9]);  | 
 | 78 | +    let r: i8x8 = transmute(vpmax_s8(transmute(a), transmute(b)));  | 
 | 79 | +    assert_eq!(r, e);  | 
 | 80 | +}  | 
 | 81 | + | 
 | 82 | +#[cfg(target_arch = "aarch64")]  | 
 | 83 | +unsafe fn test_vpmax_s16() {  | 
 | 84 | +    let a = i16x4::from([1, 2, 3, -4]);  | 
 | 85 | +    let b = i16x4::from([0, 3, 2, 5]);  | 
 | 86 | +    let e = i16x4::from([2, 3, 3, 5]);  | 
 | 87 | +    let r: i16x4 = transmute(vpmax_s16(transmute(a), transmute(b)));  | 
 | 88 | +    assert_eq!(r, e);  | 
 | 89 | +}  | 
 | 90 | + | 
 | 91 | +#[cfg(target_arch = "aarch64")]  | 
 | 92 | +unsafe fn test_vpmax_s32() {  | 
 | 93 | +    let a = i32x2::from([1, -2]);  | 
 | 94 | +    let b = i32x2::from([0, 3]);  | 
 | 95 | +    let e = i32x2::from([1, 3]);  | 
 | 96 | +    let r: i32x2 = transmute(vpmax_s32(transmute(a), transmute(b)));  | 
 | 97 | +    assert_eq!(r, e);  | 
 | 98 | +}  | 
 | 99 | + | 
 | 100 | +#[cfg(target_arch = "aarch64")]  | 
 | 101 | +unsafe fn test_vpmax_u8() {  | 
 | 102 | +    let a = u8x8::from([1, 2, 3, 4, 5, 6, 7, 8]);  | 
 | 103 | +    let b = u8x8::from([0, 3, 2, 5, 4, 7, 6, 9]);  | 
 | 104 | +    let e = u8x8::from([2, 4, 6, 8, 3, 5, 7, 9]);  | 
 | 105 | +    let r: u8x8 = transmute(vpmax_u8(transmute(a), transmute(b)));  | 
 | 106 | +    assert_eq!(r, e);  | 
 | 107 | +}  | 
 | 108 | + | 
 | 109 | +#[cfg(target_arch = "aarch64")]  | 
 | 110 | +unsafe fn test_vpmax_u16() {  | 
 | 111 | +    let a = u16x4::from([1, 2, 3, 4]);  | 
 | 112 | +    let b = u16x4::from([0, 3, 2, 5]);  | 
 | 113 | +    let e = u16x4::from([2, 4, 3, 5]);  | 
 | 114 | +    let r: u16x4 = transmute(vpmax_u16(transmute(a), transmute(b)));  | 
 | 115 | +    assert_eq!(r, e);  | 
 | 116 | +}  | 
 | 117 | + | 
 | 118 | +#[cfg(target_arch = "aarch64")]  | 
 | 119 | +unsafe fn test_vpmax_u32() {  | 
 | 120 | +    let a = u32x2::from([1, 2]);  | 
 | 121 | +    let b = u32x2::from([0, 3]);  | 
 | 122 | +    let e = u32x2::from([2, 3]);  | 
 | 123 | +    let r: u32x2 = transmute(vpmax_u32(transmute(a), transmute(b)));  | 
 | 124 | +    assert_eq!(r, e);  | 
 | 125 | +}  | 
 | 126 | + | 
 | 127 | +#[cfg(target_arch = "aarch64")]  | 
 | 128 | +unsafe fn test_vpmax_f32() {  | 
 | 129 | +    let a = f32x2::from([1., -2.]);  | 
 | 130 | +    let b = f32x2::from([0., 3.]);  | 
 | 131 | +    let e = f32x2::from([1., 3.]);  | 
 | 132 | +    let r: f32x2 = transmute(vpmax_f32(transmute(a), transmute(b)));  | 
 | 133 | +    assert_eq!(r, e);  | 
 | 134 | +}  | 
 | 135 | + | 
 | 136 | +#[cfg(target_arch = "aarch64")]  | 
 | 137 | +unsafe fn test_vpadd_s16() {  | 
 | 138 | +    let a = i16x4::from([1, 2, 3, 4]);  | 
 | 139 | +    let b = i16x4::from([0, -1, -2, -3]);  | 
 | 140 | +    let r: i16x4 = transmute(vpadd_s16(transmute(a), transmute(b)));  | 
 | 141 | +    let e = i16x4::from([3, 7, -1, -5]);  | 
 | 142 | +    assert_eq!(r, e);  | 
 | 143 | +}  | 
 | 144 | +#[cfg(target_arch = "aarch64")]  | 
 | 145 | +unsafe fn test_vpadd_s32() {  | 
 | 146 | +    let a = i32x2::from([1, 2]);  | 
 | 147 | +    let b = i32x2::from([0, -1]);  | 
 | 148 | +    let r: i32x2 = transmute(vpadd_s32(transmute(a), transmute(b)));  | 
 | 149 | +    let e = i32x2::from([3, -1]);  | 
 | 150 | +    assert_eq!(r, e);  | 
 | 151 | +}  | 
 | 152 | +#[cfg(target_arch = "aarch64")]  | 
 | 153 | +unsafe fn test_vpadd_s8() {  | 
 | 154 | +    let a = i8x8::from([1, 2, 3, 4, 5, 6, 7, 8]);  | 
 | 155 | +    let b = i8x8::from([0, -1, -2, -3, -4, -5, -6, -7]);  | 
 | 156 | +    let r: i8x8 = transmute(vpadd_s8(transmute(a), transmute(b)));  | 
 | 157 | +    let e = i8x8::from([3, 7, 11, 15, -1, -5, -9, -13]);  | 
 | 158 | +    assert_eq!(r, e);  | 
 | 159 | +}  | 
 | 160 | +#[cfg(target_arch = "aarch64")]  | 
 | 161 | +unsafe fn test_vpadd_u16() {  | 
 | 162 | +    let a = u16x4::from([1, 2, 3, 4]);  | 
 | 163 | +    let b = u16x4::from([30, 31, 32, 33]);  | 
 | 164 | +    let r: u16x4 = transmute(vpadd_u16(transmute(a), transmute(b)));  | 
 | 165 | +    let e = u16x4::from([3, 7, 61, 65]);  | 
 | 166 | +    assert_eq!(r, e);  | 
 | 167 | +}  | 
 | 168 | +#[cfg(target_arch = "aarch64")]  | 
 | 169 | +unsafe fn test_vpadd_u32() {  | 
 | 170 | +    let a = u32x2::from([1, 2]);  | 
 | 171 | +    let b = u32x2::from([30, 31]);  | 
 | 172 | +    let r: u32x2 = transmute(vpadd_u32(transmute(a), transmute(b)));  | 
 | 173 | +    let e = u32x2::from([3, 61]);  | 
 | 174 | +    assert_eq!(r, e);  | 
 | 175 | +}  | 
 | 176 | +#[cfg(target_arch = "aarch64")]  | 
 | 177 | +unsafe fn test_vpadd_u8() {  | 
 | 178 | +    let a = u8x8::from([1, 2, 3, 4, 5, 6, 7, 8]);  | 
 | 179 | +    let b = u8x8::from([30, 31, 32, 33, 34, 35, 36, 37]);  | 
 | 180 | +    let r: u8x8 = transmute(vpadd_u8(transmute(a), transmute(b)));  | 
 | 181 | +    let e = u8x8::from([3, 7, 11, 15, 61, 65, 69, 73]);  | 
 | 182 | +    assert_eq!(r, e);  | 
 | 183 | +}  | 
 | 184 | + | 
 | 185 | +#[cfg(target_arch = "aarch64")]  | 
 | 186 | +unsafe fn test_vqsub_u8() {  | 
 | 187 | +    let a = u8x8::from([1, 2, 3, 4, 5, 6, 7, 0xff]);  | 
 | 188 | +    let b = u8x8::from([30, 1, 1, 1, 34, 0xff, 36, 37]);  | 
 | 189 | +    let r: u8x8 = transmute(vqsub_u8(transmute(a), transmute(b)));  | 
 | 190 | +    let e = u8x8::from([0, 1, 2, 3, 0, 0, 0, 218]);  | 
 | 191 | +    assert_eq!(r, e);  | 
 | 192 | +}  | 
 | 193 | + | 
 | 194 | +#[cfg(target_arch = "aarch64")]  | 
 | 195 | +unsafe fn test_vqadd_u8() {  | 
 | 196 | +    let a = u8x8::from([1, 2, 3, 4, 5, 6, 7, 0xff]);  | 
 | 197 | +    let b = u8x8::from([30, 1, 1, 1, 34, 0xff, 36, 37]);  | 
 | 198 | +    let r: u8x8 = transmute(vqadd_u8(transmute(a), transmute(b)));  | 
 | 199 | +    let e = u8x8::from([31, 3, 4, 5, 39, 0xff, 43, 0xff]);  | 
 | 200 | +    assert_eq!(r, e);  | 
 | 201 | +}  | 
 | 202 | + | 
 | 203 | +#[cfg(target_arch = "aarch64")]  | 
 | 204 | +fn main() {  | 
 | 205 | +    unsafe {  | 
 | 206 | +        test_vpmin_s8();  | 
 | 207 | +        test_vpmin_s16();  | 
 | 208 | +        test_vpmin_s32();  | 
 | 209 | +        test_vpmin_u8();  | 
 | 210 | +        test_vpmin_u16();  | 
 | 211 | +        test_vpmin_u32();  | 
 | 212 | +        test_vpmin_f32();  | 
 | 213 | +        test_vpmax_s8();  | 
 | 214 | +        test_vpmax_s16();  | 
 | 215 | +        test_vpmax_s32();  | 
 | 216 | +        test_vpmax_u8();  | 
 | 217 | +        test_vpmax_u16();  | 
 | 218 | +        test_vpmax_u32();  | 
 | 219 | +        test_vpmax_f32();  | 
 | 220 | + | 
 | 221 | +        test_vpadd_s16();  | 
 | 222 | +        test_vpadd_s32();  | 
 | 223 | +        test_vpadd_s8();  | 
 | 224 | +        test_vpadd_u16();  | 
 | 225 | +        test_vpadd_u32();  | 
 | 226 | +        test_vpadd_u8();  | 
 | 227 | + | 
 | 228 | +        test_vqsub_u8();  | 
 | 229 | +        test_vqadd_u8();  | 
 | 230 | +    }  | 
 | 231 | +}  | 
 | 232 | + | 
 | 233 | +#[cfg(not(target_arch = "aarch64"))]  | 
 | 234 | +fn main() {}  | 
0 commit comments