Skip to content

NativeAOT: Cover more opcodes in type preinitializer #112073

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

Merged
merged 11 commits into from
Feb 11, 2025
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 @@ -835,6 +835,8 @@ private Status TryScanMethod(MethodIL methodIL, Value[] parameters, Stack<Method
case ILOpcode.conv_u2:
case ILOpcode.conv_u4:
case ILOpcode.conv_u8:
case ILOpcode.conv_r4:
case ILOpcode.conv_r8:
{
StackEntry popped = stack.Pop();
if (popped.ValueKind.WithNormalizedNativeInt(context) == StackValueKind.Int32)
Expand Down Expand Up @@ -874,6 +876,12 @@ private Status TryScanMethod(MethodIL methodIL, Value[] parameters, Stack<Method
case ILOpcode.conv_u8:
stack.Push(StackValueKind.Int64, ValueTypeValue.FromInt64((uint)val));
break;
case ILOpcode.conv_r4:
stack.Push(StackValueKind.Float, ValueTypeValue.FromDouble((float)val));
break;
case ILOpcode.conv_r8:
stack.Push(StackValueKind.Float, ValueTypeValue.FromDouble((double)val));
break;
default:
return Status.Fail(methodIL.OwningMethod, opcode);
}
Expand Down Expand Up @@ -912,6 +920,12 @@ private Status TryScanMethod(MethodIL methodIL, Value[] parameters, Stack<Method
case ILOpcode.conv_u8:
stack.Push(StackValueKind.Int64, ValueTypeValue.FromInt64(val));
break;
case ILOpcode.conv_r4:
stack.Push(StackValueKind.Float, ValueTypeValue.FromDouble((float)val));
break;
case ILOpcode.conv_r8:
stack.Push(StackValueKind.Float, ValueTypeValue.FromDouble((double)val));
break;
default:
return Status.Fail(methodIL.OwningMethod, opcode);
}
Expand All @@ -921,9 +935,44 @@ private Status TryScanMethod(MethodIL methodIL, Value[] parameters, Stack<Method
double val = popped.Value.AsDouble();
switch (opcode)
{
case ILOpcode.conv_i:
stack.Push(StackValueKind.NativeInt,
context.Target.PointerSize == 8 ? ValueTypeValue.FromInt64((long)val) : ValueTypeValue.FromInt32((int)val));
break;
case ILOpcode.conv_u:
stack.Push(StackValueKind.NativeInt,
context.Target.PointerSize == 8 ? ValueTypeValue.FromInt64((long)(ulong)val) : ValueTypeValue.FromInt32((int)(uint)val));
break;
case ILOpcode.conv_i1:
stack.Push(StackValueKind.Int32, ValueTypeValue.FromInt32((sbyte)val));
break;
case ILOpcode.conv_i2:
stack.Push(StackValueKind.Int32, ValueTypeValue.FromInt32((short)val));
break;
case ILOpcode.conv_i4:
stack.Push(StackValueKind.Int32, ValueTypeValue.FromInt32((int)val));
break;
case ILOpcode.conv_i8:
stack.Push(StackValueKind.Int64, ValueTypeValue.FromInt64((long)val));
break;
case ILOpcode.conv_u1:
stack.Push(StackValueKind.Int32, ValueTypeValue.FromInt32((byte)val));
break;
case ILOpcode.conv_u2:
stack.Push(StackValueKind.Int32, ValueTypeValue.FromInt32((ushort)val));
break;
case ILOpcode.conv_u4:
stack.Push(StackValueKind.Int32, ValueTypeValue.FromInt32((int)(uint)val));
break;
case ILOpcode.conv_u8:
stack.Push(StackValueKind.Int64, ValueTypeValue.FromInt64((long)(ulong)val));
break;
case ILOpcode.conv_r4:
stack.Push(StackValueKind.Float, ValueTypeValue.FromDouble((float)val));
break;
case ILOpcode.conv_r8:
stack.Push(StackValueKind.Float, ValueTypeValue.FromDouble(val));
break;
default:
return Status.Fail(methodIL.OwningMethod, opcode);
}
Expand Down Expand Up @@ -1388,8 +1437,12 @@ private Status TryScanMethod(MethodIL methodIL, Value[] parameters, Stack<Method
case ILOpcode.neg:
{
StackEntry value = stack.Pop();
if (value.ValueKind == StackValueKind.Int32)
stack.Push(StackValueKind.Int32, ValueTypeValue.FromInt32(-value.Value.AsInt32()));
if (value.ValueKind.WithNormalizedNativeInt(context) == StackValueKind.Int32)
stack.Push(value.ValueKind, ValueTypeValue.FromInt32(-value.Value.AsInt32()));
else if (value.ValueKind.WithNormalizedNativeInt(context) == StackValueKind.Int64)
stack.Push(value.ValueKind, ValueTypeValue.FromInt64(-value.Value.AsInt64()));
else if (value.ValueKind == StackValueKind.Float)
stack.Push(value.ValueKind, ValueTypeValue.FromDouble(-value.Value.AsDouble()));
else
return Status.Fail(methodIL.OwningMethod, opcode);
}
Expand Down
Loading
Loading