Skip to content

[compiler-rt] __truncXfYf2 functions ignore the current rounding mode and always round to nearest, ties to even #100413

Open
@overmighty

Description

@overmighty

https://godbolt.org/z/dchq7rxe7

C code:

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

_Float16 bar(float x) {
  return (_Float16)x;
}

int main() {
  volatile float x = 0x1.0p-25f;
  fesetround(FE_UPWARD);
  printf("%a\n", (double)bar(x));
  fesetround(FE_DOWNWARD);
  printf("%a\n", (double)bar(x));
}

Output with libgcc:

0x1p-24
0x0p+0

Output with compiler-rt:

0x0p+0
0x0p+0

Relevant compiler-rt source:

COMPILER_RT_ABI NOINLINE dst_t __truncsfhf2(float a) {
return __truncXfYf2__(a);
}

// This file implements a fairly generic conversion from a wider to a narrower
// IEEE-754 floating-point type in the default (round to nearest, ties to even)
// rounding mode. The constants and types defined following the includes below
// parameterize the conversion.

cc @lntue

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions