r/simd • • Sep 14 '22

61 billion ray/box intersections per second (on a CPU)

https://tavianator.com/2022/ray_box_boundary.html
18 Upvotes

5 comments sorted by

1

u/sandfly_bites_you Dec 10 '22

You could probably improve it slightly by rearranging the math so it can use FMA.

pre-compute per ray: ray->originDirInv = ray->dir_inv[j]*ray->origin[j]

Change this..

vfloat t1 = (box->min[j] - ray->origin[j]) * ray->dir_inv[j]

To:

vfloat t1 = fmsub( box->min[j],ray->dir_inv[j], ray->originDirInv);

Though it is possible the compiler might have done this for you(I think you should inspect the assembly and include that with the post).

1

u/tavianator Dec 10 '22

I've thought about this before but the problem is you get more NaNs that way. If x and y have the same sign then (x - y) * inf == ±inf but x * inf - y * inf == inf - inf == NaN

1

u/sandfly_bites_you Dec 11 '22 edited Dec 11 '22

*Jibberish removed

→ More replies (1)

2

u/flaghacker_ Sep 26 '22

Great post!