mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-07 03:38:31 +00:00
Productionize new APE loader and more
The APE_NO_MODIFY_SELF loader payload has been moved out of the examples folder and improved so that it works on BSD systems, and permits general elf program headers. This brings its quality up enough that it should be acceptable to use by default for many programs, e.g. Python, Lua, SQLite and Python. It's the responsibility of the user to define an appropriate TMPDIR if /tmp is considered an adversarial environment. Mac OS shall be supported by APE_NO_MODIFY_SELF soon. Fixes and improvements have been made to program_executable_name as it's now the one true way to get the absolute path of the executing image. This change fixes a memory leak in linenoise history loading, introduced by performance optimizations in51904e2687
This change fixes a longstanding regression with Mach system calls, that23ae9dfceb
back in February which impacted our sched_yield() implementation, which is why no one noticed until now. The Blinkenlights PC emulator has been improved. We now fix rendering on XNU and BSD by not making the assumption that the kernel terminal driver understands UTF8 since that seems to break its internal modeling of \r\n which is now being addressed by using \e[𝑦H instead. The paneling is now more compact in real mode so you won't need to make your font as tiny if you're only emulating an 8086 program. The CLMUL ISA is now emulated too This change also makes improvement to time. CLOCK_MONOTONIC now does the right thing on Windows NT. The nanosecond time module functions added in Python 3.7 have been backported. This change doubles the performance of Argon2 password stretching simply by not using its copy_block and xor_block helper functions, as they were trivial to inline thus resulting in us needing to iterate over each 1024 byte block four fewer times. This change makes code size improvements. _PyUnicode_ToNumeric() was 64k in size and now it's 10k. The CJK codec lookup tables now use lazy delta zigzag deflate (δzd) encoding which reduces their size from 600k to 200k plus the code bloat caused by macro abuse in _decimal.c is now addressed so our fully-loaded statically-linked hermetically-sealed Python virtual interpreter container is now 9.4 megs in the default build mode and 5.5m in MODE=tiny which leaves plenty of room for chibicc. The pydoc web server now accommodates the use case of people who work by SSH'ing into a different machine w/ python.com -m pydoc -p8080 -h0.0.0.0 Finally Python Capsulae delenda est and won't be supported in the future
This commit is contained in:
parent
9cb54218ab
commit
47a53e143b
270 changed files with 214544 additions and 23331 deletions
|
@ -136,11 +136,12 @@ ctrl-c interrupt -t tui mode\n\
|
|||
s step -r real mode\n\
|
||||
n next -s statistics\n\
|
||||
c continue -b ADDR push breakpoint\n\
|
||||
q quit -L PATH log file location\n\
|
||||
f finish -R reactive tui mode\n\
|
||||
R restart -H disable highlighting\n\
|
||||
x hex -v increase verbosity\n\
|
||||
? help -? help\n\
|
||||
C continue harder -L PATH log file location\n\
|
||||
q quit -R reactive tui mode\n\
|
||||
f finish -H disable highlighting\n\
|
||||
R restart -v increase verbosity\n\
|
||||
x hex -? help\n\
|
||||
? help\n\
|
||||
t sse type\n\
|
||||
w sse width\n\
|
||||
B pop breakpoint\n\
|
||||
|
@ -148,6 +149,7 @@ ctrl-t turbo\n\
|
|||
alt-t slowmo"
|
||||
|
||||
#define MAXZOOM 16
|
||||
#define DISWIDTH 40
|
||||
#define DUMPWIDTH 64
|
||||
#define DISPWIDTH 80
|
||||
#define WHEELDELTA 1
|
||||
|
@ -236,9 +238,13 @@ struct Panels {
|
|||
|
||||
static const signed char kThePerfectKernel[8] = {-1, -3, 3, 17, 17, 3, -3, -1};
|
||||
|
||||
static const char kRegisterNames[16][4] = {
|
||||
"RAX", "RCX", "RDX", "RBX", "RSP", "RBP", "RSI", "RDI",
|
||||
"R8", "R9", "R10", "R11", "R12", "R13", "R14", "R15",
|
||||
static const char kRipName[3][4] = {"IP", "EIP", "RIP"};
|
||||
|
||||
static const char kRegisterNames[3][16][4] = {
|
||||
{"AX", "CX", "DX", "BX", "SP", "BP", "SI", "DI"},
|
||||
{"EAX", "ECX", "EDX", "EBX", "ESP", "EBP", "ESI", "EDI"},
|
||||
{"RAX", "RCX", "RDX", "RBX", "RSP", "RBP", "RSI", "RDI", "R8", "R9", "R10",
|
||||
"R11", "R12", "R13", "R14", "R15"},
|
||||
};
|
||||
|
||||
static bool react;
|
||||
|
@ -788,18 +794,56 @@ static int PickNumberOfXmmRegistersToShow(void) {
|
|||
}
|
||||
}
|
||||
|
||||
static int GetRegHexWidth(void) {
|
||||
switch (m->mode & 3) {
|
||||
case XED_MODE_LONG:
|
||||
return 16;
|
||||
case XED_MODE_LEGACY:
|
||||
return 8;
|
||||
case XED_MODE_REAL:
|
||||
if ((Read64(m->ax) >> 16) || (Read64(m->cx) >> 16) ||
|
||||
(Read64(m->dx) >> 16) || (Read64(m->bx) >> 16) ||
|
||||
(Read64(m->sp) >> 16) || (Read64(m->bp) >> 16) ||
|
||||
(Read64(m->si) >> 16) || (Read64(m->di) >> 16)) {
|
||||
return 8;
|
||||
} else {
|
||||
return 4;
|
||||
}
|
||||
default:
|
||||
unreachable;
|
||||
}
|
||||
}
|
||||
|
||||
static int GetAddrHexWidth(void) {
|
||||
switch (m->mode & 3) {
|
||||
case XED_MODE_LONG:
|
||||
return 12;
|
||||
case XED_MODE_LEGACY:
|
||||
return 8;
|
||||
case XED_MODE_REAL:
|
||||
if (Read64(m->fs) >= 0x10fff0 || Read64(m->gs) >= 0x10fff0) {
|
||||
return 8;
|
||||
} else {
|
||||
return 6;
|
||||
}
|
||||
default:
|
||||
unreachable;
|
||||
}
|
||||
}
|
||||
|
||||
void SetupDraw(void) {
|
||||
int i, j, n, a, b, yn, cpuy, ssey, dx[2], c2y[3], c3y[5];
|
||||
int i, j, n, a, b, c, yn, cpuy, ssey, dx[2], c2y[3], c3y[5];
|
||||
|
||||
cpuy = 9;
|
||||
if (IsSegNonZero()) cpuy += 2;
|
||||
ssey = PickNumberOfXmmRegistersToShow();
|
||||
if (ssey) ++ssey;
|
||||
|
||||
a = 12 + 1 + DUMPWIDTH;
|
||||
a = GetAddrHexWidth() + 1 + DUMPWIDTH;
|
||||
b = DISPWIDTH + 1;
|
||||
c = GetAddrHexWidth() + 1 + DISWIDTH;
|
||||
dx[1] = txn >= a + b ? txn - a : txn;
|
||||
dx[0] = txn >= a + b + b ? txn - a - b : dx[1];
|
||||
dx[0] = txn >= c + b + a ? txn - a - b : dx[1];
|
||||
|
||||
yn = tyn - 1;
|
||||
a = 1 / 8. * yn;
|
||||
|
@ -1063,10 +1107,10 @@ static void DrawRegister(struct Panel *p, long i, long r) {
|
|||
value = Read64(m->reg[r]);
|
||||
previous = Read64(laststate.reg[r]);
|
||||
if (value != previous) AppendPanel(p, i, "\e[7m");
|
||||
snprintf(buf, sizeof(buf), "%-3s", kRegisterNames[r]);
|
||||
snprintf(buf, sizeof(buf), "%-3s", kRegisterNames[m->mode & 3][r]);
|
||||
AppendPanel(p, i, buf);
|
||||
AppendPanel(p, i, " ");
|
||||
snprintf(buf, sizeof(buf), "0x%016lx", value);
|
||||
snprintf(buf, sizeof(buf), "%0*lx", GetRegHexWidth(), value);
|
||||
AppendPanel(p, i, buf);
|
||||
if (value != previous) AppendPanel(p, i, "\e[27m");
|
||||
AppendPanel(p, i, " ");
|
||||
|
@ -1082,7 +1126,11 @@ static void DrawSegment(struct Panel *p, long i, const uint8_t seg[8],
|
|||
snprintf(buf, sizeof(buf), "%-3s", name);
|
||||
AppendPanel(p, i, buf);
|
||||
AppendPanel(p, i, " ");
|
||||
snprintf(buf, sizeof(buf), "0x%016lx", value);
|
||||
if ((m->mode & 3) == XED_MODE_REAL) {
|
||||
snprintf(buf, sizeof(buf), "%0*lx", GetRegHexWidth(), value >> 4);
|
||||
} else {
|
||||
snprintf(buf, sizeof(buf), "%0*lx", GetRegHexWidth(), value);
|
||||
}
|
||||
AppendPanel(p, i, buf);
|
||||
if (value != previous) AppendPanel(p, i, "\e[27m");
|
||||
AppendPanel(p, i, " ");
|
||||
|
@ -1116,7 +1164,8 @@ static void DrawCpu(struct Panel *p) {
|
|||
DrawRegister(p, 5, 9), DrawRegister(p, 5, 13), DrawSt(p, 5, 5);
|
||||
DrawRegister(p, 6, 10), DrawRegister(p, 6, 14), DrawSt(p, 6, 6);
|
||||
DrawRegister(p, 7, 11), DrawRegister(p, 7, 15), DrawSt(p, 7, 7);
|
||||
snprintf(buf, sizeof(buf), "RIP 0x%016x FLG", m->ip);
|
||||
snprintf(buf, sizeof(buf), "%-3s %0*x FLG", kRipName[m->mode & 3],
|
||||
GetRegHexWidth(), m->ip);
|
||||
AppendPanel(p, 8, buf);
|
||||
DrawFlag(p, 8, 'C', GetFlag(m->flags, FLAGS_CF));
|
||||
DrawFlag(p, 8, 'P', GetFlag(m->flags, FLAGS_PF));
|
||||
|
@ -1295,7 +1344,7 @@ static void DrawMemoryZoomed(struct Panel *p, struct MemoryView *view,
|
|||
free(ranges.p);
|
||||
high = false;
|
||||
for (c = i = 0; i < p->bottom - p->top; ++i) {
|
||||
AppendFmt(&p->lines[i], "%012lx ",
|
||||
AppendFmt(&p->lines[i], "%0*lx ", GetAddrHexWidth(),
|
||||
((view->start + i) * DUMPWIDTH * (1ull << view->zoom)) &
|
||||
0x0000ffffffffffff);
|
||||
for (j = 0; j < DUMPWIDTH; ++j, ++c) {
|
||||
|
@ -1332,7 +1381,7 @@ static void DrawMemoryUnzoomed(struct Panel *p, struct MemoryView *view,
|
|||
bool high, changed;
|
||||
high = false;
|
||||
for (i = 0; i < p->bottom - p->top; ++i) {
|
||||
AppendFmt(&p->lines[i], "%012lx ",
|
||||
AppendFmt(&p->lines[i], "%0*lx ", GetAddrHexWidth(),
|
||||
((view->start + i) * DUMPWIDTH) & 0x0000ffffffffffff);
|
||||
for (j = 0; j < DUMPWIDTH; ++j) {
|
||||
k = (view->start + i) * DUMPWIDTH + j;
|
||||
|
@ -1423,7 +1472,7 @@ static void DrawBreakpoints(struct Panel *p) {
|
|||
sym = DisFindSym(dis, addr);
|
||||
name = sym != -1 ? dis->syms.stab + dis->syms.p[sym].name : "UNKNOWN";
|
||||
s = buf;
|
||||
s += sprintf(s, "%012lx ", addr & 0x0000ffffffffffff);
|
||||
s += sprintf(s, "%0*lx ", GetAddrHexWidth(), addr & 0x0000ffffffffffff);
|
||||
CHECK_LT(Demangle(s, name, DIS_MAX_SYMBOL_LENGTH), buf + ARRAYLEN(buf));
|
||||
AppendPanel(p, line - breakpointsstart, buf);
|
||||
if (sym != -1 && addr != dis->syms.p[sym].addr) {
|
||||
|
@ -1463,7 +1512,8 @@ static void DrawFrames(struct Panel *p) {
|
|||
sym = DisFindSym(dis, rp);
|
||||
name = sym != -1 ? dis->syms.stab + dis->syms.p[sym].name : "UNKNOWN";
|
||||
s = line;
|
||||
s += sprintf(s, "%012lx %012lx ", (Read64(m->ss) + bp) & 0x0000ffffffffffff,
|
||||
s += sprintf(s, "%0*lx %0*lx ", GetAddrHexWidth(),
|
||||
(Read64(m->ss) + bp) & 0x0000ffffffffffff, GetAddrHexWidth(),
|
||||
rp & 0x0000ffffffffffff);
|
||||
s = Demangle(s, name, DIS_MAX_SYMBOL_LENGTH);
|
||||
AppendPanel(p, i - framesstart, line);
|
||||
|
@ -1504,14 +1554,15 @@ static void CheckFramePointerImpl(void) {
|
|||
sp = Read64(m->sp);
|
||||
while (bp) {
|
||||
if (!(r = FindReal(m, Read64(m->ss) + bp))) {
|
||||
INFOF("corrupt frame: %012lx", bp & 0x0000ffffffffffff);
|
||||
INFOF("corrupt frame: %0*lx", GetAddrHexWidth(), bp & 0x0000ffffffffffff);
|
||||
ThrowProtectionFault(m);
|
||||
}
|
||||
sp = bp;
|
||||
bp = Read64(r + 0) - 0;
|
||||
rp = Read64(r + 8) - 1;
|
||||
if (!bp && !(m->bofram[0] <= rp && rp <= m->bofram[1])) {
|
||||
INFOF("bad frame !(%012lx <= %012lx <= %012lx)", m->bofram[0], rp,
|
||||
INFOF("bad frame !(%0*lx <= %0*lx <= %0*lx)", GetAddrHexWidth(),
|
||||
m->bofram[0], GetAddrHexWidth(), rp, GetAddrHexWidth(),
|
||||
m->bofram[1]);
|
||||
ThrowProtectionFault(m);
|
||||
}
|
||||
|
@ -1835,8 +1886,8 @@ static void OnDebug(void) {
|
|||
}
|
||||
|
||||
static void OnSegmentationFault(void) {
|
||||
snprintf(systemfailure, sizeof(systemfailure), "SEGMENTATION FAULT %012lx",
|
||||
m->faultaddr & 0x0000ffffffffffff);
|
||||
snprintf(systemfailure, sizeof(systemfailure), "SEGMENTATION FAULT %0*lx",
|
||||
GetAddrHexWidth(), m->faultaddr & 0x0000ffffffffffff);
|
||||
LaunchDebuggerReactively();
|
||||
}
|
||||
|
||||
|
@ -2193,7 +2244,8 @@ static void OnBinbase(struct Machine *m) {
|
|||
unsigned i;
|
||||
int64_t skew;
|
||||
skew = m->xedd->op.disp * 512;
|
||||
INFOF("skew binbase %,ld @ %012lx", skew, GetIp() & 0x0000ffffffffffff);
|
||||
INFOF("skew binbase %,ld @ %0*lx", skew, GetAddrHexWidth(),
|
||||
GetIp() & 0x0000ffffffffffff);
|
||||
for (i = 0; i < dis->syms.i; ++i) dis->syms.p[i].addr += skew;
|
||||
for (i = 0; i < dis->loads.i; ++i) dis->loads.p[i].addr += skew;
|
||||
for (i = 0; i < breakpoints.i; ++i) breakpoints.p[i].addr += skew;
|
||||
|
@ -2566,7 +2618,8 @@ static void Exec(void) {
|
|||
if (!(interrupt = setjmp(m->onhalt))) {
|
||||
if (!(action & CONTINUE) &&
|
||||
(bp = IsAtBreakpoint(&breakpoints, GetIp())) != -1) {
|
||||
INFOF("BREAK1 %012lx", breakpoints.p[bp].addr & 0x0000ffffffffffff);
|
||||
INFOF("BREAK1 %0*lx", GetAddrHexWidth(),
|
||||
breakpoints.p[bp].addr & 0x0000ffffffffffff);
|
||||
tuimode = true;
|
||||
LoadInstruction(m);
|
||||
ExecuteInstruction(m);
|
||||
|
@ -2577,7 +2630,8 @@ static void Exec(void) {
|
|||
for (;;) {
|
||||
LoadInstruction(m);
|
||||
if ((bp = IsAtBreakpoint(&breakpoints, GetIp())) != -1) {
|
||||
INFOF("BREAK2 %012lx", breakpoints.p[bp].addr & 0x0000ffffffffffff);
|
||||
INFOF("BREAK2 %0*lx", GetAddrHexWidth(),
|
||||
breakpoints.p[bp].addr & 0x0000ffffffffffff);
|
||||
action &= ~(FINISH | NEXT | CONTINUE);
|
||||
tuimode = true;
|
||||
break;
|
||||
|
@ -2629,7 +2683,8 @@ static void Tui(void) {
|
|||
if ((action & (FINISH | NEXT | CONTINUE)) &&
|
||||
(bp = IsAtBreakpoint(&breakpoints, GetIp())) != -1) {
|
||||
action &= ~(FINISH | NEXT | CONTINUE);
|
||||
INFOF("BREAK %012lx", breakpoints.p[bp].addr & 0x0000ffffffffffff);
|
||||
INFOF("BREAK %0*lx", GetAddrHexWidth(),
|
||||
breakpoints.p[bp].addr & 0x0000ffffffffffff);
|
||||
}
|
||||
} else {
|
||||
m->xedd = (struct XedDecodedInst *)m->icache[0];
|
||||
|
|
|
@ -80,12 +80,20 @@ o/$(MODE)/tool/build/%.com.dbg: \
|
|||
$(APE)
|
||||
-@$(APELINK)
|
||||
|
||||
o/$(MODE)/tool/build/blinkenlights.com.dbg: \
|
||||
$(TOOL_BUILD_DEPS) \
|
||||
o/$(MODE)/tool/build/build.pkg \
|
||||
o/$(MODE)/tool/build/blinkenlights.o \
|
||||
$(CRT) \
|
||||
$(APE_NO_MODIFY_SELF)
|
||||
@$(APELINK)
|
||||
|
||||
o/$(MODE)/tool/build/ar.com.dbg: \
|
||||
$(TOOL_BUILD_DEPS) \
|
||||
o/$(MODE)/tool/build/build.pkg \
|
||||
o/$(MODE)/tool/build/ar.o \
|
||||
$(CRT) \
|
||||
$(APE_BUILDSAFE)
|
||||
$(APE)
|
||||
-@$(APELINK)
|
||||
|
||||
o/$(MODE)/tool/build/package.com.dbg: \
|
||||
|
@ -93,7 +101,7 @@ o/$(MODE)/tool/build/package.com.dbg: \
|
|||
o/$(MODE)/tool/build/build.pkg \
|
||||
o/$(MODE)/tool/build/package.o \
|
||||
$(CRT) \
|
||||
$(APE_BUILDSAFE)
|
||||
$(APE)
|
||||
-@$(APELINK)
|
||||
|
||||
o/$(MODE)/tool/build/mkdeps.com.dbg: \
|
||||
|
@ -101,7 +109,7 @@ o/$(MODE)/tool/build/mkdeps.com.dbg: \
|
|||
o/$(MODE)/tool/build/build.pkg \
|
||||
o/$(MODE)/tool/build/mkdeps.o \
|
||||
$(CRT) \
|
||||
$(APE_BUILDSAFE)
|
||||
$(APE)
|
||||
-@$(APELINK)
|
||||
|
||||
o/$(MODE)/tool/build/compile.com.dbg: \
|
||||
|
@ -109,7 +117,7 @@ o/$(MODE)/tool/build/compile.com.dbg: \
|
|||
o/$(MODE)/tool/build/build.pkg \
|
||||
o/$(MODE)/tool/build/compile.o \
|
||||
$(CRT) \
|
||||
$(APE_BUILDSAFE)
|
||||
$(APE)
|
||||
-@$(APELINK)
|
||||
|
||||
o/$(MODE)/tool/build/zipobj.com.dbg: \
|
||||
|
@ -117,7 +125,7 @@ o/$(MODE)/tool/build/zipobj.com.dbg: \
|
|||
o/$(MODE)/tool/build/build.pkg \
|
||||
o/$(MODE)/tool/build/zipobj.o \
|
||||
$(CRT) \
|
||||
$(APE_BUILDSAFE)
|
||||
$(APE)
|
||||
-@$(APELINK)
|
||||
|
||||
o/$(MODE)/tool/build/emulator.o: \
|
||||
|
|
52
tool/build/lib/clmul.c
Normal file
52
tool/build/lib/clmul.c
Normal file
|
@ -0,0 +1,52 @@
|
|||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
||||
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ Copyright 2021 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/nexgen32e/bsr.h"
|
||||
#include "libc/nexgen32e/x86feature.h"
|
||||
#include "tool/build/lib/clmul.h"
|
||||
#include "tool/build/lib/endian.h"
|
||||
#include "tool/build/lib/modrm.h"
|
||||
|
||||
/**
|
||||
* @fileoverview Carryless Multiplication ISA
|
||||
*/
|
||||
|
||||
struct clmul {
|
||||
uint64_t x, y;
|
||||
};
|
||||
|
||||
static struct clmul clmul(uint64_t a, uint64_t b) {
|
||||
uint64_t t, x = 0, y = 0;
|
||||
if (a && b) {
|
||||
if (bsrl(a) < bsrl(b)) t = a, a = b, b = t;
|
||||
for (t = 0; b; a <<= 1, b >>= 1) {
|
||||
if (b & 1) x ^= a, y ^= t;
|
||||
t = t << 1 | a >> 63;
|
||||
}
|
||||
}
|
||||
return (struct clmul){x, y};
|
||||
}
|
||||
|
||||
void OpSsePclmulqdq(struct Machine *m, uint32_t rde) {
|
||||
struct clmul res;
|
||||
res = clmul(Read64(XmmRexrReg(m, rde) + ((m->xedd->op.uimm0 & 0x01) << 3)),
|
||||
Read64(GetModrmRegisterXmmPointerRead16(m, rde) +
|
||||
((m->xedd->op.uimm0 & 0x10) >> 1)));
|
||||
Write64(XmmRexrReg(m, rde) + 0, res.x);
|
||||
Write64(XmmRexrReg(m, rde) + 8, res.y);
|
||||
}
|
11
tool/build/lib/clmul.h
Normal file
11
tool/build/lib/clmul.h
Normal file
|
@ -0,0 +1,11 @@
|
|||
#ifndef COSMOPOLITAN_TOOL_BUILD_LIB_CLMUL_H_
|
||||
#define COSMOPOLITAN_TOOL_BUILD_LIB_CLMUL_H_
|
||||
#include "tool/build/lib/machine.h"
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
COSMOPOLITAN_C_START_
|
||||
|
||||
void OpSsePclmulqdq(struct Machine *, uint32_t);
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
#endif /* COSMOPOLITAN_TOOL_BUILD_LIB_CLMUL_H_ */
|
|
@ -35,7 +35,7 @@ void OpCpuid(struct Machine *m, uint32_t rde) {
|
|||
break;
|
||||
case 1:
|
||||
cx |= 1 << 0; // sse3
|
||||
cx |= 0 << 1; // pclmulqdq
|
||||
cx |= 1 << 1; // pclmulqdq
|
||||
cx |= 1 << 9; // ssse3
|
||||
cx |= 1 << 23; // popcnt
|
||||
cx |= 1 << 30; // rdrnd
|
||||
|
|
|
@ -95,7 +95,9 @@ static char *DisError(struct Dis *d, char *p) {
|
|||
|
||||
static char *DisAddr(struct Dis *d, char *p) {
|
||||
int64_t x = d->addr;
|
||||
if (-2147483648 <= x && x <= 2147483647) {
|
||||
if (0 <= x && x < 0x10fff0) {
|
||||
return p + uint64toarray_fixed16(x, p, 24);
|
||||
} else if (-2147483648 <= x && x <= 2147483647) {
|
||||
return p + uint64toarray_fixed16(x, p, 32);
|
||||
} else {
|
||||
return p + uint64toarray_fixed16(x, p, 48);
|
||||
|
@ -104,7 +106,13 @@ static char *DisAddr(struct Dis *d, char *p) {
|
|||
|
||||
static char *DisRaw(struct Dis *d, char *p) {
|
||||
long i;
|
||||
for (i = 0; i < PFIXLEN - MIN(PFIXLEN, d->xedd->op.PIVOTOP); ++i) {
|
||||
int plen;
|
||||
if (0 <= d->addr && d->addr < 0x10fff0) {
|
||||
plen = 2;
|
||||
} else {
|
||||
plen = PFIXLEN;
|
||||
}
|
||||
for (i = 0; i < plen - MIN(plen, d->xedd->op.PIVOTOP); ++i) {
|
||||
*p++ = ' ';
|
||||
*p++ = ' ';
|
||||
}
|
||||
|
@ -127,8 +135,16 @@ static char *DisCode(struct Dis *d, char *p) {
|
|||
}
|
||||
|
||||
static char *DisLineCode(struct Dis *d, char *p) {
|
||||
int blen, plen;
|
||||
if (0 <= d->addr && d->addr < 0x10fff0) {
|
||||
plen = 2;
|
||||
blen = 6;
|
||||
} else {
|
||||
blen = BYTELEN;
|
||||
plen = PFIXLEN;
|
||||
}
|
||||
p = DisColumn(DisAddr(d, p), p, ADDRLEN);
|
||||
p = DisColumn(DisRaw(d, p), p, PFIXLEN * 2 + 1 + BYTELEN * 2);
|
||||
p = DisColumn(DisRaw(d, p), p, plen * 2 + 1 + blen * 2);
|
||||
p = DisCode(d, p);
|
||||
return p;
|
||||
}
|
||||
|
|
|
@ -24,114 +24,214 @@
|
|||
#include "tool/build/lib/modrm.h"
|
||||
#include "tool/build/lib/throw.h"
|
||||
|
||||
void OpDivAlAhAxEbSigned(struct Machine *m, uint32_t rde) {
|
||||
int8_t y, rem;
|
||||
int16_t x, quo;
|
||||
x = Read16(m->ax);
|
||||
y = Read8(GetModrmRegisterBytePointerRead(m, rde));
|
||||
if (!y || (x == INT16_MIN && y == -1)) ThrowDivideError(m);
|
||||
quo = x / y;
|
||||
rem = x % y;
|
||||
if (!(INT8_MIN <= quo && quo <= INT8_MAX)) ThrowDivideError(m);
|
||||
m->ax[0] = quo & 0xff;
|
||||
m->ax[1] = rem & 0xff;
|
||||
struct Dubble {
|
||||
uint64_t lo;
|
||||
uint64_t hi;
|
||||
};
|
||||
|
||||
static inline struct Dubble DubbleNeg(struct Dubble x) {
|
||||
struct Dubble d;
|
||||
d.lo = -x.lo;
|
||||
d.hi = ~(x.hi - (x.lo - 1 > x.lo));
|
||||
return d;
|
||||
}
|
||||
|
||||
void OpDivAlAhAxEbUnsigned(struct Machine *m, uint32_t rde) {
|
||||
uint8_t y, rem;
|
||||
uint16_t x, quo;
|
||||
static inline struct Dubble DubbleShl(struct Dubble x) {
|
||||
struct Dubble d;
|
||||
d.lo = x.lo << 1;
|
||||
d.hi = x.hi << 1 | x.lo >> 63;
|
||||
return d;
|
||||
}
|
||||
|
||||
static inline struct Dubble DubbleShr(struct Dubble x) {
|
||||
struct Dubble d;
|
||||
d.lo = x.lo >> 1 | x.hi << 63;
|
||||
d.hi = x.hi >> 1;
|
||||
return d;
|
||||
}
|
||||
|
||||
static inline unsigned DubbleLte(struct Dubble a, struct Dubble b) {
|
||||
return a.hi == b.hi ? a.lo <= b.lo : a.hi <= b.hi;
|
||||
}
|
||||
|
||||
static struct Dubble DubbleMul(uint64_t a, uint64_t b) {
|
||||
struct Dubble d;
|
||||
uint64_t x, y, t;
|
||||
x = (a & 0xffffffff) * (b & 0xffffffff);
|
||||
t = x >> 32;
|
||||
x &= 0xffffffff;
|
||||
t += (a >> 32) * (b & 0xffffffff);
|
||||
x += (t & 0xffffffff) << 32;
|
||||
y = t >> 32;
|
||||
t = x >> 32;
|
||||
x &= 0xffffffff;
|
||||
t += (b >> 32) * (a & 0xffffffff);
|
||||
x += (t & 0xffffffff) << 32;
|
||||
y += t >> 32;
|
||||
y += (a >> 32) * (b >> 32);
|
||||
d.lo = x;
|
||||
d.hi = y;
|
||||
return d;
|
||||
}
|
||||
|
||||
static struct Dubble DubbleImul(uint64_t a, uint64_t b) {
|
||||
unsigned s, t;
|
||||
struct Dubble p;
|
||||
if ((s = a >> 63)) a = -a;
|
||||
if ((t = b >> 63)) b = -b;
|
||||
p = DubbleMul(a, b);
|
||||
return s ^ t ? DubbleNeg(p) : p;
|
||||
}
|
||||
|
||||
static struct Dubble DubbleDiv(struct Dubble a, uint64_t b, uint64_t *r) {
|
||||
int n, c;
|
||||
uint64_t s;
|
||||
struct Dubble d, q, t;
|
||||
d.lo = b, d.hi = 0;
|
||||
q.lo = 0, q.hi = 0;
|
||||
for (n = 0; DubbleLte(d, a) && n < 128; ++n) {
|
||||
d = DubbleShl(d);
|
||||
}
|
||||
for (; n > 0; --n) {
|
||||
t = a;
|
||||
d = DubbleShr(d);
|
||||
q = DubbleShl(q);
|
||||
s = a.lo, a.lo -= d.lo + 0, c = a.lo > s;
|
||||
s = a.hi, a.hi -= d.hi + c, c = a.hi > s;
|
||||
if (c) {
|
||||
a = t;
|
||||
} else {
|
||||
q.lo++;
|
||||
}
|
||||
}
|
||||
*r = a.lo;
|
||||
return q;
|
||||
}
|
||||
|
||||
static struct Dubble DubbleIdiv(struct Dubble a, uint64_t b, uint64_t *r) {
|
||||
unsigned s, t;
|
||||
struct Dubble q;
|
||||
if ((s = a.hi >> 63)) a = DubbleNeg(a);
|
||||
if ((t = b >> 63)) b = -b;
|
||||
q = DubbleDiv(a, b, r);
|
||||
if (s ^ t) q = DubbleNeg(q);
|
||||
if (s) *r = -*r;
|
||||
return q;
|
||||
}
|
||||
|
||||
void OpDivAlAhAxEbSigned(struct Machine *m, uint32_t rde) {
|
||||
int8_t y, r;
|
||||
int16_t x, q;
|
||||
x = Read16(m->ax);
|
||||
y = Read8(GetModrmRegisterBytePointerRead(m, rde));
|
||||
if (!y) ThrowDivideError(m);
|
||||
quo = x / y;
|
||||
rem = x % y;
|
||||
if (!(UINT8_MIN <= quo && quo <= UINT8_MAX)) ThrowDivideError(m);
|
||||
m->ax[0] = quo & 0xff;
|
||||
m->ax[1] = rem & 0xff;
|
||||
if (x == INT16_MIN) ThrowDivideError(m);
|
||||
q = x / y;
|
||||
r = x % y;
|
||||
if (q != (int8_t)q) ThrowDivideError(m);
|
||||
m->ax[0] = q & 0xff;
|
||||
m->ax[1] = r & 0xff;
|
||||
}
|
||||
|
||||
void OpDivAlAhAxEbUnsigned(struct Machine *m, uint32_t rde) {
|
||||
uint8_t y, r;
|
||||
uint16_t x, q;
|
||||
x = Read16(m->ax);
|
||||
y = Read8(GetModrmRegisterBytePointerRead(m, rde));
|
||||
if (!y) ThrowDivideError(m);
|
||||
q = x / y;
|
||||
r = x % y;
|
||||
if (q > 255) ThrowDivideError(m);
|
||||
m->ax[0] = q & 0xff;
|
||||
m->ax[1] = r & 0xff;
|
||||
}
|
||||
|
||||
static void OpDivRdxRaxEvqpSigned64(struct Machine *m, uint32_t rde,
|
||||
uint8_t *p) {
|
||||
int64_t y, rem;
|
||||
int128_t x, quo;
|
||||
x = (uint128_t)Read64(m->dx) << 64 | Read64(m->ax);
|
||||
y = Read64(p);
|
||||
if (!y || (x == INT128_MIN && y == -1)) ThrowDivideError(m);
|
||||
quo = x / y;
|
||||
rem = x % y;
|
||||
if (!(INT64_MIN <= quo && quo <= INT64_MAX)) ThrowDivideError(m);
|
||||
Write64(m->ax, quo);
|
||||
Write64(m->dx, rem);
|
||||
uint64_t d, r;
|
||||
struct Dubble q;
|
||||
q.lo = Read64(m->ax);
|
||||
q.hi = Read64(m->dx);
|
||||
d = Read64(p);
|
||||
if (!d) ThrowDivideError(m);
|
||||
if (!q.lo && q.hi == 0x8000000000000000) ThrowDivideError(m);
|
||||
q = DubbleIdiv(q, d, &r);
|
||||
if ((int64_t)q.lo < 0 && (int64_t)q.hi != -1) ThrowDivideError(m);
|
||||
if ((int64_t)q.lo >= 0 && q.hi) ThrowDivideError(m);
|
||||
Write64(m->ax, q.lo);
|
||||
Write64(m->dx, r);
|
||||
}
|
||||
|
||||
static void OpDivRdxRaxEvqpSigned32(struct Machine *m, uint32_t rde,
|
||||
uint8_t *p) {
|
||||
int32_t y, rem;
|
||||
int64_t x, quo;
|
||||
int32_t y, r;
|
||||
int64_t x, q;
|
||||
x = (uint64_t)Read32(m->dx) << 32 | Read32(m->ax);
|
||||
y = Read32(p);
|
||||
if (!y || (x == INT64_MIN && y == -1)) ThrowDivideError(m);
|
||||
quo = x / y;
|
||||
rem = x % y;
|
||||
if (!(INT32_MIN <= quo && quo <= INT32_MAX)) ThrowDivideError(m);
|
||||
Write64(m->ax, quo & 0xffffffff);
|
||||
Write64(m->dx, rem & 0xffffffff);
|
||||
if (!y) ThrowDivideError(m);
|
||||
if (x == INT64_MIN) ThrowDivideError(m);
|
||||
q = x / y;
|
||||
r = x % y;
|
||||
if (q != (int32_t)q) ThrowDivideError(m);
|
||||
Write64(m->ax, q & 0xffffffff);
|
||||
Write64(m->dx, r & 0xffffffff);
|
||||
}
|
||||
|
||||
static void OpDivRdxRaxEvqpSigned16(struct Machine *m, uint32_t rde,
|
||||
uint8_t *p) {
|
||||
int16_t y, rem;
|
||||
int32_t x, quo;
|
||||
int16_t y, r;
|
||||
int32_t x, q;
|
||||
x = (uint32_t)Read16(m->dx) << 16 | Read16(m->ax);
|
||||
y = Read16(p);
|
||||
if (!y || (x == INT32_MIN && y == -1)) ThrowDivideError(m);
|
||||
quo = x / y;
|
||||
rem = x % y;
|
||||
if (!(INT16_MIN <= quo && quo <= INT16_MAX)) ThrowDivideError(m);
|
||||
Write16(m->ax, quo);
|
||||
Write16(m->dx, rem);
|
||||
if (!y) ThrowDivideError(m);
|
||||
if (x == INT32_MIN) ThrowDivideError(m);
|
||||
q = x / y;
|
||||
r = x % y;
|
||||
if (q != (int16_t)q) ThrowDivideError(m);
|
||||
Write16(m->ax, q);
|
||||
Write16(m->dx, r);
|
||||
}
|
||||
|
||||
static void OpDivRdxRaxEvqpUnsigned16(struct Machine *m, uint32_t rde,
|
||||
uint8_t *p) {
|
||||
uint16_t y, rem;
|
||||
uint32_t x, quo;
|
||||
uint16_t y, r;
|
||||
uint32_t x, q;
|
||||
x = (uint32_t)Read16(m->dx) << 16 | Read16(m->ax);
|
||||
y = Read16(p);
|
||||
if (!y) ThrowDivideError(m);
|
||||
quo = x / y;
|
||||
rem = x % y;
|
||||
if (!(UINT16_MIN <= quo && quo <= UINT16_MAX)) ThrowDivideError(m);
|
||||
Write16(m->ax, quo);
|
||||
Write16(m->dx, rem);
|
||||
q = x / y;
|
||||
r = x % y;
|
||||
if (q > 65535) ThrowDivideError(m);
|
||||
Write16(m->ax, q);
|
||||
Write16(m->dx, r);
|
||||
}
|
||||
|
||||
static void OpDivRdxRaxEvqpUnsigned32(struct Machine *m, uint32_t rde,
|
||||
uint8_t *p) {
|
||||
uint32_t y, rem;
|
||||
uint64_t x, quo;
|
||||
uint32_t y, r;
|
||||
uint64_t x, q;
|
||||
x = (uint64_t)Read32(m->dx) << 32 | Read32(m->ax);
|
||||
y = Read32(p);
|
||||
if (!y) ThrowDivideError(m);
|
||||
quo = x / y;
|
||||
rem = x % y;
|
||||
if (!(UINT32_MIN <= quo && quo <= UINT32_MAX)) ThrowDivideError(m);
|
||||
Write64(m->ax, quo & 0xffffffff);
|
||||
Write64(m->dx, rem & 0xffffffff);
|
||||
q = x / y;
|
||||
r = x % y;
|
||||
if (q > 4294967295) ThrowDivideError(m);
|
||||
Write64(m->ax, q & 0xffffffff);
|
||||
Write64(m->dx, r & 0xffffffff);
|
||||
}
|
||||
|
||||
static void OpDivRdxRaxEvqpUnsigned64(struct Machine *m, uint32_t rde,
|
||||
uint8_t *p) {
|
||||
uint64_t y, rem;
|
||||
uint128_t x, quo;
|
||||
x = (uint128_t)Read64(m->dx) << 64 | Read64(m->ax);
|
||||
y = Read64(p);
|
||||
if (!y) ThrowDivideError(m);
|
||||
quo = x / y;
|
||||
rem = x % y;
|
||||
if (!(UINT64_MIN <= quo && quo <= UINT64_MAX)) ThrowDivideError(m);
|
||||
Write64(m->ax, quo);
|
||||
Write64(m->dx, rem);
|
||||
uint64_t d, r;
|
||||
struct Dubble q;
|
||||
q.lo = Read64(m->ax);
|
||||
q.hi = Read64(m->dx);
|
||||
d = Read64(p);
|
||||
if (!d) ThrowDivideError(m);
|
||||
q = DubbleDiv(q, d, &r);
|
||||
if (q.hi) ThrowDivideError(m);
|
||||
Write64(m->ax, q.lo);
|
||||
Write64(m->dx, r);
|
||||
}
|
||||
|
||||
void OpDivRdxRaxEvqpSigned(struct Machine *m, uint32_t rde) {
|
||||
|
@ -159,9 +259,9 @@ void OpDivRdxRaxEvqpUnsigned(struct Machine *m, uint32_t rde) {
|
|||
}
|
||||
|
||||
void OpMulAxAlEbSigned(struct Machine *m, uint32_t rde) {
|
||||
bool of;
|
||||
int16_t ax;
|
||||
uint8_t *p;
|
||||
unsigned of;
|
||||
p = GetModrmRegisterBytePointerRead(m, rde);
|
||||
ax = (int8_t)Read8(m->ax) * (int8_t)Read8(p);
|
||||
of = ax != (int8_t)ax;
|
||||
|
@ -172,8 +272,8 @@ void OpMulAxAlEbSigned(struct Machine *m, uint32_t rde) {
|
|||
|
||||
void OpMulAxAlEbUnsigned(struct Machine *m, uint32_t rde) {
|
||||
int ax;
|
||||
bool of;
|
||||
uint8_t *p;
|
||||
unsigned of;
|
||||
p = GetModrmRegisterBytePointerRead(m, rde);
|
||||
ax = Read8(m->ax) * Read8(p);
|
||||
of = ax != (uint8_t)ax;
|
||||
|
@ -183,28 +283,25 @@ void OpMulAxAlEbUnsigned(struct Machine *m, uint32_t rde) {
|
|||
}
|
||||
|
||||
void OpMulRdxRaxEvqpSigned(struct Machine *m, uint32_t rde) {
|
||||
bool of;
|
||||
uint8_t *p;
|
||||
unsigned of;
|
||||
int32_t dxax;
|
||||
int64_t edxeax;
|
||||
int128_t rdxrax;
|
||||
struct Dubble rdxrax;
|
||||
p = GetModrmRegisterWordPointerReadOszRexw(m, rde);
|
||||
if (Rexw(rde)) {
|
||||
__builtin_mul_overflow((int128_t)(int64_t)Read64(m->ax), (int64_t)Read64(p),
|
||||
&rdxrax);
|
||||
of = (int128_t)rdxrax != (int64_t)rdxrax;
|
||||
Write64(m->ax, rdxrax);
|
||||
Write64(m->dx, rdxrax >> 64);
|
||||
rdxrax = DubbleImul(Read64(m->ax), Read64(p));
|
||||
of = !!(rdxrax.hi + (rdxrax.lo >> 63));
|
||||
Write64(m->ax, rdxrax.lo);
|
||||
Write64(m->dx, rdxrax.hi);
|
||||
} else if (!Osz(rde)) {
|
||||
__builtin_mul_overflow((int64_t)(int32_t)Read32(m->ax), (int32_t)Read32(p),
|
||||
&edxeax);
|
||||
of = (int64_t)edxeax != (int32_t)edxeax;
|
||||
edxeax = (int64_t)(int32_t)Read32(m->ax) * (int32_t)Read32(p);
|
||||
of = edxeax != (int32_t)edxeax;
|
||||
Write64(m->ax, edxeax);
|
||||
Write64(m->dx, edxeax >> 32);
|
||||
} else {
|
||||
__builtin_mul_overflow((int32_t)(int16_t)Read16(m->ax), (int16_t)Read16(p),
|
||||
&dxax);
|
||||
of = (int32_t)dxax != (int16_t)dxax;
|
||||
dxax = (int32_t)(int16_t)Read16(m->ax) * (int16_t)Read16(p);
|
||||
of = dxax != (int16_t)dxax;
|
||||
Write16(m->ax, dxax);
|
||||
Write16(m->dx, dxax >> 16);
|
||||
}
|
||||
|
@ -213,25 +310,24 @@ void OpMulRdxRaxEvqpSigned(struct Machine *m, uint32_t rde) {
|
|||
}
|
||||
|
||||
void OpMulRdxRaxEvqpUnsigned(struct Machine *m, uint32_t rde) {
|
||||
bool of;
|
||||
uint8_t *p;
|
||||
unsigned of;
|
||||
uint32_t dxax;
|
||||
uint64_t edxeax;
|
||||
uint128_t rdxrax;
|
||||
struct Dubble rdxrax;
|
||||
p = GetModrmRegisterWordPointerReadOszRexw(m, rde);
|
||||
if (Rexw(rde)) {
|
||||
__builtin_mul_overflow((uint128_t)Read64(m->ax), Read64(p), &rdxrax);
|
||||
of = (uint64_t)rdxrax != rdxrax;
|
||||
Write64(m->ax, rdxrax);
|
||||
Write64(m->dx, rdxrax >> 64);
|
||||
rdxrax = DubbleMul(Read64(m->ax), Read64(p));
|
||||
of = !!rdxrax.hi;
|
||||
Write64(m->ax, rdxrax.lo);
|
||||
Write64(m->dx, rdxrax.hi);
|
||||
} else if (!Osz(rde)) {
|
||||
__builtin_mul_overflow((uint64_t)Read32(m->ax), Read32(p), &edxeax);
|
||||
edxeax = (uint64_t)Read32(m->ax) * Read32(p);
|
||||
of = (uint32_t)edxeax != edxeax;
|
||||
Write64(m->ax, edxeax);
|
||||
Write64(m->dx, edxeax >> 32);
|
||||
} else {
|
||||
__builtin_mul_overflow((uint32_t)(uint16_t)Read16(m->ax),
|
||||
(uint16_t)Read16(p), &dxax);
|
||||
dxax = (uint32_t)(uint16_t)Read16(m->ax) * (uint16_t)Read16(p);
|
||||
of = (uint16_t)dxax != dxax;
|
||||
Write16(m->ax, dxax);
|
||||
Write16(m->dx, dxax >> 16);
|
||||
|
@ -243,23 +339,18 @@ void OpMulRdxRaxEvqpUnsigned(struct Machine *m, uint32_t rde) {
|
|||
static void AluImul(struct Machine *m, uint32_t rde, uint8_t *a, uint8_t *b) {
|
||||
unsigned of;
|
||||
if (Rexw(rde)) {
|
||||
int64_t x, y, z;
|
||||
x = Read64(a);
|
||||
y = Read64(b);
|
||||
of = __builtin_mul_overflow(x, y, &z);
|
||||
Write64(RegRexrReg(m, rde), z);
|
||||
struct Dubble p;
|
||||
p = DubbleImul(Read64(a), Read64(b));
|
||||
of = !!(p.hi + (p.lo >> 63));
|
||||
Write64(RegRexrReg(m, rde), p.lo);
|
||||
} else if (!Osz(rde)) {
|
||||
int32_t x, y, z;
|
||||
x = Read32(a);
|
||||
y = Read32(b);
|
||||
of = __builtin_mul_overflow(x, y, &z);
|
||||
int64_t z;
|
||||
z = (int64_t)(int32_t)Read32(a) * (int32_t)Read32(b);
|
||||
of = z != (int32_t)z;
|
||||
Write64(RegRexrReg(m, rde), z & 0xffffffff);
|
||||
} else {
|
||||
int z;
|
||||
int16_t x, y;
|
||||
x = Read16(a);
|
||||
y = Read16(b);
|
||||
z = x * y;
|
||||
int32_t z;
|
||||
z = (int32_t)(int16_t)Read16(a) * (int16_t)Read16(b);
|
||||
of = z != (int16_t)z;
|
||||
Write16(RegRexrReg(m, rde), z);
|
||||
}
|
||||
|
|
|
@ -1,53 +1,82 @@
|
|||
#ifndef COSMOPOLITAN_TOOL_BUILD_LIB_ENDIAN_H_
|
||||
#define COSMOPOLITAN_TOOL_BUILD_LIB_ENDIAN_H_
|
||||
#include "libc/bits/bits.h"
|
||||
#include "libc/str/str.h"
|
||||
|
||||
#define Read8(P) (*(const uint8_t *)(P))
|
||||
static inline uint8_t Read8(const uint8_t *p) {
|
||||
return p[0];
|
||||
}
|
||||
|
||||
#define Read16(P) \
|
||||
({ \
|
||||
const uint8_t *Ptr = (const uint8_t *)(P); \
|
||||
READ16LE(P); \
|
||||
})
|
||||
static inline void Write8(uint8_t *p, uint8_t v) {
|
||||
*p = v;
|
||||
}
|
||||
|
||||
#define Read32(P) \
|
||||
({ \
|
||||
const uint8_t *Ptr = (const uint8_t *)(P); \
|
||||
READ32LE(P); \
|
||||
})
|
||||
static inline uint16_t Read16(const uint8_t *p) {
|
||||
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
|
||||
uint16_t v;
|
||||
memcpy(&v, p, sizeof(v));
|
||||
return v;
|
||||
#else
|
||||
return p[1] << 8 | p[0];
|
||||
#endif
|
||||
}
|
||||
|
||||
#define Read64(P) \
|
||||
({ \
|
||||
const uint8_t *Ptr = (const uint8_t *)(P); \
|
||||
READ64LE(P); \
|
||||
})
|
||||
static inline void Write16(uint8_t *p, uint16_t v) {
|
||||
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
|
||||
memcpy(p, &v, sizeof(v));
|
||||
#else
|
||||
p[0] = (0x00FF & v) >> 000;
|
||||
p[1] = (0xFF00 & v) >> 010;
|
||||
#endif
|
||||
}
|
||||
|
||||
#define Write8(P, V) \
|
||||
do { \
|
||||
uint8_t Val = (V); \
|
||||
uint8_t *Ptr = (P); \
|
||||
*Ptr = Val; \
|
||||
} while (0)
|
||||
static inline uint32_t Read32(const uint8_t *p) {
|
||||
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
|
||||
uint32_t v;
|
||||
memcpy(&v, p, sizeof(v));
|
||||
return v;
|
||||
#else
|
||||
return ((uint32_t)p[0] << 000 | (uint32_t)p[1] << 010 |
|
||||
(uint32_t)p[2] << 020 | (uint32_t)p[3] << 030);
|
||||
#endif
|
||||
}
|
||||
|
||||
#define Write16(P, V) \
|
||||
do { \
|
||||
uint16_t Val = (V); \
|
||||
uint8_t *Ptr = (P); \
|
||||
WRITE16LE(Ptr, Val); \
|
||||
} while (0)
|
||||
static inline void Write32(uint8_t *p, uint32_t v) {
|
||||
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
|
||||
memcpy(p, &v, sizeof(v));
|
||||
#else
|
||||
p[0] = (0x000000FF & v) >> 000;
|
||||
p[1] = (0x0000FF00 & v) >> 010;
|
||||
p[2] = (0x00FF0000 & v) >> 020;
|
||||
p[3] = (0xFF000000 & v) >> 030;
|
||||
#endif
|
||||
}
|
||||
|
||||
#define Write32(P, V) \
|
||||
do { \
|
||||
uint32_t Val = (V); \
|
||||
uint8_t *Ptr = (P); \
|
||||
WRITE32LE(Ptr, Val); \
|
||||
} while (0)
|
||||
static inline uint64_t Read64(const uint8_t *p) {
|
||||
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
|
||||
uint64_t v;
|
||||
memcpy(&v, p, sizeof(v));
|
||||
return v;
|
||||
#else
|
||||
return ((uint64_t)p[0] << 000 | (uint64_t)p[1] << 010 |
|
||||
(uint64_t)p[2] << 020 | (uint64_t)p[3] << 030 |
|
||||
(uint64_t)p[4] << 040 | (uint64_t)p[5] << 050 |
|
||||
(uint64_t)p[6] << 060 | (uint64_t)p[7] << 070);
|
||||
#endif
|
||||
}
|
||||
|
||||
#define Write64(P, V) \
|
||||
do { \
|
||||
uint64_t Val = (V); \
|
||||
uint8_t *Ptr = (P); \
|
||||
WRITE64LE(Ptr, Val); \
|
||||
} while (0)
|
||||
static inline void Write64(uint8_t *p, uint64_t v) {
|
||||
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
|
||||
memcpy(p, &v, sizeof(v));
|
||||
#else
|
||||
p[0] = (0x00000000000000FF & v) >> 000;
|
||||
p[1] = (0x000000000000FF00 & v) >> 010;
|
||||
p[2] = (0x0000000000FF0000 & v) >> 020;
|
||||
p[3] = (0x00000000FF000000 & v) >> 030;
|
||||
p[4] = (0x000000FF00000000 & v) >> 040;
|
||||
p[5] = (0x0000FF0000000000 & v) >> 050;
|
||||
p[6] = (0x00FF000000000000 & v) >> 060;
|
||||
p[7] = (0xFF00000000000000 & v) >> 070;
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif /* COSMOPOLITAN_TOOL_BUILD_LIB_ENDIAN_H_ */
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
#include "tool/build/lib/bcd.h"
|
||||
#include "tool/build/lib/bitscan.h"
|
||||
#include "tool/build/lib/case.h"
|
||||
#include "tool/build/lib/clmul.h"
|
||||
#include "tool/build/lib/cpuid.h"
|
||||
#include "tool/build/lib/cvt.h"
|
||||
#include "tool/build/lib/divmul.h"
|
||||
|
@ -2215,6 +2216,7 @@ void ExecuteSparseInstruction(struct Machine *m, uint32_t rde, uint32_t d) {
|
|||
CASE(0x22a, OpMovntdqaVdqMdq(m, rde));
|
||||
CASE(0x240, OpSsePmulld(m, rde));
|
||||
CASE(0x30f, OpSsePalignr(m, rde));
|
||||
CASE(0x344, OpSsePclmulqdq(m, rde));
|
||||
default:
|
||||
OpUd(m, rde);
|
||||
}
|
||||
|
|
|
@ -48,7 +48,7 @@ ssize_t PrintPanels(int fd, long pn, struct Panel *p, long tyn, long txn) {
|
|||
bzero(&b, sizeof(b));
|
||||
AppendStr(&b, "\e[H");
|
||||
for (y = 0; y < tyn; ++y) {
|
||||
if (y) AppendStr(&b, "\r\n");
|
||||
if (y) AppendFmt(&b, "\e[%dH", y + 1);
|
||||
for (x = i = 0; i < pn; ++i) {
|
||||
if (p[i].top <= y && y < p[i].bottom) {
|
||||
j = state = 0;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue