[EmulGL] Unwind loops in gl_util
See original GitHub issuegl_util
contains lots of unneeded if
checks and its matrix-matrix, vector-vector multiplication is done in a loop way that can be unwounded. With JDK 18 and Vector API it would yield even more improvement.
I.e.:
public static float[] mulMatrix41(float a[], float b[]) {
// assume a = 4x4, b = 4x1
float temp[] = new float[4];
int i, j, x;
for (i = 0; i < 4; i++) {
for (j = 0; j < 4; j++) {
x = j << 2 | i;
if (a[x] != 0 && b[j] != 0) {
if (a[x] == 1) {
temp[i] += b[j];
} else if (b[j] == 1) {
temp[i] += a[x];
} else {
temp[i] += a[x] * b[j];
}
}
}
}
return temp;
}
Can be unwound to:
float temp[] = new float[4];
temp[0] += a[0] * b[0];
temp[0] += a[4] * b[1];
temp[0] += a[8] * b[2];
temp[0] += a[12] * b[3];
temp[1] += a[1] * b[0];
temp[1] += a[5] * b[1];
temp[1] += a[9] * b[2];
temp[1] += a[13] * b[3];
temp[2] += a[2] * b[0];
temp[2] += a[6] * b[1];
temp[2] += a[10] * b[2];
temp[2] += a[14] * b[3];
temp[3] += a[3] * b[0];
temp[3] += a[7] * b[1];
temp[3] += a[11] * b[2];
temp[3] += a[15] * b[3];
return temp;
Issue Analytics
- State:
- Created a year ago
- Reactions:1
- Comments:5 (5 by maintainers)
Top Results From Across the Web
Prevent loop unwinding in fragment shader - glsl
I do question what it is that you are doing that requires so much looping, though. Shaders are not really the right place...
Read more >Understanding Loop Unwinding - The CPROVER Manual
Iteration-based Unwinding. The basic idea of CBMC is to model a program's execution up to a bounded number of steps. Technically, this is...
Read more >Full text of "Popular Mechanics ~ 1940" - Internet Archive
Loop In end of line to change fishhooks. ... , . . , Mirror held on tent pole with ... Ttivre Is a...
Read more >understanding-npm/names.json at master - GitHub
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may...
Read more >Untitled
n u t tn r»'(!1l*«<l tr, St'tirsr Slot fils (p-r glut il*> nf p,ij|.j*N '*• No smorgasbord | ... closed again, and only...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Basically new version outperforms 3-4 times old version
Useful info related to unwinding loops : I went into GLU to debug a 3D to 2D projection stuff and noticed a lot of for loops for matrix operations in the GLU class. For the record they’re used mainly in gluProject / gluUnProject. These primitives are used for 3D text position on screen and mouse selection (hitting 3D world from a mouse click), so not that often, but worth knowing.