mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-06-27 14:58:30 +00:00
Perform some code cleanup
This commit is contained in:
parent
3e17c7b20f
commit
19d0c15e03
41 changed files with 321 additions and 459 deletions
303
third_party/xed/x86ild.greg.c
vendored
303
third_party/xed/x86ild.greg.c
vendored
|
@ -111,7 +111,6 @@ extern const uint8_t xed_disp_bits_2d[XED_ILD_MAP2][256] hidden;
|
|||
|
||||
static const struct XedDenseMagnums {
|
||||
unsigned vex_prefix_recoding[4];
|
||||
xed_bits_t eamode[2][3];
|
||||
xed_bits_t BRDISPz_BRDISP_WIDTH[4];
|
||||
xed_bits_t MEMDISPv_DISP_WIDTH[4];
|
||||
xed_bits_t SIMMz_IMM_WIDTH[4];
|
||||
|
@ -136,186 +135,177 @@ static const struct XedDenseMagnums {
|
|||
.UIMMv_IMM_WIDTH = {0x00, 0x10, 0x20, 0x40},
|
||||
.ASZ_NONTERM_EASZ =
|
||||
{
|
||||
[0][0] = 0x1,
|
||||
[1][0] = 0x2,
|
||||
[0][1] = 0x2,
|
||||
[1][1] = 0x1,
|
||||
[0][2] = 0x3,
|
||||
[1][2] = 0x2,
|
||||
[0][0] = 1,
|
||||
[1][0] = 2,
|
||||
[0][1] = 2,
|
||||
[1][1] = 1,
|
||||
[0][2] = 3,
|
||||
[1][2] = 2,
|
||||
},
|
||||
.OSZ_NONTERM_CR_WIDTH_EOSZ =
|
||||
{
|
||||
[0][0][0] = 0x2,
|
||||
[1][0][0] = 0x2,
|
||||
[0][1][0] = 0x2,
|
||||
[1][1][0] = 0x2,
|
||||
[0][1][1] = 0x2,
|
||||
[1][1][1] = 0x2,
|
||||
[0][0][1] = 0x2,
|
||||
[1][0][1] = 0x2,
|
||||
[0][1][2] = 0x3,
|
||||
[0][0][2] = 0x3,
|
||||
[1][1][2] = 0x3,
|
||||
[1][0][2] = 0x3,
|
||||
[0][0][0] = 2,
|
||||
[1][0][0] = 2,
|
||||
[0][1][0] = 2,
|
||||
[1][1][0] = 2,
|
||||
[0][1][1] = 2,
|
||||
[1][1][1] = 2,
|
||||
[0][0][1] = 2,
|
||||
[1][0][1] = 2,
|
||||
[0][1][2] = 3,
|
||||
[0][0][2] = 3,
|
||||
[1][1][2] = 3,
|
||||
[1][0][2] = 3,
|
||||
},
|
||||
.OSZ_NONTERM_DF64_EOSZ =
|
||||
{
|
||||
[0][0][0] = 0x1,
|
||||
[1][0][0] = 0x1,
|
||||
[0][1][0] = 0x2,
|
||||
[1][1][0] = 0x2,
|
||||
[0][1][1] = 0x1,
|
||||
[1][1][1] = 0x1,
|
||||
[0][0][1] = 0x2,
|
||||
[1][0][1] = 0x2,
|
||||
[0][1][2] = 0x1,
|
||||
[0][0][2] = 0x3,
|
||||
[1][1][2] = 0x3,
|
||||
[1][0][2] = 0x3,
|
||||
[0][0][0] = 1,
|
||||
[1][0][0] = 1,
|
||||
[0][1][0] = 2,
|
||||
[1][1][0] = 2,
|
||||
[0][1][1] = 1,
|
||||
[1][1][1] = 1,
|
||||
[0][0][1] = 2,
|
||||
[1][0][1] = 2,
|
||||
[0][1][2] = 1,
|
||||
[0][0][2] = 3,
|
||||
[1][1][2] = 3,
|
||||
[1][0][2] = 3,
|
||||
},
|
||||
.OSZ_NONTERM_DF64_FORCE64_EOSZ =
|
||||
{
|
||||
[0][0][0] = 0x1,
|
||||
[1][0][0] = 0x1,
|
||||
[0][1][0] = 0x2,
|
||||
[1][1][0] = 0x2,
|
||||
[0][1][1] = 0x1,
|
||||
[1][1][1] = 0x1,
|
||||
[0][0][1] = 0x2,
|
||||
[1][0][1] = 0x2,
|
||||
[0][1][2] = 0x3,
|
||||
[0][0][2] = 0x3,
|
||||
[1][1][2] = 0x3,
|
||||
[1][0][2] = 0x3,
|
||||
[0][0][0] = 1,
|
||||
[1][0][0] = 1,
|
||||
[0][1][0] = 2,
|
||||
[1][1][0] = 2,
|
||||
[0][1][1] = 1,
|
||||
[1][1][1] = 1,
|
||||
[0][0][1] = 2,
|
||||
[1][0][1] = 2,
|
||||
[0][1][2] = 3,
|
||||
[0][0][2] = 3,
|
||||
[1][1][2] = 3,
|
||||
[1][0][2] = 3,
|
||||
},
|
||||
.OSZ_NONTERM_DF64_IMMUNE66_LOOP64_EOSZ =
|
||||
{
|
||||
[0][0][0] = 0x1,
|
||||
[1][0][0] = 0x1,
|
||||
[0][1][0] = 0x2,
|
||||
[1][1][0] = 0x2,
|
||||
[0][1][1] = 0x1,
|
||||
[1][1][1] = 0x1,
|
||||
[0][0][1] = 0x2,
|
||||
[1][0][1] = 0x2,
|
||||
[0][1][2] = 0x3,
|
||||
[0][0][2] = 0x3,
|
||||
[1][1][2] = 0x3,
|
||||
[1][0][2] = 0x3,
|
||||
[0][0][0] = 1,
|
||||
[1][0][0] = 1,
|
||||
[0][1][0] = 2,
|
||||
[1][1][0] = 2,
|
||||
[0][1][1] = 1,
|
||||
[1][1][1] = 1,
|
||||
[0][0][1] = 2,
|
||||
[1][0][1] = 2,
|
||||
[0][1][2] = 3,
|
||||
[0][0][2] = 3,
|
||||
[1][1][2] = 3,
|
||||
[1][0][2] = 3,
|
||||
},
|
||||
.OSZ_NONTERM_EOSZ =
|
||||
{
|
||||
[0][0][0] = 0x1,
|
||||
[1][0][0] = 0x1,
|
||||
[0][1][0] = 0x2,
|
||||
[1][1][0] = 0x2,
|
||||
[0][1][1] = 0x1,
|
||||
[1][1][1] = 0x1,
|
||||
[0][0][1] = 0x2,
|
||||
[1][0][1] = 0x2,
|
||||
[0][1][2] = 0x1,
|
||||
[0][0][2] = 0x2,
|
||||
[1][1][2] = 0x3,
|
||||
[1][0][2] = 0x3,
|
||||
[0][0][0] = 1,
|
||||
[1][0][0] = 1,
|
||||
[0][1][0] = 2,
|
||||
[1][1][0] = 2,
|
||||
[0][1][1] = 1,
|
||||
[1][1][1] = 1,
|
||||
[0][0][1] = 2,
|
||||
[1][0][1] = 2,
|
||||
[0][1][2] = 1,
|
||||
[0][0][2] = 2,
|
||||
[1][1][2] = 3,
|
||||
[1][0][2] = 3,
|
||||
},
|
||||
.OSZ_NONTERM_FORCE64_EOSZ =
|
||||
{
|
||||
[0][0][0] = 0x1,
|
||||
[1][0][0] = 0x1,
|
||||
[0][1][0] = 0x2,
|
||||
[1][1][0] = 0x2,
|
||||
[0][1][1] = 0x1,
|
||||
[1][1][1] = 0x1,
|
||||
[0][0][1] = 0x2,
|
||||
[1][0][1] = 0x2,
|
||||
[0][1][2] = 0x3,
|
||||
[0][0][2] = 0x3,
|
||||
[1][1][2] = 0x3,
|
||||
[1][0][2] = 0x3,
|
||||
[0][0][0] = 1,
|
||||
[1][0][0] = 1,
|
||||
[0][1][0] = 2,
|
||||
[1][1][0] = 2,
|
||||
[0][1][1] = 1,
|
||||
[1][1][1] = 1,
|
||||
[0][0][1] = 2,
|
||||
[1][0][1] = 2,
|
||||
[0][1][2] = 3,
|
||||
[0][0][2] = 3,
|
||||
[1][1][2] = 3,
|
||||
[1][0][2] = 3,
|
||||
},
|
||||
.OSZ_NONTERM_IGNORE66_EOSZ =
|
||||
{
|
||||
[0][0][0] = 0x1,
|
||||
[1][0][0] = 0x1,
|
||||
[0][1][0] = 0x1,
|
||||
[1][1][0] = 0x1,
|
||||
[0][1][1] = 0x2,
|
||||
[1][1][1] = 0x2,
|
||||
[0][0][1] = 0x2,
|
||||
[1][0][1] = 0x2,
|
||||
[0][1][2] = 0x2,
|
||||
[0][0][2] = 0x2,
|
||||
[1][1][2] = 0x3,
|
||||
[1][0][2] = 0x3,
|
||||
[0][0][0] = 1,
|
||||
[1][0][0] = 1,
|
||||
[0][1][0] = 1,
|
||||
[1][1][0] = 1,
|
||||
[0][1][1] = 2,
|
||||
[1][1][1] = 2,
|
||||
[0][0][1] = 2,
|
||||
[1][0][1] = 2,
|
||||
[0][1][2] = 2,
|
||||
[0][0][2] = 2,
|
||||
[1][1][2] = 3,
|
||||
[1][0][2] = 3,
|
||||
},
|
||||
.OSZ_NONTERM_IMMUNE66_EOSZ =
|
||||
{
|
||||
[0][0][0] = 0x2,
|
||||
[1][0][0] = 0x2,
|
||||
[0][1][0] = 0x2,
|
||||
[1][1][0] = 0x2,
|
||||
[0][1][1] = 0x2,
|
||||
[1][1][1] = 0x2,
|
||||
[0][0][1] = 0x2,
|
||||
[1][0][1] = 0x2,
|
||||
[0][1][2] = 0x2,
|
||||
[0][0][2] = 0x2,
|
||||
[1][1][2] = 0x3,
|
||||
[1][0][2] = 0x3,
|
||||
[0][0][0] = 2,
|
||||
[1][0][0] = 2,
|
||||
[0][1][0] = 2,
|
||||
[1][1][0] = 2,
|
||||
[0][1][1] = 2,
|
||||
[1][1][1] = 2,
|
||||
[0][0][1] = 2,
|
||||
[1][0][1] = 2,
|
||||
[0][1][2] = 2,
|
||||
[0][0][2] = 2,
|
||||
[1][1][2] = 3,
|
||||
[1][0][2] = 3,
|
||||
},
|
||||
.OSZ_NONTERM_IMMUNE_REXW_EOSZ =
|
||||
{
|
||||
[0][0][0] = 0x1,
|
||||
[1][0][0] = 0x1,
|
||||
[0][1][0] = 0x2,
|
||||
[1][1][0] = 0x2,
|
||||
[0][1][1] = 0x1,
|
||||
[1][1][1] = 0x1,
|
||||
[0][0][1] = 0x2,
|
||||
[1][0][1] = 0x2,
|
||||
[0][1][2] = 0x1,
|
||||
[0][0][2] = 0x2,
|
||||
[1][1][2] = 0x2,
|
||||
[1][0][2] = 0x2,
|
||||
[0][0][0] = 1,
|
||||
[1][0][0] = 1,
|
||||
[0][1][0] = 2,
|
||||
[1][1][0] = 2,
|
||||
[0][1][1] = 1,
|
||||
[1][1][1] = 1,
|
||||
[0][0][1] = 2,
|
||||
[1][0][1] = 2,
|
||||
[0][1][2] = 1,
|
||||
[0][0][2] = 2,
|
||||
[1][1][2] = 2,
|
||||
[1][0][2] = 2,
|
||||
},
|
||||
.OSZ_NONTERM_REFINING66_CR_WIDTH_EOSZ =
|
||||
{
|
||||
[0][0][0] = 0x2,
|
||||
[1][0][0] = 0x2,
|
||||
[0][1][0] = 0x2,
|
||||
[1][1][0] = 0x2,
|
||||
[0][1][1] = 0x2,
|
||||
[1][1][1] = 0x2,
|
||||
[0][0][1] = 0x2,
|
||||
[1][0][1] = 0x2,
|
||||
[0][1][2] = 0x3,
|
||||
[0][0][2] = 0x3,
|
||||
[1][1][2] = 0x3,
|
||||
[1][0][2] = 0x3,
|
||||
[0][0][0] = 2,
|
||||
[1][0][0] = 2,
|
||||
[0][1][0] = 2,
|
||||
[1][1][0] = 2,
|
||||
[0][1][1] = 2,
|
||||
[1][1][1] = 2,
|
||||
[0][0][1] = 2,
|
||||
[1][0][1] = 2,
|
||||
[0][1][2] = 3,
|
||||
[0][0][2] = 3,
|
||||
[1][1][2] = 3,
|
||||
[1][0][2] = 3,
|
||||
},
|
||||
.OSZ_NONTERM_REFINING66_EOSZ =
|
||||
{
|
||||
[0][0][0] = 0x1,
|
||||
[1][0][0] = 0x1,
|
||||
[0][1][0] = 0x1,
|
||||
[1][1][0] = 0x1,
|
||||
[0][1][1] = 0x2,
|
||||
[1][1][1] = 0x2,
|
||||
[0][0][1] = 0x2,
|
||||
[1][0][1] = 0x2,
|
||||
[0][1][2] = 0x2,
|
||||
[0][0][2] = 0x2,
|
||||
[1][1][2] = 0x3,
|
||||
[1][0][2] = 0x3,
|
||||
},
|
||||
.eamode =
|
||||
{
|
||||
[0][XED_MODE_REAL] = XED_MODE_REAL,
|
||||
[0][XED_MODE_LEGACY] = XED_MODE_LEGACY,
|
||||
[0][XED_MODE_LONG] = XED_MODE_LONG,
|
||||
[1][XED_MODE_REAL] = XED_MODE_LEGACY,
|
||||
[1][XED_MODE_LEGACY] = XED_MODE_REAL,
|
||||
[1][XED_MODE_LONG] = XED_MODE_LEGACY,
|
||||
[0][0][0] = 1,
|
||||
[1][0][0] = 1,
|
||||
[0][1][0] = 1,
|
||||
[1][1][0] = 1,
|
||||
[0][1][1] = 2,
|
||||
[1][1][1] = 2,
|
||||
[0][0][1] = 2,
|
||||
[1][0][1] = 2,
|
||||
[0][1][2] = 2,
|
||||
[0][0][2] = 2,
|
||||
[1][1][2] = 3,
|
||||
[1][0][2] = 3,
|
||||
},
|
||||
};
|
||||
|
||||
|
@ -633,7 +623,6 @@ privileged static void xed_get_next_as_opcode(struct XedDecodedInst *d) {
|
|||
b = d->bytes[length];
|
||||
d->op.opcode = b;
|
||||
d->length++;
|
||||
/* d->op.srm = xed_modrm_rm(b); */
|
||||
} else {
|
||||
xed_too_short(d);
|
||||
}
|
||||
|
@ -722,7 +711,6 @@ privileged static void xed_opcode_scanner(struct XedDecodedInst *d) {
|
|||
return;
|
||||
}
|
||||
}
|
||||
/* d->op.srm = xed_modrm_rm(d->op.opcode); */
|
||||
}
|
||||
|
||||
privileged static bool xed_is_bound_instruction(struct XedDecodedInst *d) {
|
||||
|
@ -974,7 +962,7 @@ privileged static void xed_modrm_scanner(struct XedDecodedInst *d) {
|
|||
if (has_modrm != XED_ILD_HASMODRM_IGNORE_MOD) {
|
||||
asz = d->op.asz;
|
||||
mode = d->op.mode;
|
||||
eamode = kXed.eamode[asz][mode];
|
||||
eamode = kXedEamode[asz][mode];
|
||||
d->op.disp_width =
|
||||
xed_bytes2bits(xed_has_disp_regular[eamode][mod][rm]);
|
||||
d->op.has_sib = xed_has_sib_table[eamode][mod][rm];
|
||||
|
@ -1123,18 +1111,6 @@ privileged static void xed_decode_instruction_length(
|
|||
}
|
||||
}
|
||||
|
||||
privileged static void xed_encode_rde(struct XedDecodedInst *x) {
|
||||
const uint8_t kWordLog2[2][2][2] = {{{2, 3}, {1, 3}}, {{0, 0}, {0, 0}}};
|
||||
uint32_t osz = x->op.osz ^ x->op.realmode;
|
||||
x->op.rde = kWordLog2[~x->op.opcode & 1][osz][x->op.rexw] << 28 |
|
||||
x->op.mode << 26 | kXed.eamode[x->op.asz][x->op.mode] << 24 |
|
||||
x->op.rep << 30 | x->op.mod << 22 | x->op.asz << 17 |
|
||||
x->op.seg_ovd << 18 | x->op.rexw << 6 | osz << 5 |
|
||||
(x->op.rex << 4 | x->op.rexb << 3 | x->op.srm) << 12 |
|
||||
(x->op.rex << 4 | x->op.rexb << 3 | x->op.rm) << 7 |
|
||||
(x->op.rex << 4 | x->op.rexr << 3 | x->op.reg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears instruction decoder state.
|
||||
*/
|
||||
|
@ -1160,7 +1136,6 @@ privileged enum XedError xed_instruction_length_decode(
|
|||
__builtin_memcpy(xedd->bytes, itext, MIN(15, bytes));
|
||||
xedd->op.max_bytes = MIN(15, bytes);
|
||||
xed_decode_instruction_length(xedd);
|
||||
xed_encode_rde(xedd);
|
||||
if (!xedd->op.out_of_bytes) {
|
||||
if (xedd->op.map != XED_ILD_MAP_INVALID) {
|
||||
return xedd->op.error;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue