-
Notifications
You must be signed in to change notification settings - Fork 159
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding Zcb implementation #322
Conversation
Following the discussion in Zoom I had a closer look at this and almost all of these instructions map very clearly to existing instructions. Only 2 don't map cleanly and would maybe be clearer reimplemented.
For example instead of:
Use:
Primitive obsession notwithstanding, I think this is easier to understand, matches the existing C instructions and is less error prone. The intention of this extension is just to have shorter decodings, so the implementation should match. For example in this case (which I picked randomly!), reimplementing it introduced a bug, whereas just mapping it would not have. I think that's probably a strong enough argument on its own, given the lack of testing. |
Yes. See #255 (comment). |
I just asked Tariq Kurd, the original author of the spec, what he thinks we should do:
Tariq said we should do (1), that was always the intent - and demonstrates that the instructions are trivial. This is also how the other compressed instructions are implemented, e.g. So in addition to
|
Same thoughts #255 (comment) |
Makefile
Outdated
@@ -16,7 +16,6 @@ else | |||
endif | |||
|
|||
SAIL_FLEN := riscv_flen_D.sail | |||
SAIL_VLEN := riscv_vlen.sail |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh and this is removing vector, resolve conflicts accept all mine ?
Just for my understanding, can one of you please clarify the following,
|
The advantages are clarity (because it communicates the intention of the compressed instructions) and it simplifies us verifying the correctness of the Sail implementation. The performance of the Sail model is currently a secondary concern. A sufficiently smart compiler should be able to inline those function calls. The effect on actual circuits that are used to implement compressed instructions in physically is not a concern of the Sail model, as long as the have the same observable behaviour. |
Thank you Martin, Thank you. |
These instructions are only supported if the instructions they map to are are implemented. That was the bug in your |
Yes Tim, i understood that part. I was trying to understand, does this not put a limitation on the implementation, as someone could choose to implement only the compressed instructions. Is this even allowed/supported. Thank you. |
They can't. The ones that are mapped to optional instructions require those instructions to be implemented. For example here's what the spec says about Your
|
... and there's no sensible use case for it, either; if you have the hardware to do a c.mul, you might as well use it to do a mul too. Decode is very little cost compared to the actual multiplier. |
Modified the implementation and pushed the file, please review and comment. |
model/riscv_insts_zcb.sail
Outdated
/*=======================================================================================*/ | ||
|
||
/* ****************************************************************** */ | ||
/* This file specifies the instructions in the 'ZCEE' extension. */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this say Zcb not ZCEE?
model/riscv_insts_zcb.sail
Outdated
let rd = creg2reg_idx(rsd); | ||
let rs = creg2reg_idx(rs2); | ||
|
||
execute(MUL((rs, rd, rd, false, true, true))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extra brackets here.
model/riscv_insts_zcb.sail
Outdated
<-> 0b100 @ 0b000 @ rs1 : cregidx @ ui65 : bits(2) @ rd : cregidx @ 0b00 | ||
|
||
function clause execute (C_LBU(uimm, rsc, rdc)) = { | ||
let immext : xlenbits = zero_extend(uimm); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is unused
|
||
function clause execute (C_LBU(uimm, rsc, rdc)) = { | ||
let immext : xlenbits = zero_extend(uimm); | ||
let imm : bits(12) = zero_extend(uimm); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is wrong. The ui65
should be called ui01
and then
let imm : bits(12) = zero_extend(ui01[0] @ ui01[1]);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Swizzle the bits in decode not execute
} | ||
|
||
mapping clause assembly = C_LBU(uimm, rsc, rdc) | ||
<-> "c.lbu" ^ spc() ^ creg_name(rdc) ^ sep() ^ creg_name(rsc) ^ sep() ^ hex_bits_5(uimm @ 0b000) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
uimm
wrong here too.
model/riscv_insts_zcb.sail
Outdated
<-> 0b100 @ 0b001 @ rs1 : cregidx @ 0b0 @ ui5 : bits(1) @ rd : cregidx @ 0b00 | ||
|
||
function clause execute (C_LHU(uimm, rsc, rdc)) = { | ||
let immext : xlenbits = zero_extend(uimm); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also unused. Please check the other instructions too.
|
||
function clause execute (C_LHU(uimm, rsc, rdc)) = { | ||
let immext : xlenbits = zero_extend(uimm); | ||
let imm : bits(12) = zero_extend(uimm); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also wrong - should be zero_extend(ui1 @ 0b0);
Please check the other instructions too.
model/riscv_insts_zcb.sail
Outdated
/* the encode/decode mapping between AST elements and 16-bit half words */ | ||
|
||
mapping clause encdec_compressed = C_MUL(rsd, rs2) | ||
<-> 0b100 @ 0b111 @ rsd : cregidx @ 0b00 @ rs2 : cregidx @ 0b01 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ 0b00 @
should be @ 0b10 @
Given these review comments, are you testing your code before pushing it for review, and if so how? Because basic things like decode patterns should be caught by even the most basic testing. Also you've still deleted a bunch of V-related changes from Makefile which causes the build to fail in CI. So I don't think you could possibly have tested this code given it won't build. |
Thank you Tim and Jessica for the comments, i have updated the Makefile and the Zcb model. |
Makefile
Outdated
@@ -30,6 +30,9 @@ SAIL_DEFAULT_INST += riscv_insts_zbc.sail | |||
SAIL_DEFAULT_INST += riscv_insts_zbs.sail | |||
|
|||
SAIL_DEFAULT_INST += riscv_insts_zfh.sail | |||
|
|||
SAIL_DEFAULT_INST += riscv_insts_zcb.sail |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be good to keep this list sorted alphabetically, i.e. move it up one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This has been updated.
/* ****************************************************************** */ | ||
union clause ast = C_LHU : (bits(1), cregidx, cregidx) | ||
|
||
mapping clause encdec_compressed = C_LHU(ui1, rs1, rd) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mapping clause encdec_compressed = C_LHU(ui1, rs1, rd) | |
mapping clause encdec_compressed = C_LHU(ui1 @ 0b0, rs1, rd) |
Immediate is not scaled in current code. I assume this means there are no tests?
Looks like you didn't fix the issues with the immediates though? |
Hi, @jrtc27, fair question. I asked @junambi to post his current PR work early because @martinberger had interest in the work and we wanted to make sure that we didn't duplicating previous effort. |
@martinberger, what is the status of your work? I can't tell if a PR was submitted. |
There isn't a PR. I thought Martin added our implementation to a comment but I can't see it now. I'll make a new PR. |
Thanks, @Timmmm and @martinberger! |
Zcb implementation for review and merger.