From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 44082 invoked by alias); 28 May 2015 21:16:02 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 44066 invoked by uid 89); 28 May 2015 21:16:02 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.1 required=5.0 tests=BAYES_00,FREEMAIL_FROM,KAM_ASCII_DIVIDERS,RCVD_IN_DNSWL_NONE,SPF_PASS,T_RP_MATCHES_RCVD autolearn=no version=3.3.2 X-HELO: resqmta-po-03v.sys.comcast.net Received: from resqmta-po-03v.sys.comcast.net (HELO resqmta-po-03v.sys.comcast.net) (96.114.154.162) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Thu, 28 May 2015 21:16:00 +0000 Received: from resomta-po-14v.sys.comcast.net ([96.114.154.238]) by resqmta-po-03v.sys.comcast.net with comcast id ZZFA1q00A58ss0Y01ZFyh3; Thu, 28 May 2015 21:15:58 +0000 Received: from [IPv6:2001:558:6045:a4:40c6:7199:cd03:b02d] ([IPv6:2001:558:6045:a4:40c6:7199:cd03:b02d]) by resomta-po-14v.sys.comcast.net with comcast id ZZFx1q00T2ztT3H01ZFyTR; Thu, 28 May 2015 21:15:58 +0000 From: Mike Stump Content-Type: multipart/mixed; boundary="Apple-Mail=_C6760A37-764A-438F-8D57-8A4CDDC99A05" Subject: arm memcpy of aligned data Message-Id: <9FF08D9A-529E-4FDE-9193-4BD81EDD89E3@comcast.net> Date: Thu, 28 May 2015 21:36:00 -0000 To: gcc-patches Mime-Version: 1.0 (Mac OS X Mail 7.3 \(1878.6\)) X-IsSubscribed: yes X-SW-Source: 2015-05/txt/msg02702.txt.bz2 --Apple-Mail=_C6760A37-764A-438F-8D57-8A4CDDC99A05 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=windows-1252 Content-length: 2127 So, the arm memcpy code of aligned data isn=92t as good as it can be. void *memcpy(void *dest, const void *src, unsigned int n); void foo(char *dst, int i) { memcpy (dst, &i, sizeof (i)); } generates horrible code, but, it we are willing to notice the src or the de= stination are aligned, we can do much better: $ ./cc1 -fschedule-fusion -fdump-tree-all-all -da -march=3Darmv7ve -mcpu=3D= cortex-m4 -fomit-frame-pointer -quiet -O2 /tmp/t.c -o t.s $ cat t.s [ =85 ] foo: @ args =3D 0, pretend =3D 0, frame =3D 4 @ frame_needed =3D 0, uses_anonymous_args =3D 0 @ link register save eliminated. sub sp, sp, #4 str r1, [r0] @ unaligned add sp, sp, #4 Index: gcc/config/arm/arm.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- gcc/config/arm/arm.c (revision 223842) +++ gcc/config/arm/arm.c (working copy) @@ -14376,7 +14376,10 @@ arm_block_move_unaligned_straight (rtx d srcoffset + j * UNITS_PER_WORD - src_autoinc); mem =3D adjust_automodify_address (srcbase, SImode, addr, srcoffset + j * UNITS_PER_WORD); - emit_insn (gen_unaligned_loadsi (regs[j], mem)); + if (src_aligned) + emit_move_insn (regs[j], mem); + else + emit_insn (gen_unaligned_loadsi (regs[j], mem)); } srcoffset +=3D words * UNITS_PER_WORD; } @@ -14395,7 +14398,10 @@ arm_block_move_unaligned_straight (rtx d dstoffset + j * UNITS_PER_WORD - dst_autoinc); mem =3D adjust_automodify_address (dstbase, SImode, addr, dstoffset + j * UNITS_PER_WORD); - emit_insn (gen_unaligned_storesi (mem, regs[j])); + if (dst_aligned) + emit_move_insn (mem, regs[j]); + else + emit_insn (gen_unaligned_storesi (mem, regs[j])); } dstoffset +=3D words * UNITS_PER_WORD; } Ok? Can someone spin this through an arm test suite run for me, I was doing thi= s by inspection and cross compile on a system with no arm bits. Bonus poin= ts if you can check it in with the test case above marked up as appropriate. --Apple-Mail=_C6760A37-764A-438F-8D57-8A4CDDC99A05 Content-Disposition: attachment; filename=arm.diffs.txt Content-Type: text/plain; name="arm.diffs.txt" Content-Transfer-Encoding: 7bit Content-length: 1081 Index: gcc/config/arm/arm.c =================================================================== --- gcc/config/arm/arm.c (revision 223842) +++ gcc/config/arm/arm.c (working copy) @@ -14376,7 +14376,10 @@ arm_block_move_unaligned_straight (rtx d srcoffset + j * UNITS_PER_WORD - src_autoinc); mem = adjust_automodify_address (srcbase, SImode, addr, srcoffset + j * UNITS_PER_WORD); - emit_insn (gen_unaligned_loadsi (regs[j], mem)); + if (src_aligned) + emit_move_insn (regs[j], mem); + else + emit_insn (gen_unaligned_loadsi (regs[j], mem)); } srcoffset += words * UNITS_PER_WORD; } @@ -14395,7 +14398,10 @@ arm_block_move_unaligned_straight (rtx d dstoffset + j * UNITS_PER_WORD - dst_autoinc); mem = adjust_automodify_address (dstbase, SImode, addr, dstoffset + j * UNITS_PER_WORD); - emit_insn (gen_unaligned_storesi (mem, regs[j])); + if (dst_aligned) + emit_move_insn (mem, regs[j]); + else + emit_insn (gen_unaligned_storesi (mem, regs[j])); } dstoffset += words * UNITS_PER_WORD; } --Apple-Mail=_C6760A37-764A-438F-8D57-8A4CDDC99A05--