Skip to content

Commit 189d169

Browse files
committed
Add tests for generating NaN with SIMD.
1 parent 6d51774 commit 189d169

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

compiler-rt/test/nsan/vec_sqrt.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// RUN: %clangxx_nsan -O0 -g -mavx %s -o %t
2+
// RUN: NSAN_OPTIONS=check_nan=true,halt_on_error=0 %run %t 2>&1 | FileCheck %s
3+
// RUN: %clangxx_nsan -O3 -g -mavx %s -o %t
4+
// RUN: NSAN_OPTIONS=check_nan=true,halt_on_error=0 %run %t 2>&1 | FileCheck %s
5+
6+
#include <cmath>
7+
#include <immintrin.h>
8+
#include <iostream>
9+
10+
void simd_sqrt(const float *input, float *output, size_t size) {
11+
size_t i = 0;
12+
for (; i + 7 < size; i += 8) {
13+
__m256 vec = _mm256_loadu_ps(&input[i]);
14+
__m256 result = _mm256_sqrt_ps(vec);
15+
_mm256_storeu_ps(&output[i], result);
16+
}
17+
for (; i < size; ++i) {
18+
output[i] = std::sqrt(input[i]);
19+
}
20+
}
21+
22+
int main() {
23+
float input[] = {1.0, 2.0, -3.0, 4.0, 5.0, 6.0, 7.0,
24+
8.0, 9.0, -10.0, 11.0, 12.0, 13.0, 14.0,
25+
15.0, -16.0, 17.0, -18.0, -19.0, -20.0};
26+
float output[20];
27+
simd_sqrt(input, output, 20);
28+
for (int i = 0; i < 20; ++i) {
29+
std::cout << output[i] << std::endl;
30+
}
31+
return 0;
32+
}

0 commit comments

Comments
 (0)