/* * Copyright (c) 1998 by the University of Washington. All rights reserved. * * This is a proprietary and confidential document. Under no circumstances * may this document be used, modified, copied, distributed, or sold * without the express written permission of the copyright holder. */ /* * util.h */ #ifndef __UTIL_H__ #define __UTIL_H__ // Macro - try acquire a lock // // if the locking succeeds, then busy will // contain zero // otherwise it will contain 1. // In any case, lock will always be 1. // // Note: lock and busy have to be memory locations // // FIXME: Does XCHNG work in a multi-processor ? // #define macro_fast_lock(lockvar,busy) __asm { \ __asm mov eax, 1 \ __asm xchg lockvar, eax \ __asm mov busy, eax \ } // Macro - unlock // free a lock varaible #define macro_fast_unlock(lockvar) __asm { \ __asm mov lockvar, 0 \ } // Macro - spinlock // spin on a lock #define macro_fast_spinlock(lockvar,busy) {\ macro_fast_lock(lockvar,busy); \ while (busy) { \ Sleep(0); \ macro_fast_lock(lockvar,busy); \ } \ } // Macro - atomicinc // atomically increment a variable #define atomicinc(var) __asm { lock inc var } // Some code to deal with the cycle counters. #define GetCCMacro(_xxx) \ { unsigned __int32 _lo, _hi; \ __asm { __asm _emit 0x0f \ __asm _emit 0x31 \ __asm mov _lo, eax \ __asm mov _hi, edx } \ _xxx = ((__int64)_hi << 32) | _lo; \ } #define rdtsc __asm _emit 0x0f __asm _emit 0x31 #define cycle_counter(counter) \ __asm { \ rdtsc \ __asm mov counter.u.HighPart, edx \ __asm mov counter.u.LowPart, eax \ } #define lint_diff(z, x, y) \ z.u.LowPart = x.u.LowPart - y.u.LowPart; \ if (z.u.LowPart > x.u.LowPart) { \ z.u.HighPart = x.u.HighPart - y.u.HighPart - 1; \ } else { \ z.u.HighPart = x.u.HighPart - y.u.HighPart; \ } #define lint_add(z, x, y) \ z.u.HighPart = x.u.HighPart + y.u.HighPart; \ z.u.LowPart = x.u.LowPart + y.u.LowPart; \ if (z.u.LowPart < x.u.LowPart && z.u.LowPart < y.u.LowPart) { \ z.u.HighPart++; \ } #define lint_to_double(l) \ (double) (4096.0 * 1024.0 * 1024.0 * (double) l.u.HighPart + l.u.LowPart) #define FLAG_SEP '+' #define O_SEP '@' #endif /* __UTIL_H__ */