From patchwork Sun Sep 18 17:39:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Georg-Johann Lay X-Patchwork-Id: 1281 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2302:b0:79:6ae5:3758 with SMTP id gv2csp964440dyb; Sun, 18 Sep 2022 10:40:45 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6aCVl+bRMkbKyJtg1yoBbswBLj/SWAkGmfnNbbDuCnBWxombtmGDAiuhPPeA6jswaDILgO X-Received: by 2002:a17:907:1b03:b0:6ff:78d4:c140 with SMTP id mp3-20020a1709071b0300b006ff78d4c140mr10247351ejc.554.1663522845178; Sun, 18 Sep 2022 10:40:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663522845; cv=none; d=google.com; s=arc-20160816; b=K6yBWuvj92hy0Vd0JlvreI+9G8LTTcL5cB+QSbXmRlMCtWvzXWRRpNfBsuEDCIZ/wu CP+a968HTsX+nxamPx60HTylcPYXIGYZmnZCMWmrruU/iMweFy4tp/KfTMicXRMTh/nV FeiTcAyBy7FMGVcUy+EZsHPp1LSeDcsH1bHr4Tr45uzkM+8V/Ldd9OrplHK7SkancDrn emCIk1sAar5/EzPlUpdsN34En4Bhmm6HN4NZflJxmWwANcsX+n+ZOYkEEHOQS4dRnfps nKi1CzsNmBiEmIZl5QgKSOSPm7zDvkJFi0+R+HxCfSykCSb/zb47h33oAFaPkTxYRK9m Ibhw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:from:content-language :to:user-agent:mime-version:date:message-id:dkim-signature :dmarc-filter:delivered-to; bh=EUiNHyBnTqq6mSdtRosHl7TDihYd3ftdFnqynOZEsIA=; b=KSC6Jjy5kTq7Pz/8M30jd6wB0CuB7ICiNAh7LoMkp96bfFJwNtTA078NsgWxS/MlfG NqkDbiV5gZcNjEGzhJeVd/mQFb6WeqQGlrMPYKKyiXTGm1l5TBhxhNxVCUI/IrjNS2/q vMqNIIKtov7edHHS1baum8WZUPuwm7A1c9hF1r8BJUb5+1nNgTbck8vDIEjWfjrzNVVB a9cy/AanmSDsN4TVP9ZzflyYh0VW9E0jk4XRNU9E/WCyRJ5rBYkiGt/V+1ji+1FEKOty k0JGSPzI3wTPSr3b5vwx8E5JpL0ZzJZkS6MpH1e9erKBa1UcZj11FJxrt+Y30ovp5+V+ Im8g== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gjlay.de header.s=strato-dkim-0002 header.b=rAW8yBu7; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id dt9-20020a170907728900b00773fb36fcb1si2798733ejc.213.2022.09.18.10.40.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 18 Sep 2022 10:40:45 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=fail header.i=@gjlay.de header.s=strato-dkim-0002 header.b=rAW8yBu7; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 10F6B383CCAD for ; Sun, 18 Sep 2022 17:40:30 +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 [81.169.146.216]) by sourceware.org (Postfix) with ESMTPS id 499AB3858C54; Sun, 18 Sep 2022 17:40:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 499AB3858C54 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gjlay.de Authentication-Results: sourceware.org; spf=none smtp.mailfrom=gjlay.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1663522801; s=strato-dkim-0002; d=gjlay.de; h=Subject:From:Cc:To:Date:Message-ID:Cc:Date:From:Subject:Sender; bh=EUiNHyBnTqq6mSdtRosHl7TDihYd3ftdFnqynOZEsIA=; b=rAW8yBu7OEGKFjISmKKXrget+ZLApazwg2lgT11tSHl6lvXYtB1nVCkPFMuNECF1S8 8HARWWQ6gJEV/tJ6gHUJgDzbXvkO4guiuSlyt/djDaN1cSP0XMBFz4uJxzPNlHBChNID Hp4FYjJUVof+zKtz2cdCmzTECZFPZOxwopUVIjj+OrIoqmcy/zf0bBuCMkhaoz6FTseJ 6iQBPvJWjmrK/axskoZXKf7ftaefhL6sopfpcZO6NqEclsNLh7Z1EFP1YJ9XYb8xwurr MPJHP7g2p1YZBCwp9LgPVrIjVNcqrEwuT43kOmEquaS6fnvWMkvbTyuIST1ziz3RCRnB EJTQ== Authentication-Results: strato.com; dkim=none X-RZG-AUTH: ":LXoWVUeid/7A29J/hMvvT3koxZnKT7Qq0xotTetVnKkbjtK7qmy9Jvpc5Ezo" X-RZG-CLASS-ID: mo00 Received: from [192.168.2.102] by smtp.strato.de (RZmta 48.1.0 DYNA|AUTH) with ESMTPSA id 6f8f00y8IHe1WH7 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate); Sun, 18 Sep 2022 19:40:01 +0200 (CEST) Message-ID: Date: Sun, 18 Sep 2022 19:39:50 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 To: gcc-patches@gcc.gnu.org Content-Language: en-US From: Georg Johann Lay Subject: [patch, avr] Fix PR target/99184: Wrong cast from double to 16-bit and 32-bit ints. X-Spam-Status: No, score=-8.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, SPF_HELO_PASS, SPF_NONE, TXREP 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.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1744330130442895166?= X-GMAIL-MSGID: =?utf-8?q?1744330130442895166?= Hello, this patch fixed PR target/99184 which incorrectly rounded during 64-bit (long) double to 16-bit and 32-bit integers. The patch just removes the respective roundings from libf7-asm.sx::to_integer and ::to_unsigned. Luckily, LibF7 does nowhere use respective functions internally, the only user is in libf7.c::f7_exp which reads f7_round (qq, qq); int16_t q = f7_get_s16 (qq); so that f7_get_s16() operates on an already rounded value, and therefore this code works unaltered with or without rounding in to_integer. The patch applies to directory ./libgcc/config/avr/libf7/ and is the same for all GCC versions v10+. Please someone with write permissions commit it to trunk and backport to v12, v11, and v10 as it is a wrong-code issue. The patch will fit without problems (except for ChangeLog) because there is no traffic on that folder. Thanks, Johann libgcc/config/avr/libf7/ PR target/99184 Remove rounding from double to [u]int16 and [u]int32 casts. * libf7-asm.sx (to_integer, to_unsigned): Don't round 16-bit and 32-bit integers. diff --git a/ChangeLog b/ChangeLog index 7e06f52..3ec0082 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ + + PR target/99184 + Remove rounding from double to [u]int16 and [u]int32 casts. + + * libf7-asm.sx (to_integer, to_unsigned): Don't round 16-bit + and 32-bit integers. + 2022-04-21 Release Manager * GCC 11.3.0 released. diff --git a/libf7-asm.sx b/libf7-asm.sx index 7629e23..9d701f2 100644 --- a/libf7-asm.sx +++ b/libf7-asm.sx @@ -601,9 +601,6 @@ DEFUN to_integer tst C6 brmi .Lsaturate.T ; > INTxx_MAX => saturate - rcall .Lround - brmi .Lsaturate.T ; > INTxx_MAX => saturate - brtc 9f ; >= 0 => return sbrc Mask, 5 .global __negdi2 @@ -658,30 +655,6 @@ DEFUN to_integer .global __clr_8 XJMP __clr_8 -.Lround: - ;; C6.7 is known to be 0 here. - ;; Return N = 1 iff we have to saturate. - cpi Mask, 0xf - breq .Lround16 - cpi Mask, 0x1f - breq .Lround32 - - ;; For now, no rounding in the 64-bit case. This rounding - ;; would have to be integrated into the right-shift. - cln - ret - -.Lround32: - rol C2 - adc C3, ZERO - adc C4, ZERO - rjmp 2f - -.Lround16: - rol C4 -2: adc C5, ZERO - adc C6, ZERO - ret ENDF to_integer #endif /* F7MOD_to_integer_ */ @@ -725,29 +698,6 @@ DEFUN to_unsigned clr CA F7call lshrdi3 POP r16 - - ;; Rounding - ;; ??? C6.7 is known to be 0 here. - cpi Mask, 0xf - breq .Lround16 - cpi Mask, 0x1f - breq .Lround32 - - ;; For now, no rounding in the 64-bit case. This rounding - ;; would have to be integrated into the right-shift. - ret - -.Lround32: - rol C2 - adc C3, ZERO - adc C4, ZERO - rjmp 2f - -.Lround16: - rol C4 -2: adc C5, ZERO - adc C6, ZERO - brcs .Lset_0xffff ; Rounding overflow => saturate ret .Lset_0xffff: