Skip to content
This repository has been archived by the owner on Jan 13, 2025. It is now read-only.

patmos-clang: cannot bundle two immediate adds in assembly #15

Closed
Emoun opened this issue Nov 3, 2018 · 2 comments
Closed

patmos-clang: cannot bundle two immediate adds in assembly #15

Emoun opened this issue Nov 3, 2018 · 2 comments

Comments

@Emoun
Copy link
Member

Emoun commented Nov 3, 2018

patmos-clang refuses to bundle two immediate adds, where the second add's immediate is a label.

Take the following assembly program (we'll call it main.s):

  .globl main
main:                             
  {  add $r4 = $r0, 0
     add $r4 = $r0, _1 }
_1:

Trying to compile this program using the command patmos-clang main.s results in the error:

main.s:4:6: error: the bundle consists of too many instructions
     add $r4 = $r0, _1 }

We can work around this error by changing the order of the adds:

  .globl main
main:                             
  {  add $r4 = $r0, _1
     add $r4 = $r0, 0 }
_1:

Looking at an objectdump of the resulting main.o we get:

main:
  ....
  52034:	80 08 07 50                   { li $r4 = 1872
  52038:	00 08 00 00                     clr $r4 }
  ....

Which is exactly the same as our code, since li and clr are the pseudo instructions equal to the adds. Running the code in pasim also executes successfully.
Therefore, we know that the compiler produces two 32-bit instructions. Their order should not matter, which means the original code should also compile.

The error could be caused by the compiler using a long immediate add if it sees the labeled add before the other add. Should this be the case, the compiler should be updated to use the short immediate format when possible, as it is in this case.

@schoeberl
Copy link
Member

Interesting corner case. Yes, a fix would be good.

@Emoun
Copy link
Member Author

Emoun commented Nov 14, 2018

As was discovered in t-crest/patmos#41, even though the compiler allows adding a label in the first slot, it will truncate the label's actuall address if the second slot is taken. Therefore, the compiler should just refuse to compile both cases:

 .globl main
main:                             
  {  add $r4 = $r0, 0
     add $r4 = $r0, _1 }
_1:

This should fail to compile because the second instruction needs to be a long immediate, and therefore in its own bundle.

  .globl main
main:                             
  {  add $r4 = $r0, _1
     add $r4 = $r0, 0 }
_1:

this should fail to compile because the first instruction is a long immediate, which needs its own bundle. Currently, this compiles with the wrong value for _1.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants