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.129.124]) by sourceware.org (Postfix) with ESMTPS id 14D063858422 for ; Tue, 21 Nov 2023 08:22:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 14D063858422 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 14D063858422 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700554939; cv=none; b=fCh0E1x9RRWSs+V3Guh1HIWqAOq22lZE/C+WFJ//KD2W9B2kdjkecqkvfQ3IhOx4F2zFXzhlfWLTxOe1lZ1s2BU1n2OCE1oRHYJLrfqUunl0WFHIqwlzhwqf7Gnvq1/sMTf0xIbcFgYcHluyCIyHv9W7lyEGTSgzDqJ/jqWzDTk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700554939; c=relaxed/simple; bh=0LrumPNQGXq5fixvxJ/mV8NVPTobMksQzfomyvfeFrg=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=g1NwahJ13+Ao5DgO3isAfIKHkWUIjo+/lkaOQOjaTX75+4b73KEa9pVBjBjYvWY+Lv7VGs2C+HmrzZ9duBXnmPMfWQy0YTGGeij2TauGDjLoHbMVwF4gaoGPANpN+A7pJk22s2H3gP7RAtw/ywdHAWqEWojoQQ/gPM695GGCHDg= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1700554936; 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:resent-to:resent-from:resent-message-id: in-reply-to:in-reply-to:references:references; bh=GNYzWfHPST2V+3WPS2SBQ1uzDbnODoDPbHVsheJlxwg=; b=Qey2JRxGgSX2QauylQpuVVa/qLxp2x5LEvxdomkiKQeBoekakD3RYBDog8C2csjOWoSdzP 177FELLvIccsyy6nC3pOExEDC8d8HyXHHs6tW1p+r8/B8u4IyZju8PEZqNvLvBXcpGbKhi +rWt+VdsNBP08w/3czdqf4D0YTndPXU= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-619-TyrtSRsON824d8x83IFJ_g-1; Tue, 21 Nov 2023 03:22:09 -0500 X-MC-Unique: TyrtSRsON824d8x83IFJ_g-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 321B43813BD5; Tue, 21 Nov 2023 08:22:09 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.194.53]) by smtp.corp.redhat.com (Postfix) with ESMTPS id EA22140C6EB9; Tue, 21 Nov 2023 08:22:08 +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 3AL8M6Cb4109000 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Tue, 21 Nov 2023 09:22:06 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 3AL8M5qN4108999; Tue, 21 Nov 2023 09:22:05 +0100 Resent-From: Jakub Jelinek Resent-Date: Tue, 21 Nov 2023 09:22:05 +0100 Resent-Message-ID: Resent-To: "Joseph S. Myers" , gcc-patches@gcc.gnu.org, Florian Weimer Date: Mon, 20 Nov 2023 16:12:35 +0100 From: Jakub Jelinek To: Joseph Myers Cc: gcc-patches@gcc.gnu.org, Florian Weimer Subject: Re: [PATCH] c: Add __builtin_stdc_bit_{width,floor,ceil} builtins Message-ID: Reply-To: Jakub Jelinek References: MIME-Version: 1.0 In-Reply-To: X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.2 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.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham 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 Mon, Nov 20, 2023 at 02:55:33PM +0000, Joseph Myers wrote: > On Sat, 18 Nov 2023, Jakub Jelinek wrote: > > > +@defbuiltin{@var{type} __builtin_stdc_bit_ceil (@var{type} @var{arg})} > > +The @code{__builtin_stdc_bit_ceil} function is available only > > +in C. It is type-generic, the argument can be any unsigned integer > > +(standard, extended or bit-precise). No integral argument promotions are > > +performed on the argument. It is equivalent to > > +@code{@var{arg} <= 1 ? (@var{type}) 1 > > +: (@var{type}) 1 << (@var{prec} - __builtin_clzg ((@var{type}) (@var{arg} - 1)))} > > +where @var{prec} is bit width of @var{type}, except that side-effects > > +in @var{arg} are evaluated just once. > > +@enddefbuiltin > > Note that stdc_bit_ceil now has defined behavior (return 0) on overflow: > CD2 comment FR-135 was accepted for the DIS at the June WG14 meeting. > This affects both the documentation and the implementation, as they need > to avoid an undefined shift by the width of the type. That's why my > stdbit.h implementations have two shifts (not claiming that's necessarily > the optimal way of ensuring the correct result in the overflow case). > > return __x <= 1 ? 1 : ((uint64_t) 1) << (__bw64_inline (__x - 1) - 1) << 1; So return __x <= 1 ? 1 : ((uint64_t) 2) << (__bw64_inline (__x - 1) - 1); then? Jakub