[PATCH] D82107: [flang] Fix build problems on osx
Peter Klausler via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Jun 18 11:28:00 PDT 2020
This revision was automatically updated to reflect the committed changes.
Closed by commit rG3aee64a9e038: [flang] Fix build problems on osx (authored by klausler).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D82107/new/
https://reviews.llvm.org/D82107
Files:
flang/include/flang/Common/bit-population-count.h
flang/runtime/character.cpp
Index: flang/runtime/character.cpp
===================================================================
--- flang/runtime/character.cpp
+++ flang/runtime/character.cpp
@@ -688,7 +688,7 @@
}
result.Establish(string.type(), resultBytes, nullptr, 0);
RUNTIME_CHECK(terminator, result.Allocate(nullptr, nullptr) == CFI_SUCCESS);
- std::memcmp(result.OffsetElement(), string.OffsetElement(), resultBytes);
+ std::memcpy(result.OffsetElement(), string.OffsetElement(), resultBytes);
}
void RTNAME(CharacterMax)(Descriptor &accumulator, const Descriptor &x,
Index: flang/include/flang/Common/bit-population-count.h
===================================================================
--- flang/include/flang/Common/bit-population-count.h
+++ flang/include/flang/Common/bit-population-count.h
@@ -14,11 +14,14 @@
// in its argument. POPPAR is a parity function that returns true
// when POPCNT is odd.
-#include <cinttypes>
+#include <climits>
+#include <type_traits>
namespace Fortran::common {
-inline constexpr int BitPopulationCount(std::uint64_t x) {
+template <typename INT,
+ std::enable_if_t<(sizeof(INT) > 4 && sizeof(INT) <= 8), int> = 0>
+inline constexpr int BitPopulationCount(INT x) {
// In each of the 32 2-bit fields, count the bits that were present.
// This leaves a value [0..2] in each of these 2-bit fields.
x = (x & 0x5555555555555555) + ((x >> 1) & 0x5555555555555555);
@@ -34,7 +37,9 @@
return (x & 0x7f) + (x >> 32);
}
-inline constexpr int BitPopulationCount(std::uint32_t x) {
+template <typename INT,
+ std::enable_if_t<(sizeof(INT) > 2 && sizeof(INT) <= 4), int> = 0>
+inline constexpr int BitPopulationCount(INT x) {
// In each of the 16 2-bit fields, count the bits that were present.
// This leaves a value [0..2] in each of these 2-bit fields.
x = (x & 0x55555555) + ((x >> 1) & 0x55555555);
@@ -48,7 +53,8 @@
return (x & 0x3f) + (x >> 16);
}
-inline constexpr int BitPopulationCount(std::uint16_t x) {
+template <typename INT, std::enable_if_t<sizeof(INT) == 2, int> = 0>
+inline constexpr int BitPopulationCount(INT x) {
// In each of the 8 2-bit fields, count the bits that were present.
// This leaves a value [0..2] in each of these 2-bit fields.
x = (x & 0x5555) + ((x >> 1) & 0x5555);
@@ -60,7 +66,8 @@
return (x & 0x1f) + (x >> 8);
}
-inline constexpr int BitPopulationCount(std::uint8_t x) {
+template <typename INT, std::enable_if_t<sizeof(INT) == 1, int> = 0>
+inline constexpr int BitPopulationCount(INT x) {
// In each of the 4 2-bit fields, count the bits that were present.
// This leaves a value [0..2] in each of these 2-bit fields.
x = (x & 0x55) + ((x >> 1) & 0x55);
@@ -70,17 +77,19 @@
return (x & 0xf) + (x >> 4);
}
-template <typename UINT> inline constexpr bool Parity(UINT x) {
+template <typename INT> inline constexpr bool Parity(INT x) {
return BitPopulationCount(x) & 1;
}
// "Parity is for farmers." -- Seymour R. Cray
-template <typename UINT> inline constexpr int TrailingZeroBitCount(UINT x) {
+template <typename INT> inline constexpr int TrailingZeroBitCount(INT x) {
if ((x & 1) != 0) {
return 0; // fast path for odd values
+ } else if (x == 0) {
+ return CHAR_BIT * sizeof x;
} else {
- return BitPopulationCount(static_cast<UINT>(x ^ (x - 1))) - !!x;
+ return BitPopulationCount(static_cast<INT>(x ^ (x - 1))) - 1;
}
}
} // namespace Fortran::common
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D82107.271796.patch
Type: text/x-patch
Size: 3437 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200618/ef4c5255/attachment.bin>
More information about the llvm-commits
mailing list