Make -Ox the default
authorH. Peter Anvin <hpa@zytor.com>
Fri, 16 Jul 2010 01:28:52 +0000 (18:28 -0700)
committerH. Peter Anvin <hpa@zytor.com>
Fri, 16 Jul 2010 01:30:18 +0000 (18:30 -0700)
Make -Ox the default; it's the optimization level expected by most
users, and it is clearly still causing confusion that it has to be
specified manually.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
doc/changes.src
doc/nasmdoc.src
nasm.c

index e64aae7..9cd4b31 100644 (file)
@@ -50,6 +50,9 @@ since 2007.
 
 \b Tighten EA checks. We warn a user if there overflow in EA addressing.
 
+\b Make \c{-Ox} the default optimization level.  For the legacy
+  behavior, specify \c{-O0} explicitly.  See \k{opt-O}.
+
 
 \S{cl-2.08} Version 2.08
 
index 722f099..565b790 100644 (file)
@@ -866,7 +866,8 @@ levels of optimization.  The syntax is:
         releases, the letter \c{x} may also be any number greater than
         one. This number has no effect on the actual number of passes.
 
-The \c{-Ox} mode is recommended for most uses.
+The \c{-Ox} mode is recommended for most uses, and is the default
+since NASM 2.09.
 
 Note that this is a capital \c{O}, and is different from a small \c{o}, which
 is used to specify the output file name. See \k{opt-o}.
diff --git a/nasm.c b/nasm.c
index 9a8c1e5..7a63afb 100644 (file)
--- a/nasm.c
+++ b/nasm.c
@@ -1,6 +1,6 @@
 /* ----------------------------------------------------------------------- *
  *
- *   Copyright 1996-2009 The NASM Authors - All Rights Reserved
+ *   Copyright 1996-2010 The NASM Authors - All Rights Reserved
  *   See the file AUTHORS included with the NASM distribution for
  *   the specific copyright holders.
  *
 #include "output/outform.h"
 #include "listing.h"
 
+/*
+ * This is the maximum number of optimization passes to do.  If we ever
+ * find a case where the optimizer doesn't naturally converge, we might
+ * have to drop this value so the assembler doesn't appear to just hang.
+ */
+#define MAX_OPTIMIZE (INT_MAX >> 1)
+
 struct forwrefinfo {            /* info held on forward refs. */
     int lineno;
     int operand;
@@ -96,8 +103,8 @@ const struct dfmt *dfmt;
 static FILE *error_file;        /* Where to write error messages */
 
 FILE *ofile = NULL;
-int optimizing = -1;            /* number of optimization passes to take */
-static int sb, cmd_sb = 16;     /* by default */
+int optimizing = MAX_OPTIMIZE; /* number of optimization passes to take */
+static int sb, cmd_sb = 16;    /* by default */
 static uint32_t cmd_cpu = IF_PLEVEL;       /* highest level by default */
 static uint32_t cpu = IF_PLEVEL;   /* passed to insn_size & assemble.c */
 int64_t global_offset_changed;      /* referenced in labels.c */
@@ -659,7 +666,7 @@ static bool process_arg(char *p, char *q)
 
            if (!*param) {
                /* Naked -O == -Ox */
-               optimizing = INT_MAX >> 1; /* Almost unlimited */
+               optimizing = MAX_OPTIMIZE;
            } else {
                while (*param) {
                    switch (*param) {
@@ -683,7 +690,7 @@ static bool process_arg(char *p, char *q)
 
                    case 'x':
                        param++;
-                       optimizing = INT_MAX >> 1; /* Almost unlimited */
+                       optimizing = MAX_OPTIMIZE;
                        break;
 
                    default:
@@ -693,6 +700,8 @@ static bool process_arg(char *p, char *q)
                        break;
                    }
                }
+               if (optimizing > MAX_OPTIMIZE)
+                   optimizing = MAX_OPTIMIZE;
            }
            break;
        }