summaryrefslogtreecommitdiffstats
path: root/rand.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2014-12-16 19:43:55 -0800
committerKaz Kylheku <kaz@kylheku.com>2014-12-16 19:43:55 -0800
commit0cc11cca918820e2e54b9b13497e54536fd4a6e5 (patch)
treea5bcbc1750e723647ec489fa299ea1dd3c002cc7 /rand.c
parentbdde09352bed633ac31ca898d4dc3141ac1153d2 (diff)
downloadtxr-0cc11cca918820e2e54b9b13497e54536fd4a6e5.tar.gz
txr-0cc11cca918820e2e54b9b13497e54536fd4a6e5.tar.bz2
txr-0cc11cca918820e2e54b9b13497e54536fd4a6e5.zip
* rand.c (rstate): New inline function.
(rand32): Use inline function instead of macro. I compared gcc -O2 output on Intel: no difference.
Diffstat (limited to 'rand.c')
-rw-r--r--rand.c19
1 files changed, 11 insertions, 8 deletions
diff --git a/rand.c b/rand.c
index 396bb459..9a1e9d82 100644
--- a/rand.c
+++ b/rand.c
@@ -83,25 +83,28 @@ val random_state_p(val obj)
return typeof(obj) == random_state_s ? t : nil;
}
+INLINE rand32_t *rstate(struct rand_state *r, int offs)
+{
+ return &r->state[(r->cur + offs) % 16];
+}
+
static rand32_t rand32(struct rand_state *r)
{
- #define RSTATE(r,i) ((r)->state[((r)->cur + i) % 16])
- rand32_t s0 = RSTATE(r, 0);
- rand32_t s9 = RSTATE(r, 9);
- rand32_t s13 = RSTATE(r, 13);
- rand32_t s15 = RSTATE(r, 15);
+ rand32_t s0 = *rstate(r, 0);
+ rand32_t s9 = *rstate(r, 9);
+ rand32_t s13 = *rstate(r, 13);
+ rand32_t s15 = *rstate(r, 15);
rand32_t r1 = s0 ^ (s0 << 16) ^ s13 ^ (s13 << 15);
rand32_t r2 = s9 ^ (s9 >> 11);
- rand32_t ns0 = RSTATE(r, 0) = r1 ^ r2;
+ rand32_t ns0 = *rstate(r, 0) = r1 ^ r2;
rand32_t ns15 = s15 ^ (s15 << 2) ^ r1 ^ (r1 << 18) ^ r2 ^ (r2 << 28) ^
((ns0 ^ (ns0 << 5)) & 0xda442d24ul);
- RSTATE(r, 15) = ns15;
+ *rstate(r, 15) = ns15;
r->cur = (r->cur + 15) % 16;
return ns15;
- #undef RSTATE
}
val make_random_state(val seed)