> On 3 Aug 2017, at 7:18 AM, Rogier Brussee <rogier....@gmail.com> wrote:
>
> The RV ISA is spartan. Many instructions that can be found in other ISA's are supposed to be encoded with macro-op fusion, especially if they can be expressed with instructions in the Compact extension. That is all nice and dandy but for the hardware to recognise a sequence of instructions and macro fuse them, that precise sequence has to be generated.
>
> This suggests that at least some macro-op fusions should become part of the ABI as officially recommended in particular for compiler writers.
> A natural implementation of this idea would be to define asm/linker macro's that the compiler can use, effectively extending the ISA.
>
> Extra bonus, if things can be speced such that a linker or loader can safely substitute the macro with a semantically equivalent sequence that is optimal for the particular microarchitecture including substitution with a single instruction
>
> Example of what I have in mind:
>
> macro:
>
> ZEXT %rd % rs1 imm7
>
> default expansion
> srli %rd %rs1 -imm7; srai %rd %rd -imm7
>
> legitimate implementations
>
> micro architecture1 macro-op fuses everything with -32 <= imm7 <31
> micro architecture2 macro-op fuses only the compact versions with %rd ==%rs1
> micro architecture3 only macro-op fuses for imm7 == 32
> micro architecture4 just executes the two instructions
> micro architecture5 has a special zextw instruction. The non default asm macro expands to this instruction for imm7= 32.
I think zext.w pseudo to match the sext.w pseudo is a good idea.
The riscv gcc compiler metadata already has a pattern match expression called shift_shift that emits the zero extension sequence however it is currently informal, i.e. not defined in the specification pseudo-operations section.
It seems logical that we could define a pseudo called zext.w to match sext.w and change binutils to accept the macro.
Unfortunately it is unlike the strict operands situation where binutils already accepted the canonical forms as defined in the ISA specification. In this case gcc can’t emit zext.w unless the pre-requisite binutils change is in place, so it would be a much longer term change.
Adding zext.w as a pseudo op would not be changing the frozen part of the ISA, rather it would be naming the sequence which is already emitted by gcc i.e. documenting the current pseudos. By adding it to the spec, if gives implementors a guaranteed way to detect zero extension and substitute it with a micro-op or a metadata in a rename table is perceivably one possible implementation.
If there is agreement I don’t mind to submit a patch to riscv-isa-manual and binutils. This change is in essence a small change, or refinement whereby we are documenting the implementation.
We’d probably need to wait a year (or some sufficient amount of time for people to upgrade their binutils) until we make the change in gcc. Alternatively it could be enabled by a configure check assuming gcc build detects the version of binutils it is being built against, however that might make the metadata change more tricky to implement.
The first place may just be to add the pseudo to the ISA manual? as it is technically already emitted.
Michael.
We’d probably need to wait a year (or some sufficient amount of time for people to upgrade their binutils) until we make the change in gcc. Alternatively it could be enabled by a configure check assuming gcc build detects the version of binutils it is being built against, however that might make the metadata change more tricky to implement.Even for the I extension other macro ops were proposed. I would also like a neg macro but that is just cosmetics.
The first place may just be to add the pseudo to the ISA manual? as it is technically already emitted.If there is some sort of consensus it is a good idea yes.CiaoRogierMichael.
--
You received this message because you are subscribed to the Google Groups "RISC-V ISA Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to isa-dev+u...@groups.riscv.org.
To post to this group, send email to isa...@groups.riscv.org.
Visit this group at https://groups.google.com/a/groups.riscv.org/group/isa-dev/.
To view this discussion on the web visit https://groups.google.com/a/groups.riscv.org/d/msgid/isa-dev/b7809447-e4d9-4106-a3a6-a13f3333748e%40groups.riscv.org.
Adding assembler directives seems attractive for a few common idioms,
but the cross-product of fusable instructions is huge, and beyond the
scope of what the assembler should understand. Furthermore, the
patterns that should be fused will evolve over time. So while I agree
we should have canonical representations of idioms to guide compiler
writers and hardware implementors,
I don't think the assembler is the
right place for that.
> On 3 Aug 2017, at 10:43 AM, Andrew Waterman <wate...@eecs.berkeley.edu> wrote:
>
> Adding assembler directives seems attractive for a few common idioms,
> but the cross-product of fusable instructions is huge, and beyond the
> scope of what the assembler should understand. Furthermore, the
> patterns that should be fused will evolve over time. So while I agree
> we should have canonical representations of idioms to guide compiler
> writers and hardware implementors, I don't think the assembler is the
> right place for that.
Yes. Agree.
Imagine if we had all_pairs(RV32I.ALU, RV32I.ALU) with 2 pipelined ALUs, and patterns for dependent ops that use a temporary with a very short live span. e.g.
<alu_op> r1,r2,r3
<alu_op> r1,r1,r4
However zext.w seems logical due to the presence of sext.w, perhaps then just as an addition to the pseudo instruction table in the ISA manual.
The question is whether to match the sext.w form or as Rogier had defined it, with a variable width immediate, given the same pattern could be used for zero extending a half word or byte. Only 32-bit values (or 64-bit for RV128) are sign-extended in the ISA so i’m not sure of the frequency of the zero extend pattern for other immediate values. We’ll have to work on some macro-op fusion histograms…
To view this discussion on the web visit https://groups.google.com/a/groups.riscv.org/d/msgid/isa-dev/0f9186b9-5b65-409a-a72c-e7304cc90d05n%40groups.riscv.org.
To view this discussion on the web visit https://groups.google.com/a/groups.riscv.org/d/msgid/isa-dev/b4b408a1-6220-4e17-8778-d947e9043fbcn%40groups.riscv.org.
To view this discussion on the web visit https://groups.google.com/a/groups.riscv.org/d/msgid/isa-dev/1bf70c9a-d532-49db-9bf9-c5302de3adaen%40groups.riscv.org.