Commit | Line | Data |
---|---|---|
86530b38 AT |
1 | // ========== Copyright Header Begin ========================================== |
2 | // | |
3 | // OpenSPARC T2 Processor File: niu_seeding.vri | |
4 | // Copyright (C) 1995-2007 Sun Microsystems, Inc. All Rights Reserved | |
5 | // 4150 Network Circle, Santa Clara, California 95054, U.S.A. | |
6 | // | |
7 | // * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | |
8 | // | |
9 | // This program is free software; you can redistribute it and/or modify | |
10 | // it under the terms of the GNU General Public License as published by | |
11 | // the Free Software Foundation; version 2 of the License. | |
12 | // | |
13 | // This program is distributed in the hope that it will be useful, | |
14 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | // GNU General Public License for more details. | |
17 | // | |
18 | // You should have received a copy of the GNU General Public License | |
19 | // along with this program; if not, write to the Free Software | |
20 | // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
21 | // | |
22 | // For the avoidance of doubt, and except that if any non-GPL license | |
23 | // choice is available it will apply instead, Sun elects to use only | |
24 | // the General Public License version 2 (GPLv2) at this time for any | |
25 | // software where a choice of GPL license versions is made | |
26 | // available with the language indicating that GPLv2 or any later version | |
27 | // may be used, or where a choice of which version of the GPL is applied is | |
28 | // otherwise unspecified. | |
29 | // | |
30 | // Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, | |
31 | // CA 95054 USA or visit www.sun.com if you need additional information or | |
32 | // have any questions. | |
33 | // | |
34 | // ========== Copyright Header End ============================================ | |
35 | #include "niu_plusArgMacros.vri" | |
36 | ||
37 | #define MAXINT 2147483647 | |
38 | ||
39 | //----------------------------------------------------------------------------- | |
40 | // You must seed the random number generators from the vera program file | |
41 | // (*top.vr) *BEFORE* class instantiations and forks. YES, this matters | |
42 | // in vera > V5, see vera docs. If you don't seed before instantiating a | |
43 | // class, that class ALWAYS repeats the same random numbers which is NOT | |
44 | // what you want. (you have been warned :^)) | |
45 | //----------------------------------------------------------------------------- | |
46 | ||
47 | //----------------------------------------------------------------------------- | |
48 | // NOTE: random() always returns a positive integer. bit 31 ALWAYS ZERO. | |
49 | // urandom() always returns a unsigned integer. bit 31 ALWAYS RANDOM. | |
50 | // If you do myInt = urandom(); you will get a negetive integer 50% of the time! | |
51 | // If you do myReg[31:0] = random(); you will always have [31] = 0. | |
52 | // Read this again... | |
53 | //----------------------------------------------------------------------------- | |
54 | ||
55 | ||
56 | ||
57 | ||
58 | reg [31:0] seedingtmpseed = 0; | |
59 | integer gSeed = 0; | |
60 | integer gSeedFileHndl; | |
61 | string which; | |
62 | integer systime; | |
63 | ||
64 | #ifdef NTB | |
65 | string gTestNameAsm, gTestNameVera, gAltTestname; | |
66 | which = "NTB"; | |
67 | #else | |
68 | reg [1024:0] gTestNameAsm, gTestNameVera, gAltTestname; | |
69 | which = "VERA"; | |
70 | #endif | |
71 | ||
72 | ||
73 | gTestNameAsm = ""; | |
74 | gTestNameVera = ""; | |
75 | gAltTestname = ""; | |
76 | ||
77 | #ifndef HDNLNAME | |
78 | #define HDNLNAME gSeedFileHndl | |
79 | #endif | |
80 | ||
81 | #ifndef SEEDNAME | |
82 | #define SEEDNAME gSeed | |
83 | #endif | |
84 | ||
85 | #ifdef SEEDFORCE | |
86 | SEEDNAME = SEEDFORCE; | |
87 | #else | |
88 | mGetPlusargDec(tg_seed=,seedingtmpseed); | |
89 | if (seedingtmpseed[31]) { | |
90 | seedingtmpseed[31] = 0; // don't want negative integer | |
91 | printf("SEED---> sims +tg_seed: was modified to not be a negative integer\n"); | |
92 | } | |
93 | ||
94 | if( get_plus_arg(CHECK,"NIU_RANDOM")) { | |
95 | SEEDNAME = seedingtmpseed; // cast reg to positive integer | |
96 | } else { | |
97 | SEEDNAME = 0; | |
98 | } | |
99 | printf("SEED---> sims +tg_seed: %d", SEEDNAME); | |
100 | // | |
101 | // NOTE: use sims -tg_seed= to pass in a seed. | |
102 | // DO NOT use sims -vcs_run_args=+tg_seed=, it will not work! | |
103 | // | |
104 | #endif | |
105 | ||
106 | if (mChkPlusarg(vera_diag_name=)) mGetPlusargStr(vera_diag_name=,gTestNameVera); | |
107 | if (mChkPlusarg(asm_diag_name=)) mGetPlusargStr(asm_diag_name=,gTestNameAsm); | |
108 | if (mChkPlusarg(test=)) mGetPlusargStr(test=,gAltTestname); | |
109 | ||
110 | // NOTE: random always returns a positive integer. bit 31 ALWAYS ZERO. | |
111 | // urandom always returns a unsigned integer. bit 31 ALWAYS RANDOM. | |
112 | // If you do myInt = urandom(); you will get a negetive integer 50% of time! | |
113 | // If you do myReg[31:0] = random(); you will always have [31] = 0. | |
114 | // Read this again... | |
115 | ||
116 | if( get_plus_arg(CHECK,"NIU_RANDOM")) { | |
117 | rand48(SEEDNAME);urand48(SEEDNAME); // do not use these 48 calls | |
118 | urandom(SEEDNAME);random(SEEDNAME); // not really needed but safe | |
119 | srandom(SEEDNAME); // seeds main generator and random and urandom | |
120 | ||
121 | // store the seed. Lost seeds after re-runs are a real bummer! | |
122 | HDNLNAME = fopen( "./seeds.log", "a" ); | |
123 | if ( HDNLNAME == 0 ) { | |
124 | printf("\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n"); | |
125 | printf("The %s random generators have just been seeded with %d\n", which, SEEDNAME); | |
126 | printf("You need to know this SEED if you want to reproduce failures!\n"); | |
127 | printf("Use sims -tg_seed=%0d to reproduce this run.\n",SEEDNAME); | |
128 | printf("Seed not saved to file!!! Make sure that you are the owner of seeds.log and that it has 664 protection.\n"); | |
129 | printf("\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n"); | |
130 | } else { | |
131 | printf("\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n"); | |
132 | printf("The %s random generators have just been seeded with %d\n",which, SEEDNAME); | |
133 | printf("You need to know this SEED if you want to reproduce failures!\n"); | |
134 | printf("Use sims -tg_seed=%0d to reproduce this run!\n",SEEDNAME); | |
135 | printf("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n"); | |
136 | fprintf(HDNLNAME, "---------------------------------------------------------------------\n"); | |
137 | fprintf(HDNLNAME, "Test %s %s %s is using seed %d StartTime - ", gTestNameAsm, gTestNameVera, gAltTestname, SEEDNAME); | |
138 | fclose(HDNLNAME); | |
139 | os_command("date >>./seeds.log"); | |
140 | // NOTE: 'end of test' code should update this file to indicate status, | |
141 | // that way you know which seed was the failing one, which is the one | |
142 | // you are looking for... I need to make a seedingEnd.vri to do that. jp | |
143 | } | |
144 | } |