Skip to content
This repository has been archived by the owner on Aug 17, 2022. It is now read-only.

Added rm field in assembly for fcvt instructions and fixed default to dyn. #271

Open
wants to merge 1 commit into
base: riscv-binutils-2.38
Choose a base branch
from

Conversation

pawks
Copy link

@pawks pawks commented Jun 17, 2022

Fixes issues outlined here.

@cmuellner
Copy link
Contributor

Thanks for your contribution!

Binutils development is done upstream (https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git). Patches can be sent to the binutils mailing list (https://sourceware.org/mailman/listinfo/binutils).

Also, please make sure to adjust test cases that are affected by your changes (have a look into gas/testsuite/gas/riscv).

@a4lg
Copy link

a4lg commented Jul 1, 2022

I support the general idea. On disassembler, it can be great!

Problems are:

  • You are based on quite an old revision.
  • Prohibiting use of rounding mode operand in the assembler may be an option.

So, I'll make another proposal based on your idea.

@a4lg
Copy link

a4lg commented Jul 1, 2022

Wait... making DYN default for certain instructions is not good.

Quoting RISC-V ISA Manual (13.2 Floating-Point Control and Status Register):

Some instructions, including widening conversions, have the rm field but are nevertheless mathematically unaffected by the rounding mode; software should set their rm field to RNE (000) but implementations must treat the rm field as usual (in particular, with regard to decoding legal vs. reserved encodings).

Actually, fcvt.q.l[u] instructions are fixed to have RNE by default (instead of DYN) in 1d1595b.

@aswaterman
Copy link
Contributor

@a4lg speaking as one of the authors of this part of the spec, I agree that defaulting to DYN is not the preference.

Fortunately, this is a very minor issue in practice. Most importantly, there is no functional-correctness concern. There is a hypothetical loss in performance when frm is explicitly written shortly before an instruction implicitly reads frm because the rounding mode is DYN, but rarely should this loss manifest.

I support changing the default to RNE for all instructions that don't round. There would be no functional implications to this change, and it would bring the assembler more in line with the ISA spec's recommendations.

@pawks
Copy link
Author

pawks commented Jul 1, 2022

I support the general idea. On disassembler, it can be great!

Problems are:

  • You are based on quite an old revision.

I dont quite understand what you mean here.

  • Prohibiting use of rounding mode operand in the assembler may be an option.

The assembler should be supporting the rounding modes since it is a legal field in the specification. That was the motivation behind this PR. I don't think adding the rm modes breaks anything. Although having a default of RNE seems to be for the best.

So, I'll make another proposal based on your idea.

@kito-cheng
Copy link
Collaborator

@aswaterman Just make sure you mean all fcvt instructions instead of all floating point instructions, right?

@aswaterman
Copy link
Contributor

aswaterman commented Jul 1, 2022

@kito-cheng I was specifically referring to instructions that are unaffected by rounding mode: e.g., fcvt.d.w[u] and fcvt.d.s.

For any instruction that does round (e.g. fcvt.s.w or fadd.s), dyn needs to remain the default--both because it's the most logical default, and because it's necessary for backwards compatibility.

@a4lg
Copy link

a4lg commented Jul 2, 2022

My initial proposal (I will submit later to binutils ML) is rather conservative but can be easily modified to implement your proposal (by just removing warning/error generating portion).

  • Disassembler
    Full support (but print rounding mode only if no-aliases is given)
  • Assembler
    Generate error message on used (but can be easily modified to implement your proposal)
    On fcvt.q.l[u], a warning is generated when used.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants