-
Notifications
You must be signed in to change notification settings - Fork 73
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
pasim: Bundled pointer dereference followed by multiply doesn't correctly dereference #41
Comments
The mul operation has some latency (it does NOT stall the pipeline). How many is not even documented in the handbook :-( I assume that this mul latency is the reason why you are not getting the result. Add some more nops and it will be fine. Furthermore, please test this also against the emulator. That represents the real hardware. |
I have tried to add several hundred nops without a difference. Also, this error doesn't appear if the initial #include <stdio.h>
volatile int _1 = 1;
int init_func(){
int x;
asm volatile(
"add $r3 = $r0, _1\n"
"lwc $r5 = [$r3]\n"
"li $r4 = 2\n"
"mul $r4, $r5\n"
"nop\n"
"mfs %[x] = $s2\n"
:[x] "=r" (x)
:
:"$r3", "$r4", "$r5", "$r4", "$s2", "$s1"
);
return x;
}
// Should print "2" for correct execution
int main(){
printf("%d\n", init_func());
} I have tried to test the emulator |
debug_cleaned.txt is a cleaned version of the debug from |
The problem is not isolated to multiplies, but seems to be a problem with the load. Using an #include <stdio.h>
volatile int _1 = 1;
int init_func(){
int x;
asm volatile(
"add $r3 = $r0, _1\n"
"lwc $r5 = [$r3]\n"
"li $r4 = 2\n"
"add %[x] = $r4, $r5\n"
:[x] "=r" (x)
:
:"$r3", "$r4", "$r5"
);
return x;
}
// Should print "3" for correct execution
int main(){
printf("%d\n", init_func());
} The above code should print |
Cannot recreate the problem with automatic testing, i.e. creating a test in |
Hi,
did you check that the address of _1 actually matches the value of r3?
it seems that you use a normal add instruction to load the address of the label into the register. the instruction only has a short immediate field and may thus truncate the address. this might explain the problem: since you are loading from the wrong address you do not see the expected value in r5.
best,
Florian
…----- Original Message -----
[debug_cleaned.txt](https://github.com/t-crest/patmos/files/2568561/debug_cleaned.txt)
is a cleaned version of the debug from `pasim` for the `init_func`
function.
We can see that `_1` gets loaded into `r3` correctly (at cycle
24677), but the dereference into `r5` never happens.
--
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
#41 (comment)
|
@flopsi you are right. |
Will close this issue, as it is not an issue with patmos or the simulator. Will be fixed with t-crest/patmos-llvm#15. |
If we load a label into a register as part of a bundle, then dereference the register, followed by using a multiply on the resulting value, it does not execute correctly on
pasim
.Take this program (
main.c
):Looking in the inline assembly, we see that we start by loading the label
_1
intor3
. We then dereferencer3
intor5
, which meansr5 = 1
. We then loadr4 = 2
and multiplyr4
andr5
, which should result in the value 2 in the special registers2
(the lower half of themul
result).The code successfully compiles using
patmos-clang main.c
, but running it inpasim
(usingpasim a.out
) result in the program printing 0, where we would expect 2.This error is very specific. If we do any one of the following, the code will execute correctly in
pasim
:add
not be part of a bundle. Though, no matter which other instruction is part of the bundle, theadd
will not success.mul
. E.g. if we exchange themul
for anadd
the correct result will be printed.add
, or use a register, instead of a label.Looking at
pasim
debug prints, I suspect the problem lies in the stalling of the regular pipeline by the multiply pipeline, but I am not sure. I will investigate.The text was updated successfully, but these errors were encountered: