public DataTable(Byte[] inArray1, Byte[] inArray2, Byte[] outArray, int alignment) { int sizeOfinArray1 = inArray1.Length * Unsafe.SizeOf <Byte>(); int sizeOfinArray2 = inArray2.Length * Unsafe.SizeOf <Byte>(); int sizeOfoutArray = outArray.Length * Unsafe.SizeOf <Byte>(); if ((alignment != 16 && alignment != 8) || (alignment * 2) < sizeOfinArray1 || (alignment * 2) < sizeOfinArray2 || (alignment * 2) < sizeOfoutArray) { throw new ArgumentException("Invalid value of alignment"); } this.inArray1 = new byte[alignment * 2]; this.inArray2 = new byte[alignment * 2]; this.outArray = new byte[alignment * 2]; this.inHandle1 = GCHandle.Alloc(this.inArray1, GCHandleType.Pinned); this.inHandle2 = GCHandle.Alloc(this.inArray2, GCHandleType.Pinned); this.outHandle = GCHandle.Alloc(this.outArray, GCHandleType.Pinned); this.alignment = (ulong)alignment; Unsafe.CopyBlockUnaligned(ref Unsafe.AsRef <byte>(inArray1Ptr), ref Unsafe.As <Byte, byte>(ref inArray1[0]), (uint)sizeOfinArray1); Unsafe.CopyBlockUnaligned(ref Unsafe.AsRef <byte>(inArray2Ptr), ref Unsafe.As <Byte, byte>(ref inArray2[0]), (uint)sizeOfinArray2); }
public SimpleTernaryOpTest__BlendVariableDouble() { Succeeded = true; var random = new Random(); for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = (double)(random.NextDouble()); } Unsafe.CopyBlockUnaligned(ref Unsafe.As <Vector256 <Double>, byte>(ref _fld1), ref Unsafe.As <Double, byte>(ref _data1[0]), (uint)Unsafe.SizeOf <Vector256 <Double> >()); for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = (double)(random.NextDouble()); } Unsafe.CopyBlockUnaligned(ref Unsafe.As <Vector256 <Double>, byte>(ref _fld2), ref Unsafe.As <Double, byte>(ref _data2[0]), (uint)Unsafe.SizeOf <Vector256 <Double> >()); for (var i = 0; i < Op3ElementCount; i++) { _data3[i] = (double)(((i % 2) == 0) ? -0.0 : 1.0); } Unsafe.CopyBlockUnaligned(ref Unsafe.As <Vector256 <Double>, byte>(ref _fld3), ref Unsafe.As <Double, byte>(ref _data3[0]), (uint)Unsafe.SizeOf <Vector256 <Double> >()); for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = (double)(random.NextDouble()); } for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = (double)(random.NextDouble()); } for (var i = 0; i < Op3ElementCount; i++) { _data3[i] = (double)(((i % 2) == 0) ? -0.0 : 1.0); } _dataTable = new SimpleTernaryOpTest__DataTable <Double, Double, Double, Double>(_data1, _data2, _data3, new Double[RetElementCount], LargestVectorSize); }
public SimpleTernaryOpTest__BlendVariableByte() { Succeeded = true; var random = new Random(); for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = (byte)(random.Next(0, byte.MaxValue)); } Unsafe.CopyBlockUnaligned(ref Unsafe.As <Vector128 <Byte>, byte>(ref _fld1), ref Unsafe.As <Byte, byte>(ref _data1[0]), (uint)Unsafe.SizeOf <Vector128 <Byte> >()); for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = (byte)(random.Next(0, byte.MaxValue)); } Unsafe.CopyBlockUnaligned(ref Unsafe.As <Vector128 <Byte>, byte>(ref _fld2), ref Unsafe.As <Byte, byte>(ref _data2[0]), (uint)Unsafe.SizeOf <Vector128 <Byte> >()); for (var i = 0; i < Op3ElementCount; i++) { _data3[i] = (byte)(((i % 2) == 0) ? 128 : 1); } Unsafe.CopyBlockUnaligned(ref Unsafe.As <Vector128 <Byte>, byte>(ref _fld3), ref Unsafe.As <Byte, byte>(ref _data3[0]), (uint)Unsafe.SizeOf <Vector128 <Byte> >()); for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = (byte)(random.Next(0, byte.MaxValue)); } for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = (byte)(random.Next(0, byte.MaxValue)); } for (var i = 0; i < Op3ElementCount; i++) { _data3[i] = (byte)(((i % 2) == 0) ? 128 : 1); } _dataTable = new SimpleTernaryOpTest__DataTable <Byte, Byte, Byte, Byte>(_data1, _data2, _data3, new Byte[RetElementCount], LargestVectorSize); }
public SimpleTernaryOpTest__MultiplySubtractDouble() { Succeeded = true; var random = new Random(); for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetDouble(); } Unsafe.CopyBlockUnaligned(ref Unsafe.As <Vector256 <Double>, byte>(ref _fld1), ref Unsafe.As <Double, byte>(ref _data1[0]), (uint)Unsafe.SizeOf <Vector256 <Double> >()); for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = TestLibrary.Generator.GetDouble(); } Unsafe.CopyBlockUnaligned(ref Unsafe.As <Vector256 <Double>, byte>(ref _fld2), ref Unsafe.As <Double, byte>(ref _data2[0]), (uint)Unsafe.SizeOf <Vector256 <Double> >()); for (var i = 0; i < Op3ElementCount; i++) { _data3[i] = TestLibrary.Generator.GetDouble(); } Unsafe.CopyBlockUnaligned(ref Unsafe.As <Vector256 <Double>, byte>(ref _fld3), ref Unsafe.As <Double, byte>(ref _data3[0]), (uint)Unsafe.SizeOf <Vector256 <Double> >()); for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetDouble(); } for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = TestLibrary.Generator.GetDouble(); } for (var i = 0; i < Op3ElementCount; i++) { _data3[i] = TestLibrary.Generator.GetDouble(); } _dataTable = new SimpleTernaryOpTest__DataTable <Double, Double, Double, Double>(_data1, _data2, _data3, new Double[RetElementCount], LargestVectorSize); }
public static void memcpy(void *destination, void *source, UInt64 length) { Unsafe.CopyBlockUnaligned(destination, source, (uint)length); }
static SimpleUnaryOpTest__RoundToNearestIntegerSingle() { for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetSingle(); } Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector256<Single>, byte>(ref _clsVar1), ref Unsafe.As<Single, byte>(ref _data1[0]), (uint)Unsafe.SizeOf<Vector256<Single>>()); }
static VectorUnaryOpTest__SqrtUInt32() { for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetUInt32(); } Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector64<UInt32>, byte>(ref _clsVar1), ref Unsafe.As<UInt32, byte>(ref _data1[0]), (uint)Unsafe.SizeOf<Vector64<UInt32>>()); }
private void ValidateResult(void *firstOp, Int64 result, [CallerMemberName] string method = "") { Double[] inArray = new Double[Op1ElementCount]; Unsafe.CopyBlockUnaligned(ref Unsafe.As <Double, byte>(ref inArray[0]), ref Unsafe.AsRef <byte>(firstOp), (uint)Unsafe.SizeOf <Vector128 <Double> >()); ValidateResult(inArray, result, method); }
private void ValidateResult(Int16 data, void *result, [CallerMemberName] string method = "") { Int16[] outArray = new Int16[RetElementCount]; Unsafe.CopyBlockUnaligned(ref Unsafe.As <Int16, byte>(ref outArray[0]), ref Unsafe.AsRef <byte>(result), (uint)Unsafe.SizeOf <Vector64 <Int16> >()); ValidateResult(data, outArray, method); }
static ImmUnaryOpTest__ShiftRightLogical128BitLaneInt321() { for (var i = 0; i < Op1ElementCount; i++) { _data[i] = (int)8; } Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<Int32>, byte>(ref _clsVar), ref Unsafe.As<Int32, byte>(ref _data[0]), (uint)Unsafe.SizeOf<Vector128<Int32>>()); }
public static bool Update(ref XxHashState32 state, byte *input, int len) { #if DEBUG unchecked { #endif int index = 0; state.TotalLen += (uint)len; if (state.Memsize + len < 16) { var ptr = (byte *)Unsafe.AsPointer(ref state); // fixed (byte* ptr = state.Memory) { Unsafe.CopyBlockUnaligned(ptr + state.Memsize, (byte *)input, (uint)len); } //Array.Copy(input, 0, state.Memory, state.Memsize, len); state.Memsize += (uint)len; return(true); } if (state.Memsize > 0) { var ptr = (byte *)Unsafe.AsPointer(ref state); // fixed (byte* ptr = state.Memory) { Unsafe.CopyBlockUnaligned(ptr + state.Memsize, (byte *)input, (uint)(16 - state.Memsize)); } //Array.Copy(input, 0, state.Memory, state.Memsize, 16 - state.Memsize); // fixed (byte* ptr = state.Memory) { state.V1 = CalcSubHash(state.V1, ptr, index); index += 4; state.V2 = CalcSubHash(state.V2, ptr, index); index += 4; state.V3 = CalcSubHash(state.V3, ptr, index); index += 4; state.V4 = CalcSubHash(state.V4, ptr, index); //index += 4; } index = 0; state.Memsize = 0; } if (index <= len - 16) { int limit = len - 16; uint v1 = state.V1; uint v2 = state.V2; uint v3 = state.V3; uint v4 = state.V4; do { v1 = CalcSubHash(v1, input, index); index += 4; v2 = CalcSubHash(v2, input, index); index += 4; v3 = CalcSubHash(v3, input, index); index += 4; v4 = CalcSubHash(v4, input, index); index += 4; } while (index <= limit); state.V1 = v1; state.V2 = v2; state.V3 = v3; state.V4 = v4; } if (index < len) { var ptr = (byte *)Unsafe.AsPointer(ref state); // fixed (byte* ptr = state.Memory) { Unsafe.CopyBlockUnaligned(ptr + 0, (byte *)(input + index), (uint)(len - index)); } //Array.Copy(input, index, state.Memory, 0, len - index); state.Memsize = (uint)(len - index); } return(true); #if DEBUG } #endif }
static SimpleUnaryOpTest__Negate_Vector128_Int32() { for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetInt32(); } Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<Int32>, byte>(ref _clsVar1), ref Unsafe.As<Int32, byte>(ref _data1[0]), (uint)Unsafe.SizeOf<Vector128<Int32>>()); }
private void ValidateResult(void *result, [CallerMemberName] string method = "") { UInt32[] outArray = new UInt32[RetElementCount]; Unsafe.CopyBlockUnaligned(ref Unsafe.As <UInt32, byte>(ref outArray[0]), ref Unsafe.AsRef <byte>(result), (uint)Unsafe.SizeOf <Vector128 <UInt32> >()); ValidateResult(outArray, method); }
static ImmUnaryOpTest__ShiftRightLogicalNarrowingSaturateScalar_Vector64_UInt16_5() { for (var i = 0; i < Op1ElementCount; i++) { _data[i] = TestLibrary.Generator.GetUInt32(); } Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector64<UInt32>, byte>(ref _clsVar), ref Unsafe.As<UInt32, byte>(ref _data[0]), (uint)Unsafe.SizeOf<Vector64<UInt32>>()); }
static AesBinaryOpTest__EncryptLastByte() { Unsafe.CopyBlockUnaligned(ref Unsafe.As <Vector128 <Byte>, byte>(ref _clsVar1), ref Unsafe.As <Byte, byte>(ref _data1[0]), (uint)Unsafe.SizeOf <Vector128 <Byte> >()); Unsafe.CopyBlockUnaligned(ref Unsafe.As <Vector128 <Byte>, byte>(ref _clsVar2), ref Unsafe.As <Byte, byte>(ref _data2[0]), (uint)Unsafe.SizeOf <Vector128 <Byte> >()); }
static ImmUnaryOpTest__ShiftRightLogical_Vector64_SByte_1() { for (var i = 0; i < Op1ElementCount; i++) { _data[i] = TestLibrary.Generator.GetSByte(); } Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector64<SByte>, byte>(ref _clsVar), ref Unsafe.As<SByte, byte>(ref _data[0]), (uint)Unsafe.SizeOf<Vector64<SByte>>()); }
static AesUnaryOpTest__InverseMixColumnsByte() { Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<Byte>, byte>(ref _clsVar), ref Unsafe.As<Byte, byte>(ref _data[0]), (uint)Unsafe.SizeOf<Vector128<Byte>>()); }
public void InitUint32_UnsafeCopyBlockUnaligned() { Span<uint> state = stackalloc uint[8]; Unsafe.CopyBlockUnaligned(ref MemoryMarshal.GetReference(MemoryMarshal.AsBytes(state)), ref MemoryMarshal.GetReference(InitState), 32); }
static PclmulqdqOpTest__CarrylessMultiplyUInt6417() { Unsafe.CopyBlockUnaligned(ref Unsafe.As <Vector128 <UInt64>, byte>(ref _clsVar1), ref Unsafe.As <UInt64, byte>(ref _data1[0]), (uint)Unsafe.SizeOf <Vector128 <UInt64> >()); Unsafe.CopyBlockUnaligned(ref Unsafe.As <Vector128 <UInt64>, byte>(ref _clsVar2), ref Unsafe.As <UInt64, byte>(ref _data2[0]), (uint)Unsafe.SizeOf <Vector128 <UInt64> >()); }
public unsafe static void WriteUInt24LE(byte *buff, int offset, UInt32 value) { Unsafe.CopyBlockUnaligned(ref buff[offset], ref Unsafe.As <UInt32, byte>(ref value), 3); }
static SimpleUnaryOpConvTest__ConvertToVector128Int32WithTruncationVector128Double() { for (var i = 0; i < Op1ElementCount; i++) { _data[i] = TestLibrary.Generator.GetDouble(); } Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<Double>, byte>(ref _clsVar), ref Unsafe.As<Double, byte>(ref _data[0]), (uint)Unsafe.SizeOf<Vector128<Double>>()); }
public unsafe static int WriteBytes(byte *buff, int offset, byte[] input, UInt32 count) { Unsafe.CopyBlockUnaligned(ref buff[offset], ref input[0], count); return((int)count); }
public void InitUint64_UnsafeCopyBlockUnaligned() { Span<ulong> state = stackalloc ulong[8]; Unsafe.CopyBlockUnaligned(ref MemoryMarshal.GetReference(MemoryMarshal.AsBytes(state)), ref MemoryMarshal.GetReference(InitState2), 64); }
static ImmUnaryOpTest__DuplicateSelectedScalarToVector128_V64_Int32_1() { for (var i = 0; i < Op1ElementCount; i++) { _data[i] = TestLibrary.Generator.GetInt32(); } Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector64<Int32>, byte>(ref _clsVar), ref Unsafe.As<Int32, byte>(ref _data[0]), (uint)Unsafe.SizeOf<Vector64<Int32>>()); }