internal static Vector128 <T> MultiplyAdd(Vector128 <T> a, Vector128 <T> b, Vector128 <T> c) { if (typeof(T) == typeof(float)) { return(Fma.MultiplyAdd(a.As <T, float>(), b.As <T, float>(), c.As <T, float>()).As <float, T>()); } if (typeof(T) == typeof(double)) { return(Fma.MultiplyAdd(a.As <T, double>(), b.As <T, double>(), c.As <T, double>()).As <double, T>()); } Sse2.X64.ConvertScalarToVector128Double(a.As <T, double>(), 15); throw new NotSupportedException(); }
private static void KeygenThree192(Vector128 <byte>[] schedule, ref Vector128 <byte> temp1, ref Vector128 <byte> temp3, int i, byte control1, byte control2) { schedule[i] = temp1; schedule[i + 1] = temp3; var temp2 = Aes.KeygenAssist(temp3, control1); Keygen192Assist(ref temp1, ref temp2, ref temp3); schedule[i + 1] = Sse2.Shuffle(schedule[i + 1].As <byte, double>(), temp1.As <byte, double>(), 0) .As <double, byte>(); schedule[i + 2] = Sse2.Shuffle(temp1.As <byte, double>(), temp3.As <byte, double>(), 1) .As <double, byte>(); temp2 = Aes.KeygenAssist(temp3, control2); Keygen192Assist(ref temp1, ref temp2, ref temp3); }
private static Vector128 <ulong> shuffle_ulong(ref Vector128 <ulong> x, byte m) { var y = x.As <uint>(); var z = Sse2.Shuffle(y, m); return(z.As <ulong>()); }
public static void Store(T *address, Vector128 <T> source) { if (typeof(T) == typeof(sbyte)) { Sse2.Store((sbyte *)address, source.As <T, sbyte>()); } else if (typeof(T) == typeof(byte)) { Sse2.Store((byte *)address, source.As <T, byte>()); } else if (typeof(T) == typeof(short)) { Sse2.Store((short *)address, source.As <T, short>()); } else if (typeof(T) == typeof(ushort)) { Sse2.Store((ushort *)address, source.As <T, ushort>()); } else if (typeof(T) == typeof(int)) { Sse2.Store((int *)address, source.As <T, int>()); } else if (typeof(T) == typeof(uint)) { Sse2.Store((uint *)address, source.As <T, uint>()); } else if (typeof(T) == typeof(long)) { Sse2.Store((long *)address, source.As <T, long>()); } else if (typeof(T) == typeof(ulong)) { Sse2.Store((ulong *)address, source.As <T, ulong>()); } else if (typeof(T) == typeof(double)) { Sse2.Store((double *)address, source.As <T, double>()); } else if (typeof(T) == typeof(float)) { Sse.Store((float *)address, source.As <T, float>()); } else { throw new NotSupportedException(); } }
public static Vector128 <T> And(Vector128 <T> va, Vector128 <T> vb) { if (typeof(T) == typeof(sbyte)) { return(Sse2.And(va.As <T, sbyte>(), vb.As <T, sbyte>()).As <sbyte, T>()); } if (typeof(T) == typeof(byte)) { return(Sse2.And(va.As <T, byte>(), vb.As <T, byte>()).As <byte, T>()); } if (typeof(T) == typeof(short)) { return(Sse2.And(va.As <T, short>(), vb.As <T, short>()).As <short, T>()); } if (typeof(T) == typeof(ushort)) { return(Sse2.And(va.As <T, ushort>(), vb.As <T, ushort>()).As <ushort, T>()); } if (typeof(T) == typeof(int)) { return(Sse2.And(va.As <T, int>(), vb.As <T, int>()).As <int, T>()); } if (typeof(T) == typeof(uint)) { return(Sse2.And(va.As <T, uint>(), vb.As <T, uint>()).As <uint, T>()); } if (typeof(T) == typeof(long)) { return(Sse2.And(va.As <T, long>(), vb.As <T, long>()).As <long, T>()); } if (typeof(T) == typeof(ulong)) { return(Sse2.And(va.As <T, ulong>(), vb.As <T, ulong>()).As <ulong, T>()); } if (typeof(T) == typeof(double)) { return(Sse2.And(va.As <T, double>(), vb.As <T, double>()).As <double, T>()); } if (typeof(T) == typeof(float)) { return(Sse.And(va.As <T, float>(), vb.As <T, float>()).As <float, T>()); } throw new NotSupportedException(); }
internal static Vector256 <T> Insert128Vector256(Vector256 <T> value, Vector128 <T> data, byte index) { if (typeof(T) == typeof(sbyte)) { return(Avx2.InsertVector128(value.As <T, sbyte>(), data.As <T, sbyte>(), index).As <sbyte, T>()); } if (typeof(T) == typeof(byte)) { return(Avx2.InsertVector128(value.As <T, byte>(), data.As <T, byte>(), index).As <byte, T>()); } if (typeof(T) == typeof(short)) { return(Avx2.InsertVector128(value.As <T, short>(), data.As <T, short>(), index).As <short, T>()); } if (typeof(T) == typeof(ushort)) { return(Avx2.InsertVector128(value.As <T, ushort>(), data.As <T, ushort>(), index).As <ushort, T>()); } if (typeof(T) == typeof(int)) { return(Avx2.InsertVector128(value.As <T, int>(), data.As <T, int>(), index).As <int, T>()); } if (typeof(T) == typeof(uint)) { return(Avx2.InsertVector128(value.As <T, uint>(), data.As <T, uint>(), index).As <uint, T>()); } if (typeof(T) == typeof(long)) { return(Avx2.InsertVector128(value.As <T, long>(), data.As <T, long>(), index).As <long, T>()); } if (typeof(T) == typeof(ulong)) { return(Avx2.InsertVector128(value.As <T, ulong>(), data.As <T, ulong>(), index).As <ulong, T>()); } if (typeof(T) == typeof(float)) { return(Avx.InsertVector128(value.As <T, float>(), data.As <T, float>(), index).As <float, T>()); } if (typeof(T) == typeof(double)) { return(Avx.InsertVector128(value.As <T, double>(), data.As <T, double>(), index).As <double, T>()); } throw new NotSupportedException(); }
private static void diagonalize(ref Vector128 <ulong> row1l, ref Vector128 <ulong> row2l, ref Vector128 <ulong> row3l, ref Vector128 <ulong> row4l, ref Vector128 <ulong> row1h, ref Vector128 <ulong> row2h, ref Vector128 <ulong> row3h, ref Vector128 <ulong> row4h, ref Vector128 <ulong> b0) { var t0 = Ssse3.AlignRight(row2h.As <sbyte>(), row2l.As <sbyte>(), 8); var t1 = Ssse3.AlignRight(row2l.As <sbyte>(), row2h.As <sbyte>(), 8); row2l = t0.As <ulong>(); row2h = t1.As <ulong>(); b0 = row3l; row3l = row3h; row3h = b0; t0 = Ssse3.AlignRight(row4h.As <sbyte>(), row4l.As <sbyte>(), 8); t1 = Ssse3.AlignRight(row4l.As <sbyte>(), row4h.As <sbyte>(), 8); row4l = t1.As <ulong>(); row4h = t0.As <ulong>(); }
public static Vector128 <T> Select <T, U>(Vector128 <T> left, Vector128 <T> right, Vector128 <U> selector) where T : struct where U : struct { if (Sse41.IsSupported) { if (typeof(T) == typeof(float)) { return(Sse41.BlendVariable(left.AsSingle(), right.AsSingle(), selector.AsSingle()).As <float, T>()); } else if (typeof(T) == typeof(double)) { return(Sse41.BlendVariable(left.AsDouble(), right.AsDouble(), selector.AsDouble()).As <double, T>()); } return(Sse41.BlendVariable(left.AsByte(), right.AsByte(), selector.AsByte()).As <byte, T>()); } return(Or(And(selector.As <U, T>(), right), AndNot(selector.As <U, T>(), left))); }
private Vector128 <int> ExpandKey(Vector128 <int> key, byte control) { var keyGened = Aes.KeygenAssist(key.As <int, byte>(), control).As <byte, int>(); keyGened = Sse2.Shuffle(keyGened, Shuffle(3, 3, 3, 3)); key = Sse2.Xor(key, Sse2.ShiftLeftLogical(key, 4)); key = Sse2.Xor(key, Sse2.ShiftLeftLogical(key, 4)); key = Sse2.Xor(key, Sse2.ShiftLeftLogical(key, 4)); return(Sse2.Xor(key, keyGened)); }
private static void Keygen256Assist1(ref Vector128 <byte> temp1, ref Vector128 <byte> temp2) { temp2 = Sse2.Shuffle(temp2.As <byte, int>(), 0xff).As <int, byte>(); var temp4 = Sse2.ShiftLeftLogical128BitLane(temp1, 0x4); temp1 = Sse2.Xor(temp1, temp4); temp4 = Sse2.ShiftLeftLogical128BitLane(temp4, 0x4); temp1 = Sse2.Xor(temp1, temp4); temp4 = Sse2.ShiftLeftLogical128BitLane(temp4, 0x4); temp1 = Sse2.Xor(temp1, temp4); temp1 = Sse2.Xor(temp1, temp2); }
public static Vector128 <T> Select <T, U>(Vector128 <T> left, Vector128 <T> right, Vector128 <U> selector) where T : struct where U : struct => Or(And(selector.As <U, T>(), right), AndNot(selector.As <U, T>(), left));
public static T Element <T>(this Vector128 <float> vec, uint index) where T : struct => vec.As <float, T>().GetElement((int)index);
private static Vector128 <ulong> blend_ulong(ref Vector128 <ulong> x, ref Vector128 <ulong> y, byte m) => Sse41.Blend(x.As <ushort>(), y.As <ushort>(), m).As <ulong>();
private static Vector128 <ulong> ror64_shuffle(ref Vector128 <ulong> x, ref Vector128 <sbyte> y) => Ssse3.Shuffle(x.As <sbyte>(), y).As <ulong>();
private static Vector128 <ulong> ror64_32(ref Vector128 <ulong> x) => Sse2.Shuffle(x.As <uint>(), 0b_10_11_00_01).As <ulong>();
public Vector128 <T> Vec <T>() where T : unmanaged => Vector128.As <byte, T>(vxmm);
public static Vector128 <T> SelectWhereFalse <T, U>(Vector128 <T> vector, Vector128 <U> selector) where T : struct where U : struct => AndNot(selector.As <U, T>(), vector);
private static Vector128 <ulong> alignr_ulong(ref Vector128 <ulong> x, ref Vector128 <ulong> y, byte m) => Ssse3.AlignRight(x.As <sbyte>(), y.As <sbyte>(), m).As <ulong>();