Skip to content

Missing Underflow float exceptions in some cases (XuanTie Group explained) #17

@kxxt

Description

@kxxt

Some glibc tests failed because of missing expected underflow float exceptions.

FAIL: math/test-double-fma
FAIL: math/test-float-double-div  
FAIL: math/test-float-double-fma  
FAIL: math/test-float-double-mul
FAIL: math/test-float-fma
FAIL: math/test-float32-float32x-div  
FAIL: math/test-float32-float32x-fma  
FAIL: math/test-float32-float32x-mul
FAIL: math/test-float32-float64-div  
FAIL: math/test-float32-float64-fma  
FAIL: math/test-float32-float64-mul
FAIL: math/test-float32-fma
FAIL: math/test-float32x-float64-div  
FAIL: math/test-float32x-float64-fma
FAIL: math/test-float32x-fma
FAIL: math/test-float64-fma

The failing math tests have one thing in common: underflow float exception is missing. Here is the test log from math/test-float-double-div:

glibc-build/math/test-float-double-div  
testing float (argument double)  
Failure: div_downward_double (-0x4p-128, 0x1.000002p+0): Exception "Underflow" not set  
Failure: div_downward_double (0x4p-128, -0x1.000002p+0): Exception "Underflow" not set  
Failure: div_upward_double (-0x4p-128, -0x1.000002p+0): Exception "Underflow" not set  
Failure: div_upward_double (0x4p-128, 0x1.000002p+0): Exception "Underflow" not set  
  
Test suite completed:  
1732 test cases plus 1728 tests for exception flags and  
1728 tests for errno executed.  
4 errors occurred.

I built the following minimal reproduction out of this:

#include <math.h>
#include <fenv.h>
#include <stdio.h>

int main() {
  if (fesetround (FE_DOWNWARD)) {
    printf("ERROR: Failed to set rounding mode!\n");
    return 1;
  }
  float ans = fdiv(-0x4p-128, 0x1.000002p+0);
  if(fetestexcept (FE_UNDERFLOW)) {
    printf("Success: Exception Underflow is set!\n");
  } else {
    printf("Failure: Exception Underflow is not set!!!\n");
  }
}

And the following command is used to compile and run it:

gcc fdiv-repro.c  -lm -std=c2x -o fdiv-repro && ./fdiv-repro

Expected behavior: the program output Success: Exception Underflow is set!.

However, I got Failure: Exception Underflow is not set!!! .

Test results on different machines, OS and architectures:

revyos,     lpi4a: Failure: Exception Underflow is not set!!!
Arch,      sg2042: Failure: Exception Underflow is not set!!!
Arch,       lpi4a: Failure: Exception Underflow is not set!!!
Arch,   qemu-user: Success: Exception Underflow is set!
Arch,   unmatched: Success: Exception Underflow is set!
Arch, qemu-system: Success: Exception Underflow is set!
Arch,      x86_64: Success: Exception Underflow is set!

This might suggest something is wrong in the floating-point implementation of C910 & C920.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions