public void RunBasicScenario_UnsafeRead() { var result = Avx.Extract( Unsafe.Read <Vector256 <UInt32> >(_dataTable.inArrayPtr), 6 ); Unsafe.Write(_dataTable.outArrayPtr, result); ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); }
public void RunBasicScenario_Load() { var result = Avx.Extract( Avx.LoadVector256((UInt32 *)(_dataTable.inArrayPtr)), 6 ); Unsafe.Write(_dataTable.outArrayPtr, result); ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); }
public void RunClsVarScenario() { var result = Avx.Extract( _clsVar, 20 ); Unsafe.Write(_dataTable.outArrayPtr, result); ValidateResult(_clsVar, _dataTable.outArrayPtr); }
public void RunStructLclFldScenario() { TestLibrary.TestFramework.BeginScenario(nameof(RunStructLclFldScenario)); var test = TestStruct.Create(); var result = Avx.Extract(test._fld, 6); Unsafe.Write(_dataTable.outArrayPtr, result); ValidateResult(test._fld, _dataTable.outArrayPtr); }
public void RunClassLclFldScenario() { TestLibrary.TestFramework.BeginScenario(nameof(RunClassLclFldScenario)); var test = new ExtractScalarTest__ExtractUInt326(); var result = Avx.Extract(test._fld, 6); Unsafe.Write(_dataTable.outArrayPtr, result); ValidateResult(test._fld, _dataTable.outArrayPtr); }
public void RunLclVarScenario_LoadAligned() { TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_LoadAligned)); var firstOp = Avx.LoadAlignedVector256((UInt32 *)(_dataTable.inArrayPtr)); var result = Avx.Extract(firstOp, 6); Unsafe.Write(_dataTable.outArrayPtr, result); ValidateResult(firstOp, _dataTable.outArrayPtr); }
public void RunLclVarScenario_UnsafeRead() { TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_UnsafeRead)); var firstOp = Unsafe.Read <Vector256 <UInt32> >(_dataTable.inArrayPtr); var result = Avx.Extract(firstOp, 6); Unsafe.Write(_dataTable.outArrayPtr, result); ValidateResult(firstOp, _dataTable.outArrayPtr); }
public void RunClsVarScenario() { TestLibrary.TestFramework.BeginScenario(nameof(RunClsVarScenario)); var result = Avx.Extract( _clsVar, 52 ); Unsafe.Write(_dataTable.outArrayPtr, result); ValidateResult(_clsVar, _dataTable.outArrayPtr); }
public void RunBasicScenario_LoadAligned() { TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_LoadAligned)); var result = Avx.Extract( Avx.LoadAlignedVector256((Byte *)(_dataTable.inArrayPtr)), 52 ); Unsafe.Write(_dataTable.outArrayPtr, result); ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); }
public void RunBasicScenario_UnsafeRead() { TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_UnsafeRead)); var result = Avx.Extract( Unsafe.Read <Vector256 <Byte> >(_dataTable.inArrayPtr), 52 ); Unsafe.Write(_dataTable.outArrayPtr, result); ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr); }
public static Vector128 <float> GetFlewellingGrowthEffectiveAge(SiteConstants site, float timeStepInYears, Vector128 <float> treeHeight, out Vector128 <float> potentialHeightGrowth) { // for now, just a vector to scalar shim for caller convenience // TODO: SIMD implementation float growthEffectiveAge0 = WesternHemlock.GetFlewellingGrowthEffectiveAge(site, timeStepInYears, Avx.Extract(treeHeight, 0), out float potentialHeightGrowth0); float growthEffectiveAge1 = WesternHemlock.GetFlewellingGrowthEffectiveAge(site, timeStepInYears, Avx.Extract(treeHeight, 0), out float potentialHeightGrowth1); float growthEffectiveAge2 = WesternHemlock.GetFlewellingGrowthEffectiveAge(site, timeStepInYears, Avx.Extract(treeHeight, 0), out float potentialHeightGrowth2); float growthEffectiveAge3 = WesternHemlock.GetFlewellingGrowthEffectiveAge(site, timeStepInYears, Avx.Extract(treeHeight, 0), out float potentialHeightGrowth3); potentialHeightGrowth = Vector128.Create(potentialHeightGrowth0, potentialHeightGrowth1, potentialHeightGrowth2, potentialHeightGrowth3); Vector128 <float> growthEffectiveAge = Vector128.Create(growthEffectiveAge0, growthEffectiveAge1, growthEffectiveAge2, growthEffectiveAge3); return(growthEffectiveAge); }
public unsafe void Process(MutableByteImage currentPicture, MutableByteImage nextPicture) { float MaxFactor = 1; float[] attackAr = new float[] { Attack, Attack, Attack, Attack }; float[] decayAr = new float[] { Decay, Decay, Decay, Decay }; int length = nextPicture.Data.Length; float *MaxFactorPtr = &MaxFactor; fixed(float *AttackPtr = attackAr) fixed(float *DecayPtr = decayAr) fixed(byte *currentPicPtr = currentPicture.Data) fixed(byte *nextPicPtr = nextPicture.Data) { byte *currentPxPtr = currentPicPtr; byte *nextPxPtr = nextPicPtr; int remainingLength = length % 4; for (int i = 0; i < length; i += 4) { var currentColor = *nextPxPtr; var workingDataColor = *currentPxPtr; var currentColorPtr = nextPxPtr; var workingDataColorPtr = currentPxPtr; var cmpResult = Avx.ConvertToVector128Single( Sse2.CompareGreaterThan( Sse41.ConvertToVector128Int32(currentColorPtr), Sse41.ConvertToVector128Int32(workingDataColorPtr) )); var pixelFactor = Avx.Add( Avx.And(cmpResult, Avx.BroadcastScalarToVector128(AttackPtr)), Avx.AndNot(cmpResult, Avx.BroadcastScalarToVector128(DecayPtr)) ); var result = Avx.Add( Avx.Multiply( Avx.Subtract( Avx.BroadcastScalarToVector128(MaxFactorPtr), pixelFactor), Sse41.ConvertToVector128Single( Sse41.ConvertToVector128Int32(workingDataColorPtr)) ), Avx.Multiply( pixelFactor, Sse41.ConvertToVector128Single( Sse41.ConvertToVector128Int32(currentColorPtr)))); // TODO improve Store *currentPxPtr = (byte)Avx.Extract(result, 0); currentPxPtr++; *currentPxPtr = (byte)Avx.Extract(result, 1); currentPxPtr++; *currentPxPtr = (byte)Avx.Extract(result, 2); currentPxPtr++; *currentPxPtr = (byte)Avx.Extract(result, 3); currentPxPtr++; nextPxPtr += 4; } for (int i = 0; i < remainingLength; i++) { var currentColor = *nextPxPtr; var workingDataColor = *currentPxPtr; var newPixelFactor = workingDataColor < currentColor ? Attack : Decay; var newPixelValue = (byte)((currentColor * newPixelFactor) + (workingDataColor * (1 - newPixelFactor))); *currentPxPtr = newPixelValue; currentPxPtr++; nextPxPtr++; } } }