This is an archive of the discontinued LLVM Phabricator instance.

[RISCV][NFC] Add test case for accept hexadecimal floating-point for fli instructions
ClosedPublic

Authored by kito-cheng on Apr 12 2023, 1:27 AM.

Details

Summary

Zfa provide fli instruction to load a floating point immediate value,
and some of those are not easy to write and read by human, so
hexadecimal floating-point format should be a good alternative way to write:

Consider this case: 1^-16 = 1.52587890625e-05 (decimal) vs 0x1p-16 (hexadecimal)

The hexadecimal format is easier to write for human.

Fortunately hexadecimal floating-point constants already supported in
C99, so actually we don't need to add any extra code to support that.

This patch added test case for demonstrate we support that and also make
sure this will be supported in future.

I also gonna to talk with ISA folks to adding hexadecimal floating-point
to the ISA spec, so that user will know fli accept value in this format.

Diff Detail

Event Timeline

kito-cheng created this revision.Apr 12 2023, 1:27 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 12 2023, 1:27 AM
kito-cheng requested review of this revision.Apr 12 2023, 1:27 AM
asb added a comment.EditedApr 12 2023, 2:22 AM

There's obviously a judgement to be made about when you add comprehensive tests vs a sampling and rely on the hex to FP parsing logic to "just work", but I've got no objection to adding these tests. I do think it would be easier to read and more maintainable if you interspersed the hex tests with the existing ones. e.g. put fli.s ft1, -0x1p+0 and fli.h ft1, -1.000000e+00 next to each other in the file.

Regarding isa manual changes - if this is going to be documented anywhere I'd think the asm manual makes most sense.

Changes:

  • Reorder the testcase per asb's suggesion.

Regarding isa manual changes - if this is going to be documented anyway I'd think the asm manual makes most sense.

Yeah, agree that, let me find some time to handle that after GCC 13 release :P

Anyway, my goal is align the behavior/syntax of fli operand on binutils and LLVM - current working patch on binutils has supported both decimal and hexadecimal too :)

Fortunately hexadecimal floating-point constants already supported in C99

What's the relevance of C99 to the assembler?

Fortunately hexadecimal floating-point constants already supported in C99

What's the relevance of C99 to the assembler?

Let me expand more to explain my logic here: because c99 supported that format so fundamental IO functions like scanf/stof/iostream already support that - so we don't need to write any code to adding hexadecimal floating-point constants parsing.

asb accepted this revision.Apr 13 2023, 6:05 AM

LGTM.

This revision is now accepted and ready to land.Apr 13 2023, 6:05 AM