Port-m68k archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

gcc m68k default optimization flag



Hi,

I'd like to change the default optimization flag ("DBG" in sys.mk)
from "-Os" to "-O2 -fno-reorder-blocks" to generate more efficient code.


Currently all NetBSD/m68k 6.x releases and -current uses "-Os"
as the default optimization flag for all userland binaries:

 http://nxr.NetBSD.org/xref/src/share/mk/sys.mk?r=1.124#30
---
.elif ${MACHINE_ARCH} == "m68k" || ${MACHINE_ARCH} == "m68000"
# see src/doc/HACKS for details
DBG?=   -Os
---
(BTW no details in src/doc/HACKS)

It looks there was no discussion about this,
but the change log said:

http://mail-index.NetBSD.org/source-changes/2011/10/31/msg028469.html
---
switch m68k to -Os since -O2 produces much bigger code
with gcc 4.5 than it did with gcc 4.1.
---

However, "-Os" also disables "-finline-functions"
(i.e. it won't inline functions even declared with "static inline"
 if they are called more than once) and
it could cause serious and visible performance degradation
in some cases.

I met the problem on mlterm-fb scroll functions.  In that case,
disabling inline made the scroll drawing function ~30% slower.
(upstream mlterm was fixed to use macro instead of inline decls)


With several simple tests, it looks "-O2 -fno-reorder-blocks" seems
enough to reduce code size both on gcc 4.5.4 and 4.8.3.

On -current, the generated libc sizes are:
---

gcc 4.8.3 -O2:
-rw-rw-r-- 1 tsutsui tsutsui 2903924 Jun 22 12:28 obj.news68k/libc.a
-rwxrwxr-x 1 tsutsui tsutsui 1524780 Jun 22 12:28 obj.news68k/libc.so.12.192

gcc 4.8.3 -Os:
-rw-rw-r-- 1 tsutsui tsutsui 2697692 Jun 21 12:19 obj.news68k/libc.a
-rwxrwxr-x 1 tsutsui tsutsui 1352820 Jun 21 12:19 obj.news68k/libc.so.12.192

gcc 4.8.3 -O2 -fno-reorder-blocks:
-rw-rw-r-- 1 tsutsui tsutsui 2763992 Jun 22 12:40 obj.news68k/libc.a
-rwxrwxr-x 1 tsutsui tsutsui 1407604 Jun 22 12:40 obj.news68k/libc.so.12.192

---

gcc 4.5.4 -O2:
-rw-rw-r-- 1 tsutsui tsutsui 2941388 Jun 22 14:07 obj.news68k/libc.a
-rwxrwxr-x 1 tsutsui tsutsui 1564436 Jun 22 14:07 obj.news68k/libc.so.12.192

gcc 4.5.4 -Os:
-rw-rw-r-- 1 tsutsui tsutsui 2749452 Jun 22 13:40 obj.news68k/libc.a
-rwxrwxr-x 1 tsutsui tsutsui 1401228 Jun 22 13:40 obj.news68k/libc.so.12.192

gcc 4.5.4 -O2 -fno-reorder-blocks:
-rw-rw-r-- 1 tsutsui tsutsui 2796912 Jun 22 13:35 obj.news68k/libc.a
-rwxrwxr-x 1 tsutsui tsutsui 1440572 Jun 22 13:35 obj.news68k/libc.so.12.192

---

I have not checked how -fno-reorder-blocks affects performance on
real applications, but I don't think it is so efficent on m68k CPUs
because they don't have large cache memory or alignment restrictions
with visible penalty (per CPU frequency).


If there is no particular objections, I'll switch the default
DBG flag for m68k from "-Os" to "-O2 -fno-reorder-blocks"
(and related COPTS flags in MD kernel config files).

Thanks,


P.S.
It looks snapshot binaries built with gcc 4.8.3 work fine
through the whole sysinst installation both on
NetBSD/news68k and NetBSD/hp300.

---
Izumi Tsutsui


Home | Main Index | Thread Index | Old Index