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 crossgen2 for riscv64 #95188

Merged
merged 3 commits into from
Jan 3, 2024

Conversation

ashaurtaev
Copy link
Contributor

@ghost ghost added the community-contribution Indicates that the PR has been added by a community member label Nov 23, 2023
@ashaurtaev
Copy link
Contributor Author

@clamp03 @gbalykov Currently, compilation of the r2r image and work with return 0 have been added. In other cases, a segfault occurs

@clamp03 clamp03 added the arch-riscv Related to the RISC-V architecture label Nov 23, 2023
@clamp03
Copy link
Member

clamp03 commented Nov 23, 2023

Please update casing from Riscv64 to RiscV64 in all names according to #73437 (comment)

@@ -96,6 +96,7 @@ public static TargetArchitecture GetTargetArchitecture(string token)
Architecture.Arm => TargetArchitecture.ARM,
Architecture.Arm64 => TargetArchitecture.ARM64,
Architecture.LoongArch64 => TargetArchitecture.LoongArch64,
(Architecture)9 => TargetArchitecture.Riscv64,
Copy link
Member

@clamp03 clamp03 Nov 23, 2023

Choose a reason for hiding this comment

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

I think Architecture.RiscV64 is supported from #90203.

Copy link
Member

Choose a reason for hiding this comment

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

We'll have to wait for new architecture to get to sdk and for this new sdk to be used in main branch build. Currently .net-8.0.1 sdk is used for main branch, so it'll take some time until .net9-preview1 sdk arrives (changes from #90203 are not present in .net8 branch). Maybe I'm wrong here, if so please correct me.

Copy link
Member

Choose a reason for hiding this comment

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

My mistake. Thank you!

{
// ori a4, r0, #index
int index = _containingImportSection.IndexFromBeginningOfArray;
instructionEncoder.EmitMOV(Register.X14, checked((ushort)index));
Copy link
Member

Choose a reason for hiding this comment

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

Why do you use X14? Isn't T0 (X5) correct?

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 (!relocsOnly)
{
// ori a4, r0, #index
Copy link
Member

@clamp03 clamp03 Nov 24, 2023

Choose a reason for hiding this comment

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

update ori to addi and update a4 to T0

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


case Kind.DelayLoadHelper:
case Kind.VirtualStubDispatch:
// T8 contains indirection cell
Copy link
Member

Choose a reason for hiding this comment

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

There is no T8 in RISCV. Please update to T5.

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


// then get the low 12 bits
pcInstr = *(pCode + 1);
imm += (long)(pcInstr & 0xFFFF);
Copy link
Member

@clamp03 clamp03 Nov 24, 2023

Choose a reason for hiding this comment

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

Update to 0xFFF with correct shifts for JALR.

Comment on lines 323 to 324
case RelocType.IMAGE_REL_BASED_RISCV64_PC:
case RelocType.IMAGE_REL_BASED_RISCV64_JALR:
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 IMAGE_REL_BASED_RISCV64_PC and IMAGE_REL_BASED_RISCV64_JALR has the same behavior in RISCV64. IMO, it is better to merge into one such as IMAGE_REL_BASED_RISCV64_AUIPC You need to update IMAGE_REL_RISCV64_PC and IMAGE_REL_RISCV64_JALR in runtime as well.

Debug.Assert((imm20 & 0x1) == 0); // the low two bits must be zero

uint auipcInstr = *pCode;
Debug.Assert(auipcInstr == 0x00000297); // must be auipc t0, 0
Copy link
Member

Choose a reason for hiding this comment

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

Why must it be auipc t0, 0?

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 incorrect comment

@@ -317,6 +317,10 @@ public SectionBuilder(TargetDetails target)
_codePadding = 0x002A0005u;
break;

case TargetArchitecture.Riscv64:
_codePadding = 0x002A0005u;
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 explain why it is 0x002A0005u? In other archs, it is break instruction. Please clarify.

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
{
//Builder.EmitReloc(symbol, RelocType.IMAGE_REL_BASED_RISCV64_PC);
Builder.EmitUInt(0xffffffff); // bad code.
Copy link
Member

Choose a reason for hiding this comment

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

0x00000000 is used for bad code.

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


public override int PointerSize => 8;
public override int NumArgumentRegisters => 8;
public override int NumCalleeSavedRegisters => 12;
Copy link
Member

Choose a reason for hiding this comment

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

Is NumCalleeSavedRegisters correct number? Please write the comments like other architectures.

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

uint auipcInstr = *pCode;

// first get the high 20 bits,
int imm = (int)(((auipcInstr >> 12) & 0xFFFFF) << 12);
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 it is okay like auipcInstr & 0xFFFFF000 (no shifts)

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


// then get the low 12 bits,
auipcInstr = *(pCode + 1);
imm += ((int)(((auipcInstr >> 20) & 0xFFF) << 20)) >> 20;
Copy link
Member

@clamp03 clamp03 Nov 24, 2023

Choose a reason for hiding this comment

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

I think ((int)(auipcInstr & 0xfff00000)) >> 20 is better.


int relOff = (int)imm32 & 0x800;
int imm = (int)imm32 + relOff;
relOff = ((imm & 0x7ff) - relOff) & 0xfff;
Copy link
Member

@clamp03 clamp03 Nov 24, 2023

Choose a reason for hiding this comment

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

Isn't it good to make codes similar to codes in jit/emitriscv64.cpp?

code = 0x00000017;
*(code_t*)dstRW = code | (code_t)reg1 << 7 | ((imm + 0x800) & 0xfffff000);
dstRW += 4;
#ifdef DEBUG
code = emitInsCode(INS_auipc);
assert(code == 0x00000017);
code = emitInsCode(INS_addi);
assert(code == 0x00000013);
#endif
ins = INS_addi;
*(code_t*)dstRW = 0x00000013 | ((code_t)reg1 << 7) | ((code_t)reg1 << 15) | ((doff & 0xfff) << 20);

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

@clamp03
Copy link
Member

clamp03 commented Nov 24, 2023

Please add commits not force-push when you fixed.

// ld a0, 16(t0)
EmitLD(Register.X10, Register.X5, 16);
// ld t0, 24(t0)
EmitLD(Register.X5, Register.X5, 24);
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 explain why 24? It seems like 0 to me.

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

// auipc t0, 0
EmitPC(Register.X5);
// ld a0, 16(t0)
EmitLD(Register.X10, Register.X5, 16);
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 EmitJMP jumps to symbol with relocation support. But, it is different. Could you explain why you generate these code?

uint offset = symbol.RepresentsIndirectionCell ? 7u : 2u;

// bne regSrc, x0, offset
Builder.EmitUInt((uint)(0x00001063 | ((uint)regSrc << 15) | (offset << 31)));
Copy link
Member

Choose a reason for hiding this comment

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

Offset is instructions to jump. So offset value in instructions should be 7 * 4(inst size) or 2 * 4. So shift for offset is not 31 at all. Maybe 9? Please check.

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

instructionEncoder.EmitPC(Register.X6);

// load Module* -> T1
instructionEncoder.EmitLD(Register.X6, Register.X6, 0x18);
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 it is wrong. Please update to correct offset.

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

instructionEncoder.EmitPC(Register.X11);

// load Module* -> a1
instructionEncoder.EmitLD(Register.X11, Register.X11, 0x18);
Copy link
Member

Choose a reason for hiding this comment

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

Here too.

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

// Verify that we got a valid offset
Debug.Assert((imm20 >= -0x80000) && (imm20 < 0x80000));

Debug.Assert((imm20 & 0x1) == 0); // the low two bits must be zero
Copy link
Contributor

Choose a reason for hiding this comment

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

You're checking only the lowest bit, which afaik is correct. Pls update 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

public void EmitMOV(Register regDst, ushort imm16)
{
Debug.Assert((uint)regDst <= 0x1f);
Debug.Assert(imm16 <= 0xfff);
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: so it's imm12.

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

Builder.EmitUInt(0x00100073);
}

public void EmitMOV(Register regDst, ushort imm16)
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: more like EmitLI (load immediate), mov means register move on RISC-V.

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 116 to 121
public void EmitRETIfEqual(Register regSrc)
{
// bne regSrc, x0, 8
Builder.EmitUInt((uint)(0x00001463 | ((uint)regSrc << 15)));
EmitRET();
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: "equal" suggests comparing with sth else. Maybe rename to EmitRETIfZero?

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

// We need to trigger the cctor before returning the base. It is stored at the beginning of the non-GC statics region.
encoder.EmitADD(encoder.TargetRegister.Arg3, encoder.TargetRegister.Arg0, -NonGCStaticsNode.GetClassConstructorContextSize(factory.Target));
encoder.EmitLD(encoder.TargetRegister.Arg2, encoder.TargetRegister.Arg3, 0);
encoder.EmitXOR(encoder.TargetRegister.IntraProcedureCallScratch1, encoder.TargetRegister.Arg2, 0);
Copy link
Contributor

Choose a reason for hiding this comment

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

This is an oddly phrased register move (because x ^ 0 == x). Did you mean x ^ 1 like in the rest?

(if you really meant a reg move, 1. it should be addi, 2. IMO it can be elided, the branch below could work on the source register)

Comment on lines 490 to 493
auipcInstr = *(pCode + 1);

// Assemble the pc-relative low 12 bits of 'imm20' into the addi
auipcInstr |= (uint)(relOff << 20);
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: it's no longer an auipc. Pls call it e.g. addiInstr and assert it really is an addi.


encoder.EmitADD(encoder.TargetRegister.Arg2, encoder.TargetRegister.Arg2, -NonGCStaticsNode.GetClassConstructorContextSize(factory.Target));
encoder.EmitLD(encoder.TargetRegister.Arg3, encoder.TargetRegister.Arg2, factory.Target.PointerSize);
encoder.EmitXOR(encoder.TargetRegister.IntraProcedureCallScratch1, encoder.TargetRegister.Arg3, 1);
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you explain why are you flipping the lowest bit here?

// load Module* -> T1
instructionEncoder.EmitLD(Register.X6, Register.X6, 0x18);

// ld_d X6, X6, 0
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
// ld_d X6, X6, 0
// ld X6, X6, 0

{
public enum Registers
{
R0,
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's adhere to naming in RISC-V ABI.

Suggested change
R0,
Zero,

Debug.Assert((cbArg % _transitionBlock.PointerSize) == 0);

int regSlots = ALIGN_UP(cbArg, _transitionBlock.PointerSize) / _transitionBlock.PointerSize;
// Only R4-R11 are valid argument registers.
Copy link
Contributor

Choose a reason for hiding this comment

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

More like x10-x17 on RISC-V

Comment on lines 8 to 40
X0 = 0,
X1 = 1,
X2 = 2,
X3 = 3,
X4 = 4,
X5 = 5,
X6 = 6,
X7 = 7,
X8 = 8,
X9 = 9,
X10 = 10,
X11 = 11,
X12 = 12,
X13 = 13,
X14 = 14,
X15 = 15,
X16 = 16,
X17 = 17,
X18 = 18,
X19 = 19,
X20 = 20,
X21 = 21,
X22 = 22,
X23 = 23,
X24 = 24,
X25 = 25,
X26 = 26,
X27 = 27,
X28 = 28,
X29 = 29,
X30 = 30,

X31 = 31,
Copy link
Member

Choose a reason for hiding this comment

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

Any reason for not to use RISC-V ABI registers, that are more readable?

Comment on lines 26 to 35
Arg0 = Register.X10;
Arg1 = Register.X11;
Arg2 = Register.X12;
Arg3 = Register.X13;
Arg4 = Register.X14;
Arg5 = Register.X15;
Arg6 = Register.X16;
Arg7 = Register.X17;
IntraProcedureCallScratch1 = Register.X28;
Result = Register.X10;
Copy link
Member

Choose a reason for hiding this comment

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

If your enum Register would be compatible with ABI, then here you wouldn't have less readable Register.Xn, but instead:

Arg0 = Register.A0;
Arg1 = Register.A1;
Arg2 = Register.A2;
Arg3 = Register.A3;
Arg4 = Register.A4;
Arg5 = Register.A5;
Arg6 = Register.A6;
Arg7 = Register.A7;
IntraProcedureCallScratch1 = Register.T3;
Result = Register.A0;

@gbalykov
Copy link
Member

gbalykov commented Dec 21, 2023

@sirntar @tomeksowi @clamp03

Please note that these are just initial changes required for crossgen2 and just simple functionality works (both r2r image generation and launch of image are successful with debug/release runtime):

  • console helloworld compiled in debug (build -c Debug)
  • parts of JIT CodeGenBringUp tests (160 out of 641)

In order to not extend this PR more, further work can be done in separate PRs (if you will see no issues in this code):

  • potentially rename Registers to ABI namings instead of default Xn ones (for now Registers is implemented in the same way as for other architectures for consistency)
  • there might be issues/NYI with release dlls, disabled W^X (DOTNET_EnableWriteXorExecute=0) or some other non-default configs
  • potentially remove IMAGE_REL_BASED_RISCV64_JALR from runtime (removed just from crossgen2 for now)
  • R2RDump porting to RISC-V (few R2RDump-related changes are removed from this PR)
  • increase amount of passed tests
  • etc.

@ashaurtaev
Copy link
Contributor Author

Thanks a lot for your reviews, they were very useful! @clamp03 @tomeksowi @sirntar


switch (fRelocType)
{
case IMAGE_REL_RISCV64_PC:
return RelocType.IMAGE_REL_BASED_RISCV64_PC;
case IMAGE_REL_RISCV64_JALR:
return RelocType.IMAGE_REL_BASED_RISCV64_JALR;
Copy link
Member

Choose a reason for hiding this comment

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

IMO, these code be updated or removed as well. Please check.

emitRecordRelocation(dst - 4, (BYTE*)addr, IMAGE_REL_RISCV64_JALR);

#define IMAGE_REL_RISCV64_JALR 0x0004

Copy link
Member

Choose a reason for hiding this comment

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

I missed the comment. Please update in the next PR. Thank you.

@@ -411,6 +412,47 @@ private static unsafe void PutLoongArch64JIR(uint* pCode, long imm38)
Debug.Assert(GetLoongArch64JIR(pCode) == imm38);
}

private static unsafe int GetRiscV64PC12(uint* pCode)
Copy link
Contributor

Choose a reason for hiding this comment

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

As I know, PC12 means pcaddu12i in LOONGARCH64. Please update the name to GetRiscV64AUIPC or GetRiscV64PC, Please remove 12 at least.

Suggested change
private static unsafe int GetRiscV64PC12(uint* pCode)
private static unsafe int GetRiscV64PC(uint* pCode)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, I’ll fix this

@@ -319,6 +319,9 @@ public void EmitReloc(ISymbolNode symbol, RelocType relocType, int delta = 0)

case RelocType.IMAGE_REL_BASED_LOONGARCH64_PC:
case RelocType.IMAGE_REL_BASED_LOONGARCH64_JIR:

//TODO: consider removal of IMAGE_REL_BASED_RISCV64_JIR from runtime too
Copy link
Contributor

Choose a reason for hiding this comment

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

Please update IMAGE_REL_BASED_RISCV64_JIR to IMAGE_REL_RISCV64_JALR.
In the runtime, IMAGE_REL_RISCV64_JALR is used.

// case:EA_PTR_DSP_RELOC
// auipc reg, off-hi-20bits
// ld reg, reg, off-lo-12bits
private static unsafe void PutRiscV64PC12(uint* pCode, long imm32)
Copy link
Contributor

Choose a reason for hiding this comment

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

Update the name too.

Suggested change
private static unsafe void PutRiscV64PC12(uint* pCode, long imm32)
private static unsafe void PutRiscV64PC(uint* pCode, long imm32)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, I’ll fix this

EmitRET();
}

public void EmitJE(Register regSrc, ISymbolNode symbol)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think EmitJNEZ is better.

Copy link
Member

Choose a reason for hiding this comment

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

It's actually the same as for other arches meaning that we jump over the stuff generated by emitjmp in case condition is reversed (in this case ne)

Copy link
Member

@clamp03 clamp03 Dec 22, 2023

Choose a reason for hiding this comment

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

I think EmitJE naming is for ARM* arch which use flag after cmp instruction. However, in RISC-V it doesn't compare and jump like ARM*. So I thought it is better if it shows RISC-V's code generation like what you changed EmitRetIfEqual to EmitRetIfZero.
I am confusing. I think EmitJEZ seems right.

This is just my suggestion. You can freely choose. :)

Copy link
Member

Choose a reason for hiding this comment

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

Ah, my bad, thought about the other thing, yes, you are right :) I meant that it's not EmitJNotfZero, but EmitJIfZero

Comment on lines 127 to 128
uint offset = symbol.RepresentsIndirectionCell ? 14u : 4u;
uint encodedOffset = ((offset & 0x1e) << 7) | ((offset & 0x7e0) << 20) | ((offset & 0x800) >> 4) | ((offset & 0x1000) << 19);
Copy link
Contributor

Choose a reason for hiding this comment

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

With your encodedOffset logic, offset should be 7 << 2 : 2 << 2. Please check again.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks!

}

public void EmitLI(Register regDst, ushort imm12)
{
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add assert for imm12.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, I’ll fix this

protected override void EmitCode(NodeFactory factory, ref RiscV64Emitter encoder, bool relocsOnly)
{
// addi a0, a0, sizeof(void*)
encoder.EmitADDI(encoder.TargetRegister.Arg0, encoder.TargetRegister.Arg0, factory.Target.PointerSize);
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: Update EmitADDI to EmitLI.

Copy link
Member

Choose a reason for hiding this comment

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

This is addition with a0, EmitLI does similar thing, but arg is x0

Copy link
Member

Choose a reason for hiding this comment

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

You are right! Thank you!

Comment on lines 2043 to 2045
private int _riscv64IdxGenReg; // Next general register to be assigned a value
private int _riscv64OfsStack; // Offset of next stack location to be assigned a value
private int _riscv64IdxFPReg; // Next FP register to be assigned a value
Copy link
Contributor

Choose a reason for hiding this comment

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

Adds more spaces for the comments like the others.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, I’ll fix this

// a0 .. a7
public override int NumArgumentRegisters => 8;
// fp=x8, ra=x1, s1-s11(R9,R18-R27), tp=x3, gp=x4
public override int NumCalleeSavedRegisters => 15;
Copy link
Contributor

Choose a reason for hiding this comment

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

In the comment, total fp, ra, s1-s11, tp and gp is 14. Could you check which is correct?

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 that both are 15, or am I missing smth? x1, x3, x4, x8, x9, x18, x19, x20, x21, x22, x23, x24, x25, x26, x27

Copy link
Member

Choose a reason for hiding this comment

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

You are right! Thank you!

// a0 .. a7
public override int NumArgumentRegisters => 8;
// fp=x8, ra=x1, s1-s11(R9,R18-R27), tp=x3, gp=x4
public override int NumCalleeSavedRegisters => 15;
Copy link
Contributor

Choose a reason for hiding this comment

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

In the comment, total fp, ra, s1-s11, tp and gp is 14. Could you check which is correct?

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 that both are 15, or am I missing smth? x1, x3, x4, x8, x9, x18, x19, x20, x21, x22, x23, x24, x25, x26, x27

Copy link
Member

Choose a reason for hiding this comment

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

You are right! Thank you!

Copy link
Member

@clamp03 clamp03 left a comment

Choose a reason for hiding this comment

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

LGTM Thanks for doing a great job with a difficult task!

Copy link
Contributor

@JongHeonChoi JongHeonChoi left a comment

Choose a reason for hiding this comment

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

I applaud your great PR.

@clamp03
Copy link
Member

clamp03 commented Dec 26, 2023

@dotnet/crossgen-contrib Can you please take a look at this pull request and provide feedback? Thank you.

Copy link
Member

@davidwrighton davidwrighton left a comment

Choose a reason for hiding this comment

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

I've looked through the changes and they look good to me. In a few weeks I expect that we will have the updated .NET 9 sdk in place. Would you like to merge this change now and then fix the various TODO's around the Machine and Architecture enums once the new SDK is in place? If so, please file an issue to do so. Once that issue is in place, I'm willing to merge this PR.

@davidwrighton
Copy link
Member

Also, we need a clean test results before I will merge, so please look into the failures/rerun stuff if necessary.

@@ -96,6 +96,7 @@ public static TargetArchitecture GetTargetArchitecture(string token)
Architecture.Arm => TargetArchitecture.ARM,
Architecture.Arm64 => TargetArchitecture.ARM64,
Architecture.LoongArch64 => TargetArchitecture.LoongArch64,
(Architecture)9 => TargetArchitecture.RiscV64, /* TODO: update with Architecture.RiscV64 */
Copy link
Member

Choose a reason for hiding this comment

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

Is there a tracking work item for this TODO? It would be for the best to keep hard coded numbers like this one for as short as possible.

@@ -6,7 +6,7 @@
<IsDotNetFrameworkProductAssembly>true</IsDotNetFrameworkProductAssembly>
<TargetFramework>$(NetCoreAppToolCurrent)</TargetFramework>
<DefineConstants>READYTORUN;$(DefineConstants)</DefineConstants>
<Platforms>x64;x86;arm;arm64</Platforms>
<Platforms>x64;x86;arm;arm64;</Platforms>
Copy link
Member

Choose a reason for hiding this comment

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

Why is this ';' added here? Did something change in MSBuild that requires lists to be finished with a semicolon?

@@ -154,6 +154,11 @@ internal GcInfoTypes(Machine machine)
STACK_BASE_REGISTER_ENCBASE = 2;
NUM_REGISTERS_ENCBASE = 3;
break;
case (Machine)0x5064: /* TODO: update with RiscV64 */
Copy link
Member

Choose a reason for hiding this comment

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

Same question as before. Do we have a tracking work item to change these hardcoded values to the respective enum values?

@gbalykov
Copy link
Member

gbalykov commented Jan 3, 2024

@davidwrighton @ivdiazsa I've created new issue for those todos #96438.

@davidwrighton It would be better to merge the change now and fix todos in separate PR. Can you please trigger rerun of CI? @ashaurtaev will get back from vacation only at the beginning of next week. So if CI passes after rerun, please merge this and we'll fix todos next week.

@MichalStrehovsky
Copy link
Member

The easiest way to rerun the CI is to close and reopen the PR.

@ivdiazsa
Copy link
Member

ivdiazsa commented Jan 3, 2024

@gbalykov Thanks for filing the tracking issue for the TODO's!

@davidwrighton davidwrighton merged commit 5a2d151 into dotnet:main Jan 3, 2024
152 checks passed
@gbalykov
Copy link
Member

gbalykov commented Jan 4, 2024

Thank you!

1 similar comment
@ashaurtaev
Copy link
Contributor Author

Thank you!

@ashaurtaev ashaurtaev deleted the add_crossgen2_riscv64 branch January 9, 2024 09:28
@github-actions github-actions bot locked and limited conversation to collaborators Feb 9, 2024
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-crossgen2-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.

None yet

10 participants