Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bitshifting instead of multiplying in frustum #7

Closed
GoogleCodeExporter opened this issue Mar 27, 2016 · 6 comments
Closed

Bitshifting instead of multiplying in frustum #7

GoogleCodeExporter opened this issue Mar 27, 2016 · 6 comments

Comments

@GoogleCodeExporter
Copy link

mat4.frustum = function(left, right, bottom, top, near, far, dest) {
    dest[0] = near << 1 / (right - left);
    dest[1] = 0;
    dest[2] = 0;
    dest[3] = 0;
    dest[4] = 0;
    dest[5] = near << 1 / (top - bottom);
    dest[6] = 0;
    dest[7] = 0;
    dest[8] = (right + left) / (right - left);
    dest[9] = (top + bottom) / (top - bottom);
    dest[10] = -(far + near) / (far - near);
    dest[11] = -1;
    dest[12] = 0;
    dest[13] = 0;
    dest[14] = -(far * near << 1) / (far - near);
    dest[15] = 0;
    return dest;
};

Shaves about 6% from benchmark here.




Proof with microbenchmark:

<html>
<script type="text/javascript">

var d = new Date();
var i = 100;
for (var a = 0; a < 10000000; a++) {
    var i = i << 1;
}
var e = new Date() - d;

var f = new Date();
var i = 100;
for (var a = 0; a < 10000000; a++) {
    var i = i * 2;
}
var g = new Date() - f;

alert(e);
alert(g);
</script>
</html>

Original issue reported on code.google.com by danielhe...@gmail.com on 5 Jun 2010 at 7:51

@GoogleCodeExporter
Copy link
Author

Hmm... very interesting! I'm curious, though: Is bitshifting widely supported 
by the 
browsers? (Or, at the very least, WebGL enabled browsers?)

Original comment by Tojiro@gmail.com on 5 Jun 2010 at 8:32

@GoogleCodeExporter
Copy link
Author

Yes for sure. It is at least in the ECMAscript 262 first edition from 1997
http://www.mozilla.org/js/language/E262.pdf ) so I think we can assume it works!

Original comment by danielhe...@gmail.com on 5 Jun 2010 at 9:02

@GoogleCodeExporter
Copy link
Author

Excellent! I'll see if I can work it in, then!

Original comment by Tojiro@gmail.com on 7 Jun 2010 at 3:14

@GoogleCodeExporter
Copy link
Author

Original comment by Tojiro@gmail.com on 12 Jun 2010 at 5:19

  • Added labels: Type-Optimization
  • Removed labels: Type-Defect

@GoogleCodeExporter
Copy link
Author

Original comment by Tojiro@gmail.com on 12 Jun 2010 at 5:28

  • Changed state: Started

@GoogleCodeExporter
Copy link
Author

Original comment by Tojiro@gmail.com on 13 Jun 2010 at 4:13

  • Changed state: Fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant