Skip to content

Commit

Permalink
decode: implement fxam
Browse files Browse the repository at this point in the history
There's no interpreter version yet.
  • Loading branch information
zhuowei committed Nov 19, 2018
1 parent 2af50c4 commit 67f7e1f
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 2 deletions.
1 change: 1 addition & 0 deletions emu/decode.h
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,7 @@ __no_instrument DECODER_RET glue(DECODER_NAME, OP_SIZE)(DECODER_ARGS) {
default: switch (insn << 8 | modrm.opcode << 4 | modrm.rm_opcode) {
case 0xd940: TRACE("fchs"); FCHS(); break;
case 0xd941: TRACE("fabs"); FABS(); break;
case 0xd945: TRACE("fxam"); FXAM(); break;
case 0xd950: TRACE("fld1"); FLDC(one); break;
case 0xd951: TRACE("fldl2t"); FLDC(log2t); break;
case 0xd952: TRACE("fldl2e"); FLDC(log2e); break;
Expand Down
7 changes: 5 additions & 2 deletions emu/float80.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ static float80 f80_shift_right(float80 f, int shift) {
// a number is unsupported if the cursed bit (first bit of the significand,
// also known as the integer bit) is incorrect. it must be 0 for denormals and
// 1 for any other type of number.
static bool f80_is_supported(float80 f) {
bool f80_is_supported(float80 f) {
if (f.exp == EXP_DENORMAL)
return f.signif >> 63 == 0;
return f.signif >> 63 == 1;
Expand All @@ -101,9 +101,12 @@ bool f80_isnan(float80 f) {
bool f80_isinf(float80 f) {
return f.exp == EXP_SPECIAL && (f.signif & (-1ul >> 1)) == 0;
}
static bool f80_iszero(float80 f) {
bool f80_iszero(float80 f) {
return f.exp == EXP_DENORMAL && f.signif == 0;
}
bool f80_isdenormal(float80 f) {
return f.exp == EXP_DENORMAL && f.signif != 0;
}

static float80 f80_normalize(float80 f) {
// this function probably can't handle unsupported numbers
Expand Down
3 changes: 3 additions & 0 deletions emu/float80.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ double f80_to_double(float80 f);

bool f80_isnan(float80 f);
bool f80_isinf(float80 f);
bool f80_iszero(float80 f);
bool f80_isdenormal(float80 f);
bool f80_is_supported(float80 f);

float80 f80_neg(float80 f);
float80 f80_abs(float80 f);
Expand Down
24 changes: 24 additions & 0 deletions emu/fpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -245,3 +245,27 @@ void fpu_patan(struct cpu_state *cpu) {
ST(1) = f80_from_double(atan2(f80_to_double(ST(1)), f80_to_double(ST(0))));
fpu_pop(cpu);
}

void fpu_xam(struct cpu_state *cpu) {
float80 f = ST(0);
int outflags = 0;
if (!f80_is_supported(f)) {
outflags = 0b000;
} else if (f80_isnan(f)) {
outflags = 0b001;
} else if (f80_isinf(f)) {
outflags = 0b011;
} else if (f80_iszero(f)) {
outflags = 0b100;
} else if (f80_isdenormal(f)) {
outflags = 0b110;
} else {
// normal.
// todo: empty
outflags = 0b010;
}
cpu->c1 = f.sign;
cpu->c0 = outflags & 1;
cpu->c2 = (outflags >> 1) & 1;
cpu->c3 = (outflags >> 2) & 1;
}
1 change: 1 addition & 0 deletions emu/fpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,5 +93,6 @@ void fpu_divrm64(struct cpu_state *cpu, double *f);
void fpu_stcw16(struct cpu_state *cpu, uint16_t *i);
void fpu_ldcw16(struct cpu_state *cpu, uint16_t *i);
void fpu_patan(struct cpu_state *cpu);
void fpu_xam(struct cpu_state *cpu);

#endif
2 changes: 2 additions & 0 deletions emu/interp/fpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,3 +128,5 @@
#define FPATAN() \
ST(1) = f80_from_double(atan2(f80_to_double(ST(1)), f80_to_double(ST(0)))); \
FPOP

#define FXAM() UNDEFINED
1 change: 1 addition & 0 deletions jit/gen.c
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,7 @@ void helper_rdtsc(struct cpu_state *cpu);
#define FIDIVR(val,z) h_read(fpu_idivr, z)
#define FDIVRM(val,z) h_read(fpu_divrm, z)
#define FPATAN() h(fpu_patan)
#define FXAM() h(fpu_xam)

#define DECODER_RET int
#define DECODER_NAME gen_step
Expand Down

0 comments on commit 67f7e1f

Please sign in to comment.