|
14 | 14 | #define LLVM_SUPPORT_MATHEXTRAS_H
|
15 | 15 |
|
16 | 16 | #include <algorithm>
|
17 |
| - #include <cmath> |
18 | 17 | #include <cassert>
|
19 | 18 | #include <climits>
|
| 19 | + #include <cmath> |
| 20 | + #include <cstdint> |
20 | 21 | #include <cstring>
|
21 | 22 | #include <limits>
|
22 | 23 | #include <type_traits>
|
|
547 | 548 | /// (32 bit edition.)
|
548 | 549 | /// Ex. Log2_32(32) == 5, Log2_32(1) == 0, Log2_32(0) == -1, Log2_32(6) == 2
|
549 | 550 | inline unsigned Log2_32(uint32_t Value) {
|
550 |
| - return 31 - countLeadingZeros(Value); |
| 551 | + return static_cast<unsigned>(31 - countLeadingZeros(Value)); |
551 | 552 | }
|
552 | 553 |
|
553 | 554 | /// Return the floor log base 2 of the specified value, -1 if the value is zero.
|
554 | 555 | /// (64 bit edition.)
|
555 | 556 | inline unsigned Log2_64(uint64_t Value) {
|
556 |
| - return 63 - countLeadingZeros(Value); |
| 557 | + return static_cast<unsigned>(63 - countLeadingZeros(Value)); |
557 | 558 | }
|
558 | 559 |
|
559 | 560 | /// Return the ceil log base 2 of the specified value, 32 if the value is zero.
|
560 | 561 | /// (32 bit edition).
|
561 | 562 | /// Ex. Log2_32_Ceil(32) == 5, Log2_32_Ceil(1) == 0, Log2_32_Ceil(6) == 3
|
562 | 563 | inline unsigned Log2_32_Ceil(uint32_t Value) {
|
563 |
| - return 32 - countLeadingZeros(Value - 1); |
| 564 | + return static_cast<unsigned>(32 - countLeadingZeros(Value - 1)); |
564 | 565 | }
|
565 | 566 |
|
566 | 567 | /// Return the ceil log base 2 of the specified value, 64 if the value is zero.
|
567 | 568 | /// (64 bit edition.)
|
568 | 569 | inline unsigned Log2_64_Ceil(uint64_t Value) {
|
569 |
| - return 64 - countLeadingZeros(Value - 1); |
| 570 | + return static_cast<unsigned>(64 - countLeadingZeros(Value - 1)); |
570 | 571 | }
|
571 | 572 |
|
572 | 573 | /// Return the greatest common divisor of the values using Euclid's algorithm.
|
|
589 | 590 |
|
590 | 591 | /// This function takes a 32-bit integer and returns the bit equivalent float.
|
591 | 592 | inline float BitsToFloat(uint32_t Bits) {
|
| 593 | + //TODO: Use bit_cast once C++20 becomes available. |
592 | 594 | float F;
|
593 | 595 | static_assert(sizeof(uint32_t) == sizeof(float), "Unexpected type sizes");
|
594 | 596 | memcpy(&F, &Bits, sizeof(Bits));
|
|
0 commit comments