NASM 2.09 turns on optimisation by default

Programming, for all ages and all languages.
Post Reply
M-Saunders
Member
Member
Posts: 155
Joined: Fri Oct 27, 2006 5:11 am
Location: Oberbayern
Contact:

NASM 2.09 turns on optimisation by default

Post by M-Saunders »

Hi folks,

Just something I discovered today that may be useful (although I guess many people will already know about it). I was having some strange problems with MikeOS after building it on Ubuntu 11.04 (my test box had been running Ubuntu 9.04 before that). It turns out that NASM 2.09, released last year, enables the -Ox optimisation flag by default, which was doing funny things to my executables.

Using "-O0" (dash oh zero) fixed that and left the resulting binaries as intended. Just thought I'd note it here in case anyone has similar problems in the future and suspects it's something else in eg Linux/QEMU that's at fault (like I did for a few hours!).

Cheers,
Mike
MikeOS -- simple, well-documented x86 real-mode OS written in assembly language
http://mikeos.sourceforge.net
User avatar
IanSeyler
Member
Member
Posts: 326
Joined: Mon Jul 28, 2008 9:46 am
Location: Ontario, Canada
Contact:

Re: NASM 2.09 turns on optimisation by default

Post by IanSeyler »

They need to update the wording then. I just did a 'nasm -h' with 2.09.09:

-O<digit> optimize branch offsets
-O0: No optimization (default)
-O1: Minimal optimization
-Ox: Multipass optimization (recommended)

-Ian
BareMetal OS - http://www.returninfinity.com/
Mono-tasking 64-bit OS for x86-64 based computers, written entirely in Assembly
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: NASM 2.09 turns on optimisation by default

Post by Brendan »

Hi,
M-Saunders wrote:It turns out that NASM 2.09, released last year, enables the -Ox optimisation flag by default, which was doing funny things to my executables.
For high level languages like C, when someone says "enabling optimisations breaks my code" it almost always means their code is wrong (e.g. missing "volatile" somewhere, use of uninitialised data, etc).

Given that NASM's optimiser doesn't really do much (optimises short/near jump offsets and simplifies a few operands); I'd be tempted to use the same logic for NASM - e.g. "enabling optimisations breaks my code" probably means your code is broken (e.g. missing "strict" qualifier somewhere, making assumptions about the length/s of instruction/s, etc). ;)


Cheers,

Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
M-Saunders
Member
Member
Posts: 155
Joined: Fri Oct 27, 2006 5:11 am
Location: Oberbayern
Contact:

Re: NASM 2.09 turns on optimisation by default

Post by M-Saunders »

Hi,

Ian: I just saw it here: http://www.nasm.us/doc/nasmdocc.html

"Make -Ox the default optimization level. For the legacy behavior, specify -O0 explicitly."

Brendan: Oh absolutely, and I suspect that this is symptomatic of another problem in my code. Still, with different people on the MikeOS mailing list having different kernels, going back to -O0 will have us all "singing from the same hymn sheet" and we can look at it from there.

Cheers,
Mike
MikeOS -- simple, well-documented x86 real-mode OS written in assembly language
http://mikeos.sourceforge.net
Post Reply