diff --git a/Makefile b/Makefile index 68c56b6801..2c85d576ab 100644 --- a/Makefile +++ b/Makefile @@ -27,6 +27,13 @@ all: lib # User-specified CFLAGS. USER_CFLAGS=$(strip $(shell test -f perf-cppflags && cat perf-cppflags)) +# If the user doesn't specify an -O setting, we default to -O3, except +# for upb_def which gets -Os. +ifeq (, $(findstring -O, $(USER_CFLAGS))) + USER_CFLAGS += -O3 + DEF_OPT = -Os +endif + # Basic compiler/flag setup. CC=gcc CXX=g++ @@ -146,11 +153,11 @@ $(LIBUPB_PIC): $(PICOBJ) # critical path but gets very large when -O3 is used. src/upb_def.o: src/upb_def.c $(E) CC $< - $(Q) $(CC) $(CFLAGS) $(CPPFLAGS) -O0 -c -o $@ $< + $(Q) $(CC) $(CFLAGS) $(CPPFLAGS) $(DEF_OPT) -c -o $@ $< src/upb_def.lo: src/upb_def.c $(E) 'CC -fPIC' $< - $(Q) $(CC) $(CFLAGS) $(CPPFLAGS) -O0 -c -o $@ $< -fPIC + $(Q) $(CC) $(CFLAGS) $(CPPFLAGS) $(DEF_OPT) -c -o $@ $< -fPIC src/upb_decoder_x64.o: src/upb_decoder_x64.asm $(E) NASM $< diff --git a/perf-regression-test.py b/perf-regression-test.py index ae3259c5f0..09f4569bcc 100755 --- a/perf-regression-test.py +++ b/perf-regression-test.py @@ -10,7 +10,7 @@ set -v # Generate numbers for baseline. rm -rf perf-tmp git clone . perf-tmp -(cd perf-tmp && ../perf-tests.sh upb) +(cd perf-tmp && ./perf-tests.sh upb) cp perf-tmp/perf-tests.out perf-tests.baseline # Generate numbers for working directory. diff --git a/perf-tests.sh b/perf-tests.sh index bfa8bd69f1..003f866e61 100755 --- a/perf-tests.sh +++ b/perf-tests.sh @@ -13,22 +13,22 @@ rm -f perf-tests.out if [ x`uname -m` = xx86_64 ]; then make clean - echo "-O3 -DNDEBUG -msse3 -m32" > perf-cppflags + echo "-DNDEBUG -m32" > perf-cppflags make upb_benchmarks make benchmark | sed -e 's/^/plain32./g' | tee -a perf-tests.out make clean - echo "-O3 -DNDEBUG -fomit-frame-pointer -msse3 -m32" > perf-cppflags + echo "-DNDEBUG -fomit-frame-pointer -m32" > perf-cppflags make upb_benchmarks make benchmark | sed -e 's/^/omitfp32./g' | tee -a perf-tests.out fi make clean -echo "-O3 -DNDEBUG -msse3" > perf-cppflags +echo "-DNDEBUG" > perf-cppflags make $MAKETARGET make benchmark | sed -e 's/^/plain./g' | tee -a perf-tests.out make clean -echo "-O3 -DNDEBUG -fomit-frame-pointer -msse3" > perf-cppflags +echo "-DNDEBUG -fomit-frame-pointer" > perf-cppflags make $MAKETARGET make benchmark | sed -e 's/^/omitfp./g' | tee -a perf-tests.out diff --git a/src/upb_def.c b/src/upb_def.c index 3b2144367d..61d1a3e4fe 100644 --- a/src/upb_def.c +++ b/src/upb_def.c @@ -728,7 +728,7 @@ static bool upb_fielddef_setdefault(upb_string *dstr, upb_value *d, int type) { case UPB_TYPE(UINT32): case UPB_TYPE(FIXED32): if (strz) { - long val = strtoul(strz, &end, 0); + unsigned long val = strtoul(strz, &end, 0); if (val > UINT32_MAX || errno == ERANGE || *end) success = false; else