1/* SPDX-License-Identifier: GPL-2.0 */ 2/* 3 * Fast, simple, yet decent quality random number generator based on 4 * a paper by David G. Carta ("Two Fast Implementations of the 5 * `Minimal Standard' Random Number Generator," Communications of the 6 * ACM, January, 1990). 7 * 8 * Copyright (C) 2002 Hewlett-Packard Co 9 * David Mosberger-Tang <davidm@hpl.hp.com> 10 */ 11 12#include <asm/asmmacro.h> 13 14#define a r2 15#define m r3 16#define lo r8 17#define hi r9 18#define t0 r16 19#define t1 r17 20#define seed r32 21 22GLOBAL_ENTRY(carta_random32) 23 movl a = (16807 << 16) | 16807 24 ;; 25 pmpyshr2.u t0 = a, seed, 0 26 pmpyshr2.u t1 = a, seed, 16 27 ;; 28 unpack2.l t0 = t1, t0 29 dep m = -1, r0, 0, 31 30 ;; 31 zxt4 lo = t0 32 shr.u hi = t0, 32 33 ;; 34 dep t0 = 0, hi, 15, 49 // t0 = (hi & 0x7fff) 35 ;; 36 shl t0 = t0, 16 // t0 = (hi & 0x7fff) << 16 37 shr t1 = hi, 15 // t1 = (hi >> 15) 38 ;; 39 add lo = lo, t0 40 ;; 41 cmp.gtu p6, p0 = lo, m 42 ;; 43(p6) and lo = lo, m 44 ;; 45(p6) add lo = 1, lo 46 ;; 47 add lo = lo, t1 48 ;; 49 cmp.gtu p6, p0 = lo, m 50 ;; 51(p6) and lo = lo, m 52 ;; 53(p6) add lo = 1, lo 54 br.ret.sptk.many rp 55END(carta_random32) 56