Remove ref passing, but keep devirtualizations
This commit is contained in:
+12
-2
@@ -34,13 +34,22 @@ internal static class Intrinsics
|
||||
return m;
|
||||
}
|
||||
|
||||
[Pure]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private static Vector256<float> ClearLastN(Vector256<float> data, int len)
|
||||
{
|
||||
var threshold = Vector256.Create<int>(len);
|
||||
var index = Vector256.Create(0, 1, 2, 3, 4, 5, 6, 7);
|
||||
return Avx.And(Avx2.CompareGreaterThan(threshold, index).AsSingle(), data);
|
||||
}
|
||||
|
||||
[Pure]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
// https://stackoverflow.com/a/23592221
|
||||
private static int HMaxIndexAVX2(Vector<float> v, int len)
|
||||
{
|
||||
// Remove NaNs
|
||||
var vfilt = Avx.Blend(v.AsVector256(), Vector256<float>.Zero, (byte)~((1 << len) - 1));
|
||||
var vfilt = ClearLastN(v.AsVector256(), len);
|
||||
|
||||
// Find max value and broadcast to all lanes
|
||||
var vmax128 = HMax(vfilt);
|
||||
@@ -50,7 +59,7 @@ internal static class Intrinsics
|
||||
var vcmp = Avx.CompareEqual(vfilt, vmax);
|
||||
var mask = unchecked((uint)Avx2.MoveMask(vcmp.AsByte()));
|
||||
|
||||
var inverseIdx = BitOperations.LeadingZeroCount(mask << (8 - len << 2)) >> 2;
|
||||
var inverseIdx = BitOperations.LeadingZeroCount(mask << ((8 - len) << 2)) >> 2;
|
||||
|
||||
return len - 1 - inverseIdx;
|
||||
}
|
||||
@@ -158,6 +167,7 @@ internal static class Intrinsics
|
||||
|
||||
[Pure]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
[SkipLocalsInit]
|
||||
public static Vector<float> ReciprocalSqrt(Vector<float> data)
|
||||
{
|
||||
if (Avx.IsSupported && Vector<float>.Count >= Vector256<float>.Count)
|
||||
|
||||
+4
-8
@@ -41,10 +41,7 @@ internal sealed class Simulator : SimulatorNoRandom
|
||||
private bool CouldUseAction(ActionType action, BaseAction baseAction, bool strict)
|
||||
#pragma warning restore MA0051 // Method is too long
|
||||
{
|
||||
var success = 0f;
|
||||
int cost = 0, eff = 0;
|
||||
baseAction.SuccessRate(this, ref success);
|
||||
if (Math.Abs(CalculateSuccessRate(success) - 1) > float.Epsilon)
|
||||
if (CalculateSuccessRate(baseAction.SuccessRate(this)) != 1)
|
||||
return false;
|
||||
|
||||
// don't allow quality moves at max quality
|
||||
@@ -55,7 +52,7 @@ internal sealed class Simulator : SimulatorNoRandom
|
||||
{
|
||||
// always use Trained Eye if it's available
|
||||
if (action == ActionType.TrainedEye)
|
||||
return baseAction.CouldUse(this, ref cost);
|
||||
return baseAction.CouldUse(this);
|
||||
|
||||
// don't allow quality moves under Muscle Memory for difficult crafts
|
||||
if (Input.Recipe.ClassJobLevel == 90 &&
|
||||
@@ -88,8 +85,7 @@ internal sealed class Simulator : SimulatorNoRandom
|
||||
|
||||
if (baseAction.IncreasesProgress)
|
||||
{
|
||||
baseAction.Efficiency(this, ref eff);
|
||||
var progressIncrease = CalculateProgressGain(eff);
|
||||
var progressIncrease = CalculateProgressGain(baseAction.Efficiency(this));
|
||||
var wouldFinish = Progress + progressIncrease >= Input.Recipe.MaxProgress;
|
||||
|
||||
if (wouldFinish)
|
||||
@@ -133,7 +129,7 @@ internal sealed class Simulator : SimulatorNoRandom
|
||||
return false;
|
||||
}
|
||||
|
||||
return baseAction.CouldUse(this, ref cost);
|
||||
return baseAction.CouldUse(this);
|
||||
}
|
||||
|
||||
// https://github.com/alostsock/crafty/blob/cffbd0cad8bab3cef9f52a3e3d5da4f5e3781842/crafty/src/craft_state.rs#L137
|
||||
|
||||
Reference in New Issue
Block a user