diff --git a/src/coreclr/tools/Common/Compiler/VectorFieldLayoutAlgorithm.cs b/src/coreclr/tools/Common/Compiler/VectorFieldLayoutAlgorithm.cs index 33d894f75893e8..bb0a5bc71a626c 100644 --- a/src/coreclr/tools/Common/Compiler/VectorFieldLayoutAlgorithm.cs +++ b/src/coreclr/tools/Common/Compiler/VectorFieldLayoutAlgorithm.cs @@ -52,12 +52,19 @@ public override ComputedInstanceFieldLayout ComputeInstanceLayout(DefType defTyp // to the same alignment as __m128, which is supported by the ABI. alignment = new LayoutInt(8); } - else if (defType.Context.Target.Architecture == TargetArchitecture.ARM64 || defType.Context.Target.Architecture == TargetArchitecture.RiscV64) + else if (defType.Context.Target.Architecture == TargetArchitecture.ARM64) { // The Procedure Call Standard for ARM 64-bit (with SVE support) defaults to // 16-byte alignment for __m256. alignment = new LayoutInt(16); } + else if (defType.Context.Target.Architecture == TargetArchitecture.RiscV64) + { + // TODO-RISCV64: Update alignment to proper value when we implement RISC-V intrinsic. + // RISC-V Vector Extenstion Intrinsic Document + // https://github.com/riscv-non-isa/riscv-elf-psabi-doc/blob/master/vector_type_infos.adoc + alignment = new LayoutInt(16); + } else { alignment = new LayoutInt(32); @@ -73,12 +80,19 @@ public override ComputedInstanceFieldLayout ComputeInstanceLayout(DefType defTyp // to the same alignment as __m128, which is supported by the ABI. alignment = new LayoutInt(8); } - else if (defType.Context.Target.Architecture == TargetArchitecture.ARM64 || defType.Context.Target.Architecture == TargetArchitecture.RiscV64) + else if (defType.Context.Target.Architecture == TargetArchitecture.ARM64) { // The Procedure Call Standard for ARM 64-bit (with SVE support) defaults to // 16-byte alignment for __m256. alignment = new LayoutInt(16); } + else if (defType.Context.Target.Architecture == TargetArchitecture.RiscV64) + { + // TODO-RISCV64: Update alignment to proper value when we implement RISC-V intrinsic. + // RISC-V Vector Extenstion Intrinsic Document + // https://github.com/riscv-non-isa/riscv-elf-psabi-doc/blob/master/vector_type_infos.adoc + alignment = new LayoutInt(16); + } else { alignment = new LayoutInt(64); diff --git a/src/coreclr/vm/methodtablebuilder.cpp b/src/coreclr/vm/methodtablebuilder.cpp index e65c7dce41b737..e52b0ced06aef0 100644 --- a/src/coreclr/vm/methodtablebuilder.cpp +++ b/src/coreclr/vm/methodtablebuilder.cpp @@ -10051,6 +10051,11 @@ void MethodTableBuilder::CheckForSystemTypes() // The Procedure Call Standard for ARM 64-bit (with SVE support) defaults to // 16-byte alignment for __m256. + pLayout->m_ManagedLargestAlignmentRequirementOfAllMembers = 16; + #elif defined(TARGET_RISCV64) + // TODO-RISCV64: Update alignment to proper value when we implement RISC-V intrinsic. + // RISC-V Vector Extenstion Intrinsic Document + // https://github.com/riscv-non-isa/riscv-elf-psabi-doc/blob/master/vector_type_infos.adoc pLayout->m_ManagedLargestAlignmentRequirementOfAllMembers = 16; #else pLayout->m_ManagedLargestAlignmentRequirementOfAllMembers = 32; // sizeof(__m256) @@ -10068,6 +10073,12 @@ void MethodTableBuilder::CheckForSystemTypes() // 16-byte alignment for __m256. pLayout->m_ManagedLargestAlignmentRequirementOfAllMembers = 16; + + #elif defined(TARGET_RISCV64) + // TODO-RISCV64: Update alignment to proper value when we implement RISC-V intrinsic. + // RISC-V Vector Extenstion Intrinsic Document + // https://github.com/riscv-non-isa/riscv-elf-psabi-doc/blob/master/vector_type_infos.adoc + pLayout->m_ManagedLargestAlignmentRequirementOfAllMembers = 16; #else pLayout->m_ManagedLargestAlignmentRequirementOfAllMembers = 64; // sizeof(__m512) #endif // TARGET_ARM elif TARGET_ARM64 diff --git a/src/libraries/System.Private.CoreLib/src/System/Runtime/Intrinsics/Vector256.cs b/src/libraries/System.Private.CoreLib/src/System/Runtime/Intrinsics/Vector256.cs index f2eae1dad34916..1347a082afab97 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Runtime/Intrinsics/Vector256.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Runtime/Intrinsics/Vector256.cs @@ -36,6 +36,9 @@ public static unsafe class Vector256 internal const int Alignment = 8; #elif TARGET_ARM64 internal const int Alignment = 16; +#elif TARGET_RISCV64 + // TODO-RISCV64: Update alignment to proper value when we implement RISC-V intrinsic. + internal const int Alignment = 16; #else internal const int Alignment = 32; #endif diff --git a/src/libraries/System.Private.CoreLib/src/System/Runtime/Intrinsics/Vector512.cs b/src/libraries/System.Private.CoreLib/src/System/Runtime/Intrinsics/Vector512.cs index d18e705c3b1314..edb84585a987de 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Runtime/Intrinsics/Vector512.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Runtime/Intrinsics/Vector512.cs @@ -36,6 +36,9 @@ public static unsafe class Vector512 internal const int Alignment = 8; #elif TARGET_ARM64 internal const int Alignment = 16; +#elif TARGET_RISCV64 + // TODO-RISCV64: Update alignment to proper value when we implement RISC-V intrinsic. + internal const int Alignment = 16; #else internal const int Alignment = 64; #endif