From patchwork Thu Apr 11 22:27:49 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 32266 Received: (qmail 66014 invoked by alias); 11 Apr 2019 22:27:56 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 66002 invoked by uid 89); 11 Apr 2019 22:27:56 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, 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=5th, H*RU:sk:host86-, HX-Spam-Relays-External:sk:host86-, H*r:sk:host86- X-HELO: mail-wr1-f67.google.com Received: from mail-wr1-f67.google.com (HELO mail-wr1-f67.google.com) (209.85.221.67) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 11 Apr 2019 22:27:54 +0000 Received: by mail-wr1-f67.google.com with SMTP id w10so9376482wrm.4 for ; Thu, 11 Apr 2019 15:27:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=xlqORVx4cgTjk9eOnW5983la/dSEN0858U6ULzJtbBs=; b=Le9+T8AD9HPy8qayA+3/OeQG9hHSHGTvlFSQTAmBLe+WBR88vYuiTxEVBapqrL21Nw evCb73o4O0520RdHBzxUNBju/L6bCf7abiUzgih1VqhoznpHMBy8zsejmajViXHDR0YE KNUiyzHQ5ZL8i0c68Kr9y3UtbskB3OwIKOkP5CDcdaO3Jt8n/ttoPOTub9p7k/dRNfrw utTjvx8goq3AFtVNtt3KHamCtfuztFNp2Mzr3gHNkPcHy69oy/iIvQFfN5ZyZTk8sDtG DvhMvKWSnNikUOQDRrcIcXZWF94hykINwYLa5j0Krcg4MsIFq/OBxtYZoPKuYnTOFalK rurQ== Return-Path: Received: from localhost (host86-164-133-98.range86-164.btcentralplus.com. [86.164.133.98]) by smtp.gmail.com with ESMTPSA id f11sm51494140wrm.30.2019.04.11.15.27.50 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 11 Apr 2019 15:27:51 -0700 (PDT) Date: Thu, 11 Apr 2019 23:27:49 +0100 From: Andrew Burgess To: Stafford Horne Cc: GDB patches , GNU Binutils , Andrey Bacherov , Openrisc Subject: Re: [PATCH v2 6/6] sim/common: Fix issue with wrong byte order on BE targets Message-ID: <20190411222749.GB2737@embecosm.com> References: <20190409213925.32699-1-shorne@gmail.com> <20190409213925.32699-7-shorne@gmail.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20190409213925.32699-7-shorne@gmail.com> X-Fortune: And I alone am returned to wag the tail. X-Editor: GNU Emacs [ http://www.gnu.org/software/emacs ] User-Agent: Mutt/1.9.2 (2017-12-15) X-IsSubscribed: yes * Stafford Horne [2019-04-10 06:39:25 +0900]: > Currently only the OpenRISC sim uses this JOINSIDF() function to compose a > double float from 2 registers. The old code doesn't seem to work as the > work order gets swapped when running on a x86_64 host. This change > fixes that, but I am not sure if its the best thing to do. > > On mips they do similar reg pair floating point operations composing > doubles from 2 32-bit registers in sim/mips/cp1.c value_fpr(). > > sim/common/ChangeLog: > > * cgen-ops.h (JOINSIDF): Fix big endian check. > --- > sim/common/cgen-ops.h | 8 ++------ > 1 file changed, 2 insertions(+), 6 deletions(-) > > diff --git a/sim/common/cgen-ops.h b/sim/common/cgen-ops.h > index 841552066f..d718394723 100644 > --- a/sim/common/cgen-ops.h > +++ b/sim/common/cgen-ops.h > @@ -431,12 +431,8 @@ JOINSIDI (SI x0, SI x1) > SEMOPS_INLINE DF > JOINSIDF (SI x0, SI x1) > { > - union { SI in[2]; DF out; } x; > - if (CURRENT_TARGET_BYTE_ORDER == BFD_ENDIAN_BIG) I think this is the problem with the existing code, we're using memory on the HOST to perform packing / unpacking, and so its the byte ordering of the HOST that we care about here, not the target. If I change the above line to instead be: if (HOST_BYTE_ORDER == BFD_ENDIAN_BIG) then everything works fine. On inspection I believe all of the uses of CURRENT_TARGET_BYTE_ORDER in this file should be similarly replaced. I've attached a patch for this change. If you agree I'll go ahead and push it. Thanks, Andrew --- [PATCH] sim: Use host not target byte order for merging and splitting values When using writes to memory through a struct to merge and extract multi-word value, it is the endianness of the host, not the target that affects which order the component words need to be written into the structure. Of the 5 functions adjusted here 4 of them are unused. The 5th, JOINSIDF will soon be used by the or1k target. For or1k, simulated on x86-64, this change fixes this function so that the correct bytes are now returned. sim/common/ChangeLog: * cgen-ops.h (SUBWORDXFSI): Compare HOST_BYTE_ORDER not CURRENT_TARGET_BYTE_ORDER. (SUBWORDTFSI): Likewise. (JOINSIDF): Likewise. (JOINSIXF): Likewise. (JOINSITF): Likewise. --- sim/common/ChangeLog | 9 +++++++++ sim/common/cgen-ops.h | 10 +++++----- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/sim/common/cgen-ops.h b/sim/common/cgen-ops.h index 841552066f4..6fecb862a8a 100644 --- a/sim/common/cgen-ops.h +++ b/sim/common/cgen-ops.h @@ -404,7 +404,7 @@ SUBWORDXFSI (XF in, int word) /* Note: typedef struct { SI parts[3]; } XF; */ union { XF in; SI out[3]; } x; x.in = in; - if (CURRENT_TARGET_BYTE_ORDER == BFD_ENDIAN_BIG) + if (HOST_BYTE_ORDER == BFD_ENDIAN_BIG) return x.out[word]; else return x.out[2 - word]; @@ -416,7 +416,7 @@ SUBWORDTFSI (TF in, int word) /* Note: typedef struct { SI parts[4]; } TF; */ union { TF in; SI out[4]; } x; x.in = in; - if (CURRENT_TARGET_BYTE_ORDER == BFD_ENDIAN_BIG) + if (HOST_BYTE_ORDER == BFD_ENDIAN_BIG) return x.out[word]; else return x.out[3 - word]; @@ -432,7 +432,7 @@ SEMOPS_INLINE DF JOINSIDF (SI x0, SI x1) { union { SI in[2]; DF out; } x; - if (CURRENT_TARGET_BYTE_ORDER == BFD_ENDIAN_BIG) + if (HOST_BYTE_ORDER == BFD_ENDIAN_BIG) x.in[0] = x0, x.in[1] = x1; else x.in[1] = x0, x.in[0] = x1; @@ -443,7 +443,7 @@ SEMOPS_INLINE XF JOINSIXF (SI x0, SI x1, SI x2) { union { SI in[3]; XF out; } x; - if (CURRENT_TARGET_BYTE_ORDER == BFD_ENDIAN_BIG) + if (HOST_BYTE_ORDER == BFD_ENDIAN_BIG) x.in[0] = x0, x.in[1] = x1, x.in[2] = x2; else x.in[2] = x0, x.in[1] = x1, x.in[0] = x2; @@ -454,7 +454,7 @@ SEMOPS_INLINE TF JOINSITF (SI x0, SI x1, SI x2, SI x3) { union { SI in[4]; TF out; } x; - if (CURRENT_TARGET_BYTE_ORDER == BFD_ENDIAN_BIG) + if (HOST_BYTE_ORDER == BFD_ENDIAN_BIG) x.in[0] = x0, x.in[1] = x1, x.in[2] = x2, x.in[3] = x3; else x.in[3] = x0, x.in[2] = x1, x.in[1] = x2, x.in[0] = x3;