@@ -18,23 +18,10 @@ fn endian_indexing() {
18
18
19
19
#[ test]
20
20
fn endian_bitcasts ( ) {
21
+ #[ cfg_attr( rustfmt, rustfmt_skip) ]
21
22
let x = i8x16:: new (
22
- 0 ,
23
- 1 ,
24
- 2 ,
25
- 3 ,
26
- 4 ,
27
- 5 ,
28
- 6 ,
29
- 7 ,
30
- 8 ,
31
- 9 ,
32
- 10 ,
33
- 11 ,
34
- 12 ,
35
- 13 ,
36
- 14 ,
37
- 15 ,
23
+ 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 ,
24
+ 8 , 9 , 10 , 11 , 12 , 13 , 14 , 15 ,
38
25
) ;
39
26
let t: i16x8 = unsafe { mem:: transmute ( x) } ;
40
27
if cfg ! ( target_endian = "little" ) {
@@ -48,65 +35,26 @@ fn endian_bitcasts() {
48
35
49
36
#[ test]
50
37
fn endian_casts ( ) {
38
+ #[ cfg_attr( rustfmt, rustfmt_skip) ]
51
39
let x = i8x16:: new (
52
- 0 ,
53
- 1 ,
54
- 2 ,
55
- 3 ,
56
- 4 ,
57
- 5 ,
58
- 6 ,
59
- 7 ,
60
- 8 ,
61
- 9 ,
62
- 10 ,
63
- 11 ,
64
- 12 ,
65
- 13 ,
66
- 14 ,
67
- 15 ,
40
+ 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 ,
41
+ 8 , 9 , 10 , 11 , 12 , 13 , 14 , 15 ,
68
42
) ;
69
43
let t: i16x16 = x. into ( ) ; // simd_cast
44
+ #[ cfg_attr( rustfmt, rustfmt_skip) ]
70
45
let e = i16x16:: new (
71
- 0 ,
72
- 1 ,
73
- 2 ,
74
- 3 ,
75
- 4 ,
76
- 5 ,
77
- 6 ,
78
- 7 ,
79
- 8 ,
80
- 9 ,
81
- 10 ,
82
- 11 ,
83
- 12 ,
84
- 13 ,
85
- 14 ,
86
- 15 ,
46
+ 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 ,
47
+ 8 , 9 , 10 , 11 , 12 , 13 , 14 , 15 ,
87
48
) ;
88
49
assert_eq ! ( t, e) ;
89
50
}
90
51
91
52
#[ test]
92
53
fn endian_load_and_stores ( ) {
54
+ #[ cfg_attr( rustfmt, rustfmt_skip) ]
93
55
let x = i8x16:: new (
94
- 0 ,
95
- 1 ,
96
- 2 ,
97
- 3 ,
98
- 4 ,
99
- 5 ,
100
- 6 ,
101
- 7 ,
102
- 8 ,
103
- 9 ,
104
- 10 ,
105
- 11 ,
106
- 12 ,
107
- 13 ,
108
- 14 ,
109
- 15 ,
56
+ 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 ,
57
+ 8 , 9 , 10 , 11 , 12 , 13 , 14 , 15 ,
110
58
) ;
111
59
let mut y: [ i16 ; 8 ] = [ 0 ; 8 ] ;
112
60
x. store_unaligned ( unsafe {
@@ -126,3 +74,122 @@ fn endian_load_and_stores() {
126
74
} ) ;
127
75
assert_eq ! ( z, x) ;
128
76
}
77
+
78
+ #[ test]
79
+ fn endian_array_union ( ) {
80
+ union A {
81
+ data : [ f32 ; 4 ] ,
82
+ vec : f32x4 ,
83
+ }
84
+ let x: [ f32 ; 4 ] = unsafe {
85
+ A {
86
+ vec : f32x4:: new ( 0. , 1. , 2. , 3. ) ,
87
+ } . data
88
+ } ;
89
+ assert_eq ! ( x[ 0 ] , 0_f32 ) ;
90
+ assert_eq ! ( x[ 1 ] , 1_f32 ) ;
91
+ assert_eq ! ( x[ 2 ] , 2_f32 ) ;
92
+ assert_eq ! ( x[ 3 ] , 3_f32 ) ;
93
+ let y: f32x4 = unsafe {
94
+ A {
95
+ data : [ 3. , 2. , 1. , 0. ] ,
96
+ } . vec
97
+ } ;
98
+ assert_eq ! ( y, f32x4:: new( 3. , 2. , 1. , 0. ) ) ;
99
+
100
+ union B {
101
+ data : [ i8 ; 16 ] ,
102
+ vec : i8x16 ,
103
+ }
104
+ #[ cfg_attr( rustfmt, rustfmt_skip) ]
105
+ let x = i8x16:: new (
106
+ 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 ,
107
+ 8 , 9 , 10 , 11 , 12 , 13 , 14 , 15 ,
108
+ ) ;
109
+ let x: [ i8 ; 16 ] = unsafe { B { vec : x } . data } ;
110
+
111
+ for i in 0 ..16 {
112
+ assert_eq ! ( x[ i] , i as i8 ) ;
113
+ }
114
+
115
+ #[ cfg_attr( rustfmt, rustfmt_skip) ]
116
+ let y = [
117
+ 15 , 14 , 13 , 12 , 11 , 19 , 9 , 8 ,
118
+ 7 , 6 , 5 , 4 , 3 , 2 , 1 , 0
119
+ ] ;
120
+ #[ cfg_attr( rustfmt, rustfmt_skip) ]
121
+ let e = i8x16:: new (
122
+ 15 , 14 , 13 , 12 , 11 , 19 , 9 , 8 ,
123
+ 7 , 6 , 5 , 4 , 3 , 2 , 1 , 0
124
+ ) ;
125
+ let z = unsafe { B { data : y } . vec } ;
126
+ assert_eq ! ( z, e) ;
127
+ }
128
+
129
+ #[ test]
130
+ fn endian_tuple_access ( ) {
131
+ type F32x4T = ( f32 , f32 , f32 , f32 ) ;
132
+ union A {
133
+ data : F32x4T ,
134
+ vec : f32x4 ,
135
+ }
136
+ let x: F32x4T = unsafe {
137
+ A {
138
+ vec : f32x4:: new ( 0. , 1. , 2. , 3. ) ,
139
+ } . data
140
+ } ;
141
+ assert_eq ! ( x. 0 , 0_f32 ) ;
142
+ assert_eq ! ( x. 1 , 1_f32 ) ;
143
+ assert_eq ! ( x. 2 , 2_f32 ) ;
144
+ assert_eq ! ( x. 3 , 3_f32 ) ;
145
+ let y: f32x4 = unsafe {
146
+ A {
147
+ data : ( 3. , 2. , 1. , 0. ) ,
148
+ } . vec
149
+ } ;
150
+ assert_eq ! ( y, f32x4:: new( 3. , 2. , 1. , 0. ) ) ;
151
+
152
+ #[ cfg_attr( rustfmt, rustfmt_skip) ]
153
+ type I8x16T = ( i8 , i8 , i8 , i8 , i8 , i8 , i8 , i8 , i8 , i8 , i8 , i8 , i8 , i8 , i8 , i8 ) ;
154
+ union B {
155
+ data : I8x16T ,
156
+ vec : i8x16 ,
157
+ }
158
+
159
+ #[ cfg_attr( rustfmt, rustfmt_skip) ]
160
+ let x = i8x16:: new (
161
+ 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 ,
162
+ 8 , 9 , 10 , 11 , 12 , 13 , 14 , 15 ,
163
+ ) ;
164
+ let x: I8x16T = unsafe { B { vec : x } . data } ;
165
+
166
+ assert_eq ! ( x. 0 , 0 ) ;
167
+ assert_eq ! ( x. 1 , 1 ) ;
168
+ assert_eq ! ( x. 2 , 2 ) ;
169
+ assert_eq ! ( x. 3 , 3 ) ;
170
+ assert_eq ! ( x. 4 , 4 ) ;
171
+ assert_eq ! ( x. 5 , 5 ) ;
172
+ assert_eq ! ( x. 6 , 6 ) ;
173
+ assert_eq ! ( x. 7 , 7 ) ;
174
+ assert_eq ! ( x. 8 , 8 ) ;
175
+ assert_eq ! ( x. 9 , 9 ) ;
176
+ assert_eq ! ( x. 10 , 10 ) ;
177
+ assert_eq ! ( x. 11 , 11 ) ;
178
+ assert_eq ! ( x. 12 , 12 ) ;
179
+ assert_eq ! ( x. 13 , 13 ) ;
180
+ assert_eq ! ( x. 14 , 14 ) ;
181
+ assert_eq ! ( x. 15 , 15 ) ;
182
+
183
+ #[ cfg_attr( rustfmt, rustfmt_skip) ]
184
+ let y = (
185
+ 15 , 14 , 13 , 12 , 11 , 10 , 9 , 8 ,
186
+ 7 , 6 , 5 , 4 , 3 , 2 , 1 , 0
187
+ ) ;
188
+ let z: i8x16 = unsafe { B { data : y } . vec } ;
189
+ #[ cfg_attr( rustfmt, rustfmt_skip) ]
190
+ let e = i8x16:: new (
191
+ 15 , 14 , 13 , 12 , 11 , 10 , 9 , 8 ,
192
+ 7 , 6 , 5 , 4 , 3 , 2 , 1 , 0
193
+ ) ;
194
+ assert_eq ! ( e, z) ;
195
+ }
0 commit comments