Skip to content

Commit

Permalink
Test x87 FPU build in CI
Browse files Browse the repository at this point in the history
  • Loading branch information
Maratyszcza committed May 28, 2024
1 parent 7b7b039 commit 48fa2fd
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 10 deletions.
12 changes: 7 additions & 5 deletions .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
- name: Build
run: cmake --build build --parallel
- name: Test
run: ctest --test-dir build --parallel
run: ctest --test-dir build --parallel --output-on-failure
cmake-macos-x86_64:
runs-on: macos-12
timeout-minutes: 15
Expand All @@ -36,7 +36,7 @@ jobs:
- name: Build
run: cmake --build build --config Release --parallel -- -quiet
- name: Test
run: ctest --test-dir build --build-config Release --parallel
run: ctest --test-dir build --build-config Release --parallel --output-on-failure
cmake-macos-arm64:
runs-on: macos-14
timeout-minutes: 15
Expand All @@ -47,18 +47,20 @@ jobs:
- name: Build
run: cmake --build build --config Release --parallel -- -quiet
- name: Test
run: ctest --test-dir build --build-config Release --parallel
run: ctest --test-dir build --build-config Release --parallel --output-on-failure
cmake-windows-x86:
runs-on: windows-2019
timeout-minutes: 15
steps:
- uses: actions/checkout@v4
- name: Configure
run: cmake -Bbuild -S. -G "Visual Studio 16 2019" -A Win32 -DFP16_BUILD_COMPARATIVE_BENCHMARKS=ON
env:
CXXFLAGS: "/arch:IA32"
- name: Build
run: cmake --build build --config Release --parallel
- name: Test
run: ctest --test-dir build --build-config Release --parallel
run: ctest --test-dir build --build-config Release --parallel --output-on-failure
cmake-windows-x64:
runs-on: windows-2019
timeout-minutes: 15
Expand All @@ -69,7 +71,7 @@ jobs:
- name: Build
run: cmake --build build --config Release --parallel
- name: Test
run: ctest --test-dir build --build-config Release --parallel
run: ctest --test-dir build --build-config Release --parallel --output-on-failure
cmake-windows-arm64:
runs-on: windows-2019
timeout-minutes: 15
Expand Down
7 changes: 6 additions & 1 deletion include/fp16/fp16.h
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,12 @@ static inline uint16_t fp16_ieee_from_fp32_value(float f) {
const float scale_to_inf = fp32_from_bits(UINT32_C(0x77800000));
const float scale_to_zero = fp32_from_bits(UINT32_C(0x08800000));
#endif
float base = (fabsf(f) * scale_to_inf) * scale_to_zero;
#if defined(_MSC_VER) && defined(_M_IX86_FP) && (_M_IX86_FP == 0)
const volatile float saturated_f = fabsf(f) * scale_to_inf;
#else
const float saturated_f = fabsf(f) * scale_to_inf;
#endif
float base = saturated_f * scale_to_zero;

const uint32_t w = fp32_to_bits(f);
const uint32_t shl1_w = w + w;
Expand Down
48 changes: 44 additions & 4 deletions test/bitcasts.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@


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

Expand All @@ -18,7 +18,7 @@ TEST(FP32_TO_BITS, positive) {
}

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

Expand All @@ -29,8 +29,30 @@ TEST(FP32_TO_BITS, negative) {
}
}

TEST(FP32_TO_BITS, nan) {
for (uint32_t bits = UINT32_C(0x7F800001); bits <= UINT32_C(0x7FFFFFFF); bits++) {
float value;
memcpy(&value, &bits, sizeof(value));

ASSERT_GT(fp32_to_bits(value) & UINT32_C(0x7FFFFFFF), UINT32_C(0x7F800000)) <<
std::hex << std::uppercase << std::setfill('0') <<
"BITS = 0x" << std::setw(8) << bits << ", " <<
"BITCAST(VALUE) = 0x" << std::setw(8) << fp32_to_bits(value);
}

for (uint32_t bits = UINT32_C(0xFFFFFFFF); bits >= UINT32_C(0xFF800001); bits--) {
float value;
memcpy(&value, &bits, sizeof(value));

ASSERT_GT(fp32_to_bits(value) & UINT32_C(0x7FFFFFFF), UINT32_C(0x7F800000)) <<
std::hex << std::uppercase << std::setfill('0') <<
"BITS = 0x" << std::setw(8) << bits << ", " <<
"BITCAST(VALUE) = 0x" << std::setw(8) << fp32_to_bits(value);
}
}

TEST(FP32_FROM_BITS, positive) {
for (uint32_t bits = UINT32_C(0x00000000); bits <= UINT32_C(0x7FFFFFFF); bits++) {
for (uint32_t bits = UINT32_C(0x00000000); bits <= UINT32_C(0x7F800000); bits++) {
const float value = fp32_from_bits(bits);
uint32_t bitcast;
memcpy(&bitcast, &value, sizeof(bitcast));
Expand All @@ -43,7 +65,7 @@ TEST(FP32_FROM_BITS, positive) {
}

TEST(FP32_FROM_BITS, negative) {
for (uint32_t bits = UINT32_C(0xFFFFFFFF); bits >= UINT32_C(0x80000000); bits--) {
for (uint32_t bits = UINT32_C(0xFF800000); bits >= UINT32_C(0x80000000); bits--) {
const float value = fp32_from_bits(bits);
uint32_t bitcast;
memcpy(&bitcast, &value, sizeof(bitcast));
Expand All @@ -54,3 +76,21 @@ TEST(FP32_FROM_BITS, negative) {
"VALUE = 0x" << std::setw(8) << bitcast;
}
}

TEST(FP32_FROM_BITS, nan) {
for (uint32_t bits = UINT32_C(0x7F800001); bits <= UINT32_C(0x7FFFFFFF); bits++) {
const float value = fp32_from_bits(bits);

ASSERT_TRUE(std::isnan(value)) <<
std::hex << std::uppercase << std::setfill('0') <<
"BITS = 0x" << std::setw(8) << bits;
}

for (uint32_t bits = UINT32_C(0xFFFFFFFF); bits >= UINT32_C(0xFF800001); bits--) {
const float value = fp32_from_bits(bits);

ASSERT_TRUE(std::isnan(value)) <<
std::hex << std::uppercase << std::setfill('0') <<
"BITS = 0x" << std::setw(8) << bits;
}
}

0 comments on commit 48fa2fd

Please sign in to comment.