Skip to content

Commit 6d1d104

Browse files
committed
proper mul_add arg order, added tests
1 parent cf54e38 commit 6d1d104

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

crates/core_simd/examples/dot_product.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ pub fn dot_prod_simd_5(a: &[f32], b: &[f32]) -> f32 {
135135
a.array_chunks::<4>()
136136
.map(|&a| f32x4::from_array(a))
137137
.zip(b.array_chunks::<4>().map(|&b| f32x4::from_array(b)))
138-
.fold(f32x4::splat(0.), |acc, (a, b)| acc.mul_add(a, b))
138+
.fold(f32x4::splat(0.), |acc, (a, b)| a.mul_add(b, acc))
139139
.reduce_sum()
140140
}
141141

@@ -160,6 +160,8 @@ mod tests {
160160
assert_eq!(0.0, dot_prod_simd_1(&a, &b));
161161
assert_eq!(0.0, dot_prod_simd_2(&a, &b));
162162
assert_eq!(0.0, dot_prod_simd_3(&a, &b));
163+
assert_eq!(0.0, dot_prod_simd_4(&a, &b));
164+
assert_eq!(0.0, dot_prod_simd_5(&a, &b));
163165

164166
// We can handle vectors that are non-multiples of 4
165167
assert_eq!(1003.0, dot_prod_simd_3(&x, &y));

0 commit comments

Comments
 (0)