From patchwork Fri Dec 9 13:54:17 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julian Brown X-Patchwork-Id: 87480 Delivered-To: patch@linaro.org Received: by 10.140.20.101 with SMTP id 92csp316475qgi; Fri, 9 Dec 2016 05:54:55 -0800 (PST) X-Received: by 10.99.173.68 with SMTP id y4mr143440906pgo.54.1481291695219; Fri, 09 Dec 2016 05:54:55 -0800 (PST) Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id e23si34038022pli.262.2016.12.09.05.54.54 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 09 Dec 2016 05:54:55 -0800 (PST) Received-SPF: pass (google.com: domain of newlib-return-14192-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Authentication-Results: mx.google.com; dkim=pass header.i=@sourceware.org; spf=pass (google.com: domain of newlib-return-14192-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=newlib-return-14192-patch=linaro.org@sourceware.org DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:date:from:to:subject:message-id:mime-version :content-type; q=dns; s=default; b=XCngzuiMYCcMETKaBEj+f8r87wN8t Ni7bYPVHIirgMWGg4Wcrs5BV5589puPFONItTUX91slb457VgSHPoQgaj4P89IE4 46RwTLBi96w3Sc84vpe/7hUgKML2GaRlg+AdpbgaiUlcdvCNV9WAf7/KVbZwr3Al 5jAOd3xtMgjwHk= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:date:from:to:subject:message-id:mime-version :content-type; s=default; bh=Is29XGKI5YLZW1ayTOEAD5SCmiM=; b=RtQ zOLaLTlccsaOOe7n5GZ4kqs4C4pGOx5JCZl7SI1/EGUdi55E+j7GnMVtjoUOfwOp BkqFa0TgHEJmEEOolDkb6opc20A5VyJ/JZb/tdDmndMO6IEG05rE6Lk8cLCO36qm VcxSfgk7WwrkGrQQIixebH0R+ZTNrZsTpzkm6ijM= Received: (qmail 85557 invoked by alias); 9 Dec 2016 13:54:44 -0000 Mailing-List: contact newlib-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: newlib-owner@sourceware.org Delivered-To: mailing list newlib@sourceware.org Received: (qmail 85527 invoked by uid 89); 9 Dec 2016 13:54:42 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_NONE, SPF_PASS, URIBL_RED autolearn=ham version=3.3.2 spammy=julian, Julian, H*r:sk:newlib@ X-HELO: relay1.mentorg.com Received: from relay1.mentorg.com (HELO relay1.mentorg.com) (192.94.38.131) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 09 Dec 2016 13:54:32 +0000 Received: from nat-ies.mentorg.com ([192.94.31.2] helo=SVR-IES-MBX-04.mgc.mentorg.com) by relay1.mentorg.com with esmtp id 1cFLd8-0000vQ-KN from Julian_Brown@mentor.com for newlib@sourceware.org; Fri, 09 Dec 2016 05:54:30 -0800 Received: from squid.athome (137.202.0.87) by SVR-IES-MBX-04.mgc.mentorg.com (139.181.222.4) with Microsoft SMTP Server (TLS) id 15.0.1210.3; Fri, 9 Dec 2016 13:54:26 +0000 Date: Fri, 9 Dec 2016 13:54:17 +0000 From: Julian Brown To: Subject: [PATCH] Big-endian fix for memcpy-armv7m.S Message-ID: <20161209135417.15294bf2@squid.athome> MIME-Version: 1.0 X-ClientProxiedBy: svr-ies-mbx-01.mgc.mentorg.com (139.181.222.1) To SVR-IES-MBX-04.mgc.mentorg.com (139.181.222.4) X-IsSubscribed: yes Hi, I noticed that memcpy-armv7m.S makes assumptions about little-endian byte ordering that cause it to get copies with certain sizes/alignments wrong in big-endian mode. We hit this with a "generic profile" ARMv7 big-endian multilib, but I guess anyone trying to run an M-profile chip in big-endian mode (if such things exist) could hit the same problem. I've tested this with (caveat, somewhat experimental!) QEMU patches: http://lists.nongnu.org/archive/html/qemu-devel/2016-12/msg00972.html running under the GCC testsuite with an ARMv7 big-endian multilib, and results show a positive delta for about 15 tests (e.g. gcc.c-torture/execute/memcpy-2.c, gcc.c-torture/execute/pr65369.c). OK to apply? Thanks, Julian ChangeLog * libc/machine/arm/memcpy-armv7m.S (mis_src_copy): Handle big-endian mode. commit 45cd47548c95b13eed1eb0121ee15ca63df1b466 Author: Julian Brown Date: Thu Dec 8 09:56:51 2016 -0800 Big-endian armv7m memcpy fix. In the case of memcpy-armv7m.S being built for a big-endian multilib (including armv7 without a specific profile), realignment code made assumptions about the byte ordering being little-endian. diff --git a/newlib/libc/machine/arm/memcpy-armv7m.S b/newlib/libc/machine/arm/memcpy-armv7m.S index 8a70c7d..c8bff36 100644 --- a/newlib/libc/machine/arm/memcpy-armv7m.S +++ b/newlib/libc/machine/arm/memcpy-armv7m.S @@ -265,9 +265,17 @@ memcpy: .macro mis_src_copy shift 1: +#ifdef __ARM_BIG_ENDIAN + lsls r4, r4, \shift +#else lsrs r4, r4, \shift +#endif ldr r3, [r1], #4 +#ifdef __ARM_BIG_ENDIAN + lsrs r5, r3, 32-\shift +#else lsls r5, r3, 32-\shift +#endif orr r4, r4, r5 str r4, [r0], #4 mov r4, r3