[v1,1/2] stdlib: Refactor {u}int_fast defs in stdint
Checks
Context |
Check |
Description |
dj/TryBot-apply_patch |
success
|
Patch applied to master at the time it was sent
|
Commit Message
The goal is to make it easier to provide system specific defs for the
sizes of {u}int_fast{8|16|32|64}.
Note this commit does not change any of the previous values.
Full xcheck passes on x86_64.
---
stdlib/stdint.h | 70 +-----------------------
sysdeps/generic/int-fast.h | 107 +++++++++++++++++++++++++++++++++++++
2 files changed, 108 insertions(+), 69 deletions(-)
create mode 100644 sysdeps/generic/int-fast.h
Comments
On Sun, 10 Apr 2022, Noah Goldstein via Libc-alpha wrote:
> The goal is to make it easier to provide system specific defs for the
> sizes of {u}int_fast{8|16|32|64}.
>
> Note this commit does not change any of the previous values.
>
> Full xcheck passes on x86_64.
> ---
> stdlib/stdint.h | 70 +-----------------------
> sysdeps/generic/int-fast.h | 107 +++++++++++++++++++++++++++++++++++++
stdint.h is an installed header, so any headers it includes must also be
installed headers (i.e. listed in headers in Makefile). Any installed
header whose name is not a public API should be in bits/, and this header
would clearly fall in that category - no user should ever #include
<int-fast.h> themselves.
@@ -52,35 +52,6 @@ typedef __uint_least32_t uint_least32_t;
typedef __uint_least64_t uint_least64_t;
-/* Fast types. */
-
-/* Signed. */
-typedef signed char int_fast8_t;
-#if __WORDSIZE == 64
-typedef long int int_fast16_t;
-typedef long int int_fast32_t;
-typedef long int int_fast64_t;
-#else
-typedef int int_fast16_t;
-typedef int int_fast32_t;
-__extension__
-typedef long long int int_fast64_t;
-#endif
-
-/* Unsigned. */
-typedef unsigned char uint_fast8_t;
-#if __WORDSIZE == 64
-typedef unsigned long int uint_fast16_t;
-typedef unsigned long int uint_fast32_t;
-typedef unsigned long int uint_fast64_t;
-#else
-typedef unsigned int uint_fast16_t;
-typedef unsigned int uint_fast32_t;
-__extension__
-typedef unsigned long long int uint_fast64_t;
-#endif
-
-
/* Types for `void *' pointers. */
#if __WORDSIZE == 64
# ifndef __intptr_t_defined
@@ -148,37 +119,7 @@ typedef __uintmax_t uintmax_t;
# define UINT_LEAST64_MAX (__UINT64_C(18446744073709551615))
-/* Minimum of fast signed integral types having a minimum size. */
-# define INT_FAST8_MIN (-128)
-# if __WORDSIZE == 64
-# define INT_FAST16_MIN (-9223372036854775807L-1)
-# define INT_FAST32_MIN (-9223372036854775807L-1)
-# else
-# define INT_FAST16_MIN (-2147483647-1)
-# define INT_FAST32_MIN (-2147483647-1)
-# endif
-# define INT_FAST64_MIN (-__INT64_C(9223372036854775807)-1)
-/* Maximum of fast signed integral types having a minimum size. */
-# define INT_FAST8_MAX (127)
-# if __WORDSIZE == 64
-# define INT_FAST16_MAX (9223372036854775807L)
-# define INT_FAST32_MAX (9223372036854775807L)
-# else
-# define INT_FAST16_MAX (2147483647)
-# define INT_FAST32_MAX (2147483647)
-# endif
-# define INT_FAST64_MAX (__INT64_C(9223372036854775807))
-
-/* Maximum of fast unsigned integral types having a minimum size. */
-# define UINT_FAST8_MAX (255)
-# if __WORDSIZE == 64
-# define UINT_FAST16_MAX (18446744073709551615UL)
-# define UINT_FAST32_MAX (18446744073709551615UL)
-# else
-# define UINT_FAST16_MAX (4294967295U)
-# define UINT_FAST32_MAX (4294967295U)
-# endif
-# define UINT_FAST64_MAX (__UINT64_C(18446744073709551615))
+#include <int-fast.h>
/* Values to test for integral types holding `void *' pointer. */
@@ -293,15 +234,6 @@ typedef __uintmax_t uintmax_t;
# define INT_LEAST64_WIDTH 64
# define UINT_LEAST64_WIDTH 64
-# define INT_FAST8_WIDTH 8
-# define UINT_FAST8_WIDTH 8
-# define INT_FAST16_WIDTH __WORDSIZE
-# define UINT_FAST16_WIDTH __WORDSIZE
-# define INT_FAST32_WIDTH __WORDSIZE
-# define UINT_FAST32_WIDTH __WORDSIZE
-# define INT_FAST64_WIDTH 64
-# define UINT_FAST64_WIDTH 64
-
# define INTPTR_WIDTH __WORDSIZE
# define UINTPTR_WIDTH __WORDSIZE
new file mode 100644
@@ -0,0 +1,107 @@
+/* Copyright (C) 2022 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <https://www.gnu.org/licenses/>. */
+
+#ifndef _INT_FAST_H
+#define _INT_FAST_H 1
+
+#define __PRIMITIVE_INT_FAST_CAT(X, Y) X##Y
+#define __INT_FAST_CAT(X, Y) __PRIMITIVE_INT_FAST_CAT (X, Y)
+
+#ifndef __HAS_INT_FAST_DEFS
+
+
+/* Fast types. */
+
+/* Signed. */
+typedef signed char int_fast8_t;
+#if __WORDSIZE == 64
+typedef long int int_fast16_t;
+typedef long int int_fast32_t;
+typedef long int int_fast64_t;
+#else
+typedef int int_fast16_t;
+typedef int int_fast32_t;
+__extension__
+typedef long long int int_fast64_t;
+#endif
+
+/* Unsigned. */
+typedef unsigned char uint_fast8_t;
+#if __WORDSIZE == 64
+typedef unsigned long int uint_fast16_t;
+typedef unsigned long int uint_fast32_t;
+typedef unsigned long int uint_fast64_t;
+#else
+typedef unsigned int uint_fast16_t;
+typedef unsigned int uint_fast32_t;
+__extension__
+typedef unsigned long long int uint_fast64_t;
+#endif
+
+/* Base types for INT_FAST{SIZE}. */
+# define __INT_FAST8_BASE INT8
+# if __WORDSIZE == 64
+# define __INT_FAST16_BASE INT64
+# define __INT_FAST32_BASE INT64
+# else
+# define __INT_FAST16_BASE INT32
+# define __INT_FAST32_BASE INT32
+# endif
+# define __INT_FAST64_BASE INT64
+
+# define __UINT_FAST8_BASE UINT8
+# if __WORDSIZE == 64
+# define __UINT_FAST16_BASE UINT64
+# define __UINT_FAST32_BASE UINT64
+# else
+# define __UINT_FAST16_BASE UINT32
+# define __UINT_FAST32_BASE UINT32
+# endif
+# define __UINT_FAST64_BASE UINT64
+
+#endif
+
+/* Minimum of fast signed integral types having a minimum size. */
+#define INT_FAST8_MIN __INT_FAST_CAT (__INT_FAST8_BASE, _MIN)
+#define INT_FAST16_MIN __INT_FAST_CAT (__INT_FAST16_BASE, _MIN)
+#define INT_FAST32_MIN __INT_FAST_CAT (__INT_FAST32_BASE, _MIN)
+#define INT_FAST64_MIN __INT_FAST_CAT (__INT_FAST64_BASE, _MIN)
+
+/* Maximum of fast signed integral types having a minimum size. */
+#define INT_FAST8_MAX __INT_FAST_CAT (__INT_FAST8_BASE, _MAX)
+#define INT_FAST16_MAX __INT_FAST_CAT (__INT_FAST16_BASE, _MAX)
+#define INT_FAST32_MAX __INT_FAST_CAT (__INT_FAST32_BASE, _MAX)
+#define INT_FAST64_MAX __INT_FAST_CAT (__INT_FAST64_BASE, _MAX)
+
+/* Maximum of fast unsigned integral types having a minimum size. */
+#define UINT_FAST8_MAX __INT_FAST_CAT (__UINT_FAST8_BASE, _MAX)
+#define UINT_FAST16_MAX __INT_FAST_CAT (__UINT_FAST16_BASE, _MAX)
+#define UINT_FAST32_MAX __INT_FAST_CAT (__UINT_FAST32_BASE, _MAX)
+#define UINT_FAST64_MAX __INT_FAST_CAT (__UINT_FAST64_BASE, _MAX)
+
+
+#define INT_FAST8_WIDTH __INT_FAST_CAT (__INT_FAST8_BASE, _WIDTH)
+#define INT_FAST16_WIDTH __INT_FAST_CAT (__INT_FAST16_BASE, _WIDTH)
+#define INT_FAST32_WIDTH __INT_FAST_CAT (__INT_FAST32_BASE, _WIDTH)
+#define INT_FAST64_WIDTH __INT_FAST_CAT (__INT_FAST64_BASE, _WIDTH)
+
+#define UINT_FAST8_WIDTH __INT_FAST_CAT (__UINT_FAST8_BASE, _WIDTH)
+#define UINT_FAST16_WIDTH __INT_FAST_CAT (__UINT_FAST16_BASE, _WIDTH)
+#define UINT_FAST32_WIDTH __INT_FAST_CAT (__UINT_FAST32_BASE, _WIDTH)
+#define UINT_FAST64_WIDTH __INT_FAST_CAT (__UINT_FAST64_BASE, _WIDTH)
+
+#endif