v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
safe_conversions_arm_impl.h
Go to the documentation of this file.
1// Copyright 2017 The Chromium Authors
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5// Slightly adapted for inclusion in V8.
6// Copyright 2025 the V8 project authors. All rights reserved.
7
8#ifndef V8_BASE_NUMERICS_SAFE_CONVERSIONS_ARM_IMPL_H_
9#define V8_BASE_NUMERICS_SAFE_CONVERSIONS_ARM_IMPL_H_
10
11// IWYU pragma: private, include "src/base/numerics/safe_conversions.h"
12
13#include <stdint.h>
14
15#include <algorithm>
16#include <concepts>
17#include <type_traits>
18
20
21namespace v8::base {
22namespace internal {
23
24// Fast saturation to a destination type.
25template <typename Dst, typename Src>
27 static constexpr bool is_supported =
28 kEnableAsmCode && std::signed_integral<Src> && std::integral<Dst> &&
31 !kIsTypeInRangeForNumericType<Dst, Src>;
32
33 __attribute__((always_inline)) static Dst Do(Src value) {
34 int32_t src = value;
35 if constexpr (std::is_signed_v<Dst>) {
36 int32_t result;
37 asm("ssat %[dst], %[shift], %[src]"
38 : [dst] "=r"(result)
39 : [src] "r"(src), [shift] "n"(
40 std::min(kIntegerBitsPlusSign<Dst>, 32)));
41 return static_cast<Dst>(result);
42 } else {
43 uint32_t result;
44 asm("usat %[dst], %[shift], %[src]"
45 : [dst] "=r"(result)
46 : [src] "r"(src), [shift] "n"(
47 std::min(kIntegerBitsPlusSign<Dst>, 31)));
48 return static_cast<Dst>(result);
49 }
50 }
51};
52
53} // namespace internal
54} // namespace v8::base
55
56#endif // V8_BASE_NUMERICS_SAFE_CONVERSIONS_ARM_IMPL_H_
ZoneVector< RpoNumber > & result
constexpr bool kEnableAsmCode
constexpr int kIntegerBitsPlusSign
__attribute__((always_inline)) static Dst Do(Src value)
std::unique_ptr< ValueMirror > value