From a9fd902610a81d0bcbfde0fbc7377d839a41ffa2 Mon Sep 17 00:00:00 2001 From: Morten Hustveit Date: Tue, 2 Dec 2014 16:20:36 -0500 Subject: ray.c: Use __builtin_expect to mark sphere collisions as unlikely This saves 10ms/frame on yelena. --- ray.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'ray.c') diff --git a/ray.c b/ray.c index 96a605a..64f8810 100644 --- a/ray.c +++ b/ray.c @@ -16,6 +16,14 @@ #define TAU 6.28318531 +#if __GNUC__ >= 3 +# define unlikely(cond) __builtin_expect ((cond), 0) +# define likely(cond) __builtin_expect ((cond), 1) +#else +# define unlikely(cond) (cond) +# define likely(cond) (cond) +#endif + typedef struct { float position[3]; float radius; @@ -56,7 +64,7 @@ trace(const float s[3], const float d[3], float pixel[3], int n, unsigned int ma t = sphere_intersect(y, r, s, d, objects[j].position, objects[j].radius); - if(t > 0) { + if(unlikely(t > 0)) { for(m = 0; m < LENGTH(lights); ++m) { for(i = 0; i < 3; ++i) l[i] = lights[m].position[i] - y[i]; -- cgit v1.2.3