Comments (6)
Your code is modifiying itself. The tests store their results starting at address 0x68 (104), which is where the first instruction of test 3 is located, so the instructions of test 3 are completely overwritten by tests 1 and 2. That's why you are seeing "Unknown instruction". Removing some instructions makes the program shorter and therefore the test 3 instructions aren't overwritten any more.
Assembler labeling is your friend. Here is a quick and dirty example using the store global pseudo-instruction. More elegant solutions exist that avoid lots of unnecesary "auipc"s leveraging x3/gp.
# Immediates
li a0, 10
li a1, -10
li a2, 6
li t0, 1
li s0, 1
# Test1: mul, no mulh
while: # calculate 10^6 and (-10)^6
beqz a2, break
mul t0, t0, a0
mul s0, s0, a1
addi a2, a2, -1
j while
break:
li a0, -1
mul s0, s0, a0
sw t0, test1r1, t6 # 10^6 = 1.000.000 = 0x000F 4240
sw s0, test1r2, t6 # (-10)^6 = -1.000.000 = 0xFFF0 BDC0
# Test2: mul and mulh
# Positive x positive
mul t1, t0, t0 # 10^6 * 10^6, lower bits
mulh s1, t0, t0 # 10^6 * 10^6, upper bits
sw t1, test2r1l, t6 # 0xD4A5 1000
sw s1, test2r1h, t6 # 0x0000 00E8
# Positive x negative
mul t2, t0, s0 # 10^6 * (-10)^6, lower bits
mulh s2, t0, s0 # 10^6 * (-10)^6, upper bits
sw t2, test2r2l, t6 # 0x2B5A F000
sw s2, test2r2h, t6 # 0xFFFF FF17
# Negative x negative
mul t3, s0, s0 # (-10)^6 * (-10)^6, lower bits
mulh s3, s0, s0 # (-10)^6 * (-10)^6, upper bits
sw t3, test2r3l, t6 # 0xD4A5 1000
sw s3, test2r3h, t6 # 0x0000 00E8
# Test3: mul and mulhsu
# Positive x negative, interpreted as positive
# -1.000.000 = 0xFFF0 BDC0, so as a positive number, we have 4.293.967.296
mul t4, t0, s0 # 10^6 * "(-10)^6", lower bits
mulhsu s4, t0, s0 # 10^6 * "(-10)^6", upper bits
sw t4, test3r1l, t6 # 0x2B5A F000
sw s4, test3r1h, t6 # 0x000F 4157
end:
li a7, 10
ecall
.data
test1r1: .word 0
test1r2: .word 0
test2r1l: .word 0
test2r1h: .word 0
test2r2l: .word 0
test2r2h: .word 0
test2r3l: .word 0
test2r3h: .word 0
test3r1l: .word 0
test3r1h: .word 0
from ripes.
According to section 7.1 of "The RISC-V Instruction Set Manual Volume I: Unprivileged ISA" Document version 20191213, "If both the high and low bits of the same product are required, then the recommended code sequence is: MULH[[S]U] rdh, rs1, rs2; MUL rdl, rs1, rs2 (source register specifiers must be in same order and rdh cannot be the same as rs1 or rs2)." Have you tried swapping the MUL and MULH (or MULHSU) instructions (putting MULH or MULHSU before MUL)?
That's just a recommendation that makes it easier for a microarchitecture to identify whether instruction execution can be optimized (e.g. computing simultaneously both the high and low parts of the result), but the result must be the same regardless of order.
from ripes.
According to section 7.1 of "The RISC-V Instruction Set Manual Volume I: Unprivileged ISA" Document version 20191213, "If both the high and low bits of the same product are required, then the recommended code sequence is: MULH[[S]U] rdh, rs1, rs2; MUL rdl, rs1, rs2 (source register specifiers must be in same order and rdh cannot be the same as rs1 or rs2)." Have you tried swapping the MUL and MULH (or MULHSU) instructions (putting MULH or MULHSU before MUL)?
from ripes.
Also, in one of your comments you state "# (-10)^6 = -1.000.000 = 0xFFF0 BDC0". Shouldn't (-10)^6 be positive?
from ripes.
According to section 7.1 of "The RISC-V Instruction Set Manual Volume I: Unprivileged ISA" Document version 20191213, "If both the high and low bits of the same product are required, then the recommended code sequence is: MULH[[S]U] rdh, rs1, rs2; MUL rdl, rs1, rs2 (source register specifiers must be in same order and rdh cannot be the same as rs1 or rs2)." Have you tried swapping the MUL and MULH (or MULHSU) instructions (putting MULH or MULHSU before MUL)?
Swapping the instructions seems to have no effect. I get the same behaviour as before.
Also, in one of your comments you state "# (-10)^6 = -1.000.000 = 0xFFF0 BDC0". Shouldn't (-10)^6 be positive?
Yes, almost every appearance of (-10)^6
should actually be -(10^6)
, that's my bad. However the program itself does generate 10^6 and -10^6 correctly, it is only the comments.
from ripes.
Your code is modifiying itself. The tests store their results starting at address 0x68 (104), which is where the first instruction of test 3 is located, so the instructions of test 3 are completely overwritten by tests 1 and 2. That's why you are seeing "Unknown instruction". Removing some instructions makes the program shorter and therefore the test 3 instructions aren't overwritten any more.
Yep, you're right, such a silly mistake. Thanks so much!
from ripes.
Related Issues (20)
- Ripes crashes when hovering over the cache statistics chart HOT 1
- Ripes crashes when using 'Open' Syscall HOT 2
- Error reporting when running on centos7 HOT 2
- Missing virtual destructors in abstract classes
- Discussion on Github Actions HOT 1
- Add Cache Replacement Policy HOT 1
- Setting a register as the first instruction sometimes causes a runtime error in the single-cycle processors
- Using CLI without UI
- Use `magic_enum` to replace various enum<-> name maps and better-enums HOT 1
- M-extension issue (multiplication exceeds 64-bits)
- Division by zero crash in assembler constant expressions
- Adding options for branch strategies and branch delay HOT 1
- "Clock the circuit with the selected frequency" (F6) never stops HOT 5
- How to handle System Input in CLI? HOT 3
- Assembly source code execution highlight only works with default .text start address HOT 2
- Input Type always set to `Assembly` on startup
- Adding an option to change the direction of memory address growth
- .gitignore does not match files generated at configuration/compile time (?)
- unreachable code for REMU in rv_alu.h
- Unable to open Ripes v2.2.6 on mac
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ripes.