Skip to content

Commit a8f0c2d

Browse files
committed
add gather/scatter tests for pointers of pointers
1 parent f1a4291 commit a8f0c2d

File tree

1 file changed

+71
-0
lines changed

1 file changed

+71
-0
lines changed

src/test/run-pass/simd-intrinsic-generic-gather.rs

+71
Original file line numberDiff line numberDiff line change
@@ -77,4 +77,75 @@ fn main() {
7777

7878
assert_eq!(x, [42., 1., 43., 3., 4., 5., 45., 7.]);
7979
}
80+
81+
// test modifying array of *const f32
82+
let mut y = [
83+
&x[0] as *const f32,
84+
&x[1] as *const f32,
85+
&x[2] as *const f32,
86+
&x[3] as *const f32,
87+
&x[4] as *const f32,
88+
&x[5] as *const f32,
89+
&x[6] as *const f32,
90+
&x[7] as *const f32
91+
];
92+
93+
let default = x4(y[0], y[0], y[0], y[0]);
94+
let s_strided = x4(y[0], y[2], y[0], y[6]);
95+
96+
// reading from *const
97+
unsafe {
98+
let pointer = &y[0] as *const *const f32;
99+
let pointers = x4(
100+
pointer.offset(0) as *const *const f32,
101+
pointer.offset(2),
102+
pointer.offset(4),
103+
pointer.offset(6)
104+
);
105+
106+
let r_strided = simd_gather(default, pointers, mask);
107+
108+
assert_eq!(r_strided, s_strided);
109+
}
110+
111+
// reading from *mut
112+
unsafe {
113+
let pointer = &mut y[0] as *mut *const f32;
114+
let pointers = x4(
115+
pointer.offset(0) as *mut *const f32,
116+
pointer.offset(2),
117+
pointer.offset(4),
118+
pointer.offset(6)
119+
);
120+
121+
let r_strided = simd_gather(default, pointers, mask);
122+
123+
assert_eq!(r_strided, s_strided);
124+
}
125+
126+
// writing to *mut
127+
unsafe {
128+
let pointer = &mut y[0] as *mut *const f32;
129+
let pointers = x4(
130+
pointer.offset(0) as *mut *const f32,
131+
pointer.offset(2),
132+
pointer.offset(4),
133+
pointer.offset(6)
134+
);
135+
136+
let values = x4(y[7], y[6], y[5], y[1]);
137+
simd_scatter(values, pointers, mask);
138+
139+
let s = [
140+
&x[7] as *const f32,
141+
&x[1] as *const f32,
142+
&x[6] as *const f32,
143+
&x[3] as *const f32,
144+
&x[4] as *const f32,
145+
&x[5] as *const f32,
146+
&x[1] as *const f32,
147+
&x[7] as *const f32
148+
];
149+
assert_eq!(y, s);
150+
}
80151
}

0 commit comments

Comments
 (0)