8#ifndef SkMathPriv_DEFINED
9#define SkMathPriv_DEFINED
37template <
typename In,
typename Out>
38inline void SkTDivMod(In numer, In denom, Out* div, Out* mod) {
39 *div =
static_cast<Out
>(numer/denom);
40 *mod =
static_cast<Out
>(numer%denom);
45#define SkExtractSign(n) ((int32_t)(n) >> 31)
79#pragma warning(disable : 4146)
81 return -
static_cast<size_t>(
value);
95 unsigned prod =
a*
b + 1;
96 return (prod + (prod >> 8)) >> 8;
105 unsigned prod =
a*
b + 255;
106 return (prod + (prod >> 8)) >> 8;
113 return (prod + (prod >> 8)) >> 8;
121 static inline uint32_t
SkBSwap32(uint32_t v) {
return _byteswap_ulong(v); }
123 static inline uint32_t
SkBSwap32(uint32_t v) {
return __builtin_bswap32(v); }
131#if defined(__GNUC__) || defined(__clang__)
133 return __builtin_popcount(n);
151 uint32_t
y =
x >> 16;
if (
y != 0) {n -= 16;
x =
y;}
152 y =
x >> 8;
if (
y != 0) {n -= 8;
x =
y;}
153 y =
x >> 4;
if (
y != 0) {n -= 4;
x =
y;}
154 y =
x >> 2;
if (
y != 0) {n -= 2;
x =
y;}
155 y =
x >> 1;
if (
y != 0) {
return n - 2;}
156 return n -
static_cast<int>(
x);
165#if defined(SK_BUILD_FOR_WIN)
168 static inline int SkCLZ(uint32_t mask) {
170 unsigned long index = 0;
171 _BitScanReverse(&index, mask);
174 #pragma warning(suppress : 6102)
180#elif defined(SK_CPU_ARM32) || defined(__GNUC__) || defined(__clang__)
181 static inline int SkCLZ(uint32_t mask) {
183 return mask ? __builtin_clz(mask) : 32;
186 static inline int SkCLZ(uint32_t mask) {
200static_assert( 2 ==
SkCTZ_portable((1 << 30) | (1 << 24) | (1 << 2)));
203#if defined(SK_BUILD_FOR_WIN)
206 static inline int SkCTZ(uint32_t mask) {
208 unsigned long index = 0;
209 _BitScanForward(&index, mask);
212 #pragma warning(suppress : 6102)
218#elif defined(SK_CPU_ARM32) || defined(__GNUC__) || defined(__clang__)
219 static inline int SkCTZ(uint32_t mask) {
221 return mask ? __builtin_ctz(mask) : 32;
224 static inline int SkCTZ(uint32_t mask) {
303 return n ? (1 << (32 -
SkCLZ(n - 1))) : 1;
310 constexpr int kNumSizeTBits = 8 *
sizeof(size_t);
311 constexpr size_t kHighBitSet = size_t(1) << (kNumSizeTBits - 1);
315 }
else if (n >= kHighBitSet) {
321 while (shift < kNumSizeTBits) {
static int SkPopCount(uint32_t n)
constexpr int SkPrevPow2_portable(int value)
static bool SkFitsInFixed(T x)
static unsigned SkDiv255Round(unsigned prod)
static int SkPrevLog2(uint32_t value)
constexpr int SkNextPow2_portable(int value)
static uint32_t SkBSwap32(uint32_t v)
constexpr int SkPrevLog2_portable(uint32_t value)
constexpr int SkCTZ_portable(uint32_t x)
Returns the number of trailing zero bits (0...32)
static int SkClampPos(int value)
static int SkPrevPow2(int value)
static int SkCTZ(uint32_t mask)
static int32_t SkApplySign(int32_t n, int32_t sign)
static U8CPU SkMulDiv255Trunc(U8CPU a, U8CPU b)
static unsigned SkClampUMax(unsigned value, unsigned max)
static U8CPU SkMulDiv255Ceiling(U8CPU a, U8CPU b)
void SkTDivMod(In numer, In denom, Out *div, Out *mod)
static int32_t SkCopySign32(int32_t x, int32_t y)
constexpr int SkCLZ_portable(uint32_t x)
Returns the number of leading zero bits (0...32)
static size_t sk_negate_to_size_t(int32_t value)
int32_t SkSqrtBits(int32_t value, int bitBias)
static uint32_t GrNextPow2(uint32_t n)
int SkPopCount_portable(uint32_t n)
static int32_t SkSqrt32(int32_t n)
constexpr int SkNextLog2_portable(uint32_t value)
static int SkCLZ(uint32_t mask)
int SkNthSet(uint32_t target, int n)
static int SkNextPow2(int value)
static int SkNextLog2(uint32_t value)
static size_t GrNextSizePow2(size_t n)
static int sign(SkScalar x)
static float max(float r, float g, float b)