aboutsummaryrefslogtreecommitdiff
path: root/lmathlib.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2018-03-09 12:05:13 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2018-03-09 12:05:13 -0300
commit0b3db69e4102c148b45a4491ef533ff449b0b927 (patch)
tree52f78ebddc61666196d955b2719094747a837474 /lmathlib.c
parent80ae1c1c16991ef37c7360aa12da9acc68e1c0ac (diff)
downloadlua-0b3db69e4102c148b45a4491ef533ff449b0b927.tar.gz
lua-0b3db69e4102c148b45a4491ef533ff449b0b927.tar.bz2
lua-0b3db69e4102c148b45a4491ef533ff449b0b927.zip
slight simplification in 'xorshift128plus'
Diffstat (limited to 'lmathlib.c')
-rw-r--r--lmathlib.c20
1 files changed, 11 insertions, 9 deletions
diff --git a/lmathlib.c b/lmathlib.c
index e8898396..062da4a0 100644
--- a/lmathlib.c
+++ b/lmathlib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lmathlib.c,v 1.120 2018/03/05 14:07:48 roberto Exp roberto $ 2** $Id: lmathlib.c,v 1.121 2018/03/09 14:56:25 roberto Exp roberto $
3** Standard mathematical library 3** Standard mathematical library
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -268,7 +268,7 @@ static I xorshift128plus (I *state) {
268 I y = state[1]; 268 I y = state[1];
269 state[0] = y; 269 state[0] = y;
270 x ^= x << 23; 270 x ^= x << 23;
271 state[1] = x ^ y ^ (x >> 18) ^ (y >> 5); 271 state[1] = (x ^ (x >> 18)) ^ (y ^ (y >> 5));
272 return state[1] + y; 272 return state[1] + y;
273} 273}
274 274
@@ -318,12 +318,14 @@ static I pack (int x1, int x2) {
318 return result; 318 return result;
319} 319}
320 320
321static I Ishl (I i, int n) { 321/* i ^ (i << n) */
322 return pack((i.x1 << n) | (i.x2 >> (32 - n)), i.x2 << n); 322static I Ixorshl (I i, int n) {
323 return pack(i.x1 ^ ((i.x1 << n) | (i.x2 >> (32 - n))), i.x2 ^ (i.x2 << n));
323} 324}
324 325
325static I Ishr (I i, int n) { 326/* i ^ (i >> n) */
326 return pack(i.x1 >> n, (i.x2 >> n) | (i.x1 << (32 - n))); 327static I Ixorshr (I i, int n) {
328 return pack(i.x1 ^ (i.x1 >> n), i.x2 ^ ((i.x2 >> n) | (i.x1 << (32 - n))));
327} 329}
328 330
329static I Ixor (I i1, I i2) { 331static I Ixor (I i1, I i2) {
@@ -345,9 +347,9 @@ static I xorshift128plus (I *state) {
345 I x = state[0]; 347 I x = state[0];
346 I y = state[1]; 348 I y = state[1];
347 state[0] = y; 349 state[0] = y;
348 x = Ixor(x, Ishl(x, 23)); /* x ^= x << 23; */ 350 x = Ixorshl(x, 23); /* x ^= x << 23; */
349 /* s[1] = x ^ y ^ (x >> 18) ^ (y >> 5); */ 351 /* state[1] = (x ^ (x >> 18)) ^ (y ^ (y >> 5)); */
350 state[1] = Ixor(Ixor(Ixor(x, y), Ishr(x, 18)), Ishr(y, 5)); 352 state[1] = Ixor(Ixorshr(x, 18), Ixorshr(y, 5));
351 return Iadd(state[1], y); /* return state[1] + y; */ 353 return Iadd(state[1], y); /* return state[1] + y; */
352} 354}
353 355