mirror of
https://gitea.wildfiregames.com/0ad/0ad
synced 2026-07-04 05:55:47 -07:00
sync with work. faster PopulationCount; avoid invalid param handler when debug string length exceeded; return error instead of dialog box when waio_Preallocate fails
This was SVN commit r10414.
This commit is contained in:
parent
a41b0e30fe
commit
ff256528f2
4 changed files with 28 additions and 8 deletions
|
|
@ -122,14 +122,12 @@ inline T SetBitsTo(T num, size_t lo_idx, size_t hi_idx, size_t value)
|
|||
|
||||
|
||||
/**
|
||||
* @return number of 1-bits in mask
|
||||
* @return number of 1-bits in mask.
|
||||
* execution time is proportional to number of 1-bits in mask.
|
||||
**/
|
||||
template<typename T>
|
||||
inline size_t PopulationCount(T mask)
|
||||
inline size_t SparsePopulationCount(T mask)
|
||||
{
|
||||
// note: a more complex but probably faster method is given at
|
||||
// http://graphics.stanford.edu/~seander/bithacks.html#CountBitsSetParallel
|
||||
|
||||
size_t num1Bits = 0;
|
||||
while(mask)
|
||||
{
|
||||
|
|
@ -140,6 +138,24 @@ inline size_t PopulationCount(T mask)
|
|||
return num1Bits;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return number of 1-bits in mask.
|
||||
* execution time is logarithmic in the total number of bits.
|
||||
* supports up to 128-bit integers (if their arithmetic operators are defined).
|
||||
* [http://graphics.stanford.edu/~seander/bithacks.html#CountBitsSetParallel]
|
||||
**/
|
||||
template<typename T>
|
||||
static inline size_t PopulationCount(T x)
|
||||
{
|
||||
const T mask = T(~T(0));
|
||||
x -= (x >> 1) & (mask/3); // count 2 bits
|
||||
x = (x & (mask/15*3)) + ((x >> 2) & (mask/15*3)); // count 4 bits
|
||||
x = (x + (x >> 4)) & (mask/255*15); // count 8 bits
|
||||
return (x * (mask/255)) >> ((sizeof(T)-1)*CHAR_BIT);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @return whether the given number is a power of two.
|
||||
**/
|
||||
|
|
|
|||
|
|
@ -225,7 +225,7 @@ public:
|
|||
{
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
const int len = vswprintf_s(m_pos, m_charsLeft, fmt, ap);
|
||||
const int len = vswprintf(m_pos, m_charsLeft, fmt, ap);
|
||||
va_end(ap);
|
||||
if(len < 0)
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -455,7 +455,11 @@ Status waio_Preallocate(int fd, off_t size)
|
|||
// allocate all space up front to reduce fragmentation
|
||||
LARGE_INTEGER size64; size64.QuadPart = alignedSize;
|
||||
WARN_IF_FALSE(SetFilePointerEx(hFile, size64, 0, FILE_BEGIN));
|
||||
WARN_IF_FALSE(SetEndOfFile(hFile));
|
||||
if(!SetEndOfFile(hFile))
|
||||
{
|
||||
debug_printf(L"Preallocate(%lld) failed: %d\n", size, GetLastError());
|
||||
return ERR::FAIL; // NOWARN (probably not enough disk space)
|
||||
}
|
||||
|
||||
// avoid synchronous zero-fill (see discussion in header)
|
||||
if(pSetFileValidData)
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ static WUTIL_FUNC(pVirtualAllocExNuma, LPVOID, (HANDLE, LPVOID, SIZE_T, DWORD, D
|
|||
static DWORD WINAPI EmulateGetCurrentProcessorNumber(VOID)
|
||||
{
|
||||
const u8 apicId = x86_x64_ApicId();
|
||||
const DWORD processor = ProcessorFromApicId(apicId);
|
||||
const DWORD processor = (DWORD)ProcessorFromApicId(apicId);
|
||||
ASSERT(processor < os_cpu_MaxProcessors);
|
||||
return processor;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue