Skip to content

Commit

Permalink
Merge pull request #18219 from hrydgard/get-index-bounds-autovec
Browse files Browse the repository at this point in the history
Make GetIndexBounds friendlier to autovectorization. Works on x86 at least.
  • Loading branch information
hrydgard committed Sep 29, 2023
2 parents b8fa3a2 + 45bc4d8 commit cf48532
Showing 1 changed file with 20 additions and 12 deletions.
32 changes: 20 additions & 12 deletions GPU/Common/VertexDecoderCommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,28 +108,36 @@ void DecVtxFormat::InitializeFromID(uint32_t id) {
void GetIndexBounds(const void *inds, int count, u32 vertType, u16 *indexLowerBound, u16 *indexUpperBound) {
// Find index bounds. Could cache this in display lists.
// Also, this could be greatly sped up with SSE2/NEON, although rarely a bottleneck.
int lowerBound = 0x7FFFFFFF;
int upperBound = 0;
u32 idx = vertType & GE_VTYPE_IDX_MASK;
if (idx == GE_VTYPE_IDX_8BIT) {
const u8 *ind8 = (const u8 *)inds;
if (idx == GE_VTYPE_IDX_16BIT) {
uint16_t upperBound = 0;
uint16_t lowerBound = 0xFFFF;
const u16_le *ind16 = (const u16_le *)inds;
for (int i = 0; i < count; i++) {
u8 value = ind8[i];
u16 value = ind16[i];
if (value > upperBound)
upperBound = value;
if (value < lowerBound)
lowerBound = value;
}
} else if (idx == GE_VTYPE_IDX_16BIT) {
const u16_le *ind16 = (const u16_le *)inds;
*indexLowerBound = lowerBound;
*indexUpperBound = upperBound;
} else if (idx == GE_VTYPE_IDX_8BIT) {
uint8_t upperBound = 0;
uint8_t lowerBound = 0xFF;
const u8 *ind8 = (const u8 *)inds;
for (int i = 0; i < count; i++) {
u16 value = ind16[i];
u8 value = ind8[i];
if (value > upperBound)
upperBound = value;
if (value < lowerBound)
lowerBound = value;
}
*indexLowerBound = lowerBound;
*indexUpperBound = upperBound;
} else if (idx == GE_VTYPE_IDX_32BIT) {
int lowerBound = 0x7FFFFFFF;
int upperBound = 0;
WARN_LOG_REPORT_ONCE(indexBounds32, G3D, "GetIndexBounds: Decoding 32-bit indexes");
const u32_le *ind32 = (const u32_le *)inds;
for (int i = 0; i < count; i++) {
Expand All @@ -143,12 +151,12 @@ void GetIndexBounds(const void *inds, int count, u32 vertType, u16 *indexLowerBo
if (value < lowerBound)
lowerBound = value;
}
*indexLowerBound = (u16)lowerBound;
*indexUpperBound = (u16)upperBound;
} else {
lowerBound = 0;
upperBound = count - 1;
*indexLowerBound = 0;
*indexUpperBound = count - 1;
}
*indexLowerBound = (u16)lowerBound;
*indexUpperBound = (u16)upperBound;
}

void PrintDecodedVertex(const VertexReader &vtx) {
Expand Down

0 comments on commit cf48532

Please sign in to comment.