Flutter Engine
The Flutter Engine
safe_conversions_arm_impl.h
Go to the documentation of this file.
1// Copyright 2017 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef BASE_NUMERICS_SAFE_CONVERSIONS_ARM_IMPL_H_
6#define BASE_NUMERICS_SAFE_CONVERSIONS_ARM_IMPL_H_
7
8#include <cassert>
9#include <limits>
10#include <type_traits>
11
13
14namespace base {
15namespace internal {
16
17// Fast saturation to a destination type.
18template <typename Dst, typename Src>
19struct SaturateFastAsmOp {
20 static constexpr bool is_supported =
26
27 __attribute__((always_inline)) static Dst Do(Src value) {
28 int32_t src = value;
30 uint32_t>::type result;
32 asm("ssat %[dst], %[shift], %[src]"
33 : [dst] "=r"(result)
34 : [src] "r"(src), [shift] "n"(IntegerBitsPlusSign<Dst>::value <= 32
36 : 32));
37 } else {
38 asm("usat %[dst], %[shift], %[src]"
39 : [dst] "=r"(result)
40 : [src] "r"(src), [shift] "n"(IntegerBitsPlusSign<Dst>::value < 32
42 : 31));
43 }
44 return static_cast<Dst>(result);
45 }
46};
47
48} // namespace internal
49} // namespace base
50
51#endif // BASE_NUMERICS_SAFE_CONVERSIONS_ARM_IMPL_H_
GLenum type
uint8_t value
GAsyncResult * result
dst
Definition: cp.py:12
static constexpr Dst Do(Src)
__attribute__((always_inline)) static Dst Do(Src value)
static constexpr bool is_supported