mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-14 23:56:16 +00:00
Update vendored deps
This commit is contained in:
15
third_party/abseil-cpp/absl/numeric/BUILD.bazel
vendored
15
third_party/abseil-cpp/absl/numeric/BUILD.bazel
vendored
@@ -12,7 +12,6 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
load("@rules_cc//cc:defs.bzl", "cc_library", "cc_test")
|
||||
load(
|
||||
"//absl:copts/configure_copts.bzl",
|
||||
"ABSL_DEFAULT_COPTS",
|
||||
@@ -38,6 +37,20 @@ cc_library(
|
||||
],
|
||||
)
|
||||
|
||||
cc_binary(
|
||||
name = "bits_benchmark",
|
||||
testonly = 1,
|
||||
srcs = ["bits_benchmark.cc"],
|
||||
copts = ABSL_DEFAULT_COPTS,
|
||||
linkopts = ABSL_DEFAULT_LINKOPTS,
|
||||
deps = [
|
||||
":bits",
|
||||
"//absl/base:core_headers",
|
||||
"//absl/random",
|
||||
"@com_github_google_benchmark//:benchmark_main",
|
||||
],
|
||||
)
|
||||
|
||||
cc_test(
|
||||
name = "bits_test",
|
||||
size = "small",
|
||||
|
||||
3
third_party/abseil-cpp/absl/numeric/bits.h
vendored
3
third_party/abseil-cpp/absl/numeric/bits.h
vendored
@@ -133,7 +133,8 @@ template <class T>
|
||||
ABSL_INTERNAL_CONSTEXPR_CLZ inline
|
||||
typename std::enable_if<std::is_unsigned<T>::value, T>::type
|
||||
bit_width(T x) noexcept {
|
||||
return std::numeric_limits<T>::digits - countl_zero(x);
|
||||
return std::numeric_limits<T>::digits -
|
||||
static_cast<unsigned int>(countl_zero(x));
|
||||
}
|
||||
|
||||
// Returns: If x == 0, 0; otherwise the maximal value y such that
|
||||
|
||||
73
third_party/abseil-cpp/absl/numeric/bits_benchmark.cc
vendored
Normal file
73
third_party/abseil-cpp/absl/numeric/bits_benchmark.cc
vendored
Normal file
@@ -0,0 +1,73 @@
|
||||
// Copyright 2022 The Abseil Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <cstdint>
|
||||
#include <vector>
|
||||
|
||||
#include "benchmark/benchmark.h"
|
||||
#include "absl/base/optimization.h"
|
||||
#include "absl/numeric/bits.h"
|
||||
#include "absl/random/random.h"
|
||||
|
||||
namespace absl {
|
||||
namespace {
|
||||
|
||||
template <typename T>
|
||||
static void BM_bitwidth(benchmark::State& state) {
|
||||
const int count = state.range(0);
|
||||
|
||||
absl::BitGen rng;
|
||||
std::vector<T> values;
|
||||
values.reserve(count);
|
||||
for (int i = 0; i < count; ++i) {
|
||||
values.push_back(absl::Uniform<T>(rng, 0, std::numeric_limits<T>::max()));
|
||||
}
|
||||
|
||||
while (state.KeepRunningBatch(count)) {
|
||||
for (int i = 0; i < count; ++i) {
|
||||
benchmark::DoNotOptimize(values[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
BENCHMARK_TEMPLATE(BM_bitwidth, uint8_t)->Range(1, 1 << 20);
|
||||
BENCHMARK_TEMPLATE(BM_bitwidth, uint16_t)->Range(1, 1 << 20);
|
||||
BENCHMARK_TEMPLATE(BM_bitwidth, uint32_t)->Range(1, 1 << 20);
|
||||
BENCHMARK_TEMPLATE(BM_bitwidth, uint64_t)->Range(1, 1 << 20);
|
||||
|
||||
template <typename T>
|
||||
static void BM_bitwidth_nonzero(benchmark::State& state) {
|
||||
const int count = state.range(0);
|
||||
|
||||
absl::BitGen rng;
|
||||
std::vector<T> values;
|
||||
values.reserve(count);
|
||||
for (int i = 0; i < count; ++i) {
|
||||
values.push_back(absl::Uniform<T>(rng, 1, std::numeric_limits<T>::max()));
|
||||
}
|
||||
|
||||
while (state.KeepRunningBatch(count)) {
|
||||
for (int i = 0; i < count; ++i) {
|
||||
const T value = values[i];
|
||||
ABSL_ASSUME(value > 0);
|
||||
benchmark::DoNotOptimize(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
BENCHMARK_TEMPLATE(BM_bitwidth_nonzero, uint8_t)->Range(1, 1 << 20);
|
||||
BENCHMARK_TEMPLATE(BM_bitwidth_nonzero, uint16_t)->Range(1, 1 << 20);
|
||||
BENCHMARK_TEMPLATE(BM_bitwidth_nonzero, uint32_t)->Range(1, 1 << 20);
|
||||
BENCHMARK_TEMPLATE(BM_bitwidth_nonzero, uint64_t)->Range(1, 1 << 20);
|
||||
|
||||
} // namespace
|
||||
} // namespace absl
|
||||
@@ -42,11 +42,11 @@ namespace {
|
||||
// Returns: 2
|
||||
inline ABSL_ATTRIBUTE_ALWAYS_INLINE int Fls128(uint128 n) {
|
||||
if (uint64_t hi = Uint128High64(n)) {
|
||||
ABSL_INTERNAL_ASSUME(hi != 0);
|
||||
ABSL_ASSUME(hi != 0);
|
||||
return 127 - countl_zero(hi);
|
||||
}
|
||||
const uint64_t low = Uint128Low64(n);
|
||||
ABSL_INTERNAL_ASSUME(low != 0);
|
||||
ABSL_ASSUME(low != 0);
|
||||
return 63 - countl_zero(low);
|
||||
}
|
||||
|
||||
@@ -332,6 +332,7 @@ std::ostream& operator<<(std::ostream& os, int128 v) {
|
||||
ABSL_NAMESPACE_END
|
||||
} // namespace absl
|
||||
|
||||
#ifdef ABSL_INTERNAL_NEED_REDUNDANT_CONSTEXPR_DECL
|
||||
namespace std {
|
||||
constexpr bool numeric_limits<absl::uint128>::is_specialized;
|
||||
constexpr bool numeric_limits<absl::uint128>::is_signed;
|
||||
@@ -381,3 +382,4 @@ constexpr int numeric_limits<absl::int128>::max_exponent10;
|
||||
constexpr bool numeric_limits<absl::int128>::traps;
|
||||
constexpr bool numeric_limits<absl::int128>::tinyness_before;
|
||||
} // namespace std
|
||||
#endif
|
||||
|
||||
4
third_party/abseil-cpp/absl/numeric/int128.h
vendored
4
third_party/abseil-cpp/absl/numeric/int128.h
vendored
@@ -44,7 +44,7 @@
|
||||
// builtin type. We need to make sure not to define operator wchar_t()
|
||||
// alongside operator unsigned short() in these instances.
|
||||
#define ABSL_INTERNAL_WCHAR_T __wchar_t
|
||||
#if defined(_M_X64)
|
||||
#if defined(_M_X64) && !defined(_M_ARM64EC)
|
||||
#include <intrin.h>
|
||||
#pragma intrinsic(_umul128)
|
||||
#endif // defined(_M_X64)
|
||||
@@ -980,7 +980,7 @@ inline uint128 operator*(uint128 lhs, uint128 rhs) {
|
||||
// can be used for uint128 storage.
|
||||
return static_cast<unsigned __int128>(lhs) *
|
||||
static_cast<unsigned __int128>(rhs);
|
||||
#elif defined(_MSC_VER) && defined(_M_X64)
|
||||
#elif defined(_MSC_VER) && defined(_M_X64) && !defined(_M_ARM64EC)
|
||||
uint64_t carry;
|
||||
uint64_t low = _umul128(Uint128Low64(lhs), Uint128Low64(rhs), &carry);
|
||||
return MakeUint128(Uint128Low64(lhs) * Uint128High64(rhs) +
|
||||
|
||||
@@ -279,7 +279,7 @@ constexpr int128 operator^(int128 lhs, int128 rhs) {
|
||||
}
|
||||
|
||||
constexpr int128 operator<<(int128 lhs, int amount) {
|
||||
// uint64_t shifts of >= 64 are undefined, so we need some special-casing.
|
||||
// int64_t shifts of >= 64 are undefined, so we need some special-casing.
|
||||
return amount >= 64
|
||||
? MakeInt128(
|
||||
static_cast<int64_t>(Int128Low64(lhs) << (amount - 64)), 0)
|
||||
@@ -292,10 +292,16 @@ constexpr int128 operator<<(int128 lhs, int amount) {
|
||||
}
|
||||
|
||||
constexpr int128 operator>>(int128 lhs, int amount) {
|
||||
// uint64_t shifts of >= 64 are undefined, so we need some special-casing.
|
||||
// int64_t shifts of >= 64 are undefined, so we need some special-casing.
|
||||
// The (Int128High64(lhs) >> 32) >> 32 "trick" causes the the most significant
|
||||
// int64 to be inititialized with all zeros or all ones correctly. It takes
|
||||
// into account whether the number is negative or positive, and whether the
|
||||
// current architecture does arithmetic or logical right shifts for negative
|
||||
// numbers.
|
||||
return amount >= 64
|
||||
? MakeInt128(
|
||||
0, static_cast<uint64_t>(Int128High64(lhs) >> (amount - 64)))
|
||||
(Int128High64(lhs) >> 32) >> 32,
|
||||
static_cast<uint64_t>(Int128High64(lhs) >> (amount - 64)))
|
||||
: amount == 0
|
||||
? lhs
|
||||
: MakeInt128(Int128High64(lhs) >> amount,
|
||||
|
||||
@@ -239,6 +239,24 @@ TEST(Uint128, AllTests) {
|
||||
EXPECT_EQ(absl::Uint128Max(), absl::kuint128max);
|
||||
}
|
||||
|
||||
TEST(Int128, RightShiftOfNegativeNumbers) {
|
||||
absl::int128 minus_six = -6;
|
||||
absl::int128 minus_three = -3;
|
||||
absl::int128 minus_two = -2;
|
||||
absl::int128 minus_one = -1;
|
||||
if ((-6 >> 1) == -3) {
|
||||
// Right shift is arithmetic (sign propagates)
|
||||
EXPECT_EQ(minus_six >> 1, minus_three);
|
||||
EXPECT_EQ(minus_six >> 2, minus_two);
|
||||
EXPECT_EQ(minus_six >> 65, minus_one);
|
||||
} else {
|
||||
// Right shift is logical (zeros shifted in at MSB)
|
||||
EXPECT_EQ(minus_six >> 1, absl::int128(absl::uint128(minus_six) >> 1));
|
||||
EXPECT_EQ(minus_six >> 2, absl::int128(absl::uint128(minus_six) >> 2));
|
||||
EXPECT_EQ(minus_six >> 65, absl::int128(absl::uint128(minus_six) >> 65));
|
||||
}
|
||||
}
|
||||
|
||||
TEST(Uint128, ConversionTests) {
|
||||
EXPECT_TRUE(absl::MakeUint128(1, 0));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user