Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

using Internal.TypeSystem;

using Debug = System.Diagnostics.Debug;

namespace ILCompiler
{
public partial class CompilerTypeSystemContext
Expand All @@ -25,6 +27,11 @@ public partial class CompilerTypeSystemContext
/// </summary>
public void CacheV128Type(TypeDesc type)
{
// All v128 types share the same wasm ABI (16-byte aligned), so any one round-trips the
// 'V' encoding identically; a smaller alignment would change raised signatures silently.
Debug.Assert(type is DefType defType && defType.InstanceFieldAlignment.AsInt == 16,
$"v128 type {type} must be 16-byte aligned to be interchangeable in raised signatures");

_cachedV128Type ??= type;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,10 @@ public override ComputedInstanceFieldLayout ComputeInstanceLayout(DefType type,
{
ByteCountUnaligned = layoutFromSimilarIntrinsicVector.ByteCountUnaligned,
ByteCountAlignment = layoutFromMetadata.ByteCountAlignment,
FieldAlignment = layoutFromMetadata.FieldAlignment,
// On wasm Vector<T> is passed as a v128 and must share its 16-byte alignment.
FieldAlignment = type.Context.Target.Architecture == TargetArchitecture.Wasm32
? layoutFromSimilarIntrinsicVector.FieldAlignment
: layoutFromMetadata.FieldAlignment,
FieldSize = layoutFromSimilarIntrinsicVector.FieldSize,
Offsets = layoutFromMetadata.Offsets,
LayoutAbiStable = true,
Expand Down
12 changes: 12 additions & 0 deletions src/coreclr/vm/methodtablebuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10700,6 +10700,18 @@ void MethodTableBuilder::CheckForSystemTypes()

return;
}

#ifdef TARGET_WASM
// System.Numerics.Vector<T> is a v128 value on wasm, so it needs the same 16-byte
// alignment as System.Runtime.Intrinsics.Vector128<T> above. Its metadata layout is
// already 16 bytes (two UInt64 fields), but those only give it 8-byte alignment,
// which disagrees with crossgen2 and the interpreter.
if ((strcmp(nameSpace, g_NumericsNS) == 0) && (strcmp(name, "Vector`1") == 0))
Comment thread
lewing marked this conversation as resolved.
Comment thread
lewing marked this conversation as resolved.
{
pClass->GetLayoutInfo()->SetAlignmentRequirement(16); // sizeof(v128)
return;
}
#endif // TARGET_WASM
}

if (g_pNullableClass != NULL)
Expand Down
Loading