Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

scv_init_seed.cpp

Go to the documentation of this file.
00001 /*****************************************************************************
00002 
00003   The following code is derived, directly or indirectly, from the SystemC
00004   source code Copyright (c) 1996-2002 by all Contributors.
00005   All Rights reserved.
00006 
00007   The contents of this file are subject to the restrictions and limitations
00008   set forth in the SystemC Open Source License Version 2.3 (the "License");
00009   You may not use this file except in compliance with such restrictions and
00010   limitations. You may obtain instructions on how to receive a copy of the
00011   License at http://www.systemc.org/. Software distributed by Contributors
00012   under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF
00013   ANY KIND, either express or implied. See the License for the specific
00014   language governing rights and limitations under the License.
00015 
00016  *****************************************************************************/
00017 
00018 /*****************************************************************************
00019 
00020   scv_config.h
00021 
00022   Original Authors (Cadence Design Systems, Inc):
00023   Norris Ip, Dean Shea, John Rose, Jasvinder Singh, William Paulsen,
00024   John Pierce, Rachida Kebichi, Ted Elkind, David Bailey
00025   2002-09-23
00026 
00027  *****************************************************************************/
00028 
00029 /*****************************************************************************
00030 
00031   MODIFICATION LOG - modifiers, enter your name, affiliation, date and
00032   changes you are making here.
00033 
00034       Name, Affiliation, Date:
00035   Description of Modification:
00036 
00037  *****************************************************************************/
00038 
00039 #include "scv/scv_config.h"
00040 
00041 #ifndef _MSC_VER
00042 #include <sys/times.h>
00043 #endif
00044 
00045 #include <string.h>
00046 
00047 #ifdef __linux__
00048 # include <sys/time.h>
00049 #else 
00050 #include <time.h>
00051 #endif
00052 
00053 extern unsigned long long _scv_get_global_seed(void);
00054 
00055 unsigned long long
00056 _scv_default_global_init_seed(unsigned long job_number)
00057 {
00058 #ifdef _MSC_VER
00059   __time64_t ltime_sec;
00060   _time64( &ltime_sec );
00061   unsigned __int64 ltime_usec = 0;
00062   long i = 6000000L;
00063   unsigned int clk;
00064   clock_t start, finish;
00065 
00066   // measure the duration of an event
00067   start = clock();
00068   while( i-- ) ;
00069   finish = clock();
00070   clk = finish - start;
00071 
00072   // select a "random" seed
00073   unsigned __int64 seed
00074     = ((unsigned long)(ltime_sec^ltime_usec^clk^job_number) * 654435769) >> 1;
00075 #else
00076   // get time of date
00077   struct timeval tp;
00078   struct timezone dummy1;
00079   gettimeofday(&tp, &dummy1);
00080 
00081   // get system time
00082   struct tms dummy2;
00083   clock_t clk;
00084   clk = times(&dummy2);
00085 
00086   // select a "random" seed
00087   unsigned long long seed
00088     = ((unsigned long)(tp.tv_sec^tp.tv_usec^clk^job_number) * 654435769) >> 1;
00089 #endif
00090 
00091   if (seed==0) seed = 46831694;
00092   return seed;
00093 }
00094 
00095 unsigned long long 
00096 _scv_get_seed_from_name(const char * name, unsigned inst_num)
00097 {
00098   unsigned long long seed = 0;
00099 
00100   if (name) {
00101     for (unsigned i=0;i < strlen(name); i++) {
00102       if (name[i] != 0) {
00103         seed += name[i];
00104       }
00105     }
00106   } else {
00107     seed = 1;
00108   }
00109 
00110   seed = ((unsigned long) ((_scv_get_global_seed() * seed) + 
00111             inst_num * 1023 ) * 654435769) >> 1;
00112  
00113   if (seed==0) seed = 46831694;
00114   return seed;
00115 }
00116 

Generated on Fri Jan 14 08:29:10 2005 for SystemC2.1beta11(excludingMSLib)(IncludingSCV)\nProvidedby:www.openverificationfoundation.org by doxygen1.2.18