Skip to content

Commit

Permalink
Add ln2 floating point constant
Browse files Browse the repository at this point in the history
  • Loading branch information
tbodt committed Oct 30, 2018
1 parent c10fac1 commit de81156
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 10 deletions.
1 change: 1 addition & 0 deletions emu/decode.h
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,7 @@ __no_instrument DECODER_RET glue(DECODER_NAME, OP_SIZE)(DECODER_ARGS) {
case 0xd940: TRACE("fchs"); FCHS(); break;
case 0xd941: TRACE("fabs"); FABS(); break;
case 0xd950: TRACE("fld1"); FLDC(one); break;
case 0xd955: TRACE("fldln2"); FLDC(ln2); break;
case 0xd956: TRACE("fldz"); FLDC(zero); break;
case 0xd970: TRACE("fprem"); FPREM(); break;
case 0xd974: TRACE("frndint"); FRNDINT(); break;
Expand Down
7 changes: 1 addition & 6 deletions emu/fpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,7 @@ void fpu_ld(struct cpu_state *cpu, int i) {
}

void fpu_ldc(struct cpu_state *cpu, enum fpu_const c) {
switch (c) {
case fconst_zero:
fpush(f80_from_int(0)); break;
case fconst_one:
fpush(f80_from_int(1)); break;
}
fpush(fpu_consts[c]);
}

void fpu_ild32(struct cpu_state *cpu, int32_t *i) {
Expand Down
10 changes: 9 additions & 1 deletion emu/fpu.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
#ifndef EMU_FPU_H
#define EMU_FPU_H
#include "emu/float80.h"
struct cpu_state;

typedef float float32;
typedef double float64;

enum fpu_const {
fconst_one, fconst_zero,
fconst_one = 0,
fconst_ln2 = 5,
fconst_zero = 6,
};
static float80 fpu_consts[] = {
[fconst_one] = (float80) {.signif = 0x8000000000000000, .signExp = 0x3fff},
[fconst_ln2] = (float80) {.signif = 0xb17217f7d1cf79ac, .signExp = 0x3ffe},
[fconst_zero] = (float80) {.signif = 0x0000000000000000, .signExp = 0x0000},
};

void fpu_pop(struct cpu_state *cpu);
Expand Down
4 changes: 1 addition & 3 deletions emu/interp/fpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,7 @@
#define FLDM(val,z) \
FPUSH(f80_from_float(get(val,z),z))

#define FLDC(what) FPUSH(fconst_##what)
#define fconst_one f80_from_int(1)
#define fconst_zero f80_from_int(0)
#define FLDC(what) FPUSH(fconsts[fconst_##what])

#define FSTM(dst,z) \
set(dst, f80_to_float(ST(0),z),z)
Expand Down

0 comments on commit de81156

Please sign in to comment.