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

[RISC-V][JIT] Fix branch #86482

Merged
merged 7 commits into from
May 30, 2023
Merged

[RISC-V][JIT] Fix branch #86482

merged 7 commits into from
May 30, 2023

Conversation

clamp03
Copy link
Member

@clamp03 clamp03 commented May 19, 2023

@ghost ghost added the community-contribution Indicates that the PR has been added by a community member label May 19, 2023
@dotnet-issue-labeler dotnet-issue-labeler bot added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label May 19, 2023
@ghost
Copy link

ghost commented May 19, 2023

Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch
See info in area-owners.md if you want to be subscribed.

Issue Details

null

Author: clamp03
Assignees: -
Labels:

area-CodeGen-coreclr, community-contribution

Milestone: -

@alpencolt
Copy link

alpencolt commented May 20, 2023

@clamp03 I don't understand, jal is J-type instruction and has signed 20-bit immediate, branches are B-type and have signed 12-bit immediate, why have you changed to 21 and 13?

@clamp03
Copy link
Member Author

clamp03 commented May 22, 2023

@clamp03 I don't understand, jal is J-type instruction and has signed 20-bit immediate, branches are B-type and have signed 12-bit immediate, why have you changed to 21 and 13?

JAL has signed 20-bit offset size (offset[20:1]) and branches have signed 12-bits offset size (offset[12:1]) in instruction encoding.
However, those instructions do not have 0th bit. So actual immediate values is checked with signed 21-bits and signed 13-bits (0th bit ignored).

https://five-embeddev.com/riscv-isa-manual/latest/rv32.html#programmers-model-for-base-integer-isa
Unconditional Jumps
The jump and link (JAL) instruction uses the J-type format, where the J-immediate encodes a signed offset in multiples of 2 bytes. The offset is sign-extended and added to the address of the jump instruction to form the jump target address. Jumps can therefore target a ±1 MiB range. JAL stores the address of the instruction following the jump (pc+4) into register rd. The standard software calling convention uses x1 as the return address register and x5 as an alternate link register.

https://stackoverflow.com/questions/59150608/offset-address-for-jal-and-jalr-instrctions-in-risc-v

@alpencolt
Copy link

Hm, interesting, so formulas there isn't correct:
https://jemu.oscc.cc/JAL
https://msyksphinz-self.github.io/riscv-isadoc/html/rvi.html#jal

@clamp03 clamp03 marked this pull request as ready for review May 23, 2023 01:46
@clamp03
Copy link
Member Author

clamp03 commented May 23, 2023

@jakobbotsch Could you please review this patch? I fixed some errors related to branches.
Recently, I worked for RISC-V for months.Can I have an authorization to put arch-riscv label to PR or ISSUE?

@clamp03
Copy link
Member Author

clamp03 commented May 23, 2023

Hm, interesting, so formulas there isn't correct: https://jemu.oscc.cc/JAL https://msyksphinz-self.github.io/riscv-isadoc/html/rvi.html#jal

https://jemu.oscc.cc/JAL is wrong.
However, I think https://msyksphinz-self.github.io/riscv-isadoc/html/rvi.html#jal is right. In the encoding, you can find 0th bit is omitted. The offset value is made with [20:1] values in encoding like below. Bits of offset value is 21 (encoded 20 bits and not assigned 0th bit). I mean offset itself in encoding is 20 bits, however offset value range is 21 bits (0th is 0).

https://github.com/dotnet/runtime/blob/b066a16f3af015be3f457430aeddfd7f24514c0a/src/coreclr/jit/emitriscv64.cpp#L3171C15-L3172

@alpencolt
Copy link

In the encoding, you can find 0th bit is omitted.

Yep, it's copied from specification.

src/coreclr/jit/emitriscv64.cpp Show resolved Hide resolved
src/coreclr/jit/emitriscv64.cpp Show resolved Hide resolved
src/coreclr/jit/emitriscv64.h Show resolved Hide resolved
@clamp03 clamp03 added the arch-riscv Related to the RISC-V architecture label May 24, 2023
@jakobbotsch
Copy link
Member

@jakobbotsch Could you please review this patch? I fixed some errors related to branches. Recently, I worked for RISC-V for months.Can I have an authorization to put arch-riscv label to PR or ISSUE?

Thanks @clamp03. Since you have been contributing for many years now (on the ARM32 port too) we decided to grant you triaging rights so that you set the RISC-V work related area/architecture/OS labels.

@clamp03
Copy link
Member Author

clamp03 commented May 24, 2023

@jakobbotsch Could you please review this patch? I fixed some errors related to branches. Recently, I worked for RISC-V for months.Can I have an authorization to put arch-riscv label to PR or ISSUE?

Thanks @clamp03. Since you have been contributing for many years now (on the ARM32 port too) we decided to grant you triaging rights so that you set the RISC-V work related area/architecture/OS labels.

Thank you so much!

@clamp03 clamp03 marked this pull request as draft May 24, 2023 09:40
- Pass `./JIT/jit64/opt/cse/HugeField2/HugeField2.sh` test
Copy link

@alpencolt alpencolt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fixed the dest reg in jalr and checked the generated codes on ./JIT/jit64/opt/cse/HugeField2/HugeField2.sh test (It is a single test that converts jal to jalr).

I've checked it on debug build, but it still hang.
But any way this PR could be merged since it fix other tests which print messages infinetly to console:

JIT/jit64/opt/cse/staticFieldExprUnchecked1_d_loop_try/staticFieldExprUnchecked1_d_loop_try.sh
JIT/jit64/opt/cse/staticFieldExprUnchecked1_r_loop/staticFieldExprUnchecked1_r_loop.sh
JIT/jit64/opt/cse/staticFieldExprUnchecked1_r_loop_try/staticFieldExprUnchecked1_r_loop_try.sh

Copy link

@alpencolt alpencolt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fixed the dest reg in jalr and checked the generated codes on ./JIT/jit64/opt/cse/HugeField2/HugeField2.sh test (It is a single test that converts jal to jalr).

I've checked it on debug build, but it still hang.
But any way this PR could be merged since it fix other tests which print messages infinetly to console:

JIT/jit64/opt/cse/staticFieldExprUnchecked1_d_loop_try/staticFieldExprUnchecked1_d_loop_try.sh
JIT/jit64/opt/cse/staticFieldExprUnchecked1_r_loop/staticFieldExprUnchecked1_r_loop.sh
JIT/jit64/opt/cse/staticFieldExprUnchecked1_r_loop_try/staticFieldExprUnchecked1_r_loop_try.sh

@clamp03
Copy link
Member Author

clamp03 commented May 27, 2023

@alpencolt Thank you for the test. I tested HugeField2.sh on CHECKED build. It may have another issue in DEBUG build. We can handle HugeField2.sh's hang in the next PR.
Thank you.

@broudy3
Copy link
Contributor

broudy3 commented May 29, 2023

I've checked it on debug build, but it still hang.

@alpencolt please try the test JIT/jit64/opt/cse/HugeField2/HugeField2.sh with my small patch #86870. For me the test is then passing in DEBUG build.

@alpencolt
Copy link

I've checked it on debug build, but it still hang.

@alpencolt please try the test JIT/jit64/opt/cse/HugeField2/HugeField2.sh with my small patch #86870. For me the test is then passing in DEBUG build.

Hm, it still hangs for me

@broudy3
Copy link
Contributor

broudy3 commented May 29, 2023

Hm, it still hangs for me

Are you sure it hangs? Or does it take long time to run? On my test setup this test takes almost 13 minutes to run.

@alpencolt
Copy link

Ups, sorry, it's really long test. It's pass with #86482. Haven't checked without it but with #86870, but thank you for information.

@clamp03
Copy link
Member Author

clamp03 commented May 30, 2023

@jakobbotsch Could you review and merge? Thank you.

@jakobbotsch jakobbotsch merged commit 394d847 into dotnet:main May 30, 2023
@clamp03 clamp03 deleted the fixbranchoffset branch May 30, 2023 08:32
@ghost ghost locked as resolved and limited conversation to collaborators Jun 29, 2023
@clamp03 clamp03 self-assigned this Sep 7, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
arch-riscv Related to the RISC-V architecture area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI community-contribution Indicates that the PR has been added by a community member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants