1
0
mirror of https://github.com/upx/upx synced 2025-09-28 19:06:07 +08:00

New ACC version.

committer: mfx <mfx> 1062077078 +0000
This commit is contained in:
Markus F.X.J. Oberhumer 2003-08-28 13:24:38 +00:00
parent 655094239c
commit 919a899c39
9 changed files with 467 additions and 48 deletions

View File

@ -25,7 +25,7 @@
#ifndef __ACC_H_INCLUDED
#define __ACC_H_INCLUDED
#define ACC_VERSION 20030811L
#define ACC_VERSION 20030827L
#if !defined(ACC_CONFIG_INCLUDE)
# define ACC_CONFIG_INCLUDE(file) file

View File

@ -362,6 +362,8 @@
# undef HAVE_ALLOCA
# endif
#elif defined(__MINGW32__)
# define snprintf _snprintf
# define vsnprintf _vsnprintf
#elif (ACC_CC_PACIFICC)
# undef HAVE_ACCESS
# undef HAVE_ALLOCA

View File

@ -46,8 +46,6 @@
// ignored or misinterpreted (e.g. implicit cast from -1 to unsigned long)
// on some systems. OTOS, on modern compilers, the "switch" version
// may produce a pedantic warning about "selector expr. is constant".
// Also, the "switch" version must appear in a function body, so you
// cannot use this macro in header files.
************************************************************************/
/* This can be put into a header file but may get ignored by some compilers */

View File

@ -39,6 +39,7 @@
# define ACCLIB_PUBLIC(r,f) r __ACCLIB_FUNCNAME(f)
#endif
#include ACC_CONFIG_INCLUDE("acclib/bele.ch")
#include ACC_CONFIG_INCLUDE("acclib/hmemcpy.ch")
#include ACC_CONFIG_INCLUDE("acclib/halloc.ch")
#include ACC_CONFIG_INCLUDE("acclib/dosalloc.ch")
@ -48,6 +49,11 @@
#include ACC_CONFIG_INCLUDE("acclib/rand.ch")
#include ACC_CONFIG_INCLUDE("acclib/misc.ch")
#if 0
/* modules which use floating point are not included by default */
#include ACC_CONFIG_INCLUDE("acclib/uclock.ch")
#endif
/*
vi:ts=4:et

View File

@ -197,12 +197,46 @@ ACCLIB_EXTERN(int, acc_mkdir) (const char* name, unsigned mode);
ACCLIB_EXTERN(int, acc_response) (int* argc, char*** argv);
ACCLIB_EXTERN(int, acc_set_binmode) (int fd, int binary);
#if defined(acc_uint64l_t)
# define acc_uclock_t acc_uint64l_t
#else
# define acc_uclock_t acc_uint32l_t
ACCLIB_EXTERN(acc_int32l_t, acc_muldiv32) (acc_int32l_t, acc_int32l_t, acc_int32l_t);
ACCLIB_EXTERN(acc_uint32l_t, acc_umuldiv32) (acc_uint32l_t, acc_uint32l_t, acc_uint32l_t);
/*************************************************************************
// uclock
**************************************************************************/
typedef struct { /* all private */
acclib_handle_t h;
int mode;
#if (ACC_H_WINDOWS_H) && defined(acc_uint64l_t)
double qpf;
#endif
ACCLIB_EXTERN(acc_uclock_t, acc_uclock) (void);
} acc_uclock_handle_t;
typedef struct { /* all private */
union {
acc_uint32l_t t32;
#if !(ACC_OS_DOS16 || ACC_OS_WIN16)
double td;
# if defined(acc_int64l_t)
acc_int64l_t t64;
# endif
#endif
} ticks;
#if (ACC_H_WINDOWS_H) && defined(acc_int64l_t)
acc_int64l_t qpc;
#endif
} acc_uclock_t;
ACCLIB_EXTERN(int, acc_uclock_open) (acc_uclock_handle_t*);
ACCLIB_EXTERN(int, acc_uclock_close) (acc_uclock_handle_t*);
ACCLIB_EXTERN(void, acc_uclock_read) (acc_uclock_handle_t*, acc_uclock_t*);
ACCLIB_EXTERN(double, acc_uclock_get_elapsed) (acc_uclock_handle_t*, const acc_uclock_t*, const acc_uclock_t*);
/*************************************************************************
// bele (Big Endian / Little Endian)
**************************************************************************/
ACCLIB_EXTERN(unsigned, acc_get_be16) (const acc_hvoid_p);
ACCLIB_EXTERN(acc_uint32l_t, acc_get_be24) (const acc_hvoid_p);
@ -222,6 +256,7 @@ ACCLIB_EXTERN(void, acc_set_be64) (acc_hvoid_p, acc_uint64l_t);
ACCLIB_EXTERN(acc_uint64l_t, acc_get_le64) (const acc_hvoid_p);
ACCLIB_EXTERN(void, acc_set_le64) (acc_hvoid_p, acc_uint64l_t);
#endif
/* inline versions */
#if (ACC_ARCH_IA32)
# define ACC_GET_LE16(p) (* (const unsigned short *) (p))
@ -230,8 +265,10 @@ ACCLIB_EXTERN(void, acc_set_le64) (acc_hvoid_p, acc_uint64l_t);
# define ACC_SET_LE32(p,v) (* (unsigned int *) (p) = (unsigned int) (v))
#endif
ACCLIB_EXTERN(acc_int32l_t, acc_muldiv32) (acc_int32l_t, acc_int32l_t, acc_int32l_t);
ACCLIB_EXTERN(acc_uint32l_t, acc_umuldiv32) (acc_uint32l_t, acc_uint32l_t, acc_uint32l_t);
/*************************************************************************
// rand
**************************************************************************/
typedef struct {
acc_uint32l_t seed;
@ -245,6 +282,7 @@ typedef struct {
} acc_rand48_t;
ACCLIB_EXTERN(void, acc_srand48) (acc_rand48_t* r, acc_uint32l_t seed);
ACCLIB_EXTERN(acc_uint32l_t, acc_rand48) (acc_rand48_t* r);
ACCLIB_EXTERN(acc_uint32l_t, acc_rand48_r32) (acc_rand48_t* r);
#endif
#if defined(acc_uint64l_t)
@ -253,8 +291,17 @@ typedef struct {
} acc_rand64_t;
ACCLIB_EXTERN(void, acc_srand64) (acc_rand64_t* r, acc_uint64l_t seed);
ACCLIB_EXTERN(acc_uint32l_t, acc_rand64) (acc_rand64_t* r);
ACCLIB_EXTERN(acc_uint32l_t, acc_rand64_r32) (acc_rand64_t* r);
#endif
typedef struct {
unsigned n;
acc_uint32l_t s[624];
} acc_randmt_t;
ACCLIB_EXTERN(void, acc_srandmt) (acc_randmt_t* r, acc_uint32l_t seed);
ACCLIB_EXTERN(acc_uint32l_t, acc_randmt) (acc_randmt_t* r);
ACCLIB_EXTERN(acc_uint32l_t, acc_randmt_r32) (acc_randmt_t* r);
#endif /* already included */

View File

@ -19,32 +19,161 @@
/*************************************************************************
// FIXME
//
**************************************************************************/
ACCLIB_PUBLIC(unsigned, acc_get_be16) (const acc_hvoid_p);
ACCLIB_PUBLIC(acc_uint32l_t, acc_get_be24) (const acc_hvoid_p);
ACCLIB_PUBLIC(acc_uint32l_t, acc_get_be32) (const acc_hvoid_p);
ACCLIB_PUBLIC(unsigned, acc_get_be16) (const acc_hvoid_p p)
{
const acc_hbyte_p b = (const acc_hbyte_p) p;
return ((unsigned)b[1]) | ((unsigned)b[0] << 8);
}
ACCLIB_PUBLIC(void, acc_set_be16) (acc_hvoid_p, unsigned v);
ACCLIB_PUBLIC(void, acc_set_be24) (acc_hvoid_p, acc_uint32l_t v);
ACCLIB_PUBLIC(void, acc_set_be32) (acc_hvoid_p, acc_uint32l_t v);
ACCLIB_PUBLIC(acc_uint32l_t, acc_get_be24) (const acc_hvoid_p p)
{
const acc_hbyte_p b = (const acc_hbyte_p) p;
return ((acc_uint32l_t)b[2]) | ((acc_uint32l_t)b[1] << 8) | ((acc_uint32l_t)b[0] << 16);
}
ACCLIB_PUBLIC(acc_uint32l_t, acc_get_be32) (const acc_hvoid_p p)
{
const acc_hbyte_p b = (const acc_hbyte_p) p;
return ((acc_uint32l_t)b[3]) | ((acc_uint32l_t)b[2] << 8) | ((acc_uint32l_t)b[1] << 16) | ((acc_uint32l_t)b[0] << 24);
}
ACCLIB_PUBLIC(void, acc_set_be16) (acc_hvoid_p p, unsigned v)
{
acc_hbyte_p b = (acc_hbyte_p) p;
b[1] = (unsigned char) ((v >> 0) & 0xff);
b[0] = (unsigned char) ((v >> 8) & 0xff);
}
ACCLIB_PUBLIC(void, acc_set_be24) (acc_hvoid_p p, acc_uint32l_t v)
{
acc_hbyte_p b = (acc_hbyte_p) p;
b[2] = (unsigned char) ((v >> 0) & 0xff);
b[1] = (unsigned char) ((v >> 8) & 0xff);
b[0] = (unsigned char) ((v >> 16) & 0xff);
}
ACCLIB_PUBLIC(void, acc_set_be32) (acc_hvoid_p p, acc_uint32l_t v)
{
acc_hbyte_p b = (acc_hbyte_p) p;
b[3] = (unsigned char) ((v >> 0) & 0xff);
b[2] = (unsigned char) ((v >> 8) & 0xff);
b[1] = (unsigned char) ((v >> 16) & 0xff);
b[0] = (unsigned char) ((v >> 24) & 0xff);
}
ACCLIB_PUBLIC(unsigned, acc_get_le16) (const acc_hvoid_p p)
{
#if (ACC_ARCH_IA32)
return (* (const unsigned short *) (p));
#else
const acc_hbyte_p b = (const acc_hbyte_p) p;
return ((unsigned)b[0]) | ((unsigned)b[1] << 8);
#endif
}
ACCLIB_PUBLIC(acc_uint32l_t, acc_get_le24) (const acc_hvoid_p p)
{
const acc_hbyte_p b = (const acc_hbyte_p) p;
return ((acc_uint32l_t)b[0]) | ((acc_uint32l_t)b[1] << 8) | ((acc_uint32l_t)b[2] << 16);
}
ACCLIB_PUBLIC(acc_uint32l_t, acc_get_le32) (const acc_hvoid_p p)
{
#if (ACC_ARCH_IA32)
return (* (const unsigned int *) (p));
#else
const acc_hbyte_p b = (const acc_hbyte_p) p;
return ((acc_uint32l_t)b[0]) | ((acc_uint32l_t)b[1] << 8) | ((acc_uint32l_t)b[2] << 16) | ((acc_uint32l_t)b[3] << 24);
#endif
}
ACCLIB_PUBLIC(void, acc_set_le16) (acc_hvoid_p p, unsigned v)
{
#if (ACC_ARCH_IA32)
(* (unsigned short *) (p) = (unsigned short) (v));
#else
acc_hbyte_p b = (acc_hbyte_p) p;
b[0] = (unsigned char) ((v >> 0) & 0xff);
b[1] = (unsigned char) ((v >> 8) & 0xff);
#endif
}
ACCLIB_PUBLIC(void, acc_set_le24) (acc_hvoid_p p, acc_uint32l_t v)
{
acc_hbyte_p b = (acc_hbyte_p) p;
b[0] = (unsigned char) ((v >> 0) & 0xff);
b[1] = (unsigned char) ((v >> 8) & 0xff);
b[2] = (unsigned char) ((v >> 16) & 0xff);
}
ACCLIB_PUBLIC(void, acc_set_le32) (acc_hvoid_p p, acc_uint32l_t v)
{
#if (ACC_ARCH_IA32)
(* (unsigned int *) (p) = (unsigned int) (v));
#else
acc_hbyte_p b = (acc_hbyte_p) p;
b[0] = (unsigned char) ((v >> 0) & 0xff);
b[1] = (unsigned char) ((v >> 8) & 0xff);
b[2] = (unsigned char) ((v >> 16) & 0xff);
b[3] = (unsigned char) ((v >> 24) & 0xff);
#endif
}
ACCLIB_PUBLIC(unsigned, acc_get_le16) (const acc_hvoid_p);
ACCLIB_PUBLIC(acc_uint32l_t, acc_get_le24) (const acc_hvoid_p);
ACCLIB_PUBLIC(acc_uint32l_t, acc_get_le32) (const acc_hvoid_p);
ACCLIB_PUBLIC(void, acc_set_le16) (acc_hvoid_p, unsigned v);
ACCLIB_PUBLIC(void, acc_set_le24) (acc_hvoid_p, acc_uint32l_t v);
ACCLIB_PUBLIC(void, acc_set_le32) (acc_hvoid_p, acc_uint32l_t v);
#if defined(acc_uint64l_t)
ACCLIB_PUBLIC(acc_uint64l_t, acc_get_be64) (const acc_hvoid_p);
ACCLIB_PUBLIC(void, acc_set_be64) (acc_hvoid_p, acc_uint64l_t v);
ACCLIB_PUBLIC(acc_uint64l_t, acc_get_le64) (const acc_hvoid_p);
ACCLIB_PUBLIC(void, acc_set_le64) (acc_hvoid_p, acc_uint64l_t v);
#endif
ACCLIB_PUBLIC(acc_uint64l_t, acc_get_be64) (const acc_hvoid_p p)
{
const acc_hbyte_p b = (const acc_hbyte_p) p;
return ((acc_uint64l_t)b[0]) | ((acc_uint64l_t)b[1] << 8) | ((acc_uint64l_t)b[2] << 16) | ((acc_uint64l_t)b[3] << 24) | ((acc_uint64l_t)b[4] << 32) | ((acc_uint64l_t)b[5] << 40) | ((acc_uint64l_t)b[6] << 48) | ((acc_uint64l_t)b[7] << 56);
}
ACCLIB_PUBLIC(void, acc_set_be64) (acc_hvoid_p p, acc_uint64l_t v)
{
acc_hbyte_p b = (acc_hbyte_p) p;
b[7] = (unsigned char) ((v >> 0) & 0xff);
b[6] = (unsigned char) ((v >> 8) & 0xff);
b[5] = (unsigned char) ((v >> 16) & 0xff);
b[4] = (unsigned char) ((v >> 24) & 0xff);
b[3] = (unsigned char) ((v >> 32) & 0xff);
b[2] = (unsigned char) ((v >> 40) & 0xff);
b[1] = (unsigned char) ((v >> 48) & 0xff);
b[0] = (unsigned char) ((v >> 56) & 0xff);
}
ACCLIB_PUBLIC(acc_uint64l_t, acc_get_le64) (const acc_hvoid_p p)
{
const acc_hbyte_p b = (const acc_hbyte_p) p;
return ((acc_uint64l_t)b[7]) | ((acc_uint64l_t)b[6] << 8) | ((acc_uint64l_t)b[5] << 16) | ((acc_uint64l_t)b[4] << 24) | ((acc_uint64l_t)b[3] << 32) | ((acc_uint64l_t)b[2] << 40) | ((acc_uint64l_t)b[1] << 48) | ((acc_uint64l_t)b[0] << 56);
}
ACCLIB_PUBLIC(void, acc_set_le64) (acc_hvoid_p p, acc_uint64l_t v)
{
acc_hbyte_p b = (acc_hbyte_p) p;
b[0] = (unsigned char) ((v >> 0) & 0xff);
b[1] = (unsigned char) ((v >> 8) & 0xff);
b[2] = (unsigned char) ((v >> 16) & 0xff);
b[3] = (unsigned char) ((v >> 24) & 0xff);
b[4] = (unsigned char) ((v >> 32) & 0xff);
b[5] = (unsigned char) ((v >> 40) & 0xff);
b[6] = (unsigned char) ((v >> 48) & 0xff);
b[7] = (unsigned char) ((v >> 56) & 0xff);
}
#endif /* acc_uint64l_t */
/*

View File

@ -105,10 +105,8 @@ ACCLIB_PUBLIC(int, acc_isatty) (int fd)
#if (ACC_OS_DOS16 && !defined(ACC_CC_AZTECC))
{
union REGS ri, ro;
ri.x.ax = 0x4400;
ri.x.bx = fd;
ro.x.ax = 0xffff;
ro.x.cflag = 1;
ri.x.ax = 0x4400; ri.x.bx = fd;
ro.x.ax = 0xffff; ro.x.cflag = 1;
int86(0x21, &ri, &ro);
if ((ro.x.cflag & 1) == 0) /* if carry flag not set */
if ((ro.x.ax & 0x83) != 0x83)
@ -116,7 +114,13 @@ ACCLIB_PUBLIC(int, acc_isatty) (int fd)
}
#elif (ACC_OS_DOS32 && ACC_CC_WATCOMC)
{
/* FIXME */
union REGS ri, ro;
ri.w.ax = 0x4400; ri.w.bx = (unsigned short) fd;
ro.w.ax = 0xffff; ro.w.cflag = 1;
int386(0x21, &ri, &ro);
if ((ro.w.cflag & 1) == 0) /* if carry flag not set */
if ((ro.w.ax & 0x83) != 0x83)
return 0;
}
#elif (ACC_H_WINDOWS_H)
{
@ -153,26 +157,17 @@ ACCLIB_PUBLIC(int, acc_mkdir) (const char* name, unsigned mode)
ACCLIB_PUBLIC(acc_int32l_t, acc_muldiv32) (acc_int32l_t a, acc_int32l_t b, acc_int32l_t x)
{
acc_int32l_t r = 0;
if (x == 0)
return r;
#if (SIZEOF_ACC_INT32L_T > 4)
if (a > ACC_INT32L_C(2147483647) || b > (ACC_INT32L_C(-2147483647) - 1))
return r;
#endif
if (x == 0) return x;
/* FIXME */
ACC_UNUSED(a); ACC_UNUSED(b);
return r;
}
ACCLIB_PUBLIC(acc_uint32l_t, acc_umuldiv32) (acc_uint32l_t a, acc_uint32l_t b, acc_uint32l_t x)
{
acc_uint32l_t r = 0;
if (x == 0)
return r;
#if (SIZEOF_ACC_INT32L_T > 4)
if (a > ACC_UINT32L_C(0xffffffff) || b > ACC_UINT32L_C(0xffffffff))
return r;
#endif
if (x == 0) return x;
/* FIXME */
ACC_UNUSED(a); ACC_UNUSED(b);
return r;

View File

@ -29,7 +29,7 @@ ACCLIB_PUBLIC(void, acc_srand31) (acc_rand31_t* r, acc_uint32l_t seed)
ACCLIB_PUBLIC(acc_uint32l_t, acc_rand31) (acc_rand31_t* r)
{
r->seed = (r->seed * ACC_UINT32L_C(1103515245)) + 12345;
r->seed = r->seed * ACC_UINT32L_C(1103515245) + 12345;
r->seed &= ACC_UINT32L_C(0x7fffffff);
return r->seed;
}
@ -45,11 +45,18 @@ ACCLIB_PUBLIC(void, acc_srand48) (acc_rand48_t* r, acc_uint32l_t seed)
ACCLIB_PUBLIC(acc_uint32l_t, acc_rand48) (acc_rand48_t* r)
{
r->seed = (r->seed * ACC_UINT64L_C(25214903917)) + 11;
r->seed = r->seed * ACC_UINT64L_C(25214903917) + 11;
r->seed &= ACC_UINT64L_C(0xffffffffffff);
return (acc_uint32l_t) (r->seed >> 17);
}
ACCLIB_PUBLIC(acc_uint32l_t, acc_rand48_r32) (acc_rand48_t* r)
{
r->seed = r->seed * ACC_UINT64L_C(25214903917) + 11;
r->seed &= ACC_UINT64L_C(0xffffffffffff);
return (acc_uint32l_t) (r->seed >> 16);
}
#endif /* defined(acc_uint64l_t) */
@ -62,14 +69,62 @@ ACCLIB_PUBLIC(void, acc_srand64) (acc_rand64_t* r, acc_uint64l_t seed)
ACCLIB_PUBLIC(acc_uint32l_t, acc_rand64) (acc_rand64_t* r)
{
r->seed = (r->seed * ACC_UINT64L_C(6364136223846793005)) + 1;
r->seed = r->seed * ACC_UINT64L_C(6364136223846793005) + 1;
r->seed &= ACC_UINT64L_C(0xffffffffffffffff);
return (acc_uint32l_t) (r->seed >> 33);
}
ACCLIB_PUBLIC(acc_uint32l_t, acc_rand64_r32) (acc_rand64_t* r)
{
r->seed = r->seed * ACC_UINT64L_C(6364136223846793005) + 1;
r->seed &= ACC_UINT64L_C(0xffffffffffffffff);
return (acc_uint32l_t) (r->seed >> 32);
}
#endif /* defined(acc_uint64l_t) */
/*************************************************************************
// mersenne twister
**************************************************************************/
ACCLIB_PUBLIC(void, acc_srandmt) (acc_randmt_t* r, acc_uint32l_t seed)
{
unsigned i = 0;
do {
r->s[i++] = (seed &= ACC_UINT32L_C(0xffffffff));
seed ^= seed >> 30;
seed = seed * ACC_UINT32L_C(0x6c078965) + i;
} while (i != 624);
r->n = i;
}
ACCLIB_PUBLIC(acc_uint32l_t, acc_randmt) (acc_randmt_t* r)
{
return (__ACCLIB_FUNCNAME(acc_randmt_r32)(r)) >> 1;
}
ACCLIB_PUBLIC(acc_uint32l_t, acc_randmt_r32) (acc_randmt_t* r)
{
acc_uint32l_t v;
if (r->n == 624) {
int i = 0, j;
r->n = i;
do {
j = i - 623; if (j < 0) j += 624;
v = (r->s[i] & ACC_UINT32L_C(0x80000000)) ^ (r->s[j] & ACC_UINT32L_C(0x7fffffff));
j = i - 227; if (j < 0) j += 624;
r->s[i] = r->s[j] ^ (v >> 1);
if (v & 1) r->s[i] ^= ACC_UINT32L_C(0x9908b0df);
} while (++i != 624);
}
v = r->s[r->n++];
v ^= v >> 11; v ^= (v & ACC_UINT32L_C(0x013a58ad)) << 7;
v ^= (v & ACC_UINT32L_C(0x0001df8c)) << 15; v ^= v >> 18;
return v;
}
/*
vi:ts=4:et
*/

187
src/acc/acclib/uclock.ch Normal file
View File

@ -0,0 +1,187 @@
/* ACC -- Automatic Compiler Configuration
Copyright (C) 1996-2003 Markus Franz Xaver Johannes Oberhumer
All Rights Reserved.
This software is a copyrighted work licensed under the terms of
the GNU General Public License. Please consult the file "ACC_LICENSE"
for details.
Markus F.X.J. Oberhumer
<markus@oberhumer.com>
http://www.oberhumer.com/
*/
#if !defined(ACCLIB_PUBLIC)
# define ACCLIB_PUBLIC(r,f) r __ACCLIB_FUNCNAME(f)
#endif
#if (ACC_H_WINDOWS_H) && defined(acc_int64l_t)
/* See also: KB Q274323: PRB: Performance Counter Value May
* Unexpectedly Leap Forward */
# define __ACCLIB_UCLOCK_USE_QPC 1
#endif
#if (ACC_OS_DOS16 || ACC_OS_WIN16)
#elif (ACC_OS_DOS32 && defined(__DJGPP__))
#elif (ACC_OS_DOS32 || ACC_OS_OS2 || ACC_OS_OS216)
# define __ACCLIB_UCLOCK_USE_CLOCK 1
#elif (ACC_H_WINDOWS_H) && (ACC_OS_WIN32 || ACC_OS_WIN64)
# if (ACC_CC_DMC || ACC_CC_LCC)
/* winmm.lib is missing */
# define __ACCLIB_UCLOCK_USE_CLOCK 1
# else
# define __ACCLIB_UCLOCK_USE_MMSYSTEM 1
# if (ACC_CC_MSC && (_MSC_VER >= 1000))
/* avoid -W4 warnings in <mmsystem.h> */
# pragma warning(disable: 4201)
# endif
# include <mmsystem.h>
# if (ACC_CC_INTELC || ACC_CC_MSC)
# pragma comment(lib,"winmm")
# endif
# endif
#endif
/*************************************************************************
//
**************************************************************************/
ACCLIB_PUBLIC(int, acc_uclock_open) (acc_uclock_handle_t* h)
{
acc_uclock_t c;
int i;
#if (__ACCLIB_UCLOCK_USE_QPC)
LARGE_INTEGER li;
h->qpf = 0.0;
if (QueryPerformanceFrequency(&li) != 0) {
h->qpf = (double) li.QuadPart;
if (h->qpf <= 0.0 || QueryPerformanceCounter(&li) == 0) {
h->qpf = 0.0;
}
}
#endif
h->h = 1;
/* warm up */
i = 100;
do {
acc_uclock_read(h, &c);
#if (__ACCLIB_UCLOCK_USE_QPC)
if (h->qpf > 0.0 && c.qpc == 0) { h->qpf = 0.0; i = 100; }
#endif
} while (--i > 0);
return 0;
}
ACCLIB_PUBLIC(int, acc_uclock_close) (acc_uclock_handle_t* h)
{
h->h = 0;
h->mode = 0;
return 0;
}
ACCLIB_PUBLIC(void, acc_uclock_read) (acc_uclock_handle_t* h, acc_uclock_t* c)
{
#if (__ACCLIB_UCLOCK_USE_QPC)
if (h->qpf > 0.0) {
LARGE_INTEGER li;
if (QueryPerformanceCounter(&li) != 0) {
c->qpc = (acc_int64l_t) li.QuadPart;
if (c->qpc > 0)
return;
}
c->qpc = 0; /* failed */
}
#endif
{
#if (ACC_OS_DOS16 || ACC_OS_WIN16)
# if (ACC_CC_AZTECC)
c->ticks.t32 = 0;
# else
union REGS ri, ro;
ri.x.ax = 0x2c00; int86(0x21, &ri, &ro);
c->ticks.t32 = ro.h.ch*60UL*60UL*100UL + ro.h.cl*60UL*100UL + ro.h.dh*100UL + ro.h.dl;
# endif
#elif (ACC_OS_DOS32 && defined(__DJGPP__))
c->ticks.t64 = uclock();
#elif (__ACCLIB_UCLOCK_USE_CLOCK) && defined(acc_int64l_t)
c->ticks.t64 = clock();
#elif (__ACCLIB_UCLOCK_USE_CLOCK)
c->ticks.t32 = clock();
#elif (__ACCLIB_UCLOCK_USE_MMSYSTEM)
c->ticks.t32 = timeGetTime();
#elif (__ACCLIB_UCLOCK_USE_GETRUSAGE)
struct rusage ru;
if (getrusage(RUSAGE_SELF, &ru) != 0) c->ticks.rd = 0;
else c->ticks.td = ru.ru_utime.tv_sec + ru.ru_utime.tv_usec / 1000000.0;
#elif (HAVE_GETTIMEOFDAY)
struct timeval tv;
if (gettimeofday(&tv, 0) != 0) c->ticks.td = 0;
else c->ticks.td = tv.tv_sec + tv.tv_usec / 1000000.0;
#else
ACC_UNUSED(c);
#endif
}
ACC_UNUSED(h);
}
ACCLIB_PUBLIC(double, acc_uclock_get_elapsed) (acc_uclock_handle_t* h, const acc_uclock_t* start, const acc_uclock_t* stop)
{
double d;
if (!h->h)
return 0.0;
#if (__ACCLIB_UCLOCK_USE_QPC)
if (h->qpf > 0.0) {
h->mode = 1;
if (start->qpc == 0 || stop->qpc == 0) return 0.0;
return (double) (stop->qpc - start->qpc) / h->qpf;
}
#endif
#if (ACC_OS_DOS16 || ACC_OS_WIN16)
h->mode = 2;
if (stop->ticks.t32 < start->ticks.t32) /* midnight passed */
d = 86400.0 - (start->ticks.t32 - stop->ticks.t32) / 100.0;
else
d = (stop->ticks.t32 - start->ticks.t32) / 100.0;
#elif (ACC_OS_DOS32 && defined(__DJGPP__))
h->mode = 3;
d = (double) (stop->ticks.t64 - start->ticks.t64) / (UCLOCKS_PER_SEC);
#elif (__ACCLIB_UCLOCK_USE_CLOCK) && defined(acc_int64l_t)
h->mode = 4;
d = (double) (stop->ticks.t64 - start->ticks.t64) / (CLOCKS_PER_SEC);
#elif (__ACCLIB_UCLOCK_USE_CLOCK)
h->mode = 5;
d = (double) (stop->ticks.t32 - start->ticks.t32) / (CLOCKS_PER_SEC);
#elif (__ACCLIB_UCLOCK_USE_MMSYSTEM)
h->mode = 6;
d = (double) (stop->ticks.t32 - start->ticks.t32) / 1000.0;
#elif (__ACCLIB_UCLOCK_USE_GETRUSAGE)
h->mode = 7;
d = stop->ticks.td - start->ticks.td;
#elif (HAVE_GETTIMEOFDAY)
h->mode = 8;
d = stop->ticks.td - start->ticks.td;
#else
h->mode = 0;
d = 0.0;
#endif
return d;
}
/*
vi:ts=4:et
*/