Closed yidanyiji closed 7 years ago
I think the biggest problem here is that those custom macros presumably found here don't support not setting the xd field in RoCC. So rocket will always wait for the response which the SHA3 accelerator will never return. I don't believe these macros fundamentally can't be fixed to allow you to set xd, xs1, and xs2 but I don't plan to do that in the near future.
A couple side notes I thought about while reading the issue: If the values the accelerator got were wrong you should check that the code you compiled is assembling to the correct instruction. It seems pretty easy to believe that with those very different addresses the accelerator could go off the rails.
I'm also somewhat confused by your code snippets, you seem to have commented out some important things. If you use ``` to enclose your code it will be much easier to read.
And finally I'm updating the RoCC interface for a modern rocket-chip now and I've gotten several requests for an updated SHA3 accelerator so I might also get around to that soon.
Thanks, @colinschmidt
It seems pretty easy to believe that with those very different addresses the accelerator could go off the rails.
That is right.
How to assemble to the correct instuction?
please give me some proposal, thank you a lot!!!
you are right!!! The modified code is as following:
#define CUSTOMX(X, rd, rs1, rs2, funct) \
CUSTOMX_OPCODE(X) | \
(rd << (7)) | \
(0x3 << (7+5)) | \ // 7 -> 3
(rs1 << (7+5+3)) | \
(rs2 << (7+5+3+5)) | \
(EXTRACT(funct, 7, 0) << (7+5+3+5+5))
Really, I should have been setting xd
semi-automatically all along. This should be the correct macro which makes xd == (rd != x0)
.
Source:
ROCC_INSTRUCTION_RAW_R_R_R(0, 0, 0, 0, 0) ;
ROCC_INSTRUCTION_RAW_R_R_R(0, 1, 0, 0, 0) ;
Binary:
800000ec: 0000300b 0x300b // xd=0, xs1=1, xs2=1, rd=0, opcode=0b
800000f0: 0000708b 0x708b // xd=1, xs1=1, xs2=1, rd=1, opcode=0b
thanks @seldridge
I had transplanted the Chisel implementation of sha3 to the current Rocketchip as following:
1, git rocktchip and toolchain, compile them as README.md 2, git rocc-template 3, add Sha3Accel code in project-template/rocket-chip/src/main/scala/rocket/rocc.scala
4, add diractory project-template/rocket-chip/src/main/scala/sha3, and copy sha3 files including chi.scala, constants.scala, dpath.scala, rhopi.scala, common.scala, ctrl.scala, iota.scala, theta.scala from rocc-template/src/main/scala/ and modify those files to fit the new chisel3 syntax.
5, add Sha3Config code in project-template/rocket-chip/src/main/scala/coreplex/Config.scala as following:
6, add Sha3CPPConfig code in project-template/rocket-chip/src/main/scala/rocketchip/Config.scala class Sha3CPPConfig extends Config(new Sha3Config ++ new BaseConfig)
7, goto project-template/rocket-chip/emulator and make CONFIG=Sha3CPPConfig and get the emulator: emulator-rocketchip-Sha3CPPConfig
8, change the sha3 test code:rocc-template/tests/sha3-rocc.c as following
9, at last, I run emulator: ./emulator-rocketchip-Sha3CPPConfig sha3.riscv #THE EMULATOR NEVER QUIT!!!
10, then I run emulator: ./emulator-rocketchip-Sha3CPPConfig sha3.riscv +verbose I find the emulator read the first custom inst: CUSTOMX_R_R_R(0,_output,input,output,0) ### but NEVER read the second custom inst.
11, then I add test code in project-template/rocket-chip/src/main/scala/sha3/ctrl.scala
I find that # the values of msg_addr and hash_addr are wrong : msg_addr=40, hash_addr=80023b88
Where does my code's fault happen? Did Anybody run the chisel sha3 implementation correctly?
Thank you.