mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-06-27 06:48:31 +00:00
Make improvements
- Emulator can now test the αcτµαlly pδrταblε εxεcµταblε bootloader - Whipped up a webserver named redbean. It services 150k requests per second on a single core. Bundling assets inside zip enables extremely fast serving for two reasons. The first is that zip central directory lookups go faster than stat() system calls. The second is that both zip and gzip content-encoding use DEFLATE, therefore, compressed responses can be served via the sendfile() system call which does an in-kernel copy directly from the zip executable structure. Also note that red bean zip executables can be deployed easily to all platforms, since these native executables work on Linux, Mac, BSD, and Windows. - Address sanitizer now works very well
This commit is contained in:
parent
7327c345f9
commit
416fd86676
230 changed files with 9835 additions and 5682 deletions
|
@ -18,14 +18,19 @@
|
|||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/assert.h"
|
||||
#include "libc/bits/progn.h"
|
||||
#include "libc/limits.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
#include "libc/testlib/ezbench.h"
|
||||
#include "libc/testlib/testlib.h"
|
||||
#include "test/tool/build/lib/optest.h"
|
||||
#include "tool/build/lib/alu.h"
|
||||
#include "tool/build/lib/case.h"
|
||||
#include "tool/build/lib/flags.h"
|
||||
|
||||
#define ALU_TEST 8
|
||||
|
||||
#define NATIVE_ALU2(MODE, INSTRUCTION) \
|
||||
asm("pushf\n\t" \
|
||||
"andl\t%3,(%%rsp)\n\t" \
|
||||
|
@ -97,6 +102,15 @@ const char *const kAluNames[] = {
|
|||
[ALU_XOR] = "xor", [ALU_CMP] = "cmp", [ALU_AND | ALU_TEST] = "test",
|
||||
};
|
||||
|
||||
int64_t Alu(int w, int h, uint64_t x, uint64_t y, uint32_t *flags) {
|
||||
if (h < ALU_CMP) {
|
||||
return kAlu[h][w](x, y, flags);
|
||||
} else {
|
||||
kAlu[h & 7][w](x, y, flags);
|
||||
return x;
|
||||
}
|
||||
}
|
||||
|
||||
int64_t RunOpTest(char w, int h, uint64_t x, uint64_t y, uint32_t *f) {
|
||||
return Alu(w, h, x, y, f);
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
#include "tool/build/lib/flags.h"
|
||||
|
||||
#define OSZ 00000000040
|
||||
#define REXW 00000004000
|
||||
#define REXW 00000000100
|
||||
|
||||
struct Machine m[1];
|
||||
struct XedDecodedInst xedd[1];
|
||||
|
@ -38,7 +38,7 @@ TEST(bsr64, test) {
|
|||
uint64_t i, w, x, a, b;
|
||||
for (i = 0; i < ARRAYLEN(kNumbers); ++i) {
|
||||
x = kNumbers[i];
|
||||
a = AluBsr(m, REXW, 0, x);
|
||||
a = AluBsr(m, REXW, x);
|
||||
asm("bsrq\t%2,%0" : "=r"(b), "=@ccz"(zf) : "r"(x));
|
||||
ASSERT_EQ(zf, GetFlag(m->flags, FLAGS_ZF));
|
||||
if (!zf) ASSERT_EQ(a, b);
|
||||
|
@ -50,7 +50,7 @@ TEST(bsr32, test) {
|
|||
uint32_t i, w, x, a, b;
|
||||
for (i = 0; i < ARRAYLEN(kNumbers); ++i) {
|
||||
x = kNumbers[i];
|
||||
a = AluBsr(m, 0, 0, x);
|
||||
a = AluBsr(m, 0, x);
|
||||
asm("bsrl\t%2,%0" : "=r"(b), "=@ccz"(zf) : "r"(x));
|
||||
ASSERT_EQ(zf, GetFlag(m->flags, FLAGS_ZF));
|
||||
if (!zf) ASSERT_EQ(a, b);
|
||||
|
@ -62,7 +62,7 @@ TEST(bsr16, test) {
|
|||
uint16_t i, w, x, a, b;
|
||||
for (i = 0; i < ARRAYLEN(kNumbers); ++i) {
|
||||
x = kNumbers[i];
|
||||
a = AluBsr(m, OSZ, 0, x);
|
||||
a = AluBsr(m, OSZ, x);
|
||||
asm("bsrw\t%2,%0" : "=r"(b), "=@ccz"(zf) : "r"(x));
|
||||
ASSERT_EQ(zf, GetFlag(m->flags, FLAGS_ZF));
|
||||
if (!zf) ASSERT_EQ(a, b);
|
||||
|
@ -74,7 +74,7 @@ TEST(bsf64, test) {
|
|||
uint64_t i, w, x, a, b;
|
||||
for (i = 0; i < ARRAYLEN(kNumbers); ++i) {
|
||||
x = kNumbers[i];
|
||||
a = AluBsf(m, REXW, 0, x);
|
||||
a = AluBsf(m, REXW, x);
|
||||
asm("bsfq\t%2,%0" : "=r"(b), "=@ccz"(zf) : "r"(x));
|
||||
ASSERT_EQ(zf, GetFlag(m->flags, FLAGS_ZF));
|
||||
if (!zf) ASSERT_EQ(a, b);
|
||||
|
@ -86,7 +86,7 @@ TEST(bsf32, test) {
|
|||
uint32_t i, w, x, a, b;
|
||||
for (i = 0; i < ARRAYLEN(kNumbers); ++i) {
|
||||
x = kNumbers[i];
|
||||
a = AluBsf(m, 0, 0, x);
|
||||
a = AluBsf(m, 0, x);
|
||||
asm("bsfl\t%2,%0" : "=r"(b), "=@ccz"(zf) : "r"(x));
|
||||
ASSERT_EQ(zf, GetFlag(m->flags, FLAGS_ZF));
|
||||
if (!zf) ASSERT_EQ(a, b);
|
||||
|
@ -98,7 +98,7 @@ TEST(bsf16, test) {
|
|||
uint16_t i, w, x, a, b;
|
||||
for (i = 0; i < ARRAYLEN(kNumbers); ++i) {
|
||||
x = kNumbers[i];
|
||||
a = AluBsf(m, OSZ, 0, x);
|
||||
a = AluBsf(m, OSZ, x);
|
||||
asm("bsfw\t%2,%0" : "=r"(b), "=@ccz"(zf) : "r"(x));
|
||||
ASSERT_EQ(zf, GetFlag(m->flags, FLAGS_ZF));
|
||||
if (!zf) ASSERT_EQ(a, b, "%#lx", x);
|
||||
|
|
|
@ -58,6 +58,105 @@
|
|||
abort(); \
|
||||
}
|
||||
|
||||
int64_t Bsu(int w, int h, uint64_t x, uint64_t y, uint32_t *f) {
|
||||
switch (h & 7) {
|
||||
case BSU_SHR:
|
||||
switch (w) {
|
||||
case 0:
|
||||
return Shr8(x, y, f);
|
||||
case 1:
|
||||
return Shr16(x, y, f);
|
||||
case 2:
|
||||
return Shr32(x, y, f);
|
||||
case 3:
|
||||
return Shr64(x, y, f);
|
||||
default:
|
||||
unreachable;
|
||||
}
|
||||
case BSU_SAL:
|
||||
case BSU_SHL:
|
||||
switch (w) {
|
||||
case 0:
|
||||
return Shl8(x, y, f);
|
||||
case 1:
|
||||
return Shl16(x, y, f);
|
||||
case 2:
|
||||
return Shl32(x, y, f);
|
||||
case 3:
|
||||
return Shl64(x, y, f);
|
||||
default:
|
||||
unreachable;
|
||||
}
|
||||
case BSU_SAR:
|
||||
switch (w) {
|
||||
case 0:
|
||||
return Sar8(x, y, f);
|
||||
case 1:
|
||||
return Sar16(x, y, f);
|
||||
case 2:
|
||||
return Sar32(x, y, f);
|
||||
case 3:
|
||||
return Sar64(x, y, f);
|
||||
default:
|
||||
unreachable;
|
||||
}
|
||||
case BSU_ROL:
|
||||
switch (w) {
|
||||
case 0:
|
||||
return Rol8(x, y, f);
|
||||
case 1:
|
||||
return Rol16(x, y, f);
|
||||
case 2:
|
||||
return Rol32(x, y, f);
|
||||
case 3:
|
||||
return Rol64(x, y, f);
|
||||
default:
|
||||
unreachable;
|
||||
}
|
||||
case BSU_ROR:
|
||||
switch (w) {
|
||||
case 0:
|
||||
return Ror8(x, y, f);
|
||||
case 1:
|
||||
return Ror16(x, y, f);
|
||||
case 2:
|
||||
return Ror32(x, y, f);
|
||||
case 3:
|
||||
return Ror64(x, y, f);
|
||||
default:
|
||||
unreachable;
|
||||
}
|
||||
case BSU_RCR:
|
||||
switch (w) {
|
||||
case 0:
|
||||
return Rcr8(x, y, f);
|
||||
case 1:
|
||||
return Rcr16(x, y, f);
|
||||
case 2:
|
||||
return Rcr32(x, y, f);
|
||||
case 3:
|
||||
return Rcr64(x, y, f);
|
||||
default:
|
||||
unreachable;
|
||||
}
|
||||
case BSU_RCL:
|
||||
switch (w) {
|
||||
case 0:
|
||||
return Rcl8(x, y, f);
|
||||
case 1:
|
||||
return Rcl16(x, y, f);
|
||||
case 2:
|
||||
return Rcl32(x, y, f);
|
||||
case 3:
|
||||
return Rcl64(x, y, f);
|
||||
default:
|
||||
unreachable;
|
||||
}
|
||||
default:
|
||||
unreachable;
|
||||
}
|
||||
}
|
||||
|
||||
int64_t RunGolden(char w, int h, uint64_t x, uint64_t y, uint32_t *f) {
|
||||
switch (h & 7) {
|
||||
case BSU_ROR:
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/testlib/testlib.h"
|
||||
#include "tool/build/lib/dis.h"
|
||||
#include "tool/build/lib/modrm.h"
|
||||
|
||||
char b1[64];
|
||||
char b2[64];
|
||||
|
@ -80,9 +81,144 @@ TEST(DisInst, testPuttingOnTheRiz) {
|
|||
}
|
||||
|
||||
TEST(DisInst, testSibIndexOnly) {
|
||||
uint8_t op[] = {76, 141, 4, 141, 0, 0, 0, 0}; /* lea 0x0(,%rcx,4),%r8 */
|
||||
uint8_t op[] = {76, 141, 4, 141, 0, 0, 0, 0};
|
||||
xed_decoded_inst_zero_set_mode(d->xedd, XED_MACHINE_MODE_LONG_64);
|
||||
ASSERT_EQ(0, xed_instruction_length_decode(d->xedd, op, sizeof(op)));
|
||||
DisInst(b, b1, DisSpec(d->xedd, b2));
|
||||
EXPECT_STREQ("lea 0(,%rcx,4),%r8", b1);
|
||||
}
|
||||
|
||||
TEST(DisInst, testRealMode) {
|
||||
uint8_t op[] = {0x89, 0xe5};
|
||||
xed_decoded_inst_zero_set_mode(d->xedd, XED_MACHINE_MODE_REAL);
|
||||
ASSERT_EQ(0, xed_instruction_length_decode(d->xedd, op, sizeof(op)));
|
||||
DisInst(b, b1, DisSpec(d->xedd, b2));
|
||||
EXPECT_STREQ("mov %sp,%bp", b1);
|
||||
}
|
||||
|
||||
TEST(DisInst, testNop) {
|
||||
uint8_t op[] = {0x66, 0x2e, 0x0f, 0x1f, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00};
|
||||
xed_decoded_inst_zero_set_mode(d->xedd, XED_MACHINE_MODE_LONG_64);
|
||||
ASSERT_EQ(0, xed_instruction_length_decode(d->xedd, op, sizeof(op)));
|
||||
DisInst(b, b1, DisSpec(d->xedd, b2));
|
||||
EXPECT_STREQ("nopw %cs:0(%rax,%rax)", b1);
|
||||
}
|
||||
|
||||
TEST(DisInst, testPush) {
|
||||
uint8_t op[] = {0x41, 0x5c};
|
||||
xed_decoded_inst_zero_set_mode(d->xedd, XED_MACHINE_MODE_LONG_64);
|
||||
ASSERT_EQ(0, xed_instruction_length_decode(d->xedd, op, sizeof(op)));
|
||||
EXPECT_EQ(4, ModrmSrm(d->xedd->op.rde));
|
||||
EXPECT_EQ(1, Rexb(d->xedd->op.rde));
|
||||
DisInst(b, b1, DisSpec(d->xedd, b2));
|
||||
EXPECT_STREQ("pop %r12", b1);
|
||||
}
|
||||
|
||||
TEST(DisInst, testMovb) {
|
||||
uint8_t op[] = {0x8a, 0x1e, 0x0c, 0x32};
|
||||
xed_decoded_inst_zero_set_mode(d->xedd, XED_MACHINE_MODE_LONG_64);
|
||||
ASSERT_EQ(0, xed_instruction_length_decode(d->xedd, op, sizeof(op)));
|
||||
DisInst(b, b1, DisSpec(d->xedd, b2));
|
||||
EXPECT_STREQ("mov (%rsi),%bl", b1);
|
||||
xed_decoded_inst_zero_set_mode(d->xedd, XED_MACHINE_MODE_REAL);
|
||||
ASSERT_EQ(0, xed_instruction_length_decode(d->xedd, op, sizeof(op)));
|
||||
DisInst(b, b1, DisSpec(d->xedd, b2));
|
||||
EXPECT_STREQ("mov 0x320c,%bl", b1);
|
||||
}
|
||||
|
||||
TEST(DisInst, testLes) {
|
||||
uint8_t op[] = {0xc4, 0x3e, 0x16, 0x32};
|
||||
xed_decoded_inst_zero_set_mode(d->xedd, XED_MACHINE_MODE_REAL);
|
||||
ASSERT_EQ(0, xed_instruction_length_decode(d->xedd, op, sizeof(op)));
|
||||
DisInst(b, b1, DisSpec(d->xedd, b2));
|
||||
EXPECT_STREQ("les 0x3216,%di", b1);
|
||||
}
|
||||
|
||||
TEST(DisInst, testStosbLong) {
|
||||
uint8_t op[] = {0xAA};
|
||||
xed_decoded_inst_zero_set_mode(d->xedd, XED_MACHINE_MODE_LONG_64);
|
||||
ASSERT_EQ(0, xed_instruction_length_decode(d->xedd, op, sizeof(op)));
|
||||
DisInst(b, b1, DisSpec(d->xedd, b2));
|
||||
EXPECT_STREQ("stosb %al,(%rdi)", b1);
|
||||
}
|
||||
|
||||
TEST(DisInst, testStosbReal) {
|
||||
uint8_t op[] = {0xAA};
|
||||
xed_decoded_inst_zero_set_mode(d->xedd, XED_MACHINE_MODE_REAL);
|
||||
ASSERT_EQ(0, xed_instruction_length_decode(d->xedd, op, sizeof(op)));
|
||||
DisInst(b, b1, DisSpec(d->xedd, b2));
|
||||
EXPECT_STREQ("stosb %al,(%di)", b1);
|
||||
}
|
||||
|
||||
TEST(DisInst, testStosbLegacy) {
|
||||
uint8_t op[] = {0xAA};
|
||||
xed_decoded_inst_zero_set_mode(d->xedd, XED_MACHINE_MODE_LEGACY_32);
|
||||
ASSERT_EQ(0, xed_instruction_length_decode(d->xedd, op, sizeof(op)));
|
||||
DisInst(b, b1, DisSpec(d->xedd, b2));
|
||||
EXPECT_STREQ("stosb %al,(%edi)", b1);
|
||||
}
|
||||
|
||||
TEST(DisInst, testStosbLongAsz) {
|
||||
uint8_t op[] = {0x67, 0xAA};
|
||||
xed_decoded_inst_zero_set_mode(d->xedd, XED_MACHINE_MODE_LONG_64);
|
||||
ASSERT_EQ(0, xed_instruction_length_decode(d->xedd, op, sizeof(op)));
|
||||
DisInst(b, b1, DisSpec(d->xedd, b2));
|
||||
EXPECT_STREQ("stosb %al,(%edi)", b1);
|
||||
}
|
||||
|
||||
TEST(DisInst, testAddLong) {
|
||||
uint8_t op[] = {0x01, 0xff};
|
||||
xed_decoded_inst_zero_set_mode(d->xedd, XED_MACHINE_MODE_LONG_64);
|
||||
ASSERT_EQ(0, xed_instruction_length_decode(d->xedd, op, sizeof(op)));
|
||||
DisInst(b, b1, DisSpec(d->xedd, b2));
|
||||
EXPECT_STREQ("add %edi,%edi", b1);
|
||||
}
|
||||
|
||||
TEST(DisInst, testAddLegacy) {
|
||||
uint8_t op[] = {0x01, 0xff};
|
||||
xed_decoded_inst_zero_set_mode(d->xedd, XED_MACHINE_MODE_LEGACY_32);
|
||||
ASSERT_EQ(0, xed_instruction_length_decode(d->xedd, op, sizeof(op)));
|
||||
DisInst(b, b1, DisSpec(d->xedd, b2));
|
||||
EXPECT_STREQ("add %edi,%edi", b1);
|
||||
}
|
||||
|
||||
TEST(DisInst, testAddReal) {
|
||||
uint8_t op[] = {0x01, 0xff};
|
||||
xed_decoded_inst_zero_set_mode(d->xedd, XED_MACHINE_MODE_REAL);
|
||||
ASSERT_EQ(0, xed_instruction_length_decode(d->xedd, op, sizeof(op)));
|
||||
DisInst(b, b1, DisSpec(d->xedd, b2));
|
||||
EXPECT_STREQ("add %di,%di", b1);
|
||||
}
|
||||
|
||||
TEST(DisInst, testAddLongOsz) {
|
||||
uint8_t op[] = {0x66, 0x01, 0xff};
|
||||
xed_decoded_inst_zero_set_mode(d->xedd, XED_MACHINE_MODE_LONG_64);
|
||||
ASSERT_EQ(0, xed_instruction_length_decode(d->xedd, op, sizeof(op)));
|
||||
DisInst(b, b1, DisSpec(d->xedd, b2));
|
||||
EXPECT_STREQ("add %di,%di", b1);
|
||||
}
|
||||
|
||||
TEST(DisInst, testAddLegacyOsz) {
|
||||
uint8_t op[] = {0x66, 0x01, 0xff};
|
||||
xed_decoded_inst_zero_set_mode(d->xedd, XED_MACHINE_MODE_LEGACY_32);
|
||||
ASSERT_EQ(0, xed_instruction_length_decode(d->xedd, op, sizeof(op)));
|
||||
DisInst(b, b1, DisSpec(d->xedd, b2));
|
||||
EXPECT_STREQ("add %di,%di", b1);
|
||||
}
|
||||
|
||||
TEST(DisInst, testAddRealOsz) {
|
||||
uint8_t op[] = {0x66, 0x01, 0xff};
|
||||
xed_decoded_inst_zero_set_mode(d->xedd, XED_MACHINE_MODE_REAL);
|
||||
ASSERT_EQ(0, xed_instruction_length_decode(d->xedd, op, sizeof(op)));
|
||||
DisInst(b, b1, DisSpec(d->xedd, b2));
|
||||
EXPECT_STREQ("add %edi,%edi", b1);
|
||||
}
|
||||
|
||||
TEST(DisInst, testFxam) {
|
||||
uint8_t op[] = {0xd9, 0xe5};
|
||||
xed_decoded_inst_zero_set_mode(d->xedd, XED_MACHINE_MODE_LONG_64);
|
||||
ASSERT_EQ(0, xed_instruction_length_decode(d->xedd, op, sizeof(op)));
|
||||
ASSERT_EQ(4, ModrmReg(d->xedd->op.rde));
|
||||
DisInst(b, b1, DisSpec(d->xedd, b2));
|
||||
EXPECT_STREQ("fxam ", b1);
|
||||
}
|
||||
|
|
|
@ -32,8 +32,8 @@
|
|||
|
||||
#define CX 1
|
||||
#define OSZ 00000000040
|
||||
#define REXW 00000004000
|
||||
#define RM(x) (0000000700 & ((x) << 006))
|
||||
#define REXW 00000000100
|
||||
#define RM(x) (0000001600 & ((x) << 007))
|
||||
#define MOD(x) (0060000000 & ((x) << 026))
|
||||
|
||||
jmp_buf sigfpejmp;
|
||||
|
|
|
@ -106,6 +106,7 @@ struct Machine *m;
|
|||
void SetUp(void) {
|
||||
base = 0;
|
||||
m = NewMachine();
|
||||
m->cr3 = MallocPage();
|
||||
realsize = 0x10000;
|
||||
real = tmemalign(PAGESIZE, ROUNDUP(realsize, PAGESIZE));
|
||||
RegisterMemory(m, base, real, realsize);
|
||||
|
@ -115,6 +116,7 @@ void SetUp(void) {
|
|||
|
||||
void TearDown(void) {
|
||||
ResetRam(m);
|
||||
free(m->cr3);
|
||||
tfree(real);
|
||||
free(m);
|
||||
}
|
||||
|
@ -294,5 +296,34 @@ BENCH(machine, benchNop) {
|
|||
}
|
||||
|
||||
TEST(machine, sizeIsReasonable) {
|
||||
ASSERT_LE(sizeof(struct Machine), 65536 * 2);
|
||||
ASSERT_LE(sizeof(struct Machine), 65536 * 3);
|
||||
}
|
||||
|
||||
TEST(x87, fprem1) {
|
||||
// 1 rem -1.5
|
||||
const uint8_t prog[] = {
|
||||
0xd9, 0x05, 0x05, 0x00, 0x00, 0x00, // flds
|
||||
0xd9, 0xe8, // fld1
|
||||
0xd9, 0xf8, // fprem
|
||||
0xf4, // hlt
|
||||
0x00, 0x00, 0xc0, 0xbf, // .float -1.5
|
||||
};
|
||||
memcpy(real, prog, sizeof(prog));
|
||||
ASSERT_EQ(kMachineHalt, ExecuteUntilHalt(m));
|
||||
ASSERT_LDBL_EQ(1, FpuPop(m));
|
||||
}
|
||||
|
||||
TEST(x87, fprem2) {
|
||||
// 12300000000000000. rem .0000000000000123
|
||||
const uint8_t prog[] = {
|
||||
0xdd, 0x05, 0x11, 0x00, 0x00, 0x00, // fldl
|
||||
0xdd, 0x05, 0x03, 0x00, 0x00, 0x00, // fldl
|
||||
0xd9, 0xf8, // fprem
|
||||
0xf4, // hlt
|
||||
0x00, 0x60, 0x5e, 0x75, 0x64, 0xd9, 0x45, 0x43, //
|
||||
0x5b, 0x14, 0xea, 0x9d, 0x77, 0xb2, 0x0b, 0x3d, //
|
||||
};
|
||||
memcpy(real, prog, sizeof(prog));
|
||||
ASSERT_EQ(kMachineHalt, ExecuteUntilHalt(m));
|
||||
ASSERT_LDBL_EQ(1.1766221079117338e-14, FpuPop(m));
|
||||
}
|
||||
|
|
|
@ -88,6 +88,7 @@ TEST(modrm, testPuttingOnTheRiz) {
|
|||
}
|
||||
|
||||
TEST(modrm, testSibIndexOnly) {
|
||||
// lea 0x0(,%rcx,4),%r8
|
||||
// mod = 0b00 (0)
|
||||
// reg = 0b000 (0)
|
||||
// rm = 0b100 (4)
|
||||
|
@ -96,11 +97,16 @@ TEST(modrm, testSibIndexOnly) {
|
|||
// base = 0b101 (5)
|
||||
struct Machine *m = gc(NewMachine());
|
||||
struct XedDecodedInst *xedd = gc(calloc(1, sizeof(struct XedDecodedInst)));
|
||||
uint8_t op[] = {76, 141, 4, 141, 0, 0, 0, 0}; /* lea 0x0(,%rcx,4),%r8 */
|
||||
uint8_t op[] = {0x4c, 0x8d, 0x04, 0x8d, 0, 0, 0, 0};
|
||||
m->xedd = xedd;
|
||||
Write64(m->bp, 0x123);
|
||||
Write64(m->cx, 0x123);
|
||||
xed_decoded_inst_zero_set_mode(xedd, XED_MACHINE_MODE_LONG_64);
|
||||
ASSERT_EQ(0, xed_instruction_length_decode(xedd, op, sizeof(op)));
|
||||
EXPECT_TRUE(Rexw(m->xedd->op.rde));
|
||||
EXPECT_TRUE(Rexr(m->xedd->op.rde));
|
||||
EXPECT_FALSE(Rexb(m->xedd->op.rde));
|
||||
EXPECT_EQ(0b000, ModrmReg(m->xedd->op.rde));
|
||||
EXPECT_EQ(0b100, ModrmRm(m->xedd->op.rde));
|
||||
EXPECT_EQ(0x123 * 4, (uint64_t)ComputeAddress(m, m->xedd->op.rde));
|
||||
}
|
||||
|
|
|
@ -1,39 +0,0 @@
|
|||
/*-*- 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 2020 Justine Alexandra Roberts Tunney │
|
||||
│ │
|
||||
│ This program is free software; you can redistribute it and/or modify │
|
||||
│ it under the terms of the GNU General Public License as published by │
|
||||
│ the Free Software Foundation; version 2 of the License. │
|
||||
│ │
|
||||
│ This program is distributed in the hope that it will be useful, but │
|
||||
│ WITHOUT ANY WARRANTY; without even the implied warranty of │
|
||||
│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU │
|
||||
│ General Public License for more details. │
|
||||
│ │
|
||||
│ You should have received a copy of the GNU General Public License │
|
||||
│ along with this program; if not, write to the Free Software │
|
||||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/testlib/testlib.h"
|
||||
#include "tool/build/lib/x87.h"
|
||||
|
||||
TEST(x87, fprem) {
|
||||
ASSERT_LDBL_EQ(1, fprem(1, -1.5, NULL));
|
||||
ASSERT_LDBL_EQ(1.1766221079117338e-14L,
|
||||
fprem(12300000000000000.L, .0000000000000123L, NULL));
|
||||
}
|
||||
|
||||
TEST(x87, fprem1) {
|
||||
ASSERT_LDBL_EQ(-.5, fprem1(1, -1.5, NULL));
|
||||
ASSERT_LDBL_EQ(-5.337789208826618e-16,
|
||||
fprem1(12300000000000000.L, .0000000000000123L, NULL));
|
||||
}
|
||||
|
||||
TEST(x87, fpremFlags) {
|
||||
uint32_t sw = 0xffff;
|
||||
ASSERT_LDBL_EQ(1, fprem(1, -1.5, &sw));
|
||||
ASSERT_EQ(0b1011100011111111, sw);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue