From: Noah Goldstein <goldstein.w.n@gmail.com>
To: libc-alpha@sourceware.org
Subject: [PATCH v1 1/2] stdlib: Refactor {u}int_fast defs in stdint
Date: Sun, 10 Apr 2022 20:09:12 -0500 [thread overview]
Message-ID: <20220411010913.1061799-1-goldstein.w.n@gmail.com> (raw)
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
diff --git a/stdlib/stdint.h b/stdlib/stdint.h
index 2d666f79fd..00f41e9ffb 100644
--- a/stdlib/stdint.h
+++ b/stdlib/stdint.h
@@ -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
diff --git a/sysdeps/generic/int-fast.h b/sysdeps/generic/int-fast.h
new file mode 100644
index 0000000000..554593d393
--- /dev/null
+++ b/sysdeps/generic/int-fast.h
@@ -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
--
2.25.1
next reply other threads:[~2022-04-11 1:09 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-04-11 1:09 Noah Goldstein [this message]
2022-04-11 1:09 ` [PATCH v1 2/2] x86_64: Add {u}int_fast defs ideal for x86_64 Noah Goldstein
2022-04-11 2:15 ` Adam Sampson
2022-04-11 6:34 ` Florian Weimer
2022-04-14 22:24 ` Joseph Myers
2022-04-14 22:44 ` Noah Goldstein
2022-04-14 22:21 ` [PATCH v1 1/2] stdlib: Refactor {u}int_fast defs in stdint Joseph Myers
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220411010913.1061799-1-goldstein.w.n@gmail.com \
--to=goldstein.w.n@gmail.com \
--cc=libc-alpha@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).