Skip to content

Commit

Permalink
partial fix for RyuJIT perf issue
Browse files Browse the repository at this point in the history
  • Loading branch information
saucecontrol committed Jul 27, 2017
1 parent a14697e commit 2a92d02
Showing 1 changed file with 73 additions and 73 deletions.
146 changes: 73 additions & 73 deletions src/MagicScaler/Magic/FormatConversionTransform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,19 +144,19 @@ unsafe private static void mapValuesByteToUQ15Linear(byte* ipstart, byte* opstar

while (ip <= ipe)
{
ushort o0 = igt[ip[-8]];
ushort o1 = igt[ip[-7]];
ushort o2 = igt[ip[-6]];
ushort o3 = igt[ip[-5]];
ushort o0 = igt[(uint)ip[-8]];
ushort o1 = igt[(uint)ip[-7]];
ushort o2 = igt[(uint)ip[-6]];
ushort o3 = igt[(uint)ip[-5]];
op[-8] = o0;
op[-7] = o1;
op[-6] = o2;
op[-5] = o3;

o0 = igt[ip[-4]];
o1 = igt[ip[-3]];
o2 = igt[ip[-2]];
o3 = igt[ip[-1]];
o0 = igt[(uint)ip[-4]];
o1 = igt[(uint)ip[-3]];
o2 = igt[(uint)ip[-2]];
o3 = igt[(uint)ip[-1]];
op[-4] = o0;
op[-3] = o1;
op[-2] = o2;
Expand Down Expand Up @@ -186,10 +186,10 @@ unsafe private static void mapValuesByteToUQ15LinearWithAlpha(byte* ipstart, byt

while (ip <= ipe)
{
ushort o0 = igt[ip[-4]];
ushort o1 = igt[ip[-3]];
ushort o2 = igt[ip[-2]];
ushort o3 = at[ip[-1]];
ushort o0 = igt[(uint)ip[-4]];
ushort o1 = igt[(uint)ip[-3]];
ushort o2 = igt[(uint)ip[-2]];
ushort o3 = at[(uint)ip[-1]];
op[-4] = o0;
op[-3] = o1;
op[-2] = o2;
Expand All @@ -210,19 +210,19 @@ unsafe private static void mapValuesUQ15LinearToByte(byte* ipstart, byte* opstar

while (ip <= ipe)
{
byte o0 = gt[ip[-8]];
byte o1 = gt[ip[-7]];
byte o2 = gt[ip[-6]];
byte o3 = gt[ip[-5]];
byte o0 = gt[(uint)ip[-8]];
byte o1 = gt[(uint)ip[-7]];
byte o2 = gt[(uint)ip[-6]];
byte o3 = gt[(uint)ip[-5]];
op[-8] = o0;
op[-7] = o1;
op[-6] = o2;
op[-5] = o3;

o0 = gt[ip[-4]];
o1 = gt[ip[-3]];
o2 = gt[ip[-2]];
o3 = gt[ip[-1]];
o0 = gt[(uint)ip[-4]];
o1 = gt[(uint)ip[-3]];
o2 = gt[(uint)ip[-2]];
o3 = gt[(uint)ip[-1]];
op[-4] = o0;
op[-3] = o1;
op[-2] = o2;
Expand Down Expand Up @@ -252,9 +252,9 @@ unsafe private static void mapValuesUQ15LinearToByteWithAlpha(byte* ipstart, byt

while (ip <= ipe)
{
byte o0 = gt[ip[-4]];
byte o1 = gt[ip[-3]];
byte o2 = gt[ip[-2]];
byte o0 = gt[(uint)ip[-4]];
byte o1 = gt[(uint)ip[-3]];
byte o2 = gt[(uint)ip[-2]];
byte o3 = UnFix15ToByte(ip[-1] * byte.MaxValue);
op[-4] = o0;
op[-3] = o1;
Expand Down Expand Up @@ -311,14 +311,14 @@ unsafe private static void mapValuesByteToFloatLinear(byte* ipstart, byte* opsta

while (ip <= ipe)
{
float o0 = igt[ip[-8]];
float o1 = igt[ip[-7]];
float o2 = igt[ip[-6]];
float o3 = igt[ip[-5]];
float o4 = igt[ip[-4]];
float o5 = igt[ip[-3]];
float o6 = igt[ip[-2]];
float o7 = igt[ip[-1]];
float o0 = igt[(uint)ip[-8]];
float o1 = igt[(uint)ip[-7]];
float o2 = igt[(uint)ip[-6]];
float o3 = igt[(uint)ip[-5]];
float o4 = igt[(uint)ip[-4]];
float o5 = igt[(uint)ip[-3]];
float o6 = igt[(uint)ip[-2]];
float o7 = igt[(uint)ip[-1]];

op[-8] = o0;
op[-7] = o1;
Expand Down Expand Up @@ -353,10 +353,10 @@ unsafe private static void mapValuesByteToFloatLinearWithAlpha(byte* ipstart, by

while (ip <= ipe)
{
float o0 = igt[ip[-4]];
float o1 = igt[ip[-3]];
float o2 = igt[ip[-2]];
float o3 = at[ip[-1]];
float o0 = igt[(uint)ip[-4]];
float o1 = igt[(uint)ip[-3]];
float o2 = igt[(uint)ip[-2]];
float o3 = at[(uint)ip[-1]];
op[-4] = o0 * o3;
op[-3] = o1 * o3;
op[-2] = o2 * o3;
Expand All @@ -377,10 +377,10 @@ unsafe private static void mapValuesByteToFloatLinearWithAssociatedAlpha(byte* i

while (ip <= ipe)
{
float o0 = igt[ip[-4]];
float o1 = igt[ip[-3]];
float o2 = igt[ip[-2]];
float o3 = at[ip[-1]];
float o0 = igt[(uint)ip[-4]];
float o1 = igt[(uint)ip[-3]];
float o2 = igt[(uint)ip[-2]];
float o3 = at[(uint)ip[-1]];
op[-4] = o0;
op[-3] = o1;
op[-2] = o2;
Expand All @@ -401,9 +401,9 @@ unsafe private static void mapValuesByteToFloatLinearWithNullAlpha(byte* ipstart

while (ip <= ipe)
{
float o0 = igt[ip[-3]];
float o1 = igt[ip[-2]];
float o2 = igt[ip[-1]];
float o0 = igt[(uint)ip[-3]];
float o1 = igt[(uint)ip[-2]];
float o2 = igt[(uint)ip[-1]];
op[-4] = o0;
op[-3] = o1;
op[-2] = o2;
Expand Down Expand Up @@ -432,21 +432,21 @@ unsafe private static void mapValuesFloatLinearToByte(byte* ipstart, byte* opsta
v = v.Clamp(vmin, vmax);

//TODO future JIT versions will auto-unroll loops over vector elements
byte o0 = gt[(ushort)v[0]];
byte o1 = gt[(ushort)v[1]];
byte o2 = gt[(ushort)v[2]];
byte o3 = gt[(ushort)v[3]];
byte o0 = gt[(uint)v[0]];
byte o1 = gt[(uint)v[1]];
byte o2 = gt[(uint)v[2]];
byte o3 = gt[(uint)v[3]];
op[0] = o0;
op[1] = o1;
op[2] = o2;
op[3] = o3;

if (VectorF.Count == 8)
{
o0 = gt[(ushort)v[4]];
o1 = gt[(ushort)v[5]];
o2 = gt[(ushort)v[6]];
o3 = gt[(ushort)v[7]];
o0 = gt[(uint)v[4]];
o1 = gt[(uint)v[5]];
o2 = gt[(uint)v[6]];
o3 = gt[(uint)v[7]];
op[4] = o0;
op[5] = o1;
op[6] = o2;
Expand Down Expand Up @@ -511,18 +511,18 @@ unsafe private static void mapValuesFloatLinearWithNullAlphaToByte(byte* ipstart
var v = Unsafe.Read<VectorF>(ip) * vscale + vround;
v = v.Clamp(vmin, vmax);

byte o0 = gt[(ushort)v[0]];
byte o1 = gt[(ushort)v[1]];
byte o2 = gt[(ushort)v[2]];
byte o0 = gt[(uint)v[0]];
byte o1 = gt[(uint)v[1]];
byte o2 = gt[(uint)v[2]];
op[0] = o0;
op[1] = o1;
op[2] = o2;

if (VectorF.Count == 8)
{
o0 = gt[(ushort)v[4]];
o1 = gt[(ushort)v[5]];
o2 = gt[(ushort)v[6]];
o0 = gt[(uint)v[4]];
o1 = gt[(uint)v[5]];
o2 = gt[(uint)v[6]];
op[3] = o0;
op[4] = o1;
op[5] = o2;
Expand Down Expand Up @@ -554,14 +554,14 @@ unsafe private static void mapValuesByteToFloat(byte* ipstart, byte* opstart, in

while (ip <= ipe)
{
float o0 = at[ip[-8]];
float o1 = at[ip[-7]];
float o2 = at[ip[-6]];
float o3 = at[ip[-5]];
float o4 = at[ip[-4]];
float o5 = at[ip[-3]];
float o6 = at[ip[-2]];
float o7 = at[ip[-1]];
float o0 = at[(uint)ip[-8]];
float o1 = at[(uint)ip[-7]];
float o2 = at[(uint)ip[-6]];
float o3 = at[(uint)ip[-5]];
float o4 = at[(uint)ip[-4]];
float o5 = at[(uint)ip[-3]];
float o6 = at[(uint)ip[-2]];
float o7 = at[(uint)ip[-1]];

op[-8] = o0;
op[-7] = o1;
Expand Down Expand Up @@ -596,10 +596,10 @@ unsafe private static void mapValuesByteToFloatWithAlpha(byte* ipstart, byte* op

while (ip <= ipe)
{
float o0 = at[ip[-4]];
float o1 = at[ip[-3]];
float o2 = at[ip[-2]];
float o3 = at[ip[-1]];
float o0 = at[(uint)ip[-4]];
float o1 = at[(uint)ip[-3]];
float o2 = at[(uint)ip[-2]];
float o3 = at[(uint)ip[-1]];
op[-4] = o0 * o3;
op[-3] = o1 * o3;
op[-2] = o2 * o3;
Expand All @@ -620,9 +620,9 @@ unsafe private static void mapValuesByteToFloatWithNullAlpha(byte* ipstart, byte

while (ip <= ipe)
{
float o0 = at[ip[-3]];
float o1 = at[ip[-2]];
float o2 = at[ip[-1]];
float o0 = at[(uint)ip[-3]];
float o1 = at[(uint)ip[-2]];
float o2 = at[(uint)ip[-1]];
op[-4] = o0;
op[-3] = o1;
op[-2] = o2;
Expand Down Expand Up @@ -813,7 +813,7 @@ unsafe public static void ConvertBgrxToGreyUQ15(byte* ipstart, byte* opstart, in

while (ip <= ipe)
{
ushort y = Rec709.LumaFromBgr(ip[-4], ip[-3], ip[-2]);
uint y = Rec709.LumaFromBgr(ip[-4], ip[-3], ip[-2]);
op[-1] = gt[y];

ip += 4;
Expand Down Expand Up @@ -848,7 +848,7 @@ unsafe public static void ConvertGreyLinearToGreyUQ15(byte* ipstart, byte* opsta
byte* gt = gtstart;

while (ip < ipe)
*op++ = gt[*ip++];
*op++ = gt[(uint)*ip++];
}
}

Expand Down

0 comments on commit 2a92d02

Please sign in to comment.