-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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] Add DynamicHelpers to riscv64 stubs #94735
Conversation
src/coreclr/vm/riscv64/stubs.cpp
Outdated
// add t5, a0, t4 | ||
*(DWORD*)p = 0x01d50f33; p += 4; | ||
// ld t5, 0(t5) | ||
*(DWORD*)p = 0x000f3f03; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should here also be p += 4
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
src/coreclr/vm/riscv64/stubs.cpp
Outdated
|
||
BEGIN_DYNAMIC_HELPER_EMIT(32); | ||
|
||
*(DWORD*)p = 0x00000297;// auipc t0, 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
stubs.cpp for riscv64 has ITypeInstr
, STypeInstr
and RTypeInstr
functions to encode instructions. I suppose usage this functions make code more readable and prevent complicated debugging.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
p += 4; | ||
*(DWORD*)p = 0x00028067;// jr t0 | ||
p += 4; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems padding nop
should also be here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
src/coreclr/vm/riscv64/stubs.cpp
Outdated
*(DWORD*)p = 0x000eae83 | ((dataOffset & 0xfff) << 20); | ||
p += 4; | ||
// add a0, a0, t4 | ||
*(DWORD*)p = 0x01d50533; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems p += 4
missed here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
src/coreclr/vm/riscv64/stubs.cpp
Outdated
|
||
// CALL HELPER: | ||
if(pBLECall != NULL) | ||
*(DWORD*)pBLECall |= ((UINT32)(p - pBLECall) << 8); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this sets offset to pBLECall (blt t4, t5, CALL HELPER). Please check the below how offset is splitted into instruction.
// B-immediate encodes a signed offset in multiples of 2 bytes
// 12 | 11 1 | 0
// inst[31]/sign | inst[7] | inst[30:25] | inst[11:8] | 0
+ Please add an assertion for offset.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see why you shift only once. It is because max value of p - pBLECall
under 5 bits (0-4). However, I think shift value should be 7
not 8
. And please add assertions (0th is 0 and max value is under 5 bits(0-4)) for value of p - pBLECall
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
src/coreclr/vm/riscv64/stubs.cpp
Outdated
int indirectionsDataSize = 0; | ||
if (pLookup->testForNull || pLookup->sizeOffset != CORINFO_NO_SIZE_CHECK) | ||
{ | ||
codeSize += 4; //mv t2, 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the below, you added mv t2, a0
instruction. Could you update this comment?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
src/coreclr/vm/riscv64/stubs.cpp
Outdated
else | ||
{ | ||
// beq a0, x0, CALL HELPER: | ||
*(DWORD*)p = 0x00050063; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is wrong. beq a0, x0, 8 (offset to CALL HELPER)
is 0x00050463
.
Please use ITypeInstr
, STypeInstr
and RTypeInstr
functions if possible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
src/coreclr/vm/riscv64/stubs.cpp
Outdated
|
||
if (pLookup->testForNull) | ||
{ | ||
codeSize += 12; // ori-beq-jalr |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please update comment to beq-ret-ori
like actual code generation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
src/coreclr/vm/riscv64/stubs.cpp
Outdated
if (pLookup->sizeOffset > 2047) | ||
{ | ||
// auipc t4, 0 | ||
*(DWORD*)p = 0x00000297; p += 4; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't it better to use the previous t4 which is set when indirectionsDataSize is over zero? You can remove many auipc instructions, simplify complex dataOffset calculation and handle indirectionsDataSize as boolean variable. (However, You need to rename t4 which is used for lui.) If it is impossible, please remove previous auipc t4, 0
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree. This will remove both auipc
instructions in for loop, and dataOffset
will be relative not to current instruction, but to the beginning of whole code block. Also, it would be good to add assert that dataOffset
relative to beginning of code block is <= 2047.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment with more details about this logic in #94766 (comment).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
src/coreclr/vm/riscv64/stubs.cpp
Outdated
if (pLookup->sizeOffset > 2047) | ||
{ | ||
// auipc t4, 0 | ||
*(DWORD*)p = 0x00000297; p += 4; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree. This will remove both auipc
instructions in for loop, and dataOffset
will be relative not to current instruction, but to the beginning of whole code block. Also, it would be good to add assert that dataOffset
relative to beginning of code block is <= 2047.
src/coreclr/vm/riscv64/stubs.cpp
Outdated
{ | ||
_ASSERTE(dataOffset < 2047); | ||
// auipc t4, 0 | ||
*(DWORD*)p = 0x00000297; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@shushanhf it seems that for loongarch you also either need to add pcaddi
for if(pLookup->offsets[i] > 2047)
case (because dataOffset
is relative to current instruction), or change dataOffset
to be relative to the beginning of whole code block.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The LA64 had done this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
runtime/src/coreclr/vm/loongarch64/stubs.cpp
Lines 1883 to 1891 in 18cac43
if(pLookup->offsets[i] > 2047) | |
{ | |
_ASSERTE(dataOffset < 2047); | |
// ld.wu $t4,$r21,0 | |
*(DWORD*)p = 0x2a8002b0 | (dataOffset<<10); | |
p += 4; | |
// ldx.d $a0,$a0,$t4 | |
*(DWORD*)p = 0x380c4084; | |
p += 4; |
I know what you said,
runtime/src/coreclr/vm/loongarch64/stubs.cpp
Lines 1854 to 1855 in 18cac43
// pcaddi $r21,0 | |
*(DWORD*)p = 0x18000015; p += 4; |
Here the r21
was overwritten.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gbalykov What should I do ? I push a new PR to fix this or update it within this PR ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you can do it in separate PR specific to loongarch
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks very much !
src/coreclr/vm/riscv64/stubs.cpp
Outdated
*(DWORD*)p = 0x00000297;// auipc t0, 0 | ||
p += 4; | ||
*(DWORD*)p = 0x0102b503;// ld a0, 16(t0) | ||
p += 4; | ||
*(DWORD*)p = 0x0182b283;// ld t0, 24(t0) | ||
p += 4; | ||
*(DWORD*)p = 0x00028067;// jr t0 | ||
p += 4; | ||
|
||
// label: | ||
// arg | ||
*(TADDR*)p = arg; | ||
p += 8; | ||
// target | ||
*(PCODE*)p = target; | ||
p += 8; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like exactly the same sequence as EmitHelperWithArg, please deduplicate.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
src/coreclr/vm/riscv64/stubs.cpp
Outdated
if (codeSize & 0x7) | ||
codeSize += 4; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (codeSize & 0x7) | |
codeSize += 4; | |
codeSize = ALIGN_UP(codeSize, 8); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
src/coreclr/vm/riscv64/stubs.cpp
Outdated
*(DWORD*)p = 0x000e8e93 | ((slotOffset & 0xfff) << 20); p += 4; | ||
dataOffset -= 8; | ||
// blt t4, t5, CALL HELPER | ||
pBLECall = p; // Offset filled later |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: shouldn't this var be named pBLTCall to match the instruction?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
src/coreclr/vm/riscv64/stubs.cpp
Outdated
BEGIN_DYNAMIC_HELPER_EMIT(32); | ||
|
||
*(DWORD*)p = 0x00000297;// auipc t0, 0 | ||
p += 4; | ||
*(DWORD*)p = 0x0102b503;// ld a0, 16(t0) | ||
p += 4; | ||
*(DWORD*)p = 0x0182b283;// ld t0, 24(t0) | ||
p += 4; | ||
*(DWORD*)p = 0x00028067;// jr t0 | ||
p += 4; | ||
|
||
// label: | ||
// arg | ||
*(TADDR*)p = arg; | ||
p += 8; | ||
// target | ||
*(PCODE*)p = target; | ||
p += 8; | ||
|
||
END_DYNAMIC_HELPER_EMIT(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BTW, rather than manually calculate proper sizing and offsets each time, it could be useful to employ the compiler to do it for you, e.g. something like:
struct Asm
{
DWORD instructions[4] = {
UTypeInstr(AUIPC, t0, 0),
ITypeInstr(LOAD, LD, a0, t0, offsetof(Asm, _arg)),
...
};
PCODE _arg = arg;
PCODE _target = target;
};
static_assert(offsetof(Asm, _arg) % sizeof(PCODE) == 0, "naturally align data constants");
BEGIN_DYNAMIC_HELPER_EMIT(sizeof(Asm));
*(Asm*)p = Asm{};
END_DYNAMIC_HELPER_EMIT();
It also has the marginal benefit of more optimal code generated for the emitter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I left the logic of the functions by analogy with other architectures.
src/coreclr/vm/riscv64/stubs.cpp
Outdated
indirectionsDataSize += (pLookup->sizeOffset > 2047 ? 4 : 0); | ||
} | ||
|
||
codeSize += (pLookup->offsets[i] > 2047 ? 16 : 4); // if( > 2047) (8 bytes) else 4 bytes for instructions. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment says 8 bytes, the code says 16.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
src/coreclr/vm/riscv64/stubs.cpp
Outdated
// ori a0,t2,0 | ||
*(DWORD*)p = 0x0003e513; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: I think the proper instruction for moving a register on RISC-V is addi.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's more than just a nit — on an OoO CPU using the proper addi rd,rs,0
instruction is virtually guaranteed to result in a register rename with no execution resources needed, while it would be likely many or most cores would not do the same for the ori
version (or xori ...,0
or andi ...,-1
or sll ...,0
etc).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
There are no PC-relative loads or stores in RISC-V at present. (Qualcomm
has a PC-relative load, but not store, in their controversial Zics proposal)
…On Thu, Nov 16, 2023 at 4:02 AM Tomasz Sowiński ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In src/coreclr/vm/riscv64/stubs.cpp
<#94735 (comment)>:
> + *(DWORD*)p = 0x00000297;// auipc t0, 0
+ p += 4;
+ *(DWORD*)p = 0x0102b503;// ld a0, 16(t0)
+ p += 4;
I think this could be optimized to ld a0, 8(pc); the offset changed 16->8
because if you remove the auipc, the nop below is also unnecessary.
—
Reply to this email directly, view it on GitHub
<#94735 (review)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAGPYYA6OSLXZZNUMG23YDLYETKOZAVCNFSM6AAAAAA7LPRTV2VHI2DSMVQWIX3LMV43YUDVNRWFEZLROVSXG5CSMV3GSZLXHMYTOMZSGIZTQNBRHA>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Yeah, that's why I deleted the comment as soon as I realized that:) Thanks. |
src/coreclr/vm/riscv64/stubs.cpp
Outdated
p += 4; | ||
*(DWORD*)p = 0x00050513 | ((offset & 0xfff)<<20);// addi a0,a0,offset | ||
*(DWORD*)p = ITypeInstr(INSTR_ADDI, FUNCT3_ADDI, REG_A0, REG_A0, ((offset & 0xfff)<<20));// addi a0, a0, offset |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<<20
is not needed here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
src/coreclr/vm/riscv64/stubs.cpp
Outdated
*(DWORD*)p = 0x01d50f33; p += 4; | ||
// ld t5, 0(t5) | ||
*(DWORD*)p = 0x000f3f03; | ||
*(DWORD*)p = ITypeInstr(INSTR_LW, FUNCT3_LW, REG_T4, REG_T4, (dataOffset << 20));// lw t4, dataOffset(t4) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<<20
is not needed here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
src/coreclr/vm/riscv64/stubs.cpp
Outdated
// ld t5, #(pLookup->sizeOffset)(a0) | ||
*(DWORD*)p = 0x00053f03 | ((UINT32)pLookup->sizeOffset << 20); p += 4; | ||
dataOffset -= 4; // subtract 4 as we have moved PC by 4 | ||
*(DWORD*)p = ITypeInstr(INSTR_LD, FUNCT3_LD, REG_T5, REG_A0, ((UINT32)pLookup->sizeOffset << 20));// ld t5, #(pLookup->sizeOffset)(a0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<<20
is not needed here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
src/coreclr/vm/riscv64/stubs.cpp
Outdated
dataOffset -= 8; | ||
*(DWORD*)p = UTypeInstr(INSTR_LUI, REG_T4, ((((UINT32)slotOffset & 0xfffff000) >> 12) << 12)); | ||
p += 4; | ||
*(DWORD*)p = ITypeInstr(INSTR_ADDI, FUNCT3_ADDI, REG_T4, REG_T4, ((slotOffset & 0xfff) << 20));// addi t4, REG_T4, (slotOffset&0xfff) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<<20
is not needed here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
src/coreclr/vm/riscv64/stubs.cpp
Outdated
// addi t4, t4, (slotOffset&0xfff) | ||
*(DWORD*)p = 0x000e8e93 | ((slotOffset & 0xfff) << 20); p += 4; | ||
dataOffset -= 8; | ||
*(DWORD*)p = UTypeInstr(INSTR_LUI, REG_T4, ((((UINT32)slotOffset & 0xfffff000) >> 12) << 12)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<<12
is not needed here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
src/coreclr/vm/riscv64/stubs.cpp
Outdated
} | ||
|
||
if(pLookup->offsets[i] > 2047) | ||
{ | ||
_ASSERTE(dataOffset < 2047); | ||
// auipc t4, 0 | ||
*(DWORD*)p = 0x00000297; | ||
*(DWORD*)p = ITypeInstr(INSTR_LW, FUNCT3_LW, REG_T4, REG_T4, ((dataOffset & 0xfff) << 20));// lw t4, dataOffset(t4) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<<20
is not needed here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
src/coreclr/vm/riscv64/stubs.cpp
Outdated
@@ -1823,19 +1872,18 @@ PCODE DynamicHelpers::CreateDictionaryLookupHelper(LoaderAllocator * pAllocator, | |||
indirectionsDataSize += (pLookup->sizeOffset > 2047 ? 4 : 0); | |||
} | |||
|
|||
codeSize += (pLookup->offsets[i] > 2047 ? 16 : 4); // if( > 2047) (8 bytes) else 4 bytes for instructions. | |||
codeSize += (pLookup->offsets[i] > 2047 ? 16 : 4); // if( > 2047) (16 bytes) else 4 bytes for instructions. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in if above size is wrong, it seems that it should be codeSize += (pLookup->sizeOffset > 2047 ? 24 : 16);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it seems this one is also wrong:
codeSize += (pLookup->offsets[i] > 2047 ? 12 : 4); // if( > 2047) (12 bytes) else 4 bytes for instructions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
src/coreclr/vm/riscv64/stubs.cpp
Outdated
} | ||
else | ||
{ | ||
// offset must be 8 byte aligned | ||
_ASSERTE((pLookup->offsets[i] & 0x7) == 0); | ||
// ld a0, #(pLookup->offsets[i])(a0) | ||
*(DWORD*)p = 0x00053503 | ((UINT32)pLookup->offsets[i] << 20); | ||
*(DWORD*)p = ITypeInstr(INSTR_LD, FUNCT3_LD, REG_A0, REG_A0, ((UINT32)pLookup->offsets[i] << 20));// ld a0, #(pLookup->offsets[i])(a0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<<20
is not needed here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
src/coreclr/vm/riscv64/stubs.cpp
Outdated
@@ -1507,14 +1515,78 @@ void StubLinkerCPU::EmitCallManagedMethod(MethodDesc *pMD, BOOL fTailCall) | |||
// | |||
// Allocation of dynamic helpers | |||
// | |||
enum Riscv64_registers | |||
{ | |||
REG_ZERO, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We usually use REG_R0
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, now this form of register writing is used const IntReg RegR0
src/coreclr/vm/riscv64/stubs.cpp
Outdated
FUNCT3_LD = 0x3, | ||
FUNCT3_LW = 0x2, | ||
FUNCT3_JALR = 0, | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you follow the existing style in stubs.cpp?
REG is declared like const IntReg RegSp = IntReg(2);
in vm/riscv64/cgencpu.h
instructions
and funct3
are handled in Emit*
functions. I think you need to update *TypeInstr
to Emit*
functions in this PR.
You can add registers, emit functions and BTypeInstr
.
Thank you!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Created BTypeInstr
to work with the instructions of this type. But the logic of Emit*
is unclear since it uses a call to ITypeInstr
or others functions. Therefore, I left the current logic of functions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay. Emit32
cannot handle instructions well for your cases.
@ashaurtaev @gbalykov Even if it doesn't make crossgen2 work fully, I think you made simple tests on your own and checked them on your local. Could you share how you tested this PR? |
@clamp03 there're no tests for this one separately, it can't be tested without crossgen2 (as far as I know). And crossgen2 itself is not yet functional. This one is just reviewed closely, and for the next PR we'll try to bring some tests. |
src/coreclr/vm/riscv64/stubs.cpp
Outdated
p += 4; | ||
// blt t4, t5, CALL HELPER | ||
pBLTCall = p; // Offset filled later | ||
*(DWORD*)p = BTypeInstr(0x63, 0x4, RegT4, RegT5, 0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is better to remove this and update the below emittion like this.
if(pBLTCall != NULL)
*(DWORD*)pBLTCall = BTypeInstr(0x63, 0x4, RegT4, RegT5, (UINT32)(p - pBLTCall)));
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed this line and updated the instructions below.
src/coreclr/vm/riscv64/stubs.cpp
Outdated
int immLo4 = (imm13 >> 1) & 0xf; | ||
int immHi6 = (imm13 >> 5) & 0x3f; | ||
int immHi1 = (imm13 >> 12) & 0x1; | ||
return opcode | (immLo4 << 7) | (funct3 << 12) | (rs1 << 15) | (rs2 << 20) | (immHi6 << 25) | (immLo1 << 7) | (immHi1 << 31); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update to immLo4 << 8
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed it. Thank you!
src/coreclr/vm/riscv64/stubs.cpp
Outdated
else | ||
{ | ||
// beq a0, x0, CALL HELPER: | ||
*(DWORD*)p = BTypeInstr(0x63, 0, RegA0, RegR0, 0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think imm value should not be 0. It is 8
? Please check again.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed it. Thank you!
src/coreclr/vm/riscv64/stubs.cpp
Outdated
|
||
if (pLookup->testForNull) | ||
{ | ||
codeSize += 12; // beq-ret-ori |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
codeSize += 12; // beq-ret-ori | |
codeSize += 12; // beq-ret-addi |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed it. Thank you!
c8dc3b3
to
7db6a3e
Compare
*(DWORD*)p = ITypeInstr(0x13, 0, RegT4, RegT4, slotOffset & 0xfff);// addi t4, t4, (slotOffset&0xfff) | ||
p += 4; | ||
// blt t4, t5, CALL HELPER | ||
pBLTCall = p; // Offset filled later |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
p += 4; should not be removed. Please add p += 4;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
7db6a3e
to
d114c47
Compare
src/coreclr/vm/riscv64/stubs.cpp
Outdated
@@ -1611,13 +1570,15 @@ void DynamicHelpers::EmitHelperWithArg(BYTE*& p, size_t rxOffset, LoaderAllocato | |||
{ | |||
STANDARD_VM_CONTRACT; | |||
|
|||
*(DWORD*)p = UTypeInstr(INSTR_AUIPC, REG_T0, 0);// auipc t0, 0 | |||
const IntReg RegR0 = 0, RegT0 = 5, RegA0 = 10, RegA1 = 11; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
RegA1 is not used here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed RegA1
@@ -1872,15 +1848,15 @@ PCODE DynamicHelpers::CreateDictionaryLookupHelper(LoaderAllocator * pAllocator, | |||
indirectionsDataSize += (pLookup->sizeOffset > 2047 ? 4 : 0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
codeSize += (pLookup->sizeOffset > 2047 ? 24 : 16);
above
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
src/coreclr/vm/riscv64/stubs.cpp
Outdated
@@ -1872,15 +1848,15 @@ PCODE DynamicHelpers::CreateDictionaryLookupHelper(LoaderAllocator * pAllocator, | |||
indirectionsDataSize += (pLookup->sizeOffset > 2047 ? 4 : 0); | |||
} | |||
|
|||
codeSize += (pLookup->offsets[i] > 2047 ? 16 : 4); // if( > 2047) (16 bytes) else 4 bytes for instructions. | |||
codeSize += (pLookup->offsets[i] > 2047 ? 24 : 16); // if( > 2047) (24 bytes) else 16 bytes for instructions. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
codeSize += (pLookup->offsets[i] > 2047 ? 12 : 4); // if( > 2047) (12 bytes) else 4 bytes for instructions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I got it, thank you!
d114c47
to
8ada2fd
Compare
src/coreclr/vm/riscv64/stubs.cpp
Outdated
codeSize += 12; // beq-ret-addi | ||
|
||
//padding for 8-byte align (required by EmitHelperWithArg) | ||
codeSize += ALIGN_UP(codeSize, 8); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update to codeSize = ALIGN_UP(codeSize, 8);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks
Added implementation of dynamic helpers to stubs for riscv64
Part of #84834
cc @wscho77 @HJLeee @clamp03 @JongHeonChoi @t-mustafin @gbalykov @yurai007 @sirntar @tomeksowi @Bajtazar @brucehoult