private static void TestVector64C() { Assert.Throws <MarshalDirectiveException>(() => GenericsNative.GetVector64C('0', '1', '2', '3')); Vector64 <char> value2; GenericsNative.GetVector64COut('0', '1', '2', '3', &value2); Vector64 <short> tValue2 = *(Vector64 <short> *) & value2; Assert.Equal(tValue2.GetElement(0), (short)'0'); Assert.Equal(tValue2.GetElement(1), (short)'1'); Assert.Equal(tValue2.GetElement(2), (short)'2'); Assert.Equal(tValue2.GetElement(3), (short)'3'); Assert.Throws <MarshalDirectiveException>(() => GenericsNative.GetVector64COut('0', '1', '2', '3', out Vector64 <char> value3)); Vector64 <char> * value4 = GenericsNative.GetVector64CPtr('0', '1', '2', '3'); Vector64 <short> *tValue4 = (Vector64 <short> *)value4; Assert.Equal(tValue4->GetElement(0), (short)'0'); Assert.Equal(tValue4->GetElement(1), (short)'1'); Assert.Equal(tValue4->GetElement(2), (short)'2'); Assert.Equal(tValue4->GetElement(3), (short)'3'); Assert.Throws <MarshalDirectiveException>(() => GenericsNative.GetVector64CRef('0', '1', '2', '3')); Assert.Throws <MarshalDirectiveException>(() => GenericsNative.AddVector64C(default, default));
private static void TestVector64B() { Assert.Throws <MarshalDirectiveException>(() => GenericsNative.GetVector64B(true, false, true, false, true, false, true, false)); Vector64 <bool> value2; GenericsNative.GetVector64BOut(true, false, true, false, true, false, true, false, &value2); Vector64 <byte> tValue2 = *(Vector64 <byte> *) & value2; Assert.AreEqual(tValue2.GetElement(0), 1); Assert.AreEqual(tValue2.GetElement(1), 0); Assert.AreEqual(tValue2.GetElement(2), 1); Assert.AreEqual(tValue2.GetElement(3), 0); Assert.AreEqual(tValue2.GetElement(4), 1); Assert.AreEqual(tValue2.GetElement(5), 0); Assert.AreEqual(tValue2.GetElement(6), 1); Assert.AreEqual(tValue2.GetElement(7), 0); Assert.Throws <MarshalDirectiveException>(() => GenericsNative.GetVector64BOut(true, false, true, false, true, false, true, false, out Vector64 <bool> value3)); Vector64 <bool> *value4 = GenericsNative.GetVector64BPtr(true, false, true, false, true, false, true, false); Vector64 <byte> *tValue4 = (Vector64 <byte> *)value4; Assert.AreEqual(tValue4->GetElement(0), 1); Assert.AreEqual(tValue4->GetElement(1), 0); Assert.AreEqual(tValue4->GetElement(2), 1); Assert.AreEqual(tValue4->GetElement(3), 0); Assert.AreEqual(tValue4->GetElement(4), 1); Assert.AreEqual(tValue4->GetElement(5), 0); Assert.AreEqual(tValue4->GetElement(6), 1); Assert.AreEqual(tValue4->GetElement(7), 0); Assert.Throws <MarshalDirectiveException>(() => GenericsNative.GetVector64BRef(true, false, true, false, true, false, true, false)); Assert.Throws <MarshalDirectiveException>(() => GenericsNative.AddVector64B(default, default));
public static short Vector64_Create_short(short a) { Vector64 <short> x = default; for (int i = 0; i < 1; i++) { x = Vector64.Create(1, 2, 3, Inline(a)); } return(x.GetElement(3)); }
public void RunBasicScenario(int imm = 0, bool expectedOutOfRangeException = false) { TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario)); UInt32[] values = new UInt32[ElementCount]; for (int i = 0; i < ElementCount; i++) { values[i] = TestLibrary.Generator.GetUInt32(); } Vector64 <UInt32> value = Vector64.Create(values[0], values[1]); bool succeeded = !expectedOutOfRangeException; try { UInt32 result = value.GetElement(imm); ValidateGetResult(result, values); } catch (ArgumentOutOfRangeException) { succeeded = expectedOutOfRangeException; } if (!succeeded) { Succeeded = false; TestLibrary.TestFramework.LogInformation($"Vector64<UInt32.GetElement({imm}): {nameof(RunBasicScenario)} failed to throw ArgumentOutOfRangeException."); TestLibrary.TestFramework.LogInformation(string.Empty); } succeeded = !expectedOutOfRangeException; UInt32 insertedValue = TestLibrary.Generator.GetUInt32(); try { Vector64 <UInt32> result2 = value.WithElement(imm, insertedValue); ValidateWithResult(result2, values, insertedValue); } catch (ArgumentOutOfRangeException) { succeeded = expectedOutOfRangeException; } if (!succeeded) { Succeeded = false; TestLibrary.TestFramework.LogInformation($"Vector64<UInt32.WithElement({imm}): {nameof(RunBasicScenario)} failed to throw ArgumentOutOfRangeException."); TestLibrary.TestFramework.LogInformation(string.Empty); } }
unsafe static bool ValidateResult_Vector64 <T>(Vector64 <T> result, Vector64 <T> expectedElementValue) where T : unmanaged { var succeeded = true; for (var i = 0; i < (8 / sizeof(T)); i++) { if (!result.GetElement(i).Equals(expectedElementValue.GetElement(i))) { succeeded = false; } } return(succeeded); }
// Checks that the values in v correspond to those in the values array starting // with values[index] private void checkValues(string msg, Vector64 <T> v, int index) { bool printedMsg = false; // Print at most one message for (int i = 0; i < Vector64 <T> .Count; i++) { if (!CheckValue <T>(v.GetElement(i), values[index])) { if (!printedMsg) { Console.WriteLine("{0}: FAILED - Vector64<T> checkValues(index = {1}, i = {2}) {3}", msg, index, i, isReflection ? "(via reflection)" : ""); printedMsg = true; } // Record failure status in global isPassing isPassing = false; } index++; } }