| 1 |
2 |
guangxi.li |
/* Maximally equidistributed combined Tausworthe generator */
|
| 2 |
|
|
|
| 3 |
|
|
/*
|
| 4 |
|
|
* Copyright (C) 2014, Guangxi Liu <guangxi.liu@opencores.org>
|
| 5 |
|
|
*
|
| 6 |
|
|
* This source file may be used and distributed without restriction provided
|
| 7 |
|
|
* that this copyright statement is not removed from the file and that any
|
| 8 |
|
|
* derivative work contains the original copyright notice and the associated
|
| 9 |
|
|
* disclaimer.
|
| 10 |
|
|
*
|
| 11 |
|
|
* This source file is free software; you can redistribute it and/or modify it
|
| 12 |
|
|
* under the terms of the GNU Lesser General Public License as published by
|
| 13 |
|
|
* the Free Software Foundation; either version 2.1 of the License,
|
| 14 |
|
|
* or (at your option) any later version.
|
| 15 |
|
|
*
|
| 16 |
|
|
* This source is distributed in the hope that it will be useful, but
|
| 17 |
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
| 18 |
|
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
| 19 |
|
|
* License for more details.
|
| 20 |
|
|
*
|
| 21 |
|
|
* You should have received a copy of the GNU Lesser General Public License
|
| 22 |
|
|
* along with this source; if not, download it from
|
| 23 |
|
|
* http://www.opencores.org/lgpl.shtml
|
| 24 |
|
|
*/
|
| 25 |
|
|
|
| 26 |
|
|
|
| 27 |
|
|
#include "taus176.h"
|
| 28 |
|
|
|
| 29 |
|
|
|
| 30 |
|
|
/* Update state */
|
| 31 |
|
|
unsigned long long taus_get(taus_state_t *state)
|
| 32 |
|
|
{
|
| 33 |
|
|
unsigned long long b;
|
| 34 |
|
|
|
| 35 |
|
|
b = (((state->z1 << 5) ^ state->z1) >> 39);
|
| 36 |
|
|
state->z1 = (((state->z1 & 18446744073709551614ULL) << 24) ^ b);
|
| 37 |
|
|
b = (((state->z2 << 19) ^ state->z2) >> 45);
|
| 38 |
|
|
state->z2 = (((state->z2 & 18446744073709551552ULL) << 13) ^ b);
|
| 39 |
|
|
b = (((state->z3 << 24) ^ state->z3) >> 48);
|
| 40 |
|
|
state->z3 = (((state->z3 & 18446744073709551104ULL) << 7) ^ b);
|
| 41 |
|
|
|
| 42 |
|
|
return (state->z1 ^ state->z2 ^ state->z3);
|
| 43 |
|
|
}
|
| 44 |
|
|
|
| 45 |
|
|
|
| 46 |
|
|
/* Set state using seed */
|
| 47 |
|
|
#define LCG(n) (4294967291ULL * n)
|
| 48 |
|
|
|
| 49 |
|
|
void taus_set(taus_state_t *state, unsigned long s)
|
| 50 |
|
|
{
|
| 51 |
|
|
if (s == 0) s = 1; /* default seed is 1 */
|
| 52 |
|
|
|
| 53 |
|
|
state->z1 = LCG(s);
|
| 54 |
|
|
if (state->z1 < 2ULL) state->z1 += 2ULL;
|
| 55 |
|
|
state->z2 = LCG(state->z1);
|
| 56 |
|
|
if (state->z2 < 64ULL) state->z2 += 64ULL;
|
| 57 |
|
|
state->z3 = LCG(state->z2);
|
| 58 |
|
|
if (state->z3 < 512ULL) state->z3 += 512ULL;
|
| 59 |
|
|
|
| 60 |
|
|
/* "warm it up" */
|
| 61 |
|
|
taus_get(state);
|
| 62 |
|
|
taus_get(state);
|
| 63 |
|
|
taus_get(state);
|
| 64 |
|
|
taus_get(state);
|
| 65 |
|
|
taus_get(state);
|
| 66 |
|
|
taus_get(state);
|
| 67 |
|
|
taus_get(state);
|
| 68 |
|
|
taus_get(state);
|
| 69 |
|
|
taus_get(state);
|
| 70 |
|
|
taus_get(state);
|
| 71 |
|
|
}
|