From 4c7c21634eeab768971777f62dab8224f7ed2eb0 Mon Sep 17 00:00:00 2001 From: gdkchan Date: Thu, 28 Jun 2018 20:52:32 -0300 Subject: [PATCH] Add Sse2 fallback to Vector{Extract|Insert}Single methods on the CPU (#193) --- ChocolArm64/Instruction/AVectorHelper.cs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/ChocolArm64/Instruction/AVectorHelper.cs b/ChocolArm64/Instruction/AVectorHelper.cs index 1a2135923..dbfaab756 100644 --- a/ChocolArm64/Instruction/AVectorHelper.cs +++ b/ChocolArm64/Instruction/AVectorHelper.cs @@ -422,6 +422,15 @@ namespace ChocolArm64.Instruction { return Sse41.Extract(Vector, Index); } + else if (Sse2.IsSupported) + { + Vector128 ShortVector = Sse.StaticCast(Vector); + + int Low = Sse2.Extract(ShortVector, (byte)(Index * 2 + 0)); + int High = Sse2.Extract(ShortVector, (byte)(Index * 2 + 1)); + + return BitConverter.Int32BitsToSingle(Low | (High << 16)); + } throw new PlatformNotSupportedException(); } @@ -509,6 +518,20 @@ namespace ChocolArm64.Instruction { return Sse41.Insert(Vector, Value, (byte)(Index << 4)); } + else if (Sse2.IsSupported) + { + int IntValue = BitConverter.SingleToInt32Bits(Value); + + ushort Low = (ushort)(IntValue >> 0); + ushort High = (ushort)(IntValue >> 16); + + Vector128 ShortVector = Sse.StaticCast(Vector); + + ShortVector = Sse2.Insert(ShortVector, Low, (byte)(Index * 2 + 0)); + ShortVector = Sse2.Insert(ShortVector, High, (byte)(Index * 2 + 1)); + + return Sse.StaticCast(ShortVector); + } throw new PlatformNotSupportedException(); }