Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit e5bf00a

Browse files
committedMar 21, 2018
Implement SetAllVector256
1 parent 545b309 commit e5bf00a

7 files changed

+424
-8
lines changed
 

‎src/jit/hwintrinsiccodegenxarch.cpp

+61
Original file line numberDiff line numberDiff line change
@@ -1311,6 +1311,67 @@ void CodeGen::genAvxOrAvx2Intrinsic(GenTreeHWIntrinsic* node)
13111311
break;
13121312
}
13131313

1314+
case NI_AVX_SetAllVector256:
1315+
{
1316+
assert(op1 != nullptr);
1317+
assert(op2 == nullptr);
1318+
op1Reg = op1->gtRegNum;
1319+
if (varTypeIsIntegral(baseType))
1320+
{
1321+
// If the argument is a integer, it needs to be moved into a XMM register
1322+
regNumber tmpXMM = node->ExtractTempReg();
1323+
emit->emitIns_R_R(INS_mov_i2xmm, emitActualTypeSize(baseType), tmpXMM, op1Reg);
1324+
op1Reg = tmpXMM;
1325+
}
1326+
1327+
if (compiler->compSupports(InstructionSet_AVX2))
1328+
{
1329+
// generate broadcast instructions if AVX2 is available
1330+
emit->emitIns_R_R(ins, emitTypeSize(TYP_SIMD32), targetReg, op1Reg);
1331+
}
1332+
else
1333+
{
1334+
// duplicate the scalar argument to XMM register
1335+
switch (baseType)
1336+
{
1337+
case TYP_FLOAT:
1338+
emit->emitIns_SIMD_R_R_I(INS_vpermilps, emitTypeSize(TYP_SIMD16), op1Reg, op1Reg, 0);
1339+
break;
1340+
case TYP_DOUBLE:
1341+
emit->emitIns_R_R(INS_movddup, emitTypeSize(TYP_SIMD16), op1Reg, op1Reg);
1342+
break;
1343+
case TYP_BYTE:
1344+
case TYP_UBYTE:
1345+
{
1346+
regNumber tmpZeroReg = node->GetSingleTempReg();
1347+
emit->emitIns_R_R(INS_pxor, emitTypeSize(TYP_SIMD16), tmpZeroReg, tmpZeroReg);
1348+
emit->emitIns_SIMD_R_R_R(INS_pshufb, emitTypeSize(TYP_SIMD16), op1Reg, op1Reg, tmpZeroReg);
1349+
break;
1350+
}
1351+
case TYP_SHORT:
1352+
case TYP_USHORT:
1353+
emit->emitIns_SIMD_R_R_I(INS_pshuflw, emitTypeSize(TYP_SIMD16), op1Reg, op1Reg, 0);
1354+
emit->emitIns_SIMD_R_R_I(INS_pshufd, emitTypeSize(TYP_SIMD16), op1Reg, op1Reg, 80);
1355+
break;
1356+
case TYP_INT:
1357+
case TYP_UINT:
1358+
emit->emitIns_SIMD_R_R_I(INS_pshufd, emitTypeSize(TYP_SIMD16), op1Reg, op1Reg, 0);
1359+
break;
1360+
case TYP_LONG:
1361+
case TYP_ULONG:
1362+
emit->emitIns_SIMD_R_R_I(INS_pshufd, emitTypeSize(TYP_SIMD16), op1Reg, op1Reg, 68);
1363+
break;
1364+
1365+
default:
1366+
unreached();
1367+
break;
1368+
}
1369+
// duplicate the XMM register to YMM register
1370+
emit->emitIns_SIMD_R_R_R_I(INS_vinsertf128, emitTypeSize(TYP_SIMD32), targetReg, op1Reg, op1Reg, 1);
1371+
}
1372+
break;
1373+
}
1374+
13141375
case NI_AVX_ExtendToVector256:
13151376
{
13161377
// ExtendToVector256 has zero-extend semantics in order to ensure it is deterministic

‎src/jit/hwintrinsiclistxarch.h

+3
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,7 @@ HARDWARE_INTRINSIC(AVX_Divide, "Divide",
347347
HARDWARE_INTRINSIC(AVX_DotProduct, "DotProduct", AVX, -1, 32, 3, {INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_dpps, INS_invalid}, HW_Category_IMM, HW_Flag_FullRangeIMM)
348348
HARDWARE_INTRINSIC(AVX_DuplicateEvenIndexed, "DuplicateEvenIndexed", AVX, -1, 32, 1, {INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_movsldup, INS_movddup}, HW_Category_SimpleSIMD, HW_Flag_NoRMWSemantics)
349349
HARDWARE_INTRINSIC(AVX_DuplicateOddIndexed, "DuplicateOddIndexed", AVX, -1, 32, 1, {INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_movshdup, INS_invalid}, HW_Category_SimpleSIMD, HW_Flag_NoRMWSemantics)
350+
HARDWARE_INTRINSIC(AVX_Extract, "Extract", AVX, -1, 32, 2, {INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_invalid}, HW_Category_IMM, HW_Flag_BaseTypeFromFirstArg|HW_Flag_FullRangeIMM|HW_Flag_NoCodeGen)
350351
HARDWARE_INTRINSIC(AVX_ExtendToVector256, "ExtendToVector256", AVX, -1, 32, 1, {INS_movdqa, INS_movdqa, INS_movdqa, INS_movdqa, INS_movdqa, INS_movdqa, INS_movdqa, INS_movdqa, INS_movaps, INS_movapd}, HW_Category_Helper, HW_Flag_OneTypeGeneric|HW_Flag_NoRMWSemantics)
351352
HARDWARE_INTRINSIC(AVX_ExtractVector128, "ExtractVector128", AVX, -1, 32, -1, {INS_vextractf128,INS_vextractf128,INS_vextractf128,INS_vextractf128,INS_vextractf128,INS_vextractf128,INS_vextractf128,INS_vextractf128,INS_vextractf128, INS_vextractf128},HW_Category_IMM, HW_Flag_OneTypeGeneric|HW_Flag_SpecialImport|HW_Flag_SpecialCodeGen|HW_Flag_FullRangeIMM)
352353
HARDWARE_INTRINSIC(AVX_Floor, "Floor", AVX, 9, 32, 1, {INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_roundps, INS_roundpd}, HW_Category_SimpleSIMD, HW_Flag_NoRMWSemantics)
@@ -370,6 +371,8 @@ HARDWARE_INTRINSIC(AVX_RoundToNearestInteger, "RoundToNea
370371
HARDWARE_INTRINSIC(AVX_RoundToNegativeInfinity, "RoundToNegativeInfinity", AVX, 9, 32, 1, {INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_roundps, INS_roundpd}, HW_Category_SimpleSIMD, HW_Flag_NoRMWSemantics)
371372
HARDWARE_INTRINSIC(AVX_RoundToPositiveInfinity, "RoundToPositiveInfinity", AVX, 10, 32, 1, {INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_roundps, INS_roundpd}, HW_Category_SimpleSIMD, HW_Flag_NoRMWSemantics)
372373
HARDWARE_INTRINSIC(AVX_RoundToZero, "RoundToZero", AVX, 11, 32, 1, {INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_roundps, INS_roundpd}, HW_Category_SimpleSIMD, HW_Flag_NoRMWSemantics)
374+
HARDWARE_INTRINSIC(AVX_SetVector256, "SetVector256", AVX, -1, 32, -1, {INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_invalid}, HW_Category_Helper, HW_Flag_NoCodeGen|HW_Flag_SecondArgMaybe64Bit)
375+
HARDWARE_INTRINSIC(AVX_SetAllVector256, "SetAllVector256", AVX, -1, 32, 1, {INS_vpbroadcastb,INS_vpbroadcastb,INS_vpbroadcastw,INS_vpbroadcastw,INS_vpbroadcastd,INS_vpbroadcastd,INS_vpbroadcastq,INS_vpbroadcastq,INS_vbroadcastss,INS_vbroadcastsd},HW_Category_Helper, HW_Flag_MultiIns|HW_Flag_SpecialImport|HW_Flag_OneTypeGeneric)
373376
HARDWARE_INTRINSIC(AVX_SetZeroVector256, "SetZeroVector256", AVX, -1, 32, 0, {INS_pxor, INS_pxor, INS_pxor, INS_pxor, INS_pxor, INS_pxor, INS_pxor, INS_pxor, INS_xorps, INS_xorpd}, HW_Category_Helper, HW_Flag_OneTypeGeneric|HW_Flag_NoRMWSemantics)
374377
HARDWARE_INTRINSIC(AVX_Shuffle, "Shuffle", AVX, -1, 32, 3, {INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_shufps, INS_shufpd}, HW_Category_IMM, HW_Flag_NoRMWSemantics|HW_Flag_FullRangeIMM)
375378
HARDWARE_INTRINSIC(AVX_Sqrt, "Sqrt", AVX, -1, 32, 1, {INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_sqrtps, INS_sqrtpd}, HW_Category_SimpleSIMD, HW_Flag_NoRMWSemantics)

‎src/jit/hwintrinsicxarch.cpp

+40-8
Original file line numberDiff line numberDiff line change
@@ -1058,6 +1058,25 @@ GenTree* Compiler::impSSE42Intrinsic(NamedIntrinsic intrinsic,
10581058
return retNode;
10591059
}
10601060

1061+
//------------------------------------------------------------------------
1062+
// gethalfAndNormalizedIndex: compute the middle index of a Vector256<baseType>
1063+
// and normalize the index to the specific range
1064+
//
1065+
// Arguments:
1066+
// indexPtr -- the pointer to the original index value
1067+
// baseType -- the base type of the Vector256<T>
1068+
//
1069+
// Return Value:
1070+
// the middle index of a Vector256<baseType> and normalized index
1071+
//
1072+
static int getMidAndNormalizedIndex(int* indexPtr, var_types baseType)
1073+
{
1074+
assert(varTypeIsArithmetic(baseType));
1075+
// clear the unused bits to normalize the index into the range of [0, length of Vector256<baseType>)
1076+
*indexPtr = (*indexPtr) & (32 / genTypeSize(baseType) - 1);
1077+
return (16 / genTypeSize(baseType));
1078+
}
1079+
10611080
GenTree* Compiler::impAvxOrAvx2Intrinsic(NamedIntrinsic intrinsic,
10621081
CORINFO_METHOD_HANDLE method,
10631082
CORINFO_SIG_INFO* sig,
@@ -1084,16 +1103,15 @@ GenTree* Compiler::impAvxOrAvx2Intrinsic(NamedIntrinsic intrinsic,
10841103
var_types retType = JITtype2varType(sig->retType);
10851104
assert(varTypeIsArithmetic(baseType));
10861105

1087-
ival = ival & (32 / genTypeSize(baseType) - 1); // clear the unused bits
1088-
int halfIndex = 16 / genTypeSize(baseType);
1106+
int midIndex = getMidAndNormalizedIndex(&ival, baseType);
10891107
NamedIntrinsic extractIntrinsic = varTypeIsShort(baseType) ? NI_SSE2_Extract : NI_SSE41_Extract;
10901108
GenTree* half = nullptr;
10911109

1092-
if (ival >= halfIndex)
1110+
if (ival >= midIndex)
10931111
{
10941112
half = gtNewSimdHWIntrinsicNode(TYP_SIMD16, vectorOp, gtNewIconNode(1), NI_AVX_ExtractVector128,
10951113
baseType, 32);
1096-
ival -= halfIndex;
1114+
ival -= midIndex;
10971115
}
10981116
else
10991117
{
@@ -1117,21 +1135,20 @@ GenTree* Compiler::impAvxOrAvx2Intrinsic(NamedIntrinsic intrinsic,
11171135
baseType = getBaseTypeOfSIMDType(sig->retTypeSigClass);
11181136
assert(varTypeIsArithmetic(baseType));
11191137

1120-
ival = ival & (32 / genTypeSize(baseType) - 1); // clear the unused bits
1121-
int halfIndex = 16 / genTypeSize(baseType);
1138+
int midIndex = getMidAndNormalizedIndex(&ival, baseType);
11221139
NamedIntrinsic insertIntrinsic = varTypeIsShort(baseType) ? NI_SSE2_Insert : NI_SSE41_Insert;
11231140

11241141
GenTree* clonedVectorOp;
11251142
vectorOp =
11261143
impCloneExpr(vectorOp, &clonedVectorOp, info.compCompHnd->getArgClass(sig, sig->args),
11271144
(unsigned)CHECK_SPILL_ALL, nullptr DEBUGARG("AVX Insert clones the vector operand"));
11281145

1129-
if (ival >= halfIndex)
1146+
if (ival >= midIndex)
11301147
{
11311148
GenTree* halfVector = gtNewSimdHWIntrinsicNode(TYP_SIMD16, vectorOp, gtNewIconNode(1),
11321149
NI_AVX_ExtractVector128, baseType, 32);
11331150
GenTree* ModifiedHalfVector =
1134-
gtNewSimdHWIntrinsicNode(TYP_SIMD16, halfVector, dataOp, gtNewIconNode(ival - halfIndex),
1151+
gtNewSimdHWIntrinsicNode(TYP_SIMD16, halfVector, dataOp, gtNewIconNode(ival - midIndex),
11351152
insertIntrinsic, baseType, 16);
11361153
retNode = gtNewSimdHWIntrinsicNode(TYP_SIMD32, clonedVectorOp, ModifiedHalfVector, gtNewIconNode(1),
11371154
NI_AVX_InsertVector128, baseType, 32);
@@ -1197,6 +1214,21 @@ GenTree* Compiler::impAvxOrAvx2Intrinsic(NamedIntrinsic intrinsic,
11971214
break;
11981215
}
11991216

1217+
case NI_AVX_SetAllVector256:
1218+
{
1219+
baseType = getBaseTypeOfSIMDType(sig->retTypeSigClass);
1220+
#ifdef _TARGET_X86_
1221+
// TODO-XARCH: support long/ulong on 32-bit platfroms
1222+
if (varTypeIsLong(baseType))
1223+
{
1224+
return impUnsupportedHWIntrinsic(CORINFO_HELP_THROW_PLATFORM_NOT_SUPPORTED, method, sig, mustExpand);
1225+
}
1226+
#endif
1227+
GenTree* arg = impPopStack().val;
1228+
retNode = gtNewSimdHWIntrinsicNode(TYP_SIMD32, arg, NI_AVX_SetAllVector256, baseType, 32);
1229+
break;
1230+
}
1231+
12001232
case NI_AVX_ExtractVector128:
12011233
case NI_AVX2_ExtractVector128:
12021234
{

‎src/jit/lsraxarch.cpp

+14
Original file line numberDiff line numberDiff line change
@@ -2368,6 +2368,20 @@ void LinearScan::BuildHWIntrinsic(GenTreeHWIntrinsic* intrinsicTree)
23682368
break;
23692369
}
23702370

2371+
case NI_AVX_SetAllVector256:
2372+
{
2373+
if (varTypeIsIntegral(baseType))
2374+
{
2375+
info->internalFloatCount = 1;
2376+
if (!compiler->compSupports(InstructionSet_AVX2) && varTypeIsByte(baseType))
2377+
{
2378+
info->internalFloatCount += 1;
2379+
}
2380+
info->setInternalCandidates(this, allSIMDRegs());
2381+
}
2382+
break;
2383+
}
2384+
23712385
case NI_SSE2_MaskMove:
23722386
{
23732387
// SSE2 MaskMove hardcodes the destination (op3) in DI/EDI/RDI
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,238 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
//
5+
6+
using System;
7+
using System.Runtime.CompilerServices;
8+
using System.Runtime.InteropServices;
9+
using System.Runtime.Intrinsics.X86;
10+
using System.Runtime.Intrinsics;
11+
12+
namespace IntelHardwareIntrinsicTest
13+
{
14+
class Program
15+
{
16+
const int Pass = 100;
17+
const int Fail = 0;
18+
19+
static unsafe int Main(string[] args)
20+
{
21+
int testResult = Pass;
22+
23+
if (Avx.IsSupported)
24+
{
25+
using (TestTable<float> floatTable = new TestTable<float>(new float[8] { float.NaN, float.NaN, float.NaN, float.NaN, float.NaN, float.NaN, float.NaN, float.NaN }))
26+
{
27+
var vf1 = Avx.SetAllVector256<float>(-5);
28+
Unsafe.Write(floatTable.outArrayPtr, vf1);
29+
30+
if (!floatTable.CheckResult((x) => (x == -5)))
31+
{
32+
Console.WriteLine("AVX SetAllVector256 failed on float:");
33+
foreach (var item in floatTable.outArray)
34+
{
35+
Console.Write(item + ", ");
36+
}
37+
Console.WriteLine();
38+
testResult = Fail;
39+
}
40+
}
41+
42+
using (TestTable<double> doubleTable = new TestTable<double>(new double[4] { double.NaN, double.NaN, double.NaN, double.NaN }))
43+
{
44+
var vf1 = Avx.SetAllVector256<double>(3);
45+
Unsafe.Write(doubleTable.outArrayPtr, vf1);
46+
47+
if (!doubleTable.CheckResult((x) => (x == 3)))
48+
{
49+
Console.WriteLine("AVX SetAllVector256 failed on double:");
50+
foreach (var item in doubleTable.outArray)
51+
{
52+
Console.Write(item + ", ");
53+
}
54+
Console.WriteLine();
55+
testResult = Fail;
56+
}
57+
}
58+
59+
using (TestTable<sbyte> sbyteTable = new TestTable<sbyte>(new sbyte[32] { sbyte.MaxValue, sbyte.MaxValue, sbyte.MaxValue, sbyte.MaxValue, sbyte.MaxValue, sbyte.MaxValue, sbyte.MaxValue, sbyte.MaxValue,
60+
sbyte.MaxValue, sbyte.MaxValue, sbyte.MaxValue, sbyte.MaxValue, sbyte.MaxValue, sbyte.MaxValue, sbyte.MaxValue, sbyte.MaxValue,
61+
sbyte.MaxValue, sbyte.MaxValue, sbyte.MaxValue, sbyte.MaxValue, sbyte.MaxValue, sbyte.MaxValue, sbyte.MaxValue, sbyte.MaxValue,
62+
sbyte.MaxValue, sbyte.MaxValue, sbyte.MaxValue, sbyte.MaxValue, sbyte.MaxValue, sbyte.MaxValue, sbyte.MaxValue, sbyte.MaxValue }))
63+
{
64+
var vf1 = Avx.SetAllVector256<sbyte>(100);
65+
Unsafe.Write(sbyteTable.outArrayPtr, vf1);
66+
67+
if (!sbyteTable.CheckResult((x) => (x == 100)))
68+
{
69+
Console.WriteLine("AVX SetAllVector256 failed on sbyte:");
70+
foreach (var item in sbyteTable.outArray)
71+
{
72+
Console.Write(item + ", ");
73+
}
74+
Console.WriteLine();
75+
testResult = Fail;
76+
}
77+
}
78+
79+
using (TestTable<byte> byteTable = new TestTable<byte>(new byte[32] { byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue,
80+
byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue,
81+
byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue,
82+
byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue }))
83+
{
84+
Vector256<byte> vf1 = Avx.SetAllVector256<byte>(4);
85+
Unsafe.Write(byteTable.outArrayPtr, vf1);
86+
87+
if (!byteTable.CheckResult((x) => (x == 4)))
88+
{
89+
Console.WriteLine("AVX SetAllVector256 failed on byte:");
90+
foreach (var item in byteTable.outArray)
91+
{
92+
Console.Write(item + ", ");
93+
}
94+
Console.WriteLine();
95+
testResult = Fail;
96+
}
97+
}
98+
99+
using (TestTable<short> shortTable = new TestTable<short>(new short[16] { short.MaxValue, short.MaxValue, short.MaxValue, short.MaxValue, short.MaxValue, short.MaxValue, short.MaxValue, short.MaxValue,
100+
short.MaxValue, short.MaxValue, short.MaxValue, short.MaxValue, short.MaxValue, short.MaxValue, short.MaxValue, short.MaxValue }))
101+
{
102+
var vf1 = Avx.SetAllVector256<short>(-5);
103+
Unsafe.Write(shortTable.outArrayPtr, vf1);
104+
105+
if (!shortTable.CheckResult((x) => (x == -5)))
106+
{
107+
Console.WriteLine("AVX SetAllVector256 failed on short:");
108+
foreach (var item in shortTable.outArray)
109+
{
110+
Console.Write(item + ", ");
111+
}
112+
Console.WriteLine();
113+
testResult = Fail;
114+
}
115+
}
116+
117+
using (TestTable<ushort> ushortTable = new TestTable<ushort>(new ushort[16] { ushort.MaxValue, ushort.MaxValue, ushort.MaxValue, ushort.MaxValue, ushort.MaxValue, ushort.MaxValue, ushort.MaxValue, ushort.MaxValue,
118+
ushort.MaxValue, ushort.MaxValue, ushort.MaxValue, ushort.MaxValue, ushort.MaxValue, ushort.MaxValue, ushort.MaxValue, ushort.MaxValue }))
119+
{
120+
Vector256<ushort> vf1 = Avx.SetAllVector256<ushort>(2);
121+
Unsafe.Write(ushortTable.outArrayPtr, vf1);
122+
123+
if (!ushortTable.CheckResult((x) => (x == 2)))
124+
{
125+
Console.WriteLine("AVX SetAllVector256 failed on ushort:");
126+
foreach (var item in ushortTable.outArray)
127+
{
128+
Console.Write(item + ", ");
129+
}
130+
Console.WriteLine();
131+
testResult = Fail;
132+
}
133+
}
134+
135+
using (TestTable<int> intTable = new TestTable<int>(new int[8] { int.MaxValue, int.MaxValue, int.MaxValue, int.MaxValue, int.MaxValue, int.MaxValue, int.MaxValue, int.MaxValue }))
136+
{
137+
var vf1 = Avx.SetAllVector256<int>(-5);
138+
Unsafe.Write(intTable.outArrayPtr, vf1);
139+
140+
if (!intTable.CheckResult((x) => (x == -5)))
141+
{
142+
Console.WriteLine("AVX SetAllVector256 failed on int:");
143+
foreach (var item in intTable.outArray)
144+
{
145+
Console.Write(item + ", ");
146+
}
147+
Console.WriteLine();
148+
testResult = Fail;
149+
}
150+
}
151+
152+
using (TestTable<uint> uintTable = new TestTable<uint>(new uint[8] { uint.MaxValue, uint.MaxValue, uint.MaxValue, uint.MaxValue, uint.MaxValue, uint.MaxValue, uint.MaxValue, uint.MaxValue }))
153+
{
154+
Vector256<uint> vf1 = Avx.SetAllVector256<uint>(3);
155+
Unsafe.Write(uintTable.outArrayPtr, vf1);
156+
157+
if (!uintTable.CheckResult((x) => (x == 3)))
158+
{
159+
Console.WriteLine("AVX SetAllVector256 failed on uint:");
160+
foreach (var item in uintTable.outArray)
161+
{
162+
Console.Write(item + ", ");
163+
}
164+
Console.WriteLine();
165+
testResult = Fail;
166+
}
167+
}
168+
169+
using (TestTable<long> longTable = new TestTable<long>(new long[4] { long.MaxValue, long.MaxValue, long.MaxValue, long.MaxValue }))
170+
{
171+
var vf1 = Avx.SetAllVector256<long>(-199);
172+
Unsafe.Write(longTable.outArrayPtr, vf1);
173+
174+
if (!longTable.CheckResult((x) => (x == -199)))
175+
{
176+
Console.WriteLine("AVX SetAllVector256 failed on long:");
177+
foreach (var item in longTable.outArray)
178+
{
179+
Console.Write(item + ", ");
180+
}
181+
Console.WriteLine();
182+
testResult = Fail;
183+
}
184+
}
185+
186+
using (TestTable<ulong> ulongTable = new TestTable<ulong>(new ulong[4] { ulong.MaxValue, ulong.MaxValue, ulong.MaxValue, ulong.MaxValue }))
187+
{
188+
Vector256<ulong> vf1 = Avx.SetAllVector256<ulong>(34);
189+
Unsafe.Write(ulongTable.outArrayPtr, vf1);
190+
191+
if (!ulongTable.CheckResult((x) => (x == 34)))
192+
{
193+
Console.WriteLine("AVX SetAllVector256 failed on ulong:");
194+
foreach (var item in ulongTable.outArray)
195+
{
196+
Console.Write(item + ", ");
197+
}
198+
Console.WriteLine();
199+
testResult = Fail;
200+
}
201+
}
202+
}
203+
204+
return testResult;
205+
}
206+
207+
public unsafe struct TestTable<T> : IDisposable where T : struct
208+
{
209+
public T[] outArray;
210+
211+
public void* outArrayPtr => outHandle.AddrOfPinnedObject().ToPointer();
212+
213+
GCHandle outHandle;
214+
public TestTable(T[] a)
215+
{
216+
this.outArray = a;
217+
218+
outHandle = GCHandle.Alloc(outArray, GCHandleType.Pinned);
219+
}
220+
public bool CheckResult(Func<T, bool> check)
221+
{
222+
foreach (var item in outArray)
223+
{
224+
if (!check(item))
225+
{
226+
return false;
227+
}
228+
}
229+
return true;
230+
}
231+
232+
public void Dispose()
233+
{
234+
outHandle.Free();
235+
}
236+
}
237+
}
238+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<SchemaVersion>2.0</SchemaVersion>
8+
<ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
9+
<OutputType>Exe</OutputType>
10+
<ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
11+
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
12+
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
13+
</PropertyGroup>
14+
<!-- Default configurations to help VS understand the configurations -->
15+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "></PropertyGroup>
16+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' " />
17+
<ItemGroup>
18+
<CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
19+
<Visible>False</Visible>
20+
</CodeAnalysisDependentAssemblyPaths>
21+
</ItemGroup>
22+
<PropertyGroup>
23+
<DebugType>None</DebugType>
24+
<Optimize></Optimize>
25+
</PropertyGroup>
26+
<ItemGroup>
27+
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
28+
</ItemGroup>
29+
<ItemGroup>
30+
<Compile Include="SetAllVector256.cs" />
31+
</ItemGroup>
32+
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
33+
<PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' "></PropertyGroup>
34+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<SchemaVersion>2.0</SchemaVersion>
8+
<ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
9+
<OutputType>Exe</OutputType>
10+
<ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
11+
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
12+
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
13+
</PropertyGroup>
14+
<!-- Default configurations to help VS understand the configurations -->
15+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "></PropertyGroup>
16+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' " />
17+
<ItemGroup>
18+
<CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
19+
<Visible>False</Visible>
20+
</CodeAnalysisDependentAssemblyPaths>
21+
</ItemGroup>
22+
<PropertyGroup>
23+
<DebugType>None</DebugType>
24+
<Optimize>True</Optimize>
25+
</PropertyGroup>
26+
<ItemGroup>
27+
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
28+
</ItemGroup>
29+
<ItemGroup>
30+
<Compile Include="SetAllVector256.cs" />
31+
</ItemGroup>
32+
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
33+
<PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' "></PropertyGroup>
34+
</Project>

0 commit comments

Comments
 (0)
This repository has been archived.