Skip to content

Commit 6916150

Browse files
Remove further uses of dynamic from HardwareIntrinsic test code (#118449)
This will prevent any further conflict with NEON code and make it easier to enable SVE tests on NativeAOT later.
1 parent df500bd commit 6916150

File tree

1 file changed

+28
-29
lines changed
  • src/tests/JIT/HardwareIntrinsics/Arm/Shared

1 file changed

+28
-29
lines changed

src/tests/JIT/HardwareIntrinsics/Arm/Shared/Helpers.cs

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1224,11 +1224,10 @@ public static T ShiftRight<T>(T op1, ulong op2) where T : INumber<T>
12241224
return op1;
12251225
}
12261226

1227-
public static T SignExtend<T>(T n, int numBits, bool zeroExtend) where T : struct, IComparable, IConvertible
1227+
public static T SignExtend<T>(T n, int numBits, bool zeroExtend) where T : struct, IComparable, IConvertible, IBinaryInteger<T>
12281228
{
12291229
// Get the underlying integer value
1230-
dynamic value = n;
1231-
value = (long)value;
1230+
long value = long.CreateTruncating(n);
12321231

12331232
// Mask to extract the lowest numBits
12341233
long mask = (1L << numBits) - 1;
@@ -7613,15 +7612,15 @@ public static T Odd<T>(T even, T odd, int idx) where T : IBinaryInteger<T>
76137612

76147613
public static U ArithmeticShift<T, U>(T value, int count, bool rounding = false, bool saturate = false)
76157614
where T : IBinaryInteger<T>
7616-
where U : IBinaryInteger<U>
7615+
where U : IBinaryInteger<U>, IMinMaxValue<U>
76177616
{
7618-
dynamic v = value;
7619-
dynamic shifted;
7617+
long v = long.CreateChecked(value);
7618+
long shifted;
76207619
if (count > 0)
76217620
{
76227621
if (rounding)
76237622
{
7624-
dynamic bias = 1L << (count - 1);
7623+
long bias = 1L << (count - 1);
76257624
shifted = v >= 0 ? (v + bias) >> count
76267625
: (v - bias) >> count;
76277626
}
@@ -7641,21 +7640,21 @@ public static U ArithmeticShift<T, U>(T value, int count, bool rounding = false,
76417640

76427641
if (saturate)
76437642
{
7644-
dynamic min = typeof(U).GetField("MinValue", BindingFlags.Static | BindingFlags.Public).GetValue(null);
7645-
dynamic max = typeof(U).GetField("MaxValue", BindingFlags.Static | BindingFlags.Public).GetValue(null);
7643+
long min = long.CreateChecked(U.MinValue);
7644+
long max = long.CreateChecked(U.MaxValue);
76467645
if (shifted < min) shifted = min;
76477646
if (shifted > max) shifted = max;
76487647
}
76497648

7650-
return (U)shifted;
7649+
return U.CreateTruncating(shifted);
76517650
}
76527651

76537652
public static U LogicalShift<T, U>(T value, int count, bool rounding = false, bool saturate = false)
76547653
where T : IBinaryInteger<T>
7655-
where U : IBinaryInteger<U>
7654+
where U : IBinaryInteger<U>, IMinMaxValue<U>
76567655
{
7657-
ulong v = Convert.ToUInt64(value);
7658-
dynamic shifted;
7656+
ulong v = ulong.CreateTruncating(value);
7657+
ulong shifted;
76597658
if (count > 0)
76607659
{
76617660
if (rounding)
@@ -7680,107 +7679,107 @@ public static U LogicalShift<T, U>(T value, int count, bool rounding = false, bo
76807679

76817680
if (saturate)
76827681
{
7683-
dynamic max = typeof(U).GetField("MaxValue", BindingFlags.Static | BindingFlags.Public).GetValue(null);
7682+
ulong max = ulong.CreateTruncating(U.MaxValue);
76847683
if (shifted > max) shifted = max;
76857684
}
76867685

7687-
return (U)shifted;
7686+
return U.CreateTruncating(shifted);
76887687
}
76897688

76907689
public static U ShiftRightArithmeticNarrowingSaturateEven<T, U>(T op1, byte op2, int i)
76917690
where T : IBinaryInteger<T>
7692-
where U : IBinaryInteger<U>, new()
7691+
where U : IBinaryInteger<U>, IMinMaxValue<U>, new()
76937692
{
76947693
return Even<U>(ArithmeticShift<T, U>(op1, op2, saturate: true), i);
76957694
}
76967695

76977696
public static U ShiftRightArithmeticNarrowingSaturateOdd<T, U>(U op0, T op1, byte op2, int i)
76987697
where T : IBinaryInteger<T>
7699-
where U : IBinaryInteger<U>
7698+
where U : IBinaryInteger<U>, IMinMaxValue<U>
77007699
{
77017700
return Odd<U>(op0, ArithmeticShift<T, U>(op1, op2, saturate: true), i);
77027701
}
77037702

77047703
public static U ShiftRightArithmeticNarrowingSaturateUnsignedEven<T, U>(T op1, byte op2, int i)
77057704
where T : IBinaryInteger<T>
7706-
where U : IBinaryInteger<U>, new()
7705+
where U : IBinaryInteger<U>, IMinMaxValue<U>, new()
77077706
{
77087707
return ShiftRightArithmeticNarrowingSaturateEven<T, U>(op1, op2, i);
77097708
}
77107709

77117710
public static U ShiftRightArithmeticNarrowingSaturateUnsignedOdd<T, U>(U op0, T op1, byte op2, int i)
77127711
where T : IBinaryInteger<T>
7713-
where U : IBinaryInteger<U>
7712+
where U : IBinaryInteger<U>, IMinMaxValue<U>
77147713
{
77157714
return ShiftRightArithmeticNarrowingSaturateOdd<T, U>(op0, op1, op2, i);
77167715
}
77177716

77187717
public static U ShiftRightArithmeticRoundedNarrowingSaturateEven<T, U>(T val, byte shift, int i)
77197718
where T : IBinaryInteger<T>
7720-
where U : IBinaryInteger<U>, new()
7719+
where U : IBinaryInteger<U>, IMinMaxValue<U>, new()
77217720
{
77227721
return Even<U>(ArithmeticShift<T, U>(val, shift, rounding: true, saturate: true), i);
77237722
}
77247723

77257724
public static U ShiftRightArithmeticRoundedNarrowingSaturateOdd<T, U>(U even, T val, byte shift, int i)
77267725
where T : IBinaryInteger<T>
7727-
where U : IBinaryInteger<U>
7726+
where U : IBinaryInteger<U>, IMinMaxValue<U>
77287727
{
77297728
return Odd<U>(even, ArithmeticShift<T, U>(val, shift, rounding: true, saturate: true), i);
77307729
}
77317730

77327731
public static U ShiftRightArithmeticRoundedNarrowingSaturateUnsignedEven<T, U>(T val, byte shift, int i)
77337732
where T : IBinaryInteger<T>
7734-
where U : IBinaryInteger<U>, new()
7733+
where U : IBinaryInteger<U>, IMinMaxValue<U>, new()
77357734
{
77367735
return ShiftRightArithmeticRoundedNarrowingSaturateEven<T, U>(val, shift, i);
77377736
}
77387737

77397738
public static U ShiftRightArithmeticRoundedNarrowingSaturateUnsignedOdd<T, U>(U even, T val, byte shift, int i)
77407739
where T : IBinaryInteger<T>
7741-
where U : IBinaryInteger<U>, new()
7740+
where U : IBinaryInteger<U>, IMinMaxValue<U>, new()
77427741
{
77437742
return ShiftRightArithmeticRoundedNarrowingSaturateOdd<T, U>(even, val, shift, i);
77447743
}
77457744

77467745
public static U ShiftRightLogicalNarrowingEven<T, U>(T val, byte shift, int i)
77477746
where T : IBinaryInteger<T>
7748-
where U : IBinaryInteger<U>, new()
7747+
where U : IBinaryInteger<U>, IMinMaxValue<U>, new()
77497748
{
77507749
return Even<U>(LogicalShift<T, U>(val, shift), i);
77517750
}
77527751

77537752
public static U ShiftRightLogicalNarrowingOdd<T, U>(U even, T val, byte shift, int i)
77547753
where T : IBinaryInteger<T>
7755-
where U : IBinaryInteger<U>
7754+
where U : IBinaryInteger<U>, IMinMaxValue<U>
77567755
{
77577756
return Odd<U>(even, LogicalShift<T, U>(val, shift), i);
77587757
}
77597758

77607759
public static U ShiftRightLogicalRoundedNarrowingEven<T, U>(T val, byte shift, int i)
77617760
where T : IBinaryInteger<T>
7762-
where U : IBinaryInteger<U>, new()
7761+
where U : IBinaryInteger<U>, IMinMaxValue<U>, new()
77637762
{
77647763
return Even<U>(LogicalShift<T, U>(val, shift, rounding: true), i);
77657764
}
77667765

77677766
public static U ShiftRightLogicalRoundedNarrowingOdd<T, U>(U even, T val, byte shift, int i)
77687767
where T : IBinaryInteger<T>
7769-
where U : IBinaryInteger<U>
7768+
where U : IBinaryInteger<U>, IMinMaxValue<U>
77707769
{
77717770
return Odd<U>(even, LogicalShift<T, U>(val, shift, rounding: true), i);
77727771
}
77737772

77747773
public static U ShiftRightLogicalRoundedNarrowingSaturateEven<T, U>(T val, byte shift, int i)
77757774
where T : IBinaryInteger<T>
7776-
where U : IBinaryInteger<U>, new()
7775+
where U : IBinaryInteger<U>, IMinMaxValue<U>, new()
77777776
{
77787777
return Even<U>(LogicalShift<T, U>(val, shift, rounding: true, saturate: true), i);
77797778
}
77807779

77817780
public static U ShiftRightLogicalRoundedNarrowingSaturateOdd<T, U>(U even, T val, byte shift, int i)
77827781
where T : IBinaryInteger<T>
7783-
where U : IBinaryInteger<U>
7782+
where U : IBinaryInteger<U>, IMinMaxValue<U>
77847783
{
77857784
return Odd<U>(even, LogicalShift<T, U>(val, shift, rounding: true, saturate: true), i);
77867785
}

0 commit comments

Comments
 (0)