Messages in this thread | | | Date | Sat, 13 Sep 2003 21:51:38 +0200 | From | Jörn Engel <> | Subject | Re: nasm over gas? |
| |
On Sat, 13 September 2003 20:25:39 +0100, Jamie Lokier wrote: > Jörn Engel wrote: > > - Why has Alan measured faster kernels with -Os than with -O2? > > > > Code size *does* matter. > > That's not just i-cache pressure. It is partly a GCC problem, and > it's possible -Os would run faster than -O2 even with no i-cache. > > I've observed -Os emitting exactly the same code as -O2 for some > trivial functions, except that -O2 has a few extra redundant > instructions. > > Obvious the _intent_ of -O2 is to compile for speed, but it's clear > that GCC often emits trivially redundant instructions (like stack > adjustments) that don't serve to speed up the program at all.
I haven't collected too many numbers, but the few I did collect show -O2 code actually being faster than -Os, as long as you stay in userspace and the code is small and loopy. It may get worse for large run-once code, but I don't have numbers for that.
My explanation for Alans results is that nature of kernel code. Usually, kernel code execution takes only a fraction of the cpu time, so the user code run in between effectively flushes the cache. Each system call causes near 100% cache misses, so smaller code is almost always faster.
So even if your observations were wrong and gcc would create perfect code for both -O2 and -Os, I wouldn't expect -O2 to be faster for kernel code.
Jörn
-- More computing sins are committed in the name of efficiency (without necessarily achieving it) than for any other single reason - including blind stupidity. -- W. A. Wulf - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
| |