Move some functions to MathPriv.h
Change-Id: I22c57a746e4a997fc03f35aa06b23d9fa9ed4fa9 Reviewed-on: https://skia-review.googlesource.com/152183 Commit-Queue: Hal Canary <halcanary@google.com> Commit-Queue: Mike Klein <mtklein@google.com> Auto-Submit: Hal Canary <halcanary@google.com> Reviewed-by: Mike Klein <mtklein@google.com>
This commit is contained in:
parent
33d3d31a7e
commit
2d40490d4c
@ -5,11 +5,9 @@
|
||||
* found in the LICENSE file.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef SkMath_DEFINED
|
||||
#define SkMath_DEFINED
|
||||
|
||||
#include "../private/SkTo.h"
|
||||
#include "SkTypes.h"
|
||||
|
||||
// 64bit -> 32bit utilities
|
||||
@ -23,22 +21,6 @@ static inline int64_t sk_64_mul(int64_t a, int64_t b) {
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/**
|
||||
* Return the integer square root of value, with a bias of bitBias
|
||||
*/
|
||||
int32_t SkSqrtBits(int32_t value, int bitBias);
|
||||
|
||||
/** Return the integer square root of n, treated as a SkFixed (16.16)
|
||||
*/
|
||||
#define SkSqrt32(n) SkSqrtBits(n, 15)
|
||||
|
||||
/**
|
||||
* Returns (value < 0 ? 0 : value) efficiently (i.e. no compares or branches)
|
||||
*/
|
||||
static inline int SkClampPos(int value) {
|
||||
return value & ~(value >> 31);
|
||||
}
|
||||
|
||||
/** Given an integer and a positive (max) integer, return the value
|
||||
* pinned against 0 and max, inclusive.
|
||||
* @param value The value we want returned pinned between [0...max]
|
||||
@ -90,26 +72,4 @@ static inline U8CPU SkMulDiv255Round(U16CPU a, U16CPU b) {
|
||||
return (prod + (prod >> 8)) >> 8;
|
||||
}
|
||||
|
||||
/**
|
||||
* Stores numer/denom and numer%denom into div and mod respectively.
|
||||
*/
|
||||
template <typename In, typename Out>
|
||||
inline void SkTDivMod(In numer, In denom, Out* div, Out* mod) {
|
||||
#ifdef SK_CPU_ARM32
|
||||
// If we wrote this as in the else branch, GCC won't fuse the two into one
|
||||
// divmod call, but rather a div call followed by a divmod. Silly! This
|
||||
// version is just as fast as calling __aeabi_[u]idivmod manually, but with
|
||||
// prettier code.
|
||||
//
|
||||
// This benches as around 2x faster than the code in the else branch.
|
||||
const In d = numer/denom;
|
||||
*div = static_cast<Out>(d);
|
||||
*mod = static_cast<Out>(numer-d*denom);
|
||||
#else
|
||||
// On x86 this will just be a single idiv.
|
||||
*div = static_cast<Out>(numer/denom);
|
||||
*mod = static_cast<Out>(numer%denom);
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -8,6 +8,7 @@
|
||||
#include "SkBmpStandardCodec.h"
|
||||
#include "SkCodecPriv.h"
|
||||
#include "SkColorData.h"
|
||||
#include "SkMathPriv.h"
|
||||
#include "SkStream.h"
|
||||
|
||||
/*
|
||||
|
@ -8,6 +8,7 @@
|
||||
#include "SkCodec.h"
|
||||
#include "SkCodecPriv.h"
|
||||
#include "SkMath.h"
|
||||
#include "SkMathPriv.h"
|
||||
#include "SkSampledCodec.h"
|
||||
#include "SkSampler.h"
|
||||
#include "SkTemplates.h"
|
||||
|
@ -7,12 +7,13 @@
|
||||
|
||||
#include "SkBlurMask.h"
|
||||
|
||||
#include "SkTo.h"
|
||||
#include "SkColorPriv.h"
|
||||
#include "SkEndian.h"
|
||||
#include "SkMaskBlurFilter.h"
|
||||
#include "SkMath.h"
|
||||
#include "SkMathPriv.h"
|
||||
#include "SkTemplates.h"
|
||||
#include "SkEndian.h"
|
||||
#include "SkTo.h"
|
||||
|
||||
// This constant approximates the scaling done in the software path's
|
||||
// "high quality" mode, in SkBlurMask::Blur() (1 / sqrt(3)).
|
||||
|
@ -10,6 +10,44 @@
|
||||
|
||||
#include "SkMath.h"
|
||||
|
||||
/**
|
||||
* Return the integer square root of value, with a bias of bitBias
|
||||
*/
|
||||
int32_t SkSqrtBits(int32_t value, int bitBias);
|
||||
|
||||
/** Return the integer square root of n, treated as a SkFixed (16.16)
|
||||
*/
|
||||
static inline int32_t SkSqrt32(int32_t n) { return SkSqrtBits(n, 15); }
|
||||
|
||||
/**
|
||||
* Returns (value < 0 ? 0 : value) efficiently (i.e. no compares or branches)
|
||||
*/
|
||||
static inline int SkClampPos(int value) {
|
||||
return value & ~(value >> 31);
|
||||
}
|
||||
|
||||
/**
|
||||
* Stores numer/denom and numer%denom into div and mod respectively.
|
||||
*/
|
||||
template <typename In, typename Out>
|
||||
inline void SkTDivMod(In numer, In denom, Out* div, Out* mod) {
|
||||
#ifdef SK_CPU_ARM32
|
||||
// If we wrote this as in the else branch, GCC won't fuse the two into one
|
||||
// divmod call, but rather a div call followed by a divmod. Silly! This
|
||||
// version is just as fast as calling __aeabi_[u]idivmod manually, but with
|
||||
// prettier code.
|
||||
//
|
||||
// This benches as around 2x faster than the code in the else branch.
|
||||
const In d = numer/denom;
|
||||
*div = static_cast<Out>(d);
|
||||
*mod = static_cast<Out>(numer-d*denom);
|
||||
#else
|
||||
// On x86 this will just be a single idiv.
|
||||
*div = static_cast<Out>(numer/denom);
|
||||
*mod = static_cast<Out>(numer%denom);
|
||||
#endif
|
||||
}
|
||||
|
||||
/** Returns -1 if n < 0, else returns 0
|
||||
*/
|
||||
#define SkExtractSign(n) ((int32_t)(n) >> 31)
|
||||
|
@ -9,6 +9,7 @@
|
||||
|
||||
#include "SkFixed.h"
|
||||
#include "SkMath.h"
|
||||
#include "SkMathPriv.h"
|
||||
#include "SkTo.h"
|
||||
|
||||
static inline int nonzero_to_one(int x) {
|
||||
|
@ -23,6 +23,7 @@
|
||||
#include "SkMaskFilter.h"
|
||||
#include "SkMaskFilterBase.h"
|
||||
#include "SkMath.h"
|
||||
#include "SkMathPriv.h"
|
||||
#include "SkPaint.h"
|
||||
#include "SkPath.h"
|
||||
#include "SkPerlinNoiseShader.h"
|
||||
|
Loading…
Reference in New Issue
Block a user