question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[EmulGL] Unwind loops in gl_util

See original GitHub issue

gl_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:closed
  • Created a year ago
  • Reactions:1
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
valb3rcommented, May 1, 2022

Basically new version outperforms 3-4 times old version

0reactions
jzy3dcommented, Jun 29, 2022

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found