Zijf (Far jumps and calls)#3269
Conversation
Signed-off-by: Andrew Waterman <andrew@sifive.com>
Signed-off-by: Andrew Waterman <andrew@sifive.com>
|
|
Some questions here:
|
|
Thanks for chiming in Pengcheng Wang (@wangpc-pp). An additional 10% coverage is material, even if not earth-shattering. To do any better we will need longer instructions. Doing as much as we can within the 32-bit encoding space is useful even if we eventually have 48-bit jump instructions, since these instructions are denser. Also note that even implementations that optimize the AUIPC+JALR fusion pair will benefit from this extension, because of reduced code size and because a physical register allocation is skipped in the JF case. |
| insn:jfal[] writes the address of the instruction following the | ||
| jump (`pc` + 4) into register `x1`. | ||
| Then, insn:jfal[] sets the `pc` to `pc` + `offset`. | ||
| insn:jfal[] can target a range of qty:±16[MiB]. |
There was a problem hiding this comment.
The range +- 1 MiB is redundant with the existing jal. This range is easily decoded: bits 31, 19, 14, 13, 11 are either all-zeroes or all-ones.
Should these encodings be marked as reserved or are they allocated for jfal?
Similar point applies to jf with bits 31, 19, 13, 11.
There was a problem hiding this comment.
I can see it being simpler for the tools to not have to patch the opcode during relaxation.
To put some numbers to it: there are 2^21 redundant opcodes in total, which costs the sames as 64 new R-type instructions, or 1/2 of a new I-type.
There was a problem hiding this comment.
Luke Wren (@Wren6991) It's a valid point. We had been approaching this from a different angle--we were looking at the possibility of expanding the ranges of the two instructions to ±9 MiB and ±17 MiB--but found that choice to be awkward.
I agree we should at least consider reserving the redundant cases, but if we do so, we might want to change the immediate encoding so that the high-order immediate bits are in a less inconvenient place. (Right now they overlap the rs1 and rd register specifiers.)
Anyway, we'll think about it.
There was a problem hiding this comment.
Right now they overlap the rs1 and rd register specifiers
It varies a bit. When Sorry, I had this backwards. The redundant opcodes have those bits all alike.31, 14 (jfal only) and 13 are not all alike, you have completely free choice over rs1, rs2 and rd. That's half of the jf and three quarters of the jfal encoding space, so 40 clean R-types.
You're right though, I missed that, and maybe it could be avoided altogether with some shuffling.
|
Why not make the target of these instructions address be a multiple of 16 or 64 bytes? That would increase the range from 16MB to 128MB or 512MB. If someone is worried about the performance overhead of (LUI/AUIPC)+JALR then they are probably also prepared to align those important target addresses at least a little. You'd need to discard the low bits of the PC before/after adding the offset. |
This proposed extension adds two new instructions, JF (Jump Far) and JFAL (Jump Far and Link), which improve code density and performance for large programs by replacing a 64-bit AUIPC+JALR sequence with a single 32-bit instruction.