Skip to content

Commit

Permalink
[RISC-V] Fix alignment for vector types (#99589)
Browse files Browse the repository at this point in the history
For vector256 and vector512, set possible max alignment value.

Reference
https://github.com/riscv-non-isa/riscv-elf-psabi-doc/blob/master/riscv-cc.adoc
  • Loading branch information
clamp03 authored Mar 15, 2024
1 parent 45641d9 commit 7c33626
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/coreclr/tools/Common/Compiler/VectorFieldLayoutAlgorithm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
11 changes: 11 additions & 0 deletions src/coreclr/vm/methodtablebuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 7c33626

Please sign in to comment.