Browse Source
Update the compiler-rt source files to the tip of the llvm-project [1]. To do this some new header files were pulled in from the freebsd-src repo [2]. [1] https://github.com/llvm/llvm-project/commit/fae258e [2] https://github.com/freebsd/freebsd-src/commit/243a0eda Change-Id: I1a012b1fe04e127d35e208923877c98c5d999d00 Signed-off-by: Daniel Boulby <daniel.boulby@arm.com>pull/1989/head
Daniel Boulby
2 years ago
19 changed files with 2074 additions and 681 deletions
@ -0,0 +1,100 @@ |
|||
/*-
|
|||
* SPDX-License-Identifier: BSD-3-Clause |
|||
* |
|||
* Copyright (c) 1989 Regents of the University of California. |
|||
* All rights reserved. |
|||
* |
|||
* Redistribution and use in source and binary forms, with or without |
|||
* modification, are permitted provided that the following conditions |
|||
* are met: |
|||
* 1. Redistributions of source code must retain the above copyright |
|||
* notice, this list of conditions and the following disclaimer. |
|||
* 2. Redistributions in binary form must reproduce the above copyright |
|||
* notice, this list of conditions and the following disclaimer in the |
|||
* documentation and/or other materials provided with the distribution. |
|||
* 3. Neither the name of the University nor the names of its contributors |
|||
* may be used to endorse or promote products derived from this software |
|||
* without specific prior written permission. |
|||
* |
|||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND |
|||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
|||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
|||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
|||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
|||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
|||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
|||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
|||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
|||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
|||
* SUCH DAMAGE. |
|||
* |
|||
* from: @(#)float.h 7.1 (Berkeley) 5/8/90 |
|||
* $FreeBSD$ |
|||
*/ |
|||
|
|||
#ifndef _MACHINE_FLOAT_H_ |
|||
#define _MACHINE_FLOAT_H_ 1 |
|||
|
|||
#include <sys/cdefs.h> |
|||
|
|||
__BEGIN_DECLS |
|||
extern int __flt_rounds(void); |
|||
__END_DECLS |
|||
|
|||
#define FLT_RADIX 2 /* b */ |
|||
#ifndef _ARM_HARD_FLOAT |
|||
#define FLT_ROUNDS __flt_rounds() |
|||
#else |
|||
#define FLT_ROUNDS (-1) |
|||
#endif |
|||
#if __ISO_C_VISIBLE >= 1999 |
|||
#define FLT_EVAL_METHOD 0 |
|||
#define DECIMAL_DIG 17 /* max precision in decimal digits */ |
|||
#endif |
|||
|
|||
#define FLT_MANT_DIG 24 /* p */ |
|||
#define FLT_EPSILON 1.19209290E-07F /* b**(1-p) */ |
|||
#define FLT_DIG 6 /* floor((p-1)*log10(b))+(b == 10) */ |
|||
#define FLT_MIN_EXP (-125) /* emin */ |
|||
#define FLT_MIN 1.17549435E-38F /* b**(emin-1) */ |
|||
#define FLT_MIN_10_EXP (-37) /* ceil(log10(b**(emin-1))) */ |
|||
#define FLT_MAX_EXP 128 /* emax */ |
|||
#define FLT_MAX 3.40282347E+38F /* (1-b**(-p))*b**emax */ |
|||
#define FLT_MAX_10_EXP 38 /* floor(log10((1-b**(-p))*b**emax)) */ |
|||
#if __ISO_C_VISIBLE >= 2011 |
|||
#define FLT_TRUE_MIN 1.40129846E-45F /* b**(emin-p) */ |
|||
#define FLT_DECIMAL_DIG 9 /* ceil(1+p*log10(b)) */ |
|||
#define FLT_HAS_SUBNORM 1 |
|||
#endif /* __ISO_C_VISIBLE >= 2011 */ |
|||
|
|||
#define DBL_MANT_DIG 53 |
|||
#define DBL_EPSILON 2.2204460492503131E-16 |
|||
#define DBL_DIG 15 |
|||
#define DBL_MIN_EXP (-1021) |
|||
#define DBL_MIN 2.2250738585072014E-308 |
|||
#define DBL_MIN_10_EXP (-307) |
|||
#define DBL_MAX_EXP 1024 |
|||
#define DBL_MAX 1.7976931348623157E+308 |
|||
#define DBL_MAX_10_EXP 308 |
|||
#if __ISO_C_VISIBLE >= 2011 |
|||
#define DBL_TRUE_MIN 4.9406564584124654E-324 |
|||
#define DBL_DECIMAL_DIG 17 |
|||
#define DBL_HAS_SUBNORM 1 |
|||
#endif /* __ISO_C_VISIBLE >= 2011 */ |
|||
|
|||
#define LDBL_MANT_DIG DBL_MANT_DIG |
|||
#define LDBL_EPSILON ((long double)DBL_EPSILON) |
|||
#define LDBL_DIG DBL_DIG |
|||
#define LDBL_MIN_EXP DBL_MIN_EXP |
|||
#define LDBL_MIN ((long double)DBL_MIN) |
|||
#define LDBL_MIN_10_EXP DBL_MIN_10_EXP |
|||
#define LDBL_MAX_EXP DBL_MAX_EXP |
|||
#define LDBL_MAX ((long double)DBL_MAX) |
|||
#define LDBL_MAX_10_EXP DBL_MAX_10_EXP |
|||
#if __ISO_C_VISIBLE >= 2011 |
|||
#define LDBL_TRUE_MIN ((long double)DBL_TRUE_MIN) |
|||
#define LDBL_DECIMAL_DIG DBL_DECIMAL_DIG |
|||
#define LDBL_HAS_SUBNORM DBL_HAS_SUBNORM |
|||
#endif /* __ISO_C_VISIBLE >= 2011 */ |
|||
|
|||
#endif /* _MACHINE_FLOAT_H_ */ |
@ -0,0 +1,94 @@ |
|||
/*-
|
|||
* Copyright (c) 1989 Regents of the University of California. |
|||
* All rights reserved. |
|||
* |
|||
* Redistribution and use in source and binary forms, with or without |
|||
* modification, are permitted provided that the following conditions |
|||
* are met: |
|||
* 1. Redistributions of source code must retain the above copyright |
|||
* notice, this list of conditions and the following disclaimer. |
|||
* 2. Redistributions in binary form must reproduce the above copyright |
|||
* notice, this list of conditions and the following disclaimer in the |
|||
* documentation and/or other materials provided with the distribution. |
|||
* 3. Neither the name of the University nor the names of its contributors |
|||
* may be used to endorse or promote products derived from this software |
|||
* without specific prior written permission. |
|||
* |
|||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND |
|||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
|||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
|||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
|||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
|||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
|||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
|||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
|||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
|||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
|||
* SUCH DAMAGE. |
|||
* |
|||
* from: @(#)float.h 7.1 (Berkeley) 5/8/90 |
|||
* $FreeBSD$ |
|||
*/ |
|||
|
|||
#ifndef _MACHINE_FLOAT_H_ |
|||
#define _MACHINE_FLOAT_H_ |
|||
|
|||
#include <sys/cdefs.h> |
|||
|
|||
__BEGIN_DECLS |
|||
extern int __flt_rounds(void); |
|||
__END_DECLS |
|||
|
|||
#define FLT_RADIX 2 /* b */ |
|||
#define FLT_ROUNDS __flt_rounds() |
|||
#if __ISO_C_VISIBLE >= 1999 |
|||
#define FLT_EVAL_METHOD 0 |
|||
#define DECIMAL_DIG 17 /* max precision in decimal digits */ |
|||
#endif |
|||
|
|||
#define FLT_MANT_DIG 24 /* p */ |
|||
#define FLT_EPSILON 1.19209290E-07F /* b**(1-p) */ |
|||
#define FLT_DIG 6 /* floor((p-1)*log10(b))+(b == 10) */ |
|||
#define FLT_MIN_EXP (-125) /* emin */ |
|||
#define FLT_MIN 1.17549435E-38F /* b**(emin-1) */ |
|||
#define FLT_MIN_10_EXP (-37) /* ceil(log10(b**(emin-1))) */ |
|||
#define FLT_MAX_EXP 128 /* emax */ |
|||
#define FLT_MAX 3.40282347E+38F /* (1-b**(-p))*b**emax */ |
|||
#define FLT_MAX_10_EXP 38 /* floor(log10((1-b**(-p))*b**emax)) */ |
|||
#if __ISO_C_VISIBLE >= 2011 |
|||
#define FLT_TRUE_MIN 1.40129846E-45F /* b**(emin-p) */ |
|||
#define FLT_DECIMAL_DIG 9 /* ceil(1+p*log10(b)) */ |
|||
#define FLT_HAS_SUBNORM 1 |
|||
#endif /* __ISO_C_VISIBLE >= 2011 */ |
|||
|
|||
#define DBL_MANT_DIG 53 |
|||
#define DBL_EPSILON 2.2204460492503131E-16 |
|||
#define DBL_DIG 15 |
|||
#define DBL_MIN_EXP (-1021) |
|||
#define DBL_MIN 2.2250738585072014E-308 |
|||
#define DBL_MIN_10_EXP (-307) |
|||
#define DBL_MAX_EXP 1024 |
|||
#define DBL_MAX 1.7976931348623157E+308 |
|||
#define DBL_MAX_10_EXP 308 |
|||
#if __ISO_C_VISIBLE >= 2011 |
|||
#define DBL_TRUE_MIN 4.9406564584124654E-324 |
|||
#define DBL_DECIMAL_DIG 17 |
|||
#define DBL_HAS_SUBNORM 1 |
|||
#endif /* __ISO_C_VISIBLE >= 2011 */ |
|||
|
|||
#define LDBL_MANT_DIG 113 |
|||
#define LDBL_EPSILON 1.925929944387235853055977942584927319E-34L |
|||
#define LDBL_DIG 33 |
|||
#define LDBL_MIN_EXP (-16381) |
|||
#define LDBL_MIN 3.362103143112093506262677817321752603E-4932L |
|||
#define LDBL_MIN_10_EXP (-4931) |
|||
#define LDBL_MAX_EXP (+16384) |
|||
#define LDBL_MAX 1.189731495357231765085759326628007016E+4932L |
|||
#define LDBL_MAX_10_EXP (+4932) |
|||
#if __ISO_C_VISIBLE >= 2011 |
|||
#define LDBL_TRUE_MIN 6.475175119438025110924438958227646552E-4966L |
|||
#define LDBL_DECIMAL_DIG 36 |
|||
#define LDBL_HAS_SUBNORM 1 |
|||
#endif /* __ISO_C_VISIBLE >= 2011 */ |
|||
|
|||
#endif /* _MACHINE_FLOAT_H_ */ |
@ -0,0 +1,922 @@ |
|||
/*-
|
|||
* SPDX-License-Identifier: BSD-3-Clause |
|||
* |
|||
* Copyright (c) 1991, 1993 |
|||
* The Regents of the University of California. All rights reserved. |
|||
* |
|||
* This code is derived from software contributed to Berkeley by |
|||
* Berkeley Software Design, Inc. |
|||
* |
|||
* Redistribution and use in source and binary forms, with or without |
|||
* modification, are permitted provided that the following conditions |
|||
* are met: |
|||
* 1. Redistributions of source code must retain the above copyright |
|||
* notice, this list of conditions and the following disclaimer. |
|||
* 2. Redistributions in binary form must reproduce the above copyright |
|||
* notice, this list of conditions and the following disclaimer in the |
|||
* documentation and/or other materials provided with the distribution. |
|||
* 3. Neither the name of the University nor the names of its contributors |
|||
* may be used to endorse or promote products derived from this software |
|||
* without specific prior written permission. |
|||
* |
|||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND |
|||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
|||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
|||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
|||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
|||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
|||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
|||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
|||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
|||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
|||
* SUCH DAMAGE. |
|||
* |
|||
* @(#)cdefs.h 8.8 (Berkeley) 1/9/95 |
|||
* $FreeBSD$ |
|||
*/ |
|||
|
|||
#ifndef _SYS_CDEFS_H_ |
|||
#define _SYS_CDEFS_H_ |
|||
|
|||
#if defined(_KERNEL) && defined(_STANDALONE) |
|||
#error "_KERNEL and _STANDALONE are mutually exclusive" |
|||
#endif |
|||
|
|||
/*
|
|||
* Testing against Clang-specific extensions. |
|||
*/ |
|||
#ifndef __has_attribute |
|||
#define __has_attribute(x) 0 |
|||
#endif |
|||
#ifndef __has_extension |
|||
#define __has_extension __has_feature |
|||
#endif |
|||
#ifndef __has_feature |
|||
#define __has_feature(x) 0 |
|||
#endif |
|||
#ifndef __has_include |
|||
#define __has_include(x) 0 |
|||
#endif |
|||
#ifndef __has_builtin |
|||
#define __has_builtin(x) 0 |
|||
#endif |
|||
|
|||
#if defined(__cplusplus) |
|||
#define __BEGIN_DECLS extern "C" { |
|||
#define __END_DECLS } |
|||
#else |
|||
#define __BEGIN_DECLS |
|||
#define __END_DECLS |
|||
#endif |
|||
|
|||
/*
|
|||
* This code has been put in place to help reduce the addition of |
|||
* compiler specific defines in FreeBSD code. It helps to aid in |
|||
* having a compiler-agnostic source tree. |
|||
*/ |
|||
|
|||
#if defined(__GNUC__) |
|||
|
|||
#if __GNUC__ >= 3 |
|||
#define __GNUCLIKE_ASM 3 |
|||
#define __GNUCLIKE_MATH_BUILTIN_CONSTANTS |
|||
#else |
|||
#define __GNUCLIKE_ASM 2 |
|||
#endif |
|||
#define __GNUCLIKE___TYPEOF 1 |
|||
#define __GNUCLIKE___SECTION 1 |
|||
|
|||
#define __GNUCLIKE_CTOR_SECTION_HANDLING 1 |
|||
|
|||
#define __GNUCLIKE_BUILTIN_CONSTANT_P 1 |
|||
|
|||
#if (__GNUC_MINOR__ > 95 || __GNUC__ >= 3) |
|||
#define __GNUCLIKE_BUILTIN_VARARGS 1 |
|||
#define __GNUCLIKE_BUILTIN_STDARG 1 |
|||
#define __GNUCLIKE_BUILTIN_VAALIST 1 |
|||
#endif |
|||
|
|||
#define __GNUC_VA_LIST_COMPATIBILITY 1 |
|||
|
|||
/*
|
|||
* Compiler memory barriers, specific to gcc and clang. |
|||
*/ |
|||
#define __compiler_membar() __asm __volatile(" " : : : "memory") |
|||
|
|||
#define __GNUCLIKE_BUILTIN_NEXT_ARG 1 |
|||
#define __GNUCLIKE_MATH_BUILTIN_RELOPS |
|||
|
|||
#define __GNUCLIKE_BUILTIN_MEMCPY 1 |
|||
|
|||
/* XXX: if __GNUC__ >= 2: not tested everywhere originally, where replaced */ |
|||
#define __CC_SUPPORTS_INLINE 1 |
|||
#define __CC_SUPPORTS___INLINE 1 |
|||
#define __CC_SUPPORTS___INLINE__ 1 |
|||
|
|||
#define __CC_SUPPORTS___FUNC__ 1 |
|||
#define __CC_SUPPORTS_WARNING 1 |
|||
|
|||
#define __CC_SUPPORTS_VARADIC_XXX 1 /* see varargs.h */ |
|||
|
|||
#define __CC_SUPPORTS_DYNAMIC_ARRAY_INIT 1 |
|||
|
|||
#endif /* __GNUC__ */ |
|||
|
|||
/*
|
|||
* Macro to test if we're using a specific version of gcc or later. |
|||
*/ |
|||
#if defined(__GNUC__) |
|||
#define __GNUC_PREREQ__(ma, mi) \ |
|||
(__GNUC__ > (ma) || __GNUC__ == (ma) && __GNUC_MINOR__ >= (mi)) |
|||
#else |
|||
#define __GNUC_PREREQ__(ma, mi) 0 |
|||
#endif |
|||
|
|||
/*
|
|||
* The __CONCAT macro is used to concatenate parts of symbol names, e.g. |
|||
* with "#define OLD(foo) __CONCAT(old,foo)", OLD(foo) produces oldfoo. |
|||
* The __CONCAT macro is a bit tricky to use if it must work in non-ANSI |
|||
* mode -- there must be no spaces between its arguments, and for nested |
|||
* __CONCAT's, all the __CONCAT's must be at the left. __CONCAT can also |
|||
* concatenate double-quoted strings produced by the __STRING macro, but |
|||
* this only works with ANSI C. |
|||
* |
|||
* __XSTRING is like __STRING, but it expands any macros in its argument |
|||
* first. It is only available with ANSI C. |
|||
*/ |
|||
#if defined(__STDC__) || defined(__cplusplus) |
|||
#define __P(protos) protos /* full-blown ANSI C */ |
|||
#define __CONCAT1(x,y) x ## y |
|||
#define __CONCAT(x,y) __CONCAT1(x,y) |
|||
#define __STRING(x) #x /* stringify without expanding x */ |
|||
#define __XSTRING(x) __STRING(x) /* expand x, then stringify */ |
|||
|
|||
#define __const const /* define reserved names to standard */ |
|||
#define __signed signed |
|||
#define __volatile volatile |
|||
#if defined(__cplusplus) |
|||
#define __inline inline /* convert to C++ keyword */ |
|||
#else |
|||
#if !(defined(__CC_SUPPORTS___INLINE)) |
|||
#define __inline /* delete GCC keyword */ |
|||
#endif /* ! __CC_SUPPORTS___INLINE */ |
|||
#endif /* !__cplusplus */ |
|||
|
|||
#else /* !(__STDC__ || __cplusplus) */ |
|||
#define __P(protos) () /* traditional C preprocessor */ |
|||
#define __CONCAT(x,y) x/**/y |
|||
#define __STRING(x) "x" |
|||
|
|||
#if !defined(__CC_SUPPORTS___INLINE) |
|||
#define __const /* delete pseudo-ANSI C keywords */ |
|||
#define __inline |
|||
#define __signed |
|||
#define __volatile |
|||
/*
|
|||
* In non-ANSI C environments, new programs will want ANSI-only C keywords |
|||
* deleted from the program and old programs will want them left alone. |
|||
* When using a compiler other than gcc, programs using the ANSI C keywords |
|||
* const, inline etc. as normal identifiers should define -DNO_ANSI_KEYWORDS. |
|||
* When using "gcc -traditional", we assume that this is the intent; if |
|||
* __GNUC__ is defined but __STDC__ is not, we leave the new keywords alone. |
|||
*/ |
|||
#ifndef NO_ANSI_KEYWORDS |
|||
#define const /* delete ANSI C keywords */ |
|||
#define inline |
|||
#define signed |
|||
#define volatile |
|||
#endif /* !NO_ANSI_KEYWORDS */ |
|||
#endif /* !__CC_SUPPORTS___INLINE */ |
|||
#endif /* !(__STDC__ || __cplusplus) */ |
|||
|
|||
/*
|
|||
* Compiler-dependent macros to help declare dead (non-returning) and |
|||
* pure (no side effects) functions, and unused variables. They are |
|||
* null except for versions of gcc that are known to support the features |
|||
* properly (old versions of gcc-2 supported the dead and pure features |
|||
* in a different (wrong) way). If we do not provide an implementation |
|||
* for a given compiler, let the compile fail if it is told to use |
|||
* a feature that we cannot live without. |
|||
*/ |
|||
#define __weak_symbol __attribute__((__weak__)) |
|||
#if !__GNUC_PREREQ__(2, 5) |
|||
#define __dead2 |
|||
#define __pure2 |
|||
#define __unused |
|||
#endif |
|||
#if __GNUC__ == 2 && __GNUC_MINOR__ >= 5 && __GNUC_MINOR__ < 7 |
|||
#define __dead2 __attribute__((__noreturn__)) |
|||
#define __pure2 __attribute__((__const__)) |
|||
#define __unused |
|||
/* XXX Find out what to do for __packed, __aligned and __section */ |
|||
#endif |
|||
#if __GNUC_PREREQ__(2, 7) |
|||
#define __dead2 __attribute__((__noreturn__)) |
|||
#define __pure2 __attribute__((__const__)) |
|||
#define __unused __attribute__((__unused__)) |
|||
#define __used __attribute__((__used__)) |
|||
#define __packed __attribute__((__packed__)) |
|||
#define __aligned(x) __attribute__((__aligned__(x))) |
|||
#define __section(x) __attribute__((__section__(x))) |
|||
#endif |
|||
#if __GNUC_PREREQ__(4, 3) || __has_attribute(__alloc_size__) |
|||
#define __alloc_size(x) __attribute__((__alloc_size__(x))) |
|||
#define __alloc_size2(n, x) __attribute__((__alloc_size__(n, x))) |
|||
#else |
|||
#define __alloc_size(x) |
|||
#define __alloc_size2(n, x) |
|||
#endif |
|||
#if __GNUC_PREREQ__(4, 9) || __has_attribute(__alloc_align__) |
|||
#define __alloc_align(x) __attribute__((__alloc_align__(x))) |
|||
#else |
|||
#define __alloc_align(x) |
|||
#endif |
|||
|
|||
#if !__GNUC_PREREQ__(2, 95) |
|||
#define __alignof(x) __offsetof(struct { char __a; x __b; }, __b) |
|||
#endif |
|||
|
|||
/*
|
|||
* Keywords added in C11. |
|||
*/ |
|||
|
|||
#if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 201112L |
|||
|
|||
#if !__has_extension(c_alignas) |
|||
#if (defined(__cplusplus) && __cplusplus >= 201103L) || \ |
|||
__has_extension(cxx_alignas) |
|||
#define _Alignas(x) alignas(x) |
|||
#else |
|||
/* XXX: Only emulates _Alignas(constant-expression); not _Alignas(type-name). */ |
|||
#define _Alignas(x) __aligned(x) |
|||
#endif |
|||
#endif |
|||
|
|||
#if defined(__cplusplus) && __cplusplus >= 201103L |
|||
#define _Alignof(x) alignof(x) |
|||
#else |
|||
#define _Alignof(x) __alignof(x) |
|||
#endif |
|||
|
|||
#if !defined(__cplusplus) && !__has_extension(c_atomic) && \ |
|||
!__has_extension(cxx_atomic) && !__GNUC_PREREQ__(4, 7) |
|||
/*
|
|||
* No native support for _Atomic(). Place object in structure to prevent |
|||
* most forms of direct non-atomic access. |
|||
*/ |
|||
#define _Atomic(T) struct { T volatile __val; } |
|||
#endif |
|||
|
|||
#if defined(__cplusplus) && __cplusplus >= 201103L |
|||
#define _Noreturn [[noreturn]] |
|||
#else |
|||
#define _Noreturn __dead2 |
|||
#endif |
|||
|
|||
#if !__has_extension(c_static_assert) |
|||
#if (defined(__cplusplus) && __cplusplus >= 201103L) || \ |
|||
__has_extension(cxx_static_assert) |
|||
#define _Static_assert(x, y) static_assert(x, y) |
|||
#elif __GNUC_PREREQ__(4,6) && !defined(__cplusplus) |
|||
/* Nothing, gcc 4.6 and higher has _Static_assert built-in */ |
|||
#elif defined(__COUNTER__) |
|||
#define _Static_assert(x, y) __Static_assert(x, __COUNTER__) |
|||
#define __Static_assert(x, y) ___Static_assert(x, y) |
|||
#define ___Static_assert(x, y) typedef char __assert_ ## y[(x) ? 1 : -1] \ |
|||
__unused |
|||
#else |
|||
#define _Static_assert(x, y) struct __hack |
|||
#endif |
|||
#endif |
|||
|
|||
#if !__has_extension(c_thread_local) |
|||
/*
|
|||
* XXX: Some compilers (Clang 3.3, GCC 4.7) falsely announce C++11 mode |
|||
* without actually supporting the thread_local keyword. Don't check for |
|||
* the presence of C++11 when defining _Thread_local. |
|||
*/ |
|||
#if /* (defined(__cplusplus) && __cplusplus >= 201103L) || */ \ |
|||
__has_extension(cxx_thread_local) |
|||
#define _Thread_local thread_local |
|||
#else |
|||
#define _Thread_local __thread |
|||
#endif |
|||
#endif |
|||
|
|||
#endif /* __STDC_VERSION__ || __STDC_VERSION__ < 201112L */ |
|||
|
|||
/*
|
|||
* Emulation of C11 _Generic(). Unlike the previously defined C11 |
|||
* keywords, it is not possible to implement this using exactly the same |
|||
* syntax. Therefore implement something similar under the name |
|||
* __generic(). Unlike _Generic(), this macro can only distinguish |
|||
* between a single type, so it requires nested invocations to |
|||
* distinguish multiple cases. |
|||
*/ |
|||
|
|||
#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L) || \ |
|||
__has_extension(c_generic_selections) |
|||
#define __generic(expr, t, yes, no) \ |
|||
_Generic(expr, t: yes, default: no) |
|||
#elif __GNUC_PREREQ__(3, 1) && !defined(__cplusplus) |
|||
#define __generic(expr, t, yes, no) \ |
|||
__builtin_choose_expr( \ |
|||
__builtin_types_compatible_p(__typeof(expr), t), yes, no) |
|||
#endif |
|||
|
|||
/*
|
|||
* C99 Static array indices in function parameter declarations. Syntax such as: |
|||
* void bar(int myArray[static 10]); |
|||
* is allowed in C99 but not in C++. Define __min_size appropriately so |
|||
* headers using it can be compiled in either language. Use like this: |
|||
* void bar(int myArray[__min_size(10)]); |
|||
*/ |
|||
#if !defined(__cplusplus) && \ |
|||
(defined(__clang__) || __GNUC_PREREQ__(4, 6)) && \ |
|||
(!defined(__STDC_VERSION__) || (__STDC_VERSION__ >= 199901)) |
|||
#define __min_size(x) static (x) |
|||
#else |
|||
#define __min_size(x) (x) |
|||
#endif |
|||
|
|||
#if __GNUC_PREREQ__(2, 96) |
|||
#define __malloc_like __attribute__((__malloc__)) |
|||
#define __pure __attribute__((__pure__)) |
|||
#else |
|||
#define __malloc_like |
|||
#define __pure |
|||
#endif |
|||
|
|||
#if __GNUC_PREREQ__(3, 1) |
|||
#define __always_inline __attribute__((__always_inline__)) |
|||
#else |
|||
#define __always_inline |
|||
#endif |
|||
|
|||
#if __GNUC_PREREQ__(3, 1) |
|||
#define __noinline __attribute__ ((__noinline__)) |
|||
#else |
|||
#define __noinline |
|||
#endif |
|||
|
|||
#if __GNUC_PREREQ__(3, 4) |
|||
#define __fastcall __attribute__((__fastcall__)) |
|||
#define __result_use_check __attribute__((__warn_unused_result__)) |
|||
#else |
|||
#define __fastcall |
|||
#define __result_use_check |
|||
#endif |
|||
|
|||
#if __GNUC_PREREQ__(4, 1) |
|||
#define __returns_twice __attribute__((__returns_twice__)) |
|||
#else |
|||
#define __returns_twice |
|||
#endif |
|||
|
|||
#if __GNUC_PREREQ__(4, 6) || __has_builtin(__builtin_unreachable) |
|||
#define __unreachable() __builtin_unreachable() |
|||
#else |
|||
#define __unreachable() ((void)0) |
|||
#endif |
|||
|
|||
/* XXX: should use `#if __STDC_VERSION__ < 199901'. */ |
|||
#if !__GNUC_PREREQ__(2, 7) |
|||
#define __func__ NULL |
|||
#endif |
|||
|
|||
#if (defined(__GNUC__) && __GNUC__ >= 2) && !defined(__STRICT_ANSI__) || __STDC_VERSION__ >= 199901 |
|||
#define __LONG_LONG_SUPPORTED |
|||
#endif |
|||
|
|||
/* C++11 exposes a load of C99 stuff */ |
|||
#if defined(__cplusplus) && __cplusplus >= 201103L |
|||
#define __LONG_LONG_SUPPORTED |
|||
#ifndef __STDC_LIMIT_MACROS |
|||
#define __STDC_LIMIT_MACROS |
|||
#endif |
|||
#ifndef __STDC_CONSTANT_MACROS |
|||
#define __STDC_CONSTANT_MACROS |
|||
#endif |
|||
#endif |
|||
|
|||
/*
|
|||
* GCC 2.95 provides `__restrict' as an extension to C90 to support the |
|||
* C99-specific `restrict' type qualifier. We happen to use `__restrict' as |
|||
* a way to define the `restrict' type qualifier without disturbing older |
|||
* software that is unaware of C99 keywords. |
|||
*/ |
|||
#if !(__GNUC__ == 2 && __GNUC_MINOR__ == 95) |
|||
#if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 199901 |
|||
#define __restrict |
|||
#else |
|||
#define __restrict restrict |
|||
#endif |
|||
#endif |
|||
|
|||
/*
|
|||
* GNU C version 2.96 adds explicit branch prediction so that |
|||
* the CPU back-end can hint the processor and also so that |
|||
* code blocks can be reordered such that the predicted path |
|||
* sees a more linear flow, thus improving cache behavior, etc. |
|||
* |
|||
* The following two macros provide us with a way to utilize this |
|||
* compiler feature. Use __predict_true() if you expect the expression |
|||
* to evaluate to true, and __predict_false() if you expect the |
|||
* expression to evaluate to false. |
|||
* |
|||
* A few notes about usage: |
|||
* |
|||
* * Generally, __predict_false() error condition checks (unless |
|||
* you have some _strong_ reason to do otherwise, in which case |
|||
* document it), and/or __predict_true() `no-error' condition |
|||
* checks, assuming you want to optimize for the no-error case. |
|||
* |
|||
* * Other than that, if you don't know the likelihood of a test |
|||
* succeeding from empirical or other `hard' evidence, don't |
|||
* make predictions. |
|||
* |
|||
* * These are meant to be used in places that are run `a lot'. |
|||
* It is wasteful to make predictions in code that is run |
|||
* seldomly (e.g. at subsystem initialization time) as the |
|||
* basic block reordering that this affects can often generate |
|||
* larger code. |
|||
*/ |
|||
#if __GNUC_PREREQ__(2, 96) |
|||
#define __predict_true(exp) __builtin_expect((exp), 1) |
|||
#define __predict_false(exp) __builtin_expect((exp), 0) |
|||
#else |
|||
#define __predict_true(exp) (exp) |
|||
#define __predict_false(exp) (exp) |
|||
#endif |
|||
|
|||
#if __GNUC_PREREQ__(4, 0) |
|||
#define __null_sentinel __attribute__((__sentinel__)) |
|||
#define __exported __attribute__((__visibility__("default"))) |
|||
#define __hidden __attribute__((__visibility__("hidden"))) |
|||
#else |
|||
#define __null_sentinel |
|||
#define __exported |
|||
#define __hidden |
|||
#endif |
|||
|
|||
/*
|
|||
* We define this here since <stddef.h>, <sys/queue.h>, and <sys/types.h> |
|||
* require it. |
|||
*/ |
|||
#if __GNUC_PREREQ__(4, 1) |
|||
#define __offsetof(type, field) __builtin_offsetof(type, field) |
|||
#else |
|||
#ifndef __cplusplus |
|||
#define __offsetof(type, field) \ |
|||
((__size_t)(__uintptr_t)((const volatile void *)&((type *)0)->field)) |
|||
#else |
|||
#define __offsetof(type, field) \ |
|||
(__offsetof__ (reinterpret_cast <__size_t> \ |
|||
(&reinterpret_cast <const volatile char &> \ |
|||
(static_cast<type *> (0)->field)))) |
|||
#endif |
|||
#endif |
|||
#define __rangeof(type, start, end) \ |
|||
(__offsetof(type, end) - __offsetof(type, start)) |
|||
|
|||
/*
|
|||
* Given the pointer x to the member m of the struct s, return |
|||
* a pointer to the containing structure. When using GCC, we first |
|||
* assign pointer x to a local variable, to check that its type is |
|||
* compatible with member m. |
|||
*/ |
|||
#if __GNUC_PREREQ__(3, 1) |
|||
#define __containerof(x, s, m) ({ \ |
|||
const volatile __typeof(((s *)0)->m) *__x = (x); \ |
|||
__DEQUALIFY(s *, (const volatile char *)__x - __offsetof(s, m));\ |
|||
}) |
|||
#else |
|||
#define __containerof(x, s, m) \ |
|||
__DEQUALIFY(s *, (const volatile char *)(x) - __offsetof(s, m)) |
|||
#endif |
|||
|
|||
/*
|
|||
* Compiler-dependent macros to declare that functions take printf-like |
|||
* or scanf-like arguments. They are null except for versions of gcc |
|||
* that are known to support the features properly (old versions of gcc-2 |
|||
* didn't permit keeping the keywords out of the application namespace). |
|||
*/ |
|||
#if !__GNUC_PREREQ__(2, 7) |
|||
#define __printflike(fmtarg, firstvararg) |
|||
#define __scanflike(fmtarg, firstvararg) |
|||
#define __format_arg(fmtarg) |
|||
#define __strfmonlike(fmtarg, firstvararg) |
|||
#define __strftimelike(fmtarg, firstvararg) |
|||
#else |
|||
#define __printflike(fmtarg, firstvararg) \ |
|||
__attribute__((__format__ (__printf__, fmtarg, firstvararg))) |
|||
#define __scanflike(fmtarg, firstvararg) \ |
|||
__attribute__((__format__ (__scanf__, fmtarg, firstvararg))) |
|||
#define __format_arg(fmtarg) __attribute__((__format_arg__ (fmtarg))) |
|||
#define __strfmonlike(fmtarg, firstvararg) \ |
|||
__attribute__((__format__ (__strfmon__, fmtarg, firstvararg))) |
|||
#define __strftimelike(fmtarg, firstvararg) \ |
|||
__attribute__((__format__ (__strftime__, fmtarg, firstvararg))) |
|||
#endif |
|||
|
|||
/* Compiler-dependent macros that rely on FreeBSD-specific extensions. */ |
|||
#if defined(__FreeBSD_cc_version) && __FreeBSD_cc_version >= 300001 && \ |
|||
defined(__GNUC__) |
|||
#define __printf0like(fmtarg, firstvararg) \ |
|||
__attribute__((__format__ (__printf0__, fmtarg, firstvararg))) |
|||
#else |
|||
#define __printf0like(fmtarg, firstvararg) |
|||
#endif |
|||
|
|||
#if defined(__GNUC__) |
|||
#define __strong_reference(sym,aliassym) \ |
|||
extern __typeof (sym) aliassym __attribute__ ((__alias__ (#sym))) |
|||
#ifdef __STDC__ |
|||
#define __weak_reference(sym,alias) \ |
|||
__asm__(".weak " #alias); \ |
|||
__asm__(".equ " #alias ", " #sym) |
|||
#define __warn_references(sym,msg) \ |
|||
__asm__(".section .gnu.warning." #sym); \ |
|||
__asm__(".asciz \"" msg "\""); \ |
|||
__asm__(".previous") |
|||
#define __sym_compat(sym,impl,verid) \ |
|||
__asm__(".symver " #impl ", " #sym "@" #verid) |
|||
#define __sym_default(sym,impl,verid) \ |
|||
__asm__(".symver " #impl ", " #sym "@@@" #verid) |
|||
#else |
|||
#define __weak_reference(sym,alias) \ |
|||
__asm__(".weak alias"); \ |
|||
__asm__(".equ alias, sym") |
|||
#define __warn_references(sym,msg) \ |
|||
__asm__(".section .gnu.warning.sym"); \ |
|||
__asm__(".asciz \"msg\""); \ |
|||
__asm__(".previous") |
|||
#define __sym_compat(sym,impl,verid) \ |
|||
__asm__(".symver impl, sym@verid") |
|||
#define __sym_default(impl,sym,verid) \ |
|||
__asm__(".symver impl, sym@@@verid") |
|||
#endif /* __STDC__ */ |
|||
#endif /* __GNUC__ */ |
|||
|
|||
#define __GLOBL(sym) __asm__(".globl " __XSTRING(sym)) |
|||
#define __WEAK(sym) __asm__(".weak " __XSTRING(sym)) |
|||
|
|||
#if defined(__GNUC__) |
|||
#define __IDSTRING(name,string) __asm__(".ident\t\"" string "\"") |
|||
#else |
|||
/*
|
|||
* The following definition might not work well if used in header files, |
|||
* but it should be better than nothing. If you want a "do nothing" |
|||
* version, then it should generate some harmless declaration, such as: |
|||
* #define __IDSTRING(name,string) struct __hack |
|||
*/ |
|||
#define __IDSTRING(name,string) static const char name[] __unused = string |
|||
#endif |
|||
|
|||
/*
|
|||
* Embed the rcs id of a source file in the resulting library. Note that in |
|||
* more recent ELF binutils, we use .ident allowing the ID to be stripped. |
|||
* Usage: |
|||
* __FBSDID("$FreeBSD$"); |
|||
*/ |
|||
#ifndef __FBSDID |
|||
#if !defined(STRIP_FBSDID) |
|||
#define __FBSDID(s) __IDSTRING(__CONCAT(__rcsid_,__LINE__),s) |
|||
#else |
|||
#define __FBSDID(s) struct __hack |
|||
#endif |
|||
#endif |
|||
|
|||
#ifndef __RCSID |
|||
#ifndef NO__RCSID |
|||
#define __RCSID(s) __IDSTRING(__CONCAT(__rcsid_,__LINE__),s) |
|||
#else |
|||
#define __RCSID(s) struct __hack |
|||
#endif |
|||
#endif |
|||
|
|||
#ifndef __RCSID_SOURCE |
|||
#ifndef NO__RCSID_SOURCE |
|||
#define __RCSID_SOURCE(s) __IDSTRING(__CONCAT(__rcsid_source_,__LINE__),s) |
|||
#else |
|||
#define __RCSID_SOURCE(s) struct __hack |
|||
#endif |
|||
#endif |
|||
|
|||
#ifndef __SCCSID |
|||
#ifndef NO__SCCSID |
|||
#define __SCCSID(s) __IDSTRING(__CONCAT(__sccsid_,__LINE__),s) |
|||
#else |
|||
#define __SCCSID(s) struct __hack |
|||
#endif |
|||
#endif |
|||
|
|||
#ifndef __COPYRIGHT |
|||
#ifndef NO__COPYRIGHT |
|||
#define __COPYRIGHT(s) __IDSTRING(__CONCAT(__copyright_,__LINE__),s) |
|||
#else |
|||
#define __COPYRIGHT(s) struct __hack |
|||
#endif |
|||
#endif |
|||
|
|||
#ifndef __DECONST |
|||
#define __DECONST(type, var) ((type)(__uintptr_t)(const void *)(var)) |
|||
#endif |
|||
|
|||
#ifndef __DEVOLATILE |
|||
#define __DEVOLATILE(type, var) ((type)(__uintptr_t)(volatile void *)(var)) |
|||
#endif |
|||
|
|||
#ifndef __DEQUALIFY |
|||
#define __DEQUALIFY(type, var) ((type)(__uintptr_t)(const volatile void *)(var)) |
|||
#endif |
|||
|
|||
/*-
|
|||
* The following definitions are an extension of the behavior originally |
|||
* implemented in <sys/_posix.h>, but with a different level of granularity. |
|||
* POSIX.1 requires that the macros we test be defined before any standard |
|||
* header file is included. |
|||
* |
|||
* Here's a quick run-down of the versions (and some informal names) |
|||
* defined(_POSIX_SOURCE) 1003.1-1988 |
|||
* encoded as 198808 below |
|||
* _POSIX_C_SOURCE == 1 1003.1-1990 |
|||
* encoded as 199009 below |
|||
* _POSIX_C_SOURCE == 2 1003.2-1992 C Language Binding Option |
|||
* encoded as 199209 below |
|||
* _POSIX_C_SOURCE == 199309 1003.1b-1993 |
|||
* (1003.1 Issue 4, Single Unix Spec v1, Unix 93) |
|||
* _POSIX_C_SOURCE == 199506 1003.1c-1995, 1003.1i-1995, |
|||
* and the omnibus ISO/IEC 9945-1: 1996 |
|||
* (1003.1 Issue 5, Single Unix Spec v2, Unix 95) |
|||
* _POSIX_C_SOURCE == 200112 1003.1-2001 (1003.1 Issue 6, Unix 03) |
|||
* _POSIX_C_SOURCE == 200809 1003.1-2008 (1003.1 Issue 7) |
|||
* IEEE Std 1003.1-2017 (Rev of 1003.1-2008) is |
|||
* 1003.1-2008 with two TCs applied with |
|||
* _POSIX_C_SOURCE=200809 and _XOPEN_SOURCE=700 |
|||
* |
|||
* In addition, the X/Open Portability Guide, which is now the Single UNIX |
|||
* Specification, defines a feature-test macro which indicates the version of |
|||
* that specification, and which subsumes _POSIX_C_SOURCE. |
|||
* |
|||
* Our macros begin with two underscores to avoid namespace screwage. |
|||
*/ |
|||
|
|||
/* Deal with IEEE Std. 1003.1-1990, in which _POSIX_C_SOURCE == 1. */ |
|||
#if defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE == 1 |
|||
#undef _POSIX_C_SOURCE /* Probably illegal, but beyond caring now. */ |
|||
#define _POSIX_C_SOURCE 199009 |
|||
#endif |
|||
|
|||
/* Deal with IEEE Std. 1003.2-1992, in which _POSIX_C_SOURCE == 2. */ |
|||
#if defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE == 2 |
|||
#undef _POSIX_C_SOURCE |
|||
#define _POSIX_C_SOURCE 199209 |
|||
#endif |
|||
|
|||
/* Deal with various X/Open Portability Guides and Single UNIX Spec. */ |
|||
#ifdef _XOPEN_SOURCE |
|||
#if _XOPEN_SOURCE - 0 >= 700 |
|||
#define __XSI_VISIBLE 700 |
|||
#undef _POSIX_C_SOURCE |
|||
#define _POSIX_C_SOURCE 200809 |
|||
#elif _XOPEN_SOURCE - 0 >= 600 |
|||
#define __XSI_VISIBLE 600 |
|||
#undef _POSIX_C_SOURCE |
|||
#define _POSIX_C_SOURCE 200112 |
|||
#elif _XOPEN_SOURCE - 0 >= 500 |
|||
#define __XSI_VISIBLE 500 |
|||
#undef _POSIX_C_SOURCE |
|||
#define _POSIX_C_SOURCE 199506 |
|||
#endif |
|||
#endif |
|||
|
|||
/*
|
|||
* Deal with all versions of POSIX. The ordering relative to the tests above is |
|||
* important. |
|||
*/ |
|||
#if defined(_POSIX_SOURCE) && !defined(_POSIX_C_SOURCE) |
|||
#define _POSIX_C_SOURCE 198808 |
|||
#endif |
|||
#ifdef _POSIX_C_SOURCE |
|||
#if _POSIX_C_SOURCE >= 200809 |
|||
#define __POSIX_VISIBLE 200809 |
|||
#define __ISO_C_VISIBLE 1999 |
|||
#elif _POSIX_C_SOURCE >= 200112 |
|||
#define __POSIX_VISIBLE 200112 |
|||
#define __ISO_C_VISIBLE 1999 |
|||
#elif _POSIX_C_SOURCE >= 199506 |
|||
#define __POSIX_VISIBLE 199506 |
|||
#define __ISO_C_VISIBLE 1990 |
|||
#elif _POSIX_C_SOURCE >= 199309 |
|||
#define __POSIX_VISIBLE 199309 |
|||
#define __ISO_C_VISIBLE 1990 |
|||
#elif _POSIX_C_SOURCE >= 199209 |
|||
#define __POSIX_VISIBLE 199209 |
|||
#define __ISO_C_VISIBLE 1990 |
|||
#elif _POSIX_C_SOURCE >= 199009 |
|||
#define __POSIX_VISIBLE 199009 |
|||
#define __ISO_C_VISIBLE 1990 |
|||
#else |
|||
#define __POSIX_VISIBLE 198808 |
|||
#define __ISO_C_VISIBLE 0 |
|||
#endif /* _POSIX_C_SOURCE */ |
|||
/*
|
|||
* Both glibc and OpenBSD enable c11 features when _ISOC11_SOURCE is defined, or |
|||
* when compiling with -stdc=c11. A strict reading of the standard would suggest |
|||
* doing it only for the former. However, a strict reading also requires C99 |
|||
* mode only, so building with C11 is already undefined. Follow glibc's and |
|||
* OpenBSD's lead for this non-standard configuration for maximum compatibility. |
|||
*/ |
|||
#if _ISOC11_SOURCE || (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L) |
|||
#undef __ISO_C_VISIBLE |
|||
#define __ISO_C_VISIBLE 2011 |
|||
#endif |
|||
#else |
|||
/*-
|
|||
* Deal with _ANSI_SOURCE: |
|||
* If it is defined, and no other compilation environment is explicitly |
|||
* requested, then define our internal feature-test macros to zero. This |
|||
* makes no difference to the preprocessor (undefined symbols in preprocessing |
|||
* expressions are defined to have value zero), but makes it more convenient for |
|||
* a test program to print out the values. |
|||
* |
|||
* If a program mistakenly defines _ANSI_SOURCE and some other macro such as |
|||
* _POSIX_C_SOURCE, we will assume that it wants the broader compilation |
|||
* environment (and in fact we will never get here). |
|||
*/ |
|||
#if defined(_ANSI_SOURCE) /* Hide almost everything. */ |
|||
#define __POSIX_VISIBLE 0 |
|||
#define __XSI_VISIBLE 0 |
|||
#define __BSD_VISIBLE 0 |
|||
#define __ISO_C_VISIBLE 1990 |
|||
#define __EXT1_VISIBLE 0 |
|||
#elif defined(_C99_SOURCE) /* Localism to specify strict C99 env. */ |
|||
#define __POSIX_VISIBLE 0 |
|||
#define __XSI_VISIBLE 0 |
|||
#define __BSD_VISIBLE 0 |
|||
#define __ISO_C_VISIBLE 1999 |
|||
#define __EXT1_VISIBLE 0 |
|||
#elif defined(_C11_SOURCE) /* Localism to specify strict C11 env. */ |
|||
#define __POSIX_VISIBLE 0 |
|||
#define __XSI_VISIBLE 0 |
|||
#define __BSD_VISIBLE 0 |
|||
#define __ISO_C_VISIBLE 2011 |
|||
#define __EXT1_VISIBLE 0 |
|||
#else /* Default environment: show everything. */ |
|||
#define __POSIX_VISIBLE 200809 |
|||
#define __XSI_VISIBLE 700 |
|||
#define __BSD_VISIBLE 1 |
|||
#define __ISO_C_VISIBLE 2011 |
|||
#define __EXT1_VISIBLE 1 |
|||
#endif |
|||
#endif |
|||
|
|||
/* User override __EXT1_VISIBLE */ |
|||
#if defined(__STDC_WANT_LIB_EXT1__) |
|||
#undef __EXT1_VISIBLE |
|||
#if __STDC_WANT_LIB_EXT1__ |
|||
#define __EXT1_VISIBLE 1 |
|||
#else |
|||
#define __EXT1_VISIBLE 0 |
|||
#endif |
|||
#endif /* __STDC_WANT_LIB_EXT1__ */ |
|||
|
|||
/*
|
|||
* Old versions of GCC use non-standard ARM arch symbols; acle-compat.h |
|||
* translates them to __ARM_ARCH and the modern feature symbols defined by ARM. |
|||
*/ |
|||
#if defined(__arm__) && !defined(__ARM_ARCH) |
|||
#include <machine/acle-compat.h> |
|||
#endif |
|||
|
|||
/*
|
|||
* Nullability qualifiers: currently only supported by Clang. |
|||
*/ |
|||
#if !(defined(__clang__) && __has_feature(nullability)) |
|||
#define _Nonnull |
|||
#define _Nullable |
|||
#define _Null_unspecified |
|||
#define __NULLABILITY_PRAGMA_PUSH |
|||
#define __NULLABILITY_PRAGMA_POP |
|||
#else |
|||
#define __NULLABILITY_PRAGMA_PUSH _Pragma("clang diagnostic push") \ |
|||
_Pragma("clang diagnostic ignored \"-Wnullability-completeness\"") |
|||
#define __NULLABILITY_PRAGMA_POP _Pragma("clang diagnostic pop") |
|||
#endif |
|||
|
|||
/*
|
|||
* Type Safety Checking |
|||
* |
|||
* Clang provides additional attributes to enable checking type safety |
|||
* properties that cannot be enforced by the C type system. |
|||
*/ |
|||
|
|||
#if __has_attribute(__argument_with_type_tag__) && \ |
|||
__has_attribute(__type_tag_for_datatype__) |
|||
#define __arg_type_tag(arg_kind, arg_idx, type_tag_idx) \ |
|||
__attribute__((__argument_with_type_tag__(arg_kind, arg_idx, type_tag_idx))) |
|||
#define __datatype_type_tag(kind, type) \ |
|||
__attribute__((__type_tag_for_datatype__(kind, type))) |
|||
#else |
|||
#define __arg_type_tag(arg_kind, arg_idx, type_tag_idx) |
|||
#define __datatype_type_tag(kind, type) |
|||
#endif |
|||
|
|||
/*
|
|||
* Lock annotations. |
|||
* |
|||
* Clang provides support for doing basic thread-safety tests at |
|||
* compile-time, by marking which locks will/should be held when |
|||
* entering/leaving a functions. |
|||
* |
|||
* Furthermore, it is also possible to annotate variables and structure |
|||
* members to enforce that they are only accessed when certain locks are |
|||
* held. |
|||
*/ |
|||
|
|||
#if __has_extension(c_thread_safety_attributes) |
|||
#define __lock_annotate(x) __attribute__((x)) |
|||
#else |
|||
#define __lock_annotate(x) |
|||
#endif |
|||
|
|||
/* Structure implements a lock. */ |
|||
#define __lockable __lock_annotate(lockable) |
|||
|
|||
/* Function acquires an exclusive or shared lock. */ |
|||
#define __locks_exclusive(...) \ |
|||
__lock_annotate(exclusive_lock_function(__VA_ARGS__)) |
|||
#define __locks_shared(...) \ |
|||
__lock_annotate(shared_lock_function(__VA_ARGS__)) |
|||
|
|||
/* Function attempts to acquire an exclusive or shared lock. */ |
|||
#define __trylocks_exclusive(...) \ |
|||
__lock_annotate(exclusive_trylock_function(__VA_ARGS__)) |
|||
#define __trylocks_shared(...) \ |
|||
__lock_annotate(shared_trylock_function(__VA_ARGS__)) |
|||
|
|||
/* Function releases a lock. */ |
|||
#define __unlocks(...) __lock_annotate(unlock_function(__VA_ARGS__)) |
|||
|
|||
/* Function asserts that an exclusive or shared lock is held. */ |
|||
#define __asserts_exclusive(...) \ |
|||
__lock_annotate(assert_exclusive_lock(__VA_ARGS__)) |
|||
#define __asserts_shared(...) \ |
|||
__lock_annotate(assert_shared_lock(__VA_ARGS__)) |
|||
|
|||
/* Function requires that an exclusive or shared lock is or is not held. */ |
|||
#define __requires_exclusive(...) \ |
|||
__lock_annotate(exclusive_locks_required(__VA_ARGS__)) |
|||
#define __requires_shared(...) \ |
|||
__lock_annotate(shared_locks_required(__VA_ARGS__)) |
|||
#define __requires_unlocked(...) \ |
|||
__lock_annotate(locks_excluded(__VA_ARGS__)) |
|||
|
|||
/* Function should not be analyzed. */ |
|||
#define __no_lock_analysis __lock_annotate(no_thread_safety_analysis) |
|||
|
|||
/*
|
|||
* Function or variable should not be sanitized, e.g., by AddressSanitizer. |
|||
* GCC has the nosanitize attribute, but as a function attribute only, and |
|||
* warns on use as a variable attribute. |
|||
*/ |
|||
#if __has_attribute(no_sanitize) && defined(__clang__) |
|||
#ifdef _KERNEL |
|||
#define __nosanitizeaddress __attribute__((no_sanitize("kernel-address"))) |
|||
#define __nosanitizememory __attribute__((no_sanitize("kernel-memory"))) |
|||
#else |
|||
#define __nosanitizeaddress __attribute__((no_sanitize("address"))) |
|||
#define __nosanitizememory __attribute__((no_sanitize("memory"))) |
|||
#endif |
|||
#define __nosanitizethread __attribute__((no_sanitize("thread"))) |
|||
#else |
|||
#define __nosanitizeaddress |
|||
#define __nosanitizememory |
|||
#define __nosanitizethread |
|||
#endif |
|||
|
|||
/* Guard variables and structure members by lock. */ |
|||
#define __guarded_by(x) __lock_annotate(guarded_by(x)) |
|||
#define __pt_guarded_by(x) __lock_annotate(pt_guarded_by(x)) |
|||
|
|||
/* Alignment builtins for better type checking and improved code generation. */ |
|||
/* Provide fallback versions for other compilers (GCC/Clang < 10): */ |
|||
#if !__has_builtin(__builtin_is_aligned) |
|||
#define __builtin_is_aligned(x, align) \ |
|||
(((__uintptr_t)x & ((align) - 1)) == 0) |
|||
#endif |
|||
#if !__has_builtin(__builtin_align_up) |
|||
#define __builtin_align_up(x, align) \ |
|||
((__typeof__(x))(((__uintptr_t)(x)+((align)-1))&(~((align)-1)))) |
|||
#endif |
|||
#if !__has_builtin(__builtin_align_down) |
|||
#define __builtin_align_down(x, align) \ |
|||
((__typeof__(x))((x)&(~((align)-1)))) |
|||
#endif |
|||
|
|||
#define __align_up(x, y) __builtin_align_up(x, y) |
|||
#define __align_down(x, y) __builtin_align_down(x, y) |
|||
#define __is_aligned(x, y) __builtin_is_aligned(x, y) |
|||
|
|||
#endif /* !_SYS_CDEFS_H_ */ |
@ -1,29 +1,35 @@ |
|||
/* ===-- ctzdi2.c - Implement __ctzdi2 -------------------------------------===
|
|||
* |
|||
* The LLVM Compiler Infrastructure |
|||
* |
|||
* This file is dual licensed under the MIT and the University of Illinois Open |
|||
* Source Licenses. See LICENSE.TXT for details. |
|||
* |
|||
* ===----------------------------------------------------------------------=== |
|||
* |
|||
* This file implements __ctzdi2 for the compiler_rt library. |
|||
* |
|||
* ===----------------------------------------------------------------------=== |
|||
*/ |
|||
//===-- ctzdi2.c - Implement __ctzdi2 -------------------------------------===//
|
|||
//
|
|||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|||
// See https://llvm.org/LICENSE.txt for license information.
|
|||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|||
//
|
|||
//===----------------------------------------------------------------------===//
|
|||
//
|
|||
// This file implements __ctzdi2 for the compiler_rt library.
|
|||
//
|
|||
//===----------------------------------------------------------------------===//
|
|||
|
|||
#include "int_lib.h" |
|||
|
|||
/* Returns: the number of trailing 0-bits */ |
|||
// Returns: the number of trailing 0-bits
|
|||
|
|||
/* Precondition: a != 0 */ |
|||
#if !defined(__clang__) && \ |
|||
((defined(__sparc__) && defined(__arch64__)) || defined(__mips64) || \ |
|||
(defined(__riscv) && __SIZEOF_POINTER__ >= 8)) |
|||
// On 64-bit architectures with neither a native clz instruction nor a native
|
|||
// ctz instruction, gcc resolves __builtin_ctz to __ctzdi2 rather than
|
|||
// __ctzsi2, leading to infinite recursion.
|
|||
#define __builtin_ctz(a) __ctzsi2(a) |
|||
extern int __ctzsi2(si_int); |
|||
#endif |
|||
|
|||
COMPILER_RT_ABI si_int |
|||
__ctzdi2(di_int a) |
|||
{ |
|||
dwords x; |
|||
x.all = a; |
|||
const si_int f = -(x.s.low == 0); |
|||
return __builtin_ctz((x.s.high & f) | (x.s.low & ~f)) + |
|||
(f & ((si_int)(sizeof(si_int) * CHAR_BIT))); |
|||
// Precondition: a != 0
|
|||
|
|||
COMPILER_RT_ABI int __ctzdi2(di_int a) { |
|||
dwords x; |
|||
x.all = a; |
|||
const si_int f = -(x.s.low == 0); |
|||
return ctzsi((x.s.high & f) | (x.s.low & ~f)) + |
|||
(f & ((si_int)(sizeof(si_int) * CHAR_BIT))); |
|||
} |
|||
|
@ -1,29 +1,22 @@ |
|||
/* ===-- divdi3.c - Implement __divdi3 -------------------------------------===
|
|||
* |
|||
* The LLVM Compiler Infrastructure |
|||
* |
|||
* This file is dual licensed under the MIT and the University of Illinois Open |
|||
* Source Licenses. See LICENSE.TXT for details. |
|||
* |
|||
* ===----------------------------------------------------------------------=== |
|||
* |
|||
* This file implements __divdi3 for the compiler_rt library. |
|||
* |
|||
* ===----------------------------------------------------------------------=== |
|||
*/ |
|||
//===-- divdi3.c - Implement __divdi3 -------------------------------------===//
|
|||
//
|
|||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|||
// See https://llvm.org/LICENSE.txt for license information.
|
|||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|||
//
|
|||
//===----------------------------------------------------------------------===//
|
|||
//
|
|||
// This file implements __divdi3 for the compiler_rt library.
|
|||
//
|
|||
//===----------------------------------------------------------------------===//
|
|||
|
|||
#include "int_lib.h" |
|||
|
|||
/* Returns: a / b */ |
|||
// Returns: a / b
|
|||
|
|||
COMPILER_RT_ABI di_int |
|||
__divdi3(di_int a, di_int b) |
|||
{ |
|||
const int bits_in_dword_m1 = (int)(sizeof(di_int) * CHAR_BIT) - 1; |
|||
di_int s_a = a >> bits_in_dword_m1; /* s_a = a < 0 ? -1 : 0 */ |
|||
di_int s_b = b >> bits_in_dword_m1; /* s_b = b < 0 ? -1 : 0 */ |
|||
a = (a ^ s_a) - s_a; /* negate if s_a == -1 */ |
|||
b = (b ^ s_b) - s_b; /* negate if s_b == -1 */ |
|||
s_a ^= s_b; /*sign of quotient */ |
|||
return (__udivmoddi4(a, b, (du_int*)0) ^ s_a) - s_a; /* negate if s_a == -1 */ |
|||
} |
|||
#define fixint_t di_int |
|||
#define fixuint_t du_int |
|||
#define COMPUTE_UDIV(a, b) __udivmoddi4((a), (b), (du_int *)0) |
|||
#include "int_div_impl.inc" |
|||
|
|||
COMPILER_RT_ABI di_int __divdi3(di_int a, di_int b) { return __divXi3(a, b); } |
|||
|
@ -1,25 +1,28 @@ |
|||
/*===-- divmoddi4.c - Implement __divmoddi4 --------------------------------===
|
|||
* |
|||
* The LLVM Compiler Infrastructure |
|||
* |
|||
* This file is dual licensed under the MIT and the University of Illinois Open |
|||
* Source Licenses. See LICENSE.TXT for details. |
|||
* |
|||
* ===----------------------------------------------------------------------=== |
|||
* |
|||
* This file implements __divmoddi4 for the compiler_rt library. |
|||
* |
|||
* ===----------------------------------------------------------------------=== |
|||
*/ |
|||
//===-- divmoddi4.c - Implement __divmoddi4 -------------------------------===//
|
|||
//
|
|||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|||
// See https://llvm.org/LICENSE.txt for license information.
|
|||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|||
//
|
|||
//===----------------------------------------------------------------------===//
|
|||
//
|
|||
// This file implements __divmoddi4 for the compiler_rt library.
|
|||
//
|
|||
//===----------------------------------------------------------------------===//
|
|||
|
|||
#include "int_lib.h" |
|||
|
|||
/* Returns: a / b, *rem = a % b */ |
|||
// Returns: a / b, *rem = a % b
|
|||
|
|||
COMPILER_RT_ABI di_int |
|||
__divmoddi4(di_int a, di_int b, di_int* rem) |
|||
{ |
|||
di_int d = __divdi3(a,b); |
|||
*rem = a - (d*b); |
|||
return d; |
|||
COMPILER_RT_ABI di_int __divmoddi4(di_int a, di_int b, di_int *rem) { |
|||
const int bits_in_dword_m1 = (int)(sizeof(di_int) * CHAR_BIT) - 1; |
|||
di_int s_a = a >> bits_in_dword_m1; // s_a = a < 0 ? -1 : 0
|
|||
di_int s_b = b >> bits_in_dword_m1; // s_b = b < 0 ? -1 : 0
|
|||
a = (a ^ s_a) - s_a; // negate if s_a == -1
|
|||
b = (b ^ s_b) - s_b; // negate if s_b == -1
|
|||
s_b ^= s_a; // sign of quotient
|
|||
du_int r; |
|||
di_int q = (__udivmoddi4(a, b, &r) ^ s_b) - s_b; // negate if s_b == -1
|
|||
*rem = (r ^ s_a) - s_a; // negate if s_a == -1
|
|||
return q; |
|||
} |
|||
|
@ -0,0 +1,95 @@ |
|||
//===-- int_div_impl.inc - Integer division ---------------------*- C++ -*-===// |
|||
// |
|||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
|||
// See https://llvm.org/LICENSE.txt for license information. |
|||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
|||
// |
|||
//===----------------------------------------------------------------------===// |
|||
// |
|||
// Helpers used by __udivsi3, __umodsi3, __udivdi3, and __umodsi3. |
|||
// |
|||
//===----------------------------------------------------------------------===// |
|||
|
|||
#define clz(a) (sizeof(a) == sizeof(unsigned long long) ? __builtin_clzll(a) : clzsi(a)) |
|||
|
|||
// Adapted from Figure 3-40 of The PowerPC Compiler Writer's Guide |
|||
static __inline fixuint_t __udivXi3(fixuint_t n, fixuint_t d) { |
|||
const unsigned N = sizeof(fixuint_t) * CHAR_BIT; |
|||
// d == 0 cases are unspecified. |
|||
unsigned sr = (d ? clz(d) : N) - (n ? clz(n) : N); |
|||
// 0 <= sr <= N - 1 or sr is very large. |
|||
if (sr > N - 1) // n < d |
|||
return 0; |
|||
if (sr == N - 1) // d == 1 |
|||
return n; |
|||
++sr; |
|||
// 1 <= sr <= N - 1. Shifts do not trigger UB. |
|||
fixuint_t r = n >> sr; |
|||
n <<= N - sr; |
|||
fixuint_t carry = 0; |
|||
for (; sr > 0; --sr) { |
|||
r = (r << 1) | (n >> (N - 1)); |
|||
n = (n << 1) | carry; |
|||
// Branch-less version of: |
|||
// carry = 0; |
|||
// if (r >= d) r -= d, carry = 1; |
|||
const fixint_t s = (fixint_t)(d - r - 1) >> (N - 1); |
|||
carry = s & 1; |
|||
r -= d & s; |
|||
} |
|||
n = (n << 1) | carry; |
|||
return n; |
|||
} |
|||
|
|||
// Mostly identical to __udivXi3 but the return values are different. |
|||
static __inline fixuint_t __umodXi3(fixuint_t n, fixuint_t d) { |
|||
const unsigned N = sizeof(fixuint_t) * CHAR_BIT; |
|||
// d == 0 cases are unspecified. |
|||
unsigned sr = (d ? clz(d) : N) - (n ? clz(n) : N); |
|||
// 0 <= sr <= N - 1 or sr is very large. |
|||
if (sr > N - 1) // n < d |
|||
return n; |
|||
if (sr == N - 1) // d == 1 |
|||
return 0; |
|||
++sr; |
|||
// 1 <= sr <= N - 1. Shifts do not trigger UB. |
|||
fixuint_t r = n >> sr; |
|||
n <<= N - sr; |
|||
fixuint_t carry = 0; |
|||
for (; sr > 0; --sr) { |
|||
r = (r << 1) | (n >> (N - 1)); |
|||
n = (n << 1) | carry; |
|||
// Branch-less version of: |
|||
// carry = 0; |
|||
// if (r >= d) r -= d, carry = 1; |
|||
const fixint_t s = (fixint_t)(d - r - 1) >> (N - 1); |
|||
carry = s & 1; |
|||
r -= d & s; |
|||
} |
|||
return r; |
|||
} |
|||
|
|||
#ifdef COMPUTE_UDIV |
|||
static __inline fixint_t __divXi3(fixint_t a, fixint_t b) { |
|||
const int N = (int)(sizeof(fixint_t) * CHAR_BIT) - 1; |
|||
fixint_t s_a = a >> N; // s_a = a < 0 ? -1 : 0 |
|||
fixint_t s_b = b >> N; // s_b = b < 0 ? -1 : 0 |
|||
fixuint_t a_u = (fixuint_t)(a ^ s_a) + (-s_a); // negate if s_a == -1 |
|||
fixuint_t b_u = (fixuint_t)(b ^ s_b) + (-s_b); // negate if s_b == -1 |
|||
s_a ^= s_b; // sign of quotient |
|||
return (COMPUTE_UDIV(a_u, b_u) ^ s_a) + (-s_a); // negate if s_a == -1 |
|||
} |
|||
#endif // COMPUTE_UDIV |
|||
|
|||
#ifdef ASSIGN_UMOD |
|||
static __inline fixint_t __modXi3(fixint_t a, fixint_t b) { |
|||
const int N = (int)(sizeof(fixint_t) * CHAR_BIT) - 1; |
|||
fixint_t s = b >> N; // s = b < 0 ? -1 : 0 |
|||
fixuint_t b_u = (fixuint_t)(b ^ s) + (-s); // negate if s == -1 |
|||
s = a >> N; // s = a < 0 ? -1 : 0 |
|||
fixuint_t a_u = (fixuint_t)(a ^ s) + (-s); // negate if s == -1 |
|||
fixuint_t res; |
|||
ASSIGN_UMOD(res, a_u, b_u); |
|||
return (res ^ s) + (-s); // negate if s == -1 |
|||
} |
|||
#endif // ASSIGN_UMOD |
@ -0,0 +1,47 @@ |
|||
//===-- int_util.h - internal utility functions ---------------------------===//
|
|||
//
|
|||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|||
// See https://llvm.org/LICENSE.txt for license information.
|
|||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|||
//
|
|||
//===----------------------------------------------------------------------===//
|
|||
//
|
|||
// This file is not part of the interface of this library.
|
|||
//
|
|||
// This file defines non-inline utilities which are available for use in the
|
|||
// library. The function definitions themselves are all contained in int_util.c
|
|||
// which will always be compiled into any compiler-rt library.
|
|||
//
|
|||
//===----------------------------------------------------------------------===//
|
|||
|
|||
#ifndef INT_UTIL_H |
|||
#define INT_UTIL_H |
|||
|
|||
/// \brief Trigger a program abort (or panic for kernel code).
|
|||
#define compilerrt_abort() __compilerrt_abort_impl(__FILE__, __LINE__, __func__) |
|||
|
|||
NORETURN void __compilerrt_abort_impl(const char *file, int line, |
|||
const char *function); |
|||
|
|||
#define COMPILE_TIME_ASSERT(expr) COMPILE_TIME_ASSERT1(expr, __COUNTER__) |
|||
#define COMPILE_TIME_ASSERT1(expr, cnt) COMPILE_TIME_ASSERT2(expr, cnt) |
|||
#define COMPILE_TIME_ASSERT2(expr, cnt) \ |
|||
typedef char ct_assert_##cnt[(expr) ? 1 : -1] UNUSED |
|||
|
|||
// Force unrolling the code specified to be repeated N times.
|
|||
#define REPEAT_0_TIMES(code_to_repeat) /* do nothing */ |
|||
#define REPEAT_1_TIMES(code_to_repeat) code_to_repeat |
|||
#define REPEAT_2_TIMES(code_to_repeat) \ |
|||
REPEAT_1_TIMES(code_to_repeat) \ |
|||
code_to_repeat |
|||
#define REPEAT_3_TIMES(code_to_repeat) \ |
|||
REPEAT_2_TIMES(code_to_repeat) \ |
|||
code_to_repeat |
|||
#define REPEAT_4_TIMES(code_to_repeat) \ |
|||
REPEAT_3_TIMES(code_to_repeat) \ |
|||
code_to_repeat |
|||
|
|||
#define REPEAT_N_TIMES_(N, code_to_repeat) REPEAT_##N##_TIMES(code_to_repeat) |
|||
#define REPEAT_N_TIMES(N, code_to_repeat) REPEAT_N_TIMES_(N, code_to_repeat) |
|||
|
|||
#endif // INT_UTIL_H
|
@ -1,45 +1,38 @@ |
|||
/* ===-- lshrdi3.c - Implement __lshrdi3 -----------------------------------===
|
|||
* |
|||
* The LLVM Compiler Infrastructure |
|||
* |
|||
* This file is dual licensed under the MIT and the University of Illinois Open |
|||
* Source Licenses. See LICENSE.TXT for details. |
|||
* |
|||
* ===----------------------------------------------------------------------=== |
|||
* |
|||
* This file implements __lshrdi3 for the compiler_rt library. |
|||
* |
|||
* ===----------------------------------------------------------------------=== |
|||
*/ |
|||
//===-- lshrdi3.c - Implement __lshrdi3 -----------------------------------===//
|
|||
//
|
|||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|||
// See https://llvm.org/LICENSE.txt for license information.
|
|||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|||
//
|
|||
//===----------------------------------------------------------------------===//
|
|||
//
|
|||
// This file implements __lshrdi3 for the compiler_rt library.
|
|||
//
|
|||
//===----------------------------------------------------------------------===//
|
|||
|
|||
#include "int_lib.h" |
|||
|
|||
/* Returns: logical a >> b */ |
|||
// Returns: logical a >> b
|
|||
|
|||
/* Precondition: 0 <= b < bits_in_dword */ |
|||
// Precondition: 0 <= b < bits_in_dword
|
|||
|
|||
COMPILER_RT_ABI di_int |
|||
__lshrdi3(di_int a, si_int b) |
|||
{ |
|||
const int bits_in_word = (int)(sizeof(si_int) * CHAR_BIT); |
|||
udwords input; |
|||
udwords result; |
|||
input.all = a; |
|||
if (b & bits_in_word) /* bits_in_word <= b < bits_in_dword */ |
|||
{ |
|||
result.s.high = 0; |
|||
result.s.low = input.s.high >> (b - bits_in_word); |
|||
} |
|||
else /* 0 <= b < bits_in_word */ |
|||
{ |
|||
if (b == 0) |
|||
return a; |
|||
result.s.high = input.s.high >> b; |
|||
result.s.low = (input.s.high << (bits_in_word - b)) | (input.s.low >> b); |
|||
} |
|||
return result.all; |
|||
COMPILER_RT_ABI di_int __lshrdi3(di_int a, int b) { |
|||
const int bits_in_word = (int)(sizeof(si_int) * CHAR_BIT); |
|||
udwords input; |
|||
udwords result; |
|||
input.all = a; |
|||
if (b & bits_in_word) /* bits_in_word <= b < bits_in_dword */ { |
|||
result.s.high = 0; |
|||
result.s.low = input.s.high >> (b - bits_in_word); |
|||
} else /* 0 <= b < bits_in_word */ { |
|||
if (b == 0) |
|||
return a; |
|||
result.s.high = input.s.high >> b; |
|||
result.s.low = (input.s.high << (bits_in_word - b)) | (input.s.low >> b); |
|||
} |
|||
return result.all; |
|||
} |
|||
|
|||
#if defined(__ARM_EABI__) |
|||
AEABI_RTABI di_int __aeabi_llsr(di_int a, si_int b) COMPILER_RT_ALIAS(__lshrdi3); |
|||
COMPILER_RT_ALIAS(__lshrdi3, __aeabi_llsr) |
|||
#endif |
|||
|
@ -1,36 +1,32 @@ |
|||
/* ===-- popcountdi2.c - Implement __popcountdi2 ----------------------------===
|
|||
* |
|||
* The LLVM Compiler Infrastructure |
|||
* |
|||
* This file is dual licensed under the MIT and the University of Illinois Open |
|||
* Source Licenses. See LICENSE.TXT for details. |
|||
* |
|||
* ===----------------------------------------------------------------------=== |
|||
* |
|||
* This file implements __popcountdi2 for the compiler_rt library. |
|||
* |
|||
* ===----------------------------------------------------------------------=== |
|||
*/ |
|||
//===-- popcountdi2.c - Implement __popcountdi2 ---------------------------===//
|
|||
//
|
|||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|||
// See https://llvm.org/LICENSE.txt for license information.
|
|||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|||
//
|
|||
//===----------------------------------------------------------------------===//
|
|||
//
|
|||
// This file implements __popcountdi2 for the compiler_rt library.
|
|||
//
|
|||
//===----------------------------------------------------------------------===//
|
|||
|
|||
#include "int_lib.h" |
|||
|
|||
/* Returns: count of 1 bits */ |
|||
// Returns: count of 1 bits
|
|||
|
|||
COMPILER_RT_ABI si_int |
|||
__popcountdi2(di_int a) |
|||
{ |
|||
du_int x2 = (du_int)a; |
|||
x2 = x2 - ((x2 >> 1) & 0x5555555555555555uLL); |
|||
/* Every 2 bits holds the sum of every pair of bits (32) */ |
|||
x2 = ((x2 >> 2) & 0x3333333333333333uLL) + (x2 & 0x3333333333333333uLL); |
|||
/* Every 4 bits holds the sum of every 4-set of bits (3 significant bits) (16) */ |
|||
x2 = (x2 + (x2 >> 4)) & 0x0F0F0F0F0F0F0F0FuLL; |
|||
/* Every 8 bits holds the sum of every 8-set of bits (4 significant bits) (8) */ |
|||
su_int x = (su_int)(x2 + (x2 >> 32)); |
|||
/* The lower 32 bits hold four 16 bit sums (5 significant bits). */ |
|||
/* Upper 32 bits are garbage */ |
|||
x = x + (x >> 16); |
|||
/* The lower 16 bits hold two 32 bit sums (6 significant bits). */ |
|||
/* Upper 16 bits are garbage */ |
|||
return (x + (x >> 8)) & 0x0000007F; /* (7 significant bits) */ |
|||
COMPILER_RT_ABI int __popcountdi2(di_int a) { |
|||
du_int x2 = (du_int)a; |
|||
x2 = x2 - ((x2 >> 1) & 0x5555555555555555uLL); |
|||
// Every 2 bits holds the sum of every pair of bits (32)
|
|||
x2 = ((x2 >> 2) & 0x3333333333333333uLL) + (x2 & 0x3333333333333333uLL); |
|||
// Every 4 bits holds the sum of every 4-set of bits (3 significant bits) (16)
|
|||
x2 = (x2 + (x2 >> 4)) & 0x0F0F0F0F0F0F0F0FuLL; |
|||
// Every 8 bits holds the sum of every 8-set of bits (4 significant bits) (8)
|
|||
su_int x = (su_int)(x2 + (x2 >> 32)); |
|||
// The lower 32 bits hold four 16 bit sums (5 significant bits).
|
|||
// Upper 32 bits are garbage
|
|||
x = x + (x >> 16); |
|||
// The lower 16 bits hold two 32 bit sums (6 significant bits).
|
|||
// Upper 16 bits are garbage
|
|||
return (x + (x >> 8)) & 0x0000007F; // (7 significant bits)
|
|||
} |
|||
|
@ -1,33 +1,29 @@ |
|||
/* ===-- popcountsi2.c - Implement __popcountsi2 ---------------------------===
|
|||
* |
|||
* The LLVM Compiler Infrastructure |
|||
* |
|||
* This file is dual licensed under the MIT and the University of Illinois Open |
|||
* Source Licenses. See LICENSE.TXT for details. |
|||
* |
|||
* ===----------------------------------------------------------------------=== |
|||
* |
|||
* This file implements __popcountsi2 for the compiler_rt library. |
|||
* |
|||
* ===----------------------------------------------------------------------=== |
|||
*/ |
|||
//===-- popcountsi2.c - Implement __popcountsi2 ---------------------------===//
|
|||
//
|
|||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|||
// See https://llvm.org/LICENSE.txt for license information.
|
|||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|||
//
|
|||
//===----------------------------------------------------------------------===//
|
|||
//
|
|||
// This file implements __popcountsi2 for the compiler_rt library.
|
|||
//
|
|||
//===----------------------------------------------------------------------===//
|
|||
|
|||
#include "int_lib.h" |
|||
|
|||
/* Returns: count of 1 bits */ |
|||
// Returns: count of 1 bits
|
|||
|
|||
COMPILER_RT_ABI si_int |
|||
__popcountsi2(si_int a) |
|||
{ |
|||
su_int x = (su_int)a; |
|||
x = x - ((x >> 1) & 0x55555555); |
|||
/* Every 2 bits holds the sum of every pair of bits */ |
|||
x = ((x >> 2) & 0x33333333) + (x & 0x33333333); |
|||
/* Every 4 bits holds the sum of every 4-set of bits (3 significant bits) */ |
|||
x = (x + (x >> 4)) & 0x0F0F0F0F; |
|||
/* Every 8 bits holds the sum of every 8-set of bits (4 significant bits) */ |
|||
x = (x + (x >> 16)); |
|||
/* The lower 16 bits hold two 8 bit sums (5 significant bits).*/ |
|||
/* Upper 16 bits are garbage */ |
|||
return (x + (x >> 8)) & 0x0000003F; /* (6 significant bits) */ |
|||
COMPILER_RT_ABI int __popcountsi2(si_int a) { |
|||
su_int x = (su_int)a; |
|||
x = x - ((x >> 1) & 0x55555555); |
|||
// Every 2 bits holds the sum of every pair of bits
|
|||
x = ((x >> 2) & 0x33333333) + (x & 0x33333333); |
|||
// Every 4 bits holds the sum of every 4-set of bits (3 significant bits)
|
|||
x = (x + (x >> 4)) & 0x0F0F0F0F; |
|||
// Every 8 bits holds the sum of every 8-set of bits (4 significant bits)
|
|||
x = (x + (x >> 16)); |
|||
// The lower 16 bits hold two 8 bit sums (5 significant bits).
|
|||
// Upper 16 bits are garbage
|
|||
return (x + (x >> 8)) & 0x0000003F; // (6 significant bits)
|
|||
} |
|||
|
@ -1,231 +1,200 @@ |
|||
/* ===-- udivmoddi4.c - Implement __udivmoddi4 -----------------------------===
|
|||
* |
|||
* The LLVM Compiler Infrastructure |
|||
* |
|||
* This file is dual licensed under the MIT and the University of Illinois Open |
|||
* Source Licenses. See LICENSE.TXT for details. |
|||
* |
|||
* ===----------------------------------------------------------------------=== |
|||
* |
|||
* This file implements __udivmoddi4 for the compiler_rt library. |
|||
* |
|||
* ===----------------------------------------------------------------------=== |
|||
*/ |
|||
//===-- udivmoddi4.c - Implement __udivmoddi4 -----------------------------===//
|
|||
//
|
|||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|||
// See https://llvm.org/LICENSE.txt for license information.
|
|||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|||
//
|
|||
//===----------------------------------------------------------------------===//
|
|||
//
|
|||
// This file implements __udivmoddi4 for the compiler_rt library.
|
|||
//
|
|||
//===----------------------------------------------------------------------===//
|
|||
|
|||
#include "int_lib.h" |
|||
|
|||
/* Effects: if rem != 0, *rem = a % b
|
|||
* Returns: a / b |
|||
*/ |
|||
// Effects: if rem != 0, *rem = a % b
|
|||
// Returns: a / b
|
|||
|
|||
/* Translated from Figure 3-40 of The PowerPC Compiler Writer's Guide */ |
|||
// Translated from Figure 3-40 of The PowerPC Compiler Writer's Guide
|
|||
|
|||
COMPILER_RT_ABI du_int |
|||
__udivmoddi4(du_int a, du_int b, du_int* rem) |
|||
{ |
|||
const unsigned n_uword_bits = sizeof(su_int) * CHAR_BIT; |
|||
const unsigned n_udword_bits = sizeof(du_int) * CHAR_BIT; |
|||
udwords n; |
|||
n.all = a; |
|||
udwords d; |
|||
d.all = b; |
|||
udwords q; |
|||
udwords r; |
|||
unsigned sr; |
|||
/* special cases, X is unknown, K != 0 */ |
|||
if (n.s.high == 0) |
|||
{ |
|||
if (d.s.high == 0) |
|||
{ |
|||
/* 0 X
|
|||
* --- |
|||
* 0 X |
|||
*/ |
|||
if (rem) |
|||
*rem = n.s.low % d.s.low; |
|||
return n.s.low / d.s.low; |
|||
} |
|||
/* 0 X
|
|||
* --- |
|||
* K X |
|||
*/ |
|||
if (rem) |
|||
*rem = n.s.low; |
|||
return 0; |
|||
#if defined(_MSC_VER) && !defined(__clang__) |
|||
// MSVC throws a warning about mod 0 here, disable it for builds that
|
|||
// warn-as-error
|
|||
#pragma warning(push) |
|||
#pragma warning(disable : 4723 4724) |
|||
#endif |
|||
|
|||
COMPILER_RT_ABI du_int __udivmoddi4(du_int a, du_int b, du_int *rem) { |
|||
const unsigned n_uword_bits = sizeof(su_int) * CHAR_BIT; |
|||
const unsigned n_udword_bits = sizeof(du_int) * CHAR_BIT; |
|||
udwords n; |
|||
n.all = a; |
|||
udwords d; |
|||
d.all = b; |
|||
udwords q; |
|||
udwords r; |
|||
unsigned sr; |
|||
// special cases, X is unknown, K != 0
|
|||
if (n.s.high == 0) { |
|||
if (d.s.high == 0) { |
|||
// 0 X
|
|||
// ---
|
|||
// 0 X
|
|||
if (rem) |
|||
*rem = n.s.low % d.s.low; |
|||
return n.s.low / d.s.low; |
|||
} |
|||
/* n.s.high != 0 */ |
|||
if (d.s.low == 0) |
|||
{ |
|||
if (d.s.high == 0) |
|||
{ |
|||
/* K X
|
|||
* --- |
|||
* 0 0 |
|||
*/ |
|||
if (rem) |
|||
*rem = n.s.high % d.s.low; |
|||
return n.s.high / d.s.low; |
|||
} |
|||
/* d.s.high != 0 */ |
|||
if (n.s.low == 0) |
|||
{ |
|||
/* K 0
|
|||
* --- |
|||
* K 0 |
|||
*/ |
|||
if (rem) |
|||
{ |
|||
r.s.high = n.s.high % d.s.high; |
|||
r.s.low = 0; |
|||
*rem = r.all; |
|||
} |
|||
return n.s.high / d.s.high; |
|||
} |
|||
/* K K
|
|||
* --- |
|||
* K 0 |
|||
*/ |
|||
if ((d.s.high & (d.s.high - 1)) == 0) /* if d is a power of 2 */ |
|||
{ |
|||
if (rem) |
|||
{ |
|||
r.s.low = n.s.low; |
|||
r.s.high = n.s.high & (d.s.high - 1); |
|||
*rem = r.all; |
|||
} |
|||
return n.s.high >> __builtin_ctz(d.s.high); |
|||
} |
|||
/* K K
|
|||
* --- |
|||
* K 0 |
|||
*/ |
|||
sr = __builtin_clz(d.s.high) - __builtin_clz(n.s.high); |
|||
/* 0 <= sr <= n_uword_bits - 2 or sr large */ |
|||
if (sr > n_uword_bits - 2) |
|||
{ |
|||
if (rem) |
|||
*rem = n.all; |
|||
return 0; |
|||
} |
|||
++sr; |
|||
/* 1 <= sr <= n_uword_bits - 1 */ |
|||
/* q.all = n.all << (n_udword_bits - sr); */ |
|||
// 0 X
|
|||
// ---
|
|||
// K X
|
|||
if (rem) |
|||
*rem = n.s.low; |
|||
return 0; |
|||
} |
|||
// n.s.high != 0
|
|||
if (d.s.low == 0) { |
|||
if (d.s.high == 0) { |
|||
// K X
|
|||
// ---
|
|||
// 0 0
|
|||
if (rem) |
|||
*rem = n.s.high % d.s.low; |
|||
return n.s.high / d.s.low; |
|||
} |
|||
// d.s.high != 0
|
|||
if (n.s.low == 0) { |
|||
// K 0
|
|||
// ---
|
|||
// K 0
|
|||
if (rem) { |
|||
r.s.high = n.s.high % d.s.high; |
|||
r.s.low = 0; |
|||
*rem = r.all; |
|||
} |
|||
return n.s.high / d.s.high; |
|||
} |
|||
// K K
|
|||
// ---
|
|||
// K 0
|
|||
if ((d.s.high & (d.s.high - 1)) == 0) /* if d is a power of 2 */ { |
|||
if (rem) { |
|||
r.s.low = n.s.low; |
|||
r.s.high = n.s.high & (d.s.high - 1); |
|||
*rem = r.all; |
|||
} |
|||
return n.s.high >> ctzsi(d.s.high); |
|||
} |
|||
// K K
|
|||
// ---
|
|||
// K 0
|
|||
sr = clzsi(d.s.high) - clzsi(n.s.high); |
|||
// 0 <= sr <= n_uword_bits - 2 or sr large
|
|||
if (sr > n_uword_bits - 2) { |
|||
if (rem) |
|||
*rem = n.all; |
|||
return 0; |
|||
} |
|||
++sr; |
|||
// 1 <= sr <= n_uword_bits - 1
|
|||
// q.all = n.all << (n_udword_bits - sr);
|
|||
q.s.low = 0; |
|||
q.s.high = n.s.low << (n_uword_bits - sr); |
|||
// r.all = n.all >> sr;
|
|||
r.s.high = n.s.high >> sr; |
|||
r.s.low = (n.s.high << (n_uword_bits - sr)) | (n.s.low >> sr); |
|||
} else /* d.s.low != 0 */ { |
|||
if (d.s.high == 0) { |
|||
// K X
|
|||
// ---
|
|||
// 0 K
|
|||
if ((d.s.low & (d.s.low - 1)) == 0) /* if d is a power of 2 */ { |
|||
if (rem) |
|||
*rem = n.s.low & (d.s.low - 1); |
|||
if (d.s.low == 1) |
|||
return n.all; |
|||
sr = ctzsi(d.s.low); |
|||
q.s.high = n.s.high >> sr; |
|||
q.s.low = (n.s.high << (n_uword_bits - sr)) | (n.s.low >> sr); |
|||
return q.all; |
|||
} |
|||
// K X
|
|||
// ---
|
|||
// 0 K
|
|||
sr = 1 + n_uword_bits + clzsi(d.s.low) - clzsi(n.s.high); |
|||
// 2 <= sr <= n_udword_bits - 1
|
|||
// q.all = n.all << (n_udword_bits - sr);
|
|||
// r.all = n.all >> sr;
|
|||
if (sr == n_uword_bits) { |
|||
q.s.low = 0; |
|||
q.s.high = n.s.low; |
|||
r.s.high = 0; |
|||
r.s.low = n.s.high; |
|||
} else if (sr < n_uword_bits) /* 2 <= sr <= n_uword_bits - 1 */ { |
|||
q.s.low = 0; |
|||
q.s.high = n.s.low << (n_uword_bits - sr); |
|||
/* r.all = n.all >> sr; */ |
|||
r.s.high = n.s.high >> sr; |
|||
r.s.low = (n.s.high << (n_uword_bits - sr)) | (n.s.low >> sr); |
|||
} else /* n_uword_bits + 1 <= sr <= n_udword_bits - 1 */ { |
|||
q.s.low = n.s.low << (n_udword_bits - sr); |
|||
q.s.high = (n.s.high << (n_udword_bits - sr)) | |
|||
(n.s.low >> (sr - n_uword_bits)); |
|||
r.s.high = 0; |
|||
r.s.low = n.s.high >> (sr - n_uword_bits); |
|||
} |
|||
} else { |
|||
// K X
|
|||
// ---
|
|||
// K K
|
|||
sr = clzsi(d.s.high) - clzsi(n.s.high); |
|||
// 0 <= sr <= n_uword_bits - 1 or sr large
|
|||
if (sr > n_uword_bits - 1) { |
|||
if (rem) |
|||
*rem = n.all; |
|||
return 0; |
|||
} |
|||
++sr; |
|||
// 1 <= sr <= n_uword_bits
|
|||
// q.all = n.all << (n_udword_bits - sr);
|
|||
q.s.low = 0; |
|||
if (sr == n_uword_bits) { |
|||
q.s.high = n.s.low; |
|||
r.s.high = 0; |
|||
r.s.low = n.s.high; |
|||
} else { |
|||
q.s.high = n.s.low << (n_uword_bits - sr); |
|||
r.s.high = n.s.high >> sr; |
|||
r.s.low = (n.s.high << (n_uword_bits - sr)) | (n.s.low >> sr); |
|||
} |
|||
} |
|||
else /* d.s.low != 0 */ |
|||
{ |
|||
if (d.s.high == 0) |
|||
{ |
|||
/* K X
|
|||
* --- |
|||
* 0 K |
|||
*/ |
|||
if ((d.s.low & (d.s.low - 1)) == 0) /* if d is a power of 2 */ |
|||
{ |
|||
if (rem) |
|||
*rem = n.s.low & (d.s.low - 1); |
|||
if (d.s.low == 1) |
|||
return n.all; |
|||
sr = __builtin_ctz(d.s.low); |
|||
q.s.high = n.s.high >> sr; |
|||
q.s.low = (n.s.high << (n_uword_bits - sr)) | (n.s.low >> sr); |
|||
return q.all; |
|||
} |
|||
/* K X
|
|||
* --- |
|||
* 0 K |
|||
*/ |
|||
sr = 1 + n_uword_bits + __builtin_clz(d.s.low) - __builtin_clz(n.s.high); |
|||
/* 2 <= sr <= n_udword_bits - 1
|
|||
* q.all = n.all << (n_udword_bits - sr); |
|||
* r.all = n.all >> sr; |
|||
*/ |
|||
if (sr == n_uword_bits) |
|||
{ |
|||
q.s.low = 0; |
|||
q.s.high = n.s.low; |
|||
r.s.high = 0; |
|||
r.s.low = n.s.high; |
|||
} |
|||
else if (sr < n_uword_bits) // 2 <= sr <= n_uword_bits - 1
|
|||
{ |
|||
q.s.low = 0; |
|||
q.s.high = n.s.low << (n_uword_bits - sr); |
|||
r.s.high = n.s.high >> sr; |
|||
r.s.low = (n.s.high << (n_uword_bits - sr)) | (n.s.low >> sr); |
|||
} |
|||
else // n_uword_bits + 1 <= sr <= n_udword_bits - 1
|
|||
{ |
|||
q.s.low = n.s.low << (n_udword_bits - sr); |
|||
q.s.high = (n.s.high << (n_udword_bits - sr)) | |
|||
(n.s.low >> (sr - n_uword_bits)); |
|||
r.s.high = 0; |
|||
r.s.low = n.s.high >> (sr - n_uword_bits); |
|||
} |
|||
} |
|||
else |
|||
{ |
|||
/* K X
|
|||
* --- |
|||
* K K |
|||
*/ |
|||
sr = __builtin_clz(d.s.high) - __builtin_clz(n.s.high); |
|||
/* 0 <= sr <= n_uword_bits - 1 or sr large */ |
|||
if (sr > n_uword_bits - 1) |
|||
{ |
|||
if (rem) |
|||
*rem = n.all; |
|||
return 0; |
|||
} |
|||
++sr; |
|||
/* 1 <= sr <= n_uword_bits */ |
|||
/* q.all = n.all << (n_udword_bits - sr); */ |
|||
q.s.low = 0; |
|||
if (sr == n_uword_bits) |
|||
{ |
|||
q.s.high = n.s.low; |
|||
r.s.high = 0; |
|||
r.s.low = n.s.high; |
|||
} |
|||
else |
|||
{ |
|||
q.s.high = n.s.low << (n_uword_bits - sr); |
|||
r.s.high = n.s.high >> sr; |
|||
r.s.low = (n.s.high << (n_uword_bits - sr)) | (n.s.low >> sr); |
|||
} |
|||
} |
|||
} |
|||
/* Not a special case
|
|||
* q and r are initialized with: |
|||
* q.all = n.all << (n_udword_bits - sr); |
|||
* r.all = n.all >> sr; |
|||
* 1 <= sr <= n_udword_bits - 1 |
|||
*/ |
|||
su_int carry = 0; |
|||
for (; sr > 0; --sr) |
|||
{ |
|||
/* r:q = ((r:q) << 1) | carry */ |
|||
r.s.high = (r.s.high << 1) | (r.s.low >> (n_uword_bits - 1)); |
|||
r.s.low = (r.s.low << 1) | (q.s.high >> (n_uword_bits - 1)); |
|||
q.s.high = (q.s.high << 1) | (q.s.low >> (n_uword_bits - 1)); |
|||
q.s.low = (q.s.low << 1) | carry; |
|||
/* carry = 0;
|
|||
* if (r.all >= d.all) |
|||
* { |
|||
* r.all -= d.all; |
|||
* carry = 1; |
|||
* } |
|||
*/ |
|||
const di_int s = (di_int)(d.all - r.all - 1) >> (n_udword_bits - 1); |
|||
carry = s & 1; |
|||
r.all -= d.all & s; |
|||
} |
|||
q.all = (q.all << 1) | carry; |
|||
if (rem) |
|||
*rem = r.all; |
|||
return q.all; |
|||
} |
|||
// Not a special case
|
|||
// q and r are initialized with:
|
|||
// q.all = n.all << (n_udword_bits - sr);
|
|||
// r.all = n.all >> sr;
|
|||
// 1 <= sr <= n_udword_bits - 1
|
|||
su_int carry = 0; |
|||
for (; sr > 0; --sr) { |
|||
// r:q = ((r:q) << 1) | carry
|
|||
r.s.high = (r.s.high << 1) | (r.s.low >> (n_uword_bits - 1)); |
|||
r.s.low = (r.s.low << 1) | (q.s.high >> (n_uword_bits - 1)); |
|||
q.s.high = (q.s.high << 1) | (q.s.low >> (n_uword_bits - 1)); |
|||
q.s.low = (q.s.low << 1) | carry; |
|||
// carry = 0;
|
|||
// if (r.all >= d.all)
|
|||
// {
|
|||
// r.all -= d.all;
|
|||
// carry = 1;
|
|||
// }
|
|||
const di_int s = (di_int)(d.all - r.all - 1) >> (n_udword_bits - 1); |
|||
carry = s & 1; |
|||
r.all -= d.all & s; |
|||
} |
|||
q.all = (q.all << 1) | carry; |
|||
if (rem) |
|||
*rem = r.all; |
|||
return q.all; |
|||
} |
|||
|
|||
#if defined(_MSC_VER) && !defined(__clang__) |
|||
#pragma warning(pop) |
|||
#endif |
|||
|
Loading…
Reference in new issue