From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 79347 invoked by alias); 6 Jan 2020 11:42:34 -0000 Mailing-List: contact binutils-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: binutils-owner@sourceware.org Received: (qmail 79338 invoked by uid 89); 6 Jan 2020 11:42:34 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-23.3 required=5.0 tests=AWL,BAYES_00,FREEMAIL_FROM,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=ham version=3.3.1 spammy=shifting X-HELO: mail-pl1-f169.google.com Received: from mail-pl1-f169.google.com (HELO mail-pl1-f169.google.com) (209.85.214.169) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 06 Jan 2020 11:42:32 +0000 Received: by mail-pl1-f169.google.com with SMTP id b22so21772075pls.12 for ; Mon, 06 Jan 2020 03:42:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:subject:message-id:mime-version:content-disposition :user-agent; bh=dO4xn4YZYSNHBnfxKkc2jwf6LZxq3wd9U5MWxCt0m9Y=; b=OsMXAn0YXHO/n6g8u0s5rNsS1At7dbSFPZ3qxk8STLL1ceKlC5sdtr/AcgiNwM9BLC F1+CrnyWG/HyvsX5k+VK1SY8U09UkVx6F3nPvG4ru+WZVTqb5PeaL2UVDhlMb83PVmB2 l5gfo/BiTgQeWv4wAdf313Rn2tG+3MX2vlDpMcenkEHhpWy+KLH/TjaeHxkTKS9Ca59t EyYZ0oPdI6EDfLDXWobpblFzHruSrQyyLPzGIoPWH8EzOuQz96Kds3/AyHNBH28VF8xm 7oC5dmloCAwTxJPA8fnczvylU0zUooRSzlrKED/59LTQxkCIBwRQSp2hs7CvkI61NY1m hZ2Q== Return-Path: Received: from bubble.grove.modra.org (158.106.96.58.static.exetel.com.au. [58.96.106.158]) by smtp.gmail.com with ESMTPSA id t1sm73587353pgq.23.2020.01.06.03.42.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Jan 2020 03:42:29 -0800 (PST) Received: by bubble.grove.modra.org (Postfix, from userid 1000) id F259780732; Mon, 6 Jan 2020 22:12:25 +1030 (ACDT) Date: Mon, 06 Jan 2020 11:42:00 -0000 From: Alan Modra To: binutils@sourceware.org Subject: ubsan: m32c: left shift of negative value Message-ID: <20200106114225.GZ16749@bubble.grove.modra.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.9.4 (2018-02-28) X-IsSubscribed: yes X-SW-Source: 2020-01/txt/msg00050.txt.bz2 There are probably a lot more of these still here. cpu/ * m32c.cpu (f-dsp-8-u16, f-dsp-8-s16): Rearrange to mask any sign bits before shifting rather than masking after shifting. (f-dsp-16-u16, f-dsp-16-s16, f-dsp-32-u16, f-dsp-32-s16): Likewise. (f-dsp-40-u16, f-dsp-40-s16, f-dsp-48-u16, f-dsp-48-s16): Likewise. (f-dsp-64-u16, f-dsp-8-s24): Likewise. (f-bitbase32-16-s19-unprefixed): Avoid signed left shift. opcodes/ * m32c-ibld.c: Regenerate. diff --git a/cpu/m32c.cpu b/cpu/m32c.cpu index 5a38f1bd52..1e630a4a51 100644 --- a/cpu/m32c.cpu +++ b/cpu/m32c.cpu @@ -436,42 +436,42 @@ (df f-dsp-8-u16 "16 bit unsigned" (all-isas) 8 16 UINT ((value pc) (or UHI - (and (srl value 8) #x00ff) - (and (sll value 8) #xff00))) ; insert + (and (srl value 8) #xff) + (sll (and value #xff) 8))) ; insert ((value pc) (or UHI - (and UHI (srl UHI value 8) #x00ff) - (and UHI (sll UHI value 8) #xff00))) ; extract + (and UHI (srl UHI value 8) #xff) + (sll UHI (and UHI value #xff) 8))) ; extract ) (df f-dsp-8-s16 "8 bit signed" (all-isas) 8 16 INT ((value pc) (ext INT (trunc HI - (or (and (srl value 8) #x00ff) - (and (sll value 8) #xff00))))) ; insert + (or (and (srl value 8) #xff) + (sll (and value #xff) 8))))) ; insert ((value pc) (ext INT (trunc HI - (or (and (srl value 8) #x00ff) - (and (sll value 8) #xff00))))) ; extract + (or (and (srl value 8) #xff) + (sll (and value #xff) 8))))) ; extract ) (df f-dsp-16-u16 "16 bit unsigned" (all-isas) 16 16 UINT ((value pc) (or UHI - (and (srl value 8) #x00ff) - (and (sll value 8) #xff00))) ; insert + (and (srl value 8) #xff) + (sll (and value #xff) 8))) ; insert ((value pc) (or UHI - (and UHI (srl UHI value 8) #x00ff) - (and UHI (sll UHI value 8) #xff00))) ; extract + (and UHI (srl UHI value 8) #xff) + (sll UHI (and UHI value #xff) 8))) ; extract ) (df f-dsp-16-s16 "16 bit signed" (all-isas) 16 16 INT ((value pc) (ext INT (trunc HI - (or (and (srl value 8) #x00ff) - (and (sll value 8) #xff00))))) ; insert + (or (and (srl value 8) #xff) + (sll (and value #xff) 8))))) ; insert ((value pc) (ext INT (trunc HI - (or (and (srl value 8) #x00ff) - (and (sll value 8) #xff00))))) ; extract + (or (and (srl value 8) #xff) + (sll (and value #xff) 8))))) ; extract ) (dnmf f-dsp-24-u16 "16 bit unsigned" (all-isas) UINT @@ -504,79 +504,82 @@ (df f-dsp-32-u16 "16 bit unsigned" (all-isas) 32 16 UINT ((value pc) (or UHI - (and (srl value 8) #x00ff) - (and (sll value 8) #xff00))) ; insert + (and (srl value 8) #xff) + (sll (and value #xff) 8))) ; insert ((value pc) (or UHI - (and UHI (srl UHI value 8) #x00ff) - (and UHI (sll UHI value 8) #xff00))) ; extract + (and UHI (srl UHI value 8) #xff) + (sll UHI (and UHI value #xff) 8))) ; extract ) (df f-dsp-32-s16 "16 bit signed" (all-isas) 32 16 INT ((value pc) (ext INT (trunc HI - (or (and (srl value 8) #x00ff) - (and (sll value 8) #xff00))))) ; insert + (or (and (srl value 8) #xff) + (sll (and value #xff) 8))))) ; insert ((value pc) (ext INT (trunc HI - (or (and (srl value 8) #x00ff) - (and (sll value 8) #xff00))))) ; extract + (or (and (srl value 8) #xff) + (sll (and value #xff) 8))))) ; extract ) (df f-dsp-40-u16 "16 bit unsigned" (all-isas) 40 16 UINT ((value pc) (or UHI - (and (srl value 8) #x00ff) - (and (sll value 8) #xff00))) ; insert + (and (srl value 8) #xff) + (sll (and value #xff) 8))) ; insert ((value pc) (or UHI - (and UHI (srl UHI value 8) #x00ff) - (and UHI (sll UHI value 8) #xff00))) ; extract + (and UHI (srl UHI value 8) #xff) + (sll UHI (and UHI value #xff) 8))) ; extract ) (df f-dsp-40-s16 "16 bit signed" (all-isas) 40 16 INT ((value pc) (ext INT (trunc HI - (or (and (srl value 8) #x00ff) - (and (sll value 8) #xff00))))) ; insert + (or (and (srl value 8) #xff) + (sll (and value #xff) 8))))) ; insert ((value pc) (ext INT (trunc HI - (or (and (srl value 8) #x00ff) - (and (sll value 8) #xff00))))) ; extract + (or (and (srl value 8) #xff) + (sll (and value #xff) 8))))) ; extract ) (df f-dsp-48-u16 "16 bit unsigned" (all-isas) 48 16 UINT ((value pc) (or UHI - (and (srl value 8) #x00ff) - (and (sll value 8) #xff00))) ; insert + (and (srl value 8) #xff) + (sll (and value #xff) 8))) ; insert ((value pc) (or UHI - (and UHI (srl UHI value 8) #x00ff) - (and UHI (sll UHI value 8) #xff00))) ; extract + (and UHI (srl UHI value 8) #xff) + (sll UHI (and UHI value #xff) 8))) ; extract ) (df f-dsp-48-s16 "16 bit signed" (all-isas) 48 16 INT ((value pc) (ext INT (trunc HI - (or (and (srl value 8) #x00ff) - (and (sll value 8) #xff00))))) ; insert + (or (and (srl value 8) #xff) + (sll (and value #xff) 8))))) ; insert ((value pc) (ext INT (trunc HI - (or (and (srl value 8) #x00ff) - (and (sll value 8) #xff00))))) ; extract + (or (and (srl value 8) #xff) + (sll (and value #xff) 8))))) ; extract ) (df f-dsp-64-u16 "16 bit unsigned" (all-isas) 64 16 UINT ((value pc) (or UHI - (and (srl value 8) #x00ff) - (and (sll value 8) #xff00))) ; insert + (and (srl value 8) #xff) + (sll (and value #xff) 8))) ; insert ((value pc) (or UHI - (and UHI (srl UHI value 8) #x00ff) - (and UHI (sll UHI value 8) #xff00))) ; extract + (and UHI (srl UHI value 8) #xff) + (sll UHI (and UHI value #xff) 8))) ; extract ) (df f-dsp-8-s24 "24 bit signed" (all-isas) 8 24 INT - ((value pc) (or SI - (or (and (srl value 16) #xff) (and value #xff00)) - (sll (ext INT (trunc QI (and value #xff))) 16))) - ((value pc) (or SI - (or (and (srl value 16) #xff) (and value #xff00)) - (sll (ext INT (trunc QI (and value #xff))) 16))) + ((value pc) (sub SI (xor (or SI (or (and (srl value 16) #xff) + (and value #xff00)) + (sll (and value #xff) 16)) + #x800000) #x800000)) + ((value pc) (sub SI (xor (or SI + (or (and (srl value 16) #xff) + (and value #xff00)) + (sll (and value #xff) 16)) + #x800000) #x800000)) ) (df f-dsp-8-u24 "24 bit unsigned" (all-isas) 8 24 UINT @@ -846,7 +849,7 @@ (set (ifield f-dsp-16-s16) (sra INT (ifield f-bitbase32-16-s19-unprefixed) 3)) ) (sequence () ; extract - (set (ifield f-bitbase32-16-s19-unprefixed) (or (sll (ifield f-dsp-16-s16) 3) + (set (ifield f-bitbase32-16-s19-unprefixed) (or (mul (ifield f-dsp-16-s16) 8) (ifield f-bitno32-unprefixed))) ) ) -- Alan Modra Australia Development Lab, IBM