/* Template Code of a Random Number Generator for Vitis HLS Combined Tausworthe : an example of 31-bit TW module */ /* This code is based on the code in JIS Z 9031:2012, pp.54-55. */ /* Copyright (C) 2022, Yuto Asaumi and Tomonori Izumi, All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. 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. 3. The names of its contributors may not 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. Any feedback is very welcome. http://www.ritsumei.ac.jp/se/re/izumilab/dist/RNG/ */ #include #include #include #include /* seeds generated by a seed 19660809 */ #define SEED1 19660809u #define SEED2 2552272502u #define SEED3 1730193407u #define p1 31 #define q1 13 #define t1 12 #define p2 29 #define q2 2 #define t2 4 #define p3 28 #define q3 3 #define t3 17 typedef ap_uint<32> AXI_VALUE; typedef hls::stream AXI_STREAM; void random_generator(AXI_STREAM& random_out){ #pragma HLS PIPELINE #pragma HLS INTERFACE axis port=random_out #pragma HLS INTERFACE ap_ctrl_none port=return static AXI_VALUE s1 = SEED1, s2 = SEED2, s3 = SEED3; const AXI_VALUE m1 = (~0u) << (32 - (p1-t1)); const AXI_VALUE m2 = (~0u) << (32 - (p2-t2)); const AXI_VALUE m3 = (~0u) << (32 - (p3-t3)); AXI_VALUE n; s1 = ((s1 << t1) & m1) ^ ((s1 >> (p1-t1-q1)) & ~m1) ^ (s1 >> (p1-t1)); s2 = ((s2 << t2) & m2) ^ ((s2 >> (p2-t2-q2)) & ~m2) ^ (s2 >> (p2-t2)); s3 = ((s3 << t3) & m3) ^ ((s3 >> (p3-t3-q3)) & ~m3) ^ (s3 >> (p3-t3)); n = ((s1 ^ s2 ^ s3) >> (32 - p1)); random_out << n; }