Introduce MODE=fastbuild for 28% speedup

This commit is contained in:
Justine Tunney 2022-09-09 08:59:59 -07:00
parent 094ccbb4bd
commit 1729a8259c
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
14 changed files with 82 additions and 111 deletions

View file

@ -4,20 +4,35 @@
# Default Mode # Default Mode
# #
# - `make` # - `make`
# - Optimized
# - Backtraces # - Backtraces
# - Debuggable
# - Syscall tracing # - Syscall tracing
# - Function tracing # - Function tracing
# - Reasonably small # - Reasonably small
# - Reasonably optimized #
# - Reasonably debuggable
ifeq ($(MODE),) ifeq ($(MODE),)
CONFIG_CCFLAGS += \ CONFIG_CCFLAGS += $(BACKTRACES) $(FTRACE) -O2
$(BACKTRACES) \ CONFIG_CPPFLAGS += -DSYSDEBUG
$(FTRACE) \ TARGET_ARCH ?= -msse3
-DSYSDEBUG \ endif
-O2
TARGET_ARCH ?= \ # Fast Build Mode
-msse3 #
# - `make MODE=fastbuild`
# - No debugging
# - Syscall tracing
# - Function tracing
# - Some optimizations
# - Limited Backtraces
# - Compiles 28% faster
#
ifeq ($(MODE),fastbuild)
CONFIG_CCFLAGS += $(BACKTRACES) $(FTRACE) -O
CONFIG_CPPFLAGS += -DSYSDEBUG
CONFIG_OFLAGS += -g0
CONFIG_LDFLAGS += -S
TARGET_ARCH ?= -msse3
endif endif
# Optimized Mode # Optimized Mode
@ -31,19 +46,11 @@ endif
# - No memory corruption detection # - No memory corruption detection
# - assert() / CHECK_xx() may leak code into binary for debuggability # - assert() / CHECK_xx() may leak code into binary for debuggability
# - GCC 8+ hoists check fails into .text.cold, thus minimizing impact # - GCC 8+ hoists check fails into .text.cold, thus minimizing impact
#
ifeq ($(MODE), opt) ifeq ($(MODE), opt)
CONFIG_CPPFLAGS += \ CONFIG_CPPFLAGS += -DNDEBUG -DSYSDEBUG -msse2avx -Wa,-msse2avx
-DNDEBUG \ CONFIG_CCFLAGS += $(BACKTRACES) $(FTRACE) -O3 -fmerge-all-constants
-msse2avx \ TARGET_ARCH ?= -march=native
-Wa,-msse2avx
CONFIG_CCFLAGS += \
$(BACKTRACES) \
$(FTRACE) \
-DSYSDEBUG \
-O3 \
-fmerge-all-constants
TARGET_ARCH ?= \
-march=native
endif endif
# Optimized Linux Mode # Optimized Linux Mode
@ -54,18 +61,12 @@ endif
# - Turns off function tracing # - Turns off function tracing
# - Turns off support for older cpu models # - Turns off support for older cpu models
# - Turns off support for other operating systems # - Turns off support for other operating systems
#
ifeq ($(MODE), optlinux) ifeq ($(MODE), optlinux)
CONFIG_CPPFLAGS += \ CONFIG_CPPFLAGS += -DNDEBUG -msse2avx -Wa,-msse2avx -DSUPPORT_VECTOR=1
-DNDEBUG \ CONFIG_CCFLAGS += -O3 -fmerge-all-constants
-msse2avx \ DEFAULT_COPTS += -mred-zone
-Wa,-msse2avx \ TARGET_ARCH ?= -march=native
-DSUPPORT_VECTOR=1
CONFIG_CCFLAGS += \
-O3 -fmerge-all-constants
DEFAULT_COPTS += \
-mred-zone
TARGET_ARCH ?= \
-march=native
endif endif
# Release Mode # Release Mode
@ -81,16 +82,12 @@ endif
# - DCHECK_xx() statements removed # - DCHECK_xx() statements removed
# - No memory corruption detection # - No memory corruption detection
# - CHECK_xx() won't leak strings into binary # - CHECK_xx() won't leak strings into binary
#
ifeq ($(MODE), rel) ifeq ($(MODE), rel)
CONFIG_CPPFLAGS += \ CONFIG_CPPFLAGS += -DNDEBUG
-DNDEBUG CONFIG_CCFLAGS += $(BACKTRACES) -O2
CONFIG_CCFLAGS += \ TARGET_ARCH ?= -msse3
$(BACKTRACES) \ PYFLAGS += -O1
-O2
TARGET_ARCH ?= \
-msse3
PYFLAGS += \
-O1
endif endif
# Asan Mode # Asan Mode
@ -103,14 +100,11 @@ endif
# - Backtraces # - Backtraces
# - Debuggability # - Debuggability
# - Larger binaries # - Larger binaries
#
ifeq ($(MODE), asan) ifeq ($(MODE), asan)
CONFIG_CCFLAGS += \ CONFIG_CCFLAGS += $(BACKTRACES) -O2
$(BACKTRACES) \ CONFIG_COPTS += -fsanitize=address
-O2 TARGET_ARCH ?= -msse3
CONFIG_COPTS += \
-fsanitize=address
TARGET_ARCH ?= \
-msse3
endif endif
# Debug Mode # Debug Mode
@ -122,22 +116,13 @@ endif
# - Stack canaries # - Stack canaries
# - No optimization (TODO) # - No optimization (TODO)
# - Enormous binaries # - Enormous binaries
#
ifeq ($(MODE), dbg) ifeq ($(MODE), dbg)
CONFIG_CPPFLAGS += \ CONFIG_CPPFLAGS += -DMODE_DBG
-DMODE_DBG CONFIG_CCFLAGS += $(BACKTRACES) $(FTRACE) -DSYSDEBUG -O -fno-inline
CONFIG_CCFLAGS += \ CONFIG_COPTS += -fsanitize=address -fsanitize=undefined
$(BACKTRACES) \ TARGET_ARCH ?= -msse3
$(FTRACE) \ OVERRIDE_CCFLAGS += -fno-pie
-DSYSDEBUG \
-O2 \
-fno-inline
CONFIG_COPTS += \
-fsanitize=address \
-fsanitize=undefined
TARGET_ARCH ?= \
-msse3
OVERRIDE_CCFLAGS += \
-fno-pie
endif endif
# Tiny Mode # Tiny Mode
@ -151,6 +136,7 @@ endif
# - No backtraces # - No backtraces
# - No algorithmics # - No algorithmics
# - YOLO # - YOLO
#
ifeq ($(MODE), tiny) ifeq ($(MODE), tiny)
CONFIG_CPPFLAGS += \ CONFIG_CPPFLAGS += \
-DTINY \ -DTINY \
@ -185,6 +171,7 @@ endif
# - No portability # - No portability
# - No algorithmics # - No algorithmics
# - YOLO # - YOLO
#
ifeq ($(MODE), tinylinux) ifeq ($(MODE), tinylinux)
CONFIG_CPPFLAGS += \ CONFIG_CPPFLAGS += \
-DTINY \ -DTINY \
@ -216,6 +203,7 @@ endif
# - No backtraces # - No backtraces
# - No algorithmics # - No algorithmics
# - YOLO # - YOLO
#
ifeq ($(MODE), tinylinuxbsd) ifeq ($(MODE), tinylinuxbsd)
CONFIG_CPPFLAGS += \ CONFIG_CPPFLAGS += \
-DTINY \ -DTINY \
@ -246,6 +234,7 @@ endif
# - No backtraces # - No backtraces
# - No algorithmics # - No algorithmics
# - YOLO # - YOLO
#
ifeq ($(MODE), tinysysv) ifeq ($(MODE), tinysysv)
CONFIG_CPPFLAGS += \ CONFIG_CPPFLAGS += \
-DTINY \ -DTINY \
@ -276,6 +265,7 @@ endif
# - No backtraces # - No backtraces
# - No algorithmics # - No algorithmics
# - YOLO # - YOLO
#
ifeq ($(MODE), tinynowin) ifeq ($(MODE), tinynowin)
CONFIG_CPPFLAGS += \ CONFIG_CPPFLAGS += \
-DTINY \ -DTINY \

View file

@ -1,24 +0,0 @@
/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│
vi: set et ft=asm ts=8 tw=8 fenc=utf-8 :vi
Copyright 2022 Justine Alexandra Roberts Tunney
Permission to use, copy, modify, and/or distribute this software for
any purpose with or without fee is hereby granted, provided that the
above copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/macros.internal.h"
.privileged
_spinlock_yield:
jmp sched_yield
.endfn _spinlock_yield,globl

View file

@ -27,7 +27,10 @@
* This function does not need to issue a system call. The PID is * This function does not need to issue a system call. The PID is
* tracked by a global variable which is updated at fork(). The only * tracked by a global variable which is updated at fork(). The only
* exception is when the process is vfork()'d in which case a system * exception is when the process is vfork()'d in which case a system
* call shall be issued. * call shall be issued. This optimization helps make functions like
* rand64() fork-safe, however it could lead to race conditions in
* programs that mix fork() with threads. In that case, apps should
* consider using `sys_getpid().ax` instead to force a system call.
* *
* On Linux, and only Linux, the process id is guaranteed to be the same * On Linux, and only Linux, the process id is guaranteed to be the same
* as gettid() for the main thread. * as gettid() for the main thread.

View file

@ -21,13 +21,13 @@
.macro .e e s .macro .e e s
.long \e - kClockNames .long \e - kClockNames
.long 1f - kClockNames .long .L\@ - kClockNames
.rodata.str1.1 .rodata.str1.1
1: .string "\s" .L\@: .string "\s"
.previous .previous
.endm .endm
.section .rodata .section .rodata,"a",@progbits
.align 4 .align 4
.underrun .underrun
kClockNames: kClockNames:

View file

@ -28,6 +28,7 @@
.endm .endm
.section .rodata,"a",@progbits .section .rodata,"a",@progbits
.align 4
.underrun .underrun
kDos2Errno: kDos2Errno:
// .e kNtErrorInvalidFunction,ENOSYS # in consts.sh // .e kNtErrorInvalidFunction,ENOSYS # in consts.sh

View file

@ -21,9 +21,9 @@
.macro .e e s .macro .e e s
.long \e - kErrnoDocs .long \e - kErrnoDocs
.long 1f - kErrnoDocs .long .L\@ - kErrnoDocs
.rodata.str1.1 .rodata.str1.1
1: .asciz "\s" .L\@: .asciz "\s"
.previous .previous
.endm .endm

View file

@ -21,9 +21,9 @@
.macro .e e .macro .e e
.long \e - kErrnoNames .long \e - kErrnoNames
.long 1f - kErrnoNames .long .L\@ - kErrnoNames
.rodata.str1.1 .rodata.str1.1
1: .string "\e" .L\@: .string "\e"
.previous .previous
.endm .endm

View file

@ -21,9 +21,9 @@
.macro .e e s .macro .e e s
.long \e - kIpOptnames .long \e - kIpOptnames
.long 1f - kIpOptnames .long .L\@ - kIpOptnames
.rodata.str1.1 .rodata.str1.1
1: .string "\s" .L\@: .string "\s"
.previous .previous
.endm .endm

View file

@ -21,9 +21,9 @@
.macro .e e s .macro .e e s
.long \e - kOpenFlags .long \e - kOpenFlags
.long 1f - kOpenFlags .long .L\@ - kOpenFlags
.rodata.str1.1 .rodata.str1.1
1: .string "\s" .L\@: .string "\s"
.previous .previous
.endm .endm

View file

@ -21,14 +21,14 @@
.macro .e e s .macro .e e s
.long \e - kRlimitNames .long \e - kRlimitNames
.long 1f - kRlimitNames .long .L\@ - kRlimitNames
.rodata.str1.1 .rodata.str1.1
1: .string "\s" .L\@: .string "\s"
.previous .previous
.endm .endm
.section .rodata .section .rodata
.align 4 .align 4
.underrun .underrun
kRlimitNames: kRlimitNames:
.e RLIMIT_AS,"AS" .e RLIMIT_AS,"AS"

View file

@ -21,14 +21,14 @@
.macro .e e s .macro .e e s
.long \e - kSignalNames .long \e - kSignalNames
.long 1f - kSignalNames .long .L\@ - kSignalNames
.rodata.str1.1 .rodata.str1.1
1: .string "\s" .L\@: .string "\s"
.previous .previous
.endm .endm
.section .rodata .section .rodata
.align 4 .align 4
.underrun .underrun
kSignalNames: kSignalNames:
.e SIGHUP,"SIGHUP" .e SIGHUP,"SIGHUP"

View file

@ -21,14 +21,14 @@
.macro .e e s .macro .e e s
.long \e - kSockOptnames .long \e - kSockOptnames
.long 1f - kSockOptnames .long .L\@ - kSockOptnames
.rodata.str1.1 .rodata.str1.1
1: .string "\s" .L\@: .string "\s"
.previous .previous
.endm .endm
.section .rodata .section .rodata
.align 4 .align 4
.underrun .underrun
kSockOptnames: kSockOptnames:
.e SO_DEBUG,"DEBUG" # bool32 .e SO_DEBUG,"DEBUG" # bool32

View file

@ -21,9 +21,9 @@
.macro .e e s .macro .e e s
.long \e - kTcpOptnames .long \e - kTcpOptnames
.long 1f - kTcpOptnames .long .L\@ - kTcpOptnames
.rodata.str1.1 .rodata.str1.1
1: .string "\s" .L\@: .string "\s"
.previous .previous
.endm .endm

View file

@ -174,7 +174,8 @@ int pthread_barrier_init(pthread_barrier_t *, const pthread_barrierattr_t *,
#define pthread_spin_init(pSpin, multiprocess) ((pSpin)->lock = 0, 0) #define pthread_spin_init(pSpin, multiprocess) ((pSpin)->lock = 0, 0)
#define pthread_spin_destroy(pSpin) ((pSpin)->lock = -1, 0) #define pthread_spin_destroy(pSpin) ((pSpin)->lock = -1, 0)
#if (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 407 #if (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 407 && \
!defined(__STRICT_ANSI__)
extern const errno_t EBUSY; extern const errno_t EBUSY;
#define pthread_spin_lock(pSpin) \ #define pthread_spin_lock(pSpin) \
({ \ ({ \