Skip to content
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

[JSON] properly emit code for alternative function clause execute syntax #32

Open
ThinkOpenly opened this issue Jun 18, 2024 · 8 comments
Assignees
Labels
help wanted Extra attention is needed

Comments

@ThinkOpenly
Copy link
Owner

Most function clause execute stanzas use a syntax like:

function clause execute (ADDIW(imm, rs1, rd)) = {
  let result : xlenbits = sign_extend(imm) + X(rs1);
  X(rd) = sign_extend(result[31..0]);
  RETIRE_SUCCESS
}

Some use a different syntax:

function clause execute (C_ADDIW(imm, rsd)) =
  execute(ADDIW(sign_extend(imm), rsd, rsd))

This is an indirect reference to the prior function clause execute with some parameter manipulation.

It would be nice to substitute the actual code in place of the reference.

@harshagr70
Copy link

hey @ThinkOpenly i would like to work on this issue , please assign it to me !!

@ThinkOpenly
Copy link
Owner Author

@harshagr70 , you are welcome to investigate this, but this might not be an easy one. Ask lots of questions.

Interestingly, looking again at the example above, I think there is some unnecessary redundancy. The sign_extend function is called twice for the imm parameter, once before calling ADDIW and once within ADDIW. That's arguably a bug in the Sail source.

@harshagr70
Copy link

@ThinkOpenly , i am unable to find the function use , or the function discussed above in the /sail repository , please help me figure it out ! , correctly said there's probably a bug in the function's code as mentioned .

@ThinkOpenly
Copy link
Owner Author

i am unable to find the function use , or the function discussed above in the /sail repository

This project has a few related repositories, and I am probably careless in distinguishing among them:

The functions described in the opening comment for this issue can be found in the second repository:

@harshagr70
Copy link

@ThinkOpenly
I’ve submitted a pull request that addresses this issue by implementing the direct C_ADDIW clause and removing redundant operations. Please review it at your convenience.

@ThinkOpenly
Copy link
Owner Author

I’ve submitted a pull request that addresses this issue by implementing the direct C_ADDIW clause and removing redundant operations.

I commented in that PR, but copying some of that reply here for clarification as to the expectation for solving this issue...

The preferred solution would be to emit the (duplicated) code in the JSON produced by the Sail JSON backend, without changing the Sail code at all.

[Or,] it could be that the code emitted in JSON currently is just fine, and the burden of linking the indirect call to the actual code should be left to downstream users of the JSON, like that website referenced in #32 (comment)

@ThinkOpenly
Copy link
Owner Author

Interestingly, looking again at the example above, I think there is some unnecessary redundancy. The sign_extend function is called twice for the imm parameter, once before calling ADDIW and once within ADDIW. That's arguably a bug in the Sail source.

This has nothing to do with this issue, but since I brought it up here, I thought I should resolve it here.

I investigated this, and it seems this is a necessary evil:

  • C_ADDIW is given an immediate value of type bits(6)
  • ADDIW expects an immediate value of type bits(12)
  • The sign_extend() is used to sign-extend and promote the bits(6) value to a bits(12) value suitable for ADDIW

@harshagr70
Copy link

@ThinkOpenly got it !! , i will raise a pr once i fix the issue in the backend json , thanks for follow up @ThinkOpenly !!

@ThinkOpenly ThinkOpenly added the help wanted Extra attention is needed label Feb 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants