s-macke / jor1k

Online OR1K Emulator running Linux
http://jor1k.com
BSD 2-Clause "Simplified" License
1.73k stars 196 forks source link

riscv/fastcpu: UMul/IMul versus their description #104

Closed neuschaefer closed 8 years ago

neuschaefer commented 8 years ago

In js/worker/riscv/fastcpu.js, there are the two functions UMul and IMul. UMul is documented as a signedsigned multiplication and IMul as unsignedunsigned multiplication. However, their names suggest that it's in fact the other way around (UMul sounds like unsigned multiplication).

Which function does what?

andrakis commented 8 years ago

If I understand you correctly, you want to know whether jor1k is doing what the (incorrect?) documentation says, or the "correct" behavior that occurs in a real device.

According to the imul section, it's been implemented as per existing real devices, not what the documentation says.

neuschaefer commented 8 years ago

I think a was a little tired when I wrote the above :)

I'm talking about fastcpu.js in the (experimental?) RISC-V code. And by documentation I mean the comment in the third line of these functions.

By reading some more of the code, I found out that the mulh instruction (signedsigned) uses UMul and the mulhu instruction (unsignedunsigned) uses IMul. So the comments are correct, but the names are wrong (IMHO, at least).

s-macke commented 8 years ago

I think the labeling is wrong. But to check the multiplication functions was on my list anyhow. The official riscv test cases (https://github.com/riscv/riscv-tests) are fine with the implementation.

s-macke commented 8 years ago

Problem solved. The multiplication instructions still need a thorough check https://github.com/s-macke/jor1k/commit/3ce20cb17a720e0cda56288e5d00ef5d159071c3