Implement min/max neon intrisics · rust-lang/rust@1f09bae (original) (raw)

``

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

`+

use std::arch::aarch64::*;

`

``

5

`+

use std::mem::transmute;

`

``

6

`+

use std::simd::*;

`

``

7

+

``

8

`+

#[cfg(target_arch = "aarch64")]

`

``

9

`+

unsafe fn test_vpmin_s8() {

`

``

10

`+

let a = i8x8::from([1, -2, 3, -4, 5, 6, 7, 8]);

`

``

11

`+

let b = i8x8::from([0, 3, 2, 5, 4, 7, 6, 9]);

`

``

12

`+

let e = i8x8::from([-2, -4, 5, 7, 0, 2, 4, 6]);

`

``

13

`+

let r: i8x8 = transmute(vpmin_s8(transmute(a), transmute(b)));

`

``

14

`+

assert_eq!(r, e);

`

``

15

`+

}

`

``

16

+

``

17

`+

#[cfg(target_arch = "aarch64")]

`

``

18

`+

unsafe fn test_vpmin_s16() {

`

``

19

`+

let a = i16x4::from([1, 2, 3, -4]);

`

``

20

`+

let b = i16x4::from([0, 3, 2, 5]);

`

``

21

`+

let e = i16x4::from([1, -4, 0, 2]);

`

``

22

`+

let r: i16x4 = transmute(vpmin_s16(transmute(a), transmute(b)));

`

``

23

`+

assert_eq!(r, e);

`

``

24

`+

}

`

``

25

+

``

26

`+

#[cfg(target_arch = "aarch64")]

`

``

27

`+

unsafe fn test_vpmin_s32() {

`

``

28

`+

let a = i32x2::from([1, -2]);

`

``

29

`+

let b = i32x2::from([0, 3]);

`

``

30

`+

let e = i32x2::from([-2, 0]);

`

``

31

`+

let r: i32x2 = transmute(vpmin_s32(transmute(a), transmute(b)));

`

``

32

`+

assert_eq!(r, e);

`

``

33

`+

}

`

``

34

+

``

35

`+

#[cfg(target_arch = "aarch64")]

`

``

36

`+

unsafe fn test_vpmin_u8() {

`

``

37

`+

let a = u8x8::from([1, 2, 3, 4, 5, 6, 7, 8]);

`

``

38

`+

let b = u8x8::from([0, 3, 2, 5, 4, 7, 6, 9]);

`

``

39

`+

let e = u8x8::from([1, 3, 5, 7, 0, 2, 4, 6]);

`

``

40

`+

let r: u8x8 = transmute(vpmin_u8(transmute(a), transmute(b)));

`

``

41

`+

assert_eq!(r, e);

`

``

42

`+

}

`

``

43

+

``

44

`+

#[cfg(target_arch = "aarch64")]

`

``

45

`+

unsafe fn test_vpmin_u16() {

`

``

46

`+

let a = u16x4::from([1, 2, 3, 4]);

`

``

47

`+

let b = u16x4::from([0, 3, 2, 5]);

`

``

48

`+

let e = u16x4::from([1, 3, 0, 2]);

`

``

49

`+

let r: u16x4 = transmute(vpmin_u16(transmute(a), transmute(b)));

`

``

50

`+

assert_eq!(r, e);

`

``

51

`+

}

`

``

52

+

``

53

`+

#[cfg(target_arch = "aarch64")]

`

``

54

`+

unsafe fn test_vpmin_u32() {

`

``

55

`+

let a = u32x2::from([1, 2]);

`

``

56

`+

let b = u32x2::from([0, 3]);

`

``

57

`+

let e = u32x2::from([1, 0]);

`

``

58

`+

let r: u32x2 = transmute(vpmin_u32(transmute(a), transmute(b)));

`

``

59

`+

assert_eq!(r, e);

`

``

60

`+

}

`

``

61

+

``

62

`+

#[cfg(target_arch = "aarch64")]

`

``

63

`+

unsafe fn test_vpmin_f32() {

`

``

64

`+

let a = f32x2::from([1., -2.]);

`

``

65

`+

let b = f32x2::from([0., 3.]);

`

``

66

`+

let e = f32x2::from([-2., 0.]);

`

``

67

`+

let r: f32x2 = transmute(vpmin_f32(transmute(a), transmute(b)));

`

``

68

`+

assert_eq!(r, e);

`

``

69

`+

}

`

``

70

+

``

71

`+

#[cfg(target_arch = "aarch64")]

`

``

72

`+

unsafe fn test_vpmax_s8() {

`

``

73

`+

let a = i8x8::from([1, -2, 3, -4, 5, 6, 7, 8]);

`

``

74

`+

let b = i8x8::from([0, 3, 2, 5, 4, 7, 6, 9]);

`

``

75

`+

let e = i8x8::from([1, 3, 6, 8, 3, 5, 7, 9]);

`

``

76

`+

let r: i8x8 = transmute(vpmax_s8(transmute(a), transmute(b)));

`

``

77

`+

assert_eq!(r, e);

`

``

78

`+

}

`

``

79

+

``

80

`+

#[cfg(target_arch = "aarch64")]

`

``

81

`+

unsafe fn test_vpmax_s16() {

`

``

82

`+

let a = i16x4::from([1, 2, 3, -4]);

`

``

83

`+

let b = i16x4::from([0, 3, 2, 5]);

`

``

84

`+

let e = i16x4::from([2, 3, 3, 5]);

`

``

85

`+

let r: i16x4 = transmute(vpmax_s16(transmute(a), transmute(b)));

`

``

86

`+

assert_eq!(r, e);

`

``

87

`+

}

`

``

88

+

``

89

`+

#[cfg(target_arch = "aarch64")]

`

``

90

`+

unsafe fn test_vpmax_s32() {

`

``

91

`+

let a = i32x2::from([1, -2]);

`

``

92

`+

let b = i32x2::from([0, 3]);

`

``

93

`+

let e = i32x2::from([1, 3]);

`

``

94

`+

let r: i32x2 = transmute(vpmax_s32(transmute(a), transmute(b)));

`

``

95

`+

assert_eq!(r, e);

`

``

96

`+

}

`

``

97

+

``

98

`+

#[cfg(target_arch = "aarch64")]

`

``

99

`+

unsafe fn test_vpmax_u8() {

`

``

100

`+

let a = u8x8::from([1, 2, 3, 4, 5, 6, 7, 8]);

`

``

101

`+

let b = u8x8::from([0, 3, 2, 5, 4, 7, 6, 9]);

`

``

102

`+

let e = u8x8::from([2, 4, 6, 8, 3, 5, 7, 9]);

`

``

103

`+

let r: u8x8 = transmute(vpmax_u8(transmute(a), transmute(b)));

`

``

104

`+

assert_eq!(r, e);

`

``

105

`+

}

`

``

106

+

``

107

`+

#[cfg(target_arch = "aarch64")]

`

``

108

`+

unsafe fn test_vpmax_u16() {

`

``

109

`+

let a = u16x4::from([1, 2, 3, 4]);

`

``

110

`+

let b = u16x4::from([0, 3, 2, 5]);

`

``

111

`+

let e = u16x4::from([2, 4, 3, 5]);

`

``

112

`+

let r: u16x4 = transmute(vpmax_u16(transmute(a), transmute(b)));

`

``

113

`+

assert_eq!(r, e);

`

``

114

`+

}

`

``

115

+

``

116

`+

#[cfg(target_arch = "aarch64")]

`

``

117

`+

unsafe fn test_vpmax_u32() {

`

``

118

`+

let a = u32x2::from([1, 2]);

`

``

119

`+

let b = u32x2::from([0, 3]);

`

``

120

`+

let e = u32x2::from([2, 3]);

`

``

121

`+

let r: u32x2 = transmute(vpmax_u32(transmute(a), transmute(b)));

`

``

122

`+

assert_eq!(r, e);

`

``

123

`+

}

`

``

124

+

``

125

`+

#[cfg(target_arch = "aarch64")]

`

``

126

`+

unsafe fn test_vpmax_f32() {

`

``

127

`+

let a = f32x2::from([1., -2.]);

`

``

128

`+

let b = f32x2::from([0., 3.]);

`

``

129

`+

let e = f32x2::from([1., 3.]);

`

``

130

`+

let r: f32x2 = transmute(vpmax_f32(transmute(a), transmute(b)));

`

``

131

`+

assert_eq!(r, e);

`

``

132

`+

}

`

``

133

+

``

134

`+

#[cfg(target_arch = "aarch64")]

`

``

135

`+

fn main() {

`

``

136

`+

unsafe {

`

``

137

`+

test_vpmin_s8();

`

``

138

`+

test_vpmin_s16();

`

``

139

`+

test_vpmin_s32();

`

``

140

`+

test_vpmin_u8();

`

``

141

`+

test_vpmin_u16();

`

``

142

`+

test_vpmin_u32();

`

``

143

`+

test_vpmin_f32();

`

``

144

`+

test_vpmax_s8();

`

``

145

`+

test_vpmax_s16();

`

``

146

`+

test_vpmax_s32();

`

``

147

`+

test_vpmax_u8();

`

``

148

`+

test_vpmax_u16();

`

``

149

`+

test_vpmax_u32();

`

``

150

`+

test_vpmax_f32();

`

``

151

`+

}

`

``

152

`+

}

`

``

153

+

``

154

`+

#[cfg(target_arch = "x86_64")]

`

``

155

`+

fn main() {}

`