1 /* $NetBSD: random.S,v 1.4 2008/04/28 20:24:06 martin Exp $ */
4 * Copyright (c) 1998 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Charles M. Hannum.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
33 * Copyright (c) 1990,1993 The Regents of the University of California.
34 * All rights reserved.
36 * Redistribution and use in source and binary forms, with or without
37 * modification, are permitted provided that: (1) source code distributions
38 * retain the above copyright notice and this paragraph in its entirety, (2)
39 * distributions including binary code include the above copyright notice and
40 * this paragraph in its entirety in the documentation or other materials
41 * provided with the distribution, and (3) all advertising materials mentioning
42 * features or use of this software display the following acknowledgement:
43 * ``This product includes software developed by the University of California,
44 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
45 * the University nor the names of its contributors may be used to endorse
46 * or promote products derived from this software without specific prior
48 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
49 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
50 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
52 * Here is a very good random number generator. This implementation is
53 * based on ``Two Fast Implementations of the "Minimal Standard" Random
54 * Number Generator'', David G. Carta, Communications of the ACM, Jan 1990,
55 * Vol 33 No 1. Do NOT modify this code unless you have a very thorough
56 * understanding of the algorithm. It's trickier than you think. If
57 * you do change it, make sure that its 10,000'th invocation returns
60 * Here is easier-to-decipher pseudocode:
62 * p = (16807*seed)<30:0> # e.g., the low 31 bits of the product
63 * q = (16807*seed)<62:31> # e.g., the high 31 bits starting at bit 32
67 * seed = ((p + q) & (2^31 - 1)) + 1
70 * The result is in (0,2^31), e.g., it's always positive.
72 #include <machine/asm.h>
81 imull PIC_GOTOFF(randseed)
88 movl %eax,PIC_GOTOFF(randseed)
94 movl %eax,PIC_GOTOFF(randseed)