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
modeler returns "maximum code size exceeded" or "4712 expected between -4096 and 4095" if code size is increased #303
Comments
I briefly looked into the third error you described in your issue (i.e. Quickly adding some statistics I saw that an unmodified version of selfie hits a maximum (positive) immediate of I can try to look through Just as a side-note: What production compilers usually do is to rewrite a simple Rewrite this (
Into the following form (
|
@mstarzinger Thanks for looking into it. I went through my selfie.c and the biggest if-statement is the one of I looked at the assembler code of selfie with I am not familiar with modeler, but is it possible to better debug at which Also: How does the offset scale? I thought the biggest offset is the one from the first Thanks for your help! |
After refactoring So I went through all while-loops searching for the largest one (looking in selfie.c and modeler.c). After moving two parts of around 30 lines each out of the loop, Note: I copied everything outside the loop passing needed parameters, so the logic remains the same. Which leaves me with the question: Why is modeler.c failing for me, but not in the original selfie with the larger while? |
@mhatzl Nice, thanks for digging further into this. Good to know which while-loop is the culprit (and the fact that it is a while-loop instead of an if-statement). Regarding your last question: Some of the changes in your version of selfie are likely increasing the amount of code (i.e. number of RISC-V instructions) that are emitted for certain expressions/statements that appear within this loop's body. This increases the distance that |
@mstarzinger Thanks for your explanation. Do you want to dig further into this issue to find out what expression/statement is the problem? (I can not make my repository public, but I think I am allowed to give you access if you want to) Otherwise, I will keep my adaptation of |
@mhatzl I have in the meantime also refactored the while-loop in question in modeler.c a bit. I checked that it reduces the maximum (positive) My proposed change is here: https://github.com/mstarzinger/selfie/tree/refactor-modeler-control-flow |
@mstarzinger I have tested your implementation and Thanks again. |
This just refactors the handling of in-edges in modelers control flow chaining into separate methods. It is intended to make the while-loop iterating over all program locations smaller, because its size exceeded one of the limits built into selfie under certain circumstances. No functional changes intended. See issue cksystemsteaching#303 for more details. Kudos to @mhatzl for spotting and debugging this.
Some changes introduced after commit b4df450b02c1bef1cf03af46be8505aae2791dfc can not handle if selfie.c reaches a certain code size and increasing
MAX_CODE_SIZE
leads to "maximum data size exceeded" and after increasingMAX_DATA_SIZE
, modeler returns with4712 expected between -4096 and 4095
where 4172 can change depending on the number of statements inside an if.The first probblems with code/data size can be fixed by increasing the constants, but I am having trouble fixing this
expected between
error.I have tracked down the problem to
fixup_relative_BFormat
wherecode_size - from_address
is the number that is out of range. With this information I was able to reproduce all 3 errors by adding someprint("mhatzl");
and if-statements inside the main method.Note: My code was compiling and succeeded everything (except
make os
, but that got solved) executed withmake all
with the latest merged commit being b4df450b02c1bef1cf03af46be8505aae2791dfc.After merging 0d4e30fca8315363e2c8627c80de83cd17e7238c, I can run everything of
make all
exceptmake mod
which returns the above mentioned errors. (Note: All compiler assignments are still passing)With the below mentioned lines added to
main()
after `exit_code = selfie(0), I was able to reproduce all 3 errors with the current base selfie.c. So the error is not part of my code.Output for code size exceeded:
Setting
MAX_CODE_SIZE = 524288;
Setting
MAX_DATA_SIZE = 65536;
AND uncommenting the commentedprint("mhatzl");
of the lines belowLines below to reproduce the behavior.
Note: Uncomment the commented prints() for the last error.
The text was updated successfully, but these errors were encountered: