LLVM  17.0.0git
MathExtras.h
Go to the documentation of this file.
1 //===-- llvm/Support/MathExtras.h - Useful math functions -------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file contains some functions that are useful for math stuff.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef LLVM_SUPPORT_MATHEXTRAS_H
14 #define LLVM_SUPPORT_MATHEXTRAS_H
15 
16 #include "llvm/ADT/bit.h"
17 #include "llvm/Support/Compiler.h"
18 #include <cassert>
19 #include <climits>
20 #include <cstdint>
21 #include <cstring>
22 #include <limits>
23 #include <type_traits>
24 
25 namespace llvm {
26 
27 /// Mathematical constants.
28 namespace numbers {
29 // TODO: Track C++20 std::numbers.
30 // TODO: Favor using the hexadecimal FP constants (requires C++17).
31 constexpr double e = 2.7182818284590452354, // (0x1.5bf0a8b145749P+1) https://oeis.org/A001113
32  egamma = .57721566490153286061, // (0x1.2788cfc6fb619P-1) https://oeis.org/A001620
33  ln2 = .69314718055994530942, // (0x1.62e42fefa39efP-1) https://oeis.org/A002162
34  ln10 = 2.3025850929940456840, // (0x1.24bb1bbb55516P+1) https://oeis.org/A002392
35  log2e = 1.4426950408889634074, // (0x1.71547652b82feP+0)
36  log10e = .43429448190325182765, // (0x1.bcb7b1526e50eP-2)
37  pi = 3.1415926535897932385, // (0x1.921fb54442d18P+1) https://oeis.org/A000796
38  inv_pi = .31830988618379067154, // (0x1.45f306bc9c883P-2) https://oeis.org/A049541
39  sqrtpi = 1.7724538509055160273, // (0x1.c5bf891b4ef6bP+0) https://oeis.org/A002161
40  inv_sqrtpi = .56418958354775628695, // (0x1.20dd750429b6dP-1) https://oeis.org/A087197
41  sqrt2 = 1.4142135623730950488, // (0x1.6a09e667f3bcdP+0) https://oeis.org/A00219
42  inv_sqrt2 = .70710678118654752440, // (0x1.6a09e667f3bcdP-1)
43  sqrt3 = 1.7320508075688772935, // (0x1.bb67ae8584caaP+0) https://oeis.org/A002194
44  inv_sqrt3 = .57735026918962576451, // (0x1.279a74590331cP-1)
45  phi = 1.6180339887498948482; // (0x1.9e3779b97f4a8P+0) https://oeis.org/A001622
46 constexpr float ef = 2.71828183F, // (0x1.5bf0a8P+1) https://oeis.org/A001113
47  egammaf = .577215665F, // (0x1.2788d0P-1) https://oeis.org/A001620
48  ln2f = .693147181F, // (0x1.62e430P-1) https://oeis.org/A002162
49  ln10f = 2.30258509F, // (0x1.26bb1cP+1) https://oeis.org/A002392
50  log2ef = 1.44269504F, // (0x1.715476P+0)
51  log10ef = .434294482F, // (0x1.bcb7b2P-2)
52  pif = 3.14159265F, // (0x1.921fb6P+1) https://oeis.org/A000796
53  inv_pif = .318309886F, // (0x1.45f306P-2) https://oeis.org/A049541
54  sqrtpif = 1.77245385F, // (0x1.c5bf8aP+0) https://oeis.org/A002161
55  inv_sqrtpif = .564189584F, // (0x1.20dd76P-1) https://oeis.org/A087197
56  sqrt2f = 1.41421356F, // (0x1.6a09e6P+0) https://oeis.org/A002193
57  inv_sqrt2f = .707106781F, // (0x1.6a09e6P-1)
58  sqrt3f = 1.73205081F, // (0x1.bb67aeP+0) https://oeis.org/A002194
59  inv_sqrt3f = .577350269F, // (0x1.279a74P-1)
60  phif = 1.61803399F; // (0x1.9e377aP+0) https://oeis.org/A001622
61 } // namespace numbers
62 
63 /// Count number of 0's from the least significant bit to the most
64 /// stopping at the first 1.
65 ///
66 /// Only unsigned integral types are allowed.
67 ///
68 /// Returns std::numeric_limits<T>::digits on an input of 0.
69 template <typename T> unsigned countTrailingZeros(T Val) {
70  static_assert(std::is_unsigned_v<T>,
71  "Only unsigned integral types are allowed.");
72  return llvm::countr_zero(Val);
73 }
74 
75 /// Count number of 0's from the most significant bit to the least
76 /// stopping at the first 1.
77 ///
78 /// Only unsigned integral types are allowed.
79 ///
80 /// Returns std::numeric_limits<T>::digits on an input of 0.
81 template <typename T> unsigned countLeadingZeros(T Val) {
82  static_assert(std::is_unsigned_v<T>,
83  "Only unsigned integral types are allowed.");
84  return llvm::countl_zero(Val);
85 }
86 
87 /// Create a bitmask with the N right-most bits set to 1, and all other
88 /// bits set to 0. Only unsigned types are allowed.
89 template <typename T> T maskTrailingOnes(unsigned N) {
90  static_assert(std::is_unsigned<T>::value, "Invalid type!");
91  const unsigned Bits = CHAR_BIT * sizeof(T);
92  assert(N <= Bits && "Invalid bit index");
93  return N == 0 ? 0 : (T(-1) >> (Bits - N));
94 }
95 
96 /// Create a bitmask with the N left-most bits set to 1, and all other
97 /// bits set to 0. Only unsigned types are allowed.
98 template <typename T> T maskLeadingOnes(unsigned N) {
99  return ~maskTrailingOnes<T>(CHAR_BIT * sizeof(T) - N);
100 }
101 
102 /// Create a bitmask with the N right-most bits set to 0, and all other
103 /// bits set to 1. Only unsigned types are allowed.
104 template <typename T> T maskTrailingZeros(unsigned N) {
105  return maskLeadingOnes<T>(CHAR_BIT * sizeof(T) - N);
106 }
107 
108 /// Create a bitmask with the N left-most bits set to 0, and all other
109 /// bits set to 1. Only unsigned types are allowed.
110 template <typename T> T maskLeadingZeros(unsigned N) {
111  return maskTrailingOnes<T>(CHAR_BIT * sizeof(T) - N);
112 }
113 
114 /// Macro compressed bit reversal table for 256 bits.
115 ///
116 /// http://graphics.stanford.edu/~seander/bithacks.html#BitReverseTable
117 static const unsigned char BitReverseTable256[256] = {
118 #define R2(n) n, n + 2 * 64, n + 1 * 64, n + 3 * 64
119 #define R4(n) R2(n), R2(n + 2 * 16), R2(n + 1 * 16), R2(n + 3 * 16)
120 #define R6(n) R4(n), R4(n + 2 * 4), R4(n + 1 * 4), R4(n + 3 * 4)
121  R6(0), R6(2), R6(1), R6(3)
122 #undef R2
123 #undef R4
124 #undef R6
125 };
126 
127 /// Reverse the bits in \p Val.
128 template <typename T> T reverseBits(T Val) {
129 #if __has_builtin(__builtin_bitreverse8)
130  if constexpr (std::is_same_v<T, uint8_t>)
131  return __builtin_bitreverse8(Val);
132 #endif
133 #if __has_builtin(__builtin_bitreverse16)
134  if constexpr (std::is_same_v<T, uint16_t>)
135  return __builtin_bitreverse16(Val);
136 #endif
137 #if __has_builtin(__builtin_bitreverse32)
138  if constexpr (std::is_same_v<T, uint32_t>)
139  return __builtin_bitreverse32(Val);
140 #endif
141 #if __has_builtin(__builtin_bitreverse64)
142  if constexpr (std::is_same_v<T, uint64_t>)
143  return __builtin_bitreverse64(Val);
144 #endif
145 
146  unsigned char in[sizeof(Val)];
147  unsigned char out[sizeof(Val)];
148  std::memcpy(in, &Val, sizeof(Val));
149  for (unsigned i = 0; i < sizeof(Val); ++i)
150  out[(sizeof(Val) - i) - 1] = BitReverseTable256[in[i]];
151  std::memcpy(&Val, out, sizeof(Val));
152  return Val;
153 }
154 
155 // NOTE: The following support functions use the _32/_64 extensions instead of
156 // type overloading so that signed and unsigned integers can be used without
157 // ambiguity.
158 
159 /// Return the high 32 bits of a 64 bit value.
160 constexpr inline uint32_t Hi_32(uint64_t Value) {
161  return static_cast<uint32_t>(Value >> 32);
162 }
163 
164 /// Return the low 32 bits of a 64 bit value.
165 constexpr inline uint32_t Lo_32(uint64_t Value) {
166  return static_cast<uint32_t>(Value);
167 }
168 
169 /// Make a 64-bit integer from a high / low pair of 32-bit integers.
170 constexpr inline uint64_t Make_64(uint32_t High, uint32_t Low) {
171  return ((uint64_t)High << 32) | (uint64_t)Low;
172 }
173 
174 /// Checks if an integer fits into the given bit width.
175 template <unsigned N> constexpr inline bool isInt(int64_t x) {
176  if constexpr (N == 8)
177  return static_cast<int8_t>(x) == x;
178  if constexpr (N == 16)
179  return static_cast<int16_t>(x) == x;
180  if constexpr (N == 32)
181  return static_cast<int32_t>(x) == x;
182  if constexpr (N < 64)
183  return -(INT64_C(1) << (N - 1)) <= x && x < (INT64_C(1) << (N - 1));
184  (void)x; // MSVC v19.25 warns that x is unused.
185  return true;
186 }
187 
188 /// Checks if a signed integer is an N bit number shifted left by S.
189 template <unsigned N, unsigned S>
190 constexpr inline bool isShiftedInt(int64_t x) {
191  static_assert(
192  N > 0, "isShiftedInt<0> doesn't make sense (refers to a 0-bit number.");
193  static_assert(N + S <= 64, "isShiftedInt<N, S> with N + S > 64 is too wide.");
194  return isInt<N + S>(x) && (x % (UINT64_C(1) << S) == 0);
195 }
196 
197 /// Checks if an unsigned integer fits into the given bit width.
198 template <unsigned N> constexpr inline bool isUInt(uint64_t x) {
199  static_assert(N > 0, "isUInt<0> doesn't make sense");
200  if constexpr (N == 8)
201  return static_cast<uint8_t>(x) == x;
202  if constexpr (N == 16)
203  return static_cast<uint16_t>(x) == x;
204  if constexpr (N == 32)
205  return static_cast<uint32_t>(x) == x;
206  if constexpr (N < 64)
207  return x < (UINT64_C(1) << (N));
208  (void)x; // MSVC v19.25 warns that x is unused.
209  return true;
210 }
211 
212 /// Checks if a unsigned integer is an N bit number shifted left by S.
213 template <unsigned N, unsigned S>
214 constexpr inline bool isShiftedUInt(uint64_t x) {
215  static_assert(
216  N > 0, "isShiftedUInt<0> doesn't make sense (refers to a 0-bit number)");
217  static_assert(N + S <= 64,
218  "isShiftedUInt<N, S> with N + S > 64 is too wide.");
219  // Per the two static_asserts above, S must be strictly less than 64. So
220  // 1 << S is not undefined behavior.
221  return isUInt<N + S>(x) && (x % (UINT64_C(1) << S) == 0);
222 }
223 
224 /// Gets the maximum value for a N-bit unsigned integer.
226  assert(N > 0 && N <= 64 && "integer width out of range");
227 
228  // uint64_t(1) << 64 is undefined behavior, so we can't do
229  // (uint64_t(1) << N) - 1
230  // without checking first that N != 64. But this works and doesn't have a
231  // branch.
232  return UINT64_MAX >> (64 - N);
233 }
234 
235 /// Gets the minimum value for a N-bit signed integer.
236 inline int64_t minIntN(int64_t N) {
237  assert(N > 0 && N <= 64 && "integer width out of range");
238 
239  return UINT64_C(1) + ~(UINT64_C(1) << (N - 1));
240 }
241 
242 /// Gets the maximum value for a N-bit signed integer.
243 inline int64_t maxIntN(int64_t N) {
244  assert(N > 0 && N <= 64 && "integer width out of range");
245 
246  // This relies on two's complement wraparound when N == 64, so we convert to
247  // int64_t only at the very end to avoid UB.
248  return (UINT64_C(1) << (N - 1)) - 1;
249 }
250 
251 /// Checks if an unsigned integer fits into the given (dynamic) bit width.
252 inline bool isUIntN(unsigned N, uint64_t x) {
253  return N >= 64 || x <= maxUIntN(N);
254 }
255 
256 /// Checks if an signed integer fits into the given (dynamic) bit width.
257 inline bool isIntN(unsigned N, int64_t x) {
258  return N >= 64 || (minIntN(N) <= x && x <= maxIntN(N));
259 }
260 
261 /// Return true if the argument is a non-empty sequence of ones starting at the
262 /// least significant bit with the remainder zero (32 bit version).
263 /// Ex. isMask_32(0x0000FFFFU) == true.
264 constexpr inline bool isMask_32(uint32_t Value) {
265  return Value && ((Value + 1) & Value) == 0;
266 }
267 
268 /// Return true if the argument is a non-empty sequence of ones starting at the
269 /// least significant bit with the remainder zero (64 bit version).
270 constexpr inline bool isMask_64(uint64_t Value) {
271  return Value && ((Value + 1) & Value) == 0;
272 }
273 
274 /// Return true if the argument contains a non-empty sequence of ones with the
275 /// remainder zero (32 bit version.) Ex. isShiftedMask_32(0x0000FF00U) == true.
276 constexpr inline bool isShiftedMask_32(uint32_t Value) {
277  return Value && isMask_32((Value - 1) | Value);
278 }
279 
280 /// Return true if the argument contains a non-empty sequence of ones with the
281 /// remainder zero (64 bit version.)
282 constexpr inline bool isShiftedMask_64(uint64_t Value) {
283  return Value && isMask_64((Value - 1) | Value);
284 }
285 
286 /// Return true if the argument is a power of two > 0.
287 /// Ex. isPowerOf2_32(0x00100000U) == true (32 bit edition.)
288 constexpr inline bool isPowerOf2_32(uint32_t Value) {
289  return llvm::has_single_bit(Value);
290 }
291 
292 /// Return true if the argument is a power of two > 0 (64 bit edition.)
293 constexpr inline bool isPowerOf2_64(uint64_t Value) {
294  return llvm::has_single_bit(Value);
295 }
296 
297 /// Count the number of ones from the most significant bit to the first
298 /// zero bit.
299 ///
300 /// Ex. countLeadingOnes(0xFF0FFF00) == 8.
301 /// Only unsigned integral types are allowed.
302 ///
303 /// Returns std::numeric_limits<T>::digits on an input of all ones.
304 template <typename T> unsigned countLeadingOnes(T Value) {
305  static_assert(std::is_unsigned_v<T>,
306  "Only unsigned integral types are allowed.");
307  return llvm::countl_one<T>(Value);
308 }
309 
310 /// Count the number of ones from the least significant bit to the first
311 /// zero bit.
312 ///
313 /// Ex. countTrailingOnes(0x00FF00FF) == 8.
314 /// Only unsigned integral types are allowed.
315 ///
316 /// Returns std::numeric_limits<T>::digits on an input of all ones.
317 template <typename T> unsigned countTrailingOnes(T Value) {
318  static_assert(std::is_unsigned_v<T>,
319  "Only unsigned integral types are allowed.");
320  return llvm::countr_one<T>(Value);
321 }
322 
323 /// Count the number of set bits in a value.
324 /// Ex. countPopulation(0xF000F000) = 8
325 /// Returns 0 if the word is zero.
326 template <typename T>
327 inline unsigned countPopulation(T Value) {
328  static_assert(std::is_unsigned_v<T>,
329  "Only unsigned integral types are allowed.");
330  return (unsigned)llvm::popcount(Value);
331 }
332 
333 /// Return true if the argument contains a non-empty sequence of ones with the
334 /// remainder zero (32 bit version.) Ex. isShiftedMask_32(0x0000FF00U) == true.
335 /// If true, \p MaskIdx will specify the index of the lowest set bit and \p
336 /// MaskLen is updated to specify the length of the mask, else neither are
337 /// updated.
338 inline bool isShiftedMask_32(uint32_t Value, unsigned &MaskIdx,
339  unsigned &MaskLen) {
340  if (!isShiftedMask_32(Value))
341  return false;
342  MaskIdx = llvm::countr_zero(Value);
343  MaskLen = llvm::popcount(Value);
344  return true;
345 }
346 
347 /// Return true if the argument contains a non-empty sequence of ones with the
348 /// remainder zero (64 bit version.) If true, \p MaskIdx will specify the index
349 /// of the lowest set bit and \p MaskLen is updated to specify the length of the
350 /// mask, else neither are updated.
351 inline bool isShiftedMask_64(uint64_t Value, unsigned &MaskIdx,
352  unsigned &MaskLen) {
353  if (!isShiftedMask_64(Value))
354  return false;
355  MaskIdx = llvm::countr_zero(Value);
356  MaskLen = llvm::popcount(Value);
357  return true;
358 }
359 
360 /// Compile time Log2.
361 /// Valid only for positive powers of two.
362 template <size_t kValue> constexpr inline size_t CTLog2() {
363  static_assert(kValue > 0 && llvm::isPowerOf2_64(kValue),
364  "Value is not a valid power of 2");
365  return 1 + CTLog2<kValue / 2>();
366 }
367 
368 template <> constexpr inline size_t CTLog2<1>() { return 0; }
369 
370 /// Return the floor log base 2 of the specified value, -1 if the value is zero.
371 /// (32 bit edition.)
372 /// Ex. Log2_32(32) == 5, Log2_32(1) == 0, Log2_32(0) == -1, Log2_32(6) == 2
373 inline unsigned Log2_32(uint32_t Value) {
374  return 31 - llvm::countl_zero(Value);
375 }
376 
377 /// Return the floor log base 2 of the specified value, -1 if the value is zero.
378 /// (64 bit edition.)
379 inline unsigned Log2_64(uint64_t Value) {
380  return 63 - llvm::countl_zero(Value);
381 }
382 
383 /// Return the ceil log base 2 of the specified value, 32 if the value is zero.
384 /// (32 bit edition).
385 /// Ex. Log2_32_Ceil(32) == 5, Log2_32_Ceil(1) == 0, Log2_32_Ceil(6) == 3
386 inline unsigned Log2_32_Ceil(uint32_t Value) {
387  return 32 - llvm::countl_zero(Value - 1);
388 }
389 
390 /// Return the ceil log base 2 of the specified value, 64 if the value is zero.
391 /// (64 bit edition.)
392 inline unsigned Log2_64_Ceil(uint64_t Value) {
393  return 64 - llvm::countl_zero(Value - 1);
394 }
395 
396 /// This function takes a 64-bit integer and returns the bit equivalent double.
397 inline double BitsToDouble(uint64_t Bits) {
398  static_assert(sizeof(uint64_t) == sizeof(double), "Unexpected type sizes");
399  return llvm::bit_cast<double>(Bits);
400 }
401 
402 /// This function takes a 32-bit integer and returns the bit equivalent float.
403 inline float BitsToFloat(uint32_t Bits) {
404  static_assert(sizeof(uint32_t) == sizeof(float), "Unexpected type sizes");
405  return llvm::bit_cast<float>(Bits);
406 }
407 
408 /// This function takes a double and returns the bit equivalent 64-bit integer.
409 /// Note that copying doubles around changes the bits of NaNs on some hosts,
410 /// notably x86, so this routine cannot be used if these bits are needed.
411 inline uint64_t DoubleToBits(double Double) {
412  static_assert(sizeof(uint64_t) == sizeof(double), "Unexpected type sizes");
413  return llvm::bit_cast<uint64_t>(Double);
414 }
415 
416 /// This function takes a float and returns the bit equivalent 32-bit integer.
417 /// Note that copying floats around changes the bits of NaNs on some hosts,
418 /// notably x86, so this routine cannot be used if these bits are needed.
419 inline uint32_t FloatToBits(float Float) {
420  static_assert(sizeof(uint32_t) == sizeof(float), "Unexpected type sizes");
421  return llvm::bit_cast<uint32_t>(Float);
422 }
423 
424 /// A and B are either alignments or offsets. Return the minimum alignment that
425 /// may be assumed after adding the two together.
426 constexpr inline uint64_t MinAlign(uint64_t A, uint64_t B) {
427  // The largest power of 2 that divides both A and B.
428  //
429  // Replace "-Value" by "1+~Value" in the following commented code to avoid
430  // MSVC warning C4146
431  // return (A | B) & -(A | B);
432  return (A | B) & (1 + ~(A | B));
433 }
434 
435 /// Returns the next power of two (in 64-bits) that is strictly greater than A.
436 /// Returns zero on overflow.
437 constexpr inline uint64_t NextPowerOf2(uint64_t A) {
438  A |= (A >> 1);
439  A |= (A >> 2);
440  A |= (A >> 4);
441  A |= (A >> 8);
442  A |= (A >> 16);
443  A |= (A >> 32);
444  return A + 1;
445 }
446 
447 /// Returns the power of two which is less than or equal to the given value.
448 /// Essentially, it is a floor operation across the domain of powers of two.
450  return llvm::bit_floor(A);
451 }
452 
453 /// Returns the power of two which is greater than or equal to the given value.
454 /// Essentially, it is a ceil operation across the domain of powers of two.
456  if (!A)
457  return 0;
458  return NextPowerOf2(A - 1);
459 }
460 
461 /// Returns the next integer (mod 2**64) that is greater than or equal to
462 /// \p Value and is a multiple of \p Align. \p Align must be non-zero.
463 ///
464 /// Examples:
465 /// \code
466 /// alignTo(5, 8) = 8
467 /// alignTo(17, 8) = 24
468 /// alignTo(~0LL, 8) = 0
469 /// alignTo(321, 255) = 510
470 /// \endcode
472  assert(Align != 0u && "Align can't be 0.");
473  return (Value + Align - 1) / Align * Align;
474 }
475 
477  assert(Align != 0 && (Align & (Align - 1)) == 0 &&
478  "Align must be a power of 2");
479  return (Value + Align - 1) & -Align;
480 }
481 
482 /// If non-zero \p Skew is specified, the return value will be a minimal integer
483 /// that is greater than or equal to \p Size and equal to \p A * N + \p Skew for
484 /// some integer N. If \p Skew is larger than \p A, its value is adjusted to '\p
485 /// Skew mod \p A'. \p Align must be non-zero.
486 ///
487 /// Examples:
488 /// \code
489 /// alignTo(5, 8, 7) = 7
490 /// alignTo(17, 8, 1) = 17
491 /// alignTo(~0LL, 8, 3) = 3
492 /// alignTo(321, 255, 42) = 552
493 /// \endcode
495  assert(Align != 0u && "Align can't be 0.");
496  Skew %= Align;
497  return alignTo(Value - Skew, Align) + Skew;
498 }
499 
500 /// Returns the next integer (mod 2**64) that is greater than or equal to
501 /// \p Value and is a multiple of \c Align. \c Align must be non-zero.
502 template <uint64_t Align> constexpr inline uint64_t alignTo(uint64_t Value) {
503  static_assert(Align != 0u, "Align must be non-zero");
504  return (Value + Align - 1) / Align * Align;
505 }
506 
507 /// Returns the integer ceil(Numerator / Denominator).
508 inline uint64_t divideCeil(uint64_t Numerator, uint64_t Denominator) {
509  return alignTo(Numerator, Denominator) / Denominator;
510 }
511 
512 /// Returns the integer nearest(Numerator / Denominator).
513 inline uint64_t divideNearest(uint64_t Numerator, uint64_t Denominator) {
514  return (Numerator + (Denominator / 2)) / Denominator;
515 }
516 
517 /// Returns the largest uint64_t less than or equal to \p Value and is
518 /// \p Skew mod \p Align. \p Align must be non-zero
520  assert(Align != 0u && "Align can't be 0.");
521  Skew %= Align;
522  return (Value - Skew) / Align * Align + Skew;
523 }
524 
525 /// Sign-extend the number in the bottom B bits of X to a 32-bit integer.
526 /// Requires 0 < B <= 32.
527 template <unsigned B> constexpr inline int32_t SignExtend32(uint32_t X) {
528  static_assert(B > 0, "Bit width can't be 0.");
529  static_assert(B <= 32, "Bit width out of range.");
530  return int32_t(X << (32 - B)) >> (32 - B);
531 }
532 
533 /// Sign-extend the number in the bottom B bits of X to a 32-bit integer.
534 /// Requires 0 < B <= 32.
535 inline int32_t SignExtend32(uint32_t X, unsigned B) {
536  assert(B > 0 && "Bit width can't be 0.");
537  assert(B <= 32 && "Bit width out of range.");
538  return int32_t(X << (32 - B)) >> (32 - B);
539 }
540 
541 /// Sign-extend the number in the bottom B bits of X to a 64-bit integer.
542 /// Requires 0 < B <= 64.
543 template <unsigned B> constexpr inline int64_t SignExtend64(uint64_t x) {
544  static_assert(B > 0, "Bit width can't be 0.");
545  static_assert(B <= 64, "Bit width out of range.");
546  return int64_t(x << (64 - B)) >> (64 - B);
547 }
548 
549 /// Sign-extend the number in the bottom B bits of X to a 64-bit integer.
550 /// Requires 0 < B <= 64.
551 inline int64_t SignExtend64(uint64_t X, unsigned B) {
552  assert(B > 0 && "Bit width can't be 0.");
553  assert(B <= 64 && "Bit width out of range.");
554  return int64_t(X << (64 - B)) >> (64 - B);
555 }
556 
557 /// Subtract two unsigned integers, X and Y, of type T and return the absolute
558 /// value of the result.
559 template <typename T>
560 std::enable_if_t<std::is_unsigned<T>::value, T> AbsoluteDifference(T X, T Y) {
561  return X > Y ? (X - Y) : (Y - X);
562 }
563 
564 /// Add two unsigned integers, X and Y, of type T. Clamp the result to the
565 /// maximum representable value of T on overflow. ResultOverflowed indicates if
566 /// the result is larger than the maximum representable value of type T.
567 template <typename T>
568 std::enable_if_t<std::is_unsigned<T>::value, T>
569 SaturatingAdd(T X, T Y, bool *ResultOverflowed = nullptr) {
570  bool Dummy;
571  bool &Overflowed = ResultOverflowed ? *ResultOverflowed : Dummy;
572  // Hacker's Delight, p. 29
573  T Z = X + Y;
574  Overflowed = (Z < X || Z < Y);
575  if (Overflowed)
577  else
578  return Z;
579 }
580 
581 /// Add multiple unsigned integers of type T. Clamp the result to the
582 /// maximum representable value of T on overflow.
583 template <class T, class... Ts>
584 std::enable_if_t<std::is_unsigned_v<T>, T> SaturatingAdd(T X, T Y, T Z,
585  Ts... Args) {
586  bool Overflowed = false;
587  T XY = SaturatingAdd(X, Y, &Overflowed);
588  if (Overflowed)
590  return SaturatingAdd(XY, Z, Args...);
591 }
592 
593 /// Multiply two unsigned integers, X and Y, of type T. Clamp the result to the
594 /// maximum representable value of T on overflow. ResultOverflowed indicates if
595 /// the result is larger than the maximum representable value of type T.
596 template <typename T>
597 std::enable_if_t<std::is_unsigned<T>::value, T>
598 SaturatingMultiply(T X, T Y, bool *ResultOverflowed = nullptr) {
599  bool Dummy;
600  bool &Overflowed = ResultOverflowed ? *ResultOverflowed : Dummy;
601 
602  // Hacker's Delight, p. 30 has a different algorithm, but we don't use that
603  // because it fails for uint16_t (where multiplication can have undefined
604  // behavior due to promotion to int), and requires a division in addition
605  // to the multiplication.
606 
607  Overflowed = false;
608 
609  // Log2(Z) would be either Log2Z or Log2Z + 1.
610  // Special case: if X or Y is 0, Log2_64 gives -1, and Log2Z
611  // will necessarily be less than Log2Max as desired.
612  int Log2Z = Log2_64(X) + Log2_64(Y);
613  const T Max = std::numeric_limits<T>::max();
614  int Log2Max = Log2_64(Max);
615  if (Log2Z < Log2Max) {
616  return X * Y;
617  }
618  if (Log2Z > Log2Max) {
619  Overflowed = true;
620  return Max;
621  }
622 
623  // We're going to use the top bit, and maybe overflow one
624  // bit past it. Multiply all but the bottom bit then add
625  // that on at the end.
626  T Z = (X >> 1) * Y;
627  if (Z & ~(Max >> 1)) {
628  Overflowed = true;
629  return Max;
630  }
631  Z <<= 1;
632  if (X & 1)
633  return SaturatingAdd(Z, Y, ResultOverflowed);
634 
635  return Z;
636 }
637 
638 /// Multiply two unsigned integers, X and Y, and add the unsigned integer, A to
639 /// the product. Clamp the result to the maximum representable value of T on
640 /// overflow. ResultOverflowed indicates if the result is larger than the
641 /// maximum representable value of type T.
642 template <typename T>
643 std::enable_if_t<std::is_unsigned<T>::value, T>
644 SaturatingMultiplyAdd(T X, T Y, T A, bool *ResultOverflowed = nullptr) {
645  bool Dummy;
646  bool &Overflowed = ResultOverflowed ? *ResultOverflowed : Dummy;
647 
648  T Product = SaturatingMultiply(X, Y, &Overflowed);
649  if (Overflowed)
650  return Product;
651 
652  return SaturatingAdd(A, Product, &Overflowed);
653 }
654 
655 /// Use this rather than HUGE_VALF; the latter causes warnings on MSVC.
656 extern const float huge_valf;
657 
658 
659 /// Add two signed integers, computing the two's complement truncated result,
660 /// returning true if overflow occurred.
661 template <typename T>
662 std::enable_if_t<std::is_signed<T>::value, T> AddOverflow(T X, T Y, T &Result) {
663 #if __has_builtin(__builtin_add_overflow)
664  return __builtin_add_overflow(X, Y, &Result);
665 #else
666  // Perform the unsigned addition.
667  using U = std::make_unsigned_t<T>;
668  const U UX = static_cast<U>(X);
669  const U UY = static_cast<U>(Y);
670  const U UResult = UX + UY;
671 
672  // Convert to signed.
673  Result = static_cast<T>(UResult);
674 
675  // Adding two positive numbers should result in a positive number.
676  if (X > 0 && Y > 0)
677  return Result <= 0;
678  // Adding two negatives should result in a negative number.
679  if (X < 0 && Y < 0)
680  return Result >= 0;
681  return false;
682 #endif
683 }
684 
685 /// Subtract two signed integers, computing the two's complement truncated
686 /// result, returning true if an overflow ocurred.
687 template <typename T>
688 std::enable_if_t<std::is_signed<T>::value, T> SubOverflow(T X, T Y, T &Result) {
689 #if __has_builtin(__builtin_sub_overflow)
690  return __builtin_sub_overflow(X, Y, &Result);
691 #else
692  // Perform the unsigned addition.
693  using U = std::make_unsigned_t<T>;
694  const U UX = static_cast<U>(X);
695  const U UY = static_cast<U>(Y);
696  const U UResult = UX - UY;
697 
698  // Convert to signed.
699  Result = static_cast<T>(UResult);
700 
701  // Subtracting a positive number from a negative results in a negative number.
702  if (X <= 0 && Y > 0)
703  return Result >= 0;
704  // Subtracting a negative number from a positive results in a positive number.
705  if (X >= 0 && Y < 0)
706  return Result <= 0;
707  return false;
708 #endif
709 }
710 
711 /// Multiply two signed integers, computing the two's complement truncated
712 /// result, returning true if an overflow ocurred.
713 template <typename T>
714 std::enable_if_t<std::is_signed<T>::value, T> MulOverflow(T X, T Y, T &Result) {
715  // Perform the unsigned multiplication on absolute values.
716  using U = std::make_unsigned_t<T>;
717  const U UX = X < 0 ? (0 - static_cast<U>(X)) : static_cast<U>(X);
718  const U UY = Y < 0 ? (0 - static_cast<U>(Y)) : static_cast<U>(Y);
719  const U UResult = UX * UY;
720 
721  // Convert to signed.
722  const bool IsNegative = (X < 0) ^ (Y < 0);
723  Result = IsNegative ? (0 - UResult) : UResult;
724 
725  // If any of the args was 0, result is 0 and no overflow occurs.
726  if (UX == 0 || UY == 0)
727  return false;
728 
729  // UX and UY are in [1, 2^n], where n is the number of digits.
730  // Check how the max allowed absolute value (2^n for negative, 2^(n-1) for
731  // positive) divided by an argument compares to the other.
732  if (IsNegative)
733  return UX > (static_cast<U>(std::numeric_limits<T>::max()) + U(1)) / UY;
734  else
735  return UX > (static_cast<U>(std::numeric_limits<T>::max())) / UY;
736 }
737 
738 } // End llvm namespace
739 
740 #endif
llvm::SaturatingMultiply
std::enable_if_t< std::is_unsigned< T >::value, T > SaturatingMultiply(T X, T Y, bool *ResultOverflowed=nullptr)
Multiply two unsigned integers, X and Y, of type T.
Definition: MathExtras.h:598
i
i
Definition: README.txt:29
llvm::alignTo
uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
Definition: Alignment.h:155
llvm::numbers::sqrt3f
constexpr float sqrt3f
Definition: MathExtras.h:58
llvm::CTLog2< 1 >
constexpr size_t CTLog2< 1 >()
Definition: MathExtras.h:368
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
llvm::SaturatingAdd
std::enable_if_t< std::is_unsigned< T >::value, T > SaturatingAdd(T X, T Y, bool *ResultOverflowed=nullptr)
Add two unsigned integers, X and Y, of type T.
Definition: MathExtras.h:569
llvm::maskTrailingOnes
T maskTrailingOnes(unsigned N)
Create a bitmask with the N right-most bits set to 1, and all other bits set to 0.
Definition: MathExtras.h:89
llvm::numbers::sqrt3
constexpr double sqrt3
Definition: MathExtras.h:43
llvm::maskTrailingZeros
T maskTrailingZeros(unsigned N)
Create a bitmask with the N right-most bits set to 0, and all other bits set to 1.
Definition: MathExtras.h:104
llvm::reverseBits
T reverseBits(T Val)
Reverse the bits in Val.
Definition: MathExtras.h:128
llvm::CTLog2
constexpr size_t CTLog2()
Compile time Log2.
Definition: MathExtras.h:362
High
uint64_t High
Definition: NVVMIntrRange.cpp:61
llvm::huge_valf
const float huge_valf
Use this rather than HUGE_VALF; the latter causes warnings on MSVC.
Definition: MathExtras.cpp:28
llvm::isShiftedMask_32
constexpr bool isShiftedMask_32(uint32_t Value)
Return true if the argument contains a non-empty sequence of ones with the remainder zero (32 bit ver...
Definition: MathExtras.h:276
llvm::has_single_bit
constexpr bool has_single_bit(T Value) noexcept
Definition: bit.h:110
llvm::tgtok::Bits
@ Bits
Definition: TGLexer.h:50
llvm::FloatToBits
uint32_t FloatToBits(float Float)
This function takes a float and returns the bit equivalent 32-bit integer.
Definition: MathExtras.h:419
llvm::maxIntN
int64_t maxIntN(int64_t N)
Gets the maximum value for a N-bit signed integer.
Definition: MathExtras.h:243
T
#define T
Definition: Mips16ISelLowering.cpp:341
llvm::numbers::log10e
constexpr double log10e
Definition: MathExtras.h:36
llvm::max
Expected< ExpressionValue > max(const ExpressionValue &Lhs, const ExpressionValue &Rhs)
Definition: FileCheck.cpp:337
llvm::PowerOf2Ceil
uint64_t PowerOf2Ceil(uint64_t A)
Returns the power of two which is greater than or equal to the given value.
Definition: MathExtras.h:455
llvm::isPowerOf2_32
constexpr bool isPowerOf2_32(uint32_t Value)
Return true if the argument is a power of two > 0.
Definition: MathExtras.h:288
llvm::isInt
constexpr bool isInt(int64_t x)
Checks if an integer fits into the given bit width.
Definition: MathExtras.h:175
llvm::Lo_32
constexpr uint32_t Lo_32(uint64_t Value)
Return the low 32 bits of a 64 bit value.
Definition: MathExtras.h:165
llvm::numbers::log10ef
constexpr float log10ef
Definition: MathExtras.h:51
llvm::MinAlign
constexpr uint64_t MinAlign(uint64_t A, uint64_t B)
A and B are either alignments or offsets.
Definition: MathExtras.h:426
llvm::numbers::egammaf
constexpr float egammaf
Definition: MathExtras.h:47
llvm::Log2_64
unsigned Log2_64(uint64_t Value)
Return the floor log base 2 of the specified value, -1 if the value is zero.
Definition: MathExtras.h:379
llvm::numbers::inv_sqrt2
constexpr double inv_sqrt2
Definition: MathExtras.h:42
llvm::PowerOf2Floor
uint64_t PowerOf2Floor(uint64_t A)
Returns the power of two which is less than or equal to the given value.
Definition: MathExtras.h:449
llvm::popcount
int popcount(T Value) noexcept
Count the number of set bits in a value.
Definition: bit.h:349
llvm::isShiftedMask_64
constexpr bool isShiftedMask_64(uint64_t Value)
Return true if the argument contains a non-empty sequence of ones with the remainder zero (64 bit ver...
Definition: MathExtras.h:282
Y
static GCMetadataPrinterRegistry::Add< OcamlGCMetadataPrinter > Y("ocaml", "ocaml 3.10-compatible collector")
llvm::DoubleToBits
uint64_t DoubleToBits(double Double)
This function takes a double and returns the bit equivalent 64-bit integer.
Definition: MathExtras.h:411
UINT64_MAX
#define UINT64_MAX
Definition: DataTypes.h:77
llvm::NextPowerOf2
constexpr uint64_t NextPowerOf2(uint64_t A)
Returns the next power of two (in 64-bits) that is strictly greater than A.
Definition: MathExtras.h:437
llvm::numbers::log2ef
constexpr float log2ef
Definition: MathExtras.h:50
llvm::alignDown
uint64_t alignDown(uint64_t Value, uint64_t Align, uint64_t Skew=0)
Returns the largest uint64_t less than or equal to Value and is Skew mod Align.
Definition: MathExtras.h:519
llvm::Log2_32
unsigned Log2_32(uint32_t Value)
Return the floor log base 2 of the specified value, -1 if the value is zero.
Definition: MathExtras.h:373
llvm::numbers::ln10f
constexpr float ln10f
Definition: MathExtras.h:49
B
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
llvm::isUIntN
bool isUIntN(unsigned N, uint64_t x)
Checks if an unsigned integer fits into the given (dynamic) bit width.
Definition: MathExtras.h:252
in
The object format emitted by the WebAssembly backed is documented in
Definition: README.txt:11
llvm::ThreadPriority::Low
@ Low
Lower the current thread's priority such that it does not affect foreground tasks significantly.
llvm::AddOverflow
std::enable_if_t< std::is_signed< T >::value, T > AddOverflow(T X, T Y, T &Result)
Add two signed integers, computing the two's complement truncated result, returning true if overflow ...
Definition: MathExtras.h:662
llvm::numbers::inv_sqrt3f
constexpr float inv_sqrt3f
Definition: MathExtras.h:59
llvm::numbers::sqrt2
constexpr double sqrt2
Definition: MathExtras.h:41
llvm::countTrailingZeros
unsigned countTrailingZeros(T Val)
Count number of 0's from the least significant bit to the most stopping at the first 1.
Definition: MathExtras.h:69
Align
uint64_t Align
Definition: ELFObjHandler.cpp:82
llvm::Align
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition: Alignment.h:39
llvm::numbers::inv_sqrt2f
constexpr float inv_sqrt2f
Definition: MathExtras.h:57
llvm::isIntN
bool isIntN(unsigned N, int64_t x)
Checks if an signed integer fits into the given (dynamic) bit width.
Definition: MathExtras.h:257
X
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
llvm::Log2_32_Ceil
unsigned Log2_32_Ceil(uint32_t Value)
Return the ceil log base 2 of the specified value, 32 if the value is zero.
Definition: MathExtras.h:386
llvm::Hi_32
constexpr uint32_t Hi_32(uint64_t Value)
Return the high 32 bits of a 64 bit value.
Definition: MathExtras.h:160
llvm::Make_64
constexpr uint64_t Make_64(uint32_t High, uint32_t Low)
Make a 64-bit integer from a high / low pair of 32-bit integers.
Definition: MathExtras.h:170
llvm::SignExtend32
constexpr int32_t SignExtend32(uint32_t X)
Sign-extend the number in the bottom B bits of X to a 32-bit integer.
Definition: MathExtras.h:527
llvm::divideCeil
uint64_t divideCeil(uint64_t Numerator, uint64_t Denominator)
Returns the integer ceil(Numerator / Denominator).
Definition: MathExtras.h:508
llvm::countPopulation
unsigned countPopulation(T Value)
Count the number of set bits in a value.
Definition: MathExtras.h:327
llvm::minIntN
int64_t minIntN(int64_t N)
Gets the minimum value for a N-bit signed integer.
Definition: MathExtras.h:236
uint64_t
llvm::alignToPowerOf2
uint64_t alignToPowerOf2(uint64_t Value, uint64_t Align)
Definition: MathExtras.h:476
llvm::numbers::egamma
constexpr double egamma
Definition: MathExtras.h:32
llvm::numbers::e
constexpr double e
Definition: MathExtras.h:31
llvm::numbers::inv_sqrt3
constexpr double inv_sqrt3
Definition: MathExtras.h:44
llvm::SaturatingMultiplyAdd
std::enable_if_t< std::is_unsigned< T >::value, T > SaturatingMultiplyAdd(T X, T Y, T A, bool *ResultOverflowed=nullptr)
Multiply two unsigned integers, X and Y, and add the unsigned integer, A to the product.
Definition: MathExtras.h:644
llvm::maskLeadingZeros
T maskLeadingZeros(unsigned N)
Create a bitmask with the N left-most bits set to 0, and all other bits set to 1.
Definition: MathExtras.h:110
llvm::numbers::log2e
constexpr double log2e
Definition: MathExtras.h:35
llvm::Log2_64_Ceil
unsigned Log2_64_Ceil(uint64_t Value)
Return the ceil log base 2 of the specified value, 64 if the value is zero.
Definition: MathExtras.h:392
numbers
SSE has instructions for doing operations on complex numbers
Definition: README-SSE.txt:22
llvm::isUInt
constexpr bool isUInt(uint64_t x)
Checks if an unsigned integer fits into the given bit width.
Definition: MathExtras.h:198
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::numbers::inv_pif
constexpr float inv_pif
Definition: MathExtras.h:53
memcpy
<%struct.s * > cast struct s *S to sbyte *< sbyte * > sbyte uint cast struct s *agg result to sbyte *< sbyte * > sbyte uint cast struct s *memtmp to sbyte *< sbyte * > sbyte uint ret void llc ends up issuing two memcpy or custom lower memcpy(of small size) to be ldmia/stmia. I think option 2 is better but the current register allocator cannot allocate a chunk of registers at a time. A feasible temporary solution is to use specific physical registers at the lowering time for small(<
llvm::isShiftedUInt
constexpr bool isShiftedUInt(uint64_t x)
Checks if a unsigned integer is an N bit number shifted left by S.
Definition: MathExtras.h:214
llvm::numbers::inv_sqrtpi
constexpr double inv_sqrtpi
Definition: MathExtras.h:40
R6
#define R6(n)
llvm::isMask_32
constexpr bool isMask_32(uint32_t Value)
Return true if the argument is a non-empty sequence of ones starting at the least significant bit wit...
Definition: MathExtras.h:264
llvm::NVPTXISD::Dummy
@ Dummy
Definition: NVPTXISelLowering.h:60
llvm::BitReverseTable256
static const unsigned char BitReverseTable256[256]
Macro compressed bit reversal table for 256 bits.
Definition: MathExtras.h:117
uint32_t
Compiler.h
S
add sub stmia L5 ldr r0 bl L_printf $stub Instead of a and a wouldn t it be better to do three moves *Return an aggregate type is even return S
Definition: README.txt:210
llvm::BitsToFloat
float BitsToFloat(uint32_t Bits)
This function takes a 32-bit integer and returns the bit equivalent float.
Definition: MathExtras.h:403
llvm::SignExtend64
constexpr int64_t SignExtend64(uint64_t x)
Sign-extend the number in the bottom B bits of X to a 64-bit integer.
Definition: MathExtras.h:543
llvm::numbers::inv_pi
constexpr double inv_pi
Definition: MathExtras.h:38
llvm::numbers::ef
constexpr float ef
Definition: MathExtras.h:46
llvm::countLeadingOnes
unsigned countLeadingOnes(T Value)
Count the number of ones from the most significant bit to the first zero bit.
Definition: MathExtras.h:304
uint16_t
llvm::numbers::inv_sqrtpif
constexpr float inv_sqrtpif
Definition: MathExtras.h:55
llvm::maskLeadingOnes
T maskLeadingOnes(unsigned N)
Create a bitmask with the N left-most bits set to 1, and all other bits set to 0.
Definition: MathExtras.h:98
llvm::countTrailingOnes
unsigned countTrailingOnes(T Value)
Count the number of ones from the least significant bit to the first zero bit.
Definition: MathExtras.h:317
bit.h
llvm::bit_floor
T bit_floor(T Value)
Returns the largest integral power of two no greater than Value if Value is nonzero.
Definition: bit.h:291
llvm::MulOverflow
std::enable_if_t< std::is_signed< T >::value, T > MulOverflow(T X, T Y, T &Result)
Multiply two signed integers, computing the two's complement truncated result, returning true if an o...
Definition: MathExtras.h:714
llvm::TargetStackID::Value
Value
Definition: TargetFrameLowering.h:27
llvm::isShiftedInt
constexpr bool isShiftedInt(int64_t x)
Checks if a signed integer is an N bit number shifted left by S.
Definition: MathExtras.h:190
x
TODO unsigned x
Definition: README.txt:10
llvm::numbers::phif
constexpr float phif
Definition: MathExtras.h:60
llvm::ARCCC::Z
@ Z
Definition: ARCInfo.h:41
llvm::countl_zero
int countl_zero(T Val)
Count number of 0's from the most significant bit to the least stopping at the first 1.
Definition: bit.h:245
llvm::SubOverflow
std::enable_if_t< std::is_signed< T >::value, T > SubOverflow(T X, T Y, T &Result)
Subtract two signed integers, computing the two's complement truncated result, returning true if an o...
Definition: MathExtras.h:688
llvm::numbers::sqrtpi
constexpr double sqrtpi
Definition: MathExtras.h:39
llvm::BitsToDouble
double BitsToDouble(uint64_t Bits)
This function takes a 64-bit integer and returns the bit equivalent double.
Definition: MathExtras.h:397
llvm::countr_zero
int countr_zero(T Val)
Count number of 0's from the least significant bit to the most stopping at the first 1.
Definition: bit.h:179
llvm::numbers::ln2
constexpr double ln2
Definition: MathExtras.h:33
llvm::numbers::phi
constexpr double phi
Definition: MathExtras.h:45
llvm::numbers::pi
constexpr double pi
Definition: MathExtras.h:37
llvm::countLeadingZeros
unsigned countLeadingZeros(T Val)
Count number of 0's from the most significant bit to the least stopping at the first 1.
Definition: MathExtras.h:81
llvm::numbers::sqrt2f
constexpr float sqrt2f
Definition: MathExtras.h:56
N
#define N
llvm::numbers::sqrtpif
constexpr float sqrtpif
Definition: MathExtras.h:54
llvm::numbers::pif
constexpr float pif
Definition: MathExtras.h:52
llvm::maxUIntN
uint64_t maxUIntN(uint64_t N)
Gets the maximum value for a N-bit unsigned integer.
Definition: MathExtras.h:225
llvm::isMask_64
constexpr bool isMask_64(uint64_t Value)
Return true if the argument is a non-empty sequence of ones starting at the least significant bit wit...
Definition: MathExtras.h:270
llvm::AMDGPU::HSAMD::Kernel::Key::Args
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
Definition: AMDGPUMetadata.h:394
llvm::isPowerOf2_64
constexpr bool isPowerOf2_64(uint64_t Value)
Return true if the argument is a power of two > 0 (64 bit edition.)
Definition: MathExtras.h:293
llvm::numbers::ln2f
constexpr float ln2f
Definition: MathExtras.h:48
llvm::divideNearest
uint64_t divideNearest(uint64_t Numerator, uint64_t Denominator)
Returns the integer nearest(Numerator / Denominator).
Definition: MathExtras.h:513
llvm::Value
LLVM Value Representation.
Definition: Value.h:74
llvm::numbers::ln10
constexpr double ln10
Definition: MathExtras.h:34
llvm::AbsoluteDifference
std::enable_if_t< std::is_unsigned< T >::value, T > AbsoluteDifference(T X, T Y)
Subtract two unsigned integers, X and Y, of type T and return the absolute value of the result.
Definition: MathExtras.h:560