Skip to content

Compiling rv32uf-fadd fails with clang due to float NaN definition #610

Closed
@etterli

Description

@etterli

I'm trying to build the ISA tests with PULP's LLVM riscv toolchain (based on LLVM / clang 15.0.0). I can successfully build the rv32ui tests but cannot compile the rv32uf and rv32ud tests.

In particular, the testcase 11 (testing NaN) of rv32uf/fadd.s cannot be built due to how the qNaNf value is specified in the test_macros.h file. The qNaNf value is defined as:

#define qNaNf 0f:7fc00000

Thus, the test macro (TEST_FP_OP2_S) expands to the following assembly code:

test_11:
  // some instructions
.pushsection .data;
.align 2;
test_11_data:
  .float Inf;
  .float Inf;
  .float 0.0;
  .float 0f:7fc00000;  // <-- this fails
.popsection;

The build now fails on the 0f:7fc00000 floating point literal. The 0f: is marked as unexpected token. The exact error is:

riscv-tests/isa/rv64uf/fadd.S:33:300: error: unexpected token
test_11: li gp, 11; la a0, test_11_data ; flw f10, 0(a0); flw f11, 4(a0); flw f12, 8(a0); lw a3, 12(a0); fsub.s f13, f10, f11; fmv.x.s a0, f13; fsflags a1, x0; li a2, 0x10; bne a0, a3, fail; bne a1, a2, fail; .pushsection .data; .align 2; test_11_data: .float Inf; .float Inf; .float 0.0; .float 0f:7fc00000; .popsection;
                                                                                                                                                                                                                                                                                                         ^

The same problem applies to the rv32-ud tests except that 0d: instead of 0f: is used.

I tried without success:

  • Using 0x or 0h as prefix but this resulted in an invalid floating point literal error. It seems only actual floating point numbers work.
  • Using NaN instead of the special qNaNf value. This compiled but I'm not certain whether the actual NaN value is correct and/or how I can differentiate between the qNaN or sNaN value?

An alternative solution I found and works is:

  • Change the TEST_FP_OP2_S macro such that .float literal is replaced with a .quad literal and replace the qNaNf definition with the regular hex number. The generated code then is:
#define qNaNf 0x7fc00000

test_11:
  // some instructions
.pushsection .data;
.align 2;
test_11_data:
  .float Inf;
  .float Inf;
  .float 0.0;
  .quad 0x7fc00000;  // <-- this works
.popsection;

Despite this works, this solution is not very nice as I obviously cannot use the original upstream code anymore. Using a gcc toolchain to build the tests is a valid idea but I don't want to do this as we then have to setup/maintain two toolchains.

  • Is there a simpler solution such that LLVM supports the GCC float literal?
  • Is it planned to support LLVM in future?

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