d9187c085b
This reverts commit 3b347232bc
.
Reason for revert: tree done gone red.
Original change's description:
> SkMath takes some functions from from SkTypes
>
> Moved to include/core/SkMath.h: Sk{Is|}Align{2|4|8|Ptr}, SkLeftShift,
> SkAbs{32|}, SkM{ax|in}32 SkTM{in|ax}, SkTClamp, SkFastMin32, SkTPin.
>
> Change-Id: Ibcc07be0fc3677731048e7cc86006e7aa493cb92
> Reviewed-on: https://skia-review.googlesource.com/133381
> Auto-Submit: Hal Canary <halcanary@google.com>
> Reviewed-by: Ben Wagner <bungeman@google.com>
> Commit-Queue: Hal Canary <halcanary@google.com>
TBR=mtklein@google.com,halcanary@google.com,bungeman@google.com,reed@google.com
Change-Id: I44073cf397e2a3a6a941a90f0aa63c6396d4c742
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://skia-review.googlesource.com/152587
Reviewed-by: Mike Klein <mtklein@google.com>
Commit-Queue: Mike Klein <mtklein@google.com>
35 lines
907 B
C
35 lines
907 B
C
/*
|
|
* Copyright 2018 Google Inc.
|
|
*
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
* found in the LICENSE file.
|
|
*/
|
|
|
|
#ifndef SkSafe32_DEFINED
|
|
#define SkSafe32_DEFINED
|
|
|
|
#include "SkTypes.h"
|
|
|
|
static constexpr int32_t Sk64_pin_to_s32(int64_t x) {
|
|
return x < SK_MinS32 ? SK_MinS32 : (x > SK_MaxS32 ? SK_MaxS32 : (int32_t)x);
|
|
}
|
|
|
|
static constexpr int32_t Sk32_sat_add(int32_t a, int32_t b) {
|
|
return Sk64_pin_to_s32((int64_t)a + (int64_t)b);
|
|
}
|
|
|
|
static constexpr int32_t Sk32_sat_sub(int32_t a, int32_t b) {
|
|
return Sk64_pin_to_s32((int64_t)a - (int64_t)b);
|
|
}
|
|
|
|
// To avoid UBSAN complaints about 2's compliment overflows
|
|
//
|
|
static constexpr int32_t Sk32_can_overflow_add(int32_t a, int32_t b) {
|
|
return (int32_t)((uint32_t)a + (uint32_t)b);
|
|
}
|
|
static constexpr int32_t Sk32_can_overflow_sub(int32_t a, int32_t b) {
|
|
return (int32_t)((uint32_t)a - (uint32_t)b);
|
|
}
|
|
|
|
#endif
|