示例#1
0
TEST(BitsTest_CountZeros, Constants) {
    ASSERT_EQUALS(countLeadingZeros64(0ull), 64);
    ASSERT_EQUALS(countTrailingZeros64(0ull), 64);

    ASSERT_EQUALS(countLeadingZeros64(0x1234ull), 64 - 13);
    ASSERT_EQUALS(countTrailingZeros64(0x1234ull), 2);

    ASSERT_EQUALS(countLeadingZeros64(0x1234ull << 32), 32 - 13);
    ASSERT_EQUALS(countTrailingZeros64(0x1234ull << 32), 2 + 32);

    ASSERT_EQUALS(countLeadingZeros64((0x1234ull << 32) | 0x1234ull), 32 - 13);
    ASSERT_EQUALS(countTrailingZeros64((0x1234ull << 32) | 0x1234ull), 2);
}
示例#2
0
TEST(BitsTest_CountZeros, EachBit) {
    for (int i = 0; i < 64; i++) {
        unsigned long long x = 1ULL << i;
        ASSERT_EQUALS(countLeadingZeros64(x), 64 - 1 - i);
        ASSERT_EQUALS(countTrailingZeros64(x), i);
    }
}
// Computes the log base 2 of value, and checks for cases of split buckets.
int OperationLatencyHistogram::_getBucket(uint64_t value) {
    // Zero is a special case since log(0) is undefined.
    if (value == 0) {
        return 0;
    }

    int log2 = 63 - countLeadingZeros64(value);
    // Half splits occur in range [2^11, 2^21) giving 10 extra buckets.
    if (log2 < 11) {
        return log2;
    } else if (log2 < 21) {
        int extra = log2 - 11;
        // Split value boundary is at (2^n + 2^(n+1))/2 = 2^n + 2^(n-1).
        // Which corresponds to (1ULL << log2) | (1ULL << (log2 - 1))
        // Which is equivalent to the following:
        uint64_t splitBoundary = 3ULL << (log2 - 1);
        if (value >= splitBoundary) {
            extra++;
        }
        return log2 + extra;
    } else {
        // Add all of the extra 10 buckets.
        return std::min(log2 + 10, kMaxBuckets - 1);
    }
}
示例#4
0
static float64
normalizeRoundAndPackFloat64 (flag zSign, int16 zExp, bits64 zSig)
{
  int8 shiftCount;

  shiftCount = countLeadingZeros64 (zSig) - 1;
  return roundAndPackFloat64 (zSign, zExp - shiftCount, zSig << shiftCount);

}
示例#5
0
static void
normalizeFloat64Subnormal (bits64 aSig, int16 * zExpPtr, bits64 * zSigPtr)
{
  int8 shiftCount;

  shiftCount = countLeadingZeros64 (aSig) - 11;
  *zSigPtr = aSig << shiftCount;
  *zExpPtr = 1 - shiftCount;

}
示例#6
0
	static void addFeature( List< ShaderFeature >& features, const string& name, uint32 maxValue )
	{
		const ShaderFeature* pLastFeature = nullptr;
		if ( features.getCount() > 0u )
		{
			pLastFeature = &features.getLast();
		}

		ShaderFeature feature;
		feature.name		= name;
		feature.bitCount	= uint32( 64u - countLeadingZeros64( maxValue ) );
		feature.maxValue	= maxValue;

		if ( pLastFeature != nullptr )
		{
			feature.startBit = pLastFeature->startBit + pLastFeature->bitCount;
		}
		else
		{
			feature.startBit = 0u;
		}

		features.add( feature );
	}
示例#7
0
void normalizeFloatx80Subnormal(UINT64 aSig, INT32 *zExpPtr, UINT64 *zSigPtr)
{
	int shiftCount = countLeadingZeros64(aSig);
	*zSigPtr = aSig<<shiftCount;
	*zExpPtr = 1 - shiftCount;
}