diff --git a/src/misc/Makefile.am b/src/misc/Makefile.am index efaaf5e24..d20d905ae 100644 --- a/src/misc/Makefile.am +++ b/src/misc/Makefile.am @@ -2,8 +2,6 @@ noinst_LTLIBRARIES = libmisc.la -EXTRA_DIST = win_time.c - libmisc_la_SOURCES = \ getopt_long_bsd.c \ getopt_bsd.h \ diff --git a/src/misc/misc_time.c b/src/misc/misc_time.c index 0f55d9a29..e669198fe 100644 --- a/src/misc/misc_time.c +++ b/src/misc/misc_time.c @@ -1,148 +1,179 @@ -/********** -Copyright 1990 Regents of the University of California. All rights reserved. -**********/ - -/* - * Date and time utility functions - */ - -#include "ngspice/ngspice.h" -#include - -#if defined(HAS_WINGUI) || defined(__MINGW32__) || defined(_MSC_VER) -#ifdef HAVE_QUERYPERFORMANCECOUNTER -#define WIN32_LEAN_AND_MEAN - /* - * The ngspice.h file included above defines BOOLEAN (via bool.h) and this - * clashes with the definition obtained from windows.h (via winnt.h). - * However, BOOLEAN is not used by this file so we can work round this problem - * by undefining BOOLEAN before including windows.h - * SJB - April 2005 - */ -#undef BOOLEAN -#include -#endif -#endif - -#include "misc_time.h" - -#ifdef USE_OMP -#include -#endif - -/* Return the date. Return value is static data. */ - -char * -datestring(void) -{ - -#ifdef HAVE_LOCALTIME - static char tbuf[45]; - struct tm *tp; - char *ap; - size_t i; - - time_t tloc; - time(&tloc); - tp = localtime(&tloc); - ap = asctime(tp); - (void) sprintf(tbuf, "%.20s", ap); - (void) strcat(tbuf, ap + 19); - i = strlen(tbuf); - tbuf[i - 1] = '\0'; - return (tbuf); - -#else - - return ("today"); - -#endif -} - -/* return time interval in seconds and milliseconds */ - -PerfTime timebegin; - -void timediff(PerfTime *now, PerfTime *begin, int *sec, int *msec) -{ - - *msec = (int) now->milliseconds - (int) begin->milliseconds; - *sec = (int) now->seconds - (int) begin->seconds; - if (*msec < 0) { - *msec += 1000; - (*sec)--; - } - return; - -} - -/* - * How many seconds have elapsed in running time. - * This is the routine called in IFseconds - */ - -double -seconds(void) -{ -#ifdef USE_OMP - // Usage of OpenMP time function - return omp_get_wtime(); -#elif defined(HAVE_QUERYPERFORMANCECOUNTER) - // Windows (MSC and mingw) specific implementation - LARGE_INTEGER frequency, counter; - QueryPerformanceFrequency(&frequency); - QueryPerformanceCounter(&counter); - return (double)counter.QuadPart / frequency.QuadPart; -#elif defined(HAVE_CLOCK_GETTIME) - struct timespec ts; - clock_gettime(CLOCK_MONOTONIC, &ts); - return ts.tv_sec + ts.tv_nsec / 1e9; -#elif defined(HAVE_GETTIMEOFDAY) - // Usage of gettimeofday - struct timeval tv; - gettimeofday(&tv, NULL); - return tv.tv_sec + tv.tv_usec / 1e6; -#elif defined(HAVE_TIMES) - // Usage of times - struct tms t; - clock_t ticks = times(&t); - return (double)ticks / sysconf(_SC_CLK_TCK); -#elif defined(HAVE_GETRUSAGE) - // Usage of getrusage - struct rusage usage; - getrusage(RUSAGE_SELF, &usage); - return usage.ru_utime.tv_sec + usage.ru_utime.tv_usec / 1e6; -#elif defined(HAVE_FTIME) - // Usage of ftime - struct timeb tb; - ftime(&tb); - return tb.time + tb.millitm / 1000.0; -#else - #error "No timer function available." -#endif -} - -void perf_timer_start(PerfTimer *timer) -{ - timer->start = seconds(); -} - -void perf_timer_stop(PerfTimer *timer) -{ - timer->end = seconds(); -} - -void perf_timer_elapsed_sec_ms(const PerfTimer *timer, int *seconds, int *milliseconds) -{ - double elapsed = timer->end - timer->start; - *seconds = (int)elapsed; - *milliseconds = (int)((elapsed - *seconds) * 1000.0); -} - -void perf_timer_get_time(PerfTime *time) -{ - double secs = seconds(); - time->seconds = (int)secs; - time->milliseconds = (int)((secs - time->seconds) * 1000.0); - -} +/********** +Copyright 1990 Regents of the University of California. All rights reserved. +**********/ + +/* + * Date and time utility functions + */ + +#include "ngspice/ngspice.h" +#include + +#if defined(HAS_WINGUI) || defined(__MINGW32__) || defined(_MSC_VER) +#ifdef HAVE_QUERYPERFORMANCECOUNTER +#define WIN32_LEAN_AND_MEAN + /* + * The ngspice.h file included above defines BOOLEAN (via bool.h) and this + * clashes with the definition obtained from windows.h (via winnt.h). + * However, BOOLEAN is not used by this file so we can work round this problem + * by undefining BOOLEAN before including windows.h + * SJB - April 2005 + */ +#undef BOOLEAN +#include +#ifndef HAVE_GETTIMEOFDAY +#include +#include // portable: uint64_t MSVC: __int64 + +/*/ MSVC defines this in winsock2.h!? +typedef struct timeval { + long tv_sec; + long tv_usec; +} timeval; +*/ +int gettimeofday(struct timeval * tp, void * unused) +{ + // Note: some broken versions only have 8 trailing zero's, the correct epoch has 9 trailing zero's + // This magic number is the number of 100 nanosecond intervals since January 1, 1601 (UTC) + // until 00:00:00 January 1, 1970 + static const uint64_t EPOCH = ((uint64_t) 116444736000000000ULL); + + SYSTEMTIME system_time; + FILETIME file_time; + uint64_t time; + + GetSystemTime( &system_time ); + SystemTimeToFileTime( &system_time, &file_time ); + time = ((uint64_t)file_time.dwLowDateTime ) ; + time += ((uint64_t)file_time.dwHighDateTime) << 32; + + tp->tv_sec = (long) ((time - EPOCH) / 10000000L); + tp->tv_usec = (long) (system_time.wMilliseconds * 1000); + return 0; +} +#endif +#endif +#endif + +#include "misc_time.h" + +#ifdef USE_OMP +#include +#endif + +/* Return the date. Return value is static data. */ + +char * +datestring(void) +{ + +#ifdef HAVE_LOCALTIME + static char tbuf[45]; + struct tm *tp; + char *ap; + size_t i; + + time_t tloc; + time(&tloc); + tp = localtime(&tloc); + ap = asctime(tp); + (void) sprintf(tbuf, "%.20s", ap); + (void) strcat(tbuf, ap + 19); + i = strlen(tbuf); + tbuf[i - 1] = '\0'; + return (tbuf); + +#else + + return ("today"); + +#endif +} + +/* return time interval in seconds and milliseconds */ + +PerfTime timebegin; + +void timediff(PerfTime *now, PerfTime *begin, int *sec, int *msec) +{ + + *msec = (int) now->milliseconds - (int) begin->milliseconds; + *sec = (int) now->seconds - (int) begin->seconds; + if (*msec < 0) { + *msec += 1000; + (*sec)--; + } + return; + +} + +/* + * How many seconds have elapsed in running time. + * This is the routine called in IFseconds + */ + +double +seconds(void) +{ +#ifdef USE_OMP + // Usage of OpenMP time function + return omp_get_wtime(); +#elif defined(HAVE_QUERYPERFORMANCECOUNTER) + // Windows (MSC and mingw) specific implementation + LARGE_INTEGER frequency, counter; + QueryPerformanceFrequency(&frequency); + QueryPerformanceCounter(&counter); + return (double)counter.QuadPart / frequency.QuadPart; +#elif defined(HAVE_CLOCK_GETTIME) + struct timespec ts; + clock_gettime(CLOCK_MONOTONIC, &ts); + return ts.tv_sec + ts.tv_nsec / 1e9; +#elif defined(HAVE_GETTIMEOFDAY) + // Usage of gettimeofday + struct timeval tv; + gettimeofday(&tv, NULL); + return tv.tv_sec + tv.tv_usec / 1e6; +#elif defined(HAVE_TIMES) + // Usage of times + struct tms t; + clock_t ticks = times(&t); + return (double)ticks / sysconf(_SC_CLK_TCK); +#elif defined(HAVE_GETRUSAGE) + // Usage of getrusage + struct rusage usage; + getrusage(RUSAGE_SELF, &usage); + return usage.ru_utime.tv_sec + usage.ru_utime.tv_usec / 1e6; +#elif defined(HAVE_FTIME) + // Usage of ftime + struct timeb tb; + ftime(&tb); + return tb.time + tb.millitm / 1000.0; +#else + #error "No timer function available." +#endif +} + +void perf_timer_start(PerfTimer *timer) +{ + timer->start = seconds(); +} + +void perf_timer_stop(PerfTimer *timer) +{ + timer->end = seconds(); +} + +void perf_timer_elapsed_sec_ms(const PerfTimer *timer, int *seconds, int *milliseconds) +{ + double elapsed = timer->end - timer->start; + *seconds = (int)elapsed; + *milliseconds = (int)((elapsed - *seconds) * 1000.0); +} + +void perf_timer_get_time(PerfTime *time) +{ + double secs = seconds(); + time->seconds = (int)secs; + time->milliseconds = (int)((secs - time->seconds) * 1000.0); + +} diff --git a/src/misc/win_time.c b/src/misc/win_time.c deleted file mode 100644 index fd1788d7e..000000000 --- a/src/misc/win_time.c +++ /dev/null @@ -1,32 +0,0 @@ -#define WIN32_LEAN_AND_MEAN -//#include "ngspice/ngspice.h" -#include -#include -#include // portable: uint64_t MSVC: __int64 - -/*/ MSVC defines this in winsock2.h!? -typedef struct timeval { - long tv_sec; - long tv_usec; -} timeval; -*/ -int gettimeofday(struct timeval * tp, void * unused) -{ - // Note: some broken versions only have 8 trailing zero's, the correct epoch has 9 trailing zero's - // This magic number is the number of 100 nanosecond intervals since January 1, 1601 (UTC) - // until 00:00:00 January 1, 1970 - static const uint64_t EPOCH = ((uint64_t) 116444736000000000ULL); - - SYSTEMTIME system_time; - FILETIME file_time; - uint64_t time; - - GetSystemTime( &system_time ); - SystemTimeToFileTime( &system_time, &file_time ); - time = ((uint64_t)file_time.dwLowDateTime ) ; - time += ((uint64_t)file_time.dwHighDateTime) << 32; - - tp->tv_sec = (long) ((time - EPOCH) / 10000000L); - tp->tv_usec = (long) (system_time.wMilliseconds * 1000); - return 0; -} diff --git a/visualc/sharedspice.vcxproj b/visualc/sharedspice.vcxproj index c18f68813..c62fafd5e 100644 --- a/visualc/sharedspice.vcxproj +++ b/visualc/sharedspice.vcxproj @@ -1466,7 +1466,6 @@ lib /machine:x64 /def:..\..\fftw-3.3-dll64\libfftw3-3.def /out:$(IntDir)libfftw3 - diff --git a/visualc/vngspice-fftw.vcxproj b/visualc/vngspice-fftw.vcxproj index 04a189e00..ac78cc4b3 100644 --- a/visualc/vngspice-fftw.vcxproj +++ b/visualc/vngspice-fftw.vcxproj @@ -1687,7 +1687,6 @@ lib /machine:x64 /def:..\..\fftw-3.3-dll64\libfftw3-3.def /out:$(IntDir)libfftw3 - diff --git a/visualc/vngspice.vcxproj b/visualc/vngspice.vcxproj index 5281546d0..8e80be4e2 100644 --- a/visualc/vngspice.vcxproj +++ b/visualc/vngspice.vcxproj @@ -1702,7 +1702,6 @@ -