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 739033858D1E for ; Sat, 11 Nov 2023 08:18:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 739033858D1E 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 739033858D1E Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699690718; cv=none; b=WJxqQdOjfzsWSj/6aBXN0TTjCHe5w5MK331Dw/gLdQPy0117QGjPdISmMlTYK3eCu6rOqlpjhDb4J66SnXEZGB98783jmEogJ36uRNWeMST11+xy9c2UjeHdjUDDRIPU+7sdG39OvUnfW/lcja31Vu6a5h0uOVr5Cti1Ca0i3/c= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699690718; c=relaxed/simple; bh=iGiPTrbxJ80qSsH27X5X9nglzKuYAT2HDgdHpTfzO8s=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=BFMOUA+6cGcTNI+1iM4rFYSx0LAnNCU9dywV3nl2NMpBllmse6CkNF5rJdxelRdNMHqx0OayGKcqLPqNOZVitplgQvEDt8vuQKCGZqcqcI8Tr9+e/U42BzR4o4O28AOYxBHpPoqbXQ+9ZlBCcTbLfnqHolxiLHVDFthPsDv4oKg= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1699690717; h=from:from:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type:in-reply-to:in-reply-to: references:references; bh=bBJMGbIUcmM8FthlPWvNkXCeYTEhkfH+7PpESvPZDVE=; b=PUVlzaUsE1mzHbz3KLSp3ksmqRcfit/cfZfwOwPNPYzXHpTMT6Z+dTIwpBcvgFpnSoLdQU UDN5Er/dZM51rGw95XccuhMlk7i1ocz2EJ/L80jYYlrTq36j7MCj23diDKJywBTfVyfj9o zq3g1ABuplt/SmCYqDzXfNqVHoRF5RM= 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-324-78faoeamN8ys6y4t2YKb1Q-1; Sat, 11 Nov 2023 03:18:30 -0500 X-MC-Unique: 78faoeamN8ys6y4t2YKb1Q-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (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 E494F29ABA35; Sat, 11 Nov 2023 08:18:29 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.81]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 96D84502A; Sat, 11 Nov 2023 08:18:29 +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 3AB8IQ8q3773509 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Sat, 11 Nov 2023 09:18:27 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 3AB8IPa53773508; Sat, 11 Nov 2023 09:18:25 +0100 Date: Sat, 11 Nov 2023 09:18:25 +0100 From: Jakub Jelinek To: Richard Biener , "Joseph S. Myers" , Jason Merrill , gcc-patches@gcc.gnu.org Subject: Re: [PATCH] Add type-generic clz/ctz/clrsb/ffs/parity/popcount builtins [PR111309] 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.5 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_H3,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 Fri, Nov 10, 2023 at 10:44:12AM +0100, Jakub Jelinek wrote: > Because the builtins are just something matching in behavior to existing > builtins which can be used for those macros, not exact implementation of > those. BTW, the new builtins also allow implementation of generic signed_type_for and unsigned_type_for macros in C (together with __builtin_classify_type), I think _Generic over known standard and extended types plus for _BitInt (__builtin_classify_type (__typeof (x)) == 18) something like in the following source: void bar (_BitInt(193) *, unsigned _BitInt(193) *); void foo (void) { unsigned _BitInt(193) a = 0uwb; _BitInt(__builtin_popcountg ((__typeof (a)) -1)) b = 0wb; bar (&b, &a); } void baz (void) { _BitInt(193) a = 0wb; unsigned _BitInt(__builtin_clrsbg ((__typeof (a)) - 1) + 1) b = 0uwb; bar (&a, &b); } One needs to use __builtin_popcountg on all ones for unsigned types and 1 + __builtin_clrsbg on all ones for signed types, but otherwise it seems to work fine. Of course, for signed_type_for one would need to decide what to do with unsigned _BitInt(1) type which doesn't have signed counterpart, but that can be dealt in _Generic. Jakub