mirror of
https://github.com/FirebirdSQL/firebird.git
synced 2025-01-22 16:43:03 +01:00
Fix for #6978: FB4 build fails on big endian
This commit is contained in:
parent
2225e291a9
commit
cc1950a156
@ -175,6 +175,11 @@ external:
|
||||
$(MAKE) -C $(ROOT)/extern/decNumber
|
||||
ln -sf $(ROOT)/extern/decNumber/libdecFloat.a $(LIB)
|
||||
|
||||
ifeq ($(ABSEIL_BUILD_FLG),Y)
|
||||
$(MAKE) -C $(ROOT)/extern/int128/absl/numeric
|
||||
ln -sf $(ROOT)/extern/int128/absl/numeric/libi128.a $(LIB)
|
||||
endif
|
||||
|
||||
ifeq ($(RE2_BUILD_FLG),Y)
|
||||
CXXFLAGS="-O3 -g -fPIC" $(MAKE) -C $(ROOT)/extern/re2
|
||||
ln -sf $(ROOT)/extern/re2/obj/libre2.a $(LIB)
|
||||
@ -331,6 +336,8 @@ cross2:
|
||||
$(MAKE) re2
|
||||
$(MAKE) -C $(ROOT)/extern/decNumber
|
||||
ln -sf $(ROOT)/extern/decNumber/libdecFloat$(CROSS).a $(LIB)
|
||||
$(MAKE) -C $(ROOT)/extern/int128/absl/numeric
|
||||
ln -sf $(ROOT)/extern/int128/absl/numeric/libi128$(CROSS).a $(LIB)
|
||||
$(MAKE) yvalve
|
||||
$(MAKE) engine
|
||||
$(MAKE) fbintl
|
||||
@ -705,12 +712,12 @@ install install-embedded silent_install package packages dist:
|
||||
#
|
||||
.PHONY: clean clean_objects clean_dependancies clean_extern_objects clean_build \
|
||||
clean_gpre_gen clean_icu clean_dbs clean_examples clean_makefiles \
|
||||
clean_editline clean_all clean_decfloat clean_vers clean_misc
|
||||
clean_editline clean_all clean_decfloat clean_int128 clean_vers clean_misc
|
||||
|
||||
|
||||
clean: clean_objects clean_dependancies clean_extern_objects clean_build \
|
||||
clean_yacc_gen clean_gpre_gen clean_dbs clean_examples clean_tommath \
|
||||
clean_tomcrypt clean_decfloat clean_vers clean_misc
|
||||
clean_tomcrypt clean_decfloat clean_int128 clean_vers clean_misc
|
||||
|
||||
clean_vers:
|
||||
$(RM) *.vers
|
||||
@ -764,6 +771,9 @@ clean_tomcrypt:
|
||||
clean_decfloat:
|
||||
-$(MAKE) -C $(ROOT)/extern/decNumber clean
|
||||
|
||||
clean_int128:
|
||||
-$(MAKE) -C $(ROOT)/extern/int128/absl/numeric clean
|
||||
|
||||
clean_objects:
|
||||
$(RM) `find $(TMP_ROOT)/ -type f -name '*.o' -print`
|
||||
$(RM) `find $(TMP_ROOT)/ -type f -name '*.a' -print`
|
||||
|
@ -41,7 +41,7 @@ DEV_FLAGS=$(COMMON_FLAGS) $(WARN_FLAGS)
|
||||
CROSS_CONFIG=android.arm64
|
||||
|
||||
LDFLAGS += --sysroot=$(CROSS_SYSROOT) -static-libstdc++
|
||||
DroidLibs := -lm -ldl $(DECLIB) $(RE2LIB)
|
||||
DroidLibs := -lm -ldl $(DECLIB) $(RE2LIB) $(I128LIB)
|
||||
|
||||
LINK_LIBS = $(DroidLibs)
|
||||
STATICLINK_LIBS = $(DroidLibs)
|
||||
|
@ -40,7 +40,7 @@ DEV_FLAGS=$(COMMON_FLAGS) $(WARN_FLAGS)
|
||||
CROSS_CONFIG=android.arme
|
||||
|
||||
LDFLAGS += --sysroot=$(CROSS_PLATFORM) -static-libstdc++
|
||||
DroidLibs := -lm -ldl $(DECLIB) $(RE2LIB)
|
||||
DroidLibs := -lm -ldl $(DECLIB) $(RE2LIB) $(I128LIB)
|
||||
UDR_SUPPORT_LIBS :=
|
||||
|
||||
LINK_LIBS = $(DroidLibs)
|
||||
|
@ -132,10 +132,18 @@ ATOMIC_OPTIONS=@ATOMIC_OPTIONS@
|
||||
# needed at least for solaris inline assembly routines
|
||||
CAS_OPTIONS=@CAS_OPTIONS@
|
||||
|
||||
# BigEndian int128 support
|
||||
ABSEIL_BUILD_FLG = @ABSEIL_BUILD_FLG@
|
||||
|
||||
# multiple-precision integer library
|
||||
MATHLIB=@MATHLIB@
|
||||
DECLIB=-ldecFloat$(CROSS)
|
||||
RE2LIB=-lre2
|
||||
ifeq ($(ABSEIL_BUILD_FLG), Y)
|
||||
I128LIB=-li128$(CROSS)
|
||||
else
|
||||
I128LIB=
|
||||
endif
|
||||
|
||||
# crypt library
|
||||
CRYPTLIB=@CRYPTLIB@
|
||||
@ -191,8 +199,8 @@ endif
|
||||
STATICLIB_LINK = $(AR) crus
|
||||
STATICEXE_LINK = $(CXX) $(GLOB_OPTIONS) $(CXXFLAGS) -static-libstdc++
|
||||
|
||||
LINK_LIBS = @LIBS@ $(DECLIB) $(RE2LIB)
|
||||
SO_LINK_LIBS = @LIBS@ $(DECLIB) $(RE2LIB)
|
||||
LINK_LIBS = @LIBS@ $(DECLIB) $(RE2LIB) $(I128LIB)
|
||||
SO_LINK_LIBS = @LIBS@ $(DECLIB) $(RE2LIB) $(I128LIB)
|
||||
|
||||
# Default extensions
|
||||
|
||||
@ -416,13 +424,12 @@ GPRE = $(BIN)/gpre$(EXEC_EXT)
|
||||
RUN_GPRE = $(RBIN)/gpre$(EXEC_EXT)
|
||||
GPRE_CURRENT = $(RBIN)/gpre_current$(EXEC_EXT)
|
||||
|
||||
|
||||
# From msgs
|
||||
BUILD_FILE = $(BIN)/build_file$(EXEC_EXT)
|
||||
FIREBIRD_MSG = $(FIREBIRD)/firebird.msg
|
||||
|
||||
|
||||
#Platform Manager
|
||||
#For want of a better suggestion we may as well default to posix
|
||||
# Platform Manager
|
||||
# For want of a better suggestion we may as well default to posix
|
||||
PLATFORM_PATH = os/posix
|
||||
TRACE_OS_Sources =
|
||||
|
||||
|
@ -46,6 +46,10 @@ ifeq ($(RE2_BUILD_FLG),Y)
|
||||
WFLAGS += -I$(ROOT)/extern/re2
|
||||
endif
|
||||
|
||||
ifeq ($(ABSEIL_BUILD_FLG),Y)
|
||||
WFLAGS += -I$(ROOT)/extern/int128
|
||||
endif
|
||||
|
||||
ifeq ($(LSB_FLG),Y)
|
||||
WFLAGS += -DLSB_BUILD
|
||||
endif
|
||||
|
@ -18,10 +18,10 @@
|
||||
#
|
||||
# 2 Oct 2002, Nickolay Samofatov - Major cleanup
|
||||
|
||||
COMMON_FLAGS=-ggdb -DFB_SEND_FLAGS=MSG_NOSIGNAL -DLINUX -pipe -MMD -fPIC -fmessage-length=0 -fsigned-char
|
||||
COMMON_FLAGS=-ggdb -DFB_SEND_FLAGS=MSG_NOSIGNAL -DLINUX -pipe -MMD -fPIC -fmessage-length=0 -fsigned-char -Wno-invalid-offsetof
|
||||
OPTIMIZE_FLAGS=-O3 -fno-omit-frame-pointer -fno-builtin
|
||||
WARN_FLAGS=-Werror=delete-incomplete -Wall -Wno-switch -Wno-parentheses -Wno-unknown-pragmas -Wno-unused-variable -Wno-non-virtual-dtor
|
||||
|
||||
PROD_FLAGS=$(COMMON_FLAGS) $(OPTIMIZE_FLAGS)
|
||||
DEV_FLAGS=-DUSE_VALGRIND -p $(COMMON_FLAGS) $(WARN_FLAGS)
|
||||
#DEV_FLAGS=-p $(COMMON_FLAGS) $(WARN_FLAGS)
|
||||
#DEV_FLAGS=-DUSE_VALGRIND -p $(COMMON_FLAGS) $(WARN_FLAGS)
|
||||
DEV_FLAGS=-p $(COMMON_FLAGS) $(WARN_FLAGS)
|
||||
|
@ -1086,6 +1086,15 @@ if test "$ac_cv_sys_file_offset_bits" = "no"; then
|
||||
AC_MSG_RESULT(yes)],[AC_MSG_RESULT(no)],[])
|
||||
fi
|
||||
|
||||
dnl Use int128 support for big endians
|
||||
if test "$ac_cv_c_bigendian" = "yes"; then
|
||||
ABSEIL_BUILD_FLG=Y
|
||||
AC_DEFINE(FB_USE_ABSEIL_INT128, 1, [Use Abseil's class int128])
|
||||
else
|
||||
ABSEIL_BUILD_FLG=N
|
||||
fi
|
||||
AC_SUBST(ABSEIL_BUILD_FLG)
|
||||
|
||||
AC_CHECK_SIZEOF(void *)
|
||||
VOID_PTR_SIZE=$ac_cv_sizeof_void_p
|
||||
AC_SUBST(VOID_PTR_SIZE)
|
||||
|
721
extern/int128/absl/base/attributes.h
vendored
Normal file
721
extern/int128/absl/base/attributes.h
vendored
Normal file
@ -0,0 +1,721 @@
|
||||
// Copyright 2017 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.
|
||||
//
|
||||
// This header file defines macros for declaring attributes for functions,
|
||||
// types, and variables.
|
||||
//
|
||||
// These macros are used within Abseil and allow the compiler to optimize, where
|
||||
// applicable, certain function calls.
|
||||
//
|
||||
// Most macros here are exposing GCC or Clang features, and are stubbed out for
|
||||
// other compilers.
|
||||
//
|
||||
// GCC attributes documentation:
|
||||
// https://gcc.gnu.org/onlinedocs/gcc-4.7.0/gcc/Function-Attributes.html
|
||||
// https://gcc.gnu.org/onlinedocs/gcc-4.7.0/gcc/Variable-Attributes.html
|
||||
// https://gcc.gnu.org/onlinedocs/gcc-4.7.0/gcc/Type-Attributes.html
|
||||
//
|
||||
// Most attributes in this file are already supported by GCC 4.7. However, some
|
||||
// of them are not supported in older version of Clang. Thus, we check
|
||||
// `__has_attribute()` first. If the check fails, we check if we are on GCC and
|
||||
// assume the attribute exists on GCC (which is verified on GCC 4.7).
|
||||
|
||||
#ifndef ABSL_BASE_ATTRIBUTES_H_
|
||||
#define ABSL_BASE_ATTRIBUTES_H_
|
||||
|
||||
#include "absl/base/config.h"
|
||||
|
||||
// ABSL_HAVE_ATTRIBUTE
|
||||
//
|
||||
// A function-like feature checking macro that is a wrapper around
|
||||
// `__has_attribute`, which is defined by GCC 5+ and Clang and evaluates to a
|
||||
// nonzero constant integer if the attribute is supported or 0 if not.
|
||||
//
|
||||
// It evaluates to zero if `__has_attribute` is not defined by the compiler.
|
||||
//
|
||||
// GCC: https://gcc.gnu.org/gcc-5/changes.html
|
||||
// Clang: https://clang.llvm.org/docs/LanguageExtensions.html
|
||||
#ifdef __has_attribute
|
||||
#define ABSL_HAVE_ATTRIBUTE(x) __has_attribute(x)
|
||||
#else
|
||||
#define ABSL_HAVE_ATTRIBUTE(x) 0
|
||||
#endif
|
||||
|
||||
// ABSL_HAVE_CPP_ATTRIBUTE
|
||||
//
|
||||
// A function-like feature checking macro that accepts C++11 style attributes.
|
||||
// It's a wrapper around `__has_cpp_attribute`, defined by ISO C++ SD-6
|
||||
// (https://en.cppreference.com/w/cpp/experimental/feature_test). If we don't
|
||||
// find `__has_cpp_attribute`, will evaluate to 0.
|
||||
#if defined(__cplusplus) && defined(__has_cpp_attribute)
|
||||
// NOTE: requiring __cplusplus above should not be necessary, but
|
||||
// works around https://bugs.llvm.org/show_bug.cgi?id=23435.
|
||||
#define ABSL_HAVE_CPP_ATTRIBUTE(x) __has_cpp_attribute(x)
|
||||
#else
|
||||
#define ABSL_HAVE_CPP_ATTRIBUTE(x) 0
|
||||
#endif
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Function Attributes
|
||||
// -----------------------------------------------------------------------------
|
||||
//
|
||||
// GCC: https://gcc.gnu.org/onlinedocs/gcc/Function-Attributes.html
|
||||
// Clang: https://clang.llvm.org/docs/AttributeReference.html
|
||||
|
||||
// ABSL_PRINTF_ATTRIBUTE
|
||||
// ABSL_SCANF_ATTRIBUTE
|
||||
//
|
||||
// Tells the compiler to perform `printf` format string checking if the
|
||||
// compiler supports it; see the 'format' attribute in
|
||||
// <https://gcc.gnu.org/onlinedocs/gcc-4.7.0/gcc/Function-Attributes.html>.
|
||||
//
|
||||
// Note: As the GCC manual states, "[s]ince non-static C++ methods
|
||||
// have an implicit 'this' argument, the arguments of such methods
|
||||
// should be counted from two, not one."
|
||||
#if ABSL_HAVE_ATTRIBUTE(format) || (defined(__GNUC__) && !defined(__clang__))
|
||||
#define ABSL_PRINTF_ATTRIBUTE(string_index, first_to_check) \
|
||||
__attribute__((__format__(__printf__, string_index, first_to_check)))
|
||||
#define ABSL_SCANF_ATTRIBUTE(string_index, first_to_check) \
|
||||
__attribute__((__format__(__scanf__, string_index, first_to_check)))
|
||||
#else
|
||||
#define ABSL_PRINTF_ATTRIBUTE(string_index, first_to_check)
|
||||
#define ABSL_SCANF_ATTRIBUTE(string_index, first_to_check)
|
||||
#endif
|
||||
|
||||
// ABSL_ATTRIBUTE_ALWAYS_INLINE
|
||||
// ABSL_ATTRIBUTE_NOINLINE
|
||||
//
|
||||
// Forces functions to either inline or not inline. Introduced in gcc 3.1.
|
||||
#if ABSL_HAVE_ATTRIBUTE(always_inline) || \
|
||||
(defined(__GNUC__) && !defined(__clang__))
|
||||
#define ABSL_ATTRIBUTE_ALWAYS_INLINE __attribute__((always_inline))
|
||||
#define ABSL_HAVE_ATTRIBUTE_ALWAYS_INLINE 1
|
||||
#else
|
||||
#define ABSL_ATTRIBUTE_ALWAYS_INLINE
|
||||
#endif
|
||||
|
||||
#if ABSL_HAVE_ATTRIBUTE(noinline) || (defined(__GNUC__) && !defined(__clang__))
|
||||
#define ABSL_ATTRIBUTE_NOINLINE __attribute__((noinline))
|
||||
#define ABSL_HAVE_ATTRIBUTE_NOINLINE 1
|
||||
#else
|
||||
#define ABSL_ATTRIBUTE_NOINLINE
|
||||
#endif
|
||||
|
||||
// ABSL_ATTRIBUTE_NO_TAIL_CALL
|
||||
//
|
||||
// Prevents the compiler from optimizing away stack frames for functions which
|
||||
// end in a call to another function.
|
||||
#if ABSL_HAVE_ATTRIBUTE(disable_tail_calls)
|
||||
#define ABSL_HAVE_ATTRIBUTE_NO_TAIL_CALL 1
|
||||
#define ABSL_ATTRIBUTE_NO_TAIL_CALL __attribute__((disable_tail_calls))
|
||||
#elif defined(__GNUC__) && !defined(__clang__) && !defined(__e2k__)
|
||||
#define ABSL_HAVE_ATTRIBUTE_NO_TAIL_CALL 1
|
||||
#define ABSL_ATTRIBUTE_NO_TAIL_CALL \
|
||||
__attribute__((optimize("no-optimize-sibling-calls")))
|
||||
#else
|
||||
#define ABSL_ATTRIBUTE_NO_TAIL_CALL
|
||||
#define ABSL_HAVE_ATTRIBUTE_NO_TAIL_CALL 0
|
||||
#endif
|
||||
|
||||
// ABSL_ATTRIBUTE_WEAK
|
||||
//
|
||||
// Tags a function as weak for the purposes of compilation and linking.
|
||||
// Weak attributes did not work properly in LLVM's Windows backend before
|
||||
// 9.0.0, so disable them there. See https://bugs.llvm.org/show_bug.cgi?id=37598
|
||||
// for further information.
|
||||
// The MinGW compiler doesn't complain about the weak attribute until the link
|
||||
// step, presumably because Windows doesn't use ELF binaries.
|
||||
#if (ABSL_HAVE_ATTRIBUTE(weak) || \
|
||||
(defined(__GNUC__) && !defined(__clang__))) && \
|
||||
(!defined(_WIN32) || __clang_major__ < 9) && !defined(__MINGW32__)
|
||||
#undef ABSL_ATTRIBUTE_WEAK
|
||||
#define ABSL_ATTRIBUTE_WEAK __attribute__((weak))
|
||||
#define ABSL_HAVE_ATTRIBUTE_WEAK 1
|
||||
#else
|
||||
#define ABSL_ATTRIBUTE_WEAK
|
||||
#define ABSL_HAVE_ATTRIBUTE_WEAK 0
|
||||
#endif
|
||||
|
||||
// ABSL_ATTRIBUTE_NONNULL
|
||||
//
|
||||
// Tells the compiler either (a) that a particular function parameter
|
||||
// should be a non-null pointer, or (b) that all pointer arguments should
|
||||
// be non-null.
|
||||
//
|
||||
// Note: As the GCC manual states, "[s]ince non-static C++ methods
|
||||
// have an implicit 'this' argument, the arguments of such methods
|
||||
// should be counted from two, not one."
|
||||
//
|
||||
// Args are indexed starting at 1.
|
||||
//
|
||||
// For non-static class member functions, the implicit `this` argument
|
||||
// is arg 1, and the first explicit argument is arg 2. For static class member
|
||||
// functions, there is no implicit `this`, and the first explicit argument is
|
||||
// arg 1.
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
// /* arg_a cannot be null, but arg_b can */
|
||||
// void Function(void* arg_a, void* arg_b) ABSL_ATTRIBUTE_NONNULL(1);
|
||||
//
|
||||
// class C {
|
||||
// /* arg_a cannot be null, but arg_b can */
|
||||
// void Method(void* arg_a, void* arg_b) ABSL_ATTRIBUTE_NONNULL(2);
|
||||
//
|
||||
// /* arg_a cannot be null, but arg_b can */
|
||||
// static void StaticMethod(void* arg_a, void* arg_b)
|
||||
// ABSL_ATTRIBUTE_NONNULL(1);
|
||||
// };
|
||||
//
|
||||
// If no arguments are provided, then all pointer arguments should be non-null.
|
||||
//
|
||||
// /* No pointer arguments may be null. */
|
||||
// void Function(void* arg_a, void* arg_b, int arg_c) ABSL_ATTRIBUTE_NONNULL();
|
||||
//
|
||||
// NOTE: The GCC nonnull attribute actually accepts a list of arguments, but
|
||||
// ABSL_ATTRIBUTE_NONNULL does not.
|
||||
#if ABSL_HAVE_ATTRIBUTE(nonnull) || (defined(__GNUC__) && !defined(__clang__))
|
||||
#define ABSL_ATTRIBUTE_NONNULL(arg_index) __attribute__((nonnull(arg_index)))
|
||||
#else
|
||||
#define ABSL_ATTRIBUTE_NONNULL(...)
|
||||
#endif
|
||||
|
||||
// ABSL_ATTRIBUTE_NORETURN
|
||||
//
|
||||
// Tells the compiler that a given function never returns.
|
||||
#if ABSL_HAVE_ATTRIBUTE(noreturn) || (defined(__GNUC__) && !defined(__clang__))
|
||||
#define ABSL_ATTRIBUTE_NORETURN __attribute__((noreturn))
|
||||
#elif defined(_MSC_VER)
|
||||
#define ABSL_ATTRIBUTE_NORETURN __declspec(noreturn)
|
||||
#else
|
||||
#define ABSL_ATTRIBUTE_NORETURN
|
||||
#endif
|
||||
|
||||
// ABSL_ATTRIBUTE_NO_SANITIZE_ADDRESS
|
||||
//
|
||||
// Tells the AddressSanitizer (or other memory testing tools) to ignore a given
|
||||
// function. Useful for cases when a function reads random locations on stack,
|
||||
// calls _exit from a cloned subprocess, deliberately accesses buffer
|
||||
// out of bounds or does other scary things with memory.
|
||||
// NOTE: GCC supports AddressSanitizer(asan) since 4.8.
|
||||
// https://gcc.gnu.org/gcc-4.8/changes.html
|
||||
#if ABSL_HAVE_ATTRIBUTE(no_sanitize_address)
|
||||
#define ABSL_ATTRIBUTE_NO_SANITIZE_ADDRESS __attribute__((no_sanitize_address))
|
||||
#else
|
||||
#define ABSL_ATTRIBUTE_NO_SANITIZE_ADDRESS
|
||||
#endif
|
||||
|
||||
// ABSL_ATTRIBUTE_NO_SANITIZE_MEMORY
|
||||
//
|
||||
// Tells the MemorySanitizer to relax the handling of a given function. All "Use
|
||||
// of uninitialized value" warnings from such functions will be suppressed, and
|
||||
// all values loaded from memory will be considered fully initialized. This
|
||||
// attribute is similar to the ABSL_ATTRIBUTE_NO_SANITIZE_ADDRESS attribute
|
||||
// above, but deals with initialized-ness rather than addressability issues.
|
||||
// NOTE: MemorySanitizer(msan) is supported by Clang but not GCC.
|
||||
#if ABSL_HAVE_ATTRIBUTE(no_sanitize_memory)
|
||||
#define ABSL_ATTRIBUTE_NO_SANITIZE_MEMORY __attribute__((no_sanitize_memory))
|
||||
#else
|
||||
#define ABSL_ATTRIBUTE_NO_SANITIZE_MEMORY
|
||||
#endif
|
||||
|
||||
// ABSL_ATTRIBUTE_NO_SANITIZE_THREAD
|
||||
//
|
||||
// Tells the ThreadSanitizer to not instrument a given function.
|
||||
// NOTE: GCC supports ThreadSanitizer(tsan) since 4.8.
|
||||
// https://gcc.gnu.org/gcc-4.8/changes.html
|
||||
#if ABSL_HAVE_ATTRIBUTE(no_sanitize_thread)
|
||||
#define ABSL_ATTRIBUTE_NO_SANITIZE_THREAD __attribute__((no_sanitize_thread))
|
||||
#else
|
||||
#define ABSL_ATTRIBUTE_NO_SANITIZE_THREAD
|
||||
#endif
|
||||
|
||||
// ABSL_ATTRIBUTE_NO_SANITIZE_UNDEFINED
|
||||
//
|
||||
// Tells the UndefinedSanitizer to ignore a given function. Useful for cases
|
||||
// where certain behavior (eg. division by zero) is being used intentionally.
|
||||
// NOTE: GCC supports UndefinedBehaviorSanitizer(ubsan) since 4.9.
|
||||
// https://gcc.gnu.org/gcc-4.9/changes.html
|
||||
#if ABSL_HAVE_ATTRIBUTE(no_sanitize_undefined)
|
||||
#define ABSL_ATTRIBUTE_NO_SANITIZE_UNDEFINED \
|
||||
__attribute__((no_sanitize_undefined))
|
||||
#elif ABSL_HAVE_ATTRIBUTE(no_sanitize)
|
||||
#define ABSL_ATTRIBUTE_NO_SANITIZE_UNDEFINED \
|
||||
__attribute__((no_sanitize("undefined")))
|
||||
#else
|
||||
#define ABSL_ATTRIBUTE_NO_SANITIZE_UNDEFINED
|
||||
#endif
|
||||
|
||||
// ABSL_ATTRIBUTE_NO_SANITIZE_CFI
|
||||
//
|
||||
// Tells the ControlFlowIntegrity sanitizer to not instrument a given function.
|
||||
// See https://clang.llvm.org/docs/ControlFlowIntegrity.html for details.
|
||||
#if ABSL_HAVE_ATTRIBUTE(no_sanitize)
|
||||
#define ABSL_ATTRIBUTE_NO_SANITIZE_CFI __attribute__((no_sanitize("cfi")))
|
||||
#else
|
||||
#define ABSL_ATTRIBUTE_NO_SANITIZE_CFI
|
||||
#endif
|
||||
|
||||
// ABSL_ATTRIBUTE_NO_SANITIZE_SAFESTACK
|
||||
//
|
||||
// Tells the SafeStack to not instrument a given function.
|
||||
// See https://clang.llvm.org/docs/SafeStack.html for details.
|
||||
#if ABSL_HAVE_ATTRIBUTE(no_sanitize)
|
||||
#define ABSL_ATTRIBUTE_NO_SANITIZE_SAFESTACK \
|
||||
__attribute__((no_sanitize("safe-stack")))
|
||||
#else
|
||||
#define ABSL_ATTRIBUTE_NO_SANITIZE_SAFESTACK
|
||||
#endif
|
||||
|
||||
// ABSL_ATTRIBUTE_RETURNS_NONNULL
|
||||
//
|
||||
// Tells the compiler that a particular function never returns a null pointer.
|
||||
#if ABSL_HAVE_ATTRIBUTE(returns_nonnull)
|
||||
#define ABSL_ATTRIBUTE_RETURNS_NONNULL __attribute__((returns_nonnull))
|
||||
#else
|
||||
#define ABSL_ATTRIBUTE_RETURNS_NONNULL
|
||||
#endif
|
||||
|
||||
// ABSL_HAVE_ATTRIBUTE_SECTION
|
||||
//
|
||||
// Indicates whether labeled sections are supported. Weak symbol support is
|
||||
// a prerequisite. Labeled sections are not supported on Darwin/iOS.
|
||||
#ifdef ABSL_HAVE_ATTRIBUTE_SECTION
|
||||
#error ABSL_HAVE_ATTRIBUTE_SECTION cannot be directly set
|
||||
#elif (ABSL_HAVE_ATTRIBUTE(section) || \
|
||||
(defined(__GNUC__) && !defined(__clang__))) && \
|
||||
!defined(__APPLE__) && ABSL_HAVE_ATTRIBUTE_WEAK
|
||||
#define ABSL_HAVE_ATTRIBUTE_SECTION 1
|
||||
|
||||
// ABSL_ATTRIBUTE_SECTION
|
||||
//
|
||||
// Tells the compiler/linker to put a given function into a section and define
|
||||
// `__start_ ## name` and `__stop_ ## name` symbols to bracket the section.
|
||||
// This functionality is supported by GNU linker. Any function annotated with
|
||||
// `ABSL_ATTRIBUTE_SECTION` must not be inlined, or it will be placed into
|
||||
// whatever section its caller is placed into.
|
||||
//
|
||||
#ifndef ABSL_ATTRIBUTE_SECTION
|
||||
#define ABSL_ATTRIBUTE_SECTION(name) \
|
||||
__attribute__((section(#name))) __attribute__((noinline))
|
||||
#endif
|
||||
|
||||
|
||||
// ABSL_ATTRIBUTE_SECTION_VARIABLE
|
||||
//
|
||||
// Tells the compiler/linker to put a given variable into a section and define
|
||||
// `__start_ ## name` and `__stop_ ## name` symbols to bracket the section.
|
||||
// This functionality is supported by GNU linker.
|
||||
#ifndef ABSL_ATTRIBUTE_SECTION_VARIABLE
|
||||
#define ABSL_ATTRIBUTE_SECTION_VARIABLE(name) __attribute__((section(#name)))
|
||||
#endif
|
||||
|
||||
// ABSL_DECLARE_ATTRIBUTE_SECTION_VARS
|
||||
//
|
||||
// A weak section declaration to be used as a global declaration
|
||||
// for ABSL_ATTRIBUTE_SECTION_START|STOP(name) to compile and link
|
||||
// even without functions with ABSL_ATTRIBUTE_SECTION(name).
|
||||
// ABSL_DEFINE_ATTRIBUTE_SECTION should be in the exactly one file; it's
|
||||
// a no-op on ELF but not on Mach-O.
|
||||
//
|
||||
#ifndef ABSL_DECLARE_ATTRIBUTE_SECTION_VARS
|
||||
#define ABSL_DECLARE_ATTRIBUTE_SECTION_VARS(name) \
|
||||
extern char __start_##name[] ABSL_ATTRIBUTE_WEAK; \
|
||||
extern char __stop_##name[] ABSL_ATTRIBUTE_WEAK
|
||||
#endif
|
||||
#ifndef ABSL_DEFINE_ATTRIBUTE_SECTION_VARS
|
||||
#define ABSL_INIT_ATTRIBUTE_SECTION_VARS(name)
|
||||
#define ABSL_DEFINE_ATTRIBUTE_SECTION_VARS(name)
|
||||
#endif
|
||||
|
||||
// ABSL_ATTRIBUTE_SECTION_START
|
||||
//
|
||||
// Returns `void*` pointers to start/end of a section of code with
|
||||
// functions having ABSL_ATTRIBUTE_SECTION(name).
|
||||
// Returns 0 if no such functions exist.
|
||||
// One must ABSL_DECLARE_ATTRIBUTE_SECTION_VARS(name) for this to compile and
|
||||
// link.
|
||||
//
|
||||
#define ABSL_ATTRIBUTE_SECTION_START(name) \
|
||||
(reinterpret_cast<void *>(__start_##name))
|
||||
#define ABSL_ATTRIBUTE_SECTION_STOP(name) \
|
||||
(reinterpret_cast<void *>(__stop_##name))
|
||||
|
||||
#else // !ABSL_HAVE_ATTRIBUTE_SECTION
|
||||
|
||||
#define ABSL_HAVE_ATTRIBUTE_SECTION 0
|
||||
|
||||
// provide dummy definitions
|
||||
#define ABSL_ATTRIBUTE_SECTION(name)
|
||||
#define ABSL_ATTRIBUTE_SECTION_VARIABLE(name)
|
||||
#define ABSL_INIT_ATTRIBUTE_SECTION_VARS(name)
|
||||
#define ABSL_DEFINE_ATTRIBUTE_SECTION_VARS(name)
|
||||
#define ABSL_DECLARE_ATTRIBUTE_SECTION_VARS(name)
|
||||
#define ABSL_ATTRIBUTE_SECTION_START(name) (reinterpret_cast<void *>(0))
|
||||
#define ABSL_ATTRIBUTE_SECTION_STOP(name) (reinterpret_cast<void *>(0))
|
||||
|
||||
#endif // ABSL_ATTRIBUTE_SECTION
|
||||
|
||||
// ABSL_ATTRIBUTE_STACK_ALIGN_FOR_OLD_LIBC
|
||||
//
|
||||
// Support for aligning the stack on 32-bit x86.
|
||||
#if ABSL_HAVE_ATTRIBUTE(force_align_arg_pointer) || \
|
||||
(defined(__GNUC__) && !defined(__clang__))
|
||||
#if defined(__i386__)
|
||||
#define ABSL_ATTRIBUTE_STACK_ALIGN_FOR_OLD_LIBC \
|
||||
__attribute__((force_align_arg_pointer))
|
||||
#define ABSL_REQUIRE_STACK_ALIGN_TRAMPOLINE (0)
|
||||
#elif defined(__x86_64__)
|
||||
#define ABSL_REQUIRE_STACK_ALIGN_TRAMPOLINE (1)
|
||||
#define ABSL_ATTRIBUTE_STACK_ALIGN_FOR_OLD_LIBC
|
||||
#else // !__i386__ && !__x86_64
|
||||
#define ABSL_REQUIRE_STACK_ALIGN_TRAMPOLINE (0)
|
||||
#define ABSL_ATTRIBUTE_STACK_ALIGN_FOR_OLD_LIBC
|
||||
#endif // __i386__
|
||||
#else
|
||||
#define ABSL_ATTRIBUTE_STACK_ALIGN_FOR_OLD_LIBC
|
||||
#define ABSL_REQUIRE_STACK_ALIGN_TRAMPOLINE (0)
|
||||
#endif
|
||||
|
||||
// ABSL_MUST_USE_RESULT
|
||||
//
|
||||
// Tells the compiler to warn about unused results.
|
||||
//
|
||||
// When annotating a function, it must appear as the first part of the
|
||||
// declaration or definition. The compiler will warn if the return value from
|
||||
// such a function is unused:
|
||||
//
|
||||
// ABSL_MUST_USE_RESULT Sprocket* AllocateSprocket();
|
||||
// AllocateSprocket(); // Triggers a warning.
|
||||
//
|
||||
// When annotating a class, it is equivalent to annotating every function which
|
||||
// returns an instance.
|
||||
//
|
||||
// class ABSL_MUST_USE_RESULT Sprocket {};
|
||||
// Sprocket(); // Triggers a warning.
|
||||
//
|
||||
// Sprocket MakeSprocket();
|
||||
// MakeSprocket(); // Triggers a warning.
|
||||
//
|
||||
// Note that references and pointers are not instances:
|
||||
//
|
||||
// Sprocket* SprocketPointer();
|
||||
// SprocketPointer(); // Does *not* trigger a warning.
|
||||
//
|
||||
// ABSL_MUST_USE_RESULT allows using cast-to-void to suppress the unused result
|
||||
// warning. For that, warn_unused_result is used only for clang but not for gcc.
|
||||
// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66425
|
||||
//
|
||||
// Note: past advice was to place the macro after the argument list.
|
||||
#if ABSL_HAVE_ATTRIBUTE(nodiscard)
|
||||
#define ABSL_MUST_USE_RESULT [[nodiscard]]
|
||||
#elif defined(__clang__) && ABSL_HAVE_ATTRIBUTE(warn_unused_result)
|
||||
#define ABSL_MUST_USE_RESULT __attribute__((warn_unused_result))
|
||||
#else
|
||||
#define ABSL_MUST_USE_RESULT
|
||||
#endif
|
||||
|
||||
// ABSL_ATTRIBUTE_HOT, ABSL_ATTRIBUTE_COLD
|
||||
//
|
||||
// Tells GCC that a function is hot or cold. GCC can use this information to
|
||||
// improve static analysis, i.e. a conditional branch to a cold function
|
||||
// is likely to be not-taken.
|
||||
// This annotation is used for function declarations.
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
// int foo() ABSL_ATTRIBUTE_HOT;
|
||||
#if ABSL_HAVE_ATTRIBUTE(hot) || (defined(__GNUC__) && !defined(__clang__))
|
||||
#define ABSL_ATTRIBUTE_HOT __attribute__((hot))
|
||||
#else
|
||||
#define ABSL_ATTRIBUTE_HOT
|
||||
#endif
|
||||
|
||||
#if ABSL_HAVE_ATTRIBUTE(cold) || (defined(__GNUC__) && !defined(__clang__))
|
||||
#define ABSL_ATTRIBUTE_COLD __attribute__((cold))
|
||||
#else
|
||||
#define ABSL_ATTRIBUTE_COLD
|
||||
#endif
|
||||
|
||||
// ABSL_XRAY_ALWAYS_INSTRUMENT, ABSL_XRAY_NEVER_INSTRUMENT, ABSL_XRAY_LOG_ARGS
|
||||
//
|
||||
// We define the ABSL_XRAY_ALWAYS_INSTRUMENT and ABSL_XRAY_NEVER_INSTRUMENT
|
||||
// macro used as an attribute to mark functions that must always or never be
|
||||
// instrumented by XRay. Currently, this is only supported in Clang/LLVM.
|
||||
//
|
||||
// For reference on the LLVM XRay instrumentation, see
|
||||
// http://llvm.org/docs/XRay.html.
|
||||
//
|
||||
// A function with the XRAY_ALWAYS_INSTRUMENT macro attribute in its declaration
|
||||
// will always get the XRay instrumentation sleds. These sleds may introduce
|
||||
// some binary size and runtime overhead and must be used sparingly.
|
||||
//
|
||||
// These attributes only take effect when the following conditions are met:
|
||||
//
|
||||
// * The file/target is built in at least C++11 mode, with a Clang compiler
|
||||
// that supports XRay attributes.
|
||||
// * The file/target is built with the -fxray-instrument flag set for the
|
||||
// Clang/LLVM compiler.
|
||||
// * The function is defined in the translation unit (the compiler honors the
|
||||
// attribute in either the definition or the declaration, and must match).
|
||||
//
|
||||
// There are cases when, even when building with XRay instrumentation, users
|
||||
// might want to control specifically which functions are instrumented for a
|
||||
// particular build using special-case lists provided to the compiler. These
|
||||
// special case lists are provided to Clang via the
|
||||
// -fxray-always-instrument=... and -fxray-never-instrument=... flags. The
|
||||
// attributes in source take precedence over these special-case lists.
|
||||
//
|
||||
// To disable the XRay attributes at build-time, users may define
|
||||
// ABSL_NO_XRAY_ATTRIBUTES. Do NOT define ABSL_NO_XRAY_ATTRIBUTES on specific
|
||||
// packages/targets, as this may lead to conflicting definitions of functions at
|
||||
// link-time.
|
||||
//
|
||||
// XRay isn't currently supported on Android:
|
||||
// https://github.com/android/ndk/issues/368
|
||||
#if ABSL_HAVE_CPP_ATTRIBUTE(clang::xray_always_instrument) && \
|
||||
!defined(ABSL_NO_XRAY_ATTRIBUTES) && !defined(__ANDROID__)
|
||||
#define ABSL_XRAY_ALWAYS_INSTRUMENT [[clang::xray_always_instrument]]
|
||||
#define ABSL_XRAY_NEVER_INSTRUMENT [[clang::xray_never_instrument]]
|
||||
#if ABSL_HAVE_CPP_ATTRIBUTE(clang::xray_log_args)
|
||||
#define ABSL_XRAY_LOG_ARGS(N) \
|
||||
[[clang::xray_always_instrument, clang::xray_log_args(N)]]
|
||||
#else
|
||||
#define ABSL_XRAY_LOG_ARGS(N) [[clang::xray_always_instrument]]
|
||||
#endif
|
||||
#else
|
||||
#define ABSL_XRAY_ALWAYS_INSTRUMENT
|
||||
#define ABSL_XRAY_NEVER_INSTRUMENT
|
||||
#define ABSL_XRAY_LOG_ARGS(N)
|
||||
#endif
|
||||
|
||||
// ABSL_ATTRIBUTE_REINITIALIZES
|
||||
//
|
||||
// Indicates that a member function reinitializes the entire object to a known
|
||||
// state, independent of the previous state of the object.
|
||||
//
|
||||
// The clang-tidy check bugprone-use-after-move allows member functions marked
|
||||
// with this attribute to be called on objects that have been moved from;
|
||||
// without the attribute, this would result in a use-after-move warning.
|
||||
#if ABSL_HAVE_CPP_ATTRIBUTE(clang::reinitializes)
|
||||
#define ABSL_ATTRIBUTE_REINITIALIZES [[clang::reinitializes]]
|
||||
#else
|
||||
#define ABSL_ATTRIBUTE_REINITIALIZES
|
||||
#endif
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Variable Attributes
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
// ABSL_ATTRIBUTE_UNUSED
|
||||
//
|
||||
// Prevents the compiler from complaining about variables that appear unused.
|
||||
//
|
||||
// For code or headers that are assured to only build with C++17 and up, prefer
|
||||
// just using the standard '[[maybe_unused]]' directly over this macro.
|
||||
//
|
||||
// Due to differences in positioning requirements between the old, compiler
|
||||
// specific __attribute__ syntax and the now standard [[maybe_unused]], this
|
||||
// macro does not attempt to take advantage of '[[maybe_unused]]'.
|
||||
#if ABSL_HAVE_ATTRIBUTE(unused) || (defined(__GNUC__) && !defined(__clang__))
|
||||
#undef ABSL_ATTRIBUTE_UNUSED
|
||||
#define ABSL_ATTRIBUTE_UNUSED __attribute__((__unused__))
|
||||
#else
|
||||
#define ABSL_ATTRIBUTE_UNUSED
|
||||
#endif
|
||||
|
||||
// ABSL_ATTRIBUTE_INITIAL_EXEC
|
||||
//
|
||||
// Tells the compiler to use "initial-exec" mode for a thread-local variable.
|
||||
// See http://people.redhat.com/drepper/tls.pdf for the gory details.
|
||||
#if ABSL_HAVE_ATTRIBUTE(tls_model) || (defined(__GNUC__) && !defined(__clang__))
|
||||
#define ABSL_ATTRIBUTE_INITIAL_EXEC __attribute__((tls_model("initial-exec")))
|
||||
#else
|
||||
#define ABSL_ATTRIBUTE_INITIAL_EXEC
|
||||
#endif
|
||||
|
||||
// ABSL_ATTRIBUTE_PACKED
|
||||
//
|
||||
// Instructs the compiler not to use natural alignment for a tagged data
|
||||
// structure, but instead to reduce its alignment to 1. This attribute can
|
||||
// either be applied to members of a structure or to a structure in its
|
||||
// entirety. Applying this attribute (judiciously) to a structure in its
|
||||
// entirety to optimize the memory footprint of very commonly-used structs is
|
||||
// fine. Do not apply this attribute to a structure in its entirety if the
|
||||
// purpose is to control the offsets of the members in the structure. Instead,
|
||||
// apply this attribute only to structure members that need it.
|
||||
//
|
||||
// When applying ABSL_ATTRIBUTE_PACKED only to specific structure members the
|
||||
// natural alignment of structure members not annotated is preserved. Aligned
|
||||
// member accesses are faster than non-aligned member accesses even if the
|
||||
// targeted microprocessor supports non-aligned accesses.
|
||||
#if ABSL_HAVE_ATTRIBUTE(packed) || (defined(__GNUC__) && !defined(__clang__))
|
||||
#define ABSL_ATTRIBUTE_PACKED __attribute__((__packed__))
|
||||
#else
|
||||
#define ABSL_ATTRIBUTE_PACKED
|
||||
#endif
|
||||
|
||||
// ABSL_ATTRIBUTE_FUNC_ALIGN
|
||||
//
|
||||
// Tells the compiler to align the function start at least to certain
|
||||
// alignment boundary
|
||||
#if ABSL_HAVE_ATTRIBUTE(aligned) || (defined(__GNUC__) && !defined(__clang__))
|
||||
#define ABSL_ATTRIBUTE_FUNC_ALIGN(bytes) __attribute__((aligned(bytes)))
|
||||
#else
|
||||
#define ABSL_ATTRIBUTE_FUNC_ALIGN(bytes)
|
||||
#endif
|
||||
|
||||
// ABSL_FALLTHROUGH_INTENDED
|
||||
//
|
||||
// Annotates implicit fall-through between switch labels, allowing a case to
|
||||
// indicate intentional fallthrough and turn off warnings about any lack of a
|
||||
// `break` statement. The ABSL_FALLTHROUGH_INTENDED macro should be followed by
|
||||
// a semicolon and can be used in most places where `break` can, provided that
|
||||
// no statements exist between it and the next switch label.
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
// switch (x) {
|
||||
// case 40:
|
||||
// case 41:
|
||||
// if (truth_is_out_there) {
|
||||
// ++x;
|
||||
// ABSL_FALLTHROUGH_INTENDED; // Use instead of/along with annotations
|
||||
// // in comments
|
||||
// } else {
|
||||
// return x;
|
||||
// }
|
||||
// case 42:
|
||||
// ...
|
||||
//
|
||||
// Notes: When supported, GCC and Clang can issue a warning on switch labels
|
||||
// with unannotated fallthrough using the warning `-Wimplicit-fallthrough`. See
|
||||
// clang documentation on language extensions for details:
|
||||
// https://clang.llvm.org/docs/AttributeReference.html#fallthrough-clang-fallthrough
|
||||
//
|
||||
// When used with unsupported compilers, the ABSL_FALLTHROUGH_INTENDED macro has
|
||||
// no effect on diagnostics. In any case this macro has no effect on runtime
|
||||
// behavior and performance of code.
|
||||
|
||||
#ifdef ABSL_FALLTHROUGH_INTENDED
|
||||
#error "ABSL_FALLTHROUGH_INTENDED should not be defined."
|
||||
#elif ABSL_HAVE_CPP_ATTRIBUTE(fallthrough)
|
||||
#define ABSL_FALLTHROUGH_INTENDED [[fallthrough]]
|
||||
#elif ABSL_HAVE_CPP_ATTRIBUTE(clang::fallthrough)
|
||||
#define ABSL_FALLTHROUGH_INTENDED [[clang::fallthrough]]
|
||||
#elif ABSL_HAVE_CPP_ATTRIBUTE(gnu::fallthrough)
|
||||
#define ABSL_FALLTHROUGH_INTENDED [[gnu::fallthrough]]
|
||||
#else
|
||||
#define ABSL_FALLTHROUGH_INTENDED \
|
||||
do { \
|
||||
} while (0)
|
||||
#endif
|
||||
|
||||
// ABSL_DEPRECATED()
|
||||
//
|
||||
// Marks a deprecated class, struct, enum, function, method and variable
|
||||
// declarations. The macro argument is used as a custom diagnostic message (e.g.
|
||||
// suggestion of a better alternative).
|
||||
//
|
||||
// Examples:
|
||||
//
|
||||
// class ABSL_DEPRECATED("Use Bar instead") Foo {...};
|
||||
//
|
||||
// ABSL_DEPRECATED("Use Baz() instead") void Bar() {...}
|
||||
//
|
||||
// template <typename T>
|
||||
// ABSL_DEPRECATED("Use DoThat() instead")
|
||||
// void DoThis();
|
||||
//
|
||||
// Every usage of a deprecated entity will trigger a warning when compiled with
|
||||
// clang's `-Wdeprecated-declarations` option. This option is turned off by
|
||||
// default, but the warnings will be reported by clang-tidy.
|
||||
#if defined(__clang__) && defined(__cplusplus) && __cplusplus >= 201103L
|
||||
#define ABSL_DEPRECATED(message) __attribute__((deprecated(message)))
|
||||
#endif
|
||||
|
||||
#ifndef ABSL_DEPRECATED
|
||||
#define ABSL_DEPRECATED(message)
|
||||
#endif
|
||||
|
||||
// ABSL_CONST_INIT
|
||||
//
|
||||
// A variable declaration annotated with the `ABSL_CONST_INIT` attribute will
|
||||
// not compile (on supported platforms) unless the variable has a constant
|
||||
// initializer. This is useful for variables with static and thread storage
|
||||
// duration, because it guarantees that they will not suffer from the so-called
|
||||
// "static init order fiasco". Prefer to put this attribute on the most visible
|
||||
// declaration of the variable, if there's more than one, because code that
|
||||
// accesses the variable can then use the attribute for optimization.
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
// class MyClass {
|
||||
// public:
|
||||
// ABSL_CONST_INIT static MyType my_var;
|
||||
// };
|
||||
//
|
||||
// MyType MyClass::my_var = MakeMyType(...);
|
||||
//
|
||||
// Note that this attribute is redundant if the variable is declared constexpr.
|
||||
#if ABSL_HAVE_CPP_ATTRIBUTE(clang::require_constant_initialization)
|
||||
#define ABSL_CONST_INIT [[clang::require_constant_initialization]]
|
||||
#else
|
||||
#define ABSL_CONST_INIT
|
||||
#endif // ABSL_HAVE_CPP_ATTRIBUTE(clang::require_constant_initialization)
|
||||
|
||||
// ABSL_ATTRIBUTE_PURE_FUNCTION
|
||||
//
|
||||
// ABSL_ATTRIBUTE_PURE_FUNCTION is used to annotate declarations of "pure"
|
||||
// functions. A function is pure if its return value is only a function of its
|
||||
// arguments. The pure attribute prohibits a function from modifying the state
|
||||
// of the program that is observable by means other than inspecting the
|
||||
// function's return value. Declaring such functions with the pure attribute
|
||||
// allows the compiler to avoid emitting some calls in repeated invocations of
|
||||
// the function with the same argument values.
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
// ABSL_ATTRIBUTE_PURE_FUNCTION int64_t ToInt64Milliseconds(Duration d);
|
||||
#if ABSL_HAVE_CPP_ATTRIBUTE(gnu::pure)
|
||||
#define ABSL_ATTRIBUTE_PURE_FUNCTION [[gnu::pure]]
|
||||
#elif ABSL_HAVE_ATTRIBUTE(pure)
|
||||
#define ABSL_ATTRIBUTE_PURE_FUNCTION __attribute__((pure))
|
||||
#else
|
||||
#define ABSL_ATTRIBUTE_PURE_FUNCTION
|
||||
#endif
|
||||
|
||||
// ABSL_ATTRIBUTE_LIFETIME_BOUND indicates that a resource owned by a function
|
||||
// parameter or implicit object parameter is retained by the return value of the
|
||||
// annotated function (or, for a parameter of a constructor, in the value of the
|
||||
// constructed object). This attribute causes warnings to be produced if a
|
||||
// temporary object does not live long enough.
|
||||
//
|
||||
// When applied to a reference parameter, the referenced object is assumed to be
|
||||
// retained by the return value of the function. When applied to a non-reference
|
||||
// parameter (for example, a pointer or a class type), all temporaries
|
||||
// referenced by the parameter are assumed to be retained by the return value of
|
||||
// the function.
|
||||
//
|
||||
// See also the upstream documentation:
|
||||
// https://clang.llvm.org/docs/AttributeReference.html#lifetimebound
|
||||
#if ABSL_HAVE_CPP_ATTRIBUTE(clang::lifetimebound)
|
||||
#define ABSL_ATTRIBUTE_LIFETIME_BOUND [[clang::lifetimebound]]
|
||||
#elif ABSL_HAVE_ATTRIBUTE(lifetimebound)
|
||||
#define ABSL_ATTRIBUTE_LIFETIME_BOUND __attribute__((lifetimebound))
|
||||
#else
|
||||
#define ABSL_ATTRIBUTE_LIFETIME_BOUND
|
||||
#endif
|
||||
|
||||
#endif // ABSL_BASE_ATTRIBUTES_H_
|
745
extern/int128/absl/base/config.h
vendored
Normal file
745
extern/int128/absl/base/config.h
vendored
Normal file
@ -0,0 +1,745 @@
|
||||
//
|
||||
// Copyright 2017 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.
|
||||
//
|
||||
// -----------------------------------------------------------------------------
|
||||
// File: config.h
|
||||
// -----------------------------------------------------------------------------
|
||||
//
|
||||
// This header file defines a set of macros for checking the presence of
|
||||
// important compiler and platform features. Such macros can be used to
|
||||
// produce portable code by parameterizing compilation based on the presence or
|
||||
// lack of a given feature.
|
||||
//
|
||||
// We define a "feature" as some interface we wish to program to: for example,
|
||||
// a library function or system call. A value of `1` indicates support for
|
||||
// that feature; any other value indicates the feature support is undefined.
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
// Suppose a programmer wants to write a program that uses the 'mmap()' system
|
||||
// call. The Abseil macro for that feature (`ABSL_HAVE_MMAP`) allows you to
|
||||
// selectively include the `mmap.h` header and bracket code using that feature
|
||||
// in the macro:
|
||||
//
|
||||
// #include "absl/base/config.h"
|
||||
//
|
||||
// #ifdef ABSL_HAVE_MMAP
|
||||
// #include "sys/mman.h"
|
||||
// #endif //ABSL_HAVE_MMAP
|
||||
//
|
||||
// ...
|
||||
// #ifdef ABSL_HAVE_MMAP
|
||||
// void *ptr = mmap(...);
|
||||
// ...
|
||||
// #endif // ABSL_HAVE_MMAP
|
||||
|
||||
#ifndef ABSL_BASE_CONFIG_H_
|
||||
#define ABSL_BASE_CONFIG_H_
|
||||
|
||||
// Included for the __GLIBC__ macro (or similar macros on other systems).
|
||||
#include <limits.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
// Included for __GLIBCXX__, _LIBCPP_VERSION
|
||||
#include <cstddef>
|
||||
#endif // __cplusplus
|
||||
|
||||
#if defined(__APPLE__)
|
||||
// Included for TARGET_OS_IPHONE, __IPHONE_OS_VERSION_MIN_REQUIRED,
|
||||
// __IPHONE_8_0.
|
||||
#include <Availability.h>
|
||||
#include <TargetConditionals.h>
|
||||
#endif
|
||||
|
||||
#include "absl/base/options.h"
|
||||
#include "absl/base/policy_checks.h"
|
||||
|
||||
// Helper macro to convert a CPP variable to a string literal.
|
||||
#define ABSL_INTERNAL_DO_TOKEN_STR(x) #x
|
||||
#define ABSL_INTERNAL_TOKEN_STR(x) ABSL_INTERNAL_DO_TOKEN_STR(x)
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Abseil namespace annotations
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
// ABSL_NAMESPACE_BEGIN/ABSL_NAMESPACE_END
|
||||
//
|
||||
// An annotation placed at the beginning/end of each `namespace absl` scope.
|
||||
// This is used to inject an inline namespace.
|
||||
//
|
||||
// The proper way to write Abseil code in the `absl` namespace is:
|
||||
//
|
||||
// namespace absl {
|
||||
// ABSL_NAMESPACE_BEGIN
|
||||
//
|
||||
// void Foo(); // absl::Foo().
|
||||
//
|
||||
// ABSL_NAMESPACE_END
|
||||
// } // namespace absl
|
||||
//
|
||||
// Users of Abseil should not use these macros, because users of Abseil should
|
||||
// not write `namespace absl {` in their own code for any reason. (Abseil does
|
||||
// not support forward declarations of its own types, nor does it support
|
||||
// user-provided specialization of Abseil templates. Code that violates these
|
||||
// rules may be broken without warning.)
|
||||
#if !defined(ABSL_OPTION_USE_INLINE_NAMESPACE) || \
|
||||
!defined(ABSL_OPTION_INLINE_NAMESPACE_NAME)
|
||||
#error options.h is misconfigured.
|
||||
#endif
|
||||
|
||||
// Check that ABSL_OPTION_INLINE_NAMESPACE_NAME is neither "head" nor ""
|
||||
#if defined(__cplusplus) && ABSL_OPTION_USE_INLINE_NAMESPACE == 1
|
||||
|
||||
#define ABSL_INTERNAL_INLINE_NAMESPACE_STR \
|
||||
ABSL_INTERNAL_TOKEN_STR(ABSL_OPTION_INLINE_NAMESPACE_NAME)
|
||||
|
||||
static_assert(ABSL_INTERNAL_INLINE_NAMESPACE_STR[0] != '\0',
|
||||
"options.h misconfigured: ABSL_OPTION_INLINE_NAMESPACE_NAME must "
|
||||
"not be empty.");
|
||||
static_assert(ABSL_INTERNAL_INLINE_NAMESPACE_STR[0] != 'h' ||
|
||||
ABSL_INTERNAL_INLINE_NAMESPACE_STR[1] != 'e' ||
|
||||
ABSL_INTERNAL_INLINE_NAMESPACE_STR[2] != 'a' ||
|
||||
ABSL_INTERNAL_INLINE_NAMESPACE_STR[3] != 'd' ||
|
||||
ABSL_INTERNAL_INLINE_NAMESPACE_STR[4] != '\0',
|
||||
"options.h misconfigured: ABSL_OPTION_INLINE_NAMESPACE_NAME must "
|
||||
"be changed to a new, unique identifier name.");
|
||||
|
||||
#endif
|
||||
|
||||
#if ABSL_OPTION_USE_INLINE_NAMESPACE == 0
|
||||
#define ABSL_NAMESPACE_BEGIN
|
||||
#define ABSL_NAMESPACE_END
|
||||
#define ABSL_INTERNAL_C_SYMBOL(x) x
|
||||
#elif ABSL_OPTION_USE_INLINE_NAMESPACE == 1
|
||||
#define ABSL_NAMESPACE_BEGIN \
|
||||
inline namespace ABSL_OPTION_INLINE_NAMESPACE_NAME {
|
||||
#define ABSL_NAMESPACE_END }
|
||||
#define ABSL_INTERNAL_C_SYMBOL_HELPER_2(x, v) x##_##v
|
||||
#define ABSL_INTERNAL_C_SYMBOL_HELPER_1(x, v) \
|
||||
ABSL_INTERNAL_C_SYMBOL_HELPER_2(x, v)
|
||||
#define ABSL_INTERNAL_C_SYMBOL(x) \
|
||||
ABSL_INTERNAL_C_SYMBOL_HELPER_1(x, ABSL_OPTION_INLINE_NAMESPACE_NAME)
|
||||
#else
|
||||
#error options.h is misconfigured.
|
||||
#endif
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Compiler Feature Checks
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
// ABSL_HAVE_BUILTIN()
|
||||
//
|
||||
// Checks whether the compiler supports a Clang Feature Checking Macro, and if
|
||||
// so, checks whether it supports the provided builtin function "x" where x
|
||||
// is one of the functions noted in
|
||||
// https://clang.llvm.org/docs/LanguageExtensions.html
|
||||
//
|
||||
// Note: Use this macro to avoid an extra level of #ifdef __has_builtin check.
|
||||
// http://releases.llvm.org/3.3/tools/clang/docs/LanguageExtensions.html
|
||||
#ifdef __has_builtin
|
||||
#define ABSL_HAVE_BUILTIN(x) __has_builtin(x)
|
||||
#else
|
||||
#define ABSL_HAVE_BUILTIN(x) 0
|
||||
#endif
|
||||
|
||||
#if defined(__is_identifier)
|
||||
#define ABSL_INTERNAL_HAS_KEYWORD(x) !(__is_identifier(x))
|
||||
#else
|
||||
#define ABSL_INTERNAL_HAS_KEYWORD(x) 0
|
||||
#endif
|
||||
|
||||
#ifdef __has_feature
|
||||
#define ABSL_HAVE_FEATURE(f) __has_feature(f)
|
||||
#else
|
||||
#define ABSL_HAVE_FEATURE(f) 0
|
||||
#endif
|
||||
|
||||
// Portable check for GCC minimum version:
|
||||
// https://gcc.gnu.org/onlinedocs/cpp/Common-Predefined-Macros.html
|
||||
#if defined(__GNUC__) && defined(__GNUC_MINOR__)
|
||||
#define ABSL_INTERNAL_HAVE_MIN_GNUC_VERSION(x, y) \
|
||||
(__GNUC__ > (x) || __GNUC__ == (x) && __GNUC_MINOR__ >= (y))
|
||||
#else
|
||||
#define ABSL_INTERNAL_HAVE_MIN_GNUC_VERSION(x, y) 0
|
||||
#endif
|
||||
|
||||
#if defined(__clang__) && defined(__clang_major__) && defined(__clang_minor__)
|
||||
#define ABSL_INTERNAL_HAVE_MIN_CLANG_VERSION(x, y) \
|
||||
(__clang_major__ > (x) || __clang_major__ == (x) && __clang_minor__ >= (y))
|
||||
#else
|
||||
#define ABSL_INTERNAL_HAVE_MIN_CLANG_VERSION(x, y) 0
|
||||
#endif
|
||||
|
||||
// ABSL_HAVE_TLS is defined to 1 when __thread should be supported.
|
||||
// We assume __thread is supported on Linux when compiled with Clang or compiled
|
||||
// against libstdc++ with _GLIBCXX_HAVE_TLS defined.
|
||||
#ifdef ABSL_HAVE_TLS
|
||||
#error ABSL_HAVE_TLS cannot be directly set
|
||||
#elif defined(__linux__) && (defined(__clang__) || defined(_GLIBCXX_HAVE_TLS))
|
||||
#define ABSL_HAVE_TLS 1
|
||||
#endif
|
||||
|
||||
// ABSL_HAVE_STD_IS_TRIVIALLY_DESTRUCTIBLE
|
||||
//
|
||||
// Checks whether `std::is_trivially_destructible<T>` is supported.
|
||||
//
|
||||
// Notes: All supported compilers using libc++ support this feature, as does
|
||||
// gcc >= 4.8.1 using libstdc++, and Visual Studio.
|
||||
#ifdef ABSL_HAVE_STD_IS_TRIVIALLY_DESTRUCTIBLE
|
||||
#error ABSL_HAVE_STD_IS_TRIVIALLY_DESTRUCTIBLE cannot be directly set
|
||||
#elif defined(_LIBCPP_VERSION) || defined(_MSC_VER) || \
|
||||
(!defined(__clang__) && defined(__GLIBCXX__) && \
|
||||
ABSL_INTERNAL_HAVE_MIN_GNUC_VERSION(4, 8))
|
||||
#define ABSL_HAVE_STD_IS_TRIVIALLY_DESTRUCTIBLE 1
|
||||
#endif
|
||||
|
||||
// ABSL_HAVE_STD_IS_TRIVIALLY_CONSTRUCTIBLE
|
||||
//
|
||||
// Checks whether `std::is_trivially_default_constructible<T>` and
|
||||
// `std::is_trivially_copy_constructible<T>` are supported.
|
||||
|
||||
// ABSL_HAVE_STD_IS_TRIVIALLY_ASSIGNABLE
|
||||
//
|
||||
// Checks whether `std::is_trivially_copy_assignable<T>` is supported.
|
||||
|
||||
// Notes: Clang with libc++ supports these features, as does gcc >= 5.1 with
|
||||
// either libc++ or libstdc++, and Visual Studio (but not NVCC).
|
||||
#if defined(ABSL_HAVE_STD_IS_TRIVIALLY_CONSTRUCTIBLE)
|
||||
#error ABSL_HAVE_STD_IS_TRIVIALLY_CONSTRUCTIBLE cannot be directly set
|
||||
#elif defined(ABSL_HAVE_STD_IS_TRIVIALLY_ASSIGNABLE)
|
||||
#error ABSL_HAVE_STD_IS_TRIVIALLY_ASSIGNABLE cannot directly set
|
||||
#elif (defined(__clang__) && defined(_LIBCPP_VERSION)) || \
|
||||
(!defined(__clang__) && ABSL_INTERNAL_HAVE_MIN_GNUC_VERSION(7, 4) && \
|
||||
(defined(_LIBCPP_VERSION) || defined(__GLIBCXX__))) || \
|
||||
(defined(_MSC_VER) && !defined(__NVCC__))
|
||||
#define ABSL_HAVE_STD_IS_TRIVIALLY_CONSTRUCTIBLE 1
|
||||
#define ABSL_HAVE_STD_IS_TRIVIALLY_ASSIGNABLE 1
|
||||
#endif
|
||||
|
||||
// ABSL_HAVE_SOURCE_LOCATION_CURRENT
|
||||
//
|
||||
// Indicates whether `absl::SourceLocation::current()` will return useful
|
||||
// information in some contexts.
|
||||
#ifndef ABSL_HAVE_SOURCE_LOCATION_CURRENT
|
||||
#if ABSL_INTERNAL_HAS_KEYWORD(__builtin_LINE) && \
|
||||
ABSL_INTERNAL_HAS_KEYWORD(__builtin_FILE)
|
||||
#define ABSL_HAVE_SOURCE_LOCATION_CURRENT 1
|
||||
#elif ABSL_INTERNAL_HAVE_MIN_GNUC_VERSION(5, 0)
|
||||
#define ABSL_HAVE_SOURCE_LOCATION_CURRENT 1
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// ABSL_HAVE_THREAD_LOCAL
|
||||
//
|
||||
// Checks whether C++11's `thread_local` storage duration specifier is
|
||||
// supported.
|
||||
#ifdef ABSL_HAVE_THREAD_LOCAL
|
||||
#error ABSL_HAVE_THREAD_LOCAL cannot be directly set
|
||||
#elif defined(__APPLE__)
|
||||
// Notes:
|
||||
// * Xcode's clang did not support `thread_local` until version 8, and
|
||||
// even then not for all iOS < 9.0.
|
||||
// * Xcode 9.3 started disallowing `thread_local` for 32-bit iOS simulator
|
||||
// targeting iOS 9.x.
|
||||
// * Xcode 10 moves the deployment target check for iOS < 9.0 to link time
|
||||
// making ABSL_HAVE_FEATURE unreliable there.
|
||||
//
|
||||
#if ABSL_HAVE_FEATURE(cxx_thread_local) && \
|
||||
!(TARGET_OS_IPHONE && __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_9_0)
|
||||
#define ABSL_HAVE_THREAD_LOCAL 1
|
||||
#endif
|
||||
#else // !defined(__APPLE__)
|
||||
#define ABSL_HAVE_THREAD_LOCAL 1
|
||||
#endif
|
||||
|
||||
// There are platforms for which TLS should not be used even though the compiler
|
||||
// makes it seem like it's supported (Android NDK < r12b for example).
|
||||
// This is primarily because of linker problems and toolchain misconfiguration:
|
||||
// Abseil does not intend to support this indefinitely. Currently, the newest
|
||||
// toolchain that we intend to support that requires this behavior is the
|
||||
// r11 NDK - allowing for a 5 year support window on that means this option
|
||||
// is likely to be removed around June of 2021.
|
||||
// TLS isn't supported until NDK r12b per
|
||||
// https://developer.android.com/ndk/downloads/revision_history.html
|
||||
// Since NDK r16, `__NDK_MAJOR__` and `__NDK_MINOR__` are defined in
|
||||
// <android/ndk-version.h>. For NDK < r16, users should define these macros,
|
||||
// e.g. `-D__NDK_MAJOR__=11 -D__NKD_MINOR__=0` for NDK r11.
|
||||
#if defined(__ANDROID__) && defined(__clang__)
|
||||
#if __has_include(<android/ndk-version.h>)
|
||||
#include <android/ndk-version.h>
|
||||
#endif // __has_include(<android/ndk-version.h>)
|
||||
#if defined(__ANDROID__) && defined(__clang__) && defined(__NDK_MAJOR__) && \
|
||||
defined(__NDK_MINOR__) && \
|
||||
((__NDK_MAJOR__ < 12) || ((__NDK_MAJOR__ == 12) && (__NDK_MINOR__ < 1)))
|
||||
#undef ABSL_HAVE_TLS
|
||||
#undef ABSL_HAVE_THREAD_LOCAL
|
||||
#endif
|
||||
#endif // defined(__ANDROID__) && defined(__clang__)
|
||||
|
||||
// ABSL_HAVE_INTRINSIC_INT128
|
||||
//
|
||||
// Checks whether the __int128 compiler extension for a 128-bit integral type is
|
||||
// supported.
|
||||
//
|
||||
// Note: __SIZEOF_INT128__ is defined by Clang and GCC when __int128 is
|
||||
// supported, but we avoid using it in certain cases:
|
||||
// * On Clang:
|
||||
// * Building using Clang for Windows, where the Clang runtime library has
|
||||
// 128-bit support only on LP64 architectures, but Windows is LLP64.
|
||||
// * On Nvidia's nvcc:
|
||||
// * nvcc also defines __GNUC__ and __SIZEOF_INT128__, but not all versions
|
||||
// actually support __int128.
|
||||
|
||||
/* Unfortunately FB does not support alignment requirements (16) in ODS
|
||||
|
||||
#ifdef ABSL_HAVE_INTRINSIC_INT128
|
||||
#error ABSL_HAVE_INTRINSIC_INT128 cannot be directly set
|
||||
#elif defined(__SIZEOF_INT128__)
|
||||
#if (defined(__clang__) && !defined(_WIN32)) || \
|
||||
(defined(__CUDACC__) && __CUDACC_VER_MAJOR__ >= 9) || \
|
||||
(defined(__GNUC__) && !defined(__clang__) && !defined(__CUDACC__))
|
||||
#define ABSL_HAVE_INTRINSIC_INT128 1
|
||||
#elif defined(__CUDACC__)
|
||||
// __CUDACC_VER__ is a full version number before CUDA 9, and is defined to a
|
||||
// string explaining that it has been removed starting with CUDA 9. We use
|
||||
// nested #ifs because there is no short-circuiting in the preprocessor.
|
||||
// NOTE: `__CUDACC__` could be undefined while `__CUDACC_VER__` is defined.
|
||||
#if __CUDACC_VER__ >= 70000
|
||||
#define ABSL_HAVE_INTRINSIC_INT128 1
|
||||
#endif // __CUDACC_VER__ >= 70000
|
||||
#endif // defined(__CUDACC__)
|
||||
#endif // ABSL_HAVE_INTRINSIC_INT128
|
||||
*/
|
||||
#undef ABSL_HAVE_INTRINSIC_INT128
|
||||
|
||||
// ABSL_HAVE_EXCEPTIONS
|
||||
//
|
||||
// Checks whether the compiler both supports and enables exceptions. Many
|
||||
// compilers support a "no exceptions" mode that disables exceptions.
|
||||
//
|
||||
// Generally, when ABSL_HAVE_EXCEPTIONS is not defined:
|
||||
//
|
||||
// * Code using `throw` and `try` may not compile.
|
||||
// * The `noexcept` specifier will still compile and behave as normal.
|
||||
// * The `noexcept` operator may still return `false`.
|
||||
//
|
||||
// For further details, consult the compiler's documentation.
|
||||
#ifdef ABSL_HAVE_EXCEPTIONS
|
||||
#error ABSL_HAVE_EXCEPTIONS cannot be directly set.
|
||||
#elif ABSL_INTERNAL_HAVE_MIN_CLANG_VERSION(3, 6)
|
||||
// Clang >= 3.6
|
||||
#if ABSL_HAVE_FEATURE(cxx_exceptions)
|
||||
#define ABSL_HAVE_EXCEPTIONS 1
|
||||
#endif // ABSL_HAVE_FEATURE(cxx_exceptions)
|
||||
#elif defined(__clang__)
|
||||
// Clang < 3.6
|
||||
// http://releases.llvm.org/3.6.0/tools/clang/docs/ReleaseNotes.html#the-exceptions-macro
|
||||
#if defined(__EXCEPTIONS) && ABSL_HAVE_FEATURE(cxx_exceptions)
|
||||
#define ABSL_HAVE_EXCEPTIONS 1
|
||||
#endif // defined(__EXCEPTIONS) && ABSL_HAVE_FEATURE(cxx_exceptions)
|
||||
// Handle remaining special cases and default to exceptions being supported.
|
||||
#elif !(defined(__GNUC__) && (__GNUC__ < 5) && !defined(__EXCEPTIONS)) && \
|
||||
!(ABSL_INTERNAL_HAVE_MIN_GNUC_VERSION(5, 0) && \
|
||||
!defined(__cpp_exceptions)) && \
|
||||
!(defined(_MSC_VER) && !defined(_CPPUNWIND))
|
||||
#define ABSL_HAVE_EXCEPTIONS 1
|
||||
#endif
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Platform Feature Checks
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
// Currently supported operating systems and associated preprocessor
|
||||
// symbols:
|
||||
//
|
||||
// Linux and Linux-derived __linux__
|
||||
// Android __ANDROID__ (implies __linux__)
|
||||
// Linux (non-Android) __linux__ && !__ANDROID__
|
||||
// Darwin (macOS and iOS) __APPLE__
|
||||
// Akaros (http://akaros.org) __ros__
|
||||
// Windows _WIN32
|
||||
// NaCL __native_client__
|
||||
// AsmJS __asmjs__
|
||||
// WebAssembly __wasm__
|
||||
// Fuchsia __Fuchsia__
|
||||
//
|
||||
// Note that since Android defines both __ANDROID__ and __linux__, one
|
||||
// may probe for either Linux or Android by simply testing for __linux__.
|
||||
|
||||
// ABSL_HAVE_MMAP
|
||||
//
|
||||
// Checks whether the platform has an mmap(2) implementation as defined in
|
||||
// POSIX.1-2001.
|
||||
#ifdef ABSL_HAVE_MMAP
|
||||
#error ABSL_HAVE_MMAP cannot be directly set
|
||||
#elif defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__) || \
|
||||
defined(__ros__) || defined(__native_client__) || defined(__asmjs__) || \
|
||||
defined(__wasm__) || defined(__Fuchsia__) || defined(__sun) || \
|
||||
defined(__ASYLO__) || defined(__myriad2__)
|
||||
#define ABSL_HAVE_MMAP 1
|
||||
#endif
|
||||
|
||||
// ABSL_HAVE_PTHREAD_GETSCHEDPARAM
|
||||
//
|
||||
// Checks whether the platform implements the pthread_(get|set)schedparam(3)
|
||||
// functions as defined in POSIX.1-2001.
|
||||
#ifdef ABSL_HAVE_PTHREAD_GETSCHEDPARAM
|
||||
#error ABSL_HAVE_PTHREAD_GETSCHEDPARAM cannot be directly set
|
||||
#elif defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__) || \
|
||||
defined(__ros__)
|
||||
#define ABSL_HAVE_PTHREAD_GETSCHEDPARAM 1
|
||||
#endif
|
||||
|
||||
// ABSL_HAVE_SCHED_GETCPU
|
||||
//
|
||||
// Checks whether sched_getcpu is available.
|
||||
#ifdef ABSL_HAVE_SCHED_GETCPU
|
||||
#error ABSL_HAVE_SCHED_GETCPU cannot be directly set
|
||||
#elif defined(__linux__)
|
||||
#define ABSL_HAVE_SCHED_GETCPU 1
|
||||
#endif
|
||||
|
||||
// ABSL_HAVE_SCHED_YIELD
|
||||
//
|
||||
// Checks whether the platform implements sched_yield(2) as defined in
|
||||
// POSIX.1-2001.
|
||||
#ifdef ABSL_HAVE_SCHED_YIELD
|
||||
#error ABSL_HAVE_SCHED_YIELD cannot be directly set
|
||||
#elif defined(__linux__) || defined(__ros__) || defined(__native_client__)
|
||||
#define ABSL_HAVE_SCHED_YIELD 1
|
||||
#endif
|
||||
|
||||
// ABSL_HAVE_SEMAPHORE_H
|
||||
//
|
||||
// Checks whether the platform supports the <semaphore.h> header and sem_init(3)
|
||||
// family of functions as standardized in POSIX.1-2001.
|
||||
//
|
||||
// Note: While Apple provides <semaphore.h> for both iOS and macOS, it is
|
||||
// explicitly deprecated and will cause build failures if enabled for those
|
||||
// platforms. We side-step the issue by not defining it here for Apple
|
||||
// platforms.
|
||||
#ifdef ABSL_HAVE_SEMAPHORE_H
|
||||
#error ABSL_HAVE_SEMAPHORE_H cannot be directly set
|
||||
#elif defined(__linux__) || defined(__ros__)
|
||||
#define ABSL_HAVE_SEMAPHORE_H 1
|
||||
#endif
|
||||
|
||||
// ABSL_HAVE_ALARM
|
||||
//
|
||||
// Checks whether the platform supports the <signal.h> header and alarm(2)
|
||||
// function as standardized in POSIX.1-2001.
|
||||
#ifdef ABSL_HAVE_ALARM
|
||||
#error ABSL_HAVE_ALARM cannot be directly set
|
||||
#elif defined(__GOOGLE_GRTE_VERSION__)
|
||||
// feature tests for Google's GRTE
|
||||
#define ABSL_HAVE_ALARM 1
|
||||
#elif defined(__GLIBC__)
|
||||
// feature test for glibc
|
||||
#define ABSL_HAVE_ALARM 1
|
||||
#elif defined(_MSC_VER)
|
||||
// feature tests for Microsoft's library
|
||||
#elif defined(__MINGW32__)
|
||||
// mingw32 doesn't provide alarm(2):
|
||||
// https://osdn.net/projects/mingw/scm/git/mingw-org-wsl/blobs/5.2-trunk/mingwrt/include/unistd.h
|
||||
// mingw-w64 provides a no-op implementation:
|
||||
// https://sourceforge.net/p/mingw-w64/mingw-w64/ci/master/tree/mingw-w64-crt/misc/alarm.c
|
||||
#elif defined(__EMSCRIPTEN__)
|
||||
// emscripten doesn't support signals
|
||||
#elif defined(__Fuchsia__)
|
||||
// Signals don't exist on fuchsia.
|
||||
#elif defined(__native_client__)
|
||||
#else
|
||||
// other standard libraries
|
||||
#define ABSL_HAVE_ALARM 1
|
||||
#endif
|
||||
|
||||
// ABSL_IS_LITTLE_ENDIAN
|
||||
// ABSL_IS_BIG_ENDIAN
|
||||
//
|
||||
// Checks the endianness of the platform.
|
||||
//
|
||||
// Notes: uses the built in endian macros provided by GCC (since 4.6) and
|
||||
// Clang (since 3.2); see
|
||||
// https://gcc.gnu.org/onlinedocs/cpp/Common-Predefined-Macros.html.
|
||||
// Otherwise, if _WIN32, assume little endian. Otherwise, bail with an error.
|
||||
#if defined(ABSL_IS_BIG_ENDIAN)
|
||||
#error "ABSL_IS_BIG_ENDIAN cannot be directly set."
|
||||
#endif
|
||||
#if defined(ABSL_IS_LITTLE_ENDIAN)
|
||||
#error "ABSL_IS_LITTLE_ENDIAN cannot be directly set."
|
||||
#endif
|
||||
|
||||
#if (defined(__BYTE_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) && \
|
||||
__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)
|
||||
#define ABSL_IS_LITTLE_ENDIAN 1
|
||||
#elif defined(__BYTE_ORDER__) && defined(__ORDER_BIG_ENDIAN__) && \
|
||||
__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
|
||||
#define ABSL_IS_BIG_ENDIAN 1
|
||||
#elif defined(_WIN32)
|
||||
#define ABSL_IS_LITTLE_ENDIAN 1
|
||||
#else
|
||||
#error "absl endian detection needs to be set up for your compiler"
|
||||
#endif
|
||||
|
||||
// macOS 10.13 and iOS 10.11 don't let you use <any>, <optional>, or <variant>
|
||||
// even though the headers exist and are publicly noted to work. See
|
||||
// https://github.com/abseil/abseil-cpp/issues/207 and
|
||||
// https://developer.apple.com/documentation/xcode_release_notes/xcode_10_release_notes
|
||||
// libc++ spells out the availability requirements in the file
|
||||
// llvm-project/libcxx/include/__config via the #define
|
||||
// _LIBCPP_AVAILABILITY_BAD_OPTIONAL_ACCESS.
|
||||
#if defined(__APPLE__) && defined(_LIBCPP_VERSION) && \
|
||||
((defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && \
|
||||
__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 101400) || \
|
||||
(defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__) && \
|
||||
__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ < 120000) || \
|
||||
(defined(__ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__) && \
|
||||
__ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__ < 50000) || \
|
||||
(defined(__ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__) && \
|
||||
__ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__ < 120000))
|
||||
#define ABSL_INTERNAL_APPLE_CXX17_TYPES_UNAVAILABLE 1
|
||||
#else
|
||||
#define ABSL_INTERNAL_APPLE_CXX17_TYPES_UNAVAILABLE 0
|
||||
#endif
|
||||
|
||||
// ABSL_HAVE_STD_ANY
|
||||
//
|
||||
// Checks whether C++17 std::any is available by checking whether <any> exists.
|
||||
#ifdef ABSL_HAVE_STD_ANY
|
||||
#error "ABSL_HAVE_STD_ANY cannot be directly set."
|
||||
#endif
|
||||
|
||||
#ifdef __has_include
|
||||
#if __has_include(<any>) && defined(__cplusplus) && __cplusplus >= 201703L && \
|
||||
!ABSL_INTERNAL_APPLE_CXX17_TYPES_UNAVAILABLE
|
||||
#define ABSL_HAVE_STD_ANY 1
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// ABSL_HAVE_STD_OPTIONAL
|
||||
//
|
||||
// Checks whether C++17 std::optional is available.
|
||||
#ifdef ABSL_HAVE_STD_OPTIONAL
|
||||
#error "ABSL_HAVE_STD_OPTIONAL cannot be directly set."
|
||||
#endif
|
||||
|
||||
#ifdef __has_include
|
||||
#if __has_include(<optional>) && defined(__cplusplus) && \
|
||||
__cplusplus >= 201703L && !ABSL_INTERNAL_APPLE_CXX17_TYPES_UNAVAILABLE
|
||||
#define ABSL_HAVE_STD_OPTIONAL 1
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// ABSL_HAVE_STD_VARIANT
|
||||
//
|
||||
// Checks whether C++17 std::variant is available.
|
||||
#ifdef ABSL_HAVE_STD_VARIANT
|
||||
#error "ABSL_HAVE_STD_VARIANT cannot be directly set."
|
||||
#endif
|
||||
|
||||
#ifdef __has_include
|
||||
#if __has_include(<variant>) && defined(__cplusplus) && \
|
||||
__cplusplus >= 201703L && !ABSL_INTERNAL_APPLE_CXX17_TYPES_UNAVAILABLE
|
||||
#define ABSL_HAVE_STD_VARIANT 1
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// ABSL_HAVE_STD_STRING_VIEW
|
||||
//
|
||||
// Checks whether C++17 std::string_view is available.
|
||||
#ifdef ABSL_HAVE_STD_STRING_VIEW
|
||||
#error "ABSL_HAVE_STD_STRING_VIEW cannot be directly set."
|
||||
#endif
|
||||
|
||||
#ifdef __has_include
|
||||
#if __has_include(<string_view>) && defined(__cplusplus) && \
|
||||
__cplusplus >= 201703L
|
||||
#define ABSL_HAVE_STD_STRING_VIEW 1
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// For MSVC, `__has_include` is supported in VS 2017 15.3, which is later than
|
||||
// the support for <optional>, <any>, <string_view>, <variant>. So we use
|
||||
// _MSC_VER to check whether we have VS 2017 RTM (when <optional>, <any>,
|
||||
// <string_view>, <variant> is implemented) or higher. Also, `__cplusplus` is
|
||||
// not correctly set by MSVC, so we use `_MSVC_LANG` to check the language
|
||||
// version.
|
||||
// TODO(zhangxy): fix tests before enabling aliasing for `std::any`.
|
||||
#if defined(_MSC_VER) && _MSC_VER >= 1910 && \
|
||||
((defined(_MSVC_LANG) && _MSVC_LANG > 201402) || \
|
||||
(defined(__cplusplus) && __cplusplus > 201402))
|
||||
// #define ABSL_HAVE_STD_ANY 1
|
||||
#define ABSL_HAVE_STD_OPTIONAL 1
|
||||
#define ABSL_HAVE_STD_VARIANT 1
|
||||
#define ABSL_HAVE_STD_STRING_VIEW 1
|
||||
#endif
|
||||
|
||||
// ABSL_USES_STD_ANY
|
||||
//
|
||||
// Indicates whether absl::any is an alias for std::any.
|
||||
#if !defined(ABSL_OPTION_USE_STD_ANY)
|
||||
#error options.h is misconfigured.
|
||||
#elif ABSL_OPTION_USE_STD_ANY == 0 || \
|
||||
(ABSL_OPTION_USE_STD_ANY == 2 && !defined(ABSL_HAVE_STD_ANY))
|
||||
#undef ABSL_USES_STD_ANY
|
||||
#elif ABSL_OPTION_USE_STD_ANY == 1 || \
|
||||
(ABSL_OPTION_USE_STD_ANY == 2 && defined(ABSL_HAVE_STD_ANY))
|
||||
#define ABSL_USES_STD_ANY 1
|
||||
#else
|
||||
#error options.h is misconfigured.
|
||||
#endif
|
||||
|
||||
// ABSL_USES_STD_OPTIONAL
|
||||
//
|
||||
// Indicates whether absl::optional is an alias for std::optional.
|
||||
#if !defined(ABSL_OPTION_USE_STD_OPTIONAL)
|
||||
#error options.h is misconfigured.
|
||||
#elif ABSL_OPTION_USE_STD_OPTIONAL == 0 || \
|
||||
(ABSL_OPTION_USE_STD_OPTIONAL == 2 && !defined(ABSL_HAVE_STD_OPTIONAL))
|
||||
#undef ABSL_USES_STD_OPTIONAL
|
||||
#elif ABSL_OPTION_USE_STD_OPTIONAL == 1 || \
|
||||
(ABSL_OPTION_USE_STD_OPTIONAL == 2 && defined(ABSL_HAVE_STD_OPTIONAL))
|
||||
#define ABSL_USES_STD_OPTIONAL 1
|
||||
#else
|
||||
#error options.h is misconfigured.
|
||||
#endif
|
||||
|
||||
// ABSL_USES_STD_VARIANT
|
||||
//
|
||||
// Indicates whether absl::variant is an alias for std::variant.
|
||||
#if !defined(ABSL_OPTION_USE_STD_VARIANT)
|
||||
#error options.h is misconfigured.
|
||||
#elif ABSL_OPTION_USE_STD_VARIANT == 0 || \
|
||||
(ABSL_OPTION_USE_STD_VARIANT == 2 && !defined(ABSL_HAVE_STD_VARIANT))
|
||||
#undef ABSL_USES_STD_VARIANT
|
||||
#elif ABSL_OPTION_USE_STD_VARIANT == 1 || \
|
||||
(ABSL_OPTION_USE_STD_VARIANT == 2 && defined(ABSL_HAVE_STD_VARIANT))
|
||||
#define ABSL_USES_STD_VARIANT 1
|
||||
#else
|
||||
#error options.h is misconfigured.
|
||||
#endif
|
||||
|
||||
// ABSL_USES_STD_STRING_VIEW
|
||||
//
|
||||
// Indicates whether absl::string_view is an alias for std::string_view.
|
||||
#if !defined(ABSL_OPTION_USE_STD_STRING_VIEW)
|
||||
#error options.h is misconfigured.
|
||||
#elif ABSL_OPTION_USE_STD_STRING_VIEW == 0 || \
|
||||
(ABSL_OPTION_USE_STD_STRING_VIEW == 2 && \
|
||||
!defined(ABSL_HAVE_STD_STRING_VIEW))
|
||||
#undef ABSL_USES_STD_STRING_VIEW
|
||||
#elif ABSL_OPTION_USE_STD_STRING_VIEW == 1 || \
|
||||
(ABSL_OPTION_USE_STD_STRING_VIEW == 2 && \
|
||||
defined(ABSL_HAVE_STD_STRING_VIEW))
|
||||
#define ABSL_USES_STD_STRING_VIEW 1
|
||||
#else
|
||||
#error options.h is misconfigured.
|
||||
#endif
|
||||
|
||||
// In debug mode, MSVC 2017's std::variant throws a EXCEPTION_ACCESS_VIOLATION
|
||||
// SEH exception from emplace for variant<SomeStruct> when constructing the
|
||||
// struct can throw. This defeats some of variant_test and
|
||||
// variant_exception_safety_test.
|
||||
#if defined(_MSC_VER) && _MSC_VER >= 1700 && defined(_DEBUG)
|
||||
#define ABSL_INTERNAL_MSVC_2017_DBG_MODE
|
||||
#endif
|
||||
|
||||
// ABSL_INTERNAL_MANGLED_NS
|
||||
// ABSL_INTERNAL_MANGLED_BACKREFERENCE
|
||||
//
|
||||
// Internal macros for building up mangled names in our internal fork of CCTZ.
|
||||
// This implementation detail is only needed and provided for the MSVC build.
|
||||
//
|
||||
// These macros both expand to string literals. ABSL_INTERNAL_MANGLED_NS is
|
||||
// the mangled spelling of the `absl` namespace, and
|
||||
// ABSL_INTERNAL_MANGLED_BACKREFERENCE is a back-reference integer representing
|
||||
// the proper count to skip past the CCTZ fork namespace names. (This number
|
||||
// is one larger when there is an inline namespace name to skip.)
|
||||
#if defined(_MSC_VER)
|
||||
#if ABSL_OPTION_USE_INLINE_NAMESPACE == 0
|
||||
#define ABSL_INTERNAL_MANGLED_NS "absl"
|
||||
#define ABSL_INTERNAL_MANGLED_BACKREFERENCE "5"
|
||||
#else
|
||||
#define ABSL_INTERNAL_MANGLED_NS \
|
||||
ABSL_INTERNAL_TOKEN_STR(ABSL_OPTION_INLINE_NAMESPACE_NAME) "@absl"
|
||||
#define ABSL_INTERNAL_MANGLED_BACKREFERENCE "6"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#undef ABSL_INTERNAL_HAS_KEYWORD
|
||||
|
||||
// ABSL_DLL
|
||||
//
|
||||
// When building Abseil as a DLL, this macro expands to `__declspec(dllexport)`
|
||||
// so we can annotate symbols appropriately as being exported. When used in
|
||||
// headers consuming a DLL, this macro expands to `__declspec(dllimport)` so
|
||||
// that consumers know the symbol is defined inside the DLL. In all other cases,
|
||||
// the macro expands to nothing.
|
||||
#if defined(_MSC_VER)
|
||||
#if defined(ABSL_BUILD_DLL)
|
||||
#define ABSL_DLL __declspec(dllexport)
|
||||
#elif defined(ABSL_CONSUME_DLL)
|
||||
#define ABSL_DLL __declspec(dllimport)
|
||||
#else
|
||||
#define ABSL_DLL
|
||||
#endif
|
||||
#else
|
||||
#define ABSL_DLL
|
||||
#endif // defined(_MSC_VER)
|
||||
|
||||
// ABSL_HAVE_MEMORY_SANITIZER
|
||||
//
|
||||
// MemorySanitizer (MSan) is a detector of uninitialized reads. It consists of
|
||||
// a compiler instrumentation module and a run-time library.
|
||||
#ifdef ABSL_HAVE_MEMORY_SANITIZER
|
||||
#error "ABSL_HAVE_MEMORY_SANITIZER cannot be directly set."
|
||||
#elif defined(__SANITIZE_MEMORY__)
|
||||
#define ABSL_HAVE_MEMORY_SANITIZER 1
|
||||
#elif !defined(__native_client__) && ABSL_HAVE_FEATURE(memory_sanitizer)
|
||||
#define ABSL_HAVE_MEMORY_SANITIZER 1
|
||||
#endif
|
||||
|
||||
// ABSL_HAVE_THREAD_SANITIZER
|
||||
//
|
||||
// ThreadSanitizer (TSan) is a fast data race detector.
|
||||
#ifdef ABSL_HAVE_THREAD_SANITIZER
|
||||
#error "ABSL_HAVE_THREAD_SANITIZER cannot be directly set."
|
||||
#elif defined(__SANITIZE_THREAD__)
|
||||
#define ABSL_HAVE_THREAD_SANITIZER 1
|
||||
#elif ABSL_HAVE_FEATURE(thread_sanitizer)
|
||||
#define ABSL_HAVE_THREAD_SANITIZER 1
|
||||
#endif
|
||||
|
||||
// ABSL_HAVE_ADDRESS_SANITIZER
|
||||
//
|
||||
// AddressSanitizer (ASan) is a fast memory error detector.
|
||||
#ifdef ABSL_HAVE_ADDRESS_SANITIZER
|
||||
#error "ABSL_HAVE_ADDRESS_SANITIZER cannot be directly set."
|
||||
#elif defined(__SANITIZE_ADDRESS__)
|
||||
#define ABSL_HAVE_ADDRESS_SANITIZER 1
|
||||
#elif ABSL_HAVE_FEATURE(address_sanitizer)
|
||||
#define ABSL_HAVE_ADDRESS_SANITIZER 1
|
||||
#endif
|
||||
|
||||
// ABSL_HAVE_CLASS_TEMPLATE_ARGUMENT_DEDUCTION
|
||||
//
|
||||
// Class template argument deduction is a language feature added in C++17.
|
||||
#ifdef ABSL_HAVE_CLASS_TEMPLATE_ARGUMENT_DEDUCTION
|
||||
#error "ABSL_HAVE_CLASS_TEMPLATE_ARGUMENT_DEDUCTION cannot be directly set."
|
||||
#elif defined(__cpp_deduction_guides)
|
||||
#define ABSL_HAVE_CLASS_TEMPLATE_ARGUMENT_DEDUCTION 1
|
||||
#endif
|
||||
|
||||
#endif // ABSL_BASE_CONFIG_H_
|
158
extern/int128/absl/base/macros.h
vendored
Normal file
158
extern/int128/absl/base/macros.h
vendored
Normal file
@ -0,0 +1,158 @@
|
||||
//
|
||||
// Copyright 2017 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.
|
||||
//
|
||||
// -----------------------------------------------------------------------------
|
||||
// File: macros.h
|
||||
// -----------------------------------------------------------------------------
|
||||
//
|
||||
// This header file defines the set of language macros used within Abseil code.
|
||||
// For the set of macros used to determine supported compilers and platforms,
|
||||
// see absl/base/config.h instead.
|
||||
//
|
||||
// This code is compiled directly on many platforms, including client
|
||||
// platforms like Windows, Mac, and embedded systems. Before making
|
||||
// any changes here, make sure that you're not breaking any platforms.
|
||||
|
||||
#ifndef ABSL_BASE_MACROS_H_
|
||||
#define ABSL_BASE_MACROS_H_
|
||||
|
||||
#include <cassert>
|
||||
#include <cstddef>
|
||||
|
||||
#include "absl/base/attributes.h"
|
||||
#include "absl/base/config.h"
|
||||
#include "absl/base/optimization.h"
|
||||
#include "absl/base/port.h"
|
||||
|
||||
// ABSL_ARRAYSIZE()
|
||||
//
|
||||
// Returns the number of elements in an array as a compile-time constant, which
|
||||
// can be used in defining new arrays. If you use this macro on a pointer by
|
||||
// mistake, you will get a compile-time error.
|
||||
#define ABSL_ARRAYSIZE(array) \
|
||||
(sizeof(::absl::macros_internal::ArraySizeHelper(array)))
|
||||
|
||||
namespace absl {
|
||||
ABSL_NAMESPACE_BEGIN
|
||||
namespace macros_internal {
|
||||
// Note: this internal template function declaration is used by ABSL_ARRAYSIZE.
|
||||
// The function doesn't need a definition, as we only use its type.
|
||||
template <typename T, size_t N>
|
||||
auto ArraySizeHelper(const T (&array)[N]) -> char (&)[N];
|
||||
} // namespace macros_internal
|
||||
ABSL_NAMESPACE_END
|
||||
} // namespace absl
|
||||
|
||||
// ABSL_BAD_CALL_IF()
|
||||
//
|
||||
// Used on a function overload to trap bad calls: any call that matches the
|
||||
// overload will cause a compile-time error. This macro uses a clang-specific
|
||||
// "enable_if" attribute, as described at
|
||||
// https://clang.llvm.org/docs/AttributeReference.html#enable-if
|
||||
//
|
||||
// Overloads which use this macro should be bracketed by
|
||||
// `#ifdef ABSL_BAD_CALL_IF`.
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
// int isdigit(int c);
|
||||
// #ifdef ABSL_BAD_CALL_IF
|
||||
// int isdigit(int c)
|
||||
// ABSL_BAD_CALL_IF(c <= -1 || c > 255,
|
||||
// "'c' must have the value of an unsigned char or EOF");
|
||||
// #endif // ABSL_BAD_CALL_IF
|
||||
#if ABSL_HAVE_ATTRIBUTE(enable_if)
|
||||
#define ABSL_BAD_CALL_IF(expr, msg) \
|
||||
__attribute__((enable_if(expr, "Bad call trap"), unavailable(msg)))
|
||||
#endif
|
||||
|
||||
// ABSL_ASSERT()
|
||||
//
|
||||
// In C++11, `assert` can't be used portably within constexpr functions.
|
||||
// ABSL_ASSERT functions as a runtime assert but works in C++11 constexpr
|
||||
// functions. Example:
|
||||
//
|
||||
// constexpr double Divide(double a, double b) {
|
||||
// return ABSL_ASSERT(b != 0), a / b;
|
||||
// }
|
||||
//
|
||||
// This macro is inspired by
|
||||
// https://akrzemi1.wordpress.com/2017/05/18/asserts-in-constexpr-functions/
|
||||
#if defined(NDEBUG)
|
||||
#define ABSL_ASSERT(expr) \
|
||||
(false ? static_cast<void>(expr) : static_cast<void>(0))
|
||||
#else
|
||||
#define ABSL_ASSERT(expr) \
|
||||
(ABSL_PREDICT_TRUE((expr)) ? static_cast<void>(0) \
|
||||
: [] { assert(false && #expr); }()) // NOLINT
|
||||
#endif
|
||||
|
||||
// `ABSL_INTERNAL_HARDENING_ABORT()` controls how `ABSL_HARDENING_ASSERT()`
|
||||
// aborts the program in release mode (when NDEBUG is defined). The
|
||||
// implementation should abort the program as quickly as possible and ideally it
|
||||
// should not be possible to ignore the abort request.
|
||||
#if (ABSL_HAVE_BUILTIN(__builtin_trap) && \
|
||||
ABSL_HAVE_BUILTIN(__builtin_unreachable)) || \
|
||||
(defined(__GNUC__) && !defined(__clang__))
|
||||
#define ABSL_INTERNAL_HARDENING_ABORT() \
|
||||
do { \
|
||||
__builtin_trap(); \
|
||||
__builtin_unreachable(); \
|
||||
} while (false)
|
||||
#else
|
||||
#define ABSL_INTERNAL_HARDENING_ABORT() abort()
|
||||
#endif
|
||||
|
||||
// ABSL_HARDENING_ASSERT()
|
||||
//
|
||||
// `ABSL_HARDENING_ASSERT()` is like `ABSL_ASSERT()`, but used to implement
|
||||
// runtime assertions that should be enabled in hardened builds even when
|
||||
// `NDEBUG` is defined.
|
||||
//
|
||||
// When `NDEBUG` is not defined, `ABSL_HARDENING_ASSERT()` is identical to
|
||||
// `ABSL_ASSERT()`.
|
||||
//
|
||||
// See `ABSL_OPTION_HARDENED` in `absl/base/options.h` for more information on
|
||||
// hardened mode.
|
||||
#if ABSL_OPTION_HARDENED == 1 && defined(NDEBUG)
|
||||
#define ABSL_HARDENING_ASSERT(expr) \
|
||||
(ABSL_PREDICT_TRUE((expr)) ? static_cast<void>(0) \
|
||||
: [] { ABSL_INTERNAL_HARDENING_ABORT(); }())
|
||||
#else
|
||||
#define ABSL_HARDENING_ASSERT(expr) ABSL_ASSERT(expr)
|
||||
#endif
|
||||
|
||||
#ifdef ABSL_HAVE_EXCEPTIONS
|
||||
#define ABSL_INTERNAL_TRY try
|
||||
#define ABSL_INTERNAL_CATCH_ANY catch (...)
|
||||
#define ABSL_INTERNAL_RETHROW do { throw; } while (false)
|
||||
#else // ABSL_HAVE_EXCEPTIONS
|
||||
#define ABSL_INTERNAL_TRY if (true)
|
||||
#define ABSL_INTERNAL_CATCH_ANY else if (false)
|
||||
#define ABSL_INTERNAL_RETHROW do {} while (false)
|
||||
#endif // ABSL_HAVE_EXCEPTIONS
|
||||
|
||||
// `ABSL_INTERNAL_UNREACHABLE` is an unreachable statement. A program which
|
||||
// reaches one has undefined behavior, and the compiler may optimize
|
||||
// accordingly.
|
||||
#if defined(__GNUC__) || ABSL_HAVE_BUILTIN(__builtin_unreachable)
|
||||
#define ABSL_INTERNAL_UNREACHABLE __builtin_unreachable()
|
||||
#elif defined(_MSC_VER)
|
||||
#define ABSL_INTERNAL_UNREACHABLE __assume(0)
|
||||
#else
|
||||
#define ABSL_INTERNAL_UNREACHABLE
|
||||
#endif
|
||||
|
||||
#endif // ABSL_BASE_MACROS_H_
|
244
extern/int128/absl/base/optimization.h
vendored
Normal file
244
extern/int128/absl/base/optimization.h
vendored
Normal file
@ -0,0 +1,244 @@
|
||||
//
|
||||
// Copyright 2017 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.
|
||||
//
|
||||
// -----------------------------------------------------------------------------
|
||||
// File: optimization.h
|
||||
// -----------------------------------------------------------------------------
|
||||
//
|
||||
// This header file defines portable macros for performance optimization.
|
||||
|
||||
#ifndef ABSL_BASE_OPTIMIZATION_H_
|
||||
#define ABSL_BASE_OPTIMIZATION_H_
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
#include "absl/base/config.h"
|
||||
|
||||
// ABSL_BLOCK_TAIL_CALL_OPTIMIZATION
|
||||
//
|
||||
// Instructs the compiler to avoid optimizing tail-call recursion. This macro is
|
||||
// useful when you wish to preserve the existing function order within a stack
|
||||
// trace for logging, debugging, or profiling purposes.
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
// int f() {
|
||||
// int result = g();
|
||||
// ABSL_BLOCK_TAIL_CALL_OPTIMIZATION();
|
||||
// return result;
|
||||
// }
|
||||
#if defined(__pnacl__)
|
||||
#define ABSL_BLOCK_TAIL_CALL_OPTIMIZATION() if (volatile int x = 0) { (void)x; }
|
||||
#elif defined(__clang__)
|
||||
// Clang will not tail call given inline volatile assembly.
|
||||
#define ABSL_BLOCK_TAIL_CALL_OPTIMIZATION() __asm__ __volatile__("")
|
||||
#elif defined(__GNUC__)
|
||||
// GCC will not tail call given inline volatile assembly.
|
||||
#define ABSL_BLOCK_TAIL_CALL_OPTIMIZATION() __asm__ __volatile__("")
|
||||
#elif defined(_MSC_VER)
|
||||
#include <intrin.h>
|
||||
// The __nop() intrinsic blocks the optimisation.
|
||||
#define ABSL_BLOCK_TAIL_CALL_OPTIMIZATION() __nop()
|
||||
#else
|
||||
#define ABSL_BLOCK_TAIL_CALL_OPTIMIZATION() if (volatile int x = 0) { (void)x; }
|
||||
#endif
|
||||
|
||||
// ABSL_CACHELINE_SIZE
|
||||
//
|
||||
// Explicitly defines the size of the L1 cache for purposes of alignment.
|
||||
// Setting the cacheline size allows you to specify that certain objects be
|
||||
// aligned on a cacheline boundary with `ABSL_CACHELINE_ALIGNED` declarations.
|
||||
// (See below.)
|
||||
//
|
||||
// NOTE: this macro should be replaced with the following C++17 features, when
|
||||
// those are generally available:
|
||||
//
|
||||
// * `std::hardware_constructive_interference_size`
|
||||
// * `std::hardware_destructive_interference_size`
|
||||
//
|
||||
// See http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0154r1.html
|
||||
// for more information.
|
||||
#if defined(__GNUC__)
|
||||
// Cache line alignment
|
||||
#if defined(__i386__) || defined(__x86_64__)
|
||||
#define ABSL_CACHELINE_SIZE 64
|
||||
#elif defined(__powerpc64__)
|
||||
#define ABSL_CACHELINE_SIZE 128
|
||||
#elif defined(__aarch64__)
|
||||
// We would need to read special register ctr_el0 to find out L1 dcache size.
|
||||
// This value is a good estimate based on a real aarch64 machine.
|
||||
#define ABSL_CACHELINE_SIZE 64
|
||||
#elif defined(__arm__)
|
||||
// Cache line sizes for ARM: These values are not strictly correct since
|
||||
// cache line sizes depend on implementations, not architectures. There
|
||||
// are even implementations with cache line sizes configurable at boot
|
||||
// time.
|
||||
#if defined(__ARM_ARCH_5T__)
|
||||
#define ABSL_CACHELINE_SIZE 32
|
||||
#elif defined(__ARM_ARCH_7A__)
|
||||
#define ABSL_CACHELINE_SIZE 64
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef ABSL_CACHELINE_SIZE
|
||||
// A reasonable default guess. Note that overestimates tend to waste more
|
||||
// space, while underestimates tend to waste more time.
|
||||
#define ABSL_CACHELINE_SIZE 64
|
||||
#endif
|
||||
|
||||
// ABSL_CACHELINE_ALIGNED
|
||||
//
|
||||
// Indicates that the declared object be cache aligned using
|
||||
// `ABSL_CACHELINE_SIZE` (see above). Cacheline aligning objects allows you to
|
||||
// load a set of related objects in the L1 cache for performance improvements.
|
||||
// Cacheline aligning objects properly allows constructive memory sharing and
|
||||
// prevents destructive (or "false") memory sharing.
|
||||
//
|
||||
// NOTE: callers should replace uses of this macro with `alignas()` using
|
||||
// `std::hardware_constructive_interference_size` and/or
|
||||
// `std::hardware_destructive_interference_size` when C++17 becomes available to
|
||||
// them.
|
||||
//
|
||||
// See http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0154r1.html
|
||||
// for more information.
|
||||
//
|
||||
// On some compilers, `ABSL_CACHELINE_ALIGNED` expands to an `__attribute__`
|
||||
// or `__declspec` attribute. For compilers where this is not known to work,
|
||||
// the macro expands to nothing.
|
||||
//
|
||||
// No further guarantees are made here. The result of applying the macro
|
||||
// to variables and types is always implementation-defined.
|
||||
//
|
||||
// WARNING: It is easy to use this attribute incorrectly, even to the point
|
||||
// of causing bugs that are difficult to diagnose, crash, etc. It does not
|
||||
// of itself guarantee that objects are aligned to a cache line.
|
||||
//
|
||||
// NOTE: Some compilers are picky about the locations of annotations such as
|
||||
// this attribute, so prefer to put it at the beginning of your declaration.
|
||||
// For example,
|
||||
//
|
||||
// ABSL_CACHELINE_ALIGNED static Foo* foo = ...
|
||||
//
|
||||
// class ABSL_CACHELINE_ALIGNED Bar { ...
|
||||
//
|
||||
// Recommendations:
|
||||
//
|
||||
// 1) Consult compiler documentation; this comment is not kept in sync as
|
||||
// toolchains evolve.
|
||||
// 2) Verify your use has the intended effect. This often requires inspecting
|
||||
// the generated machine code.
|
||||
// 3) Prefer applying this attribute to individual variables. Avoid
|
||||
// applying it to types. This tends to localize the effect.
|
||||
#define ABSL_CACHELINE_ALIGNED __attribute__((aligned(ABSL_CACHELINE_SIZE)))
|
||||
#elif defined(_MSC_VER)
|
||||
#define ABSL_CACHELINE_SIZE 64
|
||||
#define ABSL_CACHELINE_ALIGNED __declspec(align(ABSL_CACHELINE_SIZE))
|
||||
#else
|
||||
#define ABSL_CACHELINE_SIZE 64
|
||||
#define ABSL_CACHELINE_ALIGNED
|
||||
#endif
|
||||
|
||||
// ABSL_PREDICT_TRUE, ABSL_PREDICT_FALSE
|
||||
//
|
||||
// Enables the compiler to prioritize compilation using static analysis for
|
||||
// likely paths within a boolean branch.
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
// if (ABSL_PREDICT_TRUE(expression)) {
|
||||
// return result; // Faster if more likely
|
||||
// } else {
|
||||
// return 0;
|
||||
// }
|
||||
//
|
||||
// Compilers can use the information that a certain branch is not likely to be
|
||||
// taken (for instance, a CHECK failure) to optimize for the common case in
|
||||
// the absence of better information (ie. compiling gcc with `-fprofile-arcs`).
|
||||
//
|
||||
// Recommendation: Modern CPUs dynamically predict branch execution paths,
|
||||
// typically with accuracy greater than 97%. As a result, annotating every
|
||||
// branch in a codebase is likely counterproductive; however, annotating
|
||||
// specific branches that are both hot and consistently mispredicted is likely
|
||||
// to yield performance improvements.
|
||||
#if ABSL_HAVE_BUILTIN(__builtin_expect) || \
|
||||
(defined(__GNUC__) && !defined(__clang__))
|
||||
#define ABSL_PREDICT_FALSE(x) (__builtin_expect(false || (x), false))
|
||||
#define ABSL_PREDICT_TRUE(x) (__builtin_expect(false || (x), true))
|
||||
#else
|
||||
#define ABSL_PREDICT_FALSE(x) (x)
|
||||
#define ABSL_PREDICT_TRUE(x) (x)
|
||||
#endif
|
||||
|
||||
// ABSL_INTERNAL_ASSUME(cond)
|
||||
// Informs the compiler that a condition is always true and that it can assume
|
||||
// it to be true for optimization purposes. The call has undefined behavior if
|
||||
// the condition is false.
|
||||
// In !NDEBUG mode, the condition is checked with an assert().
|
||||
// NOTE: The expression must not have side effects, as it will only be evaluated
|
||||
// in some compilation modes and not others.
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
// int x = ...;
|
||||
// ABSL_INTERNAL_ASSUME(x >= 0);
|
||||
// // The compiler can optimize the division to a simple right shift using the
|
||||
// // assumption specified above.
|
||||
// int y = x / 16;
|
||||
//
|
||||
#if !defined(NDEBUG)
|
||||
#define ABSL_INTERNAL_ASSUME(cond) assert(cond)
|
||||
#elif ABSL_HAVE_BUILTIN(__builtin_assume)
|
||||
#define ABSL_INTERNAL_ASSUME(cond) __builtin_assume(cond)
|
||||
#elif defined(__GNUC__) || ABSL_HAVE_BUILTIN(__builtin_unreachable)
|
||||
#define ABSL_INTERNAL_ASSUME(cond) \
|
||||
do { \
|
||||
if (!(cond)) __builtin_unreachable(); \
|
||||
} while (0)
|
||||
#elif defined(_MSC_VER)
|
||||
#define ABSL_INTERNAL_ASSUME(cond) __assume(cond)
|
||||
#else
|
||||
#define ABSL_INTERNAL_ASSUME(cond) \
|
||||
do { \
|
||||
static_cast<void>(false && (cond)); \
|
||||
} while (0)
|
||||
#endif
|
||||
|
||||
// ABSL_INTERNAL_UNIQUE_SMALL_NAME(cond)
|
||||
// This macro forces small unique name on a static file level symbols like
|
||||
// static local variables or static functions. This is intended to be used in
|
||||
// macro definitions to optimize the cost of generated code. Do NOT use it on
|
||||
// symbols exported from translation unit since it may cause a link time
|
||||
// conflict.
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
// #define MY_MACRO(txt)
|
||||
// namespace {
|
||||
// char VeryVeryLongVarName[] ABSL_INTERNAL_UNIQUE_SMALL_NAME() = txt;
|
||||
// const char* VeryVeryLongFuncName() ABSL_INTERNAL_UNIQUE_SMALL_NAME();
|
||||
// const char* VeryVeryLongFuncName() { return txt; }
|
||||
// }
|
||||
//
|
||||
|
||||
#if defined(__GNUC__)
|
||||
#define ABSL_INTERNAL_UNIQUE_SMALL_NAME2(x) #x
|
||||
#define ABSL_INTERNAL_UNIQUE_SMALL_NAME1(x) ABSL_INTERNAL_UNIQUE_SMALL_NAME2(x)
|
||||
#define ABSL_INTERNAL_UNIQUE_SMALL_NAME() \
|
||||
asm(ABSL_INTERNAL_UNIQUE_SMALL_NAME1(.absl.__COUNTER__))
|
||||
#else
|
||||
#define ABSL_INTERNAL_UNIQUE_SMALL_NAME()
|
||||
#endif
|
||||
|
||||
#endif // ABSL_BASE_OPTIMIZATION_H_
|
238
extern/int128/absl/base/options.h
vendored
Normal file
238
extern/int128/absl/base/options.h
vendored
Normal file
@ -0,0 +1,238 @@
|
||||
// Copyright 2019 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.
|
||||
//
|
||||
// -----------------------------------------------------------------------------
|
||||
// File: options.h
|
||||
// -----------------------------------------------------------------------------
|
||||
//
|
||||
// This file contains Abseil configuration options for setting specific
|
||||
// implementations instead of letting Abseil determine which implementation to
|
||||
// use at compile-time. Setting these options may be useful for package or build
|
||||
// managers who wish to guarantee ABI stability within binary builds (which are
|
||||
// otherwise difficult to enforce).
|
||||
//
|
||||
// *** IMPORTANT NOTICE FOR PACKAGE MANAGERS: It is important that
|
||||
// maintainers of package managers who wish to package Abseil read and
|
||||
// understand this file! ***
|
||||
//
|
||||
// Abseil contains a number of possible configuration endpoints, based on
|
||||
// parameters such as the detected platform, language version, or command-line
|
||||
// flags used to invoke the underlying binary. As is the case with all
|
||||
// libraries, binaries which contain Abseil code must ensure that separate
|
||||
// packages use the same compiled copy of Abseil to avoid a diamond dependency
|
||||
// problem, which can occur if two packages built with different Abseil
|
||||
// configuration settings are linked together. Diamond dependency problems in
|
||||
// C++ may manifest as violations to the One Definition Rule (ODR) (resulting in
|
||||
// linker errors), or undefined behavior (resulting in crashes).
|
||||
//
|
||||
// Diamond dependency problems can be avoided if all packages utilize the same
|
||||
// exact version of Abseil. Building from source code with the same compilation
|
||||
// parameters is the easiest way to avoid such dependency problems. However, for
|
||||
// package managers who cannot control such compilation parameters, we are
|
||||
// providing the file to allow you to inject ABI (Application Binary Interface)
|
||||
// stability across builds. Settings options in this file will neither change
|
||||
// API nor ABI, providing a stable copy of Abseil between packages.
|
||||
//
|
||||
// Care must be taken to keep options within these configurations isolated
|
||||
// from any other dynamic settings, such as command-line flags which could alter
|
||||
// these options. This file is provided specifically to help build and package
|
||||
// managers provide a stable copy of Abseil within their libraries and binaries;
|
||||
// other developers should not have need to alter the contents of this file.
|
||||
//
|
||||
// -----------------------------------------------------------------------------
|
||||
// Usage
|
||||
// -----------------------------------------------------------------------------
|
||||
//
|
||||
// For any particular package release, set the appropriate definitions within
|
||||
// this file to whatever value makes the most sense for your package(s). Note
|
||||
// that, by default, most of these options, at the moment, affect the
|
||||
// implementation of types; future options may affect other implementation
|
||||
// details.
|
||||
//
|
||||
// NOTE: the defaults within this file all assume that Abseil can select the
|
||||
// proper Abseil implementation at compile-time, which will not be sufficient
|
||||
// to guarantee ABI stability to package managers.
|
||||
|
||||
#ifndef ABSL_BASE_OPTIONS_H_
|
||||
#define ABSL_BASE_OPTIONS_H_
|
||||
|
||||
// Include a standard library header to allow configuration based on the
|
||||
// standard library in use.
|
||||
#ifdef __cplusplus
|
||||
#include <ciso646>
|
||||
#endif
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Type Compatibility Options
|
||||
// -----------------------------------------------------------------------------
|
||||
//
|
||||
// ABSL_OPTION_USE_STD_ANY
|
||||
//
|
||||
// This option controls whether absl::any is implemented as an alias to
|
||||
// std::any, or as an independent implementation.
|
||||
//
|
||||
// A value of 0 means to use Abseil's implementation. This requires only C++11
|
||||
// support, and is expected to work on every toolchain we support.
|
||||
//
|
||||
// A value of 1 means to use an alias to std::any. This requires that all code
|
||||
// using Abseil is built in C++17 mode or later.
|
||||
//
|
||||
// A value of 2 means to detect the C++ version being used to compile Abseil,
|
||||
// and use an alias only if a working std::any is available. This option is
|
||||
// useful when you are building your entire program, including all of its
|
||||
// dependencies, from source. It should not be used otherwise -- for example,
|
||||
// if you are distributing Abseil in a binary package manager -- since in
|
||||
// mode 2, absl::any will name a different type, with a different mangled name
|
||||
// and binary layout, depending on the compiler flags passed by the end user.
|
||||
// For more info, see https://abseil.io/about/design/dropin-types.
|
||||
//
|
||||
// User code should not inspect this macro. To check in the preprocessor if
|
||||
// absl::any is a typedef of std::any, use the feature macro ABSL_USES_STD_ANY.
|
||||
|
||||
#define ABSL_OPTION_USE_STD_ANY 2
|
||||
|
||||
|
||||
// ABSL_OPTION_USE_STD_OPTIONAL
|
||||
//
|
||||
// This option controls whether absl::optional is implemented as an alias to
|
||||
// std::optional, or as an independent implementation.
|
||||
//
|
||||
// A value of 0 means to use Abseil's implementation. This requires only C++11
|
||||
// support, and is expected to work on every toolchain we support.
|
||||
//
|
||||
// A value of 1 means to use an alias to std::optional. This requires that all
|
||||
// code using Abseil is built in C++17 mode or later.
|
||||
//
|
||||
// A value of 2 means to detect the C++ version being used to compile Abseil,
|
||||
// and use an alias only if a working std::optional is available. This option
|
||||
// is useful when you are building your program from source. It should not be
|
||||
// used otherwise -- for example, if you are distributing Abseil in a binary
|
||||
// package manager -- since in mode 2, absl::optional will name a different
|
||||
// type, with a different mangled name and binary layout, depending on the
|
||||
// compiler flags passed by the end user. For more info, see
|
||||
// https://abseil.io/about/design/dropin-types.
|
||||
|
||||
// User code should not inspect this macro. To check in the preprocessor if
|
||||
// absl::optional is a typedef of std::optional, use the feature macro
|
||||
// ABSL_USES_STD_OPTIONAL.
|
||||
|
||||
#define ABSL_OPTION_USE_STD_OPTIONAL 2
|
||||
|
||||
|
||||
// ABSL_OPTION_USE_STD_STRING_VIEW
|
||||
//
|
||||
// This option controls whether absl::string_view is implemented as an alias to
|
||||
// std::string_view, or as an independent implementation.
|
||||
//
|
||||
// A value of 0 means to use Abseil's implementation. This requires only C++11
|
||||
// support, and is expected to work on every toolchain we support.
|
||||
//
|
||||
// A value of 1 means to use an alias to std::string_view. This requires that
|
||||
// all code using Abseil is built in C++17 mode or later.
|
||||
//
|
||||
// A value of 2 means to detect the C++ version being used to compile Abseil,
|
||||
// and use an alias only if a working std::string_view is available. This
|
||||
// option is useful when you are building your program from source. It should
|
||||
// not be used otherwise -- for example, if you are distributing Abseil in a
|
||||
// binary package manager -- since in mode 2, absl::string_view will name a
|
||||
// different type, with a different mangled name and binary layout, depending on
|
||||
// the compiler flags passed by the end user. For more info, see
|
||||
// https://abseil.io/about/design/dropin-types.
|
||||
//
|
||||
// User code should not inspect this macro. To check in the preprocessor if
|
||||
// absl::string_view is a typedef of std::string_view, use the feature macro
|
||||
// ABSL_USES_STD_STRING_VIEW.
|
||||
|
||||
#define ABSL_OPTION_USE_STD_STRING_VIEW 2
|
||||
|
||||
// ABSL_OPTION_USE_STD_VARIANT
|
||||
//
|
||||
// This option controls whether absl::variant is implemented as an alias to
|
||||
// std::variant, or as an independent implementation.
|
||||
//
|
||||
// A value of 0 means to use Abseil's implementation. This requires only C++11
|
||||
// support, and is expected to work on every toolchain we support.
|
||||
//
|
||||
// A value of 1 means to use an alias to std::variant. This requires that all
|
||||
// code using Abseil is built in C++17 mode or later.
|
||||
//
|
||||
// A value of 2 means to detect the C++ version being used to compile Abseil,
|
||||
// and use an alias only if a working std::variant is available. This option
|
||||
// is useful when you are building your program from source. It should not be
|
||||
// used otherwise -- for example, if you are distributing Abseil in a binary
|
||||
// package manager -- since in mode 2, absl::variant will name a different
|
||||
// type, with a different mangled name and binary layout, depending on the
|
||||
// compiler flags passed by the end user. For more info, see
|
||||
// https://abseil.io/about/design/dropin-types.
|
||||
//
|
||||
// User code should not inspect this macro. To check in the preprocessor if
|
||||
// absl::variant is a typedef of std::variant, use the feature macro
|
||||
// ABSL_USES_STD_VARIANT.
|
||||
|
||||
#define ABSL_OPTION_USE_STD_VARIANT 2
|
||||
|
||||
|
||||
// ABSL_OPTION_USE_INLINE_NAMESPACE
|
||||
// ABSL_OPTION_INLINE_NAMESPACE_NAME
|
||||
//
|
||||
// These options controls whether all entities in the absl namespace are
|
||||
// contained within an inner inline namespace. This does not affect the
|
||||
// user-visible API of Abseil, but it changes the mangled names of all symbols.
|
||||
//
|
||||
// This can be useful as a version tag if you are distributing Abseil in
|
||||
// precompiled form. This will prevent a binary library build of Abseil with
|
||||
// one inline namespace being used with headers configured with a different
|
||||
// inline namespace name. Binary packagers are reminded that Abseil does not
|
||||
// guarantee any ABI stability in Abseil, so any update of Abseil or
|
||||
// configuration change in such a binary package should be combined with a
|
||||
// new, unique value for the inline namespace name.
|
||||
//
|
||||
// A value of 0 means not to use inline namespaces.
|
||||
//
|
||||
// A value of 1 means to use an inline namespace with the given name inside
|
||||
// namespace absl. If this is set, ABSL_OPTION_INLINE_NAMESPACE_NAME must also
|
||||
// be changed to a new, unique identifier name. In particular "head" is not
|
||||
// allowed.
|
||||
|
||||
#define ABSL_OPTION_USE_INLINE_NAMESPACE 0
|
||||
#define ABSL_OPTION_INLINE_NAMESPACE_NAME head
|
||||
|
||||
// ABSL_OPTION_HARDENED
|
||||
//
|
||||
// This option enables a "hardened" build in release mode (in this context,
|
||||
// release mode is defined as a build where the `NDEBUG` macro is defined).
|
||||
//
|
||||
// A value of 0 means that "hardened" mode is not enabled.
|
||||
//
|
||||
// A value of 1 means that "hardened" mode is enabled.
|
||||
//
|
||||
// Hardened builds have additional security checks enabled when `NDEBUG` is
|
||||
// defined. Defining `NDEBUG` is normally used to turn `assert()` macro into a
|
||||
// no-op, as well as disabling other bespoke program consistency checks. By
|
||||
// defining ABSL_OPTION_HARDENED to 1, a select set of checks remain enabled in
|
||||
// release mode. These checks guard against programming errors that may lead to
|
||||
// security vulnerabilities. In release mode, when one of these programming
|
||||
// errors is encountered, the program will immediately abort, possibly without
|
||||
// any attempt at logging.
|
||||
//
|
||||
// The checks enabled by this option are not free; they do incur runtime cost.
|
||||
//
|
||||
// The checks enabled by this option are always active when `NDEBUG` is not
|
||||
// defined, even in the case when ABSL_OPTION_HARDENED is defined to 0. The
|
||||
// checks enabled by this option may abort the program in a different way and
|
||||
// log additional information when `NDEBUG` is not defined.
|
||||
|
||||
#define ABSL_OPTION_HARDENED 0
|
||||
|
||||
#endif // ABSL_BASE_OPTIONS_H_
|
111
extern/int128/absl/base/policy_checks.h
vendored
Normal file
111
extern/int128/absl/base/policy_checks.h
vendored
Normal file
@ -0,0 +1,111 @@
|
||||
// Copyright 2017 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.
|
||||
//
|
||||
// -----------------------------------------------------------------------------
|
||||
// File: policy_checks.h
|
||||
// -----------------------------------------------------------------------------
|
||||
//
|
||||
// This header enforces a minimum set of policies at build time, such as the
|
||||
// supported compiler and library versions. Unsupported configurations are
|
||||
// reported with `#error`. This enforcement is best effort, so successfully
|
||||
// compiling this header does not guarantee a supported configuration.
|
||||
|
||||
#ifndef ABSL_BASE_POLICY_CHECKS_H_
|
||||
#define ABSL_BASE_POLICY_CHECKS_H_
|
||||
|
||||
// Included for the __GLIBC_PREREQ macro used below.
|
||||
#include <limits.h>
|
||||
|
||||
// Included for the _STLPORT_VERSION macro used below.
|
||||
#if defined(__cplusplus)
|
||||
#include <cstddef>
|
||||
#endif
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Operating System Check
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
#if defined(__CYGWIN__)
|
||||
#error "Cygwin is not supported."
|
||||
#endif
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Toolchain Check
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
// We support MSVC++ 14.0 update 2 and later.
|
||||
// This minimum will go up.
|
||||
#if defined(_MSC_FULL_VER) && _MSC_FULL_VER < 190023918 && !defined(__clang__)
|
||||
#error "This package requires Visual Studio 2015 Update 2 or higher."
|
||||
#endif
|
||||
|
||||
// We support gcc 4.7 and later.
|
||||
// This minimum will go up.
|
||||
#if defined(__GNUC__) && !defined(__clang__)
|
||||
#if __GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 7)
|
||||
#error "This package requires gcc 4.7 or higher."
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// We support Apple Xcode clang 4.2.1 (version 421.11.65) and later.
|
||||
// This corresponds to Apple Xcode version 4.5.
|
||||
// This minimum will go up.
|
||||
#if defined(__apple_build_version__) && __apple_build_version__ < 4211165
|
||||
#error "This package requires __apple_build_version__ of 4211165 or higher."
|
||||
#endif
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// C++ Version Check
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
// Enforce C++11 as the minimum. Note that Visual Studio has not
|
||||
// advanced __cplusplus despite being good enough for our purposes, so
|
||||
// so we exempt it from the check.
|
||||
#if defined(__cplusplus) && !defined(_MSC_VER)
|
||||
#if __cplusplus < 201103L
|
||||
#error "C++ versions less than C++11 are not supported."
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Standard Library Check
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
#if defined(_STLPORT_VERSION)
|
||||
#error "STLPort is not supported."
|
||||
#endif
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// `char` Size Check
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
// Abseil currently assumes CHAR_BIT == 8. If you would like to use Abseil on a
|
||||
// platform where this is not the case, please provide us with the details about
|
||||
// your platform so we can consider relaxing this requirement.
|
||||
#if CHAR_BIT != 8
|
||||
#error "Abseil assumes CHAR_BIT == 8."
|
||||
#endif
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// `int` Size Check
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
// Abseil currently assumes that an int is 4 bytes. If you would like to use
|
||||
// Abseil on a platform where this is not the case, please provide us with the
|
||||
// details about your platform so we can consider relaxing this requirement.
|
||||
#if INT_MAX < 2147483647
|
||||
#error "Abseil assumes that int is at least 4 bytes. "
|
||||
#endif
|
||||
|
||||
#endif // ABSL_BASE_POLICY_CHECKS_H_
|
25
extern/int128/absl/base/port.h
vendored
Normal file
25
extern/int128/absl/base/port.h
vendored
Normal file
@ -0,0 +1,25 @@
|
||||
// Copyright 2017 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.
|
||||
//
|
||||
// This files is a forwarding header for other headers containing various
|
||||
// portability macros and functions.
|
||||
|
||||
#ifndef ABSL_BASE_PORT_H_
|
||||
#define ABSL_BASE_PORT_H_
|
||||
|
||||
#include "absl/base/attributes.h"
|
||||
#include "absl/base/config.h"
|
||||
#include "absl/base/optimization.h"
|
||||
|
||||
#endif // ABSL_BASE_PORT_H_
|
11
extern/int128/absl/numeric/Makefile
vendored
Normal file
11
extern/int128/absl/numeric/Makefile
vendored
Normal file
@ -0,0 +1,11 @@
|
||||
LIBRARY=libi128$(CROSS).a
|
||||
|
||||
$(LIBRARY): $(wildcard *.cc) $(wildcard *.h) $(wildcard internal/*.h) $(wildcard ../base/*.h) $(wildcard *.inc) Makefile
|
||||
$(RM) -f *.o
|
||||
$(CXX) $(CROSS_FLAGS) -I../.. -c -O3 -fPIC int128.cc
|
||||
$(AR) crs $(LIBRARY) *.o
|
||||
$(RM) -f *.o
|
||||
|
||||
.PHONY: clean
|
||||
clean:
|
||||
$(RM) -f *.o *.a
|
177
extern/int128/absl/numeric/bits.h
vendored
Normal file
177
extern/int128/absl/numeric/bits.h
vendored
Normal file
@ -0,0 +1,177 @@
|
||||
// Copyright 2020 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.
|
||||
//
|
||||
// -----------------------------------------------------------------------------
|
||||
// File: bits.h
|
||||
// -----------------------------------------------------------------------------
|
||||
//
|
||||
// This file contains implementations of C++20's bitwise math functions, as
|
||||
// defined by:
|
||||
//
|
||||
// P0553R4:
|
||||
// http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p0553r4.html
|
||||
// P0556R3:
|
||||
// http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p0556r3.html
|
||||
// P1355R2:
|
||||
// http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p1355r2.html
|
||||
// P1956R1:
|
||||
// http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2020/p1956r1.pdf
|
||||
//
|
||||
// When using a standard library that implements these functions, we use the
|
||||
// standard library's implementation.
|
||||
|
||||
#ifndef ABSL_NUMERIC_BITS_H_
|
||||
#define ABSL_NUMERIC_BITS_H_
|
||||
|
||||
#include <cstdint>
|
||||
#include <limits>
|
||||
#include <type_traits>
|
||||
|
||||
#if (defined(__cpp_lib_int_pow2) && __cpp_lib_int_pow2 >= 202002L) || \
|
||||
(defined(__cpp_lib_bitops) && __cpp_lib_bitops >= 201907L)
|
||||
#include <bit>
|
||||
#endif
|
||||
|
||||
#include "absl/base/attributes.h"
|
||||
#include "absl/base/config.h"
|
||||
#include "absl/numeric/internal/bits.h"
|
||||
|
||||
namespace absl {
|
||||
ABSL_NAMESPACE_BEGIN
|
||||
|
||||
#if !(defined(__cpp_lib_bitops) && __cpp_lib_bitops >= 201907L)
|
||||
// rotating
|
||||
template <class T>
|
||||
ABSL_MUST_USE_RESULT constexpr
|
||||
typename std::enable_if<std::is_unsigned<T>::value, T>::type
|
||||
rotl(T x, int s) noexcept {
|
||||
return numeric_internal::RotateLeft(x, s);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
ABSL_MUST_USE_RESULT constexpr
|
||||
typename std::enable_if<std::is_unsigned<T>::value, T>::type
|
||||
rotr(T x, int s) noexcept {
|
||||
return numeric_internal::RotateRight(x, s);
|
||||
}
|
||||
|
||||
// Counting functions
|
||||
//
|
||||
// While these functions are typically constexpr, on some platforms, they may
|
||||
// not be marked as constexpr due to constraints of the compiler/available
|
||||
// intrinsics.
|
||||
template <class T>
|
||||
ABSL_INTERNAL_CONSTEXPR_CLZ inline
|
||||
typename std::enable_if<std::is_unsigned<T>::value, int>::type
|
||||
countl_zero(T x) noexcept {
|
||||
return numeric_internal::CountLeadingZeroes(x);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
ABSL_INTERNAL_CONSTEXPR_CLZ inline
|
||||
typename std::enable_if<std::is_unsigned<T>::value, int>::type
|
||||
countl_one(T x) noexcept {
|
||||
// Avoid integer promotion to a wider type
|
||||
return countl_zero(static_cast<T>(~x));
|
||||
}
|
||||
|
||||
template <class T>
|
||||
ABSL_INTERNAL_CONSTEXPR_CTZ inline
|
||||
typename std::enable_if<std::is_unsigned<T>::value, int>::type
|
||||
countr_zero(T x) noexcept {
|
||||
return numeric_internal::CountTrailingZeroes(x);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
ABSL_INTERNAL_CONSTEXPR_CTZ inline
|
||||
typename std::enable_if<std::is_unsigned<T>::value, int>::type
|
||||
countr_one(T x) noexcept {
|
||||
// Avoid integer promotion to a wider type
|
||||
return countr_zero(static_cast<T>(~x));
|
||||
}
|
||||
|
||||
template <class T>
|
||||
ABSL_INTERNAL_CONSTEXPR_POPCOUNT inline
|
||||
typename std::enable_if<std::is_unsigned<T>::value, int>::type
|
||||
popcount(T x) noexcept {
|
||||
return numeric_internal::Popcount(x);
|
||||
}
|
||||
#else // defined(__cpp_lib_bitops) && __cpp_lib_bitops >= 201907L
|
||||
|
||||
using std::countl_one;
|
||||
using std::countl_zero;
|
||||
using std::countr_one;
|
||||
using std::countr_zero;
|
||||
using std::popcount;
|
||||
using std::rotl;
|
||||
using std::rotr;
|
||||
|
||||
#endif
|
||||
|
||||
#if !(defined(__cpp_lib_int_pow2) && __cpp_lib_int_pow2 >= 202002L)
|
||||
// Returns: true if x is an integral power of two; false otherwise.
|
||||
template <class T>
|
||||
constexpr inline typename std::enable_if<std::is_unsigned<T>::value, bool>::type
|
||||
has_single_bit(T x) noexcept {
|
||||
return x != 0 && (x & (x - 1)) == 0;
|
||||
}
|
||||
|
||||
// Returns: If x == 0, 0; otherwise one plus the base-2 logarithm of x, with any
|
||||
// fractional part discarded.
|
||||
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);
|
||||
}
|
||||
|
||||
// Returns: If x == 0, 0; otherwise the maximal value y such that
|
||||
// has_single_bit(y) is true and y <= x.
|
||||
template <class T>
|
||||
ABSL_INTERNAL_CONSTEXPR_CLZ inline
|
||||
typename std::enable_if<std::is_unsigned<T>::value, T>::type
|
||||
bit_floor(T x) noexcept {
|
||||
return x == 0 ? 0 : T{1} << (bit_width(x) - 1);
|
||||
}
|
||||
|
||||
// Returns: N, where N is the smallest power of 2 greater than or equal to x.
|
||||
//
|
||||
// Preconditions: N is representable as a value of type T.
|
||||
template <class T>
|
||||
ABSL_INTERNAL_CONSTEXPR_CLZ inline
|
||||
typename std::enable_if<std::is_unsigned<T>::value, T>::type
|
||||
bit_ceil(T x) {
|
||||
// If T is narrower than unsigned, T{1} << bit_width will be promoted. We
|
||||
// want to force it to wraparound so that bit_ceil of an invalid value are not
|
||||
// core constant expressions.
|
||||
//
|
||||
// BitCeilNonPowerOf2 triggers an overflow in constexpr contexts if we would
|
||||
// undergo promotion to unsigned but not fit the result into T without
|
||||
// truncation.
|
||||
return has_single_bit(x) ? T{1} << (bit_width(x) - 1)
|
||||
: numeric_internal::BitCeilNonPowerOf2(x);
|
||||
}
|
||||
#else // defined(__cpp_lib_int_pow2) && __cpp_lib_int_pow2 >= 202002L
|
||||
|
||||
using std::bit_ceil;
|
||||
using std::bit_floor;
|
||||
using std::bit_width;
|
||||
using std::has_single_bit;
|
||||
|
||||
#endif
|
||||
|
||||
ABSL_NAMESPACE_END
|
||||
} // namespace absl
|
||||
|
||||
#endif // ABSL_NUMERIC_BITS_H_
|
383
extern/int128/absl/numeric/int128.cc
vendored
Normal file
383
extern/int128/absl/numeric/int128.cc
vendored
Normal file
@ -0,0 +1,383 @@
|
||||
// Copyright 2017 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 "absl/numeric/int128.h"
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#include <cassert>
|
||||
#include <iomanip>
|
||||
#include <ostream> // NOLINT(readability/streams)
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <type_traits>
|
||||
|
||||
#include "absl/base/optimization.h"
|
||||
#include "absl/numeric/bits.h"
|
||||
|
||||
namespace absl {
|
||||
ABSL_NAMESPACE_BEGIN
|
||||
|
||||
ABSL_DLL const uint128 kuint128max = MakeUint128(
|
||||
std::numeric_limits<uint64_t>::max(), std::numeric_limits<uint64_t>::max());
|
||||
|
||||
namespace {
|
||||
|
||||
// Returns the 0-based position of the last set bit (i.e., most significant bit)
|
||||
// in the given uint128. The argument is not 0.
|
||||
//
|
||||
// For example:
|
||||
// Given: 5 (decimal) == 101 (binary)
|
||||
// Returns: 2
|
||||
inline ABSL_ATTRIBUTE_ALWAYS_INLINE int Fls128(uint128 n) {
|
||||
if (uint64_t hi = Uint128High64(n)) {
|
||||
ABSL_INTERNAL_ASSUME(hi != 0);
|
||||
return 127 - countl_zero(hi);
|
||||
}
|
||||
const uint64_t low = Uint128Low64(n);
|
||||
ABSL_INTERNAL_ASSUME(low != 0);
|
||||
return 63 - countl_zero(low);
|
||||
}
|
||||
|
||||
// Long division/modulo for uint128 implemented using the shift-subtract
|
||||
// division algorithm adapted from:
|
||||
// https://stackoverflow.com/questions/5386377/division-without-using
|
||||
inline void DivModImpl(uint128 dividend, uint128 divisor, uint128* quotient_ret,
|
||||
uint128* remainder_ret) {
|
||||
assert(divisor != 0);
|
||||
|
||||
if (divisor > dividend) {
|
||||
*quotient_ret = 0;
|
||||
*remainder_ret = dividend;
|
||||
return;
|
||||
}
|
||||
|
||||
if (divisor == dividend) {
|
||||
*quotient_ret = 1;
|
||||
*remainder_ret = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
uint128 denominator = divisor;
|
||||
uint128 quotient = 0;
|
||||
|
||||
// Left aligns the MSB of the denominator and the dividend.
|
||||
const int shift = Fls128(dividend) - Fls128(denominator);
|
||||
denominator <<= shift;
|
||||
|
||||
// Uses shift-subtract algorithm to divide dividend by denominator. The
|
||||
// remainder will be left in dividend.
|
||||
for (int i = 0; i <= shift; ++i) {
|
||||
quotient <<= 1;
|
||||
if (dividend >= denominator) {
|
||||
dividend -= denominator;
|
||||
quotient |= 1;
|
||||
}
|
||||
denominator >>= 1;
|
||||
}
|
||||
|
||||
*quotient_ret = quotient;
|
||||
*remainder_ret = dividend;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
uint128 MakeUint128FromFloat(T v) {
|
||||
static_assert(std::is_floating_point<T>::value, "");
|
||||
|
||||
// Rounding behavior is towards zero, same as for built-in types.
|
||||
|
||||
// Undefined behavior if v is NaN or cannot fit into uint128.
|
||||
assert(std::isfinite(v) && v > -1 &&
|
||||
(std::numeric_limits<T>::max_exponent <= 128 ||
|
||||
v < std::ldexp(static_cast<T>(1), 128)));
|
||||
|
||||
if (v >= std::ldexp(static_cast<T>(1), 64)) {
|
||||
uint64_t hi = static_cast<uint64_t>(std::ldexp(v, -64));
|
||||
uint64_t lo = static_cast<uint64_t>(v - std::ldexp(static_cast<T>(hi), 64));
|
||||
return MakeUint128(hi, lo);
|
||||
}
|
||||
|
||||
return MakeUint128(0, static_cast<uint64_t>(v));
|
||||
}
|
||||
|
||||
#if defined(__clang__) && !defined(__SSE3__)
|
||||
// Workaround for clang bug: https://bugs.llvm.org/show_bug.cgi?id=38289
|
||||
// Casting from long double to uint64_t is miscompiled and drops bits.
|
||||
// It is more work, so only use when we need the workaround.
|
||||
uint128 MakeUint128FromFloat(long double v) {
|
||||
// Go 50 bits at a time, that fits in a double
|
||||
static_assert(std::numeric_limits<double>::digits >= 50, "");
|
||||
static_assert(std::numeric_limits<long double>::digits <= 150, "");
|
||||
// Undefined behavior if v is not finite or cannot fit into uint128.
|
||||
assert(std::isfinite(v) && v > -1 && v < std::ldexp(1.0L, 128));
|
||||
|
||||
v = std::ldexp(v, -100);
|
||||
uint64_t w0 = static_cast<uint64_t>(static_cast<double>(std::trunc(v)));
|
||||
v = std::ldexp(v - static_cast<double>(w0), 50);
|
||||
uint64_t w1 = static_cast<uint64_t>(static_cast<double>(std::trunc(v)));
|
||||
v = std::ldexp(v - static_cast<double>(w1), 50);
|
||||
uint64_t w2 = static_cast<uint64_t>(static_cast<double>(std::trunc(v)));
|
||||
return (static_cast<uint128>(w0) << 100) | (static_cast<uint128>(w1) << 50) |
|
||||
static_cast<uint128>(w2);
|
||||
}
|
||||
#endif // __clang__ && !__SSE3__
|
||||
} // namespace
|
||||
|
||||
uint128::uint128(float v) : uint128(MakeUint128FromFloat(v)) {}
|
||||
uint128::uint128(double v) : uint128(MakeUint128FromFloat(v)) {}
|
||||
uint128::uint128(long double v) : uint128(MakeUint128FromFloat(v)) {}
|
||||
|
||||
#if !defined(ABSL_HAVE_INTRINSIC_INT128)
|
||||
uint128 operator/(uint128 lhs, uint128 rhs) {
|
||||
uint128 quotient = 0;
|
||||
uint128 remainder = 0;
|
||||
DivModImpl(lhs, rhs, "ient, &remainder);
|
||||
return quotient;
|
||||
}
|
||||
|
||||
uint128 operator%(uint128 lhs, uint128 rhs) {
|
||||
uint128 quotient = 0;
|
||||
uint128 remainder = 0;
|
||||
DivModImpl(lhs, rhs, "ient, &remainder);
|
||||
return remainder;
|
||||
}
|
||||
#endif // !defined(ABSL_HAVE_INTRINSIC_INT128)
|
||||
|
||||
namespace {
|
||||
|
||||
std::string Uint128ToFormattedString(uint128 v, std::ios_base::fmtflags flags) {
|
||||
// Select a divisor which is the largest power of the base < 2^64.
|
||||
uint128 div;
|
||||
int div_base_log;
|
||||
switch (flags & std::ios::basefield) {
|
||||
case std::ios::hex:
|
||||
div = 0x1000000000000000; // 16^15
|
||||
div_base_log = 15;
|
||||
break;
|
||||
case std::ios::oct:
|
||||
div = 01000000000000000000000; // 8^21
|
||||
div_base_log = 21;
|
||||
break;
|
||||
default: // std::ios::dec
|
||||
div = 10000000000000000000u; // 10^19
|
||||
div_base_log = 19;
|
||||
break;
|
||||
}
|
||||
|
||||
// Now piece together the uint128 representation from three chunks of the
|
||||
// original value, each less than "div" and therefore representable as a
|
||||
// uint64_t.
|
||||
std::ostringstream os;
|
||||
std::ios_base::fmtflags copy_mask =
|
||||
std::ios::basefield | std::ios::showbase | std::ios::uppercase;
|
||||
os.setf(flags & copy_mask, copy_mask);
|
||||
uint128 high = v;
|
||||
uint128 low;
|
||||
DivModImpl(high, div, &high, &low);
|
||||
uint128 mid;
|
||||
DivModImpl(high, div, &high, &mid);
|
||||
if (Uint128Low64(high) != 0) {
|
||||
os << Uint128Low64(high);
|
||||
os << std::noshowbase << std::setfill('0') << std::setw(div_base_log);
|
||||
os << Uint128Low64(mid);
|
||||
os << std::setw(div_base_log);
|
||||
} else if (Uint128Low64(mid) != 0) {
|
||||
os << Uint128Low64(mid);
|
||||
os << std::noshowbase << std::setfill('0') << std::setw(div_base_log);
|
||||
}
|
||||
os << Uint128Low64(low);
|
||||
return os.str();
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
std::ostream& operator<<(std::ostream& os, uint128 v) {
|
||||
std::ios_base::fmtflags flags = os.flags();
|
||||
std::string rep = Uint128ToFormattedString(v, flags);
|
||||
|
||||
// Add the requisite padding.
|
||||
std::streamsize width = os.width(0);
|
||||
if (static_cast<size_t>(width) > rep.size()) {
|
||||
std::ios::fmtflags adjustfield = flags & std::ios::adjustfield;
|
||||
if (adjustfield == std::ios::left) {
|
||||
rep.append(width - rep.size(), os.fill());
|
||||
} else if (adjustfield == std::ios::internal &&
|
||||
(flags & std::ios::showbase) &&
|
||||
(flags & std::ios::basefield) == std::ios::hex && v != 0) {
|
||||
rep.insert(2, width - rep.size(), os.fill());
|
||||
} else {
|
||||
rep.insert(0, width - rep.size(), os.fill());
|
||||
}
|
||||
}
|
||||
|
||||
return os << rep;
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
uint128 UnsignedAbsoluteValue(int128 v) {
|
||||
// Cast to uint128 before possibly negating because -Int128Min() is undefined.
|
||||
return Int128High64(v) < 0 ? -uint128(v) : uint128(v);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
#if !defined(ABSL_HAVE_INTRINSIC_INT128)
|
||||
namespace {
|
||||
|
||||
template <typename T>
|
||||
int128 MakeInt128FromFloat(T v) {
|
||||
// Conversion when v is NaN or cannot fit into int128 would be undefined
|
||||
// behavior if using an intrinsic 128-bit integer.
|
||||
assert(std::isfinite(v) && (std::numeric_limits<T>::max_exponent <= 127 ||
|
||||
(v >= -std::ldexp(static_cast<T>(1), 127) &&
|
||||
v < std::ldexp(static_cast<T>(1), 127))));
|
||||
|
||||
// We must convert the absolute value and then negate as needed, because
|
||||
// floating point types are typically sign-magnitude. Otherwise, the
|
||||
// difference between the high and low 64 bits when interpreted as two's
|
||||
// complement overwhelms the precision of the mantissa.
|
||||
uint128 result = v < 0 ? -MakeUint128FromFloat(-v) : MakeUint128FromFloat(v);
|
||||
return MakeInt128(int128_internal::BitCastToSigned(Uint128High64(result)),
|
||||
Uint128Low64(result));
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
int128::int128(float v) : int128(MakeInt128FromFloat(v)) {}
|
||||
int128::int128(double v) : int128(MakeInt128FromFloat(v)) {}
|
||||
int128::int128(long double v) : int128(MakeInt128FromFloat(v)) {}
|
||||
|
||||
int128 operator/(int128 lhs, int128 rhs) {
|
||||
assert(lhs != Int128Min() || rhs != -1); // UB on two's complement.
|
||||
|
||||
uint128 quotient = 0;
|
||||
uint128 remainder = 0;
|
||||
DivModImpl(UnsignedAbsoluteValue(lhs), UnsignedAbsoluteValue(rhs),
|
||||
"ient, &remainder);
|
||||
if ((Int128High64(lhs) < 0) != (Int128High64(rhs) < 0)) quotient = -quotient;
|
||||
return MakeInt128(int128_internal::BitCastToSigned(Uint128High64(quotient)),
|
||||
Uint128Low64(quotient));
|
||||
}
|
||||
|
||||
int128 operator%(int128 lhs, int128 rhs) {
|
||||
assert(lhs != Int128Min() || rhs != -1); // UB on two's complement.
|
||||
|
||||
uint128 quotient = 0;
|
||||
uint128 remainder = 0;
|
||||
DivModImpl(UnsignedAbsoluteValue(lhs), UnsignedAbsoluteValue(rhs),
|
||||
"ient, &remainder);
|
||||
if (Int128High64(lhs) < 0) remainder = -remainder;
|
||||
return MakeInt128(int128_internal::BitCastToSigned(Uint128High64(remainder)),
|
||||
Uint128Low64(remainder));
|
||||
}
|
||||
#endif // ABSL_HAVE_INTRINSIC_INT128
|
||||
|
||||
std::ostream& operator<<(std::ostream& os, int128 v) {
|
||||
std::ios_base::fmtflags flags = os.flags();
|
||||
std::string rep;
|
||||
|
||||
// Add the sign if needed.
|
||||
bool print_as_decimal =
|
||||
(flags & std::ios::basefield) == std::ios::dec ||
|
||||
(flags & std::ios::basefield) == std::ios_base::fmtflags();
|
||||
if (print_as_decimal) {
|
||||
if (Int128High64(v) < 0) {
|
||||
rep = "-";
|
||||
} else if (flags & std::ios::showpos) {
|
||||
rep = "+";
|
||||
}
|
||||
}
|
||||
|
||||
rep.append(Uint128ToFormattedString(
|
||||
print_as_decimal ? UnsignedAbsoluteValue(v) : uint128(v), os.flags()));
|
||||
|
||||
// Add the requisite padding.
|
||||
std::streamsize width = os.width(0);
|
||||
if (static_cast<size_t>(width) > rep.size()) {
|
||||
switch (flags & std::ios::adjustfield) {
|
||||
case std::ios::left:
|
||||
rep.append(width - rep.size(), os.fill());
|
||||
break;
|
||||
case std::ios::internal:
|
||||
if (print_as_decimal && (rep[0] == '+' || rep[0] == '-')) {
|
||||
rep.insert(1, width - rep.size(), os.fill());
|
||||
} else if ((flags & std::ios::basefield) == std::ios::hex &&
|
||||
(flags & std::ios::showbase) && v != 0) {
|
||||
rep.insert(2, width - rep.size(), os.fill());
|
||||
} else {
|
||||
rep.insert(0, width - rep.size(), os.fill());
|
||||
}
|
||||
break;
|
||||
default: // std::ios::right
|
||||
rep.insert(0, width - rep.size(), os.fill());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return os << rep;
|
||||
}
|
||||
|
||||
ABSL_NAMESPACE_END
|
||||
} // namespace absl
|
||||
|
||||
namespace std {
|
||||
constexpr bool numeric_limits<absl::uint128>::is_specialized;
|
||||
constexpr bool numeric_limits<absl::uint128>::is_signed;
|
||||
constexpr bool numeric_limits<absl::uint128>::is_integer;
|
||||
constexpr bool numeric_limits<absl::uint128>::is_exact;
|
||||
constexpr bool numeric_limits<absl::uint128>::has_infinity;
|
||||
constexpr bool numeric_limits<absl::uint128>::has_quiet_NaN;
|
||||
constexpr bool numeric_limits<absl::uint128>::has_signaling_NaN;
|
||||
constexpr float_denorm_style numeric_limits<absl::uint128>::has_denorm;
|
||||
constexpr bool numeric_limits<absl::uint128>::has_denorm_loss;
|
||||
constexpr float_round_style numeric_limits<absl::uint128>::round_style;
|
||||
constexpr bool numeric_limits<absl::uint128>::is_iec559;
|
||||
constexpr bool numeric_limits<absl::uint128>::is_bounded;
|
||||
constexpr bool numeric_limits<absl::uint128>::is_modulo;
|
||||
constexpr int numeric_limits<absl::uint128>::digits;
|
||||
constexpr int numeric_limits<absl::uint128>::digits10;
|
||||
constexpr int numeric_limits<absl::uint128>::max_digits10;
|
||||
constexpr int numeric_limits<absl::uint128>::radix;
|
||||
constexpr int numeric_limits<absl::uint128>::min_exponent;
|
||||
constexpr int numeric_limits<absl::uint128>::min_exponent10;
|
||||
constexpr int numeric_limits<absl::uint128>::max_exponent;
|
||||
constexpr int numeric_limits<absl::uint128>::max_exponent10;
|
||||
constexpr bool numeric_limits<absl::uint128>::traps;
|
||||
constexpr bool numeric_limits<absl::uint128>::tinyness_before;
|
||||
|
||||
constexpr bool numeric_limits<absl::int128>::is_specialized;
|
||||
constexpr bool numeric_limits<absl::int128>::is_signed;
|
||||
constexpr bool numeric_limits<absl::int128>::is_integer;
|
||||
constexpr bool numeric_limits<absl::int128>::is_exact;
|
||||
constexpr bool numeric_limits<absl::int128>::has_infinity;
|
||||
constexpr bool numeric_limits<absl::int128>::has_quiet_NaN;
|
||||
constexpr bool numeric_limits<absl::int128>::has_signaling_NaN;
|
||||
constexpr float_denorm_style numeric_limits<absl::int128>::has_denorm;
|
||||
constexpr bool numeric_limits<absl::int128>::has_denorm_loss;
|
||||
constexpr float_round_style numeric_limits<absl::int128>::round_style;
|
||||
constexpr bool numeric_limits<absl::int128>::is_iec559;
|
||||
constexpr bool numeric_limits<absl::int128>::is_bounded;
|
||||
constexpr bool numeric_limits<absl::int128>::is_modulo;
|
||||
constexpr int numeric_limits<absl::int128>::digits;
|
||||
constexpr int numeric_limits<absl::int128>::digits10;
|
||||
constexpr int numeric_limits<absl::int128>::max_digits10;
|
||||
constexpr int numeric_limits<absl::int128>::radix;
|
||||
constexpr int numeric_limits<absl::int128>::min_exponent;
|
||||
constexpr int numeric_limits<absl::int128>::min_exponent10;
|
||||
constexpr int numeric_limits<absl::int128>::max_exponent;
|
||||
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
|
1155
extern/int128/absl/numeric/int128.h
vendored
Normal file
1155
extern/int128/absl/numeric/int128.h
vendored
Normal file
File diff suppressed because it is too large
Load Diff
302
extern/int128/absl/numeric/int128_have_intrinsic.inc
vendored
Normal file
302
extern/int128/absl/numeric/int128_have_intrinsic.inc
vendored
Normal file
@ -0,0 +1,302 @@
|
||||
//
|
||||
// Copyright 2017 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.
|
||||
|
||||
// This file contains :int128 implementation details that depend on internal
|
||||
// representation when ABSL_HAVE_INTRINSIC_INT128 is defined. This file is
|
||||
// included by int128.h and relies on ABSL_INTERNAL_WCHAR_T being defined.
|
||||
|
||||
namespace int128_internal {
|
||||
|
||||
// Casts from unsigned to signed while preserving the underlying binary
|
||||
// representation.
|
||||
constexpr __int128 BitCastToSigned(unsigned __int128 v) {
|
||||
// Casting an unsigned integer to a signed integer of the same
|
||||
// width is implementation defined behavior if the source value would not fit
|
||||
// in the destination type. We step around it with a roundtrip bitwise not
|
||||
// operation to make sure this function remains constexpr. Clang and GCC
|
||||
// optimize this to a no-op on x86-64.
|
||||
return v & (static_cast<unsigned __int128>(1) << 127)
|
||||
? ~static_cast<__int128>(~v)
|
||||
: static_cast<__int128>(v);
|
||||
}
|
||||
|
||||
} // namespace int128_internal
|
||||
|
||||
inline int128& int128::operator=(__int128 v) {
|
||||
v_ = v;
|
||||
return *this;
|
||||
}
|
||||
|
||||
constexpr uint64_t Int128Low64(int128 v) {
|
||||
return static_cast<uint64_t>(v.v_ & ~uint64_t{0});
|
||||
}
|
||||
|
||||
constexpr int64_t Int128High64(int128 v) {
|
||||
// Initially cast to unsigned to prevent a right shift on a negative value.
|
||||
return int128_internal::BitCastToSigned(
|
||||
static_cast<uint64_t>(static_cast<unsigned __int128>(v.v_) >> 64));
|
||||
}
|
||||
|
||||
constexpr int128::int128(int64_t high, uint64_t low)
|
||||
// Initially cast to unsigned to prevent a left shift that overflows.
|
||||
: v_(int128_internal::BitCastToSigned(static_cast<unsigned __int128>(high)
|
||||
<< 64) |
|
||||
low) {}
|
||||
|
||||
|
||||
constexpr int128::int128(int v) : v_{v} {}
|
||||
|
||||
constexpr int128::int128(long v) : v_{v} {} // NOLINT(runtime/int)
|
||||
|
||||
constexpr int128::int128(long long v) : v_{v} {} // NOLINT(runtime/int)
|
||||
|
||||
constexpr int128::int128(__int128 v) : v_{v} {}
|
||||
|
||||
constexpr int128::int128(unsigned int v) : v_{v} {}
|
||||
|
||||
constexpr int128::int128(unsigned long v) : v_{v} {} // NOLINT(runtime/int)
|
||||
|
||||
// NOLINTNEXTLINE(runtime/int)
|
||||
constexpr int128::int128(unsigned long long v) : v_{v} {}
|
||||
|
||||
constexpr int128::int128(unsigned __int128 v) : v_{static_cast<__int128>(v)} {}
|
||||
|
||||
inline int128::int128(float v) {
|
||||
v_ = static_cast<__int128>(v);
|
||||
}
|
||||
|
||||
inline int128::int128(double v) {
|
||||
v_ = static_cast<__int128>(v);
|
||||
}
|
||||
|
||||
inline int128::int128(long double v) {
|
||||
v_ = static_cast<__int128>(v);
|
||||
}
|
||||
|
||||
constexpr int128::int128(uint128 v) : v_{static_cast<__int128>(v)} {}
|
||||
|
||||
constexpr int128::operator bool() const { return static_cast<bool>(v_); }
|
||||
|
||||
constexpr int128::operator char() const { return static_cast<char>(v_); }
|
||||
|
||||
constexpr int128::operator signed char() const {
|
||||
return static_cast<signed char>(v_);
|
||||
}
|
||||
|
||||
constexpr int128::operator unsigned char() const {
|
||||
return static_cast<unsigned char>(v_);
|
||||
}
|
||||
|
||||
constexpr int128::operator char16_t() const {
|
||||
return static_cast<char16_t>(v_);
|
||||
}
|
||||
|
||||
constexpr int128::operator char32_t() const {
|
||||
return static_cast<char32_t>(v_);
|
||||
}
|
||||
|
||||
constexpr int128::operator ABSL_INTERNAL_WCHAR_T() const {
|
||||
return static_cast<ABSL_INTERNAL_WCHAR_T>(v_);
|
||||
}
|
||||
|
||||
constexpr int128::operator short() const { // NOLINT(runtime/int)
|
||||
return static_cast<short>(v_); // NOLINT(runtime/int)
|
||||
}
|
||||
|
||||
constexpr int128::operator unsigned short() const { // NOLINT(runtime/int)
|
||||
return static_cast<unsigned short>(v_); // NOLINT(runtime/int)
|
||||
}
|
||||
|
||||
constexpr int128::operator int() const {
|
||||
return static_cast<int>(v_);
|
||||
}
|
||||
|
||||
constexpr int128::operator unsigned int() const {
|
||||
return static_cast<unsigned int>(v_);
|
||||
}
|
||||
|
||||
constexpr int128::operator long() const { // NOLINT(runtime/int)
|
||||
return static_cast<long>(v_); // NOLINT(runtime/int)
|
||||
}
|
||||
|
||||
constexpr int128::operator unsigned long() const { // NOLINT(runtime/int)
|
||||
return static_cast<unsigned long>(v_); // NOLINT(runtime/int)
|
||||
}
|
||||
|
||||
constexpr int128::operator long long() const { // NOLINT(runtime/int)
|
||||
return static_cast<long long>(v_); // NOLINT(runtime/int)
|
||||
}
|
||||
|
||||
constexpr int128::operator unsigned long long() const { // NOLINT(runtime/int)
|
||||
return static_cast<unsigned long long>(v_); // NOLINT(runtime/int)
|
||||
}
|
||||
|
||||
constexpr int128::operator __int128() const { return v_; }
|
||||
|
||||
constexpr int128::operator unsigned __int128() const {
|
||||
return static_cast<unsigned __int128>(v_);
|
||||
}
|
||||
|
||||
// Clang on PowerPC sometimes produces incorrect __int128 to floating point
|
||||
// conversions. In that case, we do the conversion with a similar implementation
|
||||
// to the conversion operators in int128_no_intrinsic.inc.
|
||||
#if defined(__clang__) && !defined(__ppc64__)
|
||||
inline int128::operator float() const { return static_cast<float>(v_); }
|
||||
|
||||
inline int128::operator double () const { return static_cast<double>(v_); }
|
||||
|
||||
inline int128::operator long double() const {
|
||||
return static_cast<long double>(v_);
|
||||
}
|
||||
|
||||
#else // Clang on PowerPC
|
||||
// Forward declaration for conversion operators to floating point types.
|
||||
int128 operator-(int128 v);
|
||||
bool operator!=(int128 lhs, int128 rhs);
|
||||
|
||||
inline int128::operator float() const {
|
||||
// We must convert the absolute value and then negate as needed, because
|
||||
// floating point types are typically sign-magnitude. Otherwise, the
|
||||
// difference between the high and low 64 bits when interpreted as two's
|
||||
// complement overwhelms the precision of the mantissa.
|
||||
//
|
||||
// Also check to make sure we don't negate Int128Min()
|
||||
return v_ < 0 && *this != Int128Min()
|
||||
? -static_cast<float>(-*this)
|
||||
: static_cast<float>(Int128Low64(*this)) +
|
||||
std::ldexp(static_cast<float>(Int128High64(*this)), 64);
|
||||
}
|
||||
|
||||
inline int128::operator double() const {
|
||||
// See comment in int128::operator float() above.
|
||||
return v_ < 0 && *this != Int128Min()
|
||||
? -static_cast<double>(-*this)
|
||||
: static_cast<double>(Int128Low64(*this)) +
|
||||
std::ldexp(static_cast<double>(Int128High64(*this)), 64);
|
||||
}
|
||||
|
||||
inline int128::operator long double() const {
|
||||
// See comment in int128::operator float() above.
|
||||
return v_ < 0 && *this != Int128Min()
|
||||
? -static_cast<long double>(-*this)
|
||||
: static_cast<long double>(Int128Low64(*this)) +
|
||||
std::ldexp(static_cast<long double>(Int128High64(*this)),
|
||||
64);
|
||||
}
|
||||
#endif // Clang on PowerPC
|
||||
|
||||
// Comparison operators.
|
||||
|
||||
inline bool operator==(int128 lhs, int128 rhs) {
|
||||
return static_cast<__int128>(lhs) == static_cast<__int128>(rhs);
|
||||
}
|
||||
|
||||
inline bool operator!=(int128 lhs, int128 rhs) {
|
||||
return static_cast<__int128>(lhs) != static_cast<__int128>(rhs);
|
||||
}
|
||||
|
||||
inline bool operator<(int128 lhs, int128 rhs) {
|
||||
return static_cast<__int128>(lhs) < static_cast<__int128>(rhs);
|
||||
}
|
||||
|
||||
inline bool operator>(int128 lhs, int128 rhs) {
|
||||
return static_cast<__int128>(lhs) > static_cast<__int128>(rhs);
|
||||
}
|
||||
|
||||
inline bool operator<=(int128 lhs, int128 rhs) {
|
||||
return static_cast<__int128>(lhs) <= static_cast<__int128>(rhs);
|
||||
}
|
||||
|
||||
inline bool operator>=(int128 lhs, int128 rhs) {
|
||||
return static_cast<__int128>(lhs) >= static_cast<__int128>(rhs);
|
||||
}
|
||||
|
||||
// Unary operators.
|
||||
|
||||
inline int128 operator-(int128 v) {
|
||||
return -static_cast<__int128>(v);
|
||||
}
|
||||
|
||||
inline bool operator!(int128 v) {
|
||||
return !static_cast<__int128>(v);
|
||||
}
|
||||
|
||||
inline int128 operator~(int128 val) {
|
||||
return ~static_cast<__int128>(val);
|
||||
}
|
||||
|
||||
// Arithmetic operators.
|
||||
|
||||
inline int128 operator+(int128 lhs, int128 rhs) {
|
||||
return static_cast<__int128>(lhs) + static_cast<__int128>(rhs);
|
||||
}
|
||||
|
||||
inline int128 operator-(int128 lhs, int128 rhs) {
|
||||
return static_cast<__int128>(lhs) - static_cast<__int128>(rhs);
|
||||
}
|
||||
|
||||
inline int128 operator*(int128 lhs, int128 rhs) {
|
||||
return static_cast<__int128>(lhs) * static_cast<__int128>(rhs);
|
||||
}
|
||||
|
||||
inline int128 operator/(int128 lhs, int128 rhs) {
|
||||
return static_cast<__int128>(lhs) / static_cast<__int128>(rhs);
|
||||
}
|
||||
|
||||
inline int128 operator%(int128 lhs, int128 rhs) {
|
||||
return static_cast<__int128>(lhs) % static_cast<__int128>(rhs);
|
||||
}
|
||||
|
||||
inline int128 int128::operator++(int) {
|
||||
int128 tmp(*this);
|
||||
++v_;
|
||||
return tmp;
|
||||
}
|
||||
|
||||
inline int128 int128::operator--(int) {
|
||||
int128 tmp(*this);
|
||||
--v_;
|
||||
return tmp;
|
||||
}
|
||||
|
||||
inline int128& int128::operator++() {
|
||||
++v_;
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline int128& int128::operator--() {
|
||||
--v_;
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline int128 operator|(int128 lhs, int128 rhs) {
|
||||
return static_cast<__int128>(lhs) | static_cast<__int128>(rhs);
|
||||
}
|
||||
|
||||
inline int128 operator&(int128 lhs, int128 rhs) {
|
||||
return static_cast<__int128>(lhs) & static_cast<__int128>(rhs);
|
||||
}
|
||||
|
||||
inline int128 operator^(int128 lhs, int128 rhs) {
|
||||
return static_cast<__int128>(lhs) ^ static_cast<__int128>(rhs);
|
||||
}
|
||||
|
||||
inline int128 operator<<(int128 lhs, int amount) {
|
||||
return static_cast<__int128>(lhs) << amount;
|
||||
}
|
||||
|
||||
inline int128 operator>>(int128 lhs, int amount) {
|
||||
return static_cast<__int128>(lhs) >> amount;
|
||||
}
|
308
extern/int128/absl/numeric/int128_no_intrinsic.inc
vendored
Normal file
308
extern/int128/absl/numeric/int128_no_intrinsic.inc
vendored
Normal file
@ -0,0 +1,308 @@
|
||||
//
|
||||
// Copyright 2017 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.
|
||||
|
||||
// This file contains :int128 implementation details that depend on internal
|
||||
// representation when ABSL_HAVE_INTRINSIC_INT128 is *not* defined. This file
|
||||
// is included by int128.h and relies on ABSL_INTERNAL_WCHAR_T being defined.
|
||||
|
||||
constexpr uint64_t Int128Low64(int128 v) { return v.lo_; }
|
||||
|
||||
constexpr int64_t Int128High64(int128 v) { return v.hi_; }
|
||||
|
||||
#if defined(ABSL_IS_LITTLE_ENDIAN)
|
||||
|
||||
constexpr int128::int128(int64_t high, uint64_t low) :
|
||||
lo_(low), hi_(high) {}
|
||||
|
||||
constexpr int128::int128(int v)
|
||||
: lo_{static_cast<uint64_t>(v)}, hi_{v < 0 ? ~int64_t{0} : 0} {}
|
||||
constexpr int128::int128(long v) // NOLINT(runtime/int)
|
||||
: lo_{static_cast<uint64_t>(v)}, hi_{v < 0 ? ~int64_t{0} : 0} {}
|
||||
constexpr int128::int128(long long v) // NOLINT(runtime/int)
|
||||
: lo_{static_cast<uint64_t>(v)}, hi_{v < 0 ? ~int64_t{0} : 0} {}
|
||||
|
||||
constexpr int128::int128(unsigned int v) : lo_{v}, hi_{0} {}
|
||||
// NOLINTNEXTLINE(runtime/int)
|
||||
constexpr int128::int128(unsigned long v) : lo_{v}, hi_{0} {}
|
||||
// NOLINTNEXTLINE(runtime/int)
|
||||
constexpr int128::int128(unsigned long long v) : lo_{v}, hi_{0} {}
|
||||
|
||||
constexpr int128::int128(uint128 v)
|
||||
: lo_{Uint128Low64(v)}, hi_{static_cast<int64_t>(Uint128High64(v))} {}
|
||||
|
||||
#elif defined(ABSL_IS_BIG_ENDIAN)
|
||||
|
||||
constexpr int128::int128(int64_t high, uint64_t low) :
|
||||
hi_{high}, lo_{low} {}
|
||||
|
||||
constexpr int128::int128(int v)
|
||||
: hi_{v < 0 ? ~int64_t{0} : 0}, lo_{static_cast<uint64_t>(v)} {}
|
||||
constexpr int128::int128(long v) // NOLINT(runtime/int)
|
||||
: hi_{v < 0 ? ~int64_t{0} : 0}, lo_{static_cast<uint64_t>(v)} {}
|
||||
constexpr int128::int128(long long v) // NOLINT(runtime/int)
|
||||
: hi_{v < 0 ? ~int64_t{0} : 0}, lo_{static_cast<uint64_t>(v)} {}
|
||||
|
||||
constexpr int128::int128(unsigned int v) : hi_{0}, lo_{v} {}
|
||||
// NOLINTNEXTLINE(runtime/int)
|
||||
constexpr int128::int128(unsigned long v) : hi_{0}, lo_{v} {}
|
||||
// NOLINTNEXTLINE(runtime/int)
|
||||
constexpr int128::int128(unsigned long long v) : hi_{0}, lo_{v} {}
|
||||
|
||||
constexpr int128::int128(uint128 v)
|
||||
: hi_{static_cast<int64_t>(Uint128High64(v))}, lo_{Uint128Low64(v)} {}
|
||||
|
||||
#else // byte order
|
||||
#error "Unsupported byte order: must be little-endian or big-endian."
|
||||
#endif // byte order
|
||||
|
||||
constexpr int128::operator bool() const { return lo_ || hi_; }
|
||||
|
||||
constexpr int128::operator char() const {
|
||||
// NOLINTNEXTLINE(runtime/int)
|
||||
return static_cast<char>(static_cast<long long>(*this));
|
||||
}
|
||||
|
||||
constexpr int128::operator signed char() const {
|
||||
// NOLINTNEXTLINE(runtime/int)
|
||||
return static_cast<signed char>(static_cast<long long>(*this));
|
||||
}
|
||||
|
||||
constexpr int128::operator unsigned char() const {
|
||||
return static_cast<unsigned char>(lo_);
|
||||
}
|
||||
|
||||
constexpr int128::operator char16_t() const {
|
||||
return static_cast<char16_t>(lo_);
|
||||
}
|
||||
|
||||
constexpr int128::operator char32_t() const {
|
||||
return static_cast<char32_t>(lo_);
|
||||
}
|
||||
|
||||
constexpr int128::operator ABSL_INTERNAL_WCHAR_T() const {
|
||||
// NOLINTNEXTLINE(runtime/int)
|
||||
return static_cast<ABSL_INTERNAL_WCHAR_T>(static_cast<long long>(*this));
|
||||
}
|
||||
|
||||
constexpr int128::operator short() const { // NOLINT(runtime/int)
|
||||
// NOLINTNEXTLINE(runtime/int)
|
||||
return static_cast<short>(static_cast<long long>(*this));
|
||||
}
|
||||
|
||||
constexpr int128::operator unsigned short() const { // NOLINT(runtime/int)
|
||||
return static_cast<unsigned short>(lo_); // NOLINT(runtime/int)
|
||||
}
|
||||
|
||||
constexpr int128::operator int() const {
|
||||
// NOLINTNEXTLINE(runtime/int)
|
||||
return static_cast<int>(static_cast<long long>(*this));
|
||||
}
|
||||
|
||||
constexpr int128::operator unsigned int() const {
|
||||
return static_cast<unsigned int>(lo_);
|
||||
}
|
||||
|
||||
constexpr int128::operator long() const { // NOLINT(runtime/int)
|
||||
// NOLINTNEXTLINE(runtime/int)
|
||||
return static_cast<long>(static_cast<long long>(*this));
|
||||
}
|
||||
|
||||
constexpr int128::operator unsigned long() const { // NOLINT(runtime/int)
|
||||
return static_cast<unsigned long>(lo_); // NOLINT(runtime/int)
|
||||
}
|
||||
|
||||
constexpr int128::operator long long() const { // NOLINT(runtime/int)
|
||||
// We don't bother checking the value of hi_. If *this < 0, lo_'s high bit
|
||||
// must be set in order for the value to fit into a long long. Conversely, if
|
||||
// lo_'s high bit is set, *this must be < 0 for the value to fit.
|
||||
return int128_internal::BitCastToSigned(lo_);
|
||||
}
|
||||
|
||||
constexpr int128::operator unsigned long long() const { // NOLINT(runtime/int)
|
||||
return static_cast<unsigned long long>(lo_); // NOLINT(runtime/int)
|
||||
}
|
||||
|
||||
// Forward declaration for conversion operators to floating point types.
|
||||
int128 operator-(int128 v);
|
||||
bool operator!=(int128 lhs, int128 rhs);
|
||||
|
||||
inline int128::operator float() const {
|
||||
// We must convert the absolute value and then negate as needed, because
|
||||
// floating point types are typically sign-magnitude. Otherwise, the
|
||||
// difference between the high and low 64 bits when interpreted as two's
|
||||
// complement overwhelms the precision of the mantissa.
|
||||
//
|
||||
// Also check to make sure we don't negate Int128Min()
|
||||
return hi_ < 0 && *this != Int128Min()
|
||||
? -static_cast<float>(-*this)
|
||||
: static_cast<float>(lo_) +
|
||||
std::ldexp(static_cast<float>(hi_), 64);
|
||||
}
|
||||
|
||||
inline int128::operator double() const {
|
||||
// See comment in int128::operator float() above.
|
||||
return hi_ < 0 && *this != Int128Min()
|
||||
? -static_cast<double>(-*this)
|
||||
: static_cast<double>(lo_) +
|
||||
std::ldexp(static_cast<double>(hi_), 64);
|
||||
}
|
||||
|
||||
inline int128::operator long double() const {
|
||||
// See comment in int128::operator float() above.
|
||||
return hi_ < 0 && *this != Int128Min()
|
||||
? -static_cast<long double>(-*this)
|
||||
: static_cast<long double>(lo_) +
|
||||
std::ldexp(static_cast<long double>(hi_), 64);
|
||||
}
|
||||
|
||||
// Comparison operators.
|
||||
|
||||
inline bool operator==(int128 lhs, int128 rhs) {
|
||||
return (Int128Low64(lhs) == Int128Low64(rhs) &&
|
||||
Int128High64(lhs) == Int128High64(rhs));
|
||||
}
|
||||
|
||||
inline bool operator!=(int128 lhs, int128 rhs) {
|
||||
return !(lhs == rhs);
|
||||
}
|
||||
|
||||
inline bool operator<(int128 lhs, int128 rhs) {
|
||||
return (Int128High64(lhs) == Int128High64(rhs))
|
||||
? (Int128Low64(lhs) < Int128Low64(rhs))
|
||||
: (Int128High64(lhs) < Int128High64(rhs));
|
||||
}
|
||||
|
||||
inline bool operator>(int128 lhs, int128 rhs) {
|
||||
return (Int128High64(lhs) == Int128High64(rhs))
|
||||
? (Int128Low64(lhs) > Int128Low64(rhs))
|
||||
: (Int128High64(lhs) > Int128High64(rhs));
|
||||
}
|
||||
|
||||
inline bool operator<=(int128 lhs, int128 rhs) {
|
||||
return !(lhs > rhs);
|
||||
}
|
||||
|
||||
inline bool operator>=(int128 lhs, int128 rhs) {
|
||||
return !(lhs < rhs);
|
||||
}
|
||||
|
||||
// Unary operators.
|
||||
|
||||
inline int128 operator-(int128 v) {
|
||||
int64_t hi = ~Int128High64(v);
|
||||
uint64_t lo = ~Int128Low64(v) + 1;
|
||||
if (lo == 0) ++hi; // carry
|
||||
return MakeInt128(hi, lo);
|
||||
}
|
||||
|
||||
inline bool operator!(int128 v) {
|
||||
return !Int128Low64(v) && !Int128High64(v);
|
||||
}
|
||||
|
||||
inline int128 operator~(int128 val) {
|
||||
return MakeInt128(~Int128High64(val), ~Int128Low64(val));
|
||||
}
|
||||
|
||||
// Arithmetic operators.
|
||||
|
||||
inline int128 operator+(int128 lhs, int128 rhs) {
|
||||
int128 result = MakeInt128(Int128High64(lhs) + Int128High64(rhs),
|
||||
Int128Low64(lhs) + Int128Low64(rhs));
|
||||
if (Int128Low64(result) < Int128Low64(lhs)) { // check for carry
|
||||
return MakeInt128(Int128High64(result) + 1, Int128Low64(result));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
inline int128 operator-(int128 lhs, int128 rhs) {
|
||||
int128 result = MakeInt128(Int128High64(lhs) - Int128High64(rhs),
|
||||
Int128Low64(lhs) - Int128Low64(rhs));
|
||||
if (Int128Low64(lhs) < Int128Low64(rhs)) { // check for carry
|
||||
return MakeInt128(Int128High64(result) - 1, Int128Low64(result));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
inline int128 operator*(int128 lhs, int128 rhs) {
|
||||
uint128 result = uint128(lhs) * rhs;
|
||||
return MakeInt128(int128_internal::BitCastToSigned(Uint128High64(result)),
|
||||
Uint128Low64(result));
|
||||
}
|
||||
|
||||
inline int128 int128::operator++(int) {
|
||||
int128 tmp(*this);
|
||||
*this += 1;
|
||||
return tmp;
|
||||
}
|
||||
|
||||
inline int128 int128::operator--(int) {
|
||||
int128 tmp(*this);
|
||||
*this -= 1;
|
||||
return tmp;
|
||||
}
|
||||
|
||||
inline int128& int128::operator++() {
|
||||
*this += 1;
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline int128& int128::operator--() {
|
||||
*this -= 1;
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline int128 operator|(int128 lhs, int128 rhs) {
|
||||
return MakeInt128(Int128High64(lhs) | Int128High64(rhs),
|
||||
Int128Low64(lhs) | Int128Low64(rhs));
|
||||
}
|
||||
|
||||
inline int128 operator&(int128 lhs, int128 rhs) {
|
||||
return MakeInt128(Int128High64(lhs) & Int128High64(rhs),
|
||||
Int128Low64(lhs) & Int128Low64(rhs));
|
||||
}
|
||||
|
||||
inline int128 operator^(int128 lhs, int128 rhs) {
|
||||
return MakeInt128(Int128High64(lhs) ^ Int128High64(rhs),
|
||||
Int128Low64(lhs) ^ Int128Low64(rhs));
|
||||
}
|
||||
|
||||
inline int128 operator<<(int128 lhs, int amount) {
|
||||
// uint64_t shifts of >= 64 are undefined, so we need some special-casing.
|
||||
if (amount < 64) {
|
||||
if (amount != 0) {
|
||||
return MakeInt128(
|
||||
(Int128High64(lhs) << amount) |
|
||||
static_cast<int64_t>(Int128Low64(lhs) >> (64 - amount)),
|
||||
Int128Low64(lhs) << amount);
|
||||
}
|
||||
return lhs;
|
||||
}
|
||||
return MakeInt128(static_cast<int64_t>(Int128Low64(lhs) << (amount - 64)), 0);
|
||||
}
|
||||
|
||||
inline int128 operator>>(int128 lhs, int amount) {
|
||||
// uint64_t shifts of >= 64 are undefined, so we need some special-casing.
|
||||
if (amount < 64) {
|
||||
if (amount != 0) {
|
||||
return MakeInt128(
|
||||
Int128High64(lhs) >> amount,
|
||||
(Int128Low64(lhs) >> amount) |
|
||||
(static_cast<uint64_t>(Int128High64(lhs)) << (64 - amount)));
|
||||
}
|
||||
return lhs;
|
||||
}
|
||||
return MakeInt128(0,
|
||||
static_cast<uint64_t>(Int128High64(lhs) >> (amount - 64)));
|
||||
}
|
358
extern/int128/absl/numeric/internal/bits.h
vendored
Normal file
358
extern/int128/absl/numeric/internal/bits.h
vendored
Normal file
@ -0,0 +1,358 @@
|
||||
// Copyright 2020 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.
|
||||
|
||||
#ifndef ABSL_NUMERIC_INTERNAL_BITS_H_
|
||||
#define ABSL_NUMERIC_INTERNAL_BITS_H_
|
||||
|
||||
#include <cstdint>
|
||||
#include <limits>
|
||||
#include <type_traits>
|
||||
|
||||
// Clang on Windows has __builtin_clzll; otherwise we need to use the
|
||||
// windows intrinsic functions.
|
||||
#if defined(_MSC_VER) && !defined(__clang__)
|
||||
#include <intrin.h>
|
||||
#endif
|
||||
|
||||
#include "absl/base/attributes.h"
|
||||
#include "absl/base/config.h"
|
||||
|
||||
#if defined(__GNUC__) && !defined(__clang__)
|
||||
// GCC
|
||||
#define ABSL_NUMERIC_INTERNAL_HAVE_BUILTIN_OR_GCC(x) 1
|
||||
#else
|
||||
#define ABSL_NUMERIC_INTERNAL_HAVE_BUILTIN_OR_GCC(x) ABSL_HAVE_BUILTIN(x)
|
||||
#endif
|
||||
|
||||
#if ABSL_NUMERIC_INTERNAL_HAVE_BUILTIN_OR_GCC(__builtin_popcountl) && \
|
||||
ABSL_NUMERIC_INTERNAL_HAVE_BUILTIN_OR_GCC(__builtin_popcountll)
|
||||
#define ABSL_INTERNAL_CONSTEXPR_POPCOUNT constexpr
|
||||
#define ABSL_INTERNAL_HAS_CONSTEXPR_POPCOUNT 1
|
||||
#else
|
||||
#define ABSL_INTERNAL_CONSTEXPR_POPCOUNT
|
||||
#define ABSL_INTERNAL_HAS_CONSTEXPR_POPCOUNT 0
|
||||
#endif
|
||||
|
||||
#if ABSL_NUMERIC_INTERNAL_HAVE_BUILTIN_OR_GCC(__builtin_clz) && \
|
||||
ABSL_NUMERIC_INTERNAL_HAVE_BUILTIN_OR_GCC(__builtin_clzll)
|
||||
#define ABSL_INTERNAL_CONSTEXPR_CLZ constexpr
|
||||
#define ABSL_INTERNAL_HAS_CONSTEXPR_CLZ 1
|
||||
#else
|
||||
#define ABSL_INTERNAL_CONSTEXPR_CLZ
|
||||
#define ABSL_INTERNAL_HAS_CONSTEXPR_CLZ 0
|
||||
#endif
|
||||
|
||||
#if ABSL_NUMERIC_INTERNAL_HAVE_BUILTIN_OR_GCC(__builtin_ctz) && \
|
||||
ABSL_NUMERIC_INTERNAL_HAVE_BUILTIN_OR_GCC(__builtin_ctzll)
|
||||
#define ABSL_INTERNAL_CONSTEXPR_CTZ constexpr
|
||||
#define ABSL_INTERNAL_HAS_CONSTEXPR_CTZ 1
|
||||
#else
|
||||
#define ABSL_INTERNAL_CONSTEXPR_CTZ
|
||||
#define ABSL_INTERNAL_HAS_CONSTEXPR_CTZ 0
|
||||
#endif
|
||||
|
||||
namespace absl {
|
||||
ABSL_NAMESPACE_BEGIN
|
||||
namespace numeric_internal {
|
||||
|
||||
constexpr bool IsPowerOf2(unsigned int x) noexcept {
|
||||
return x != 0 && (x & (x - 1)) == 0;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
ABSL_MUST_USE_RESULT ABSL_ATTRIBUTE_ALWAYS_INLINE constexpr T RotateRight(
|
||||
T x, int s) noexcept {
|
||||
static_assert(std::is_unsigned<T>::value, "T must be unsigned");
|
||||
static_assert(IsPowerOf2(std::numeric_limits<T>::digits),
|
||||
"T must have a power-of-2 size");
|
||||
|
||||
return static_cast<T>(x >> (s & (std::numeric_limits<T>::digits - 1))) |
|
||||
static_cast<T>(x << ((-s) & (std::numeric_limits<T>::digits - 1)));
|
||||
}
|
||||
|
||||
template <class T>
|
||||
ABSL_MUST_USE_RESULT ABSL_ATTRIBUTE_ALWAYS_INLINE constexpr T RotateLeft(
|
||||
T x, int s) noexcept {
|
||||
static_assert(std::is_unsigned<T>::value, "T must be unsigned");
|
||||
static_assert(IsPowerOf2(std::numeric_limits<T>::digits),
|
||||
"T must have a power-of-2 size");
|
||||
|
||||
return static_cast<T>(x << (s & (std::numeric_limits<T>::digits - 1))) |
|
||||
static_cast<T>(x >> ((-s) & (std::numeric_limits<T>::digits - 1)));
|
||||
}
|
||||
|
||||
ABSL_ATTRIBUTE_ALWAYS_INLINE ABSL_INTERNAL_CONSTEXPR_POPCOUNT inline int
|
||||
Popcount32(uint32_t x) noexcept {
|
||||
#if ABSL_NUMERIC_INTERNAL_HAVE_BUILTIN_OR_GCC(__builtin_popcount)
|
||||
static_assert(sizeof(unsigned int) == sizeof(x),
|
||||
"__builtin_popcount does not take 32-bit arg");
|
||||
return __builtin_popcount(x);
|
||||
#else
|
||||
x -= ((x >> 1) & 0x55555555);
|
||||
x = ((x >> 2) & 0x33333333) + (x & 0x33333333);
|
||||
return static_cast<int>((((x + (x >> 4)) & 0xF0F0F0F) * 0x1010101) >> 24);
|
||||
#endif
|
||||
}
|
||||
|
||||
ABSL_ATTRIBUTE_ALWAYS_INLINE ABSL_INTERNAL_CONSTEXPR_POPCOUNT inline int
|
||||
Popcount64(uint64_t x) noexcept {
|
||||
#if ABSL_NUMERIC_INTERNAL_HAVE_BUILTIN_OR_GCC(__builtin_popcountll)
|
||||
static_assert(sizeof(unsigned long long) == sizeof(x), // NOLINT(runtime/int)
|
||||
"__builtin_popcount does not take 64-bit arg");
|
||||
return __builtin_popcountll(x);
|
||||
#else
|
||||
x -= (x >> 1) & 0x5555555555555555ULL;
|
||||
x = ((x >> 2) & 0x3333333333333333ULL) + (x & 0x3333333333333333ULL);
|
||||
return static_cast<int>(
|
||||
(((x + (x >> 4)) & 0xF0F0F0F0F0F0F0FULL) * 0x101010101010101ULL) >> 56);
|
||||
#endif
|
||||
}
|
||||
|
||||
template <class T>
|
||||
ABSL_ATTRIBUTE_ALWAYS_INLINE ABSL_INTERNAL_CONSTEXPR_POPCOUNT inline int
|
||||
Popcount(T x) noexcept {
|
||||
static_assert(std::is_unsigned<T>::value, "T must be unsigned");
|
||||
static_assert(IsPowerOf2(std::numeric_limits<T>::digits),
|
||||
"T must have a power-of-2 size");
|
||||
static_assert(sizeof(x) <= sizeof(uint64_t), "T is too large");
|
||||
return sizeof(x) <= sizeof(uint32_t) ? Popcount32(x) : Popcount64(x);
|
||||
}
|
||||
|
||||
ABSL_ATTRIBUTE_ALWAYS_INLINE ABSL_INTERNAL_CONSTEXPR_CLZ inline int
|
||||
CountLeadingZeroes32(uint32_t x) {
|
||||
#if ABSL_NUMERIC_INTERNAL_HAVE_BUILTIN_OR_GCC(__builtin_clz)
|
||||
// Use __builtin_clz, which uses the following instructions:
|
||||
// x86: bsr, lzcnt
|
||||
// ARM64: clz
|
||||
// PPC: cntlzd
|
||||
|
||||
static_assert(sizeof(unsigned int) == sizeof(x),
|
||||
"__builtin_clz does not take 32-bit arg");
|
||||
// Handle 0 as a special case because __builtin_clz(0) is undefined.
|
||||
return x == 0 ? 32 : __builtin_clz(x);
|
||||
#elif defined(_MSC_VER) && !defined(__clang__)
|
||||
unsigned long result = 0; // NOLINT(runtime/int)
|
||||
if (_BitScanReverse(&result, x)) {
|
||||
return 31 - result;
|
||||
}
|
||||
return 32;
|
||||
#else
|
||||
int zeroes = 28;
|
||||
if (x >> 16) {
|
||||
zeroes -= 16;
|
||||
x >>= 16;
|
||||
}
|
||||
if (x >> 8) {
|
||||
zeroes -= 8;
|
||||
x >>= 8;
|
||||
}
|
||||
if (x >> 4) {
|
||||
zeroes -= 4;
|
||||
x >>= 4;
|
||||
}
|
||||
return "\4\3\2\2\1\1\1\1\0\0\0\0\0\0\0"[x] + zeroes;
|
||||
#endif
|
||||
}
|
||||
|
||||
ABSL_ATTRIBUTE_ALWAYS_INLINE ABSL_INTERNAL_CONSTEXPR_CLZ inline int
|
||||
CountLeadingZeroes16(uint16_t x) {
|
||||
#if ABSL_HAVE_BUILTIN(__builtin_clzs)
|
||||
static_assert(sizeof(unsigned short) == sizeof(x), // NOLINT(runtime/int)
|
||||
"__builtin_clzs does not take 16-bit arg");
|
||||
return x == 0 ? 16 : __builtin_clzs(x);
|
||||
#else
|
||||
return CountLeadingZeroes32(x) - 16;
|
||||
#endif
|
||||
}
|
||||
|
||||
ABSL_ATTRIBUTE_ALWAYS_INLINE ABSL_INTERNAL_CONSTEXPR_CLZ inline int
|
||||
CountLeadingZeroes64(uint64_t x) {
|
||||
#if ABSL_NUMERIC_INTERNAL_HAVE_BUILTIN_OR_GCC(__builtin_clzll)
|
||||
// Use __builtin_clzll, which uses the following instructions:
|
||||
// x86: bsr, lzcnt
|
||||
// ARM64: clz
|
||||
// PPC: cntlzd
|
||||
static_assert(sizeof(unsigned long long) == sizeof(x), // NOLINT(runtime/int)
|
||||
"__builtin_clzll does not take 64-bit arg");
|
||||
|
||||
// Handle 0 as a special case because __builtin_clzll(0) is undefined.
|
||||
return x == 0 ? 64 : __builtin_clzll(x);
|
||||
#elif defined(_MSC_VER) && !defined(__clang__) && \
|
||||
(defined(_M_X64) || defined(_M_ARM64))
|
||||
// MSVC does not have __buitin_clzll. Use _BitScanReverse64.
|
||||
unsigned long result = 0; // NOLINT(runtime/int)
|
||||
if (_BitScanReverse64(&result, x)) {
|
||||
return 63 - result;
|
||||
}
|
||||
return 64;
|
||||
#elif defined(_MSC_VER) && !defined(__clang__)
|
||||
// MSVC does not have __buitin_clzll. Compose two calls to _BitScanReverse
|
||||
unsigned long result = 0; // NOLINT(runtime/int)
|
||||
if ((x >> 32) &&
|
||||
_BitScanReverse(&result, static_cast<unsigned long>(x >> 32))) {
|
||||
return 31 - result;
|
||||
}
|
||||
if (_BitScanReverse(&result, static_cast<unsigned long>(x))) {
|
||||
return 63 - result;
|
||||
}
|
||||
return 64;
|
||||
#else
|
||||
int zeroes = 60;
|
||||
if (x >> 32) {
|
||||
zeroes -= 32;
|
||||
x >>= 32;
|
||||
}
|
||||
if (x >> 16) {
|
||||
zeroes -= 16;
|
||||
x >>= 16;
|
||||
}
|
||||
if (x >> 8) {
|
||||
zeroes -= 8;
|
||||
x >>= 8;
|
||||
}
|
||||
if (x >> 4) {
|
||||
zeroes -= 4;
|
||||
x >>= 4;
|
||||
}
|
||||
return "\4\3\2\2\1\1\1\1\0\0\0\0\0\0\0"[x] + zeroes;
|
||||
#endif
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
ABSL_ATTRIBUTE_ALWAYS_INLINE ABSL_INTERNAL_CONSTEXPR_CLZ inline int
|
||||
CountLeadingZeroes(T x) {
|
||||
static_assert(std::is_unsigned<T>::value, "T must be unsigned");
|
||||
static_assert(IsPowerOf2(std::numeric_limits<T>::digits),
|
||||
"T must have a power-of-2 size");
|
||||
static_assert(sizeof(T) <= sizeof(uint64_t), "T too large");
|
||||
return sizeof(T) <= sizeof(uint16_t)
|
||||
? CountLeadingZeroes16(static_cast<uint16_t>(x)) -
|
||||
(std::numeric_limits<uint16_t>::digits -
|
||||
std::numeric_limits<T>::digits)
|
||||
: (sizeof(T) <= sizeof(uint32_t)
|
||||
? CountLeadingZeroes32(static_cast<uint32_t>(x)) -
|
||||
(std::numeric_limits<uint32_t>::digits -
|
||||
std::numeric_limits<T>::digits)
|
||||
: CountLeadingZeroes64(x));
|
||||
}
|
||||
|
||||
ABSL_ATTRIBUTE_ALWAYS_INLINE ABSL_INTERNAL_CONSTEXPR_CTZ inline int
|
||||
CountTrailingZeroesNonzero32(uint32_t x) {
|
||||
#if ABSL_NUMERIC_INTERNAL_HAVE_BUILTIN_OR_GCC(__builtin_ctz)
|
||||
static_assert(sizeof(unsigned int) == sizeof(x),
|
||||
"__builtin_ctz does not take 32-bit arg");
|
||||
return __builtin_ctz(x);
|
||||
#elif defined(_MSC_VER) && !defined(__clang__)
|
||||
unsigned long result = 0; // NOLINT(runtime/int)
|
||||
_BitScanForward(&result, x);
|
||||
return result;
|
||||
#else
|
||||
int c = 31;
|
||||
x &= ~x + 1;
|
||||
if (x & 0x0000FFFF) c -= 16;
|
||||
if (x & 0x00FF00FF) c -= 8;
|
||||
if (x & 0x0F0F0F0F) c -= 4;
|
||||
if (x & 0x33333333) c -= 2;
|
||||
if (x & 0x55555555) c -= 1;
|
||||
return c;
|
||||
#endif
|
||||
}
|
||||
|
||||
ABSL_ATTRIBUTE_ALWAYS_INLINE ABSL_INTERNAL_CONSTEXPR_CTZ inline int
|
||||
CountTrailingZeroesNonzero64(uint64_t x) {
|
||||
#if ABSL_NUMERIC_INTERNAL_HAVE_BUILTIN_OR_GCC(__builtin_ctzll)
|
||||
static_assert(sizeof(unsigned long long) == sizeof(x), // NOLINT(runtime/int)
|
||||
"__builtin_ctzll does not take 64-bit arg");
|
||||
return __builtin_ctzll(x);
|
||||
#elif defined(_MSC_VER) && !defined(__clang__) && \
|
||||
(defined(_M_X64) || defined(_M_ARM64))
|
||||
unsigned long result = 0; // NOLINT(runtime/int)
|
||||
_BitScanForward64(&result, x);
|
||||
return result;
|
||||
#elif defined(_MSC_VER) && !defined(__clang__)
|
||||
unsigned long result = 0; // NOLINT(runtime/int)
|
||||
if (static_cast<uint32_t>(x) == 0) {
|
||||
_BitScanForward(&result, static_cast<unsigned long>(x >> 32));
|
||||
return result + 32;
|
||||
}
|
||||
_BitScanForward(&result, static_cast<unsigned long>(x));
|
||||
return result;
|
||||
#else
|
||||
int c = 63;
|
||||
x &= ~x + 1;
|
||||
if (x & 0x00000000FFFFFFFF) c -= 32;
|
||||
if (x & 0x0000FFFF0000FFFF) c -= 16;
|
||||
if (x & 0x00FF00FF00FF00FF) c -= 8;
|
||||
if (x & 0x0F0F0F0F0F0F0F0F) c -= 4;
|
||||
if (x & 0x3333333333333333) c -= 2;
|
||||
if (x & 0x5555555555555555) c -= 1;
|
||||
return c;
|
||||
#endif
|
||||
}
|
||||
|
||||
ABSL_ATTRIBUTE_ALWAYS_INLINE ABSL_INTERNAL_CONSTEXPR_CTZ inline int
|
||||
CountTrailingZeroesNonzero16(uint16_t x) {
|
||||
#if ABSL_HAVE_BUILTIN(__builtin_ctzs)
|
||||
static_assert(sizeof(unsigned short) == sizeof(x), // NOLINT(runtime/int)
|
||||
"__builtin_ctzs does not take 16-bit arg");
|
||||
return __builtin_ctzs(x);
|
||||
#else
|
||||
return CountTrailingZeroesNonzero32(x);
|
||||
#endif
|
||||
}
|
||||
|
||||
template <class T>
|
||||
ABSL_ATTRIBUTE_ALWAYS_INLINE ABSL_INTERNAL_CONSTEXPR_CTZ inline int
|
||||
CountTrailingZeroes(T x) noexcept {
|
||||
static_assert(std::is_unsigned<T>::value, "T must be unsigned");
|
||||
static_assert(IsPowerOf2(std::numeric_limits<T>::digits),
|
||||
"T must have a power-of-2 size");
|
||||
static_assert(sizeof(T) <= sizeof(uint64_t), "T too large");
|
||||
return x == 0 ? std::numeric_limits<T>::digits
|
||||
: (sizeof(T) <= sizeof(uint16_t)
|
||||
? CountTrailingZeroesNonzero16(static_cast<uint16_t>(x))
|
||||
: (sizeof(T) <= sizeof(uint32_t)
|
||||
? CountTrailingZeroesNonzero32(
|
||||
static_cast<uint32_t>(x))
|
||||
: CountTrailingZeroesNonzero64(x)));
|
||||
}
|
||||
|
||||
// If T is narrower than unsigned, T{1} << bit_width will be promoted. We
|
||||
// want to force it to wraparound so that bit_ceil of an invalid value are not
|
||||
// core constant expressions.
|
||||
template <class T>
|
||||
ABSL_ATTRIBUTE_ALWAYS_INLINE ABSL_INTERNAL_CONSTEXPR_CLZ inline
|
||||
typename std::enable_if<std::is_unsigned<T>::value, T>::type
|
||||
BitCeilPromotionHelper(T x, T promotion) {
|
||||
return (T{1} << (x + promotion)) >> promotion;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
ABSL_ATTRIBUTE_ALWAYS_INLINE ABSL_INTERNAL_CONSTEXPR_CLZ inline
|
||||
typename std::enable_if<std::is_unsigned<T>::value, T>::type
|
||||
BitCeilNonPowerOf2(T x) {
|
||||
// If T is narrower than unsigned, it undergoes promotion to unsigned when we
|
||||
// shift. We calculate the number of bits added by the wider type.
|
||||
return BitCeilPromotionHelper(
|
||||
static_cast<T>(std::numeric_limits<T>::digits - CountLeadingZeroes(x)),
|
||||
T{sizeof(T) >= sizeof(unsigned) ? 0
|
||||
: std::numeric_limits<unsigned>::digits -
|
||||
std::numeric_limits<T>::digits});
|
||||
}
|
||||
|
||||
} // namespace numeric_internal
|
||||
ABSL_NAMESPACE_END
|
||||
} // namespace absl
|
||||
|
||||
#endif // ABSL_NUMERIC_INTERNAL_BITS_H_
|
55
extern/int128/absl/numeric/internal/representation.h
vendored
Normal file
55
extern/int128/absl/numeric/internal/representation.h
vendored
Normal file
@ -0,0 +1,55 @@
|
||||
// Copyright 2021 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.
|
||||
|
||||
#ifndef ABSL_NUMERIC_INTERNAL_REPRESENTATION_H_
|
||||
#define ABSL_NUMERIC_INTERNAL_REPRESENTATION_H_
|
||||
|
||||
#include <limits>
|
||||
|
||||
#include "absl/base/config.h"
|
||||
|
||||
namespace absl {
|
||||
ABSL_NAMESPACE_BEGIN
|
||||
namespace numeric_internal {
|
||||
|
||||
// Returns true iff long double is represented as a pair of doubles added
|
||||
// together.
|
||||
inline constexpr bool IsDoubleDouble() {
|
||||
// A double-double value always has exactly twice the precision of a double
|
||||
// value--one double carries the high digits and one double carries the low
|
||||
// digits. This property is not shared with any other common floating-point
|
||||
// representation, so this test won't trigger false positives. For reference,
|
||||
// this table gives the number of bits of precision of each common
|
||||
// floating-point representation:
|
||||
//
|
||||
// type precision
|
||||
// IEEE single 24 b
|
||||
// IEEE double 53
|
||||
// x86 long double 64
|
||||
// double-double 106
|
||||
// IEEE quadruple 113
|
||||
//
|
||||
// Note in particular that a quadruple-precision float has greater precision
|
||||
// than a double-double float despite taking up the same amount of memory; the
|
||||
// quad has more of its bits allocated to the mantissa than the double-double
|
||||
// has.
|
||||
return std::numeric_limits<long double>::digits ==
|
||||
2 * std::numeric_limits<double>::digits;
|
||||
}
|
||||
|
||||
} // namespace numeric_internal
|
||||
ABSL_NAMESPACE_END
|
||||
} // namespace absl
|
||||
|
||||
#endif // ABSL_NUMERIC_INTERNAL_REPRESENTATION_H_
|
BIN
extern/int128/absl/numeric/libi128.a
vendored
Normal file
BIN
extern/int128/absl/numeric/libi128.a
vendored
Normal file
Binary file not shown.
@ -42,6 +42,249 @@
|
||||
|
||||
using namespace Firebird;
|
||||
|
||||
#ifdef FB_USE_ABSEIL_INT128
|
||||
|
||||
namespace {
|
||||
|
||||
const CInt128 i64max(MAX_SINT64), i64min(MIN_SINT64);
|
||||
const double p2_32 = 4294967296.0;
|
||||
const I128limit i128limit;
|
||||
const CInt128 minus1(-1);
|
||||
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
|
||||
namespace Firebird {
|
||||
|
||||
Int128 Int128::set(const char* value)
|
||||
{
|
||||
// This is simplified method - it does not perform all what's needed for CVT_decompose
|
||||
for (v = 0; ; ++value)
|
||||
{
|
||||
if (*value < '0' or *value > '9')
|
||||
break;
|
||||
|
||||
v *= 10;
|
||||
v += (*value - '0');
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
Int128 Int128::set(DecimalStatus decSt, Decimal128 value)
|
||||
{
|
||||
static CDecimal128 quant(1);
|
||||
value = value.quantize(decSt, quant);
|
||||
|
||||
Decimal128::BCD bcd;
|
||||
value.getBcd(&bcd);
|
||||
fb_assert(bcd.exp == 0);
|
||||
|
||||
v = 0;
|
||||
for (unsigned b = 0; b < sizeof(bcd.bcd); ++b)
|
||||
{
|
||||
v *= 10;
|
||||
v += bcd.bcd[b];
|
||||
}
|
||||
if (bcd.sign < 0)
|
||||
v = -v;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
void Int128::setScale(int scale)
|
||||
{
|
||||
if (scale > 0)
|
||||
{
|
||||
int rem = 0;
|
||||
while (scale--)
|
||||
{
|
||||
if (scale == 0)
|
||||
rem = int(v % 10);
|
||||
v /= 10;
|
||||
}
|
||||
|
||||
if (rem > 4)
|
||||
v++;
|
||||
else if (rem < -4)
|
||||
v--;
|
||||
}
|
||||
else if (scale < 0)
|
||||
{
|
||||
while (scale++) {
|
||||
if (v > i128limit.v || v < -i128limit.v)
|
||||
(Arg::Gds(isc_arith_except) << Arg::Gds(isc_numeric_out_of_range)).raise();
|
||||
v *= 10;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Int128::toString(int scale, unsigned length, char* to) const
|
||||
{
|
||||
string buffer;
|
||||
toString(scale, buffer);
|
||||
if (buffer.length() + 1 > length)
|
||||
{
|
||||
(Arg::Gds(isc_arith_except) << Arg::Gds(isc_string_truncation) <<
|
||||
Arg::Gds(isc_trunc_limits) << Arg::Num(length) << Arg::Num(buffer.length() + 1)).raise();
|
||||
}
|
||||
buffer.copyTo(to, length);
|
||||
}
|
||||
|
||||
void Int128::toString(int scale, string& to) const
|
||||
{
|
||||
to.erase();
|
||||
absl::int128 vv = v;
|
||||
|
||||
bool sgn = (vv < 0);
|
||||
if (sgn)
|
||||
vv = -vv;
|
||||
|
||||
while (vv > 0)
|
||||
{
|
||||
int dig = int(vv % 10);
|
||||
to.insert(string::size_type(0), string::size_type(1), char(dig + '0'));
|
||||
vv /= 10;
|
||||
}
|
||||
|
||||
if (to.isEmpty())
|
||||
to = "0";
|
||||
|
||||
if (scale)
|
||||
{
|
||||
if (scale < -38 || scale > 4)
|
||||
{
|
||||
string tmp;
|
||||
tmp.printf("E%d", scale);
|
||||
to += tmp;
|
||||
}
|
||||
else if (scale > 0)
|
||||
{
|
||||
string tmp(scale, '0');
|
||||
to += tmp;
|
||||
}
|
||||
else
|
||||
{
|
||||
unsigned posScale = -scale;
|
||||
if (posScale > to.length())
|
||||
{
|
||||
string tmp(posScale - to.length(), '0');
|
||||
to.insert(0, tmp);
|
||||
}
|
||||
if (posScale == to.length())
|
||||
{
|
||||
to.insert(0, "0.");
|
||||
}
|
||||
else
|
||||
to.insert(to.length() - posScale, ".");
|
||||
}
|
||||
}
|
||||
|
||||
if (sgn)
|
||||
to.insert(0, "-");
|
||||
}
|
||||
|
||||
Int128 Int128::abs() const
|
||||
{
|
||||
if (compare(MIN_Int128) == 0)
|
||||
overflow();
|
||||
|
||||
Int128 rc;
|
||||
rc.v = v < 0 ? -v : v;
|
||||
return rc;
|
||||
}
|
||||
|
||||
Int128 Int128::neg() const
|
||||
{
|
||||
if (compare(MIN_Int128) == 0)
|
||||
overflow();
|
||||
|
||||
Int128 rc;
|
||||
rc.v = -v;
|
||||
return rc;
|
||||
}
|
||||
|
||||
Int128 Int128::div(Int128 op2, int scale) const
|
||||
{
|
||||
if (compare(MIN_Int128) == 0 && op2.compare(minus1) == 0)
|
||||
Arg::Gds(isc_exception_integer_overflow).raise();
|
||||
|
||||
if (op2.v == 0)
|
||||
zerodivide();
|
||||
|
||||
static const CInt128 MIN_BY10(MIN_Int128 / 10);
|
||||
static const CInt128 MAX_BY10(MAX_Int128 / 10);
|
||||
|
||||
// Scale op1 by as many of the needed powers of 10 as possible without an overflow.
|
||||
Int128 op1(*this);
|
||||
int sign1 = op1.sign();
|
||||
while ((scale < 0) && (sign1 >= 0 ? op1.compare(MAX_BY10) <= 0 : op1.compare(MIN_BY10) >= 0))
|
||||
{
|
||||
op1.v *= 10;
|
||||
++scale;
|
||||
}
|
||||
|
||||
// Scale op2 shifting it to the right as long as only zeroes are thrown away.
|
||||
while (scale < 0)
|
||||
{
|
||||
int rem = int(v % 10);
|
||||
if (rem)
|
||||
break;
|
||||
op2.v /= 10;
|
||||
++scale;
|
||||
}
|
||||
|
||||
op1.v /= op2.v;
|
||||
|
||||
op1.setScale(scale);
|
||||
return op1;
|
||||
}
|
||||
|
||||
void Int128::zerodivide()
|
||||
{
|
||||
(Arg::Gds(isc_arith_except) << Arg::Gds(isc_exception_integer_divide_by_zero)).raise();
|
||||
}
|
||||
|
||||
void Int128::overflow()
|
||||
{
|
||||
(Arg::Gds(isc_arith_except) << Arg::Gds(isc_exception_integer_overflow)).raise();
|
||||
}
|
||||
|
||||
#ifdef DEV_BUILD
|
||||
const char* Int128::show()
|
||||
{
|
||||
static char to[64];
|
||||
toString(0, sizeof(to), to);
|
||||
return to;
|
||||
}
|
||||
#endif
|
||||
|
||||
CInt128::CInt128(SINT64 value)
|
||||
{
|
||||
set(value, 0);
|
||||
}
|
||||
|
||||
CInt128::CInt128(minmax mm)
|
||||
{
|
||||
switch(mm)
|
||||
{
|
||||
case MkMax:
|
||||
v = absl::Int128Max();
|
||||
break;
|
||||
case MkMin:
|
||||
v = absl::Int128Min();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
CInt128 MIN_Int128(CInt128::MkMin);
|
||||
CInt128 MAX_Int128(CInt128::MkMax);
|
||||
|
||||
} // namespace Firebird
|
||||
|
||||
#else // FB_USE_ABSEIL_INT128
|
||||
|
||||
namespace {
|
||||
|
||||
const CInt128 i64max(MAX_SINT64), i64min(MIN_SINT64);
|
||||
@ -545,3 +788,6 @@ CInt128 MIN_Int128(CInt128::MkMin);
|
||||
CInt128 MAX_Int128(CInt128::MkMax);
|
||||
|
||||
} // namespace Firebird
|
||||
|
||||
#endif // FB_USE_ABSEIL_INT128
|
||||
|
||||
|
@ -36,6 +36,313 @@
|
||||
|
||||
#include "classes/fb_string.h"
|
||||
|
||||
#ifdef FB_USE_ABSEIL_INT128
|
||||
|
||||
#include "absl/numeric/int128.h"
|
||||
|
||||
namespace Firebird {
|
||||
|
||||
class Decimal64;
|
||||
class Decimal128;
|
||||
struct DecimalStatus;
|
||||
|
||||
class Int128 //: public Decimal128Base
|
||||
{
|
||||
public:
|
||||
#if SIZEOF_LONG < 8
|
||||
Int128 set(int value, int scale)
|
||||
{
|
||||
return set(SLONG(value), scale);
|
||||
}
|
||||
#endif
|
||||
|
||||
Int128 set(SLONG value, int scale)
|
||||
{
|
||||
v = value;
|
||||
setScale(scale);
|
||||
return *this;
|
||||
}
|
||||
|
||||
Int128 set(SINT64 value, int scale)
|
||||
{
|
||||
v = value;
|
||||
setScale(scale);
|
||||
return *this;
|
||||
}
|
||||
|
||||
Int128 set(double value)
|
||||
{
|
||||
v = absl::int128(value);
|
||||
return *this;
|
||||
}
|
||||
|
||||
Int128 set(DecimalStatus decSt, Decimal128 value);
|
||||
|
||||
Int128 set(Int128 value)
|
||||
{
|
||||
v = value.v;
|
||||
return *this;
|
||||
}
|
||||
|
||||
Int128 operator=(SINT64 value)
|
||||
{
|
||||
set(value, 0);
|
||||
return *this;
|
||||
}
|
||||
|
||||
#ifdef DEV_BUILD
|
||||
const char* show();
|
||||
#endif
|
||||
|
||||
int toInteger(int scale) const
|
||||
{
|
||||
Int128 tmp(*this);
|
||||
tmp.setScale(scale);
|
||||
int rc = int(tmp.v);
|
||||
if (tmp.v != rc)
|
||||
overflow();
|
||||
return rc;
|
||||
}
|
||||
|
||||
SINT64 toInt64(int scale) const
|
||||
{
|
||||
Int128 tmp(*this);
|
||||
tmp.setScale(scale);
|
||||
SINT64 rc = SINT64(tmp.v);
|
||||
if (tmp.v != rc)
|
||||
overflow();
|
||||
return rc;
|
||||
}
|
||||
|
||||
void toString(int scale, unsigned length, char* to) const;
|
||||
void toString(int scale, string& to) const;
|
||||
|
||||
double toDouble() const
|
||||
{
|
||||
return double(v);
|
||||
}
|
||||
|
||||
Int128 operator&=(FB_UINT64 mask)
|
||||
{
|
||||
v &= mask;
|
||||
return *this;
|
||||
}
|
||||
|
||||
Int128 operator&=(ULONG mask)
|
||||
{
|
||||
v &= mask;
|
||||
return *this;
|
||||
}
|
||||
|
||||
Int128 operator-() const
|
||||
{
|
||||
Int128 rc;
|
||||
rc.v = -v;
|
||||
return rc;
|
||||
}
|
||||
|
||||
Int128 operator/(unsigned value) const
|
||||
{
|
||||
Int128 rc;
|
||||
rc.v = v / value;
|
||||
return rc;
|
||||
}
|
||||
|
||||
Int128 operator+=(unsigned value)
|
||||
{
|
||||
v += value;
|
||||
return *this;
|
||||
}
|
||||
|
||||
Int128 operator-=(unsigned value)
|
||||
{
|
||||
v -= value;
|
||||
return *this;
|
||||
}
|
||||
|
||||
Int128 operator*=(unsigned value)
|
||||
{
|
||||
v *= value;
|
||||
return *this;
|
||||
}
|
||||
|
||||
Int128 operator<<(int value) const
|
||||
{
|
||||
Int128 rc;
|
||||
rc.v = v << value;
|
||||
return rc;
|
||||
}
|
||||
|
||||
Int128 operator>>(int value) const
|
||||
{
|
||||
Int128 rc;
|
||||
rc.v = v >> value;
|
||||
return rc;
|
||||
}
|
||||
|
||||
int compare(Int128 tgt) const
|
||||
{
|
||||
return v < tgt.v ? -1 : v > tgt.v ? 1 : 0;
|
||||
}
|
||||
|
||||
bool operator>(Int128 value) const
|
||||
{
|
||||
return v > value.v;
|
||||
}
|
||||
|
||||
bool operator>=(Int128 value) const
|
||||
{
|
||||
return v >= value.v;
|
||||
}
|
||||
|
||||
bool operator==(Int128 value) const
|
||||
{
|
||||
return v == value.v;
|
||||
}
|
||||
|
||||
bool operator!=(Int128 value) const
|
||||
{
|
||||
return v != value.v;
|
||||
}
|
||||
|
||||
Int128 operator&=(Int128 value)
|
||||
{
|
||||
v &= value.v;
|
||||
return *this;
|
||||
}
|
||||
|
||||
Int128 operator|=(Int128 value)
|
||||
{
|
||||
v |= value.v;
|
||||
return *this;
|
||||
}
|
||||
|
||||
Int128 operator^=(Int128 value)
|
||||
{
|
||||
v ^= value.v;
|
||||
return *this;
|
||||
}
|
||||
|
||||
Int128 operator~() const
|
||||
{
|
||||
Int128 rc;
|
||||
rc.v = ~v;
|
||||
return rc;
|
||||
}
|
||||
|
||||
int sign() const
|
||||
{
|
||||
return v < 0 ? -1 : v == 0 ? 0 : 1;
|
||||
}
|
||||
|
||||
Int128 abs() const;
|
||||
Int128 neg() const;
|
||||
|
||||
Int128 add(Int128 op2) const
|
||||
{
|
||||
Int128 rc;
|
||||
rc.v = v + op2.v;
|
||||
|
||||
// see comment ArithmeticNode::add2()
|
||||
if (sign() == op2.sign() && op2.sign() != rc.sign())
|
||||
overflow();
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
Int128 sub(Int128 op2) const
|
||||
{
|
||||
Int128 rc;
|
||||
rc.v = v - op2.v;
|
||||
|
||||
// see comment ArithmeticNode::add2()
|
||||
if (sign() != op2.sign() && op2.sign() == rc.sign())
|
||||
overflow();
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
Int128 mul(Int128 op2) const
|
||||
{
|
||||
Int128 rc;
|
||||
rc.v = v * op2.v;
|
||||
|
||||
if (rc.v / v != op2.v)
|
||||
overflow();
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
Int128 div(Int128 op2, int scale) const;
|
||||
|
||||
Int128 mod(Int128 op2) const
|
||||
{
|
||||
if (op2.v == 0)
|
||||
zerodivide();
|
||||
|
||||
Int128 rc;
|
||||
rc.v = v % op2.v;
|
||||
return rc;
|
||||
}
|
||||
|
||||
// returns internal data in per-32bit form
|
||||
void getTable32(unsigned* dwords) const
|
||||
{
|
||||
absl::int128 vv = v;
|
||||
for (int i = 0; i < 4; ++i)
|
||||
{
|
||||
dwords[i] = unsigned(vv);
|
||||
vv >>= 32;
|
||||
}
|
||||
}
|
||||
|
||||
void setScale(int scale);
|
||||
|
||||
UCHAR* getBytes()
|
||||
{
|
||||
return (UCHAR*)(&v);
|
||||
}
|
||||
|
||||
protected:
|
||||
absl::int128 v;
|
||||
|
||||
static void overflow();
|
||||
static void zerodivide();
|
||||
|
||||
Int128 set(const char* value);
|
||||
};
|
||||
|
||||
class CInt128 : public Int128
|
||||
{
|
||||
public:
|
||||
enum minmax {MkMax, MkMin};
|
||||
|
||||
CInt128(SINT64 value);
|
||||
CInt128(minmax mm);
|
||||
CInt128(const Int128& value)
|
||||
{
|
||||
set(value);
|
||||
}
|
||||
};
|
||||
|
||||
extern CInt128 MAX_Int128, MIN_Int128;
|
||||
|
||||
class I128limit : public Int128
|
||||
{
|
||||
public:
|
||||
I128limit()
|
||||
{
|
||||
v = 1;
|
||||
for (int i = 0; i < 126; ++i)
|
||||
v *= 2;
|
||||
v *= 5;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace Firebird
|
||||
|
||||
#else // FB_USE_ABSEIL_INT128
|
||||
|
||||
#include "../../extern/ttmath/ttmath.h"
|
||||
|
||||
namespace Firebird {
|
||||
@ -152,5 +459,6 @@ public:
|
||||
|
||||
} // namespace Firebird
|
||||
|
||||
#endif // FB_USE_ABSEIL_INT128
|
||||
|
||||
#endif // FB_INT128
|
||||
|
@ -114,7 +114,7 @@ static const USHORT type_alignments[DTYPE_TYPE_MAX] =
|
||||
sizeof(UCHAR), /* dtype_boolean */
|
||||
sizeof(Firebird::Decimal64),/* dtype_dec64 */
|
||||
sizeof(Firebird::Decimal64),/* dtype_dec128 */
|
||||
sizeof(Firebird::Decimal64),/* dtype_int128 */
|
||||
sizeof(SINT64), /* dtype_int128 */
|
||||
sizeof(GDS_TIME), /* dtype_sql_time_tz */
|
||||
sizeof(GDS_DATE), /* dtype_timestamp_tz */
|
||||
sizeof(GDS_TIME), /* dtype_ex_time_tz */
|
||||
|
Loading…
Reference in New Issue
Block a user