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 2AFE638618A3 for ; Thu, 15 Feb 2024 11:46:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2AFE638618A3 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 2AFE638618A3 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=1707997600; cv=none; b=L4sf3DGJNP/BPEKTqiVIOfl3M4vg+C5fyAZpO7+UABHM9GGnKtnNf69KCOBrqhCPfpDze4YSF+RYNWxqUbIsgkviQcm/e65nb9SdQ+awWRBNmkx9HDDe+gOyBXuEsGqvvxNk6t+4g53zdN1qP1ZM6r9Fj1mEYu/ehqVERLJIRSo= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1707997600; c=relaxed/simple; bh=zAMzguvrxSiPftop+kcqEs4liQEOQVDHjMscCZxR3Xo=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=uKHAKqwkb1cYAUOHit7GVDgGTQJ66ZzHm/5JY+IrLV7Xl8In0HMpXjU32zm1yLI2kR+j3vuLH1NafpaUruxxlnsWIphHpFz9kErcYF0WsB2ESlYq2BhUVn8hfqPgpe+jKDUk7qpa4rTB1W+SqwYvCGFuMnWKG75qOqwfKOXj5MQ= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1707997597; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=0TsdmpRSGTvGP2AEmZzOTeo8917I7gcIpT2StV+5BP4=; b=KpYcN3YsipZklNthfOfeEN1rPIjO+0LpFpyX/gkArhlP1DoYyQ+4/kUa0YwnTTLBd9JxMP OglLOaROY/GNcS4Uxs9ghqwQC1SuxUruvhD56suYM5aa+3alGZ0Iehyr4mzqpwtAtbcnWc TZJGLFPY1elIB5oz7Fxt9nGhrL02tf0= 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-189-G_uPD5C0OVakTjTvd0W28Q-1; Thu, 15 Feb 2024 06:46:34 -0500 X-MC-Unique: G_uPD5C0OVakTjTvd0W28Q-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (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 A9EAB3C0009D; Thu, 15 Feb 2024 11:46:34 +0000 (UTC) Received: from localhost (unknown [10.42.28.206]) by smtp.corp.redhat.com (Postfix) with ESMTP id 77C442166B36; Thu, 15 Feb 2024 11:46:34 +0000 (UTC) From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [committed] libstdc++: Use memset to optimize std::bitset::set() [PR113807] Date: Thu, 15 Feb 2024 11:46:29 +0000 Message-ID: <20240215114633.50124-1-jwakely@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.6 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-12.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,TXREP,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Tested aarch64-linux and x86_64-linux. Pushed to trunk. -- >8 -- As pointed out in the PR we already do this for reset(). libstdc++-v3/ChangeLog: PR libstdc++/113807 * include/std/bitset (bitset::set()): Use memset instead of a loop over the individual words. --- libstdc++-v3/include/std/bitset | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/libstdc++-v3/include/std/bitset b/libstdc++-v3/include/std/bitset index 3243c649731..16c4040f532 100644 --- a/libstdc++-v3/include/std/bitset +++ b/libstdc++-v3/include/std/bitset @@ -177,8 +177,15 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER _GLIBCXX14_CONSTEXPR void _M_do_set() _GLIBCXX_NOEXCEPT { - for (size_t __i = 0; __i < _Nw; __i++) - _M_w[__i] = ~static_cast<_WordT>(0); +#if __cplusplus >= 201402L + if (__builtin_is_constant_evaluated()) + { + for (_WordT& __w : _M_w) + __w = ~static_cast<_WordT>(0);; + return; + } +#endif + __builtin_memset(_M_w, 0xFF, _Nw * sizeof(_WordT)); } _GLIBCXX14_CONSTEXPR void -- 2.43.0