Gentoo Archives: gentoo-commits

From: Mike Gilbert <floppym@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] repo/gentoo:master commit in: dev-util/gn/files/, dev-util/gn/
Date: Mon, 10 Dec 2018 15:31:21
Message-Id: 1544455865.c007723d59cc377de003e291c4614d36c4e51a41.floppym@gentoo
1 commit: c007723d59cc377de003e291c4614d36c4e51a41
2 Author: Mike Gilbert <floppym <AT> gentoo <DOT> org>
3 AuthorDate: Mon Dec 10 15:31:05 2018 +0000
4 Commit: Mike Gilbert <floppym <AT> gentoo <DOT> org>
5 CommitDate: Mon Dec 10 15:31:05 2018 +0000
6 URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=c007723d
7
8 dev-util/gn: restore missing headers to fix ARM build
9
10 Bug: https://bugs.gentoo.org/672862
11 Package-Manager: Portage-2.3.52_p8, Repoman-2.3.12_p20
12 Signed-off-by: Mike Gilbert <floppym <AT> gentoo.org>
13
14 dev-util/gn/files/gn-numerics-arm.patch | 201 ++++++++++++++++++++++++++++++++
15 dev-util/gn/gn-0.1479.ebuild | 1 +
16 2 files changed, 202 insertions(+)
17
18 diff --git a/dev-util/gn/files/gn-numerics-arm.patch b/dev-util/gn/files/gn-numerics-arm.patch
19 new file mode 100644
20 index 00000000000..f822cdb4085
21 --- /dev/null
22 +++ b/dev-util/gn/files/gn-numerics-arm.patch
23 @@ -0,0 +1,201 @@
24 +From 8952cb06749d4bd390991878281bc7e72a6eef2c Mon Sep 17 00:00:00 2001
25 +From: Mike Gilbert <floppymaster@×××××.com>
26 +Date: Mon, 10 Dec 2018 10:27:20 -0500
27 +Subject: [PATCH] Add missing headers for ARM
28 +
29 +Bug: https://bugs.gentoo.org/672862
30 +---
31 + base/numerics/safe_conversions_arm_impl.h | 51 +++++++++
32 + base/numerics/safe_math_arm_impl.h | 122 ++++++++++++++++++++++
33 + 2 files changed, 173 insertions(+)
34 + create mode 100644 base/numerics/safe_conversions_arm_impl.h
35 + create mode 100644 base/numerics/safe_math_arm_impl.h
36 +
37 +diff --git a/base/numerics/safe_conversions_arm_impl.h b/base/numerics/safe_conversions_arm_impl.h
38 +new file mode 100644
39 +index 00000000..da5813f6
40 +--- /dev/null
41 ++++ b/base/numerics/safe_conversions_arm_impl.h
42 +@@ -0,0 +1,51 @@
43 ++// Copyright 2017 The Chromium Authors. All rights reserved.
44 ++// Use of this source code is governed by a BSD-style license that can be
45 ++// found in the LICENSE file.
46 ++
47 ++#ifndef BASE_NUMERICS_SAFE_CONVERSIONS_ARM_IMPL_H_
48 ++#define BASE_NUMERICS_SAFE_CONVERSIONS_ARM_IMPL_H_
49 ++
50 ++#include <cassert>
51 ++#include <limits>
52 ++#include <type_traits>
53 ++
54 ++#include "base/numerics/safe_conversions_impl.h"
55 ++
56 ++namespace base {
57 ++namespace internal {
58 ++
59 ++// Fast saturation to a destination type.
60 ++template <typename Dst, typename Src>
61 ++struct SaturateFastAsmOp {
62 ++ static const bool is_supported =
63 ++ std::is_signed<Src>::value && std::is_integral<Dst>::value &&
64 ++ std::is_integral<Src>::value &&
65 ++ IntegerBitsPlusSign<Src>::value <= IntegerBitsPlusSign<int32_t>::value &&
66 ++ IntegerBitsPlusSign<Dst>::value <= IntegerBitsPlusSign<int32_t>::value &&
67 ++ !IsTypeInRangeForNumericType<Dst, Src>::value;
68 ++
69 ++ __attribute__((always_inline)) static Dst Do(Src value) {
70 ++ int32_t src = value;
71 ++ typename std::conditional<std::is_signed<Dst>::value, int32_t,
72 ++ uint32_t>::type result;
73 ++ if (std::is_signed<Dst>::value) {
74 ++ asm("ssat %[dst], %[shift], %[src]"
75 ++ : [dst] "=r"(result)
76 ++ : [src] "r"(src), [shift] "n"(IntegerBitsPlusSign<Dst>::value <= 32
77 ++ ? IntegerBitsPlusSign<Dst>::value
78 ++ : 32));
79 ++ } else {
80 ++ asm("usat %[dst], %[shift], %[src]"
81 ++ : [dst] "=r"(result)
82 ++ : [src] "r"(src), [shift] "n"(IntegerBitsPlusSign<Dst>::value < 32
83 ++ ? IntegerBitsPlusSign<Dst>::value
84 ++ : 31));
85 ++ }
86 ++ return static_cast<Dst>(result);
87 ++ }
88 ++};
89 ++
90 ++} // namespace internal
91 ++} // namespace base
92 ++
93 ++#endif // BASE_NUMERICS_SAFE_CONVERSIONS_ARM_IMPL_H_
94 +diff --git a/base/numerics/safe_math_arm_impl.h b/base/numerics/safe_math_arm_impl.h
95 +new file mode 100644
96 +index 00000000..a7cda1bb
97 +--- /dev/null
98 ++++ b/base/numerics/safe_math_arm_impl.h
99 +@@ -0,0 +1,122 @@
100 ++// Copyright 2017 The Chromium Authors. All rights reserved.
101 ++// Use of this source code is governed by a BSD-style license that can be
102 ++// found in the LICENSE file.
103 ++
104 ++#ifndef BASE_NUMERICS_SAFE_MATH_ARM_IMPL_H_
105 ++#define BASE_NUMERICS_SAFE_MATH_ARM_IMPL_H_
106 ++
107 ++#include <cassert>
108 ++#include <limits>
109 ++#include <type_traits>
110 ++
111 ++#include "base/numerics/safe_conversions.h"
112 ++
113 ++namespace base {
114 ++namespace internal {
115 ++
116 ++template <typename T, typename U>
117 ++struct CheckedMulFastAsmOp {
118 ++ static const bool is_supported =
119 ++ FastIntegerArithmeticPromotion<T, U>::is_contained;
120 ++
121 ++ // The following is much more efficient than the Clang and GCC builtins for
122 ++ // performing overflow-checked multiplication when a twice wider type is
123 ++ // available. The below compiles down to 2-3 instructions, depending on the
124 ++ // width of the types in use.
125 ++ // As an example, an int32_t multiply compiles to:
126 ++ // smull r0, r1, r0, r1
127 ++ // cmp r1, r1, asr #31
128 ++ // And an int16_t multiply compiles to:
129 ++ // smulbb r1, r1, r0
130 ++ // asr r2, r1, #16
131 ++ // cmp r2, r1, asr #15
132 ++ template <typename V>
133 ++ __attribute__((always_inline)) static bool Do(T x, U y, V* result) {
134 ++ using Promotion = typename FastIntegerArithmeticPromotion<T, U>::type;
135 ++ Promotion presult;
136 ++
137 ++ presult = static_cast<Promotion>(x) * static_cast<Promotion>(y);
138 ++ *result = static_cast<V>(presult);
139 ++ return IsValueInRangeForNumericType<V>(presult);
140 ++ }
141 ++};
142 ++
143 ++template <typename T, typename U>
144 ++struct ClampedAddFastAsmOp {
145 ++ static const bool is_supported =
146 ++ BigEnoughPromotion<T, U>::is_contained &&
147 ++ IsTypeInRangeForNumericType<
148 ++ int32_t,
149 ++ typename BigEnoughPromotion<T, U>::type>::value;
150 ++
151 ++ template <typename V>
152 ++ __attribute__((always_inline)) static V Do(T x, U y) {
153 ++ // This will get promoted to an int, so let the compiler do whatever is
154 ++ // clever and rely on the saturated cast to bounds check.
155 ++ if (IsIntegerArithmeticSafe<int, T, U>::value)
156 ++ return saturated_cast<V>(x + y);
157 ++
158 ++ int32_t result;
159 ++ int32_t x_i32 = x;
160 ++ int32_t y_i32 = y;
161 ++
162 ++ asm("qadd %[result], %[first], %[second]"
163 ++ : [result] "=r"(result)
164 ++ : [first] "r"(x_i32), [second] "r"(y_i32));
165 ++ return saturated_cast<V>(result);
166 ++ }
167 ++};
168 ++
169 ++template <typename T, typename U>
170 ++struct ClampedSubFastAsmOp {
171 ++ static const bool is_supported =
172 ++ BigEnoughPromotion<T, U>::is_contained &&
173 ++ IsTypeInRangeForNumericType<
174 ++ int32_t,
175 ++ typename BigEnoughPromotion<T, U>::type>::value;
176 ++
177 ++ template <typename V>
178 ++ __attribute__((always_inline)) static V Do(T x, U y) {
179 ++ // This will get promoted to an int, so let the compiler do whatever is
180 ++ // clever and rely on the saturated cast to bounds check.
181 ++ if (IsIntegerArithmeticSafe<int, T, U>::value)
182 ++ return saturated_cast<V>(x - y);
183 ++
184 ++ int32_t result;
185 ++ int32_t x_i32 = x;
186 ++ int32_t y_i32 = y;
187 ++
188 ++ asm("qsub %[result], %[first], %[second]"
189 ++ : [result] "=r"(result)
190 ++ : [first] "r"(x_i32), [second] "r"(y_i32));
191 ++ return saturated_cast<V>(result);
192 ++ }
193 ++};
194 ++
195 ++template <typename T, typename U>
196 ++struct ClampedMulFastAsmOp {
197 ++ static const bool is_supported = CheckedMulFastAsmOp<T, U>::is_supported;
198 ++
199 ++ template <typename V>
200 ++ __attribute__((always_inline)) static V Do(T x, U y) {
201 ++ // Use the CheckedMulFastAsmOp for full-width 32-bit values, because
202 ++ // it's fewer instructions than promoting and then saturating.
203 ++ if (!IsIntegerArithmeticSafe<int32_t, T, U>::value &&
204 ++ !IsIntegerArithmeticSafe<uint32_t, T, U>::value) {
205 ++ V result;
206 ++ if (CheckedMulFastAsmOp<T, U>::Do(x, y, &result))
207 ++ return result;
208 ++ return CommonMaxOrMin<V>(IsValueNegative(x) ^ IsValueNegative(y));
209 ++ }
210 ++
211 ++ assert((FastIntegerArithmeticPromotion<T, U>::is_contained));
212 ++ using Promotion = typename FastIntegerArithmeticPromotion<T, U>::type;
213 ++ return saturated_cast<V>(static_cast<Promotion>(x) *
214 ++ static_cast<Promotion>(y));
215 ++ }
216 ++};
217 ++
218 ++} // namespace internal
219 ++} // namespace base
220 ++
221 ++#endif // BASE_NUMERICS_SAFE_MATH_ARM_IMPL_H_
222 +--
223 +2.20.0.rc2
224 +
225
226 diff --git a/dev-util/gn/gn-0.1479.ebuild b/dev-util/gn/gn-0.1479.ebuild
227 index fc369d2c0db..89fd565c959 100644
228 --- a/dev-util/gn/gn-0.1479.ebuild
229 +++ b/dev-util/gn/gn-0.1479.ebuild
230 @@ -22,6 +22,7 @@ BDEPEND="
231
232 PATCHES=(
233 "${FILESDIR}"/gn-gen-r2.patch
234 + "${FILESDIR}"/gn-numerics-arm.patch
235 )
236
237 pkg_setup() {