diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2018-03-09 12:05:13 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2018-03-09 12:05:13 -0300 |
commit | 0b3db69e4102c148b45a4491ef533ff449b0b927 (patch) | |
tree | 52f78ebddc61666196d955b2719094747a837474 /lmathlib.c | |
parent | 80ae1c1c16991ef37c7360aa12da9acc68e1c0ac (diff) | |
download | lua-0b3db69e4102c148b45a4491ef533ff449b0b927.tar.gz lua-0b3db69e4102c148b45a4491ef533ff449b0b927.tar.bz2 lua-0b3db69e4102c148b45a4491ef533ff449b0b927.zip |
slight simplification in 'xorshift128plus'
Diffstat (limited to 'lmathlib.c')
-rw-r--r-- | lmathlib.c | 20 |
1 files changed, 11 insertions, 9 deletions
@@ -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 | ||
321 | static I Ishl (I i, int n) { | 321 | /* i ^ (i << n) */ |
322 | return pack((i.x1 << n) | (i.x2 >> (32 - n)), i.x2 << n); | 322 | static 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 | ||
325 | static I Ishr (I i, int n) { | 326 | /* i ^ (i >> n) */ |
326 | return pack(i.x1 >> n, (i.x2 >> n) | (i.x1 << (32 - n))); | 327 | static 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 | ||
329 | static I Ixor (I i1, I i2) { | 331 | static 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 | ||