Improve dead code elimination

This commit is contained in:
Justine Tunney 2021-02-08 04:04:42 -08:00
parent 760db8c5ad
commit 0e36cb3ac4
6606 changed files with 9685 additions and 9854 deletions

View file

@ -22,7 +22,6 @@
#include "libc/sysv/consts/nr.h"
#include "libc/macros.h"
.privileged
.source __FILE__
/ Terminates program abnormally.
/
@ -38,8 +37,10 @@ abort: push %rbp
mov %rsp,%rbp
and $-16,%rsp
sub $16,%rsp
#if SupportsWindows()
testb IsWindows()
jnz 2f
jnz sys_abort_nt
#endif
mov SIG_SETMASK,%edi
mov %rsp,%rsi
push $0xffffffffffffffdf # all bits blocked but SIGABRT
@ -56,5 +57,5 @@ abort: push %rbp
mov SIGABRT,%esi
mov __NR_kill,%eax
syscall # avoid hook and less bt noise
2: call sys_abort_nt
call _Exit
.endfn abort,globl,protected

View file

@ -30,23 +30,6 @@
_construct:
push %rbp
mov %rsp,%rbp
ezlea __init_array_start,ax # static ctors in forward order
.weak __init_array_start # could be called multiple times
ezlea __init_array_end,cx # idempotency recommended
.weak __init_array_end # @see ape/ape.lds
1: cmp %rax,%rcx
je 2f
push %rax
push %rcx
mov %r12,%rdi
mov %r13,%rsi
mov %r14,%rdx
mov %r15,%rcx
call *(%rax)
pop %rcx
pop %rax
add $8,%rax
jmp 1b
2: pop %rbp
pop %rbp
ret
.endfn _construct,globl

View file

@ -23,7 +23,6 @@
#include "libc/sysv/consts/map.h"
#include "libc/dce.h"
.text.startup
.source __FILE__
/ Cosmopolitan runtime.
/
@ -34,30 +33,48 @@
/ @noreturn
cosmo: push %rbp
mov %rsp,%rbp
ezlea _base,bx
mov %edi,%r12d
mov %rsi,%r13
mov %rdx,%r14
mov %rcx,%r15
#ifdef __FAST_MATH__
call __fast_math
push %rax
stmxcsr (%rsp)
orl $0x8040,(%rsp)
ldmxcsr (%rsp)
pop %rax
#endif
call _init
call _construct
ezlea __init_array_start,ax # static ctors in forward order
.weak __init_array_start # could be called multiple times
ezlea __init_array_end,cx # idempotency recommended
.weak __init_array_end # @see ape/ape.lds
1: cmp %rax,%rcx
je 2f
push %rax
push %rcx
call .Largs
call *(%rax)
pop %rcx
pop %rax
add $8,%rax
jmp 1b
2: nop
#if !IsTrustworthy()
mov $PROT_READ,%edi
call _piro
#endif
mov %r12d,%edi
mov %r13,%rsi
mov %r14,%rdx
mov %r15,%rcx
call .Largs
.weak main
call main
xchg %eax,%edi
call exit
.endfn cosmo,weak,hidden
ud2
.Largs: mov %r12d,%edi
mov %r13,%rsi
mov %r14,%rdx
mov %r15,%rcx
ret
.endfn cosmo,weak
#ifdef __PG__
.init.start 800,_init_ftrace

View file

@ -1,45 +0,0 @@
/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│
vi: set et ft=asm ts=8 sw=8 fenc=utf-8 :vi
Copyright 2020 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.h"
#include "libc/notice.inc"
.text.startup
.source __FILE__
/ Intel Manual V.1 §10.2.3 - MXCSR Control and Status Register
#define MXCSR_DE (1 << 1) /* Denormal Flag */
#define MXCSR_DAZ (1 << 6) /* Denormals Are Zeros */
#define MXCSR_DM (1 << 8) /* Denormal Operation Mask */
#define MXCSR_FTZ (1 << 15) /* Flush to Zero */
/ Initializes fast math.
/
/ Seymour Cray didn't care that 81.0/3.0 did not give exactly
/ 27.0 on the CDC 6000 class machines, and he was universally
/ respected for making the fastest machines around.
/ Linus Torvalds
__fast_math:
push %rbp
mov %rsp,%rbp
push %rax
stmxcsr (%rsp)
orl $MXCSR_FTZ+MXCSR_DAZ,(%rsp)
ldmxcsr (%rsp)
leave
ret
.endfn __fast_math,globl

View file

@ -16,7 +16,6 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/bits/progn.internal.h"
#include "libc/bits/safemacros.h"
#include "libc/mem/mem.h"
#include "libc/runtime/interruptiblecall.h"
@ -53,7 +52,8 @@ intptr_t interruptiblecall(struct InterruptibleCall *icall,
icall->sa_new.sa_handler = interruptcall;
icall->sa_new.sa_flags |= SA_RESTART | SA_RESETHAND;
if ((rc = (sigaction)(icall->sig, &icall->sa_new, &icall->sa_old)) != -1) {
g_interruptiblecall = PROGN((icall->prev = g_interruptiblecall), icall);
icall->prev = g_interruptiblecall;
g_interruptiblecall = icall;
if (!setjmp(icall->jb)) {
icall->returnval = rc = callback(p1, p2, p3, p4);
} else {

View file

@ -69,7 +69,6 @@ int mprotect(void *, uint64_t, int) privileged;
int msync(void *, size_t, int);
void __print(const void *, size_t);
void __print_string(const char *);
void __fast_math(void);
void *sbrk(intptr_t);
int brk(void *);
int NtGetVersion(void);

View file

@ -16,6 +16,7 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/dce.h"
#include "libc/macros.h"
#include "libc/runtime/memtrack.h"
@ -23,5 +24,9 @@ int UntrackMemoryIntervals(void *addr, size_t size) {
int a, b;
a = ROUNDDOWN((intptr_t)addr, FRAMESIZE) >> 16;
b = ROUNDDOWN((intptr_t)addr + size - 1, FRAMESIZE) >> 16;
return ReleaseMemoryIntervals(&_mmi, a, b, ReleaseMemoryNt);
if (SupportsWindows()) {
return ReleaseMemoryIntervals(&_mmi, a, b, ReleaseMemoryNt);
} else {
return ReleaseMemoryIntervals(&_mmi, a, b, 0);
}
}