Ejemplo n.º 1
0
        public static Vector128 <T> And <T>(Vector128 <T> left, Vector128 <T> right) where T : struct
        {
            if (typeof(T) == typeof(float))
            {
                if (Sse.IsSupported)
                {
                    return(Sse.And(left.AsSingle(), right.AsSingle()).As <float, T>());
                }
            }

            if (typeof(T) == typeof(double))
            {
                if (Sse2.IsSupported)
                {
                    return(Sse2.And(left.AsDouble(), right.AsDouble()).As <double, T>());
                }
                if (Sse.IsSupported)
                {
                    return(Sse.And(left.AsSingle(), right.AsSingle()).As <float, T>());
                }
            }

            if (Sse2.IsSupported)
            {
                return(Sse2.And(left.AsByte(), right.AsByte()).As <byte, T>());
            }
            if (Sse.IsSupported)
            {
                return(Sse.And(left.AsSingle(), right.AsSingle()).As <float, T>());
            }

            return(SoftwareFallbacks.And_Software(left, right));
        }
Ejemplo n.º 2
0
        private static void KeyRound(
            out Vector128 <byte> a, out Vector128 <byte> b, out Vector128 <byte> c,
            ref Vector128 <byte> t0, ref Vector128 <byte> t1,
            byte rcon0, byte rcon1)
        {
            a = t0;
            b = t1;
            var t2 = Aes.KeygenAssist(t1, rcon0);

            KeyRound(ref t0, ref t2, ref t1);

            b  = Sse2.Shuffle(b.AsDouble(), t0.AsDouble(), 0).AsByte();
            c  = Sse2.Shuffle(t0.AsDouble(), t1.AsDouble(), 1).AsByte();
            t2 = Aes.KeygenAssist(t1, rcon1);
            KeyRound(ref t0, ref t2, ref t1);
        }
Ejemplo n.º 3
0
 public static Vector128 <T> Vector128Add <T>(Vector128 <T> left, Vector128 <T> right) where T : struct
 {
     if (typeof(T) == typeof(byte))
     {
         return(Sse2.Add(left.AsByte(), right.AsByte()).As <byte, T>());
     }
     else if (typeof(T) == typeof(sbyte))
     {
         return(Sse2.Add(left.AsSByte(), right.AsSByte()).As <sbyte, T>());
     }
     else if (typeof(T) == typeof(short))
     {
         return(Sse2.Add(left.AsInt16(), right.AsInt16()).As <short, T>());
     }
     else if (typeof(T) == typeof(ushort))
     {
         return(Sse2.Add(left.AsUInt16(), right.AsUInt16()).As <ushort, T>());
     }
     else if (typeof(T) == typeof(int))
     {
         return(Sse2.Add(left.AsInt32(), right.AsInt32()).As <int, T>());
     }
     else if (typeof(T) == typeof(uint))
     {
         return(Sse2.Add(left.AsUInt32(), right.AsUInt32()).As <uint, T>());
     }
     else if (typeof(T) == typeof(long))
     {
         return(Sse2.Add(left.AsInt64(), right.AsInt64()).As <long, T>());
     }
     else if (typeof(T) == typeof(ulong))
     {
         return(Sse2.Add(left.AsUInt64(), right.AsUInt64()).As <ulong, T>());
     }
     else if (typeof(T) == typeof(float))
     {
         return(Sse.Add(left.AsSingle(), right.AsSingle()).As <float, T>());
     }
     else if (typeof(T) == typeof(double))
     {
         return(Sse2.Add(left.AsDouble(), right.AsDouble()).As <double, T>());
     }
     else
     {
         throw new NotSupportedException();
     }
 }
Ejemplo n.º 4
0
        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)));
        }
Ejemplo n.º 5
0
 private static Vector128 <byte> Shuffle(Vector128 <byte> left, Vector128 <byte> right, byte control)
 => Sse2.Shuffle(left.AsDouble(), right.AsDouble(), control).AsByte();