mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-04 10:18:31 +00:00
Improve dead code elimination
This commit is contained in:
parent
760db8c5ad
commit
0e36cb3ac4
6606 changed files with 9685 additions and 9854 deletions
|
@ -17,13 +17,10 @@
|
|||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "dsp/tty/quant.h"
|
||||
#include "libc/bits/progn.internal.h"
|
||||
#include "libc/testlib/ezbench.h"
|
||||
#include "libc/testlib/testlib.h"
|
||||
#include "net/http/csscolor.h"
|
||||
|
||||
/*TODO(jart): Re-enable me
|
||||
|
||||
static const struct TtyRgb kBlack = {0, 0, 0, 16};
|
||||
static const struct TtyRgb kWhite = {255, 255, 255, 231};
|
||||
static const struct TtyRgb kRed = {0xff, 0, 0, 196};
|
||||
|
@ -45,8 +42,8 @@ void ttyraster2x2_true(void) {
|
|||
|
||||
TEST(ttyraster, testCorner) {
|
||||
ttyraster_true_setup();
|
||||
EXPECT_STREQ("\e[48;2;139;0;0;38;2;3;3;3m▝",
|
||||
PROGN(ttyraster2x2_true(), vtbuf));
|
||||
ttyraster2x2_true();
|
||||
EXPECT_STREQ("\e[48;2;139;0;0;38;2;3;3;3m▝", vtbuf);
|
||||
}
|
||||
|
||||
TEST(ttyraster, testFullBlock_favorsSpace) {
|
||||
|
@ -147,5 +144,3 @@ BENCH(ttyraster_xterm256, bench6) {
|
|||
ttyraster_xterm256_setup();
|
||||
EZBENCH(donothing, ttyraster6x2_xterm256());
|
||||
}
|
||||
|
||||
*/
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/bits/bits.h"
|
||||
#include "libc/bits/progn.internal.h"
|
||||
#include "libc/testlib/ezbench.h"
|
||||
#include "libc/testlib/testlib.h"
|
||||
|
||||
|
@ -27,41 +26,18 @@
|
|||
|
||||
TEST(division, testUnsigned) {
|
||||
volatile uint128_t x;
|
||||
EXPECT_EQ(U(20769187431582143),
|
||||
PROGN(x = U(1000000000123123123), (U(1125899906842624) << 64) / x));
|
||||
x = U(1000000000123123123);
|
||||
EXPECT_EQ(U(20769187431582143), (U(1125899906842624) << 64) / x);
|
||||
x = U(42);
|
||||
EXPECT_EQ((U(26807140639110) << 64) | U(1756832768924719201),
|
||||
PROGN(x = U(42), (U(1125899906842624) << 64) / x));
|
||||
(U(1125899906842624) << 64) / x);
|
||||
}
|
||||
|
||||
TEST(division, testSigned) {
|
||||
volatile int128_t x;
|
||||
EXPECT_EQ(S(20769187431582143),
|
||||
PROGN(x = S(1000000000123123123), (S(1125899906842624) << 64) / x));
|
||||
x = S(1000000000123123123);
|
||||
EXPECT_EQ(S(20769187431582143), (S(1125899906842624) << 64) / x);
|
||||
x = S(42);
|
||||
EXPECT_EQ(S(26807140639110) << 64 | S(1756832768924719201),
|
||||
PROGN(x = S(42), (S(1125899906842624) << 64) / x));
|
||||
}
|
||||
|
||||
BENCH(divmodti4, bench) {
|
||||
volatile int128_t x;
|
||||
EZBENCH2("divmodti4 small / small", donothing,
|
||||
PROGN(x = S(42), x = S(112589990684) / x));
|
||||
EZBENCH2("divmodti4 small / large", donothing,
|
||||
PROGN(x = U(123) << 64 | 123, x = S(112589990684) / x));
|
||||
EZBENCH2("divmodti4 large / small", donothing,
|
||||
PROGN(x = 123, x = (S(1125899906842624) << 64 | 334) / x));
|
||||
EZBENCH2(
|
||||
"divmodti4 large / large", donothing,
|
||||
PROGN(x = U(123) << 64 | 123, x = (S(1125899906842624) << 64 | 334) / x));
|
||||
}
|
||||
|
||||
BENCH(idiv32, bench) {
|
||||
volatile int32_t x;
|
||||
EZBENCH2("idiv32", donothing,
|
||||
PROGN(x = L(1000000000123123123), x = L(1125899906842624) / x));
|
||||
}
|
||||
|
||||
BENCH(idiv64, bench) {
|
||||
volatile int64_t x;
|
||||
EZBENCH2("idiv64", donothing,
|
||||
PROGN(x = L(1000000000123123123), x = L(1125899906842624) / x));
|
||||
(S(1125899906842624) << 64) / x);
|
||||
}
|
||||
|
|
|
@ -24,7 +24,6 @@
|
|||
│ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN │
|
||||
│ THE SOFTWARE. │
|
||||
└─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/bits/progn.internal.h"
|
||||
#include "libc/bits/pushpop.h"
|
||||
#include "libc/bits/safemacros.h"
|
||||
#include "libc/errno.h"
|
||||
|
@ -40,7 +39,7 @@
|
|||
#include "libc/x/x.h"
|
||||
|
||||
static char buffer[128];
|
||||
#define Format(...) PROGN(snprintf(buffer, sizeof(buffer), __VA_ARGS__), buffer)
|
||||
#define Format(...) gc(xasprintf(__VA_ARGS__))
|
||||
|
||||
TEST(sprintf, test_space_flag) {
|
||||
EXPECT_STREQ(" 42", Format("% d", 42));
|
||||
|
|
|
@ -17,14 +17,15 @@
|
|||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/bits/bits.h"
|
||||
#include "libc/bits/progn.internal.h"
|
||||
#include "libc/bits/safemacros.h"
|
||||
#include "libc/fmt/fmt.h"
|
||||
#include "libc/runtime/gc.h"
|
||||
#include "libc/testlib/testlib.h"
|
||||
#include "libc/x/x.h"
|
||||
|
||||
static char buffer[128];
|
||||
|
||||
#define Format(...) PROGN(snprintf(buffer, sizeof(buffer), __VA_ARGS__), buffer)
|
||||
#define Format(...) gc(xasprintf(__VA_ARGS__))
|
||||
|
||||
/**
|
||||
* @fileoverview String formatting tests.
|
||||
|
|
|
@ -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/intrin/mpsadbw.h"
|
||||
#include "libc/intrin/pabsb.h"
|
||||
#include "libc/intrin/pabsd.h"
|
||||
|
@ -2082,19 +2081,3 @@ TEST(pext, fuzz) {
|
|||
ASSERT_EQ(pext(x, y), (pext)(x, y));
|
||||
}
|
||||
}
|
||||
|
||||
BENCH(psrldq, bench) {
|
||||
volatile uint8_t A[16];
|
||||
volatile uint8_t B[16];
|
||||
EZBENCH2("psrldq const 𝑖", donothing, PROGN(psrldq(A, B, 7)));
|
||||
EZBENCH2("psrldq var 𝑖", donothing, PROGN(psrldq(A, B, VEIL("r", 7))));
|
||||
EZBENCH2("psrldq ansi", donothing, PROGN((psrldq)(A, B, 7)));
|
||||
}
|
||||
|
||||
BENCH(pslldq, bench) {
|
||||
volatile uint8_t A[16];
|
||||
volatile uint8_t B[16];
|
||||
EZBENCH2("pslldq const 𝑖", donothing, PROGN(pslldq(A, B, 7)));
|
||||
EZBENCH2("pslldq var 𝑖", donothing, PROGN(pslldq(A, B, VEIL("r", 7))));
|
||||
EZBENCH2("pslldq ansi", donothing, PROGN((pslldq)(A, B, 7)));
|
||||
}
|
||||
|
|
|
@ -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/intrin/palignr.h"
|
||||
#include "libc/rand/rand.h"
|
||||
#include "libc/testlib/ezbench.h"
|
||||
|
@ -220,12 +219,3 @@ TEST(palignrc, test32orHigher_clearsOutput) {
|
|||
ASSERT_EQ(0, C[2]);
|
||||
ASSERT_EQ(0, C[3]);
|
||||
}
|
||||
|
||||
BENCH(palignr, bench) {
|
||||
volatile __intrin_xmm_t A;
|
||||
volatile __intrin_xmm_t B;
|
||||
EZBENCH2("palignr const 𝑖", donothing, PROGN(palignr(&A, &A, &B, 7)));
|
||||
EZBENCH2("palignr var 𝑖", donothing,
|
||||
PROGN(palignr(&A, &A, &B, VEIL("r", 7))));
|
||||
EZBENCH2("palignr ansi", donothing, PROGN((palignr)(&A, &A, &B, 7)));
|
||||
}
|
||||
|
|
24
test/libc/release/clang.sh
Executable file
24
test/libc/release/clang.sh
Executable file
|
@ -0,0 +1,24 @@
|
|||
#!/bin/sh
|
||||
#-*-mode:sh;indent-tabs-mode:nil;tab-width:2;coding:utf-8-*-┐
|
||||
#───vi: set net ft=sh ts=2 sts=2 fenc=utf-8 :vi─────────────┘
|
||||
|
||||
if CLANG=$(command -v clang); then
|
||||
$COMPILE $CLANG \
|
||||
-o o/$MODE/test/libc/release/smokeclang.com.dbg \
|
||||
-Os \
|
||||
-static \
|
||||
-no-pie \
|
||||
-fno-pie \
|
||||
-nostdlib \
|
||||
-nostdinc \
|
||||
-mno-red-zone \
|
||||
-Wl,--gc-sections \
|
||||
-Wl,-z,max-page-size=0x1000 \
|
||||
-Wl,-T,o/$MODE/ape/ape.lds \
|
||||
-include o/cosmopolitan.h \
|
||||
test/libc/release/smoke.c \
|
||||
o/$MODE/libc/crt/crt.o \
|
||||
o/$MODE/ape/ape.o \
|
||||
o/$MODE/cosmopolitan.a || exit
|
||||
o/$MODE/test/libc/release/smokeclang.com.dbg || exit
|
||||
fi
|
|
@ -93,30 +93,15 @@ o/$(MODE)/test/libc/release/smokeansi.com.dbg: \
|
|||
o/$(MODE)/ape/ape.o \
|
||||
o/$(MODE)/cosmopolitan.a
|
||||
|
||||
o/$(MODE)/test/libc/release/smokeclang.com.dbg: \
|
||||
o/$(MODE)/test/libc/release/smokeclang.ok: \
|
||||
test/libc/release/clang.sh \
|
||||
test/libc/release/smoke.c \
|
||||
o/cosmopolitan.h \
|
||||
o/$(MODE)/ape/ape.lds \
|
||||
o/$(MODE)/libc/crt/crt.o \
|
||||
o/$(MODE)/ape/ape.o \
|
||||
o/$(MODE)/cosmopolitan.a
|
||||
@ACTION=CLANG $(COMPILE) clang \
|
||||
-o $@ \
|
||||
-Os \
|
||||
-static \
|
||||
-no-pie \
|
||||
-fno-pie \
|
||||
-nostdlib \
|
||||
-nostdinc \
|
||||
-mno-red-zone \
|
||||
-Wl,--gc-sections \
|
||||
-Wl,-z,max-page-size=0x1000 \
|
||||
-Wl,-T,o/$(MODE)/ape/ape.lds \
|
||||
-include o/cosmopolitan.h \
|
||||
test/libc/release/smoke.c \
|
||||
o/$(MODE)/libc/crt/crt.o \
|
||||
o/$(MODE)/ape/ape.o \
|
||||
o/$(MODE)/cosmopolitan.a
|
||||
@$<
|
||||
|
||||
.PHONY: o/$(MODE)/test/libc/release
|
||||
o/$(MODE)/test/libc/release: \
|
||||
|
@ -125,4 +110,5 @@ o/$(MODE)/test/libc/release: \
|
|||
o/$(MODE)/test/libc/release/smokecxx.com \
|
||||
o/$(MODE)/test/libc/release/smokecxx.com.runs \
|
||||
o/$(MODE)/test/libc/release/smokeansi.com \
|
||||
o/$(MODE)/test/libc/release/smokeansi.com.runs
|
||||
o/$(MODE)/test/libc/release/smokeansi.com.runs \
|
||||
o/$(MODE)/test/libc/release/smokeclang.ok
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/assert.h"
|
||||
#include "libc/bits/progn.internal.h"
|
||||
#include "libc/limits.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
|
|
|
@ -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/calls/struct/sigaction.h"
|
||||
#include "libc/log/check.h"
|
||||
#include "libc/runtime/gc.h"
|
||||
|
@ -550,47 +549,3 @@ TEST(div64, test) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
BENCH(imul, bench) {
|
||||
volatile register int8_t x8, y8;
|
||||
volatile register int16_t x16, y16;
|
||||
volatile register int32_t x32, y32;
|
||||
volatile register int64_t x64, y64;
|
||||
EZBENCH2("imul8", PROGN(x8 = 7, y8 = 18), y8 *= x8);
|
||||
EZBENCH2("imul16", PROGN(x16 = 123, y16 = 116), y16 *= x16);
|
||||
EZBENCH2("imul32", PROGN(x32 = 0x238943, y32 = 0x238), y32 *= x32);
|
||||
EZBENCH2("imul64", PROGN(x64 = 0x23894329838932, y64 = 0x238), y64 *= x64);
|
||||
}
|
||||
|
||||
BENCH(idiv, bench) {
|
||||
volatile register int8_t x8, y8;
|
||||
volatile register int16_t x16, y16;
|
||||
volatile register int32_t x32, y32;
|
||||
volatile register int64_t x64, y64;
|
||||
EZBENCH2("idiv8", PROGN(x8 = 7, y8 = 18), x8 /= y8);
|
||||
EZBENCH2("idiv16", PROGN(x16 = 123, y16 = 116), x16 /= y16);
|
||||
EZBENCH2("idiv32", PROGN(x32 = 0x238943298, y32 = 0x238), x32 /= y32);
|
||||
EZBENCH2("idiv64", PROGN(x64 = 0x23894329838932, y64 = 0x238), x64 /= y64);
|
||||
}
|
||||
|
||||
BENCH(mul, bench) {
|
||||
volatile register uint8_t x8, y8;
|
||||
volatile register uint16_t x16, y16;
|
||||
volatile register uint32_t x32, y32;
|
||||
volatile register uint64_t x64, y64;
|
||||
EZBENCH2("mul8", PROGN(x8 = 7, y8 = 18), y8 *= x8);
|
||||
EZBENCH2("mul16", PROGN(x16 = 123, y16 = 116), y16 *= x16);
|
||||
EZBENCH2("mul32", PROGN(x32 = 0x238943, y32 = 0x238), y32 *= x32);
|
||||
EZBENCH2("mul64", PROGN(x64 = 0x23894329838932, y64 = 0x238), y64 *= x64);
|
||||
}
|
||||
|
||||
BENCH(div, bench) {
|
||||
volatile register uint8_t x8, y8;
|
||||
volatile register uint16_t x16, y16;
|
||||
volatile register uint32_t x32, y32;
|
||||
volatile register uint64_t x64, y64;
|
||||
EZBENCH2("div8", PROGN(x8 = 7, y8 = 18), x8 /= y8);
|
||||
EZBENCH2("div16", PROGN(x16 = 123, y16 = 116), x16 /= y16);
|
||||
EZBENCH2("div32", PROGN(x32 = 0x238943298, y32 = 0x238), x32 /= y32);
|
||||
EZBENCH2("div64", PROGN(x64 = 0x23894329838932, y64 = 0x238), x64 /= y64);
|
||||
}
|
||||
|
|
|
@ -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/fmt/bing.internal.h"
|
||||
#include "libc/math.h"
|
||||
#include "libc/mem/mem.h"
|
||||
|
@ -161,9 +160,14 @@ BENCH(machine, benchPrimeNumberPrograms) {
|
|||
ASSERT_EQ(15, Read32(m->ax));
|
||||
}
|
||||
|
||||
static void machine_benchFpu_fn(void) {
|
||||
ExecuteUntilHalt(m);
|
||||
FpuPop(m);
|
||||
}
|
||||
|
||||
BENCH(machine, benchFpu) {
|
||||
VirtualRecv(m, 0, kPi80, sizeof(kPi80));
|
||||
EZBENCH2("pi80", m->ip = 0, PROGN(ExecuteUntilHalt(m), FpuPop(m)));
|
||||
EZBENCH2("pi80", m->ip = 0, machine_benchFpu_fn());
|
||||
}
|
||||
|
||||
BENCH(machine, benchLoadExec2) {
|
||||
|
@ -266,13 +270,18 @@ BENCH(machine, benchLoadExec8) {
|
|||
EZBENCH2("fchs", m->ip = 0, ExecuteInstruction(m));
|
||||
}
|
||||
|
||||
static void machine_benchPushpop_fn(void) {
|
||||
LoadInstruction(m);
|
||||
ExecuteInstruction(m);
|
||||
LoadInstruction(m);
|
||||
ExecuteInstruction(m);
|
||||
}
|
||||
|
||||
BENCH(machine, benchPushpop) {
|
||||
uint8_t kPushpop[] = {0x50, 0x58};
|
||||
Write64(m->ax, 0);
|
||||
VirtualRecv(m, 0, kPushpop, sizeof(kPushpop));
|
||||
EZBENCH2("pushpop", m->ip = 0,
|
||||
PROGN(LoadInstruction(m), ExecuteInstruction(m), LoadInstruction(m),
|
||||
ExecuteInstruction(m)));
|
||||
EZBENCH2("pushpop", m->ip = 0, machine_benchPushpop_fn());
|
||||
}
|
||||
|
||||
BENCH(machine, benchPause) {
|
||||
|
@ -291,14 +300,18 @@ BENCH(machine, benchClc) {
|
|||
EZBENCH2("clc", m->ip = 0, ExecuteInstruction(m));
|
||||
}
|
||||
|
||||
static void machine_benchNop_fn(void) {
|
||||
LoadInstruction(m);
|
||||
ExecuteInstruction(m);
|
||||
}
|
||||
|
||||
BENCH(machine, benchNop) {
|
||||
uint8_t kNop[] = {0x90};
|
||||
Write64(m->ax, 0);
|
||||
VirtualRecv(m, 0, kNop, sizeof(kNop));
|
||||
LoadInstruction(m);
|
||||
EZBENCH2("nop", m->ip = 0, ExecuteInstruction(m));
|
||||
EZBENCH2("nop w/ load", m->ip = 0,
|
||||
PROGN(LoadInstruction(m), ExecuteInstruction(m)));
|
||||
EZBENCH2("nop w/ load", m->ip = 0, machine_benchNop_fn());
|
||||
}
|
||||
|
||||
TEST(x87, fprem1) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue