From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-yw1-x1136.google.com (mail-yw1-x1136.google.com [IPv6:2607:f8b0:4864:20::1136]) by sourceware.org (Postfix) with ESMTPS id AD130385840A; Sat, 11 Nov 2023 01:23:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org AD130385840A Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org AD130385840A Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::1136 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699665824; cv=none; b=CfeMBf6WLxgEwR22Xecdb3GavcNFDAcSzBoFPK7IIL/2PjG7W+H93Z1HWvqwhg01JWqv6SI7e8W97y3w7ctkkqpPmQ/3GWrMFvozIrkxB9s055apdeV7aFO+5cL75pqcNKD8w+3KHhVcYf4zVTmOSOKlpR7Z6uiF0m+ndhKWQno= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699665824; c=relaxed/simple; bh=+OHxyRNE8376Ui9FHDxLcThJNh9OpFdYXSn6eVxkHIA=; h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To; b=Qh9/OokcsEiDtbuFXVaFGG6GtFVdU4vEPTHiLZ8Hz7UAAIh+Sa240GLCzzyAtwqGfGBGBnT6MANc3GZkM58tpDpr/PjKn1A6f9WAGsP6wdj3Oy/4UmaaE7NQ1BRebmLzxuvAvcPtDdYOvW/b2KHEFwL0unJ0QSfqlJESITGAZx4= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-yw1-x1136.google.com with SMTP id 00721157ae682-5bf58914bacso28141417b3.3; Fri, 10 Nov 2023 17:23:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1699665822; x=1700270622; darn=gcc.gnu.org; h=to:subject:message-id:date:from:reply-to:mime-version:from:to:cc :subject:date:message-id:reply-to; bh=Csq9c5K4WUHbBJECVBL1mF6JU/DaYa6tPCuXIgDviSw=; b=dAkh5/wbeTwO3Zgp13IhDg/u82xi75WFiMKj9VbFR7Tx4tFI1YFStgG4dRkBJ5HqRC wPG8Yj+/eNzCkaIA9pi1ZS5TLisFERAV4Btoiukd3YqmcErvfIDoHJVYL8voCvB99oS0 LPVsNmNbYCdv445UgEV6x0YwADaHpGDrMWTl8WhJ9ebNhokHwBFPGw0cbusTOSRozVCq H5gZhlpQJM+c6HjzSPJ3zv2j2FKceDniYARQ29UlsKgzAOsdaT8SpgDk64GqThHcoq3h cw/TsmLVqWOIDm29knehEXxBJu9LhOfpn8Jbiildfm316FwymvHL/RZ513uK5Zhnwlg+ XOvA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699665822; x=1700270622; h=to:subject:message-id:date:from:reply-to:mime-version :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Csq9c5K4WUHbBJECVBL1mF6JU/DaYa6tPCuXIgDviSw=; b=HYBLg+jX91eIMRVwZzl3aY6IZYX2wHowGdtZu48CsW2JFXFITiRq2nSL2r2v4Jd/TV 4gDce6Ss70drwVfRzq7mr5VfNiFCH5tR3sUAakbVv2hOcurG95ERrIEg4GzQEyblBXMw misvQW6EIKLeqkfLIQXyslW3CHW9NS5fJJiipsfrCGGIedkmyHXIhNJ53zBS1KGQLax8 ORLQvpqqfOOJOhjbmHIzpOLLsSpDEMfbzAiwop/in0xAvjMbEF1jHG2CwHpYdfVy04W1 nfChdcjYY8NK5kB995iJCUABLFK9etDGZgwDtnB3NmGdCDh58rc/ErOxmPbqnn2IRAcd zviA== X-Gm-Message-State: AOJu0YyaenNe/wGuqrCw09brHMbcMkQyrtO73HZ87tdAu3ZSFPwrKhSY X6BxNHuXPJCm1CKg1G+QcUl6lSfkx3gkypEVHhUwZRMl9VU= X-Google-Smtp-Source: AGHT+IGfJc1iETDnLl6VhORRLGh4nz8ODXbvi5pA6QkCR18XN9/x20rwL8lTPTUKR/5zS9Cvgz5Y1lmERKJW6tgTFqQ= X-Received: by 2002:a25:e010:0:b0:da3:7524:76f0 with SMTP id x16-20020a25e010000000b00da3752476f0mr891847ybg.30.1699665821695; Fri, 10 Nov 2023 17:23:41 -0800 (PST) MIME-Version: 1.0 Reply-To: cassio.neri@gmail.com From: Cassio Neri Date: Sat, 11 Nov 2023 01:23:30 +0000 Message-ID: Subject: [PATCH v2] Remove unnecessary "& 1" in year_month_day_last::day() To: "libstdc++" , Gcc-patches Content-Type: multipart/alternative; boundary="0000000000008a024f0609d649e9" X-Spam-Status: No, score=-8.0 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,GIT_PATCH_0,HTML_MESSAGE,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,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: --0000000000008a024f0609d649e9 Content-Type: text/plain; charset="UTF-8" When year_month_day_last::day() was implemented, Dr. Matthias Kretz realised that the operation "& 1" wasn't necessary but we did not patch it at that time. This patch removes the unnecessary operation. libstdc++-v3/ChangeLog: * include/std/chrono: --- libstdc++-v3/include/std/chrono | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/libstdc++-v3/include/std/chrono b/libstdc++-v3/include/std/chrono index 10e868e5a03..a826982803b 100644 --- a/libstdc++-v3/include/std/chrono +++ b/libstdc++-v3/include/std/chrono @@ -1800,22 +1800,26 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { const auto __m = static_cast(month()); - // Excluding February, the last day of month __m is either 30 or 31 or, - // in another words, it is 30 + b = 30 | b, where b is in {0, 1}. + // The result is unspecified if __m < 1 or __m > 12. Hence, assume + // 1 <= __m <= 12. For __m != 2, day() == 30 or day() == 31 or, in + // other words, day () == 30 | b, where b is in {0, 1}. - // If __m in {1, 3, 4, 5, 6, 7}, then b is 1 if, and only if __m is odd. - // Hence, b = __m & 1 = (__m ^ 0) & 1. + // If __m in {1, 3, 4, 5, 6, 7}, then b is 1 if, and only if, __m is + // odd. Hence, b = __m & 1 = (__m ^ 0) & 1. - // If __m in {8, 9, 10, 11, 12}, then b is 1 if, and only if __m is even. - // Hence, b = (__m ^ 1) & 1. + // If __m in {8, 9, 10, 11, 12}, then b is 1 if, and only if, __m is + // even. Hence, b = (__m ^ 1) & 1. // Therefore, b = (__m ^ c) & 1, where c = 0, if __m < 8, or c = 1 if // __m >= 8, that is, c = __m >> 3. - // The above mathematically justifies this implementation whose - // performance does not depend on look-up tables being on the L1 cache. - return chrono::day{__m != 2 ? ((__m ^ (__m >> 3)) & 1) | 30 - : _M_y.is_leap() ? 29 : 28}; + // Since 30 = (11110)_2 and __m <= 31 = (11111)_2, the "& 1" in b's + // calculation is unnecessary. + + // The performance of this implementation does not depend on look-up + // tables being on the L1 cache. + return chrono::day{__m != 2 ? (__m ^ (__m >> 3)) | 30 + : _M_y.is_leap() ? 29 : 28}; } constexpr --0000000000008a024f0609d649e9--