Skip to content

Commit

Permalink
Upgrade SFMT to 1.5.1
Browse files Browse the repository at this point in the history
  • Loading branch information
shawnw committed May 30, 2017
1 parent 488def8 commit df8c48b
Show file tree
Hide file tree
Showing 12 changed files with 932 additions and 513 deletions.
3 changes: 3 additions & 0 deletions CHANGES.186
Expand Up @@ -17,6 +17,9 @@ Version 1.8.6 patchlevel 2 ??? ??, 20??
Fixes:
* Fix compilation errors with OpenSSL 1.1. [SW]

Minor changes:
* Upgrade random number generator to SFMT 1.5.1. [SW]

Version 1.8.6 patchlevel 1 Mar 29, 2017

Major changes:
Expand Down
48 changes: 8 additions & 40 deletions COPYRITE
Expand Up @@ -187,7 +187,10 @@
+ Penn includes the SIMD-oriented Fast Mersenne Twister PRNG:

Copyright (c) 2006,2007 Mutsuo Saito, Makoto Matsumoto and Hiroshima
University. All rights reserved.
University.
Copyright (c) 2012 Mutsuo Saito, Makoto Matsumoto, Hiroshima University
and The University of Tokyo.
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
Expand All @@ -199,10 +202,10 @@ met:
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* Neither the name of the Hiroshima University nor the names of
its contributors may be used to endorse or promote products
derived from this software without specific prior written
permission.
* Neither the names of Hiroshima University, The University of
Tokyo nor the names of its contributors may be used to endorse
or promote products derived from this software without specific
prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
Expand All @@ -215,38 +218,3 @@ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

+ Penn includes a heavily modified old version of the Perl Compatible
Regular Expression library:

Written by Philip Hazel
Copyright (c) 1997-2005 University of Cambridge

-----------------------------------------------------------------------------
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.

* Neither the name of the University of Cambridge nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
-----------------------------------------------------------------------------

175 changes: 84 additions & 91 deletions hdrs/SFMT-alti.h
Expand Up @@ -19,9 +19,9 @@
#define SFMT_ALTI_H

inline static vector unsigned int vec_recursion(vector unsigned int a,
vector unsigned int b,
vector unsigned int c,
vector unsigned int d);
vector unsigned int b,
vector unsigned int c,
vector unsigned int d);

/**
* This function represents the recursion formula in AltiVec and BIG ENDIAN.
Expand All @@ -31,61 +31,58 @@ inline static vector unsigned int vec_recursion(vector unsigned int a,
* @param d a 128-bit part of the interal state array
* @return output
*/
inline static vector unsigned int
vec_recursion(vector unsigned int a,
vector unsigned int b,
vector unsigned int c, vector unsigned int d)
{
inline static vector unsigned int vec_recursion(vector unsigned int a,
vector unsigned int b,
vector unsigned int c,
vector unsigned int d) {

const vector unsigned int sl1 = SFMT_ALTI_SL1;
const vector unsigned int sr1 = SFMT_ALTI_SR1;
const vector unsigned int sl1 = SFMT_ALTI_SL1;
const vector unsigned int sr1 = SFMT_ALTI_SR1;
#ifdef ONLY64
const vector unsigned int mask = SFMT_ALTI_MSK64;
const vector unsigned char perm_sl = SFMT_ALTI_SL2_PERM64;
const vector unsigned char perm_sr = SFMT_ALTI_SR2_PERM64;
const vector unsigned int mask = SFMT_ALTI_MSK64;
const vector unsigned char perm_sl = SFMT_ALTI_SL2_PERM64;
const vector unsigned char perm_sr = SFMT_ALTI_SR2_PERM64;
#else
const vector unsigned int mask = SFMT_ALTI_MSK;
const vector unsigned char perm_sl = SFMT_ALTI_SL2_PERM;
const vector unsigned char perm_sr = SFMT_ALTI_SR2_PERM;
const vector unsigned int mask = SFMT_ALTI_MSK;
const vector unsigned char perm_sl = SFMT_ALTI_SL2_PERM;
const vector unsigned char perm_sr = SFMT_ALTI_SR2_PERM;
#endif
vector unsigned int v, w, x, y, z;
x = vec_perm(a, (vector unsigned int) perm_sl, perm_sl);
v = a;
y = vec_sr(b, sr1);
z = vec_perm(c, (vector unsigned int) perm_sr, perm_sr);
w = vec_sl(d, sl1);
z = vec_xor(z, w);
y = vec_and(y, mask);
v = vec_xor(v, x);
z = vec_xor(z, y);
z = vec_xor(z, v);
return z;
vector unsigned int v, w, x, y, z;
x = vec_perm(a, (vector unsigned int)perm_sl, perm_sl);
v = a;
y = vec_sr(b, sr1);
z = vec_perm(c, (vector unsigned int)perm_sr, perm_sr);
w = vec_sl(d, sl1);
z = vec_xor(z, w);
y = vec_and(y, mask);
v = vec_xor(v, x);
z = vec_xor(z, y);
z = vec_xor(z, v);
return z;
}

/**
* This function fills the internal state array with pseudorandom
* integers.
*/
void
sfmt_gen_rand_all(sfmt_t * sfmt)
{
int i;
vector unsigned int r, r1, r2;
void sfmt_gen_rand_all(sfmt_t * sfmt) {
int i;
vector unsigned int r, r1, r2;

r1 = sfmt->state[N - 2].s;
r2 = sfmt->state[N - 1].s;
for (i = 0; i < N - POS1; i++) {
r = vec_recursion(sfmt->state[i].s, sfmt->state[i + POS1].s, r1, r2);
sfmt->state[i].s = r;
r1 = r2;
r2 = r;
}
for (; i < N; i++) {
r = vec_recursion(sfmt->state[i].s, sfmt->state[i + POS1 - N].s, r1, r2);
sfmt->state[i].s = r;
r1 = r2;
r2 = r;
}
r1 = sfmt->state[N - 2].s;
r2 = sfmt->state[N - 1].s;
for (i = 0; i < N - POS1; i++) {
r = vec_recursion(sfmt->state[i].s, sfmt->state[i + POS1].s, r1, r2);
sfmt->state[i].s = r;
r1 = r2;
r2 = r;
}
for (; i < N; i++) {
r = vec_recursion(sfmt->state[i].s, sfmt->state[i + POS1 - N].s, r1, r2);
sfmt->state[i].s = r;
r1 = r2;
r2 = r;
}
}

/**
Expand All @@ -95,43 +92,41 @@ sfmt_gen_rand_all(sfmt_t * sfmt)
* @param array an 128-bit array to be filled by pseudorandom numbers.
* @param size number of 128-bit pesudorandom numbers to be generated.
*/
inline static void
gen_rand_array(sfmt_t * sfmt, w128_t * array, int size)
{
int i, j;
vector unsigned int r, r1, r2;
inline static void gen_rand_array(sfmt_t * sfmt, w128_t *array, int size) {
int i, j;
vector unsigned int r, r1, r2;

r1 = sfmt->state[N - 2].s;
r2 = sfmt->state[N - 1].s;
for (i = 0; i < N - POS1; i++) {
r = vec_recursion(sfmt->state[i].s, sfmt->state[i + POS1].s, r1, r2);
array[i].s = r;
r1 = r2;
r2 = r;
}
for (; i < N; i++) {
r = vec_recursion(sfmt->state[i].s, array[i + POS1 - N].s, r1, r2);
array[i].s = r;
r1 = r2;
r2 = r;
}
/* main loop */
for (; i < size - N; i++) {
r = vec_recursion(array[i - N].s, array[i + POS1 - N].s, r1, r2);
array[i].s = r;
r1 = r2;
r2 = r;
}
for (j = 0; j < 2 * N - size; j++) {
sfmt->state[j].s = array[j + size - N].s;
}
for (; i < size; i++) {
r = vec_recursion(array[i - N].s, array[i + POS1 - N].s, r1, r2);
array[i].s = r;
sfmt->state[j++].s = r;
r1 = r2;
r2 = r;
}
r1 = sfmt->state[N - 2].s;
r2 = sfmt->state[N - 1].s;
for (i = 0; i < N - POS1; i++) {
r = vec_recursion(sfmt->state[i].s, sfmt->state[i + POS1].s, r1, r2);
array[i].s = r;
r1 = r2;
r2 = r;
}
for (; i < N; i++) {
r = vec_recursion(sfmt->state[i].s, array[i + POS1 - N].s, r1, r2);
array[i].s = r;
r1 = r2;
r2 = r;
}
/* main loop */
for (; i < size - N; i++) {
r = vec_recursion(array[i - N].s, array[i + POS1 - N].s, r1, r2);
array[i].s = r;
r1 = r2;
r2 = r;
}
for (j = 0; j < 2 * N - size; j++) {
sfmt->state[j].s = array[j + size - N].s;
}
for (; i < size; i++) {
r = vec_recursion(array[i - N].s, array[i + POS1 - N].s, r1, r2);
array[i].s = r;
sfmt->state[j++].s = r;
r1 = r2;
r2 = r;
}
}

#ifndef ONLY64
Expand All @@ -148,15 +143,13 @@ gen_rand_array(sfmt_t * sfmt, w128_t * array, int size)
* @param array an 128-bit array to be swaped.
* @param size size of 128-bit array.
*/
inline static void
swap(w128_t * array, int size)
{
int i;
const vector unsigned char perm = SFMT_ALTI_SWAP;
inline static void swap(w128_t *array, int size) {
int i;
const vector unsigned char perm = SFMT_ALTI_SWAP;

for (i = 0; i < size; i++) {
array[i].s = vec_perm(array[i].s, (vector unsigned int) perm, perm);
}
for (i = 0; i < size; i++) {
array[i].s = vec_perm(array[i].s, (vector unsigned int)perm, perm);
}
}
#endif

Expand Down

0 comments on commit df8c48b

Please sign in to comment.