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

Go to the source code of this file.

Functions

static constexpr int32_t Sk64_pin_to_s32 (int64_t x)
 
static constexpr int32_t Sk32_sat_add (int32_t a, int32_t b)
 
static constexpr int32_t Sk32_sat_sub (int32_t a, int32_t b)
 
static constexpr int32_t Sk32_can_overflow_add (int32_t a, int32_t b)
 
static constexpr int32_t Sk32_can_overflow_sub (int32_t a, int32_t b)
 
static int32_t SkAbs32 (int32_t value)
 

Function Documentation

◆ Sk32_can_overflow_add()

static constexpr int32_t Sk32_can_overflow_add ( int32_t  a,
int32_t  b 
)
staticconstexpr

Definition at line 30 of file SkSafe32.h.

30 {
31 return (int32_t)((uint32_t)a + (uint32_t)b);
32}
static bool b
struct MyStruct a[10]

◆ Sk32_can_overflow_sub()

static constexpr int32_t Sk32_can_overflow_sub ( int32_t  a,
int32_t  b 
)
staticconstexpr

Definition at line 33 of file SkSafe32.h.

33 {
34 return (int32_t)((uint32_t)a - (uint32_t)b);
35}

◆ Sk32_sat_add()

static constexpr int32_t Sk32_sat_add ( int32_t  a,
int32_t  b 
)
staticconstexpr

Definition at line 20 of file SkSafe32.h.

20 {
21 return Sk64_pin_to_s32((int64_t)a + (int64_t)b);
22}
static constexpr int32_t Sk64_pin_to_s32(int64_t x)
Definition SkSafe32.h:16

◆ Sk32_sat_sub()

static constexpr int32_t Sk32_sat_sub ( int32_t  a,
int32_t  b 
)
staticconstexpr

Definition at line 24 of file SkSafe32.h.

24 {
25 return Sk64_pin_to_s32((int64_t)a - (int64_t)b);
26}

◆ Sk64_pin_to_s32()

static constexpr int32_t Sk64_pin_to_s32 ( int64_t  x)
staticconstexpr

Definition at line 16 of file SkSafe32.h.

16 {
17 return x < SK_MinS32 ? SK_MinS32 : (x > SK_MaxS32 ? SK_MaxS32 : (int32_t)x);
18}
static constexpr int32_t SK_MinS32
Definition SkMath.h:22
static constexpr int32_t SK_MaxS32
Definition SkMath.h:21
double x

◆ SkAbs32()

static int32_t SkAbs32 ( int32_t  value)
inlinestatic

This is a 'safe' abs for 32-bit integers that asserts when undefined behavior would occur. SkTAbs (in SkTemplates.h) is a general purpose absolute-value function.

Definition at line 41 of file SkSafe32.h.

41 {
42 SkASSERT(value != SK_NaN32); // The most negative int32_t can't be negated.
43 if (value < 0) {
44 value = -value;
45 }
46 return value;
47}
#define SkASSERT(cond)
Definition SkAssert.h:116
static constexpr int32_t SK_NaN32
Definition SkMath.h:23
uint8_t value