From patchwork Fri Jun 14 16:36:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Georg-Johann Lay X-Patchwork-Id: 1948004 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gjlay.de header.i=@gjlay.de header.a=rsa-sha256 header.s=strato-dkim-0002 header.b=VCWH79oF; dkim=pass header.d=gjlay.de header.i=@gjlay.de header.a=ed25519-sha256 header.s=strato-dkim-0003 header.b=TaA5VYs9; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4W14g24MZ5z20X9 for ; Sat, 15 Jun 2024 02:36:45 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7C5033882168 for ; Fri, 14 Jun 2024 16:36:35 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mo4-p00-ob.smtp.rzone.de (mo4-p00-ob.smtp.rzone.de [85.215.255.25]) by sourceware.org (Postfix) with ESMTPS id 126FE3882100 for ; Fri, 14 Jun 2024 16:36:14 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 126FE3882100 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gjlay.de Authentication-Results: sourceware.org; spf=none smtp.mailfrom=gjlay.de ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 126FE3882100 Authentication-Results: server2.sourceware.org; arc=pass smtp.remote-ip=85.215.255.25 ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1718382977; cv=pass; b=omwBysnW9M/NoPM3cgRxlWaQbeB9s+y/PHL6GBVgpvTTGM9yFYAltCTi9TwBIftvCU3wcrLM0bscvtUbG+5QYOJIofRbYwkmYgiiWP/5Ww96PUkFKxPt5MOB2jqyQkmgfxSkntClpUzdOABUEs+UR/HBHxcpMkZqFl6ofw/gxWE= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1718382977; c=relaxed/simple; bh=bgQZ1VsDyPDC2N1eAww87GPJYIFchFSs6ocHEFwHV7U=; h=DKIM-Signature:DKIM-Signature:Message-ID:Date:MIME-Version:From: To:Subject; b=So8PKud4H+8QmlwtubEy/W1bimye6xao7pPUIU+tegiipT9xowjQ4QoqV6jWeDdGJcIQ0CL/AFDOCpkavahB6qoVKl8obF2Bj2sLlHz2SU4JLSwck3bIWvVGdrD9c58h2p4UCkJe109Gc2boHLH77/jZp51hHb+Yzjom2JjgLgM= ARC-Authentication-Results: i=2; server2.sourceware.org ARC-Seal: i=1; a=rsa-sha256; t=1718382973; cv=none; d=strato.com; s=strato-dkim-0002; b=PYm1R5SShWpIe04EFPsh0NYr4mbre0XB20+AJSaw8JpucFr4V+PPGe26Pl9HMfivgz XQbJVnlG5ceQXpKurils+NXy7VhdsXjwBxHOykvR097h0fNjDhp9Lx09gY5b6DY6ivWt PrpNMtuTsd49UHH/7taCPE0rvcSC6pI60FTLZO/Pvumiue5/9K4izOhTVWOdL56smbWX eOcVA95M3KYQrYcJAgu89DJTjPXluSy2HsIVTmFa0D0i8CUzeBdpPyu81u93MQEoLHjd DLwE8C4T9m/a9UujJeN6IOpFVpA4lilnxGNbipkZF/U9wdGmAHoObEvhpi1+m8Zf8ajn kMaw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; t=1718382973; s=strato-dkim-0002; d=strato.com; h=Subject:To:From:Date:Message-ID:Cc:Date:From:Subject:Sender; bh=gjU40137tV1IbYbYuiWBsbdr4hFyCDXLswWNt2lGTVo=; b=TP/fnnuSBWvFXHKV6kC/x6LCSj8fWb2Kd7igXprPkzMDPEyCngOlFg4e5Fd5YWaOQe 371Lgadwdll3zl+mO2+3NdIfkCX346BoeqGjjwjQFKi4PIKGBV44/TzxiGq/430X0VoE nvueUC0KM+QTXZuocGO0BWrb776l5LPS57pI5AHiX1lOWzFXIZfqvcrTe8tXSIprtxWv KKN5etPFIc2ylV3mITthnf6f2lIh+g0RDg0tvxkHE2+W9wpdCpdisKmZbT2WxssGpZXh npkXZq1lv13h+NGh0i9CCsFVqepJG1NOlffsPN899ZauKOVGfJt1T3OTQEuthB/rOxxr xHuQ== ARC-Authentication-Results: i=1; strato.com; arc=none; dkim=none X-RZG-CLASS-ID: mo00 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1718382973; s=strato-dkim-0002; d=gjlay.de; h=Subject:To:From:Date:Message-ID:Cc:Date:From:Subject:Sender; bh=gjU40137tV1IbYbYuiWBsbdr4hFyCDXLswWNt2lGTVo=; b=VCWH79oFikJVrDR68fnUnO/DcHmPtjpW6oFcIvPwnXlftZab+AReMQ3yy1jMw9p2O3 LsmBzPgtb1CqWb7FCiv/40zLFMYxJoYkPC0Tgap8IdpDOpTvOz66xIxmGr67bJIvvqS4 7VgeFNLD16SPJ1Bp2h+42SX/vfptw4KuQ9a5rZ/rz2fsfRMtVJ3G9TtXGDUWBtopIEFE xY/ke3NjnN/t7w/MeVvcpJ/abvmQLbAUNOiVzsyFyVVhO+9Y9DGXCNzrBk9Ixic5HJK6 R3MS9VR4J5ptm8MvUH2/K8gYibyEfpWqRz2q8m4+guQFiYADNIynjYJmqHUr/z69GjLc Fexw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; t=1718382973; s=strato-dkim-0003; d=gjlay.de; h=Subject:To:From:Date:Message-ID:Cc:Date:From:Subject:Sender; bh=gjU40137tV1IbYbYuiWBsbdr4hFyCDXLswWNt2lGTVo=; b=TaA5VYs9zjLMUKozVN7tjONCcATAv+/1q5bgULN7LxcGqtJdOtcaayfDaT5/LkXJAq agvm21pgpoKcOiTkejDg== X-RZG-AUTH: ":LXoWVUeid/7A29J/hMvvT3koxZnKT7Qq0xotTetVnKkbjtK7q2y9L+qNvyhO" Received: from [192.168.2.102] by smtp.strato.de (RZmta 50.5.0 DYNA|AUTH) with ESMTPSA id x0577805EGaDFIv (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate) for ; Fri, 14 Jun 2024 18:36:13 +0200 (CEST) Message-ID: Date: Fri, 14 Jun 2024 18:36:13 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird From: Georg-Johann Lay Content-Language: en-US To: "gcc-patches@gcc.gnu.org" Subject: [patch,avr,applied] PR115419: round double to even LSB on tie breaks X-Spam-Status: No, score=-11.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_PASS, 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 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org The convention in round-to-nearest floating-point rounding is to round to even ("Banker's rounding"). Johann AVR: target/115419 - Tie breaks are rounded-to-even. libgcc/config/avr/libf7/ PR target/115419 * libf7.c (f7_get_double): Round tie breaks to even LSB. diff --git a/libgcc/config/avr/libf7/libf7.c b/libgcc/config/avr/libf7/libf7.c index 375becb854c..6fae4fc1a2d 100644 --- a/libgcc/config/avr/libf7/libf7.c +++ b/libgcc/config/avr/libf7/libf7.c @@ -440,11 +440,21 @@ f7_double_t f7_get_double (const f7_t *aa) mant &= 0x00ffffffffffffff; - // FIXME: For subnormals, rounding is premature and should be - // done *after* the mantissa has been shifted into place - // (or the round value be shifted left accordingly). - // Round. - mant += 1u << (F7_MANT_BITS - (1 + DBL_DIG_MANT) - 1); + // PR115419: The least significant nibble tells how to round: + // Tie breaks are rounded to even (Banker's rounding). + uint8_t lsn = mant & 0xff; + lsn &= 0xf; + // The LSB of the outgoing double is at bit 3. + if (lsn & (1 << 3)) + ++lsn; + if (lsn > (1 << 2)) + { + // FIXME: For subnormals, rounding is premature and should be + // done *after* the mantissa has been shifted into place + // (or the round value be shifted left accordingly). + // Round. + mant += 1u << (F7_MANT_BITS - (1 + DBL_DIG_MANT) - 1); + } uint8_t dex; register uint64_t r18 __asm ("r18") = mant;