Commit 3b6c9cff by Alexis Hetu Committed by Nicolas Capens

Replace if/else with switch.

Change-Id: I970a64ffdc18b240239092615f87a59b84c5e364 Reviewed-on: https://swiftshader-review.googlesource.com/3071Reviewed-by: 's avatarNicolas Capens <capn@google.com> Tested-by: 's avatarNicolas Capens <capn@google.com>
parent 9919b6c8
...@@ -275,207 +275,255 @@ namespace sw ...@@ -275,207 +275,255 @@ namespace sw
} }
#endif #endif
if(state.destFormat == FORMAT_X8R8G8B8 || state.destFormat == FORMAT_A8R8G8B8) switch(state.destFormat)
{ {
Int x = x0; case FORMAT_X8R8G8B8:
case FORMAT_A8R8G8B8:
if(state.sourceFormat == FORMAT_X8R8G8B8 || state.sourceFormat == FORMAT_A8R8G8B8)
{ {
For(, x < width - 3, x += 4) Int x = x0;
{
*Pointer<Int4>(d, 1) = *Pointer<Int4>(s, width % 4 ? 1 : 16);
s += 4 * sBytes; switch(state.sourceFormat)
d += 4 * dBytes;
}
}
else if(state.sourceFormat == FORMAT_X8B8G8R8 || state.sourceFormat == FORMAT_A8B8G8R8)
{
For(, x < width - 3, x += 4)
{ {
Int4 bgra = *Pointer<Int4>(s, width % 4 ? 1 : 16); case FORMAT_X8R8G8B8:
case FORMAT_A8R8G8B8:
For(, x < width - 3, x += 4)
{
*Pointer<Int4>(d, 1) = *Pointer<Int4>(s, width % 4 ? 1 : 16);
*Pointer<Int4>(d, 1) = ((bgra & Int4(0x00FF0000)) >> 16) | s += 4 * sBytes;
((bgra & Int4(0x000000FF)) << 16) | d += 4 * dBytes;
(bgra & Int4(0xFF00FF00)); }
break;
case FORMAT_X8B8G8R8:
case FORMAT_A8B8G8R8:
For(, x < width - 3, x += 4)
{
Int4 bgra = *Pointer<Int4>(s, width % 4 ? 1 : 16);
s += 4 * sBytes; *Pointer<Int4>(d, 1) = ((bgra & Int4(0x00FF0000)) >> 16) |
d += 4 * dBytes; ((bgra & Int4(0x000000FF)) << 16) |
} (bgra & Int4(0xFF00FF00));
}
else if(state.sourceFormat == FORMAT_A16B16G16R16)
{
For(, x < width - 1, x += 2)
{
UShort4 c0 = As<UShort4>(Swizzle(*Pointer<Short4>(s + 0), 0xC6)) >> 8;
UShort4 c1 = As<UShort4>(Swizzle(*Pointer<Short4>(s + 8), 0xC6)) >> 8;
*Pointer<Int2>(d) = As<Int2>(Pack(c0, c1)); s += 4 * sBytes;
d += 4 * dBytes;
}
break;
case FORMAT_A16B16G16R16:
For(, x < width - 1, x += 2)
{
UShort4 c0 = As<UShort4>(Swizzle(*Pointer<Short4>(s + 0), 0xC6)) >> 8;
UShort4 c1 = As<UShort4>(Swizzle(*Pointer<Short4>(s + 8), 0xC6)) >> 8;
s += 2 * sBytes; *Pointer<Int2>(d) = As<Int2>(Pack(c0, c1));
d += 2 * dBytes;
}
}
else ASSERT(false);
For(, x < width, x++) s += 2 * sBytes;
{ d += 2 * dBytes;
if(state.sourceFormat == FORMAT_X8R8G8B8 || state.sourceFormat == FORMAT_A8R8G8B8) }
{ break;
*Pointer<Int>(d) = *Pointer<Int>(s); default:
ASSERT(false);
break;
} }
else if(state.sourceFormat == FORMAT_X8B8G8R8 || state.sourceFormat == FORMAT_A8B8G8R8)
{
Int rgba = *Pointer<Int>(s);
*Pointer<Int>(d) = ((rgba & Int(0x00FF0000)) >> 16) | For(, x < width, x++)
((rgba & Int(0x000000FF)) << 16) |
(rgba & Int(0xFF00FF00));
}
else if(state.sourceFormat == FORMAT_A16B16G16R16)
{ {
UShort4 c = As<UShort4>(Swizzle(*Pointer<Short4>(s), 0xC6)) >> 8; switch(state.sourceFormat)
{
*Pointer<Int>(d) = Int(As<Int2>(Pack(c, c))); case FORMAT_X8R8G8B8:
} case FORMAT_A8R8G8B8:
else ASSERT(false); *Pointer<Int>(d) = *Pointer<Int>(s);
break;
case FORMAT_X8B8G8R8:
case FORMAT_A8B8G8R8:
{
Int rgba = *Pointer<Int>(s);
s += sBytes; *Pointer<Int>(d) = ((rgba & Int(0x00FF0000)) >> 16) |
d += dBytes; ((rgba & Int(0x000000FF)) << 16) |
} (rgba & Int(0xFF00FF00));
} }
else if(state.destFormat == FORMAT_X8B8G8R8 || state.destFormat == FORMAT_A8B8G8R8) break;
{ case FORMAT_A16B16G16R16:
Int x = x0; {
UShort4 c = As<UShort4>(Swizzle(*Pointer<Short4>(s), 0xC6)) >> 8;
if(state.sourceFormat == FORMAT_X8B8G8R8 || state.sourceFormat == FORMAT_A8B8G8R8) *Pointer<Int>(d) = Int(As<Int2>(Pack(c, c)));
{ }
For(, x < width - 3, x += 4) break;
{ default:
*Pointer<Int4>(d, 1) = *Pointer<Int4>(s, width % 4 ? 1 : 16); ASSERT(false);
break;
}
s += 4 * sBytes; s += sBytes;
d += 4 * dBytes; d += dBytes;
} }
} }
else if(state.sourceFormat == FORMAT_X8R8G8B8 || state.sourceFormat == FORMAT_A8R8G8B8) break;
case FORMAT_X8B8G8R8:
case FORMAT_A8B8G8R8:
{ {
For(, x < width - 3, x += 4) Int x = x0;
switch(state.sourceFormat)
{ {
Int4 bgra = *Pointer<Int4>(s, width % 4 ? 1 : 16); case FORMAT_X8B8G8R8:
case FORMAT_A8B8G8R8:
For(, x < width - 3, x += 4)
{
*Pointer<Int4>(d, 1) = *Pointer<Int4>(s, width % 4 ? 1 : 16);
*Pointer<Int4>(d, 1) = ((bgra & Int4(0x00FF0000)) >> 16) | s += 4 * sBytes;
((bgra & Int4(0x000000FF)) << 16) | d += 4 * dBytes;
(bgra & Int4(0xFF00FF00)); }
break;
case FORMAT_X8R8G8B8:
case FORMAT_A8R8G8B8:
For(, x < width - 3, x += 4)
{
Int4 bgra = *Pointer<Int4>(s, width % 4 ? 1 : 16);
s += 4 * sBytes; *Pointer<Int4>(d, 1) = ((bgra & Int4(0x00FF0000)) >> 16) |
d += 4 * dBytes; ((bgra & Int4(0x000000FF)) << 16) |
} (bgra & Int4(0xFF00FF00));
}
else if(state.sourceFormat == FORMAT_A16B16G16R16)
{
For(, x < width - 1, x += 2)
{
UShort4 c0 = *Pointer<UShort4>(s + 0) >> 8;
UShort4 c1 = *Pointer<UShort4>(s + 8) >> 8;
*Pointer<Int2>(d) = As<Int2>(Pack(c0, c1)); s += 4 * sBytes;
d += 4 * dBytes;
}
break;
case FORMAT_A16B16G16R16:
For(, x < width - 1, x += 2)
{
UShort4 c0 = *Pointer<UShort4>(s + 0) >> 8;
UShort4 c1 = *Pointer<UShort4>(s + 8) >> 8;
s += 2 * sBytes; *Pointer<Int2>(d) = As<Int2>(Pack(c0, c1));
d += 2 * dBytes;
}
}
else ASSERT(false);
For(, x < width, x++) s += 2 * sBytes;
{ d += 2 * dBytes;
if(state.sourceFormat == FORMAT_X8B8G8R8 || state.sourceFormat == FORMAT_A8B8G8R8) }
{ break;
*Pointer<Int>(d) = *Pointer<Int>(s); default:
} ASSERT(false);
else if(state.sourceFormat == FORMAT_X8R8G8B8 || state.sourceFormat == FORMAT_A8R8G8B8) break;
{
Int bgra = *Pointer<Int>(s);
*Pointer<Int>(d) = ((bgra & Int(0x00FF0000)) >> 16) |
((bgra & Int(0x000000FF)) << 16) |
(bgra & Int(0xFF00FF00));
} }
else if(state.sourceFormat == FORMAT_A16B16G16R16)
For(, x < width, x++)
{ {
UShort4 c = *Pointer<UShort4>(s) >> 8; switch(state.sourceFormat)
{
case FORMAT_X8B8G8R8:
case FORMAT_A8B8G8R8:
*Pointer<Int>(d) = *Pointer<Int>(s);
break;
case FORMAT_X8R8G8B8:
case FORMAT_A8R8G8B8:
{
Int bgra = *Pointer<Int>(s);
*Pointer<Int>(d) = ((bgra & Int(0x00FF0000)) >> 16) |
((bgra & Int(0x000000FF)) << 16) |
(bgra & Int(0xFF00FF00));
}
break;
case FORMAT_A16B16G16R16:
{
UShort4 c = *Pointer<UShort4>(s) >> 8;
*Pointer<Int>(d) = Int(As<Int2>(Pack(c, c))); *Pointer<Int>(d) = Int(As<Int2>(Pack(c, c)));
} }
else ASSERT(false); break;
default:
ASSERT(false);
break;
}
s += sBytes; s += sBytes;
d += dBytes; d += dBytes;
}
} }
} case FORMAT_R8G8B8:
else if(state.destFormat == FORMAT_R8G8B8)
{
For(Int x = x0, x < width, x++)
{ {
if(state.sourceFormat == FORMAT_X8R8G8B8 || state.sourceFormat == FORMAT_A8R8G8B8) For(Int x = x0, x < width, x++)
{
*Pointer<Byte>(d + 0) = *Pointer<Byte>(s + 0);
*Pointer<Byte>(d + 1) = *Pointer<Byte>(s + 1);
*Pointer<Byte>(d + 2) = *Pointer<Byte>(s + 2);
}
else if(state.sourceFormat == FORMAT_X8B8G8R8 || state.sourceFormat == FORMAT_A8B8G8R8)
{
*Pointer<Byte>(d + 0) = *Pointer<Byte>(s + 2);
*Pointer<Byte>(d + 1) = *Pointer<Byte>(s + 1);
*Pointer<Byte>(d + 2) = *Pointer<Byte>(s + 0);
}
else if(state.sourceFormat == FORMAT_A16B16G16R16)
{ {
*Pointer<Byte>(d + 0) = *Pointer<Byte>(s + 5); switch(state.sourceFormat)
*Pointer<Byte>(d + 1) = *Pointer<Byte>(s + 3); {
*Pointer<Byte>(d + 2) = *Pointer<Byte>(s + 1); case FORMAT_X8R8G8B8:
} case FORMAT_A8R8G8B8:
else ASSERT(false); *Pointer<Byte>(d + 0) = *Pointer<Byte>(s + 0);
*Pointer<Byte>(d + 1) = *Pointer<Byte>(s + 1);
*Pointer<Byte>(d + 2) = *Pointer<Byte>(s + 2);
break;
case FORMAT_X8B8G8R8:
case FORMAT_A8B8G8R8:
*Pointer<Byte>(d + 0) = *Pointer<Byte>(s + 2);
*Pointer<Byte>(d + 1) = *Pointer<Byte>(s + 1);
*Pointer<Byte>(d + 2) = *Pointer<Byte>(s + 0);
break;
case FORMAT_A16B16G16R16:
*Pointer<Byte>(d + 0) = *Pointer<Byte>(s + 5);
*Pointer<Byte>(d + 1) = *Pointer<Byte>(s + 3);
*Pointer<Byte>(d + 2) = *Pointer<Byte>(s + 1);
break;
default:
ASSERT(false);
break;
}
s += sBytes; s += sBytes;
d += dBytes; d += dBytes;
}
} }
} break;
else if(state.destFormat == FORMAT_R5G6B5) case FORMAT_R5G6B5:
{
For(Int x = x0, x < width, x++)
{ {
if(state.sourceFormat == FORMAT_X8R8G8B8 || state.sourceFormat == FORMAT_A8R8G8B8) For(Int x = x0, x < width, x++)
{ {
Int c = *Pointer<Int>(s); switch(state.sourceFormat)
{
case FORMAT_X8R8G8B8:
case FORMAT_A8R8G8B8:
{
Int c = *Pointer<Int>(s);
*Pointer<Short>(d) = Short((c & 0x00F80000) >> 8 | *Pointer<Short>(d) = Short((c & 0x00F80000) >> 8 |
(c & 0x0000FC00) >> 5 | (c & 0x0000FC00) >> 5 |
(c & 0x000000F8) >> 3); (c & 0x000000F8) >> 3);
} }
else if(state.sourceFormat == FORMAT_X8B8G8R8 || state.sourceFormat == FORMAT_A8B8G8R8) break;
{ case FORMAT_X8B8G8R8:
Int c = *Pointer<Int>(s); case FORMAT_A8B8G8R8:
{
Int c = *Pointer<Int>(s);
*Pointer<Short>(d) = Short((c & 0x00F80000) >> 19 | *Pointer<Short>(d) = Short((c & 0x00F80000) >> 19 |
(c & 0x0000FC00) >> 5 | (c & 0x0000FC00) >> 5 |
(c & 0x000000F8) << 8); (c & 0x000000F8) << 8);
} }
else if(state.sourceFormat == FORMAT_A16B16G16R16) break;
{ case FORMAT_A16B16G16R16:
UShort4 cc = *Pointer<UShort4>(s) >> 8; {
Int c = Int(As<Int2>(Pack(cc, cc))); UShort4 cc = *Pointer<UShort4>(s) >> 8;
Int c = Int(As<Int2>(Pack(cc, cc)));
*Pointer<Short>(d) = Short((c & 0x00F80000) >> 19 | *Pointer<Short>(d) = Short((c & 0x00F80000) >> 19 |
(c & 0x0000FC00) >> 5 | (c & 0x0000FC00) >> 5 |
(c & 0x000000F8) << 8); (c & 0x000000F8) << 8);
} }
else ASSERT(false); break;
default:
ASSERT(false);
break;
}
s += sBytes; s += sBytes;
d += dBytes; d += dBytes;
}
} }
break;
default:
ASSERT(false);
break;
} }
else ASSERT(false);
} }
#if DISPLAY_LOGO #if DISPLAY_LOGO
...@@ -551,19 +599,23 @@ namespace sw ...@@ -551,19 +599,23 @@ namespace sw
c1 = UnpackLow(As<Byte8>(c1), *Pointer<Byte8>(c)); c1 = UnpackLow(As<Byte8>(c1), *Pointer<Byte8>(c));
if(state.sourceFormat == FORMAT_X8R8G8B8 || state.sourceFormat == FORMAT_A8R8G8B8) switch(state.sourceFormat)
{ {
case FORMAT_X8R8G8B8:
case FORMAT_A8R8G8B8:
c2 = UnpackLow(As<Byte8>(c2), *Pointer<Byte8>(s)); c2 = UnpackLow(As<Byte8>(c2), *Pointer<Byte8>(s));
} break;
else if(state.sourceFormat == FORMAT_X8B8G8R8 || state.sourceFormat == FORMAT_A8B8G8R8) case FORMAT_X8B8G8R8:
{ case FORMAT_A8B8G8R8:
c2 = Swizzle(UnpackLow(As<Byte8>(c2), *Pointer<Byte8>(s)), 0xC6); c2 = Swizzle(UnpackLow(As<Byte8>(c2), *Pointer<Byte8>(s)), 0xC6);
} break;
else if(state.sourceFormat == FORMAT_A16B16G16R16) case FORMAT_A16B16G16R16:
{
c2 = Swizzle(*Pointer<Short4>(s + 0), 0xC6); c2 = Swizzle(*Pointer<Short4>(s + 0), 0xC6);
break;
default:
ASSERT(false);
break;
} }
else ASSERT(false);
c1 = As<Short4>(As<UShort4>(c1) >> 9); c1 = As<Short4>(As<UShort4>(c1) >> 9);
c2 = As<Short4>(As<UShort4>(c2) >> 9); c2 = As<Short4>(As<UShort4>(c2) >> 9);
...@@ -575,33 +627,42 @@ namespace sw ...@@ -575,33 +627,42 @@ namespace sw
c1 = c1 + c2; c1 = c1 + c2;
c1 = c1 + c1; c1 = c1 + c1;
if(state.destFormat == FORMAT_X8R8G8B8 || state.destFormat == FORMAT_A8R8G8B8) switch(state.destFormat)
{ {
case FORMAT_X8R8G8B8:
case FORMAT_A8R8G8B8:
*Pointer<UInt>(d) = UInt(As<Long>(Pack(As<UShort4>(c1), As<UShort4>(c1)))); *Pointer<UInt>(d) = UInt(As<Long>(Pack(As<UShort4>(c1), As<UShort4>(c1))));
} break;
else if(state.destFormat == FORMAT_X8B8G8R8 || state.destFormat == FORMAT_A8B8G8R8) case FORMAT_X8B8G8R8:
{ case FORMAT_A8B8G8R8:
c1 = Swizzle(c1, 0xC6); {
c1 = Swizzle(c1, 0xC6);
*Pointer<UInt>(d) = UInt(As<Long>(Pack(As<UShort4>(c1), As<UShort4>(c1)))); *Pointer<UInt>(d) = UInt(As<Long>(Pack(As<UShort4>(c1), As<UShort4>(c1))));
} }
else if(state.destFormat == FORMAT_R8G8B8) break;
{ case FORMAT_R8G8B8:
Int c = Int(As<Int2>(Pack(As<UShort4>(c1), As<UShort4>(c1)))); {
Int c = Int(As<Int2>(Pack(As<UShort4>(c1), As<UShort4>(c1))));
*Pointer<Byte>(d + 0) = Byte(c >> 0); *Pointer<Byte>(d + 0) = Byte(c >> 0);
*Pointer<Byte>(d + 1) = Byte(c >> 8); *Pointer<Byte>(d + 1) = Byte(c >> 8);
*Pointer<Byte>(d + 2) = Byte(c >> 16); *Pointer<Byte>(d + 2) = Byte(c >> 16);
} }
else if(state.destFormat == FORMAT_R5G6B5) break;
{ case FORMAT_R5G6B5:
Int c = Int(As<Int2>(Pack(As<UShort4>(c1), As<UShort4>(c1)))); {
Int c = Int(As<Int2>(Pack(As<UShort4>(c1), As<UShort4>(c1))));
*Pointer<Short>(d) = Short((c & 0x00F80000) >> 8 | *Pointer<Short>(d) = Short((c & 0x00F80000) >> 8 |
(c & 0x0000FC00) >> 5 | (c & 0x0000FC00) >> 5 |
(c & 0x000000F8) >> 3); (c & 0x000000F8) >> 3);
}
break;
default:
ASSERT(false);
break;
} }
else ASSERT(false);
} }
void FrameBuffer::threadFunction(void *parameters) void FrameBuffer::threadFunction(void *parameters)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment