Sun Jan 4 17:10:47 2009 UTC ()
Support PIC for inclusion in librump.  (m68k untested)


(pooka)
diff -r1.4 -r1.5 src/sys/lib/libkern/arch/i386/random.S
diff -r1.2 -r1.3 src/sys/lib/libkern/arch/m68k/random.S
diff -r1.1 -r1.2 src/sys/lib/libkern/arch/sparc/random.S
diff -r1.1.1.1 -r1.2 src/sys/lib/libkern/arch/sparc64/random.S

cvs diff -r1.4 -r1.5 src/sys/lib/libkern/arch/i386/random.S (switch to unified diff)

--- src/sys/lib/libkern/arch/i386/random.S 2008/04/28 20:24:06 1.4
+++ src/sys/lib/libkern/arch/i386/random.S 2009/01/04 17:10:46 1.5
@@ -1,90 +1,96 @@ @@ -1,90 +1,96 @@
1/* $NetBSD: random.S,v 1.4 2008/04/28 20:24:06 martin Exp $ */ 1/* $NetBSD: random.S,v 1.5 2009/01/04 17:10:46 pooka Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 1998 The NetBSD Foundation, Inc. 4 * Copyright (c) 1998 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Charles M. Hannum. 8 * by Charles M. Hannum.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright 15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the 16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution. 17 * documentation and/or other materials provided with the distribution.
18 * 18 *
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 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 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 21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 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 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 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 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE. 29 * POSSIBILITY OF SUCH DAMAGE.
30 */ 30 */
31 31
32/* 32/*
33 * Copyright (c) 1990,1993 The Regents of the University of California. 33 * Copyright (c) 1990,1993 The Regents of the University of California.
34 * All rights reserved. 34 * All rights reserved.
35 * 35 *
36 * Redistribution and use in source and binary forms, with or without 36 * Redistribution and use in source and binary forms, with or without
37 * modification, are permitted provided that: (1) source code distributions 37 * modification, are permitted provided that: (1) source code distributions
38 * retain the above copyright notice and this paragraph in its entirety, (2) 38 * retain the above copyright notice and this paragraph in its entirety, (2)
39 * distributions including binary code include the above copyright notice and 39 * distributions including binary code include the above copyright notice and
40 * this paragraph in its entirety in the documentation or other materials 40 * this paragraph in its entirety in the documentation or other materials
41 * provided with the distribution, and (3) all advertising materials mentioning 41 * provided with the distribution, and (3) all advertising materials mentioning
42 * features or use of this software display the following acknowledgement: 42 * features or use of this software display the following acknowledgement:
43 * ``This product includes software developed by the University of California, 43 * ``This product includes software developed by the University of California,
44 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of 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 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 46 * or promote products derived from this software without specific prior
47 * written permission. 47 * written permission.
48 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED 48 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
49 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF 49 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
50 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 50 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
51 * 51 *
52 * Here is a very good random number generator. This implementation is 52 * Here is a very good random number generator. This implementation is
53 * based on ``Two Fast Implementations of the "Minimal Standard" Random 53 * based on ``Two Fast Implementations of the "Minimal Standard" Random
54 * Number Generator'', David G. Carta, Communications of the ACM, Jan 1990, 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 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 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 57 * you do change it, make sure that its 10,000'th invocation returns
58 * 1043618065. 58 * 1043618065.
59 * 59 *
60 * Here is easier-to-decipher pseudocode: 60 * Here is easier-to-decipher pseudocode:
61 * 61 *
62 * p = (16807*seed)<30:0> # e.g., the low 31 bits of the product 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 63 * q = (16807*seed)<62:31> # e.g., the high 31 bits starting at bit 32
64 * if (p + q < 2^31) 64 * if (p + q < 2^31)
65 * seed = p + q 65 * seed = p + q
66 * else 66 * else
67 * seed = ((p + q) & (2^31 - 1)) + 1 67 * seed = ((p + q) & (2^31 - 1)) + 1
68 * return (seed); 68 * return (seed);
69 * 69 *
70 * The result is in (0,2^31), e.g., it's always positive. 70 * The result is in (0,2^31), e.g., it's always positive.
71 */ 71 */
72#include <machine/asm.h> 72#include <machine/asm.h>
73 73
74 .data 74 .data
75randseed: 75randseed:
76 .long 1 76 .long 1
77 .text 77 .text
78ENTRY(random) 78ENTRY(random)
79 movl $16807,%eax 79 movl $16807,%eax
80 imull randseed 80 PIC_PROLOGUE
 81 imull PIC_GOTOFF(randseed)
 82 PIC_EPILOGUE
81 shld $1,%eax,%edx 83 shld $1,%eax,%edx
82 andl $0x7fffffff,%eax 84 andl $0x7fffffff,%eax
83 addl %edx,%eax 85 addl %edx,%eax
84 js 1f 86 js 1f
85 movl %eax,randseed 87 PIC_PROLOGUE
 88 movl %eax,PIC_GOTOFF(randseed)
 89 PIC_EPILOGUE
86 ret 90 ret
871: 911:
88 subl $0x7fffffff,%eax 92 subl $0x7fffffff,%eax
89 movl %eax,randseed 93 PIC_PROLOGUE
 94 movl %eax,PIC_GOTOFF(randseed)
 95 PIC_EPILOGUE
90 ret 96 ret

cvs diff -r1.2 -r1.3 src/sys/lib/libkern/arch/m68k/random.S (switch to unified diff)

--- src/sys/lib/libkern/arch/m68k/random.S 1999/11/11 01:53:46 1.2
+++ src/sys/lib/libkern/arch/m68k/random.S 2009/01/04 17:10:46 1.3
@@ -1,59 +1,68 @@ @@ -1,59 +1,68 @@
1/* $NetBSD: random.S,v 1.2 1999/11/11 01:53:46 thorpej Exp $ */ 1/* $NetBSD: random.S,v 1.3 2009/01/04 17:10:46 pooka Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1990,1993 The Regents of the University of California. 4 * Copyright (c) 1990,1993 The Regents of the University of California.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that: (1) source code distributions 8 * modification, are permitted provided that: (1) source code distributions
9 * retain the above copyright notice and this paragraph in its entirety, (2) 9 * retain the above copyright notice and this paragraph in its entirety, (2)
10 * distributions including binary code include the above copyright notice and 10 * distributions including binary code include the above copyright notice and
11 * this paragraph in its entirety in the documentation or other materials 11 * this paragraph in its entirety in the documentation or other materials
12 * provided with the distribution, and (3) all advertising materials mentioning 12 * provided with the distribution, and (3) all advertising materials mentioning
13 * features or use of this software display the following acknowledgement: 13 * features or use of this software display the following acknowledgement:
14 * ``This product includes software developed by the University of California, 14 * ``This product includes software developed by the University of California,
15 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of 15 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
16 * the University nor the names of its contributors may be used to endorse 16 * the University nor the names of its contributors may be used to endorse
17 * or promote products derived from this software without specific prior 17 * or promote products derived from this software without specific prior
18 * written permission. 18 * written permission.
19 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED 19 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
20 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF 20 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
21 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 21 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
22 * 22 *
23 * Here is a very good random number generator. This implementation is 23 * Here is a very good random number generator. This implementation is
24 * based on ``Two Fast Implementations of the "Minimal Standard" Random 24 * based on ``Two Fast Implementations of the "Minimal Standard" Random
25 * Number Generator'', David G. Carta, Communications of the ACM, Jan 1990, 25 * Number Generator'', David G. Carta, Communications of the ACM, Jan 1990,
26 * Vol 33 No 1. Do NOT modify this code unless you have a very thorough 26 * Vol 33 No 1. Do NOT modify this code unless you have a very thorough
27 * understanding of the algorithm. It's trickier than you think. If 27 * understanding of the algorithm. It's trickier than you think. If
28 * you do change it, make sure that its 10,000'th invocation returns 28 * you do change it, make sure that its 10,000'th invocation returns
29 * 1043618065. 29 * 1043618065.
30 * 30 *
31 * Here is easier-to-decipher pseudocode: 31 * Here is easier-to-decipher pseudocode:
32 * 32 *
33 * p = (16807*seed)<30:0> # e.g., the low 31 bits of the product 33 * p = (16807*seed)<30:0> # e.g., the low 31 bits of the product
34 * q = (16807*seed)<62:31> # e.g., the high 31 bits starting at bit 32 34 * q = (16807*seed)<62:31> # e.g., the high 31 bits starting at bit 32
35 * if (p + q < 2^31) 35 * if (p + q < 2^31)
36 * seed = p + q 36 * seed = p + q
37 * else 37 * else
38 * seed = ((p + q) & (2^31 - 1)) + 1 38 * seed = ((p + q) & (2^31 - 1)) + 1
39 * return (seed); 39 * return (seed);
40 * 40 *
41 * The result is in (0,2^31), e.g., it's always positive. 41 * The result is in (0,2^31), e.g., it's always positive.
42 */ 42 */
43#include <machine/asm.h> 43#include <machine/asm.h>
44 44
45 .data 45 .data
46ASLOCAL(randseed) 46ASLOCAL(randseed)
47 .long 1 47 .long 1
48 48
49ENTRY(random) 49ENTRY(random)
50 movl #16807, %d0 50 movl #16807, %d0
 51#ifdef PIC
 52 lea %pc@(_GLOBAL_OFFSET_TABLE_@GOTPC), %a0
 53 mulsl _ASM_LABEL(randseed)@GOT(%a0), %d1:%d0
 54#else
51 mulsl _ASM_LABEL(randseed), %d1:%d0 55 mulsl _ASM_LABEL(randseed), %d1:%d0
 56#endif
52 lsll #1, %d0 57 lsll #1, %d0
53 roxll #2, %d1 58 roxll #2, %d1
54 addl %d1, %d0 59 addl %d1, %d0
55 moveql #1, %d1 60 moveql #1, %d1
56 addxl %d1, %d0 61 addxl %d1, %d0
57 lsrl #1, %d0 62 lsrl #1, %d0
 63#ifdef PIC
 64 movl %d0, _ASM_LABEL(randseed)@GOT(%a0)
 65#else
58 movl %d0, _ASM_LABEL(randseed) 66 movl %d0, _ASM_LABEL(randseed)
 67#endif
59 rts 68 rts

cvs diff -r1.1 -r1.2 src/sys/lib/libkern/arch/sparc/random.S (switch to unified diff)

--- src/sys/lib/libkern/arch/sparc/random.S 1998/02/22 09:33:27 1.1
+++ src/sys/lib/libkern/arch/sparc/random.S 2009/01/04 17:10:46 1.2
@@ -1,88 +1,102 @@ @@ -1,88 +1,102 @@
1/* $NetBSD: random.S,v 1.1 1998/02/22 09:33:27 mycroft Exp $ */ 1/* $NetBSD: random.S,v 1.2 2009/01/04 17:10:46 pooka Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1990,1993 The Regents of the University of California. 4 * Copyright (c) 1990,1993 The Regents of the University of California.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that: (1) source code distributions 8 * modification, are permitted provided that: (1) source code distributions
9 * retain the above copyright notice and this paragraph in its entirety, (2) 9 * retain the above copyright notice and this paragraph in its entirety, (2)
10 * distributions including binary code include the above copyright notice and 10 * distributions including binary code include the above copyright notice and
11 * this paragraph in its entirety in the documentation or other materials 11 * this paragraph in its entirety in the documentation or other materials
12 * provided with the distribution, and (3) all advertising materials mentioning 12 * provided with the distribution, and (3) all advertising materials mentioning
13 * features or use of this software display the following acknowledgement: 13 * features or use of this software display the following acknowledgement:
14 * ``This product includes software developed by the University of California, 14 * ``This product includes software developed by the University of California,
15 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of 15 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
16 * the University nor the names of its contributors may be used to endorse 16 * the University nor the names of its contributors may be used to endorse
17 * or promote products derived from this software without specific prior 17 * or promote products derived from this software without specific prior
18 * written permission. 18 * written permission.
19 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED 19 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
20 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF 20 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
21 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 21 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
22 * 22 *
23 * Here is a very good random number generator. This implementation is 23 * Here is a very good random number generator. This implementation is
24 * based on ``Two Fast Implementations of the "Minimal Standard" Random 24 * based on ``Two Fast Implementations of the "Minimal Standard" Random
25 * Number Generator'', David G. Carta, Communications of the ACM, Jan 1990, 25 * Number Generator'', David G. Carta, Communications of the ACM, Jan 1990,
26 * Vol 33 No 1. Do NOT modify this code unless you have a very thorough 26 * Vol 33 No 1. Do NOT modify this code unless you have a very thorough
27 * understanding of the algorithm. It's trickier than you think. If 27 * understanding of the algorithm. It's trickier than you think. If
28 * you do change it, make sure that its 10,000'th invocation returns 28 * you do change it, make sure that its 10,000'th invocation returns
29 * 1043618065. 29 * 1043618065.
30 * 30 *
31 * Here is easier-to-decipher pseudocode: 31 * Here is easier-to-decipher pseudocode:
32 * 32 *
33 * p = (16807*seed)<30:0> # e.g., the low 31 bits of the product 33 * p = (16807*seed)<30:0> # e.g., the low 31 bits of the product
34 * q = (16807*seed)<62:31> # e.g., the high 31 bits starting at bit 32 34 * q = (16807*seed)<62:31> # e.g., the high 31 bits starting at bit 32
35 * if (p + q < 2^31) 35 * if (p + q < 2^31)
36 * seed = p + q 36 * seed = p + q
37 * else 37 * else
38 * seed = ((p + q) & (2^31 - 1)) + 1 38 * seed = ((p + q) & (2^31 - 1)) + 1
39 * return (seed); 39 * return (seed);
40 * 40 *
41 * The result is in (0,2^31), e.g., it's always positive. 41 * The result is in (0,2^31), e.g., it's always positive.
42 */ 42 */
43#include <machine/asm.h> 43#include <machine/asm.h>
44 44
45 .data 45 .data
46randseed: 46randseed:
47 .long 1 47 .long 1
48 .text 48 .text
49ENTRY(random) 49ENTRY(random)
50 sethi %hi(16807), %o1 50 sethi %hi(16807), %o1
51 wr %o1, %lo(16807), %y 51 wr %o1, %lo(16807), %y
52 sethi %hi(randseed), %g1 52#ifdef PIC
53 ld [%g1 + %lo(randseed)], %o0 53 PIC_PROLOGUE(%g1, %g2)
54 andcc %g0, 0, %o2 54 set randseed, %g2
 55 ld [%g1 + %g2], %o0
 56#else
 57 sethi %hi(randseed), %g1
 58 ld [%g1 + %lo(randseed)], %o0
 59#endif
 60 andcc %g0, 0, %o2
55 mulscc %o2, %o0, %o2 61 mulscc %o2, %o0, %o2
56 mulscc %o2, %o0, %o2 62 mulscc %o2, %o0, %o2
57 mulscc %o2, %o0, %o2 63 mulscc %o2, %o0, %o2
58 mulscc %o2, %o0, %o2 64 mulscc %o2, %o0, %o2
59 mulscc %o2, %o0, %o2 65 mulscc %o2, %o0, %o2
60 mulscc %o2, %o0, %o2 66 mulscc %o2, %o0, %o2
61 mulscc %o2, %o0, %o2 67 mulscc %o2, %o0, %o2
62 mulscc %o2, %o0, %o2 68 mulscc %o2, %o0, %o2
63 mulscc %o2, %o0, %o2 69 mulscc %o2, %o0, %o2
64 mulscc %o2, %o0, %o2 70 mulscc %o2, %o0, %o2
65 mulscc %o2, %o0, %o2 71 mulscc %o2, %o0, %o2
66 mulscc %o2, %o0, %o2 72 mulscc %o2, %o0, %o2
67 mulscc %o2, %o0, %o2 73 mulscc %o2, %o0, %o2
68 mulscc %o2, %o0, %o2 74 mulscc %o2, %o0, %o2
69 mulscc %o2, %o0, %o2 75 mulscc %o2, %o0, %o2
70 mulscc %o2, %g0, %o2 76 mulscc %o2, %g0, %o2
71 rd %y, %o3 77 rd %y, %o3
72 srl %o2, 16, %o1 78 srl %o2, 16, %o1
73 set 0xffff, %o4 79 set 0xffff, %o4
74 and %o4, %o2, %o0 80 and %o4, %o2, %o0
75 sll %o0, 15, %o0 81 sll %o0, 15, %o0
76 srl %o3, 17, %o3 82 srl %o3, 17, %o3
77 or %o3, %o0, %o0 83 or %o3, %o0, %o0
78 addcc %o0, %o1, %o0 84 addcc %o0, %o1, %o0
79 bneg 1f 85 bneg 1f
80 sethi %hi(0x7fffffff), %o1 86 sethi %hi(0x7fffffff), %o1
81 retl 87 retl
82 st %o0, [%g1 + %lo(randseed)] 88#ifdef PIC
 89 st %o0, [%g1 + %g2]
 90#else
 91 st %o0, [%g1 + %lo(randseed)]
 92#endif
831: 931:
84 or %o1, %lo(0x7fffffff), %o1 94 or %o1, %lo(0x7fffffff), %o1
85 add %o0, 1, %o0 95 add %o0, 1, %o0
86 and %o1, %o0, %o0 96 and %o1, %o0, %o0
87 retl 97 retl
88 st %o0, [%g1 + %lo(randseed)] 98#ifdef PIC
 99 st %o0, [%g1 + %g2]
 100#else
 101 st %o0, [%g1 + %lo(randseed)]
 102#endif

cvs diff -r1.1.1.1 -r1.2 src/sys/lib/libkern/arch/sparc64/random.S (switch to unified diff)

--- src/sys/lib/libkern/arch/sparc64/random.S 1998/06/20 05:18:14 1.1.1.1
+++ src/sys/lib/libkern/arch/sparc64/random.S 2009/01/04 17:10:47 1.2
@@ -1,88 +1,102 @@ @@ -1,88 +1,102 @@
1/* $NetBSD: random.S,v 1.1.1.1 1998/06/20 05:18:14 eeh Exp $ */ 1/* $NetBSD: random.S,v 1.2 2009/01/04 17:10:47 pooka Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1990,1993 The Regents of the University of California. 4 * Copyright (c) 1990,1993 The Regents of the University of California.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that: (1) source code distributions 8 * modification, are permitted provided that: (1) source code distributions
9 * retain the above copyright notice and this paragraph in its entirety, (2) 9 * retain the above copyright notice and this paragraph in its entirety, (2)
10 * distributions including binary code include the above copyright notice and 10 * distributions including binary code include the above copyright notice and
11 * this paragraph in its entirety in the documentation or other materials 11 * this paragraph in its entirety in the documentation or other materials
12 * provided with the distribution, and (3) all advertising materials mentioning 12 * provided with the distribution, and (3) all advertising materials mentioning
13 * features or use of this software display the following acknowledgement: 13 * features or use of this software display the following acknowledgement:
14 * ``This product includes software developed by the University of California, 14 * ``This product includes software developed by the University of California,
15 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of 15 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
16 * the University nor the names of its contributors may be used to endorse 16 * the University nor the names of its contributors may be used to endorse
17 * or promote products derived from this software without specific prior 17 * or promote products derived from this software without specific prior
18 * written permission. 18 * written permission.
19 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED 19 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
20 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF 20 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
21 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 21 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
22 * 22 *
23 * Here is a very good random number generator. This implementation is 23 * Here is a very good random number generator. This implementation is
24 * based on ``Two Fast Implementations of the "Minimal Standard" Random 24 * based on ``Two Fast Implementations of the "Minimal Standard" Random
25 * Number Generator'', David G. Carta, Communications of the ACM, Jan 1990, 25 * Number Generator'', David G. Carta, Communications of the ACM, Jan 1990,
26 * Vol 33 No 1. Do NOT modify this code unless you have a very thorough 26 * Vol 33 No 1. Do NOT modify this code unless you have a very thorough
27 * understanding of the algorithm. It's trickier than you think. If 27 * understanding of the algorithm. It's trickier than you think. If
28 * you do change it, make sure that its 10,000'th invocation returns 28 * you do change it, make sure that its 10,000'th invocation returns
29 * 1043618065. 29 * 1043618065.
30 * 30 *
31 * Here is easier-to-decipher pseudocode: 31 * Here is easier-to-decipher pseudocode:
32 * 32 *
33 * p = (16807*seed)<30:0> # e.g., the low 31 bits of the product 33 * p = (16807*seed)<30:0> # e.g., the low 31 bits of the product
34 * q = (16807*seed)<62:31> # e.g., the high 31 bits starting at bit 32 34 * q = (16807*seed)<62:31> # e.g., the high 31 bits starting at bit 32
35 * if (p + q < 2^31) 35 * if (p + q < 2^31)
36 * seed = p + q 36 * seed = p + q
37 * else 37 * else
38 * seed = ((p + q) & (2^31 - 1)) + 1 38 * seed = ((p + q) & (2^31 - 1)) + 1
39 * return (seed); 39 * return (seed);
40 * 40 *
41 * The result is in (0,2^31), e.g., it's always positive. 41 * The result is in (0,2^31), e.g., it's always positive.
42 */ 42 */
43#include <machine/asm.h> 43#include <machine/asm.h>
44 44
45 .data 45 .data
46randseed: 46randseed:
47 .long 1 47 .long 1
48 .text 48 .text
49ENTRY(random) 49ENTRY(random)
50 sethi %hi(16807), %o1 50 sethi %hi(16807), %o1
51 wr %o1, %lo(16807), %y 51 wr %o1, %lo(16807), %y
52 sethi %hi(randseed), %g1 52#ifdef PIC
53 ld [%g1 + %lo(randseed)], %o0 53 PIC_PROLOGUE(%g1, %g2)
54 andcc %g0, 0, %o2 54 set randseed, %g2
 55 ld [%g1 + %g2], %o0
 56#else
 57 sethi %hi(randseed), %g1
 58 ld [%g1 + %lo(randseed)], %o0
 59#endif
 60 andcc %g0, 0, %o2
55 mulscc %o2, %o0, %o2 61 mulscc %o2, %o0, %o2
56 mulscc %o2, %o0, %o2 62 mulscc %o2, %o0, %o2
57 mulscc %o2, %o0, %o2 63 mulscc %o2, %o0, %o2
58 mulscc %o2, %o0, %o2 64 mulscc %o2, %o0, %o2
59 mulscc %o2, %o0, %o2 65 mulscc %o2, %o0, %o2
60 mulscc %o2, %o0, %o2 66 mulscc %o2, %o0, %o2
61 mulscc %o2, %o0, %o2 67 mulscc %o2, %o0, %o2
62 mulscc %o2, %o0, %o2 68 mulscc %o2, %o0, %o2
63 mulscc %o2, %o0, %o2 69 mulscc %o2, %o0, %o2
64 mulscc %o2, %o0, %o2 70 mulscc %o2, %o0, %o2
65 mulscc %o2, %o0, %o2 71 mulscc %o2, %o0, %o2
66 mulscc %o2, %o0, %o2 72 mulscc %o2, %o0, %o2
67 mulscc %o2, %o0, %o2 73 mulscc %o2, %o0, %o2
68 mulscc %o2, %o0, %o2 74 mulscc %o2, %o0, %o2
69 mulscc %o2, %o0, %o2 75 mulscc %o2, %o0, %o2
70 mulscc %o2, %g0, %o2 76 mulscc %o2, %g0, %o2
71 rd %y, %o3 77 rd %y, %o3
72 srl %o2, 16, %o1 78 srl %o2, 16, %o1
73 set 0xffff, %o4 79 set 0xffff, %o4
74 and %o4, %o2, %o0 80 and %o4, %o2, %o0
75 sll %o0, 15, %o0 81 sll %o0, 15, %o0
76 srl %o3, 17, %o3 82 srl %o3, 17, %o3
77 or %o3, %o0, %o0 83 or %o3, %o0, %o0
78 addcc %o0, %o1, %o0 84 addcc %o0, %o1, %o0
79 bneg 1f 85 bneg 1f
80 sethi %hi(0x7fffffff), %o1 86 sethi %hi(0x7fffffff), %o1
81 retl 87 retl
82 st %o0, [%g1 + %lo(randseed)] 88#ifdef PIC
 89 st %o0, [%g1 + %g2]
 90#else
 91 st %o0, [%g1 + %lo(randseed)]
 92#endif
831: 931:
84 or %o1, %lo(0x7fffffff), %o1 94 or %o1, %lo(0x7fffffff), %o1
85 add %o0, 1, %o0 95 add %o0, 1, %o0
86 and %o1, %o0, %o0 96 and %o1, %o0, %o0
87 retl 97 retl
88 st %o0, [%g1 + %lo(randseed)] 98#ifdef PIC
 99 st %o0, [%g1 + %g2]
 100#else
 101 st %o0, [%g1 + %lo(randseed)]
 102#endif