From: Fredrik Olsson <peylow@gmail.com>
To: gcc@gcc.gnu.org
Subject: m68k optimisations?
Date: Fri, 08 Nov 2013 11:08:00 -0000 [thread overview]
Message-ID: <CAO9OKOO6NbmPwuSPWwoGFRWbxx0DqrZ8neN_wWNhUyiaZWiZmQ@mail.gmail.com> (raw)
I have this simple functions:
int sum_vec(int c, ...) {
va_list argptr;
va_start(argptr, c);
int sum = 0;
while (c--) {
int x = va_arg(argptr, int);
sum += x;
}
va_end(argptr);
return sum;
}
When compiling with "-fomit-frame-pointer -Os -march=68000 -c -S
-mshort" I get this assembly (I have manually added comments with
clock cycles per instruction and a total for a count of 0, 8 and n>0):
.even
.globl _sum_vec
_sum_vec:
lea (6,%sp),%a0 | 8
move.w 4(%sp),%d1 | 12
clr.w %d0 | 4
jra .L1 | 12
.L2:
add.w (%a0)+,%d0 | 8
.L1:
dbra %d1,.L2 | 16,12
rts | 16
| c==0: 8+12+4+12+12+16=64
| c==8: 8+12+4+12+(16+8)*8+12+16=256
| c==n: =64+24n
When instead compiling with "-fomit-frame-pointer -O3 -march=68000 -c
-S -mshort" I expect to get more aggressive optimisation than -Os, or
at least just as performant, but instead I get this:
.even
.globl _sum_vec
_sum_vec:
move.w 4(%sp),%d0 | 12
jeq .L2 | 12,8
lea (6,%sp),%a0 | 8
subq.w #1,%d0 | 4
and.l #65535,%d0 | 16
add.l %d0,%d0 | 8
lea 8(%sp,%d0.l),%a1 | 16
clr.w %d0 | 4
.L1:
add.w (%a0)+,%d0 | 8
cmp.l %a0,%a1 | 8
jne .L1 | 12|8
rts | 16
.L2:
clr.w %d0 | 4
rts | 16
| c==0: 12+12+4+16=44
| c==8: 12+8+8+4+16+8+16+4+(8+8+12)*4-4+16=316
| c==n: =88+28n
The count==0 case is better. I can see what optimisation has been
tried for the loop, but it just not working since both the ini for the
loop and the loop itself becomes more costly.
Being a GCC beginner I would like a few pointers as to how I should go
about to fix this?
// Fredrik
next reply other threads:[~2013-11-08 11:08 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-11-08 11:08 Fredrik Olsson [this message]
2013-12-05 0:48 ` Maxim Kuvyrkov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAO9OKOO6NbmPwuSPWwoGFRWbxx0DqrZ8neN_wWNhUyiaZWiZmQ@mail.gmail.com \
--to=peylow@gmail.com \
--cc=gcc@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).