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] Add DynamicHelpers to riscv64 stubs #94735

Merged
merged 5 commits into from
Nov 22, 2023

Conversation

ashaurtaev
Copy link
Contributor

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

@ghost ghost added the community-contribution Indicates that the PR has been added by a community member label Nov 14, 2023
@clamp03 clamp03 added the arch-riscv Related to the RISC-V architecture label Nov 14, 2023
// add t5, a0, t4
*(DWORD*)p = 0x01d50f33; p += 4;
// ld t5, 0(t5)
*(DWORD*)p = 0x000f3f03;
Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done


BEGIN_DYNAMIC_HELPER_EMIT(32);

*(DWORD*)p = 0x00000297;// auipc t0, 0
Copy link
Contributor

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.

Copy link
Contributor Author

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;

Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

*(DWORD*)p = 0x000eae83 | ((dataOffset & 0xfff) << 20);
p += 4;
// add a0, a0, t4
*(DWORD*)p = 0x01d50533;
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done


// CALL HELPER:
if(pBLECall != NULL)
*(DWORD*)pBLECall |= ((UINT32)(p - pBLECall) << 8);
Copy link
Member

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.

Copy link
Member

@clamp03 clamp03 Nov 15, 2023

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

int indirectionsDataSize = 0;
if (pLookup->testForNull || pLookup->sizeOffset != CORINFO_NO_SIZE_CHECK)
{
codeSize += 4; //mv t2, 0
Copy link
Member

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

else
{
// beq a0, x0, CALL HELPER:
*(DWORD*)p = 0x00050063;
Copy link
Member

@clamp03 clamp03 Nov 15, 2023

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done


if (pLookup->testForNull)
{
codeSize += 12; // ori-beq-jalr
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

if (pLookup->sizeOffset > 2047)
{
// auipc t4, 0
*(DWORD*)p = 0x00000297; p += 4;
Copy link
Member

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.

Copy link
Member

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.

Copy link
Member

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).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

if (pLookup->sizeOffset > 2047)
{
// auipc t4, 0
*(DWORD*)p = 0x00000297; p += 4;
Copy link
Member

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.

{
_ASSERTE(dataOffset < 2047);
// auipc t4, 0
*(DWORD*)p = 0x00000297;
Copy link
Member

@gbalykov gbalykov Nov 15, 2023

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.

Copy link
Contributor

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.

Copy link
Contributor

@shushanhf shushanhf Nov 15, 2023

Choose a reason for hiding this comment

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

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,

// pcaddi $r21,0
*(DWORD*)p = 0x18000015; p += 4;

Here the r21 was overwritten.

Copy link
Contributor

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 ?

Copy link
Member

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks very much !

Comment on lines 1541 to 1556
*(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;
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Comment on lines 1837 to 1838
if (codeSize & 0x7)
codeSize += 4;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if (codeSize & 0x7)
codeSize += 4;
codeSize = ALIGN_UP(codeSize, 8);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

*(DWORD*)p = 0x000e8e93 | ((slotOffset & 0xfff) << 20); p += 4;
dataOffset -= 8;
// blt t4, t5, CALL HELPER
pBLECall = p; // Offset filled later
Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Comment on lines 1539 to 1558
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();
Copy link
Contributor

@tomeksowi tomeksowi Nov 15, 2023

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.

Copy link
Contributor Author

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.

indirectionsDataSize += (pLookup->sizeOffset > 2047 ? 4 : 0);
}

codeSize += (pLookup->offsets[i] > 2047 ? 16 : 4); // if( > 2047) (8 bytes) else 4 bytes for instructions.
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Comment on lines 1959 to 1960
// ori a0,t2,0
*(DWORD*)p = 0x0003e513;
Copy link
Contributor

@tomeksowi tomeksowi Nov 15, 2023

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.

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).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@brucehoult
Copy link

brucehoult commented Nov 16, 2023 via email

@shushanhf
Copy link
Contributor

@gbalykov
I have rewrite the dataOffset for LoongArch64, welcome to review #94766
By the way, maybe it's useful for RISCV64.

Thanks

@tomeksowi
Copy link
Contributor

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)

Yeah, that's why I deleted the comment as soon as I realized that:) Thanks.

@ashaurtaev ashaurtaev changed the title Add DynamicHelpers to riscv64 stubs [RISC-V] Add DynamicHelpers to riscv64 stubs Nov 17, 2023
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
Copy link
Member

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

*(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)
Copy link
Member

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

// 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)
Copy link
Member

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

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)
Copy link
Member

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

// 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));
Copy link
Member

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

}

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)
Copy link
Member

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@@ -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.
Copy link
Member

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);

Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

}
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)
Copy link
Member

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@@ -1507,14 +1515,78 @@ void StubLinkerCPU::EmitCallManagedMethod(MethodDesc *pMD, BOOL fTailCall)
//
// Allocation of dynamic helpers
//
enum Riscv64_registers
{
REG_ZERO,
Copy link
Member

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.

Copy link
Contributor Author

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

FUNCT3_LD = 0x3,
FUNCT3_LW = 0x2,
FUNCT3_JALR = 0,
};
Copy link
Member

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!

Copy link
Contributor Author

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.

Copy link
Member

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.

@clamp03
Copy link
Member

clamp03 commented Nov 19, 2023

@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?

@gbalykov
Copy link
Member

@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.

p += 4;
// blt t4, t5, CALL HELPER
pBLTCall = p; // Offset filled later
*(DWORD*)p = BTypeInstr(0x63, 0x4, RegT4, RegT5, 0);
Copy link
Member

@clamp03 clamp03 Nov 21, 2023

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)));

Copy link
Contributor Author

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.

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);
Copy link
Member

Choose a reason for hiding this comment

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

Update to immLo4 << 8.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed it. Thank you!

else
{
// beq a0, x0, CALL HELPER:
*(DWORD*)p = BTypeInstr(0x63, 0, RegA0, RegR0, 0);
Copy link
Member

@clamp03 clamp03 Nov 21, 2023

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.

Copy link
Contributor Author

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 Show resolved Hide resolved

if (pLookup->testForNull)
{
codeSize += 12; // beq-ret-ori
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
codeSize += 12; // beq-ret-ori
codeSize += 12; // beq-ret-addi

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed it. Thank you!

*(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
Copy link
Member

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;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@@ -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;
Copy link
Member

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

Copy link
Contributor Author

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);
Copy link
Member

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@@ -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.
Copy link
Member

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.

Copy link
Contributor Author

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!

codeSize += 12; // beq-ret-addi

//padding for 8-byte align (required by EmitHelperWithArg)
codeSize += ALIGN_UP(codeSize, 8);
Copy link
Member

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);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed it

@clamp03 clamp03 requested a review from jkotas November 22, 2023 10:22
src/coreclr/vm/riscv64/stubs.cpp Outdated Show resolved Hide resolved
src/coreclr/vm/riscv64/stubs.cpp Outdated Show resolved Hide resolved
src/coreclr/vm/riscv64/stubs.cpp Outdated Show resolved Hide resolved
Copy link
Member

@jkotas jkotas left a comment

Choose a reason for hiding this comment

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

Thanks

@jkotas jkotas merged commit 2096625 into dotnet:main Nov 22, 2023
6 of 16 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Dec 23, 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-VM-coreclr 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.

8 participants