Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Functions
SkMathPriv.cpp File Reference
#include "src/base/SkMathPriv.h"
#include "include/private/base/SkAssert.h"
#include <cstdint>

Go to the source code of this file.

Functions

int32_t SkSqrtBits (int32_t x, int count)
 
int SkPopCount_portable (uint32_t n)
 
int SkNthSet (uint32_t target, int n)
 

Function Documentation

◆ SkNthSet()

int SkNthSet ( uint32_t  target,
int  n 
)

Definition at line 53 of file SkMathPriv.cpp.

53 {
55
56 for (int i = 0; i < n; ++i) {
57 target &= (target - 1); // Remove the lowest bit in the integer.
58 }
59
60 return SkCTZ(target);
61}
#define SkASSERT(cond)
Definition SkAssert.h:116
static int SkPopCount(uint32_t n)
Definition SkMathPriv.h:136
static int SkCTZ(uint32_t mask)
Definition SkMathPriv.h:224
uint32_t * target

◆ SkPopCount_portable()

int SkPopCount_portable ( uint32_t  n)

Definition at line 42 of file SkMathPriv.cpp.

42 {
43 int count = 0;
44
45 while (n) {
46 n &= (n - 1); // Remove the lowest bit in the integer.
47 count++;
48 }
49 return count;
50}
int count

◆ SkSqrtBits()

int32_t SkSqrtBits ( int32_t  value,
int  bitBias 
)

Return the integer square root of value, with a bias of bitBias

Definition at line 18 of file SkMathPriv.cpp.

18 {
19 SkASSERT(x >= 0 && count > 0 && (unsigned)count <= 30);
20
21 uint32_t root = 0;
22 uint32_t remHi = 0;
23 uint32_t remLo = x;
24
25 do {
26 root <<= 1;
27
28 remHi = (remHi<<2) | (remLo>>30);
29 remLo <<= 2;
30
31 uint32_t testDiv = (root << 1) + 1;
32 if (remHi >= testDiv) {
33 remHi -= testDiv;
34 root++;
35 }
36 } while (--count >= 0);
37
38 return root;
39}
double x