From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 2F1FC3858C53 for ; Tue, 13 Jun 2023 15:20:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2F1FC3858C53 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1686669656; h=from:from:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:in-reply-to:in-reply-to: references:references; bh=lSRd66kwzNwThVZqdKKTa6lXVZkeHIDRUK6T4GUIGV4=; b=THJbnS38X/hGAtHdnEpnUOUG43UZ5zuQgMC5APdALTg/Yup0dA7NahfMhp48KJrAwHVBC0 7rxoHMpsVvS85O8lFb8aUTTGY0WV7fG/Q6s15K0R/AAdP0jb9n/YoKxZ8HtJsWclIDB7LS UMADtZq/Ej2WeF3B5YRh4F/DxzLHH0g= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-94-HuvNG-kYOUqefPMm471ltg-1; Tue, 13 Jun 2023 11:20:54 -0400 X-MC-Unique: HuvNG-kYOUqefPMm471ltg-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 329308030D1; Tue, 13 Jun 2023 15:20:44 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.194.30]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E47241121314; Tue, 13 Jun 2023 15:20:43 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.17.1/8.17.1) with ESMTPS id 35DFKfnd1890110 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Tue, 13 Jun 2023 17:20:41 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 35DFKdtx1890107; Tue, 13 Jun 2023 17:20:39 +0200 Date: Tue, 13 Jun 2023 17:20:39 +0200 From: Jakub Jelinek To: Joseph Myers Cc: Marek Polacek , gcc-patches@gcc.gnu.org, libc-alpha@sourceware.org Subject: Re: [RFC] Add stdckdint.h header for C23 Message-ID: Reply-To: Jakub Jelinek References: <68578b43-939-1879-9676-2ea55249a2c5@codesourcery.com> MIME-Version: 1.0 In-Reply-To: X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-3.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,KAM_NUMSUBJECT,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,TXREP,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On Tue, Jun 13, 2023 at 03:10:48PM +0000, Joseph Myers wrote: > > So why does C2X say > > Recommended practice > > It is recommended to produce a diagnostic message if type2 or type3 are > > not suitable integer types, or if *result is not a modifiable lvalue of > > a suitable integer type. > > ? > > Or is it meant that a suitable integer type doesn't need to be necessarily > > one that is listed in the previous paragraph? > > Perhaps the checking could be guarded on #ifdef __STRICT_ANSI__, sure... > > Diagnostics are better than doing something completely random - but making > it conditional when there are sensible semantics also makes sense. > > It seems likely a future standard version will support these operations > for bit-precise types, at least. (Bit-precise types are generally tricky > for type-generic operations; there's no standard way to select on them > with _Generic beyond listing individual types with specific widths, and no > standard way to determine the width of the bit-precise type of an > argument. So implementing some type-generic operations for such types may > need new language extensions, prompting WG14 caution about requiring such > support - but this also makes support for such types in standard > type-generic macros in headers particularly valuable, precisely because > they can't be implemented purely in user code using standard language > features.) Yeah, having say __builtin_{clz,ctz,ffs,popcount,parity} variants which would be typegeneric and would allow say any normal integral or _BitInt type (or just unsigned versions thereof?) would be useful. Even without _BitInt we have the problem that we don't have builtins for __uint128_t. One question is if we should keep them UB on zero input or hardcode some particular behavior for clz/ctz. The backend defaults might not be appropriate, I think if we'd make it non-UB, using the precision of the type would be reasonable, whatever it is (__builtin_clzb ((unsigned _BitInt(126)) 0) might be 126 etc.). Jakub