Skip to content

Commit 48fa2fd

Browse files
committed
Test x87 FPU build in CI
1 parent 7b7b039 commit 48fa2fd

3 files changed

Lines changed: 57 additions & 10 deletions

File tree

.github/workflows/cmake.yml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
- name: Build
2626
run: cmake --build build --parallel
2727
- name: Test
28-
run: ctest --test-dir build --parallel
28+
run: ctest --test-dir build --parallel --output-on-failure
2929
cmake-macos-x86_64:
3030
runs-on: macos-12
3131
timeout-minutes: 15
@@ -36,7 +36,7 @@ jobs:
3636
- name: Build
3737
run: cmake --build build --config Release --parallel -- -quiet
3838
- name: Test
39-
run: ctest --test-dir build --build-config Release --parallel
39+
run: ctest --test-dir build --build-config Release --parallel --output-on-failure
4040
cmake-macos-arm64:
4141
runs-on: macos-14
4242
timeout-minutes: 15
@@ -47,18 +47,20 @@ jobs:
4747
- name: Build
4848
run: cmake --build build --config Release --parallel -- -quiet
4949
- name: Test
50-
run: ctest --test-dir build --build-config Release --parallel
50+
run: ctest --test-dir build --build-config Release --parallel --output-on-failure
5151
cmake-windows-x86:
5252
runs-on: windows-2019
5353
timeout-minutes: 15
5454
steps:
5555
- uses: actions/checkout@v4
5656
- name: Configure
5757
run: cmake -Bbuild -S. -G "Visual Studio 16 2019" -A Win32 -DFP16_BUILD_COMPARATIVE_BENCHMARKS=ON
58+
env:
59+
CXXFLAGS: "/arch:IA32"
5860
- name: Build
5961
run: cmake --build build --config Release --parallel
6062
- name: Test
61-
run: ctest --test-dir build --build-config Release --parallel
63+
run: ctest --test-dir build --build-config Release --parallel --output-on-failure
6264
cmake-windows-x64:
6365
runs-on: windows-2019
6466
timeout-minutes: 15
@@ -69,7 +71,7 @@ jobs:
6971
- name: Build
7072
run: cmake --build build --config Release --parallel
7173
- name: Test
72-
run: ctest --test-dir build --build-config Release --parallel
74+
run: ctest --test-dir build --build-config Release --parallel --output-on-failure
7375
cmake-windows-arm64:
7476
runs-on: windows-2019
7577
timeout-minutes: 15

include/fp16/fp16.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,12 @@ static inline uint16_t fp16_ieee_from_fp32_value(float f) {
228228
const float scale_to_inf = fp32_from_bits(UINT32_C(0x77800000));
229229
const float scale_to_zero = fp32_from_bits(UINT32_C(0x08800000));
230230
#endif
231-
float base = (fabsf(f) * scale_to_inf) * scale_to_zero;
231+
#if defined(_MSC_VER) && defined(_M_IX86_FP) && (_M_IX86_FP == 0)
232+
const volatile float saturated_f = fabsf(f) * scale_to_inf;
233+
#else
234+
const float saturated_f = fabsf(f) * scale_to_inf;
235+
#endif
236+
float base = saturated_f * scale_to_zero;
232237

233238
const uint32_t w = fp32_to_bits(f);
234239
const uint32_t shl1_w = w + w;

test/bitcasts.cc

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77

88
TEST(FP32_TO_BITS, positive) {
9-
for (uint32_t bits = UINT32_C(0x00000000); bits <= UINT32_C(0x7FFFFFFF); bits++) {
9+
for (uint32_t bits = UINT32_C(0x00000000); bits <= UINT32_C(0x7F800000); bits++) {
1010
float value;
1111
memcpy(&value, &bits, sizeof(value));
1212

@@ -18,7 +18,7 @@ TEST(FP32_TO_BITS, positive) {
1818
}
1919

2020
TEST(FP32_TO_BITS, negative) {
21-
for (uint32_t bits = UINT32_C(0xFFFFFFFF); bits >= UINT32_C(0x80000000); bits--) {
21+
for (uint32_t bits = UINT32_C(0xFF800000); bits >= UINT32_C(0x80000000); bits--) {
2222
float value;
2323
memcpy(&value, &bits, sizeof(value));
2424

@@ -29,8 +29,30 @@ TEST(FP32_TO_BITS, negative) {
2929
}
3030
}
3131

32+
TEST(FP32_TO_BITS, nan) {
33+
for (uint32_t bits = UINT32_C(0x7F800001); bits <= UINT32_C(0x7FFFFFFF); bits++) {
34+
float value;
35+
memcpy(&value, &bits, sizeof(value));
36+
37+
ASSERT_GT(fp32_to_bits(value) & UINT32_C(0x7FFFFFFF), UINT32_C(0x7F800000)) <<
38+
std::hex << std::uppercase << std::setfill('0') <<
39+
"BITS = 0x" << std::setw(8) << bits << ", " <<
40+
"BITCAST(VALUE) = 0x" << std::setw(8) << fp32_to_bits(value);
41+
}
42+
43+
for (uint32_t bits = UINT32_C(0xFFFFFFFF); bits >= UINT32_C(0xFF800001); bits--) {
44+
float value;
45+
memcpy(&value, &bits, sizeof(value));
46+
47+
ASSERT_GT(fp32_to_bits(value) & UINT32_C(0x7FFFFFFF), UINT32_C(0x7F800000)) <<
48+
std::hex << std::uppercase << std::setfill('0') <<
49+
"BITS = 0x" << std::setw(8) << bits << ", " <<
50+
"BITCAST(VALUE) = 0x" << std::setw(8) << fp32_to_bits(value);
51+
}
52+
}
53+
3254
TEST(FP32_FROM_BITS, positive) {
33-
for (uint32_t bits = UINT32_C(0x00000000); bits <= UINT32_C(0x7FFFFFFF); bits++) {
55+
for (uint32_t bits = UINT32_C(0x00000000); bits <= UINT32_C(0x7F800000); bits++) {
3456
const float value = fp32_from_bits(bits);
3557
uint32_t bitcast;
3658
memcpy(&bitcast, &value, sizeof(bitcast));
@@ -43,7 +65,7 @@ TEST(FP32_FROM_BITS, positive) {
4365
}
4466

4567
TEST(FP32_FROM_BITS, negative) {
46-
for (uint32_t bits = UINT32_C(0xFFFFFFFF); bits >= UINT32_C(0x80000000); bits--) {
68+
for (uint32_t bits = UINT32_C(0xFF800000); bits >= UINT32_C(0x80000000); bits--) {
4769
const float value = fp32_from_bits(bits);
4870
uint32_t bitcast;
4971
memcpy(&bitcast, &value, sizeof(bitcast));
@@ -54,3 +76,21 @@ TEST(FP32_FROM_BITS, negative) {
5476
"VALUE = 0x" << std::setw(8) << bitcast;
5577
}
5678
}
79+
80+
TEST(FP32_FROM_BITS, nan) {
81+
for (uint32_t bits = UINT32_C(0x7F800001); bits <= UINT32_C(0x7FFFFFFF); bits++) {
82+
const float value = fp32_from_bits(bits);
83+
84+
ASSERT_TRUE(std::isnan(value)) <<
85+
std::hex << std::uppercase << std::setfill('0') <<
86+
"BITS = 0x" << std::setw(8) << bits;
87+
}
88+
89+
for (uint32_t bits = UINT32_C(0xFFFFFFFF); bits >= UINT32_C(0xFF800001); bits--) {
90+
const float value = fp32_from_bits(bits);
91+
92+
ASSERT_TRUE(std::isnan(value)) <<
93+
std::hex << std::uppercase << std::setfill('0') <<
94+
"BITS = 0x" << std::setw(8) << bits;
95+
}
96+
}

0 commit comments

Comments
 (0)