From b76cebdc8a7d26bd108a50abc81a51d0f27d621d Mon Sep 17 00:00:00 2001 From: Michael McConville Date: Thu, 17 Dec 2015 22:43:48 -0500 Subject: [PATCH] Beautify ISAAC's mixing arithmetic Call me verbose, but the existing logic was hideously formatted. The result still fits in a small terminal. No functional change. --- src/librand/isaac.rs | 78 +++++++++++++++++++++++++++++++++++--------- 1 file changed, 62 insertions(+), 16 deletions(-) diff --git a/src/librand/isaac.rs b/src/librand/isaac.rs index dd99bc93ef3..28eff87bde3 100644 --- a/src/librand/isaac.rs +++ b/src/librand/isaac.rs @@ -77,14 +77,37 @@ fn init(&mut self, use_rsl: bool) { macro_rules! mix { () => {{ - a=a^(b<<11); d=d+a; b=b+c; - b=b^(c>>2); e=e+b; c=c+d; - c=c^(d<<8); f=f+c; d=d+e; - d=d^(e>>16); g=g+d; e=e+f; - e=e^(f<<10); h=h+e; f=f+g; - f=f^(g>>4); a=a+f; g=g+h; - g=g^(h<<8); b=b+g; h=h+a; - h=h^(a>>9); c=c+h; a=a+b; + a = a ^ (b << 11); + d = d + a; + b = b + c; + + b = b ^ (c >> 2); + e = e + b; + c = c + d; + + c = c ^ (d << 8); + f = f + c; + d = d + e; + + d = d ^ (e >> 16); + g = g + d; + e = e + f; + + e = e ^ (f << 10); + h = h + e; + f = f + g; + + f = f ^ (g >> 4); + a = a + f; + g = g + h; + + g = g ^ (h << 8); + b = b + g; + h = h + a; + + h = h ^ (a >> 9); + c = c + h; + a = a + b; }} } @@ -337,14 +360,37 @@ macro_rules! init { macro_rules! mix { () => {{ - a=a-e; f=f^(h>>9); h=h+a; - b=b-f; g=g^(a<<9); a=a+b; - c=c-g; h=h^(b>>23); b=b+c; - d=d-h; a=a^(c<<15); c=c+d; - e=e-a; b=b^(d>>14); d=d+e; - f=f-b; c=c^(e<<20); e=e+f; - g=g-c; d=d^(f>>17); f=f+g; - h=h-d; e=e^(g<<14); g=g+h; + a = a - e; + f = f ^ (h >> 9); + h = h + a; + + b = b - f; + g = g ^ (a << 9); + a = a + b; + + c = c - g; + h = h ^ (b >> 23); + b = b + c; + + d = d - h; + a = a ^ (c << 15); + c = c + d; + + e = e - a; + b = b ^ (d >> 14); + d = d + e; + + f = f - b; + c = c ^ (e << 20); + e = e + f; + + g = g - c; + d = d ^ (f >> 17); + f = f + g; + + h = h - d; + e = e ^ (g << 14); + g = g + h; }} }