From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-1.5 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_LOW,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 8306 invoked from network); 31 May 2023 14:16:55 -0000 Received: from second.openwall.net (193.110.157.125) by inbox.vuxu.org with ESMTPUTF8; 31 May 2023 14:16:55 -0000 Received: (qmail 13961 invoked by uid 550); 31 May 2023 14:16:11 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Reply-To: musl@lists.openwall.com Received: (qmail 13774 invoked from network); 31 May 2023 14:16:07 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=inria.fr; s=dc; h=from:to:subject:date:message-id:in-reply-to:references: mime-version:content-transfer-encoding; bh=OXJTub9Q4EmCxJ4dCqIgkZBxm+OB+tf7GLbA1T/F82c=; b=M+Hw47gtz+tSu+L3upj3i4a8pmshxAIPGjDVlQExsgaQWSLvwc0Cj/U3 +vcrXw0vFCbogVIH1bS+Prnk1AUob/6ZyUxu9VeVjuGZFRbOEcISKqC5q CM69CGbz5Y7UOI8ltd3bkclr8HMfCG4UKEUsXQ39m+tInw02RszcmW05A 8=; Authentication-Results: mail3-relais-sop.national.inria.fr; dkim=none (message not signed) header.i=none; spf=SoftFail smtp.mailfrom=Jens.Gustedt@inria.fr; dmarc=fail (p=none dis=none) d=inria.fr X-IronPort-AV: E=Sophos;i="6.00,207,1681164000"; d="scan'208";a="57463845" From: Jens Gustedt To: musl@lists.openwall.com Date: Wed, 31 May 2023 16:15:50 +0200 Message-Id: <1c8e850ed3190af39b9e3f501d79899d438e7292.1685536608.git.Jens.Gustedt@inria.fr> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [musl] [C23 128 bit 4/4] C23: implement proper support for int128_t and uint128_t By implementing support for w128 length specifiers for printf and scanf, the only final bit that we need to be able to support these types officially as extended integer type and map them to the fixed-width types are the integer literals. In C23, the new types `_IntBit(N)` and their literals are mandatory. Most commonly they will support N >= 128. The maximum value for N can be queried with `BITINT_MAXWIDTH`. If we have such literals, use them to construct the constants for `[U]INT128_C` and provide the rest of the macros for these types. --- include/inttypes.h | 55 ++++++++++++++++++++++++++++++++++++++++++++++ include/stdint.h | 37 +++++++++++++++++++++++++++++++ 2 files changed, 92 insertions(+) diff --git a/include/inttypes.h b/include/inttypes.h index 780c2bb0..0d81029b 100644 --- a/include/inttypes.h +++ b/include/inttypes.h @@ -272,6 +272,61 @@ uintmax_t wcstoumax(const wchar_t *__restrict, wchar_t **__restrict, int); #define SCNuPTR __PRIPTR "u" #define SCNxPTR __PRIPTR "x" +#if __has_int128_t +#define __PRILEAST128 "w128" + +#define PRIdLEAST128 __PRILEAST128 "d" +#define PRIiLEAST128 __PRILEAST128 "i" +#define PRIoLEAST128 __PRILEAST128 "o" +#define PRIuLEAST128 __PRILEAST128 "u" +#define PRIxLEAST128 __PRILEAST128 "x" +#define PRIXLEAST128 __PRILEAST128 "X" +#define PRIbLEAST128 __PRILEAST128 "b" +#define PRIBLEAST128 __PRILEAST128 "B" + +#define SCNbLEAST128 __PRILEAST128 "b" +#define SCNdLEAST128 __PRILEAST128 "d" +#define SCNiLEAST128 __PRILEAST128 "i" +#define SCNoLEAST128 __PRILEAST128 "o" +#define SCNuLEAST128 __PRILEAST128 "u" +#define SCNxLEAST128 __PRILEAST128 "x" + +#define PRId128 PRIdLEAST128 +#define PRIi128 PRIiLEAST128 +#define PRIo128 PRIoLEAST128 +#define PRIu128 PRIuLEAST128 +#define PRIx128 PRIxLEAST128 +#define PRIX128 PRIXLEAST128 +#define PRIb128 PRIbLEAST128 +#define PRIB128 PRIBLEAST128 + +#define SCNb128 SCNbLEAST128 +#define SCNd128 SCNdLEAST128 +#define SCNi128 SCNiLEAST128 +#define SCNo128 SCNoLEAST128 +#define SCNu128 SCNuLEAST128 +#define SCNx128 SCNxLEAST128 + +#define __PRIFAST128 "wf128" + +#define PRIdFAST128 __PRIFAST128 "d" +#define PRIiFAST128 __PRIFAST128 "i" +#define PRIoFAST128 __PRIFAST128 "o" +#define PRIuFAST128 __PRIFAST128 "u" +#define PRIxFAST128 __PRIFAST128 "x" +#define PRIXFAST128 __PRIFAST128 "X" +#define PRIbFAST128 __PRIFAST128 "b" +#define PRIBFAST128 __PRIFAST128 "B" + +#define SCNbFAST128 __PRIFAST128 "b" +#define SCNdFAST128 __PRIFAST128 "d" +#define SCNiFAST128 __PRIFAST128 "i" +#define SCNoFAST128 __PRIFAST128 "o" +#define SCNuFAST128 __PRIFAST128 "u" +#define SCNxFAST128 __PRIFAST128 "x" + +#endif + #ifdef __cplusplus } #endif diff --git a/include/stdint.h b/include/stdint.h index 1f68b3bb..8dda9991 100644 --- a/include/stdint.h +++ b/include/stdint.h @@ -187,4 +187,41 @@ typedef uint64_t uint_least64_t; #define BITINT_MAXWIDTH __BITINT_MAXWIDTH__ #endif +#if __has_int128_t +typedef __int128 int128_t; +typedef int128_t int_fast128_t; +typedef int128_t int_least128_t; + +typedef unsigned __int128 uint128_t; +typedef uint128_t uint_fast128_t; +typedef uint128_t uint_least128_t; + +#define INT128_WIDTH 128 +#define INT_LEAST128_WIDTH 128 +#define INT_FAST128_WIDTH 128 +#define UINT128_WIDTH 128 +#define UINT_LEAST128_WIDTH 128 +#define UINT_FAST128_WIDTH 128 + +// This uses the new integer constants for _BitInt(N) types for the +// 128 bit type and is the only thing that we need in addition to the +// types themselves to enable 128 bit support officially. Usually this +// will not be fit for preprocessor arithmetic, but we should do an +// effort to make this possible. +#define INT128_C(X) ((int128_t)+(X ## wb)) +#define UINT128_C(X) ((uint128_t)+(X ## wbu)) + +#define INT128_MAX INT128_C(0x7fffffffffffffffffffffffffffffff) +#define INT128_MIN (-1-INT128_MAX) +#define UINT128_MAX UINT128_C(0xffffffffffffffffffffffffffffffff) + +#define INT_LEAST128_MAX INT128_MAX +#define INT_LEAST128_MIN INT128_MIN +#define INT_FAST128_MAX INT128_MAX +#define INT_FAST128_MIN INT128_MIN +#define UINT_LEAST128_MAX UINT128_MAX +#define UINT_FAST128_MAX UINT128_MAX + +#endif + #endif -- 2.34.1