[qfvis] Replace modulo and SISD cross-product

At least modern gcc produces nice code for ?: (cmov), and a SIMD
cross-product uses several fewer instructions. The cross-product shaved
off 0.5-1s, but the modulo -> ?: shaved off about 3-4s, for a total of
about 10% speedup (1.09 insn/cyc vs 1.01 insn/cyc, so even perf agrees).
This commit is contained in:
Bill Currie 2022-11-19 20:49:13 +09:00
parent 2a8c12426d
commit d283f07890
2 changed files with 8 additions and 13 deletions

View file

@ -139,16 +139,11 @@ calc_plane (vec4f_t v1, vec4f_t v2, int flip, vec4f_t p, vec4f_t *plane)
if (flip < 0) {
//CrossProduct (v2, v1, plane.normal);
(*plane)[0] = v2[1] * v1[2] - v2[2] * v1[1];
(*plane)[1] = v2[2] * v1[0] - v2[0] * v1[2];
(*plane)[2] = v2[0] * v1[1] - v2[1] * v1[0];
*plane = crossf (v2, v1);
} else {
//CrossProduct (v1, v2, plane.normal);
(*plane)[0] = v1[1] * v2[2] - v1[2] * v2[1];
(*plane)[1] = v1[2] * v2[0] - v1[0] * v2[2];
(*plane)[2] = v1[0] * v2[1] - v1[1] * v2[0];
*plane = crossf (v1, v2);
}
(*plane)[3] = 0;
length = dotf (*plane, *plane);
@ -162,16 +157,16 @@ calc_plane (vec4f_t v1, vec4f_t v2, int flip, vec4f_t p, vec4f_t *plane)
}
static inline int
test_plane (vec4f_t plane, const winding_t *pass, int index)
test_plane (vec4f_t plane, const winding_t *pass, unsigned index)
{
int s1, s2;
int k;
vec4f_t d;
k = (index + 1) % pass->numpoints;
k = index + 1 == pass->numpoints ? 0 : index + 1;
d = dotf (pass->points[k], plane);
s1 = test_zero (d[0]);
k = (index + pass->numpoints - 1) % pass->numpoints;
k = (index == 0 ? pass->numpoints : index) - 1;
d = dotf (pass->points[k], plane);
s2 = test_zero (d[0]);
if (s1 == 0 && s2 == 0)
@ -239,7 +234,7 @@ FindSeparators (threaddata_t *thread,
sep_t *separators = 0, *sep;
for (i = 0; i < source->numpoints; i++) {
l = (i + 1) % source->numpoints;
l = (i + 1) == source->numpoints ? 0 : i + 1;
v1 = source->points[l] - source->points[i];
for (j = 0; j < pass->numpoints; j++) {

View file

@ -372,8 +372,8 @@ ClipWinding (threaddata_t *thread, winding_t *in, vec4f_t split,
if (sides[i + 1] == SIDE_ON || sides[i + 1] == sides[i]) {
continue;
}
vec4f_t mid = split_edge (in->points, dists, i,
(i + 1) % in->numpoints, split);
unsigned j = (i + 1) == in->numpoints ? 0 : i + 1;
vec4f_t mid = split_edge (in->points, dists, i, j, split);
neww->points[neww->numpoints++] = mid;
}