public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [PATCH v1 1/2] stdlib: Refactor {u}int_fast defs in stdint
@ 2022-04-11  1:09 Noah Goldstein
  2022-04-11  1:09 ` [PATCH v1 2/2] x86_64: Add {u}int_fast defs ideal for x86_64 Noah Goldstein
  2022-04-14 22:21 ` [PATCH v1 1/2] stdlib: Refactor {u}int_fast defs in stdint Joseph Myers
  0 siblings, 2 replies; 7+ messages in thread
From: Noah Goldstein @ 2022-04-11  1:09 UTC (permalink / raw)
  To: libc-alpha

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


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH v1 2/2] x86_64: Add {u}int_fast defs ideal for x86_64
  2022-04-11  1:09 [PATCH v1 1/2] stdlib: Refactor {u}int_fast defs in stdint Noah Goldstein
@ 2022-04-11  1:09 ` Noah Goldstein
  2022-04-11  2:15   ` Adam Sampson
  2022-04-14 22:24   ` Joseph Myers
  2022-04-14 22:21 ` [PATCH v1 1/2] stdlib: Refactor {u}int_fast defs in stdint Joseph Myers
  1 sibling, 2 replies; 7+ messages in thread
From: Noah Goldstein @ 2022-04-11  1:09 UTC (permalink / raw)
  To: libc-alpha

{u}int_fast{16|32} should never use 64-bit types. 64-bit instructions
often use more code size (REX prefix) and a variety of instructions are
slower on many implementations (div, bswap, etc...).

Full xcheck passes on x86_64.
---
 sysdeps/x86_64/int-fast.h | 50 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 50 insertions(+)
 create mode 100644 sysdeps/x86_64/int-fast.h

diff --git a/sysdeps/x86_64/int-fast.h b/sysdeps/x86_64/int-fast.h
new file mode 100644
index 0000000000..8f341de646
--- /dev/null
+++ b/sysdeps/x86_64/int-fast.h
@@ -0,0 +1,50 @@
+/* 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_X86_64_H
+#define _INT_FAST_X86_64_H	1
+
+#define __HAS_INT_FAST_DEFS	1
+
+/* Signed.  */
+typedef signed char		int_fast8_t;
+/* On x86_64 32-bit instructions are almost always fastest.  */
+typedef int			int_fast16_t;
+typedef int			int_fast32_t;
+typedef long int		int_fast64_t;
+
+/* Unsigned.  */
+typedef unsigned char		uint_fast8_t;
+/* On x86_64 32-bit instructions are almost always fastest.  */
+typedef unsigned int		uint_fast16_t;
+typedef unsigned int		uint_fast32_t;
+typedef unsigned long int	uint_fast64_t;
+
+
+# define __INT_FAST8_BASE		INT8
+# define __INT_FAST16_BASE		INT32
+# define __INT_FAST32_BASE		INT32
+# define __INT_FAST64_BASE		INT64
+
+# define __UINT_FAST8_BASE		UINT8
+# define __UINT_FAST16_BASE		UINT32
+# define __UINT_FAST32_BASE		UINT32
+# define __UINT_FAST64_BASE		UINT64
+
+# include <sysdeps/generic/int-fast.h>
+
+#endif
-- 
2.25.1


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v1 2/2] x86_64: Add {u}int_fast defs ideal for x86_64
  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
  1 sibling, 1 reply; 7+ messages in thread
From: Adam Sampson @ 2022-04-11  2:15 UTC (permalink / raw)
  To: Noah Goldstein via Libc-alpha

Noah Goldstein via Libc-alpha <libc-alpha@sourceware.org> writes:

> {u}int_fast{16|32} should never use 64-bit types. 64-bit instructions
> often use more code size (REX prefix) and a variety of instructions
> are slower on many implementations (div, bswap, etc...).

Isn't that going to cause ABI breakage in other libraries, though?
For example, the jasper JPEG2000 decoder library uses stdint.h's
uint_fast32_t in its public API, and the HDF5 scientific data library
includes constants for the sizes of various types including *int*fast*.

Thanks,

-- 
Adam Sampson <ats@offog.org>                         <http://offog.org/>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v1 2/2] x86_64: Add {u}int_fast defs ideal for x86_64
  2022-04-11  2:15   ` Adam Sampson
@ 2022-04-11  6:34     ` Florian Weimer
  0 siblings, 0 replies; 7+ messages in thread
From: Florian Weimer @ 2022-04-11  6:34 UTC (permalink / raw)
  To: Adam Sampson via Libc-alpha

* Adam Sampson via Libc-alpha:

> Noah Goldstein via Libc-alpha <libc-alpha@sourceware.org> writes:
>
>> {u}int_fast{16|32} should never use 64-bit types. 64-bit instructions
>> often use more code size (REX prefix) and a variety of instructions
>> are slower on many implementations (div, bswap, etc...).
>
> Isn't that going to cause ABI breakage in other libraries, though?
> For example, the jasper JPEG2000 decoder library uses stdint.h's
> uint_fast32_t in its public API, and the HDF5 scientific data library
> includes constants for the sizes of various types including *int*fast*.

Agreed, it's too late for such changes.

Thanks,
Florian


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v1 1/2] stdlib: Refactor {u}int_fast defs in stdint
  2022-04-11  1:09 [PATCH v1 1/2] stdlib: Refactor {u}int_fast defs in stdint Noah Goldstein
  2022-04-11  1:09 ` [PATCH v1 2/2] x86_64: Add {u}int_fast defs ideal for x86_64 Noah Goldstein
@ 2022-04-14 22:21 ` Joseph Myers
  1 sibling, 0 replies; 7+ messages in thread
From: Joseph Myers @ 2022-04-14 22:21 UTC (permalink / raw)
  To: Noah Goldstein; +Cc: libc-alpha

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.

-- 
Joseph S. Myers
joseph@codesourcery.com

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v1 2/2] x86_64: Add {u}int_fast defs ideal for x86_64
  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-14 22:24   ` Joseph Myers
  2022-04-14 22:44     ` Noah Goldstein
  1 sibling, 1 reply; 7+ messages in thread
From: Joseph Myers @ 2022-04-14 22:24 UTC (permalink / raw)
  To: Noah Goldstein; +Cc: libc-alpha

On Sun, 10 Apr 2022, Noah Goldstein via Libc-alpha wrote:

> {u}int_fast{16|32} should never use 64-bit types. 64-bit instructions
> often use more code size (REX prefix) and a variety of instructions are
> slower on many implementations (div, bswap, etc...).

Apart from the other issues discussed with this patch, installed headers 
should not be specific to either x86_64 or 32-bit x86; such headers, where 
architecture-specific, should go in an x86/ sysdeps directory and contain 
appropriate conditionals within the header, so a single set of installed 
headers works with a multilibbed compiler.

> +# include <sysdeps/generic/int-fast.h>

And an installed header can't do that sort of thing, because only a single 
version of any such header gets installed.  If you want to include a 
generic file it has to have a different name, with both being installed 
(cf. bits/mman-*.h, for example).

-- 
Joseph S. Myers
joseph@codesourcery.com

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v1 2/2] x86_64: Add {u}int_fast defs ideal for x86_64
  2022-04-14 22:24   ` Joseph Myers
@ 2022-04-14 22:44     ` Noah Goldstein
  0 siblings, 0 replies; 7+ messages in thread
From: Noah Goldstein @ 2022-04-14 22:44 UTC (permalink / raw)
  To: Joseph Myers; +Cc: GNU C Library

On Thu, Apr 14, 2022 at 5:24 PM Joseph Myers <joseph@codesourcery.com> wrote:
>
> On Sun, 10 Apr 2022, Noah Goldstein via Libc-alpha wrote:
>
> > {u}int_fast{16|32} should never use 64-bit types. 64-bit instructions
> > often use more code size (REX prefix) and a variety of instructions are
> > slower on many implementations (div, bswap, etc...).
>
> Apart from the other issues discussed with this patch, installed headers
> should not be specific to either x86_64 or 32-bit x86; such headers, where
> architecture-specific, should go in an x86/ sysdeps directory and contain
> appropriate conditionals within the header, so a single set of installed
> headers works with a multilibbed compiler.
>
> > +# include <sysdeps/generic/int-fast.h>
>
> And an installed header can't do that sort of thing, because only a single
> version of any such header gets installed.  If you want to include a
> generic file it has to have a different name, with both being installed
> (cf. bits/mman-*.h, for example).

Good info to have but the patches have been drop for the ABI concerns.
>
> --
> Joseph S. Myers
> joseph@codesourcery.com

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2022-04-14 22:44 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-11  1:09 [PATCH v1 1/2] stdlib: Refactor {u}int_fast defs in stdint Noah Goldstein
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

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).