x86: lindent arch/i386/math-emu
lindent these files: errors lines of code errors/KLOC arch/x86/math-emu/ 2236 9424 237.2 arch/x86/math-emu/ 128 8706 14.7 no other changes. No code changed: text data bss dec hex filename5589802
612739 3833856 10036397 9924ad vmlinux.before5589802
612739 3833856 10036397 9924ad vmlinux.after the intent of this patch is to ease the automated tracking of kernel code quality - it's just much easier for us to maintain it if every file in arch/x86 is supposed to be clean. NOTE: it is a known problem of lindent that it causes some style damage of its own, but it's a safe tool (well, except for the gcc array range initializers extension), so we did the bulk of the changes via lindent, and did the manual fixups in a followup patch. the resulting math-emu code has been tested by Thomas Gleixner on a real 386 DX CPU as well, and it works fine. Signed-off-by: Ingo Molnar <mingo@elte.hu> Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
This commit is contained in:
Родитель
a4ec1effce
Коммит
3d0d14f983
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -9,7 +9,6 @@
|
|||
#ifndef _EXCEPTION_H_
|
||||
#define _EXCEPTION_H_
|
||||
|
||||
|
||||
#ifdef __ASSEMBLY__
|
||||
#define Const_(x) $##x
|
||||
#else
|
||||
|
@ -20,8 +19,8 @@
|
|||
#include "fpu_emu.h"
|
||||
#endif /* SW_C1 */
|
||||
|
||||
#define FPU_BUSY Const_(0x8000) /* FPU busy bit (8087 compatibility) */
|
||||
#define EX_ErrorSummary Const_(0x0080) /* Error summary status */
|
||||
#define FPU_BUSY Const_(0x8000) /* FPU busy bit (8087 compatibility) */
|
||||
#define EX_ErrorSummary Const_(0x0080) /* Error summary status */
|
||||
/* Special exceptions: */
|
||||
#define EX_INTERNAL Const_(0x8000) /* Internal error in wm-FPU-emu */
|
||||
#define EX_StackOver Const_(0x0041|SW_C1) /* stack overflow */
|
||||
|
@ -34,11 +33,9 @@
|
|||
#define EX_Denormal Const_(0x0002) /* denormalized operand */
|
||||
#define EX_Invalid Const_(0x0001) /* invalid operation */
|
||||
|
||||
|
||||
#define PRECISION_LOST_UP Const_((EX_Precision | SW_C1))
|
||||
#define PRECISION_LOST_DOWN Const_(EX_Precision)
|
||||
|
||||
|
||||
#ifndef __ASSEMBLY__
|
||||
|
||||
#ifdef DEBUG
|
||||
|
@ -48,6 +45,6 @@
|
|||
#define EXCEPTION(x) FPU_exception(x)
|
||||
#endif
|
||||
|
||||
#endif /* __ASSEMBLY__ */
|
||||
#endif /* __ASSEMBLY__ */
|
||||
|
||||
#endif /* _EXCEPTION_H_ */
|
||||
|
|
|
@ -15,160 +15,138 @@
|
|||
#include "control_w.h"
|
||||
#include "status_w.h"
|
||||
|
||||
|
||||
void fadd__(void)
|
||||
{
|
||||
/* fadd st,st(i) */
|
||||
int i = FPU_rm;
|
||||
clear_C1();
|
||||
FPU_add(&st(i), FPU_gettagi(i), 0, control_word);
|
||||
/* fadd st,st(i) */
|
||||
int i = FPU_rm;
|
||||
clear_C1();
|
||||
FPU_add(&st(i), FPU_gettagi(i), 0, control_word);
|
||||
}
|
||||
|
||||
|
||||
void fmul__(void)
|
||||
{
|
||||
/* fmul st,st(i) */
|
||||
int i = FPU_rm;
|
||||
clear_C1();
|
||||
FPU_mul(&st(i), FPU_gettagi(i), 0, control_word);
|
||||
/* fmul st,st(i) */
|
||||
int i = FPU_rm;
|
||||
clear_C1();
|
||||
FPU_mul(&st(i), FPU_gettagi(i), 0, control_word);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void fsub__(void)
|
||||
{
|
||||
/* fsub st,st(i) */
|
||||
clear_C1();
|
||||
FPU_sub(0, FPU_rm, control_word);
|
||||
/* fsub st,st(i) */
|
||||
clear_C1();
|
||||
FPU_sub(0, FPU_rm, control_word);
|
||||
}
|
||||
|
||||
|
||||
void fsubr_(void)
|
||||
{
|
||||
/* fsubr st,st(i) */
|
||||
clear_C1();
|
||||
FPU_sub(REV, FPU_rm, control_word);
|
||||
/* fsubr st,st(i) */
|
||||
clear_C1();
|
||||
FPU_sub(REV, FPU_rm, control_word);
|
||||
}
|
||||
|
||||
|
||||
void fdiv__(void)
|
||||
{
|
||||
/* fdiv st,st(i) */
|
||||
clear_C1();
|
||||
FPU_div(0, FPU_rm, control_word);
|
||||
/* fdiv st,st(i) */
|
||||
clear_C1();
|
||||
FPU_div(0, FPU_rm, control_word);
|
||||
}
|
||||
|
||||
|
||||
void fdivr_(void)
|
||||
{
|
||||
/* fdivr st,st(i) */
|
||||
clear_C1();
|
||||
FPU_div(REV, FPU_rm, control_word);
|
||||
/* fdivr st,st(i) */
|
||||
clear_C1();
|
||||
FPU_div(REV, FPU_rm, control_word);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void fadd_i(void)
|
||||
{
|
||||
/* fadd st(i),st */
|
||||
int i = FPU_rm;
|
||||
clear_C1();
|
||||
FPU_add(&st(i), FPU_gettagi(i), i, control_word);
|
||||
/* fadd st(i),st */
|
||||
int i = FPU_rm;
|
||||
clear_C1();
|
||||
FPU_add(&st(i), FPU_gettagi(i), i, control_word);
|
||||
}
|
||||
|
||||
|
||||
void fmul_i(void)
|
||||
{
|
||||
/* fmul st(i),st */
|
||||
clear_C1();
|
||||
FPU_mul(&st(0), FPU_gettag0(), FPU_rm, control_word);
|
||||
/* fmul st(i),st */
|
||||
clear_C1();
|
||||
FPU_mul(&st(0), FPU_gettag0(), FPU_rm, control_word);
|
||||
}
|
||||
|
||||
|
||||
void fsubri(void)
|
||||
{
|
||||
/* fsubr st(i),st */
|
||||
clear_C1();
|
||||
FPU_sub(DEST_RM, FPU_rm, control_word);
|
||||
/* fsubr st(i),st */
|
||||
clear_C1();
|
||||
FPU_sub(DEST_RM, FPU_rm, control_word);
|
||||
}
|
||||
|
||||
|
||||
void fsub_i(void)
|
||||
{
|
||||
/* fsub st(i),st */
|
||||
clear_C1();
|
||||
FPU_sub(REV|DEST_RM, FPU_rm, control_word);
|
||||
/* fsub st(i),st */
|
||||
clear_C1();
|
||||
FPU_sub(REV | DEST_RM, FPU_rm, control_word);
|
||||
}
|
||||
|
||||
|
||||
void fdivri(void)
|
||||
{
|
||||
/* fdivr st(i),st */
|
||||
clear_C1();
|
||||
FPU_div(DEST_RM, FPU_rm, control_word);
|
||||
/* fdivr st(i),st */
|
||||
clear_C1();
|
||||
FPU_div(DEST_RM, FPU_rm, control_word);
|
||||
}
|
||||
|
||||
|
||||
void fdiv_i(void)
|
||||
{
|
||||
/* fdiv st(i),st */
|
||||
clear_C1();
|
||||
FPU_div(REV|DEST_RM, FPU_rm, control_word);
|
||||
/* fdiv st(i),st */
|
||||
clear_C1();
|
||||
FPU_div(REV | DEST_RM, FPU_rm, control_word);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void faddp_(void)
|
||||
{
|
||||
/* faddp st(i),st */
|
||||
int i = FPU_rm;
|
||||
clear_C1();
|
||||
if ( FPU_add(&st(i), FPU_gettagi(i), i, control_word) >= 0 )
|
||||
FPU_pop();
|
||||
/* faddp st(i),st */
|
||||
int i = FPU_rm;
|
||||
clear_C1();
|
||||
if (FPU_add(&st(i), FPU_gettagi(i), i, control_word) >= 0)
|
||||
FPU_pop();
|
||||
}
|
||||
|
||||
|
||||
void fmulp_(void)
|
||||
{
|
||||
/* fmulp st(i),st */
|
||||
clear_C1();
|
||||
if ( FPU_mul(&st(0), FPU_gettag0(), FPU_rm, control_word) >= 0 )
|
||||
FPU_pop();
|
||||
/* fmulp st(i),st */
|
||||
clear_C1();
|
||||
if (FPU_mul(&st(0), FPU_gettag0(), FPU_rm, control_word) >= 0)
|
||||
FPU_pop();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void fsubrp(void)
|
||||
{
|
||||
/* fsubrp st(i),st */
|
||||
clear_C1();
|
||||
if ( FPU_sub(DEST_RM, FPU_rm, control_word) >= 0 )
|
||||
FPU_pop();
|
||||
/* fsubrp st(i),st */
|
||||
clear_C1();
|
||||
if (FPU_sub(DEST_RM, FPU_rm, control_word) >= 0)
|
||||
FPU_pop();
|
||||
}
|
||||
|
||||
|
||||
void fsubp_(void)
|
||||
{
|
||||
/* fsubp st(i),st */
|
||||
clear_C1();
|
||||
if ( FPU_sub(REV|DEST_RM, FPU_rm, control_word) >= 0 )
|
||||
FPU_pop();
|
||||
/* fsubp st(i),st */
|
||||
clear_C1();
|
||||
if (FPU_sub(REV | DEST_RM, FPU_rm, control_word) >= 0)
|
||||
FPU_pop();
|
||||
}
|
||||
|
||||
|
||||
void fdivrp(void)
|
||||
{
|
||||
/* fdivrp st(i),st */
|
||||
clear_C1();
|
||||
if ( FPU_div(DEST_RM, FPU_rm, control_word) >= 0 )
|
||||
FPU_pop();
|
||||
/* fdivrp st(i),st */
|
||||
clear_C1();
|
||||
if (FPU_div(DEST_RM, FPU_rm, control_word) >= 0)
|
||||
FPU_pop();
|
||||
}
|
||||
|
||||
|
||||
void fdivp_(void)
|
||||
{
|
||||
/* fdivp st(i),st */
|
||||
clear_C1();
|
||||
if ( FPU_div(REV|DEST_RM, FPU_rm, control_word) >= 0 )
|
||||
FPU_pop();
|
||||
/* fdivp st(i),st */
|
||||
clear_C1();
|
||||
if (FPU_div(REV | DEST_RM, FPU_rm, control_word) >= 0)
|
||||
FPU_pop();
|
||||
}
|
||||
|
|
|
@ -14,7 +14,6 @@
|
|||
|
||||
#define EXCEPTION FPU_exception
|
||||
|
||||
|
||||
#define PARAM1 8(%ebp)
|
||||
#define PARAM2 12(%ebp)
|
||||
#define PARAM3 16(%ebp)
|
||||
|
|
|
@ -16,34 +16,34 @@
|
|||
#include "status_w.h"
|
||||
#include "control_w.h"
|
||||
|
||||
|
||||
static void fnop(void)
|
||||
{
|
||||
}
|
||||
|
||||
static void fclex(void)
|
||||
{
|
||||
partial_status &= ~(SW_Backward|SW_Summary|SW_Stack_Fault|SW_Precision|
|
||||
SW_Underflow|SW_Overflow|SW_Zero_Div|SW_Denorm_Op|
|
||||
SW_Invalid);
|
||||
no_ip_update = 1;
|
||||
partial_status &=
|
||||
~(SW_Backward | SW_Summary | SW_Stack_Fault | SW_Precision |
|
||||
SW_Underflow | SW_Overflow | SW_Zero_Div | SW_Denorm_Op |
|
||||
SW_Invalid);
|
||||
no_ip_update = 1;
|
||||
}
|
||||
|
||||
/* Needs to be externally visible */
|
||||
void finit(void)
|
||||
{
|
||||
control_word = 0x037f;
|
||||
partial_status = 0;
|
||||
top = 0; /* We don't keep top in the status word internally. */
|
||||
fpu_tag_word = 0xffff;
|
||||
/* The behaviour is different from that detailed in
|
||||
Section 15.1.6 of the Intel manual */
|
||||
operand_address.offset = 0;
|
||||
operand_address.selector = 0;
|
||||
instruction_address.offset = 0;
|
||||
instruction_address.selector = 0;
|
||||
instruction_address.opcode = 0;
|
||||
no_ip_update = 1;
|
||||
control_word = 0x037f;
|
||||
partial_status = 0;
|
||||
top = 0; /* We don't keep top in the status word internally. */
|
||||
fpu_tag_word = 0xffff;
|
||||
/* The behaviour is different from that detailed in
|
||||
Section 15.1.6 of the Intel manual */
|
||||
operand_address.offset = 0;
|
||||
operand_address.selector = 0;
|
||||
instruction_address.offset = 0;
|
||||
instruction_address.selector = 0;
|
||||
instruction_address.opcode = 0;
|
||||
no_ip_update = 1;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -54,151 +54,134 @@ void finit(void)
|
|||
#define fsetpm fnop
|
||||
|
||||
static FUNC const finit_table[] = {
|
||||
feni, fdisi, fclex, finit,
|
||||
fsetpm, FPU_illegal, FPU_illegal, FPU_illegal
|
||||
feni, fdisi, fclex, finit,
|
||||
fsetpm, FPU_illegal, FPU_illegal, FPU_illegal
|
||||
};
|
||||
|
||||
void finit_(void)
|
||||
{
|
||||
(finit_table[FPU_rm])();
|
||||
(finit_table[FPU_rm]) ();
|
||||
}
|
||||
|
||||
|
||||
static void fstsw_ax(void)
|
||||
{
|
||||
*(short *) &FPU_EAX = status_word();
|
||||
no_ip_update = 1;
|
||||
*(short *)&FPU_EAX = status_word();
|
||||
no_ip_update = 1;
|
||||
}
|
||||
|
||||
static FUNC const fstsw_table[] = {
|
||||
fstsw_ax, FPU_illegal, FPU_illegal, FPU_illegal,
|
||||
FPU_illegal, FPU_illegal, FPU_illegal, FPU_illegal
|
||||
fstsw_ax, FPU_illegal, FPU_illegal, FPU_illegal,
|
||||
FPU_illegal, FPU_illegal, FPU_illegal, FPU_illegal
|
||||
};
|
||||
|
||||
void fstsw_(void)
|
||||
{
|
||||
(fstsw_table[FPU_rm])();
|
||||
(fstsw_table[FPU_rm]) ();
|
||||
}
|
||||
|
||||
|
||||
static FUNC const fp_nop_table[] = {
|
||||
fnop, FPU_illegal, FPU_illegal, FPU_illegal,
|
||||
FPU_illegal, FPU_illegal, FPU_illegal, FPU_illegal
|
||||
fnop, FPU_illegal, FPU_illegal, FPU_illegal,
|
||||
FPU_illegal, FPU_illegal, FPU_illegal, FPU_illegal
|
||||
};
|
||||
|
||||
void fp_nop(void)
|
||||
{
|
||||
(fp_nop_table[FPU_rm])();
|
||||
(fp_nop_table[FPU_rm]) ();
|
||||
}
|
||||
|
||||
|
||||
void fld_i_(void)
|
||||
{
|
||||
FPU_REG *st_new_ptr;
|
||||
int i;
|
||||
u_char tag;
|
||||
FPU_REG *st_new_ptr;
|
||||
int i;
|
||||
u_char tag;
|
||||
|
||||
if ( STACK_OVERFLOW )
|
||||
{ FPU_stack_overflow(); return; }
|
||||
|
||||
/* fld st(i) */
|
||||
i = FPU_rm;
|
||||
if ( NOT_EMPTY(i) )
|
||||
{
|
||||
reg_copy(&st(i), st_new_ptr);
|
||||
tag = FPU_gettagi(i);
|
||||
push();
|
||||
FPU_settag0(tag);
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( control_word & CW_Invalid )
|
||||
{
|
||||
/* The masked response */
|
||||
FPU_stack_underflow();
|
||||
if (STACK_OVERFLOW) {
|
||||
FPU_stack_overflow();
|
||||
return;
|
||||
}
|
||||
|
||||
/* fld st(i) */
|
||||
i = FPU_rm;
|
||||
if (NOT_EMPTY(i)) {
|
||||
reg_copy(&st(i), st_new_ptr);
|
||||
tag = FPU_gettagi(i);
|
||||
push();
|
||||
FPU_settag0(tag);
|
||||
} else {
|
||||
if (control_word & CW_Invalid) {
|
||||
/* The masked response */
|
||||
FPU_stack_underflow();
|
||||
} else
|
||||
EXCEPTION(EX_StackUnder);
|
||||
}
|
||||
else
|
||||
EXCEPTION(EX_StackUnder);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
void fxch_i(void)
|
||||
{
|
||||
/* fxch st(i) */
|
||||
FPU_REG t;
|
||||
int i = FPU_rm;
|
||||
FPU_REG *st0_ptr = &st(0), *sti_ptr = &st(i);
|
||||
long tag_word = fpu_tag_word;
|
||||
int regnr = top & 7, regnri = ((regnr + i) & 7);
|
||||
u_char st0_tag = (tag_word >> (regnr*2)) & 3;
|
||||
u_char sti_tag = (tag_word >> (regnri*2)) & 3;
|
||||
/* fxch st(i) */
|
||||
FPU_REG t;
|
||||
int i = FPU_rm;
|
||||
FPU_REG *st0_ptr = &st(0), *sti_ptr = &st(i);
|
||||
long tag_word = fpu_tag_word;
|
||||
int regnr = top & 7, regnri = ((regnr + i) & 7);
|
||||
u_char st0_tag = (tag_word >> (regnr * 2)) & 3;
|
||||
u_char sti_tag = (tag_word >> (regnri * 2)) & 3;
|
||||
|
||||
if ( st0_tag == TAG_Empty )
|
||||
{
|
||||
if ( sti_tag == TAG_Empty )
|
||||
{
|
||||
FPU_stack_underflow();
|
||||
FPU_stack_underflow_i(i);
|
||||
return;
|
||||
if (st0_tag == TAG_Empty) {
|
||||
if (sti_tag == TAG_Empty) {
|
||||
FPU_stack_underflow();
|
||||
FPU_stack_underflow_i(i);
|
||||
return;
|
||||
}
|
||||
if (control_word & CW_Invalid) {
|
||||
/* Masked response */
|
||||
FPU_copy_to_reg0(sti_ptr, sti_tag);
|
||||
}
|
||||
FPU_stack_underflow_i(i);
|
||||
return;
|
||||
}
|
||||
if ( control_word & CW_Invalid )
|
||||
{
|
||||
/* Masked response */
|
||||
FPU_copy_to_reg0(sti_ptr, sti_tag);
|
||||
if (sti_tag == TAG_Empty) {
|
||||
if (control_word & CW_Invalid) {
|
||||
/* Masked response */
|
||||
FPU_copy_to_regi(st0_ptr, st0_tag, i);
|
||||
}
|
||||
FPU_stack_underflow();
|
||||
return;
|
||||
}
|
||||
FPU_stack_underflow_i(i);
|
||||
return;
|
||||
}
|
||||
if ( sti_tag == TAG_Empty )
|
||||
{
|
||||
if ( control_word & CW_Invalid )
|
||||
{
|
||||
/* Masked response */
|
||||
FPU_copy_to_regi(st0_ptr, st0_tag, i);
|
||||
}
|
||||
FPU_stack_underflow();
|
||||
return;
|
||||
}
|
||||
clear_C1();
|
||||
clear_C1();
|
||||
|
||||
reg_copy(st0_ptr, &t);
|
||||
reg_copy(sti_ptr, st0_ptr);
|
||||
reg_copy(&t, sti_ptr);
|
||||
reg_copy(st0_ptr, &t);
|
||||
reg_copy(sti_ptr, st0_ptr);
|
||||
reg_copy(&t, sti_ptr);
|
||||
|
||||
tag_word &= ~(3 << (regnr*2)) & ~(3 << (regnri*2));
|
||||
tag_word |= (sti_tag << (regnr*2)) | (st0_tag << (regnri*2));
|
||||
fpu_tag_word = tag_word;
|
||||
tag_word &= ~(3 << (regnr * 2)) & ~(3 << (regnri * 2));
|
||||
tag_word |= (sti_tag << (regnr * 2)) | (st0_tag << (regnri * 2));
|
||||
fpu_tag_word = tag_word;
|
||||
}
|
||||
|
||||
|
||||
void ffree_(void)
|
||||
{
|
||||
/* ffree st(i) */
|
||||
FPU_settagi(FPU_rm, TAG_Empty);
|
||||
/* ffree st(i) */
|
||||
FPU_settagi(FPU_rm, TAG_Empty);
|
||||
}
|
||||
|
||||
|
||||
void ffreep(void)
|
||||
{
|
||||
/* ffree st(i) + pop - unofficial code */
|
||||
FPU_settagi(FPU_rm, TAG_Empty);
|
||||
FPU_pop();
|
||||
/* ffree st(i) + pop - unofficial code */
|
||||
FPU_settagi(FPU_rm, TAG_Empty);
|
||||
FPU_pop();
|
||||
}
|
||||
|
||||
|
||||
void fst_i_(void)
|
||||
{
|
||||
/* fst st(i) */
|
||||
FPU_copy_to_regi(&st(0), FPU_gettag0(), FPU_rm);
|
||||
/* fst st(i) */
|
||||
FPU_copy_to_regi(&st(0), FPU_gettag0(), FPU_rm);
|
||||
}
|
||||
|
||||
|
||||
void fstp_i(void)
|
||||
{
|
||||
/* fstp st(i) */
|
||||
FPU_copy_to_regi(&st(0), FPU_gettag0(), FPU_rm);
|
||||
FPU_pop();
|
||||
/* fstp st(i) */
|
||||
FPU_copy_to_regi(&st(0), FPU_gettag0(), FPU_rm);
|
||||
FPU_pop();
|
||||
}
|
||||
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
| |
|
||||
+---------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
#ifndef _FPU_EMU_H_
|
||||
#define _FPU_EMU_H_
|
||||
|
||||
|
@ -28,15 +27,15 @@
|
|||
#endif
|
||||
|
||||
#define EXP_BIAS Const(0)
|
||||
#define EXP_OVER Const(0x4000) /* smallest invalid large exponent */
|
||||
#define EXP_UNDER Const(-0x3fff) /* largest invalid small exponent */
|
||||
#define EXP_WAY_UNDER Const(-0x6000) /* Below the smallest denormal, but
|
||||
still a 16 bit nr. */
|
||||
#define EXP_OVER Const(0x4000) /* smallest invalid large exponent */
|
||||
#define EXP_UNDER Const(-0x3fff) /* largest invalid small exponent */
|
||||
#define EXP_WAY_UNDER Const(-0x6000) /* Below the smallest denormal, but
|
||||
still a 16 bit nr. */
|
||||
#define EXP_Infinity EXP_OVER
|
||||
#define EXP_NaN EXP_OVER
|
||||
|
||||
#define EXTENDED_Ebias Const(0x3fff)
|
||||
#define EXTENDED_Emin (-0x3ffe) /* smallest valid exponent */
|
||||
#define EXTENDED_Emin (-0x3ffe) /* smallest valid exponent */
|
||||
|
||||
#define SIGN_POS Const(0)
|
||||
#define SIGN_NEG Const(0x80)
|
||||
|
@ -44,10 +43,9 @@
|
|||
#define SIGN_Positive Const(0)
|
||||
#define SIGN_Negative Const(0x8000)
|
||||
|
||||
|
||||
/* Keep the order TAG_Valid, TAG_Zero, TW_Denormal */
|
||||
/* The following fold to 2 (Special) in the Tag Word */
|
||||
#define TW_Denormal Const(4) /* De-normal */
|
||||
#define TW_Denormal Const(4) /* De-normal */
|
||||
#define TW_Infinity Const(5) /* + or - infinity */
|
||||
#define TW_NaN Const(6) /* Not a Number */
|
||||
#define TW_Unsupported Const(7) /* Not supported by an 80486 */
|
||||
|
@ -67,14 +65,13 @@
|
|||
#define DEST_RM 0x20
|
||||
#define LOADED 0x40
|
||||
|
||||
#define FPU_Exception Const(0x80000000) /* Added to tag returns. */
|
||||
|
||||
#define FPU_Exception Const(0x80000000) /* Added to tag returns. */
|
||||
|
||||
#ifndef __ASSEMBLY__
|
||||
|
||||
#include "fpu_system.h"
|
||||
|
||||
#include <asm/sigcontext.h> /* for struct _fpstate */
|
||||
#include <asm/sigcontext.h> /* for struct _fpstate */
|
||||
#include <asm/math_emu.h>
|
||||
#include <linux/linkage.h>
|
||||
|
||||
|
@ -112,30 +109,33 @@ extern u_char emulating;
|
|||
#define PREFIX_DEFAULT 7
|
||||
|
||||
struct address {
|
||||
unsigned int offset;
|
||||
unsigned int selector:16;
|
||||
unsigned int opcode:11;
|
||||
unsigned int empty:5;
|
||||
unsigned int offset;
|
||||
unsigned int selector:16;
|
||||
unsigned int opcode:11;
|
||||
unsigned int empty:5;
|
||||
};
|
||||
struct fpu__reg {
|
||||
unsigned sigl;
|
||||
unsigned sigh;
|
||||
short exp;
|
||||
unsigned sigl;
|
||||
unsigned sigh;
|
||||
short exp;
|
||||
};
|
||||
|
||||
typedef void (*FUNC)(void);
|
||||
typedef void (*FUNC) (void);
|
||||
typedef struct fpu__reg FPU_REG;
|
||||
typedef void (*FUNC_ST0)(FPU_REG *st0_ptr, u_char st0_tag);
|
||||
typedef struct { u_char address_size, operand_size, segment; }
|
||||
overrides;
|
||||
typedef void (*FUNC_ST0) (FPU_REG * st0_ptr, u_char st0_tag);
|
||||
typedef struct {
|
||||
u_char address_size, operand_size, segment;
|
||||
} overrides;
|
||||
/* This structure is 32 bits: */
|
||||
typedef struct { overrides override;
|
||||
u_char default_mode; } fpu_addr_modes;
|
||||
typedef struct {
|
||||
overrides override;
|
||||
u_char default_mode;
|
||||
} fpu_addr_modes;
|
||||
/* PROTECTED has a restricted meaning in the emulator; it is used
|
||||
to signal that the emulator needs to do special things to ensure
|
||||
that protection is respected in a segmented model. */
|
||||
#define PROTECTED 4
|
||||
#define SIXTEEN 1 /* We rely upon this being 1 (true) */
|
||||
#define SIXTEEN 1 /* We rely upon this being 1 (true) */
|
||||
#define VM86 SIXTEEN
|
||||
#define PM16 (SIXTEEN | PROTECTED)
|
||||
#define SEG32 PROTECTED
|
||||
|
@ -166,10 +166,10 @@ extern u_char const data_sizes_16[32];
|
|||
#define signpositive(a) ( (signbyte(a) & 0x80) == 0 )
|
||||
#define signnegative(a) (signbyte(a) & 0x80)
|
||||
|
||||
static inline void reg_copy(FPU_REG const *x, FPU_REG *y)
|
||||
static inline void reg_copy(FPU_REG const *x, FPU_REG * y)
|
||||
{
|
||||
*(short *)&(y->exp) = *(const short *)&(x->exp);
|
||||
*(long long *)&(y->sigl) = *(const long long *)&(x->sigl);
|
||||
*(short *)&(y->exp) = *(const short *)&(x->exp);
|
||||
*(long long *)&(y->sigl) = *(const long long *)&(x->sigl);
|
||||
}
|
||||
|
||||
#define exponent(x) (((*(short *)&((x)->exp)) & 0x7fff) - EXTENDED_Ebias)
|
||||
|
@ -184,29 +184,28 @@ static inline void reg_copy(FPU_REG const *x, FPU_REG *y)
|
|||
|
||||
#define significand(x) ( ((unsigned long long *)&((x)->sigl))[0] )
|
||||
|
||||
|
||||
/*----- Prototypes for functions written in assembler -----*/
|
||||
/* extern void reg_move(FPU_REG *a, FPU_REG *b); */
|
||||
|
||||
asmlinkage int FPU_normalize(FPU_REG *x);
|
||||
asmlinkage int FPU_normalize_nuo(FPU_REG *x);
|
||||
asmlinkage int FPU_normalize(FPU_REG * x);
|
||||
asmlinkage int FPU_normalize_nuo(FPU_REG * x);
|
||||
asmlinkage int FPU_u_sub(FPU_REG const *arg1, FPU_REG const *arg2,
|
||||
FPU_REG *answ, unsigned int control_w, u_char sign,
|
||||
FPU_REG * answ, unsigned int control_w, u_char sign,
|
||||
int expa, int expb);
|
||||
asmlinkage int FPU_u_mul(FPU_REG const *arg1, FPU_REG const *arg2,
|
||||
FPU_REG *answ, unsigned int control_w, u_char sign,
|
||||
FPU_REG * answ, unsigned int control_w, u_char sign,
|
||||
int expon);
|
||||
asmlinkage int FPU_u_div(FPU_REG const *arg1, FPU_REG const *arg2,
|
||||
FPU_REG *answ, unsigned int control_w, u_char sign);
|
||||
FPU_REG * answ, unsigned int control_w, u_char sign);
|
||||
asmlinkage int FPU_u_add(FPU_REG const *arg1, FPU_REG const *arg2,
|
||||
FPU_REG *answ, unsigned int control_w, u_char sign,
|
||||
FPU_REG * answ, unsigned int control_w, u_char sign,
|
||||
int expa, int expb);
|
||||
asmlinkage int wm_sqrt(FPU_REG *n, int dummy1, int dummy2,
|
||||
asmlinkage int wm_sqrt(FPU_REG * n, int dummy1, int dummy2,
|
||||
unsigned int control_w, u_char sign);
|
||||
asmlinkage unsigned FPU_shrx(void *l, unsigned x);
|
||||
asmlinkage unsigned FPU_shrxs(void *v, unsigned x);
|
||||
asmlinkage unsigned FPU_shrx(void *l, unsigned x);
|
||||
asmlinkage unsigned FPU_shrxs(void *v, unsigned x);
|
||||
asmlinkage unsigned long FPU_div_small(unsigned long long *x, unsigned long y);
|
||||
asmlinkage int FPU_round(FPU_REG *arg, unsigned int extent, int dummy,
|
||||
asmlinkage int FPU_round(FPU_REG * arg, unsigned int extent, int dummy,
|
||||
unsigned int control_w, u_char sign);
|
||||
|
||||
#ifndef MAKING_PROTO
|
||||
|
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -16,128 +16,115 @@
|
|||
#include "status_w.h"
|
||||
#include "reg_constant.h"
|
||||
|
||||
|
||||
static void fchs(FPU_REG *st0_ptr, u_char st0tag)
|
||||
static void fchs(FPU_REG * st0_ptr, u_char st0tag)
|
||||
{
|
||||
if ( st0tag ^ TAG_Empty )
|
||||
{
|
||||
signbyte(st0_ptr) ^= SIGN_NEG;
|
||||
clear_C1();
|
||||
}
|
||||
else
|
||||
FPU_stack_underflow();
|
||||
if (st0tag ^ TAG_Empty) {
|
||||
signbyte(st0_ptr) ^= SIGN_NEG;
|
||||
clear_C1();
|
||||
} else
|
||||
FPU_stack_underflow();
|
||||
}
|
||||
|
||||
|
||||
static void fabs(FPU_REG *st0_ptr, u_char st0tag)
|
||||
static void fabs(FPU_REG * st0_ptr, u_char st0tag)
|
||||
{
|
||||
if ( st0tag ^ TAG_Empty )
|
||||
{
|
||||
setpositive(st0_ptr);
|
||||
clear_C1();
|
||||
}
|
||||
else
|
||||
FPU_stack_underflow();
|
||||
if (st0tag ^ TAG_Empty) {
|
||||
setpositive(st0_ptr);
|
||||
clear_C1();
|
||||
} else
|
||||
FPU_stack_underflow();
|
||||
}
|
||||
|
||||
|
||||
static void ftst_(FPU_REG *st0_ptr, u_char st0tag)
|
||||
static void ftst_(FPU_REG * st0_ptr, u_char st0tag)
|
||||
{
|
||||
switch (st0tag)
|
||||
{
|
||||
case TAG_Zero:
|
||||
setcc(SW_C3);
|
||||
break;
|
||||
case TAG_Valid:
|
||||
if (getsign(st0_ptr) == SIGN_POS)
|
||||
setcc(0);
|
||||
else
|
||||
setcc(SW_C0);
|
||||
break;
|
||||
case TAG_Special:
|
||||
switch ( FPU_Special(st0_ptr) )
|
||||
{
|
||||
case TW_Denormal:
|
||||
if (getsign(st0_ptr) == SIGN_POS)
|
||||
setcc(0);
|
||||
else
|
||||
setcc(SW_C0);
|
||||
if ( denormal_operand() < 0 )
|
||||
{
|
||||
#ifdef PECULIAR_486
|
||||
/* This is weird! */
|
||||
if (getsign(st0_ptr) == SIGN_POS)
|
||||
switch (st0tag) {
|
||||
case TAG_Zero:
|
||||
setcc(SW_C3);
|
||||
break;
|
||||
case TAG_Valid:
|
||||
if (getsign(st0_ptr) == SIGN_POS)
|
||||
setcc(0);
|
||||
else
|
||||
setcc(SW_C0);
|
||||
break;
|
||||
case TAG_Special:
|
||||
switch (FPU_Special(st0_ptr)) {
|
||||
case TW_Denormal:
|
||||
if (getsign(st0_ptr) == SIGN_POS)
|
||||
setcc(0);
|
||||
else
|
||||
setcc(SW_C0);
|
||||
if (denormal_operand() < 0) {
|
||||
#ifdef PECULIAR_486
|
||||
/* This is weird! */
|
||||
if (getsign(st0_ptr) == SIGN_POS)
|
||||
setcc(SW_C3);
|
||||
#endif /* PECULIAR_486 */
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case TW_NaN:
|
||||
setcc(SW_C0|SW_C2|SW_C3); /* Operand is not comparable */
|
||||
EXCEPTION(EX_Invalid);
|
||||
break;
|
||||
case TW_Infinity:
|
||||
if (getsign(st0_ptr) == SIGN_POS)
|
||||
setcc(0);
|
||||
else
|
||||
setcc(SW_C0);
|
||||
break;
|
||||
default:
|
||||
setcc(SW_C0|SW_C2|SW_C3); /* Operand is not comparable */
|
||||
EXCEPTION(EX_INTERNAL|0x14);
|
||||
break;
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case TW_NaN:
|
||||
setcc(SW_C0 | SW_C2 | SW_C3); /* Operand is not comparable */
|
||||
EXCEPTION(EX_Invalid);
|
||||
break;
|
||||
case TW_Infinity:
|
||||
if (getsign(st0_ptr) == SIGN_POS)
|
||||
setcc(0);
|
||||
else
|
||||
setcc(SW_C0);
|
||||
break;
|
||||
default:
|
||||
setcc(SW_C0 | SW_C2 | SW_C3); /* Operand is not comparable */
|
||||
EXCEPTION(EX_INTERNAL | 0x14);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case TAG_Empty:
|
||||
setcc(SW_C0 | SW_C2 | SW_C3);
|
||||
EXCEPTION(EX_StackUnder);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case TAG_Empty:
|
||||
setcc(SW_C0|SW_C2|SW_C3);
|
||||
EXCEPTION(EX_StackUnder);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void fxam(FPU_REG *st0_ptr, u_char st0tag)
|
||||
static void fxam(FPU_REG * st0_ptr, u_char st0tag)
|
||||
{
|
||||
int c = 0;
|
||||
switch (st0tag)
|
||||
{
|
||||
case TAG_Empty:
|
||||
c = SW_C3|SW_C0;
|
||||
break;
|
||||
case TAG_Zero:
|
||||
c = SW_C3;
|
||||
break;
|
||||
case TAG_Valid:
|
||||
c = SW_C2;
|
||||
break;
|
||||
case TAG_Special:
|
||||
switch ( FPU_Special(st0_ptr) )
|
||||
{
|
||||
case TW_Denormal:
|
||||
c = SW_C2|SW_C3; /* Denormal */
|
||||
break;
|
||||
case TW_NaN:
|
||||
/* We also use NaN for unsupported types. */
|
||||
if ( (st0_ptr->sigh & 0x80000000) && (exponent(st0_ptr) == EXP_OVER) )
|
||||
c = SW_C0;
|
||||
break;
|
||||
case TW_Infinity:
|
||||
c = SW_C2|SW_C0;
|
||||
break;
|
||||
int c = 0;
|
||||
switch (st0tag) {
|
||||
case TAG_Empty:
|
||||
c = SW_C3 | SW_C0;
|
||||
break;
|
||||
case TAG_Zero:
|
||||
c = SW_C3;
|
||||
break;
|
||||
case TAG_Valid:
|
||||
c = SW_C2;
|
||||
break;
|
||||
case TAG_Special:
|
||||
switch (FPU_Special(st0_ptr)) {
|
||||
case TW_Denormal:
|
||||
c = SW_C2 | SW_C3; /* Denormal */
|
||||
break;
|
||||
case TW_NaN:
|
||||
/* We also use NaN for unsupported types. */
|
||||
if ((st0_ptr->sigh & 0x80000000)
|
||||
&& (exponent(st0_ptr) == EXP_OVER))
|
||||
c = SW_C0;
|
||||
break;
|
||||
case TW_Infinity:
|
||||
c = SW_C2 | SW_C0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ( getsign(st0_ptr) == SIGN_NEG )
|
||||
c |= SW_C1;
|
||||
setcc(c);
|
||||
if (getsign(st0_ptr) == SIGN_NEG)
|
||||
c |= SW_C1;
|
||||
setcc(c);
|
||||
}
|
||||
|
||||
|
||||
static FUNC_ST0 const fp_etc_table[] = {
|
||||
fchs, fabs, (FUNC_ST0)FPU_illegal, (FUNC_ST0)FPU_illegal,
|
||||
ftst_, fxam, (FUNC_ST0)FPU_illegal, (FUNC_ST0)FPU_illegal
|
||||
fchs, fabs, (FUNC_ST0) FPU_illegal, (FUNC_ST0) FPU_illegal,
|
||||
ftst_, fxam, (FUNC_ST0) FPU_illegal, (FUNC_ST0) FPU_illegal
|
||||
};
|
||||
|
||||
void FPU_etc(void)
|
||||
{
|
||||
(fp_etc_table[FPU_rm])(&st(0), FPU_gettag0());
|
||||
(fp_etc_table[FPU_rm]) (&st(0), FPU_gettag0());
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
extern void FPU_illegal(void);
|
||||
extern void FPU_printall(void);
|
||||
asmlinkage void FPU_exception(int n);
|
||||
extern int real_1op_NaN(FPU_REG *a);
|
||||
extern int real_1op_NaN(FPU_REG * a);
|
||||
extern int real_2op_NaN(FPU_REG const *b, u_char tagb, int deststnr,
|
||||
FPU_REG const *defaultNaN);
|
||||
asmlinkage int arith_invalid(int deststnr);
|
||||
|
@ -14,8 +14,8 @@ extern int set_precision_flag(int flags);
|
|||
asmlinkage void set_precision_flag_up(void);
|
||||
asmlinkage void set_precision_flag_down(void);
|
||||
asmlinkage int denormal_operand(void);
|
||||
asmlinkage int arith_overflow(FPU_REG *dest);
|
||||
asmlinkage int arith_underflow(FPU_REG *dest);
|
||||
asmlinkage int arith_overflow(FPU_REG * dest);
|
||||
asmlinkage int arith_underflow(FPU_REG * dest);
|
||||
extern void FPU_stack_overflow(void);
|
||||
extern void FPU_stack_underflow(void);
|
||||
extern void FPU_stack_underflow_i(int i);
|
||||
|
@ -66,7 +66,7 @@ extern int FPU_Special(FPU_REG const *ptr);
|
|||
extern int isNaN(FPU_REG const *ptr);
|
||||
extern void FPU_pop(void);
|
||||
extern int FPU_empty_i(int stnr);
|
||||
extern int FPU_stackoverflow(FPU_REG **st_new_ptr);
|
||||
extern int FPU_stackoverflow(FPU_REG ** st_new_ptr);
|
||||
extern void FPU_copy_to_regi(FPU_REG const *r, u_char tag, int stnr);
|
||||
extern void FPU_copy_to_reg1(FPU_REG const *r, u_char tag);
|
||||
extern void FPU_copy_to_reg0(FPU_REG const *r, u_char tag);
|
||||
|
@ -75,26 +75,28 @@ extern void FPU_triga(void);
|
|||
extern void FPU_trigb(void);
|
||||
/* get_address.c */
|
||||
extern void __user *FPU_get_address(u_char FPU_modrm, unsigned long *fpu_eip,
|
||||
struct address *addr, fpu_addr_modes addr_modes);
|
||||
struct address *addr,
|
||||
fpu_addr_modes addr_modes);
|
||||
extern void __user *FPU_get_address_16(u_char FPU_modrm, unsigned long *fpu_eip,
|
||||
struct address *addr, fpu_addr_modes addr_modes);
|
||||
struct address *addr,
|
||||
fpu_addr_modes addr_modes);
|
||||
/* load_store.c */
|
||||
extern int FPU_load_store(u_char type, fpu_addr_modes addr_modes,
|
||||
void __user *data_address);
|
||||
void __user * data_address);
|
||||
/* poly_2xm1.c */
|
||||
extern int poly_2xm1(u_char sign, FPU_REG *arg, FPU_REG *result);
|
||||
extern int poly_2xm1(u_char sign, FPU_REG * arg, FPU_REG * result);
|
||||
/* poly_atan.c */
|
||||
extern void poly_atan(FPU_REG *st0_ptr, u_char st0_tag, FPU_REG *st1_ptr,
|
||||
extern void poly_atan(FPU_REG * st0_ptr, u_char st0_tag, FPU_REG * st1_ptr,
|
||||
u_char st1_tag);
|
||||
/* poly_l2.c */
|
||||
extern void poly_l2(FPU_REG *st0_ptr, FPU_REG *st1_ptr, u_char st1_sign);
|
||||
extern int poly_l2p1(u_char s0, u_char s1, FPU_REG *r0, FPU_REG *r1,
|
||||
FPU_REG *d);
|
||||
extern void poly_l2(FPU_REG * st0_ptr, FPU_REG * st1_ptr, u_char st1_sign);
|
||||
extern int poly_l2p1(u_char s0, u_char s1, FPU_REG * r0, FPU_REG * r1,
|
||||
FPU_REG * d);
|
||||
/* poly_sin.c */
|
||||
extern void poly_sine(FPU_REG *st0_ptr);
|
||||
extern void poly_cos(FPU_REG *st0_ptr);
|
||||
extern void poly_sine(FPU_REG * st0_ptr);
|
||||
extern void poly_cos(FPU_REG * st0_ptr);
|
||||
/* poly_tan.c */
|
||||
extern void poly_tan(FPU_REG *st0_ptr);
|
||||
extern void poly_tan(FPU_REG * st0_ptr);
|
||||
/* reg_add_sub.c */
|
||||
extern int FPU_add(FPU_REG const *b, u_char tagb, int destrnr, int control_w);
|
||||
extern int FPU_sub(int flags, int rm, int control_w);
|
||||
|
@ -109,32 +111,34 @@ extern void fucompp(void);
|
|||
/* reg_constant.c */
|
||||
extern void fconst(void);
|
||||
/* reg_ld_str.c */
|
||||
extern int FPU_load_extended(long double __user *s, int stnr);
|
||||
extern int FPU_load_double(double __user *dfloat, FPU_REG *loaded_data);
|
||||
extern int FPU_load_single(float __user *single, FPU_REG *loaded_data);
|
||||
extern int FPU_load_int64(long long __user *_s);
|
||||
extern int FPU_load_int32(long __user *_s, FPU_REG *loaded_data);
|
||||
extern int FPU_load_int16(short __user *_s, FPU_REG *loaded_data);
|
||||
extern int FPU_load_bcd(u_char __user *s);
|
||||
extern int FPU_store_extended(FPU_REG *st0_ptr, u_char st0_tag,
|
||||
long double __user *d);
|
||||
extern int FPU_store_double(FPU_REG *st0_ptr, u_char st0_tag, double __user *dfloat);
|
||||
extern int FPU_store_single(FPU_REG *st0_ptr, u_char st0_tag, float __user *single);
|
||||
extern int FPU_store_int64(FPU_REG *st0_ptr, u_char st0_tag, long long __user *d);
|
||||
extern int FPU_store_int32(FPU_REG *st0_ptr, u_char st0_tag, long __user *d);
|
||||
extern int FPU_store_int16(FPU_REG *st0_ptr, u_char st0_tag, short __user *d);
|
||||
extern int FPU_store_bcd(FPU_REG *st0_ptr, u_char st0_tag, u_char __user *d);
|
||||
extern int FPU_round_to_int(FPU_REG *r, u_char tag);
|
||||
extern u_char __user *fldenv(fpu_addr_modes addr_modes, u_char __user *s);
|
||||
extern void frstor(fpu_addr_modes addr_modes, u_char __user *data_address);
|
||||
extern u_char __user *fstenv(fpu_addr_modes addr_modes, u_char __user *d);
|
||||
extern void fsave(fpu_addr_modes addr_modes, u_char __user *data_address);
|
||||
extern int FPU_tagof(FPU_REG *ptr);
|
||||
extern int FPU_load_extended(long double __user * s, int stnr);
|
||||
extern int FPU_load_double(double __user * dfloat, FPU_REG * loaded_data);
|
||||
extern int FPU_load_single(float __user * single, FPU_REG * loaded_data);
|
||||
extern int FPU_load_int64(long long __user * _s);
|
||||
extern int FPU_load_int32(long __user * _s, FPU_REG * loaded_data);
|
||||
extern int FPU_load_int16(short __user * _s, FPU_REG * loaded_data);
|
||||
extern int FPU_load_bcd(u_char __user * s);
|
||||
extern int FPU_store_extended(FPU_REG * st0_ptr, u_char st0_tag,
|
||||
long double __user * d);
|
||||
extern int FPU_store_double(FPU_REG * st0_ptr, u_char st0_tag,
|
||||
double __user * dfloat);
|
||||
extern int FPU_store_single(FPU_REG * st0_ptr, u_char st0_tag,
|
||||
float __user * single);
|
||||
extern int FPU_store_int64(FPU_REG * st0_ptr, u_char st0_tag,
|
||||
long long __user * d);
|
||||
extern int FPU_store_int32(FPU_REG * st0_ptr, u_char st0_tag, long __user * d);
|
||||
extern int FPU_store_int16(FPU_REG * st0_ptr, u_char st0_tag, short __user * d);
|
||||
extern int FPU_store_bcd(FPU_REG * st0_ptr, u_char st0_tag, u_char __user * d);
|
||||
extern int FPU_round_to_int(FPU_REG * r, u_char tag);
|
||||
extern u_char __user *fldenv(fpu_addr_modes addr_modes, u_char __user * s);
|
||||
extern void frstor(fpu_addr_modes addr_modes, u_char __user * data_address);
|
||||
extern u_char __user *fstenv(fpu_addr_modes addr_modes, u_char __user * d);
|
||||
extern void fsave(fpu_addr_modes addr_modes, u_char __user * data_address);
|
||||
extern int FPU_tagof(FPU_REG * ptr);
|
||||
/* reg_mul.c */
|
||||
extern int FPU_mul(FPU_REG const *b, u_char tagb, int deststnr, int control_w);
|
||||
|
||||
extern int FPU_div(int flags, int regrm, int control_w);
|
||||
/* reg_convert.c */
|
||||
extern int FPU_to_exp16(FPU_REG const *a, FPU_REG *x);
|
||||
extern int FPU_to_exp16(FPU_REG const *a, FPU_REG * x);
|
||||
#endif /* _FPU_PROTO_H */
|
||||
|
||||
|
|
|
@ -14,114 +14,102 @@
|
|||
#include "fpu_system.h"
|
||||
#include "exception.h"
|
||||
|
||||
|
||||
void FPU_pop(void)
|
||||
{
|
||||
fpu_tag_word |= 3 << ((top & 7)*2);
|
||||
top++;
|
||||
fpu_tag_word |= 3 << ((top & 7) * 2);
|
||||
top++;
|
||||
}
|
||||
|
||||
|
||||
int FPU_gettag0(void)
|
||||
{
|
||||
return (fpu_tag_word >> ((top & 7)*2)) & 3;
|
||||
return (fpu_tag_word >> ((top & 7) * 2)) & 3;
|
||||
}
|
||||
|
||||
|
||||
int FPU_gettagi(int stnr)
|
||||
{
|
||||
return (fpu_tag_word >> (((top+stnr) & 7)*2)) & 3;
|
||||
return (fpu_tag_word >> (((top + stnr) & 7) * 2)) & 3;
|
||||
}
|
||||
|
||||
|
||||
int FPU_gettag(int regnr)
|
||||
{
|
||||
return (fpu_tag_word >> ((regnr & 7)*2)) & 3;
|
||||
return (fpu_tag_word >> ((regnr & 7) * 2)) & 3;
|
||||
}
|
||||
|
||||
|
||||
void FPU_settag0(int tag)
|
||||
{
|
||||
int regnr = top;
|
||||
regnr &= 7;
|
||||
fpu_tag_word &= ~(3 << (regnr*2));
|
||||
fpu_tag_word |= (tag & 3) << (regnr*2);
|
||||
int regnr = top;
|
||||
regnr &= 7;
|
||||
fpu_tag_word &= ~(3 << (regnr * 2));
|
||||
fpu_tag_word |= (tag & 3) << (regnr * 2);
|
||||
}
|
||||
|
||||
|
||||
void FPU_settagi(int stnr, int tag)
|
||||
{
|
||||
int regnr = stnr+top;
|
||||
regnr &= 7;
|
||||
fpu_tag_word &= ~(3 << (regnr*2));
|
||||
fpu_tag_word |= (tag & 3) << (regnr*2);
|
||||
int regnr = stnr + top;
|
||||
regnr &= 7;
|
||||
fpu_tag_word &= ~(3 << (regnr * 2));
|
||||
fpu_tag_word |= (tag & 3) << (regnr * 2);
|
||||
}
|
||||
|
||||
|
||||
void FPU_settag(int regnr, int tag)
|
||||
{
|
||||
regnr &= 7;
|
||||
fpu_tag_word &= ~(3 << (regnr*2));
|
||||
fpu_tag_word |= (tag & 3) << (regnr*2);
|
||||
regnr &= 7;
|
||||
fpu_tag_word &= ~(3 << (regnr * 2));
|
||||
fpu_tag_word |= (tag & 3) << (regnr * 2);
|
||||
}
|
||||
|
||||
|
||||
int FPU_Special(FPU_REG const *ptr)
|
||||
{
|
||||
int exp = exponent(ptr);
|
||||
int exp = exponent(ptr);
|
||||
|
||||
if ( exp == EXP_BIAS+EXP_UNDER )
|
||||
return TW_Denormal;
|
||||
else if ( exp != EXP_BIAS+EXP_OVER )
|
||||
return TW_NaN;
|
||||
else if ( (ptr->sigh == 0x80000000) && (ptr->sigl == 0) )
|
||||
return TW_Infinity;
|
||||
return TW_NaN;
|
||||
if (exp == EXP_BIAS + EXP_UNDER)
|
||||
return TW_Denormal;
|
||||
else if (exp != EXP_BIAS + EXP_OVER)
|
||||
return TW_NaN;
|
||||
else if ((ptr->sigh == 0x80000000) && (ptr->sigl == 0))
|
||||
return TW_Infinity;
|
||||
return TW_NaN;
|
||||
}
|
||||
|
||||
|
||||
int isNaN(FPU_REG const *ptr)
|
||||
{
|
||||
return ( (exponent(ptr) == EXP_BIAS+EXP_OVER)
|
||||
&& !((ptr->sigh == 0x80000000) && (ptr->sigl == 0)) );
|
||||
return ((exponent(ptr) == EXP_BIAS + EXP_OVER)
|
||||
&& !((ptr->sigh == 0x80000000) && (ptr->sigl == 0)));
|
||||
}
|
||||
|
||||
|
||||
int FPU_empty_i(int stnr)
|
||||
{
|
||||
int regnr = (top+stnr) & 7;
|
||||
int regnr = (top + stnr) & 7;
|
||||
|
||||
return ((fpu_tag_word >> (regnr*2)) & 3) == TAG_Empty;
|
||||
return ((fpu_tag_word >> (regnr * 2)) & 3) == TAG_Empty;
|
||||
}
|
||||
|
||||
|
||||
int FPU_stackoverflow(FPU_REG **st_new_ptr)
|
||||
int FPU_stackoverflow(FPU_REG ** st_new_ptr)
|
||||
{
|
||||
*st_new_ptr = &st(-1);
|
||||
*st_new_ptr = &st(-1);
|
||||
|
||||
return ((fpu_tag_word >> (((top - 1) & 7)*2)) & 3) != TAG_Empty;
|
||||
return ((fpu_tag_word >> (((top - 1) & 7) * 2)) & 3) != TAG_Empty;
|
||||
}
|
||||
|
||||
|
||||
void FPU_copy_to_regi(FPU_REG const *r, u_char tag, int stnr)
|
||||
{
|
||||
reg_copy(r, &st(stnr));
|
||||
FPU_settagi(stnr, tag);
|
||||
reg_copy(r, &st(stnr));
|
||||
FPU_settagi(stnr, tag);
|
||||
}
|
||||
|
||||
void FPU_copy_to_reg1(FPU_REG const *r, u_char tag)
|
||||
{
|
||||
reg_copy(r, &st(1));
|
||||
FPU_settagi(1, tag);
|
||||
reg_copy(r, &st(1));
|
||||
FPU_settagi(1, tag);
|
||||
}
|
||||
|
||||
void FPU_copy_to_reg0(FPU_REG const *r, u_char tag)
|
||||
{
|
||||
int regnr = top;
|
||||
regnr &= 7;
|
||||
int regnr = top;
|
||||
regnr &= 7;
|
||||
|
||||
reg_copy(r, &st(0));
|
||||
reg_copy(r, &st(0));
|
||||
|
||||
fpu_tag_word &= ~(3 << (regnr*2));
|
||||
fpu_tag_word |= (tag & 3) << (regnr*2);
|
||||
fpu_tag_word &= ~(3 << (regnr * 2));
|
||||
fpu_tag_word |= (tag & 3) << (regnr * 2);
|
||||
}
|
||||
|
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -17,7 +17,6 @@
|
|||
| other processes using the emulator while swapping is in progress. |
|
||||
+---------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
#include <linux/stddef.h>
|
||||
|
||||
#include <asm/uaccess.h>
|
||||
|
@ -27,31 +26,30 @@
|
|||
#include "exception.h"
|
||||
#include "fpu_emu.h"
|
||||
|
||||
|
||||
#define FPU_WRITE_BIT 0x10
|
||||
|
||||
static int reg_offset[] = {
|
||||
offsetof(struct info,___eax),
|
||||
offsetof(struct info,___ecx),
|
||||
offsetof(struct info,___edx),
|
||||
offsetof(struct info,___ebx),
|
||||
offsetof(struct info,___esp),
|
||||
offsetof(struct info,___ebp),
|
||||
offsetof(struct info,___esi),
|
||||
offsetof(struct info,___edi)
|
||||
offsetof(struct info, ___eax),
|
||||
offsetof(struct info, ___ecx),
|
||||
offsetof(struct info, ___edx),
|
||||
offsetof(struct info, ___ebx),
|
||||
offsetof(struct info, ___esp),
|
||||
offsetof(struct info, ___ebp),
|
||||
offsetof(struct info, ___esi),
|
||||
offsetof(struct info, ___edi)
|
||||
};
|
||||
|
||||
#define REG_(x) (*(long *)(reg_offset[(x)]+(u_char *) FPU_info))
|
||||
|
||||
static int reg_offset_vm86[] = {
|
||||
offsetof(struct info,___cs),
|
||||
offsetof(struct info,___vm86_ds),
|
||||
offsetof(struct info,___vm86_es),
|
||||
offsetof(struct info,___vm86_fs),
|
||||
offsetof(struct info,___vm86_gs),
|
||||
offsetof(struct info,___ss),
|
||||
offsetof(struct info,___vm86_ds)
|
||||
};
|
||||
offsetof(struct info, ___cs),
|
||||
offsetof(struct info, ___vm86_ds),
|
||||
offsetof(struct info, ___vm86_es),
|
||||
offsetof(struct info, ___vm86_fs),
|
||||
offsetof(struct info, ___vm86_gs),
|
||||
offsetof(struct info, ___ss),
|
||||
offsetof(struct info, ___vm86_ds)
|
||||
};
|
||||
|
||||
#define VM86_REG_(x) (*(unsigned short *) \
|
||||
(reg_offset_vm86[((unsigned)x)]+(u_char *) FPU_info))
|
||||
|
@ -60,158 +58,141 @@ static int reg_offset_vm86[] = {
|
|||
#define ___GS ___ds
|
||||
|
||||
static int reg_offset_pm[] = {
|
||||
offsetof(struct info,___cs),
|
||||
offsetof(struct info,___ds),
|
||||
offsetof(struct info,___es),
|
||||
offsetof(struct info,___fs),
|
||||
offsetof(struct info,___GS),
|
||||
offsetof(struct info,___ss),
|
||||
offsetof(struct info,___ds)
|
||||
};
|
||||
offsetof(struct info, ___cs),
|
||||
offsetof(struct info, ___ds),
|
||||
offsetof(struct info, ___es),
|
||||
offsetof(struct info, ___fs),
|
||||
offsetof(struct info, ___GS),
|
||||
offsetof(struct info, ___ss),
|
||||
offsetof(struct info, ___ds)
|
||||
};
|
||||
|
||||
#define PM_REG_(x) (*(unsigned short *) \
|
||||
(reg_offset_pm[((unsigned)x)]+(u_char *) FPU_info))
|
||||
|
||||
|
||||
/* Decode the SIB byte. This function assumes mod != 0 */
|
||||
static int sib(int mod, unsigned long *fpu_eip)
|
||||
{
|
||||
u_char ss,index,base;
|
||||
long offset;
|
||||
u_char ss, index, base;
|
||||
long offset;
|
||||
|
||||
RE_ENTRANT_CHECK_OFF;
|
||||
FPU_code_access_ok(1);
|
||||
FPU_get_user(base, (u_char __user *) (*fpu_eip)); /* The SIB byte */
|
||||
RE_ENTRANT_CHECK_ON;
|
||||
(*fpu_eip)++;
|
||||
ss = base >> 6;
|
||||
index = (base >> 3) & 7;
|
||||
base &= 7;
|
||||
RE_ENTRANT_CHECK_OFF;
|
||||
FPU_code_access_ok(1);
|
||||
FPU_get_user(base, (u_char __user *) (*fpu_eip)); /* The SIB byte */
|
||||
RE_ENTRANT_CHECK_ON;
|
||||
(*fpu_eip)++;
|
||||
ss = base >> 6;
|
||||
index = (base >> 3) & 7;
|
||||
base &= 7;
|
||||
|
||||
if ((mod == 0) && (base == 5))
|
||||
offset = 0; /* No base register */
|
||||
else
|
||||
offset = REG_(base);
|
||||
if ((mod == 0) && (base == 5))
|
||||
offset = 0; /* No base register */
|
||||
else
|
||||
offset = REG_(base);
|
||||
|
||||
if (index == 4)
|
||||
{
|
||||
/* No index register */
|
||||
/* A non-zero ss is illegal */
|
||||
if ( ss )
|
||||
EXCEPTION(EX_Invalid);
|
||||
}
|
||||
else
|
||||
{
|
||||
offset += (REG_(index)) << ss;
|
||||
}
|
||||
if (index == 4) {
|
||||
/* No index register */
|
||||
/* A non-zero ss is illegal */
|
||||
if (ss)
|
||||
EXCEPTION(EX_Invalid);
|
||||
} else {
|
||||
offset += (REG_(index)) << ss;
|
||||
}
|
||||
|
||||
if (mod == 1)
|
||||
{
|
||||
/* 8 bit signed displacement */
|
||||
long displacement;
|
||||
RE_ENTRANT_CHECK_OFF;
|
||||
FPU_code_access_ok(1);
|
||||
FPU_get_user(displacement, (signed char __user *) (*fpu_eip));
|
||||
offset += displacement;
|
||||
RE_ENTRANT_CHECK_ON;
|
||||
(*fpu_eip)++;
|
||||
}
|
||||
else if (mod == 2 || base == 5) /* The second condition also has mod==0 */
|
||||
{
|
||||
/* 32 bit displacement */
|
||||
long displacement;
|
||||
RE_ENTRANT_CHECK_OFF;
|
||||
FPU_code_access_ok(4);
|
||||
FPU_get_user(displacement, (long __user *) (*fpu_eip));
|
||||
offset += displacement;
|
||||
RE_ENTRANT_CHECK_ON;
|
||||
(*fpu_eip) += 4;
|
||||
}
|
||||
if (mod == 1) {
|
||||
/* 8 bit signed displacement */
|
||||
long displacement;
|
||||
RE_ENTRANT_CHECK_OFF;
|
||||
FPU_code_access_ok(1);
|
||||
FPU_get_user(displacement, (signed char __user *)(*fpu_eip));
|
||||
offset += displacement;
|
||||
RE_ENTRANT_CHECK_ON;
|
||||
(*fpu_eip)++;
|
||||
} else if (mod == 2 || base == 5) { /* The second condition also has mod==0 */
|
||||
/* 32 bit displacement */
|
||||
long displacement;
|
||||
RE_ENTRANT_CHECK_OFF;
|
||||
FPU_code_access_ok(4);
|
||||
FPU_get_user(displacement, (long __user *)(*fpu_eip));
|
||||
offset += displacement;
|
||||
RE_ENTRANT_CHECK_ON;
|
||||
(*fpu_eip) += 4;
|
||||
}
|
||||
|
||||
return offset;
|
||||
return offset;
|
||||
}
|
||||
|
||||
|
||||
static unsigned long vm86_segment(u_char segment,
|
||||
struct address *addr)
|
||||
static unsigned long vm86_segment(u_char segment, struct address *addr)
|
||||
{
|
||||
segment--;
|
||||
segment--;
|
||||
#ifdef PARANOID
|
||||
if ( segment > PREFIX_SS_ )
|
||||
{
|
||||
EXCEPTION(EX_INTERNAL|0x130);
|
||||
math_abort(FPU_info,SIGSEGV);
|
||||
}
|
||||
if (segment > PREFIX_SS_) {
|
||||
EXCEPTION(EX_INTERNAL | 0x130);
|
||||
math_abort(FPU_info, SIGSEGV);
|
||||
}
|
||||
#endif /* PARANOID */
|
||||
addr->selector = VM86_REG_(segment);
|
||||
return (unsigned long)VM86_REG_(segment) << 4;
|
||||
addr->selector = VM86_REG_(segment);
|
||||
return (unsigned long)VM86_REG_(segment) << 4;
|
||||
}
|
||||
|
||||
|
||||
/* This should work for 16 and 32 bit protected mode. */
|
||||
static long pm_address(u_char FPU_modrm, u_char segment,
|
||||
struct address *addr, long offset)
|
||||
{
|
||||
struct desc_struct descriptor;
|
||||
unsigned long base_address, limit, address, seg_top;
|
||||
{
|
||||
struct desc_struct descriptor;
|
||||
unsigned long base_address, limit, address, seg_top;
|
||||
|
||||
segment--;
|
||||
segment--;
|
||||
|
||||
#ifdef PARANOID
|
||||
/* segment is unsigned, so this also detects if segment was 0: */
|
||||
if ( segment > PREFIX_SS_ )
|
||||
{
|
||||
EXCEPTION(EX_INTERNAL|0x132);
|
||||
math_abort(FPU_info,SIGSEGV);
|
||||
}
|
||||
/* segment is unsigned, so this also detects if segment was 0: */
|
||||
if (segment > PREFIX_SS_) {
|
||||
EXCEPTION(EX_INTERNAL | 0x132);
|
||||
math_abort(FPU_info, SIGSEGV);
|
||||
}
|
||||
#endif /* PARANOID */
|
||||
|
||||
switch ( segment )
|
||||
{
|
||||
/* gs isn't used by the kernel, so it still has its
|
||||
user-space value. */
|
||||
case PREFIX_GS_-1:
|
||||
/* N.B. - movl %seg, mem is a 2 byte write regardless of prefix */
|
||||
savesegment(gs, addr->selector);
|
||||
break;
|
||||
default:
|
||||
addr->selector = PM_REG_(segment);
|
||||
}
|
||||
|
||||
descriptor = LDT_DESCRIPTOR(PM_REG_(segment));
|
||||
base_address = SEG_BASE_ADDR(descriptor);
|
||||
address = base_address + offset;
|
||||
limit = base_address
|
||||
+ (SEG_LIMIT(descriptor)+1) * SEG_GRANULARITY(descriptor) - 1;
|
||||
if ( limit < base_address ) limit = 0xffffffff;
|
||||
|
||||
if ( SEG_EXPAND_DOWN(descriptor) )
|
||||
{
|
||||
if ( SEG_G_BIT(descriptor) )
|
||||
seg_top = 0xffffffff;
|
||||
else
|
||||
{
|
||||
seg_top = base_address + (1 << 20);
|
||||
if ( seg_top < base_address ) seg_top = 0xffffffff;
|
||||
switch (segment) {
|
||||
/* gs isn't used by the kernel, so it still has its
|
||||
user-space value. */
|
||||
case PREFIX_GS_ - 1:
|
||||
/* N.B. - movl %seg, mem is a 2 byte write regardless of prefix */
|
||||
savesegment(gs, addr->selector);
|
||||
break;
|
||||
default:
|
||||
addr->selector = PM_REG_(segment);
|
||||
}
|
||||
access_limit =
|
||||
(address <= limit) || (address >= seg_top) ? 0 :
|
||||
((seg_top-address) >= 255 ? 255 : seg_top-address);
|
||||
}
|
||||
else
|
||||
{
|
||||
access_limit =
|
||||
(address > limit) || (address < base_address) ? 0 :
|
||||
((limit-address) >= 254 ? 255 : limit-address+1);
|
||||
}
|
||||
if ( SEG_EXECUTE_ONLY(descriptor) ||
|
||||
(!SEG_WRITE_PERM(descriptor) && (FPU_modrm & FPU_WRITE_BIT)) )
|
||||
{
|
||||
access_limit = 0;
|
||||
}
|
||||
return address;
|
||||
}
|
||||
|
||||
descriptor = LDT_DESCRIPTOR(PM_REG_(segment));
|
||||
base_address = SEG_BASE_ADDR(descriptor);
|
||||
address = base_address + offset;
|
||||
limit = base_address
|
||||
+ (SEG_LIMIT(descriptor) + 1) * SEG_GRANULARITY(descriptor) - 1;
|
||||
if (limit < base_address)
|
||||
limit = 0xffffffff;
|
||||
|
||||
if (SEG_EXPAND_DOWN(descriptor)) {
|
||||
if (SEG_G_BIT(descriptor))
|
||||
seg_top = 0xffffffff;
|
||||
else {
|
||||
seg_top = base_address + (1 << 20);
|
||||
if (seg_top < base_address)
|
||||
seg_top = 0xffffffff;
|
||||
}
|
||||
access_limit =
|
||||
(address <= limit) || (address >= seg_top) ? 0 :
|
||||
((seg_top - address) >= 255 ? 255 : seg_top - address);
|
||||
} else {
|
||||
access_limit =
|
||||
(address > limit) || (address < base_address) ? 0 :
|
||||
((limit - address) >= 254 ? 255 : limit - address + 1);
|
||||
}
|
||||
if (SEG_EXECUTE_ONLY(descriptor) ||
|
||||
(!SEG_WRITE_PERM(descriptor) && (FPU_modrm & FPU_WRITE_BIT))) {
|
||||
access_limit = 0;
|
||||
}
|
||||
return address;
|
||||
}
|
||||
|
||||
/*
|
||||
MOD R/M byte: MOD == 3 has a special use for the FPU
|
||||
|
@ -221,7 +202,6 @@ static long pm_address(u_char FPU_modrm, u_char segment,
|
|||
..... ......... .........
|
||||
MOD OPCODE(2) R/M
|
||||
|
||||
|
||||
SIB byte
|
||||
|
||||
7 6 5 4 3 2 1 0
|
||||
|
@ -231,208 +211,194 @@ static long pm_address(u_char FPU_modrm, u_char segment,
|
|||
*/
|
||||
|
||||
void __user *FPU_get_address(u_char FPU_modrm, unsigned long *fpu_eip,
|
||||
struct address *addr,
|
||||
fpu_addr_modes addr_modes)
|
||||
struct address *addr, fpu_addr_modes addr_modes)
|
||||
{
|
||||
u_char mod;
|
||||
unsigned rm = FPU_modrm & 7;
|
||||
long *cpu_reg_ptr;
|
||||
int address = 0; /* Initialized just to stop compiler warnings. */
|
||||
u_char mod;
|
||||
unsigned rm = FPU_modrm & 7;
|
||||
long *cpu_reg_ptr;
|
||||
int address = 0; /* Initialized just to stop compiler warnings. */
|
||||
|
||||
/* Memory accessed via the cs selector is write protected
|
||||
in `non-segmented' 32 bit protected mode. */
|
||||
if ( !addr_modes.default_mode && (FPU_modrm & FPU_WRITE_BIT)
|
||||
&& (addr_modes.override.segment == PREFIX_CS_) )
|
||||
{
|
||||
math_abort(FPU_info,SIGSEGV);
|
||||
}
|
||||
|
||||
addr->selector = FPU_DS; /* Default, for 32 bit non-segmented mode. */
|
||||
|
||||
mod = (FPU_modrm >> 6) & 3;
|
||||
|
||||
if (rm == 4 && mod != 3)
|
||||
{
|
||||
address = sib(mod, fpu_eip);
|
||||
}
|
||||
else
|
||||
{
|
||||
cpu_reg_ptr = & REG_(rm);
|
||||
switch (mod)
|
||||
{
|
||||
case 0:
|
||||
if (rm == 5)
|
||||
{
|
||||
/* Special case: disp32 */
|
||||
RE_ENTRANT_CHECK_OFF;
|
||||
FPU_code_access_ok(4);
|
||||
FPU_get_user(address, (unsigned long __user *) (*fpu_eip));
|
||||
(*fpu_eip) += 4;
|
||||
RE_ENTRANT_CHECK_ON;
|
||||
addr->offset = address;
|
||||
return (void __user *) address;
|
||||
}
|
||||
else
|
||||
{
|
||||
address = *cpu_reg_ptr; /* Just return the contents
|
||||
of the cpu register */
|
||||
addr->offset = address;
|
||||
return (void __user *) address;
|
||||
}
|
||||
case 1:
|
||||
/* 8 bit signed displacement */
|
||||
RE_ENTRANT_CHECK_OFF;
|
||||
FPU_code_access_ok(1);
|
||||
FPU_get_user(address, (signed char __user *) (*fpu_eip));
|
||||
RE_ENTRANT_CHECK_ON;
|
||||
(*fpu_eip)++;
|
||||
break;
|
||||
case 2:
|
||||
/* 32 bit displacement */
|
||||
RE_ENTRANT_CHECK_OFF;
|
||||
FPU_code_access_ok(4);
|
||||
FPU_get_user(address, (long __user *) (*fpu_eip));
|
||||
(*fpu_eip) += 4;
|
||||
RE_ENTRANT_CHECK_ON;
|
||||
break;
|
||||
case 3:
|
||||
/* Not legal for the FPU */
|
||||
EXCEPTION(EX_Invalid);
|
||||
/* Memory accessed via the cs selector is write protected
|
||||
in `non-segmented' 32 bit protected mode. */
|
||||
if (!addr_modes.default_mode && (FPU_modrm & FPU_WRITE_BIT)
|
||||
&& (addr_modes.override.segment == PREFIX_CS_)) {
|
||||
math_abort(FPU_info, SIGSEGV);
|
||||
}
|
||||
address += *cpu_reg_ptr;
|
||||
}
|
||||
|
||||
addr->offset = address;
|
||||
addr->selector = FPU_DS; /* Default, for 32 bit non-segmented mode. */
|
||||
|
||||
switch ( addr_modes.default_mode )
|
||||
{
|
||||
case 0:
|
||||
break;
|
||||
case VM86:
|
||||
address += vm86_segment(addr_modes.override.segment, addr);
|
||||
break;
|
||||
case PM16:
|
||||
case SEG32:
|
||||
address = pm_address(FPU_modrm, addr_modes.override.segment,
|
||||
addr, address);
|
||||
break;
|
||||
default:
|
||||
EXCEPTION(EX_INTERNAL|0x133);
|
||||
}
|
||||
mod = (FPU_modrm >> 6) & 3;
|
||||
|
||||
return (void __user *)address;
|
||||
if (rm == 4 && mod != 3) {
|
||||
address = sib(mod, fpu_eip);
|
||||
} else {
|
||||
cpu_reg_ptr = ®_(rm);
|
||||
switch (mod) {
|
||||
case 0:
|
||||
if (rm == 5) {
|
||||
/* Special case: disp32 */
|
||||
RE_ENTRANT_CHECK_OFF;
|
||||
FPU_code_access_ok(4);
|
||||
FPU_get_user(address,
|
||||
(unsigned long __user
|
||||
*)(*fpu_eip));
|
||||
(*fpu_eip) += 4;
|
||||
RE_ENTRANT_CHECK_ON;
|
||||
addr->offset = address;
|
||||
return (void __user *)address;
|
||||
} else {
|
||||
address = *cpu_reg_ptr; /* Just return the contents
|
||||
of the cpu register */
|
||||
addr->offset = address;
|
||||
return (void __user *)address;
|
||||
}
|
||||
case 1:
|
||||
/* 8 bit signed displacement */
|
||||
RE_ENTRANT_CHECK_OFF;
|
||||
FPU_code_access_ok(1);
|
||||
FPU_get_user(address, (signed char __user *)(*fpu_eip));
|
||||
RE_ENTRANT_CHECK_ON;
|
||||
(*fpu_eip)++;
|
||||
break;
|
||||
case 2:
|
||||
/* 32 bit displacement */
|
||||
RE_ENTRANT_CHECK_OFF;
|
||||
FPU_code_access_ok(4);
|
||||
FPU_get_user(address, (long __user *)(*fpu_eip));
|
||||
(*fpu_eip) += 4;
|
||||
RE_ENTRANT_CHECK_ON;
|
||||
break;
|
||||
case 3:
|
||||
/* Not legal for the FPU */
|
||||
EXCEPTION(EX_Invalid);
|
||||
}
|
||||
address += *cpu_reg_ptr;
|
||||
}
|
||||
|
||||
addr->offset = address;
|
||||
|
||||
switch (addr_modes.default_mode) {
|
||||
case 0:
|
||||
break;
|
||||
case VM86:
|
||||
address += vm86_segment(addr_modes.override.segment, addr);
|
||||
break;
|
||||
case PM16:
|
||||
case SEG32:
|
||||
address = pm_address(FPU_modrm, addr_modes.override.segment,
|
||||
addr, address);
|
||||
break;
|
||||
default:
|
||||
EXCEPTION(EX_INTERNAL | 0x133);
|
||||
}
|
||||
|
||||
return (void __user *)address;
|
||||
}
|
||||
|
||||
|
||||
void __user *FPU_get_address_16(u_char FPU_modrm, unsigned long *fpu_eip,
|
||||
struct address *addr,
|
||||
fpu_addr_modes addr_modes)
|
||||
struct address *addr, fpu_addr_modes addr_modes)
|
||||
{
|
||||
u_char mod;
|
||||
unsigned rm = FPU_modrm & 7;
|
||||
int address = 0; /* Default used for mod == 0 */
|
||||
u_char mod;
|
||||
unsigned rm = FPU_modrm & 7;
|
||||
int address = 0; /* Default used for mod == 0 */
|
||||
|
||||
/* Memory accessed via the cs selector is write protected
|
||||
in `non-segmented' 32 bit protected mode. */
|
||||
if ( !addr_modes.default_mode && (FPU_modrm & FPU_WRITE_BIT)
|
||||
&& (addr_modes.override.segment == PREFIX_CS_) )
|
||||
{
|
||||
math_abort(FPU_info,SIGSEGV);
|
||||
}
|
||||
|
||||
addr->selector = FPU_DS; /* Default, for 32 bit non-segmented mode. */
|
||||
|
||||
mod = (FPU_modrm >> 6) & 3;
|
||||
|
||||
switch (mod)
|
||||
{
|
||||
case 0:
|
||||
if (rm == 6)
|
||||
{
|
||||
/* Special case: disp16 */
|
||||
RE_ENTRANT_CHECK_OFF;
|
||||
FPU_code_access_ok(2);
|
||||
FPU_get_user(address, (unsigned short __user *) (*fpu_eip));
|
||||
(*fpu_eip) += 2;
|
||||
RE_ENTRANT_CHECK_ON;
|
||||
goto add_segment;
|
||||
/* Memory accessed via the cs selector is write protected
|
||||
in `non-segmented' 32 bit protected mode. */
|
||||
if (!addr_modes.default_mode && (FPU_modrm & FPU_WRITE_BIT)
|
||||
&& (addr_modes.override.segment == PREFIX_CS_)) {
|
||||
math_abort(FPU_info, SIGSEGV);
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
/* 8 bit signed displacement */
|
||||
RE_ENTRANT_CHECK_OFF;
|
||||
FPU_code_access_ok(1);
|
||||
FPU_get_user(address, (signed char __user *) (*fpu_eip));
|
||||
RE_ENTRANT_CHECK_ON;
|
||||
(*fpu_eip)++;
|
||||
break;
|
||||
case 2:
|
||||
/* 16 bit displacement */
|
||||
RE_ENTRANT_CHECK_OFF;
|
||||
FPU_code_access_ok(2);
|
||||
FPU_get_user(address, (unsigned short __user *) (*fpu_eip));
|
||||
(*fpu_eip) += 2;
|
||||
RE_ENTRANT_CHECK_ON;
|
||||
break;
|
||||
case 3:
|
||||
/* Not legal for the FPU */
|
||||
EXCEPTION(EX_Invalid);
|
||||
break;
|
||||
}
|
||||
switch ( rm )
|
||||
{
|
||||
case 0:
|
||||
address += FPU_info->___ebx + FPU_info->___esi;
|
||||
break;
|
||||
case 1:
|
||||
address += FPU_info->___ebx + FPU_info->___edi;
|
||||
break;
|
||||
case 2:
|
||||
address += FPU_info->___ebp + FPU_info->___esi;
|
||||
if ( addr_modes.override.segment == PREFIX_DEFAULT )
|
||||
addr_modes.override.segment = PREFIX_SS_;
|
||||
break;
|
||||
case 3:
|
||||
address += FPU_info->___ebp + FPU_info->___edi;
|
||||
if ( addr_modes.override.segment == PREFIX_DEFAULT )
|
||||
addr_modes.override.segment = PREFIX_SS_;
|
||||
break;
|
||||
case 4:
|
||||
address += FPU_info->___esi;
|
||||
break;
|
||||
case 5:
|
||||
address += FPU_info->___edi;
|
||||
break;
|
||||
case 6:
|
||||
address += FPU_info->___ebp;
|
||||
if ( addr_modes.override.segment == PREFIX_DEFAULT )
|
||||
addr_modes.override.segment = PREFIX_SS_;
|
||||
break;
|
||||
case 7:
|
||||
address += FPU_info->___ebx;
|
||||
break;
|
||||
}
|
||||
|
||||
add_segment:
|
||||
address &= 0xffff;
|
||||
addr->selector = FPU_DS; /* Default, for 32 bit non-segmented mode. */
|
||||
|
||||
addr->offset = address;
|
||||
mod = (FPU_modrm >> 6) & 3;
|
||||
|
||||
switch ( addr_modes.default_mode )
|
||||
{
|
||||
case 0:
|
||||
break;
|
||||
case VM86:
|
||||
address += vm86_segment(addr_modes.override.segment, addr);
|
||||
break;
|
||||
case PM16:
|
||||
case SEG32:
|
||||
address = pm_address(FPU_modrm, addr_modes.override.segment,
|
||||
addr, address);
|
||||
break;
|
||||
default:
|
||||
EXCEPTION(EX_INTERNAL|0x131);
|
||||
}
|
||||
switch (mod) {
|
||||
case 0:
|
||||
if (rm == 6) {
|
||||
/* Special case: disp16 */
|
||||
RE_ENTRANT_CHECK_OFF;
|
||||
FPU_code_access_ok(2);
|
||||
FPU_get_user(address,
|
||||
(unsigned short __user *)(*fpu_eip));
|
||||
(*fpu_eip) += 2;
|
||||
RE_ENTRANT_CHECK_ON;
|
||||
goto add_segment;
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
/* 8 bit signed displacement */
|
||||
RE_ENTRANT_CHECK_OFF;
|
||||
FPU_code_access_ok(1);
|
||||
FPU_get_user(address, (signed char __user *)(*fpu_eip));
|
||||
RE_ENTRANT_CHECK_ON;
|
||||
(*fpu_eip)++;
|
||||
break;
|
||||
case 2:
|
||||
/* 16 bit displacement */
|
||||
RE_ENTRANT_CHECK_OFF;
|
||||
FPU_code_access_ok(2);
|
||||
FPU_get_user(address, (unsigned short __user *)(*fpu_eip));
|
||||
(*fpu_eip) += 2;
|
||||
RE_ENTRANT_CHECK_ON;
|
||||
break;
|
||||
case 3:
|
||||
/* Not legal for the FPU */
|
||||
EXCEPTION(EX_Invalid);
|
||||
break;
|
||||
}
|
||||
switch (rm) {
|
||||
case 0:
|
||||
address += FPU_info->___ebx + FPU_info->___esi;
|
||||
break;
|
||||
case 1:
|
||||
address += FPU_info->___ebx + FPU_info->___edi;
|
||||
break;
|
||||
case 2:
|
||||
address += FPU_info->___ebp + FPU_info->___esi;
|
||||
if (addr_modes.override.segment == PREFIX_DEFAULT)
|
||||
addr_modes.override.segment = PREFIX_SS_;
|
||||
break;
|
||||
case 3:
|
||||
address += FPU_info->___ebp + FPU_info->___edi;
|
||||
if (addr_modes.override.segment == PREFIX_DEFAULT)
|
||||
addr_modes.override.segment = PREFIX_SS_;
|
||||
break;
|
||||
case 4:
|
||||
address += FPU_info->___esi;
|
||||
break;
|
||||
case 5:
|
||||
address += FPU_info->___edi;
|
||||
break;
|
||||
case 6:
|
||||
address += FPU_info->___ebp;
|
||||
if (addr_modes.override.segment == PREFIX_DEFAULT)
|
||||
addr_modes.override.segment = PREFIX_SS_;
|
||||
break;
|
||||
case 7:
|
||||
address += FPU_info->___ebx;
|
||||
break;
|
||||
}
|
||||
|
||||
return (void __user *)address ;
|
||||
add_segment:
|
||||
address &= 0xffff;
|
||||
|
||||
addr->offset = address;
|
||||
|
||||
switch (addr_modes.default_mode) {
|
||||
case 0:
|
||||
break;
|
||||
case VM86:
|
||||
address += vm86_segment(addr_modes.override.segment, addr);
|
||||
break;
|
||||
case PM16:
|
||||
case SEG32:
|
||||
address = pm_address(FPU_modrm, addr_modes.override.segment,
|
||||
addr, address);
|
||||
break;
|
||||
default:
|
||||
EXCEPTION(EX_INTERNAL | 0x131);
|
||||
}
|
||||
|
||||
return (void __user *)address;
|
||||
}
|
||||
|
|
|
@ -26,247 +26,257 @@
|
|||
#include "status_w.h"
|
||||
#include "control_w.h"
|
||||
|
||||
|
||||
#define _NONE_ 0 /* st0_ptr etc not needed */
|
||||
#define _REG0_ 1 /* Will be storing st(0) */
|
||||
#define _PUSH_ 3 /* Need to check for space to push onto stack */
|
||||
#define _null_ 4 /* Function illegal or not implemented */
|
||||
#define _NONE_ 0 /* st0_ptr etc not needed */
|
||||
#define _REG0_ 1 /* Will be storing st(0) */
|
||||
#define _PUSH_ 3 /* Need to check for space to push onto stack */
|
||||
#define _null_ 4 /* Function illegal or not implemented */
|
||||
|
||||
#define pop_0() { FPU_settag0(TAG_Empty); top++; }
|
||||
|
||||
|
||||
static u_char const type_table[32] = {
|
||||
_PUSH_, _PUSH_, _PUSH_, _PUSH_,
|
||||
_null_, _null_, _null_, _null_,
|
||||
_REG0_, _REG0_, _REG0_, _REG0_,
|
||||
_REG0_, _REG0_, _REG0_, _REG0_,
|
||||
_NONE_, _null_, _NONE_, _PUSH_,
|
||||
_NONE_, _PUSH_, _null_, _PUSH_,
|
||||
_NONE_, _null_, _NONE_, _REG0_,
|
||||
_NONE_, _REG0_, _NONE_, _REG0_
|
||||
};
|
||||
_PUSH_, _PUSH_, _PUSH_, _PUSH_,
|
||||
_null_, _null_, _null_, _null_,
|
||||
_REG0_, _REG0_, _REG0_, _REG0_,
|
||||
_REG0_, _REG0_, _REG0_, _REG0_,
|
||||
_NONE_, _null_, _NONE_, _PUSH_,
|
||||
_NONE_, _PUSH_, _null_, _PUSH_,
|
||||
_NONE_, _null_, _NONE_, _REG0_,
|
||||
_NONE_, _REG0_, _NONE_, _REG0_
|
||||
};
|
||||
|
||||
u_char const data_sizes_16[32] = {
|
||||
4, 4, 8, 2, 0, 0, 0, 0,
|
||||
4, 4, 8, 2, 4, 4, 8, 2,
|
||||
14, 0, 94, 10, 2, 10, 0, 8,
|
||||
14, 0, 94, 10, 2, 10, 2, 8
|
||||
4, 4, 8, 2, 0, 0, 0, 0,
|
||||
4, 4, 8, 2, 4, 4, 8, 2,
|
||||
14, 0, 94, 10, 2, 10, 0, 8,
|
||||
14, 0, 94, 10, 2, 10, 2, 8
|
||||
};
|
||||
|
||||
static u_char const data_sizes_32[32] = {
|
||||
4, 4, 8, 2, 0, 0, 0, 0,
|
||||
4, 4, 8, 2, 4, 4, 8, 2,
|
||||
28, 0,108, 10, 2, 10, 0, 8,
|
||||
28, 0,108, 10, 2, 10, 2, 8
|
||||
4, 4, 8, 2, 0, 0, 0, 0,
|
||||
4, 4, 8, 2, 4, 4, 8, 2,
|
||||
28, 0, 108, 10, 2, 10, 0, 8,
|
||||
28, 0, 108, 10, 2, 10, 2, 8
|
||||
};
|
||||
|
||||
int FPU_load_store(u_char type, fpu_addr_modes addr_modes,
|
||||
void __user *data_address)
|
||||
void __user * data_address)
|
||||
{
|
||||
FPU_REG loaded_data;
|
||||
FPU_REG *st0_ptr;
|
||||
u_char st0_tag = TAG_Empty; /* This is just to stop a gcc warning. */
|
||||
u_char loaded_tag;
|
||||
FPU_REG loaded_data;
|
||||
FPU_REG *st0_ptr;
|
||||
u_char st0_tag = TAG_Empty; /* This is just to stop a gcc warning. */
|
||||
u_char loaded_tag;
|
||||
|
||||
st0_ptr = NULL; /* Initialized just to stop compiler warnings. */
|
||||
st0_ptr = NULL; /* Initialized just to stop compiler warnings. */
|
||||
|
||||
if ( addr_modes.default_mode & PROTECTED )
|
||||
{
|
||||
if ( addr_modes.default_mode == SEG32 )
|
||||
{
|
||||
if ( access_limit < data_sizes_32[type] )
|
||||
math_abort(FPU_info,SIGSEGV);
|
||||
}
|
||||
else if ( addr_modes.default_mode == PM16 )
|
||||
{
|
||||
if ( access_limit < data_sizes_16[type] )
|
||||
math_abort(FPU_info,SIGSEGV);
|
||||
}
|
||||
if (addr_modes.default_mode & PROTECTED) {
|
||||
if (addr_modes.default_mode == SEG32) {
|
||||
if (access_limit < data_sizes_32[type])
|
||||
math_abort(FPU_info, SIGSEGV);
|
||||
} else if (addr_modes.default_mode == PM16) {
|
||||
if (access_limit < data_sizes_16[type])
|
||||
math_abort(FPU_info, SIGSEGV);
|
||||
}
|
||||
#ifdef PARANOID
|
||||
else
|
||||
EXCEPTION(EX_INTERNAL|0x140);
|
||||
else
|
||||
EXCEPTION(EX_INTERNAL | 0x140);
|
||||
#endif /* PARANOID */
|
||||
}
|
||||
}
|
||||
|
||||
switch ( type_table[type] )
|
||||
{
|
||||
case _NONE_:
|
||||
break;
|
||||
case _REG0_:
|
||||
st0_ptr = &st(0); /* Some of these instructions pop after
|
||||
storing */
|
||||
st0_tag = FPU_gettag0();
|
||||
break;
|
||||
case _PUSH_:
|
||||
{
|
||||
if ( FPU_gettagi(-1) != TAG_Empty )
|
||||
{ FPU_stack_overflow(); return 0; }
|
||||
top--;
|
||||
st0_ptr = &st(0);
|
||||
}
|
||||
break;
|
||||
case _null_:
|
||||
FPU_illegal();
|
||||
return 0;
|
||||
switch (type_table[type]) {
|
||||
case _NONE_:
|
||||
break;
|
||||
case _REG0_:
|
||||
st0_ptr = &st(0); /* Some of these instructions pop after
|
||||
storing */
|
||||
st0_tag = FPU_gettag0();
|
||||
break;
|
||||
case _PUSH_:
|
||||
{
|
||||
if (FPU_gettagi(-1) != TAG_Empty) {
|
||||
FPU_stack_overflow();
|
||||
return 0;
|
||||
}
|
||||
top--;
|
||||
st0_ptr = &st(0);
|
||||
}
|
||||
break;
|
||||
case _null_:
|
||||
FPU_illegal();
|
||||
return 0;
|
||||
#ifdef PARANOID
|
||||
default:
|
||||
EXCEPTION(EX_INTERNAL|0x141);
|
||||
return 0;
|
||||
default:
|
||||
EXCEPTION(EX_INTERNAL | 0x141);
|
||||
return 0;
|
||||
#endif /* PARANOID */
|
||||
}
|
||||
}
|
||||
|
||||
switch ( type )
|
||||
{
|
||||
case 000: /* fld m32real */
|
||||
clear_C1();
|
||||
loaded_tag = FPU_load_single((float __user *)data_address, &loaded_data);
|
||||
if ( (loaded_tag == TAG_Special)
|
||||
&& isNaN(&loaded_data)
|
||||
&& (real_1op_NaN(&loaded_data) < 0) )
|
||||
{
|
||||
top++;
|
||||
break;
|
||||
}
|
||||
FPU_copy_to_reg0(&loaded_data, loaded_tag);
|
||||
break;
|
||||
case 001: /* fild m32int */
|
||||
clear_C1();
|
||||
loaded_tag = FPU_load_int32((long __user *)data_address, &loaded_data);
|
||||
FPU_copy_to_reg0(&loaded_data, loaded_tag);
|
||||
break;
|
||||
case 002: /* fld m64real */
|
||||
clear_C1();
|
||||
loaded_tag = FPU_load_double((double __user *)data_address, &loaded_data);
|
||||
if ( (loaded_tag == TAG_Special)
|
||||
&& isNaN(&loaded_data)
|
||||
&& (real_1op_NaN(&loaded_data) < 0) )
|
||||
{
|
||||
top++;
|
||||
break;
|
||||
}
|
||||
FPU_copy_to_reg0(&loaded_data, loaded_tag);
|
||||
break;
|
||||
case 003: /* fild m16int */
|
||||
clear_C1();
|
||||
loaded_tag = FPU_load_int16((short __user *)data_address, &loaded_data);
|
||||
FPU_copy_to_reg0(&loaded_data, loaded_tag);
|
||||
break;
|
||||
case 010: /* fst m32real */
|
||||
clear_C1();
|
||||
FPU_store_single(st0_ptr, st0_tag, (float __user *)data_address);
|
||||
break;
|
||||
case 011: /* fist m32int */
|
||||
clear_C1();
|
||||
FPU_store_int32(st0_ptr, st0_tag, (long __user *)data_address);
|
||||
break;
|
||||
case 012: /* fst m64real */
|
||||
clear_C1();
|
||||
FPU_store_double(st0_ptr, st0_tag, (double __user *)data_address);
|
||||
break;
|
||||
case 013: /* fist m16int */
|
||||
clear_C1();
|
||||
FPU_store_int16(st0_ptr, st0_tag, (short __user *)data_address);
|
||||
break;
|
||||
case 014: /* fstp m32real */
|
||||
clear_C1();
|
||||
if ( FPU_store_single(st0_ptr, st0_tag, (float __user *)data_address) )
|
||||
pop_0(); /* pop only if the number was actually stored
|
||||
(see the 80486 manual p16-28) */
|
||||
break;
|
||||
case 015: /* fistp m32int */
|
||||
clear_C1();
|
||||
if ( FPU_store_int32(st0_ptr, st0_tag, (long __user *)data_address) )
|
||||
pop_0(); /* pop only if the number was actually stored
|
||||
(see the 80486 manual p16-28) */
|
||||
break;
|
||||
case 016: /* fstp m64real */
|
||||
clear_C1();
|
||||
if ( FPU_store_double(st0_ptr, st0_tag, (double __user *)data_address) )
|
||||
pop_0(); /* pop only if the number was actually stored
|
||||
(see the 80486 manual p16-28) */
|
||||
break;
|
||||
case 017: /* fistp m16int */
|
||||
clear_C1();
|
||||
if ( FPU_store_int16(st0_ptr, st0_tag, (short __user *)data_address) )
|
||||
pop_0(); /* pop only if the number was actually stored
|
||||
(see the 80486 manual p16-28) */
|
||||
break;
|
||||
case 020: /* fldenv m14/28byte */
|
||||
fldenv(addr_modes, (u_char __user *)data_address);
|
||||
/* Ensure that the values just loaded are not changed by
|
||||
fix-up operations. */
|
||||
return 1;
|
||||
case 022: /* frstor m94/108byte */
|
||||
frstor(addr_modes, (u_char __user *)data_address);
|
||||
/* Ensure that the values just loaded are not changed by
|
||||
fix-up operations. */
|
||||
return 1;
|
||||
case 023: /* fbld m80dec */
|
||||
clear_C1();
|
||||
loaded_tag = FPU_load_bcd((u_char __user *)data_address);
|
||||
FPU_settag0(loaded_tag);
|
||||
break;
|
||||
case 024: /* fldcw */
|
||||
RE_ENTRANT_CHECK_OFF;
|
||||
FPU_access_ok(VERIFY_READ, data_address, 2);
|
||||
FPU_get_user(control_word, (unsigned short __user *) data_address);
|
||||
RE_ENTRANT_CHECK_ON;
|
||||
if ( partial_status & ~control_word & CW_Exceptions )
|
||||
partial_status |= (SW_Summary | SW_Backward);
|
||||
else
|
||||
partial_status &= ~(SW_Summary | SW_Backward);
|
||||
switch (type) {
|
||||
case 000: /* fld m32real */
|
||||
clear_C1();
|
||||
loaded_tag =
|
||||
FPU_load_single((float __user *)data_address, &loaded_data);
|
||||
if ((loaded_tag == TAG_Special)
|
||||
&& isNaN(&loaded_data)
|
||||
&& (real_1op_NaN(&loaded_data) < 0)) {
|
||||
top++;
|
||||
break;
|
||||
}
|
||||
FPU_copy_to_reg0(&loaded_data, loaded_tag);
|
||||
break;
|
||||
case 001: /* fild m32int */
|
||||
clear_C1();
|
||||
loaded_tag =
|
||||
FPU_load_int32((long __user *)data_address, &loaded_data);
|
||||
FPU_copy_to_reg0(&loaded_data, loaded_tag);
|
||||
break;
|
||||
case 002: /* fld m64real */
|
||||
clear_C1();
|
||||
loaded_tag =
|
||||
FPU_load_double((double __user *)data_address,
|
||||
&loaded_data);
|
||||
if ((loaded_tag == TAG_Special)
|
||||
&& isNaN(&loaded_data)
|
||||
&& (real_1op_NaN(&loaded_data) < 0)) {
|
||||
top++;
|
||||
break;
|
||||
}
|
||||
FPU_copy_to_reg0(&loaded_data, loaded_tag);
|
||||
break;
|
||||
case 003: /* fild m16int */
|
||||
clear_C1();
|
||||
loaded_tag =
|
||||
FPU_load_int16((short __user *)data_address, &loaded_data);
|
||||
FPU_copy_to_reg0(&loaded_data, loaded_tag);
|
||||
break;
|
||||
case 010: /* fst m32real */
|
||||
clear_C1();
|
||||
FPU_store_single(st0_ptr, st0_tag,
|
||||
(float __user *)data_address);
|
||||
break;
|
||||
case 011: /* fist m32int */
|
||||
clear_C1();
|
||||
FPU_store_int32(st0_ptr, st0_tag, (long __user *)data_address);
|
||||
break;
|
||||
case 012: /* fst m64real */
|
||||
clear_C1();
|
||||
FPU_store_double(st0_ptr, st0_tag,
|
||||
(double __user *)data_address);
|
||||
break;
|
||||
case 013: /* fist m16int */
|
||||
clear_C1();
|
||||
FPU_store_int16(st0_ptr, st0_tag, (short __user *)data_address);
|
||||
break;
|
||||
case 014: /* fstp m32real */
|
||||
clear_C1();
|
||||
if (FPU_store_single
|
||||
(st0_ptr, st0_tag, (float __user *)data_address))
|
||||
pop_0(); /* pop only if the number was actually stored
|
||||
(see the 80486 manual p16-28) */
|
||||
break;
|
||||
case 015: /* fistp m32int */
|
||||
clear_C1();
|
||||
if (FPU_store_int32
|
||||
(st0_ptr, st0_tag, (long __user *)data_address))
|
||||
pop_0(); /* pop only if the number was actually stored
|
||||
(see the 80486 manual p16-28) */
|
||||
break;
|
||||
case 016: /* fstp m64real */
|
||||
clear_C1();
|
||||
if (FPU_store_double
|
||||
(st0_ptr, st0_tag, (double __user *)data_address))
|
||||
pop_0(); /* pop only if the number was actually stored
|
||||
(see the 80486 manual p16-28) */
|
||||
break;
|
||||
case 017: /* fistp m16int */
|
||||
clear_C1();
|
||||
if (FPU_store_int16
|
||||
(st0_ptr, st0_tag, (short __user *)data_address))
|
||||
pop_0(); /* pop only if the number was actually stored
|
||||
(see the 80486 manual p16-28) */
|
||||
break;
|
||||
case 020: /* fldenv m14/28byte */
|
||||
fldenv(addr_modes, (u_char __user *) data_address);
|
||||
/* Ensure that the values just loaded are not changed by
|
||||
fix-up operations. */
|
||||
return 1;
|
||||
case 022: /* frstor m94/108byte */
|
||||
frstor(addr_modes, (u_char __user *) data_address);
|
||||
/* Ensure that the values just loaded are not changed by
|
||||
fix-up operations. */
|
||||
return 1;
|
||||
case 023: /* fbld m80dec */
|
||||
clear_C1();
|
||||
loaded_tag = FPU_load_bcd((u_char __user *) data_address);
|
||||
FPU_settag0(loaded_tag);
|
||||
break;
|
||||
case 024: /* fldcw */
|
||||
RE_ENTRANT_CHECK_OFF;
|
||||
FPU_access_ok(VERIFY_READ, data_address, 2);
|
||||
FPU_get_user(control_word,
|
||||
(unsigned short __user *)data_address);
|
||||
RE_ENTRANT_CHECK_ON;
|
||||
if (partial_status & ~control_word & CW_Exceptions)
|
||||
partial_status |= (SW_Summary | SW_Backward);
|
||||
else
|
||||
partial_status &= ~(SW_Summary | SW_Backward);
|
||||
#ifdef PECULIAR_486
|
||||
control_word |= 0x40; /* An 80486 appears to always set this bit */
|
||||
control_word |= 0x40; /* An 80486 appears to always set this bit */
|
||||
#endif /* PECULIAR_486 */
|
||||
return 1;
|
||||
case 025: /* fld m80real */
|
||||
clear_C1();
|
||||
loaded_tag = FPU_load_extended((long double __user *)data_address, 0);
|
||||
FPU_settag0(loaded_tag);
|
||||
break;
|
||||
case 027: /* fild m64int */
|
||||
clear_C1();
|
||||
loaded_tag = FPU_load_int64((long long __user *)data_address);
|
||||
if (loaded_tag == TAG_Error)
|
||||
return 1;
|
||||
case 025: /* fld m80real */
|
||||
clear_C1();
|
||||
loaded_tag =
|
||||
FPU_load_extended((long double __user *)data_address, 0);
|
||||
FPU_settag0(loaded_tag);
|
||||
break;
|
||||
case 027: /* fild m64int */
|
||||
clear_C1();
|
||||
loaded_tag = FPU_load_int64((long long __user *)data_address);
|
||||
if (loaded_tag == TAG_Error)
|
||||
return 0;
|
||||
FPU_settag0(loaded_tag);
|
||||
break;
|
||||
case 030: /* fstenv m14/28byte */
|
||||
fstenv(addr_modes, (u_char __user *) data_address);
|
||||
return 1;
|
||||
case 032: /* fsave */
|
||||
fsave(addr_modes, (u_char __user *) data_address);
|
||||
return 1;
|
||||
case 033: /* fbstp m80dec */
|
||||
clear_C1();
|
||||
if (FPU_store_bcd
|
||||
(st0_ptr, st0_tag, (u_char __user *) data_address))
|
||||
pop_0(); /* pop only if the number was actually stored
|
||||
(see the 80486 manual p16-28) */
|
||||
break;
|
||||
case 034: /* fstcw m16int */
|
||||
RE_ENTRANT_CHECK_OFF;
|
||||
FPU_access_ok(VERIFY_WRITE, data_address, 2);
|
||||
FPU_put_user(control_word,
|
||||
(unsigned short __user *)data_address);
|
||||
RE_ENTRANT_CHECK_ON;
|
||||
return 1;
|
||||
case 035: /* fstp m80real */
|
||||
clear_C1();
|
||||
if (FPU_store_extended
|
||||
(st0_ptr, st0_tag, (long double __user *)data_address))
|
||||
pop_0(); /* pop only if the number was actually stored
|
||||
(see the 80486 manual p16-28) */
|
||||
break;
|
||||
case 036: /* fstsw m2byte */
|
||||
RE_ENTRANT_CHECK_OFF;
|
||||
FPU_access_ok(VERIFY_WRITE, data_address, 2);
|
||||
FPU_put_user(status_word(),
|
||||
(unsigned short __user *)data_address);
|
||||
RE_ENTRANT_CHECK_ON;
|
||||
return 1;
|
||||
case 037: /* fistp m64int */
|
||||
clear_C1();
|
||||
if (FPU_store_int64
|
||||
(st0_ptr, st0_tag, (long long __user *)data_address))
|
||||
pop_0(); /* pop only if the number was actually stored
|
||||
(see the 80486 manual p16-28) */
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
FPU_settag0(loaded_tag);
|
||||
break;
|
||||
case 030: /* fstenv m14/28byte */
|
||||
fstenv(addr_modes, (u_char __user *)data_address);
|
||||
return 1;
|
||||
case 032: /* fsave */
|
||||
fsave(addr_modes, (u_char __user *)data_address);
|
||||
return 1;
|
||||
case 033: /* fbstp m80dec */
|
||||
clear_C1();
|
||||
if ( FPU_store_bcd(st0_ptr, st0_tag, (u_char __user *)data_address) )
|
||||
pop_0(); /* pop only if the number was actually stored
|
||||
(see the 80486 manual p16-28) */
|
||||
break;
|
||||
case 034: /* fstcw m16int */
|
||||
RE_ENTRANT_CHECK_OFF;
|
||||
FPU_access_ok(VERIFY_WRITE,data_address,2);
|
||||
FPU_put_user(control_word, (unsigned short __user *) data_address);
|
||||
RE_ENTRANT_CHECK_ON;
|
||||
return 1;
|
||||
case 035: /* fstp m80real */
|
||||
clear_C1();
|
||||
if ( FPU_store_extended(st0_ptr, st0_tag, (long double __user *)data_address) )
|
||||
pop_0(); /* pop only if the number was actually stored
|
||||
(see the 80486 manual p16-28) */
|
||||
break;
|
||||
case 036: /* fstsw m2byte */
|
||||
RE_ENTRANT_CHECK_OFF;
|
||||
FPU_access_ok(VERIFY_WRITE,data_address,2);
|
||||
FPU_put_user(status_word(),(unsigned short __user *) data_address);
|
||||
RE_ENTRANT_CHECK_ON;
|
||||
return 1;
|
||||
case 037: /* fistp m64int */
|
||||
clear_C1();
|
||||
if ( FPU_store_int64(st0_ptr, st0_tag, (long long __user *)data_address) )
|
||||
pop_0(); /* pop only if the number was actually stored
|
||||
(see the 80486 manual p16-28) */
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -21,9 +21,9 @@
|
|||
allows. 9-byte would probably be sufficient.
|
||||
*/
|
||||
typedef struct {
|
||||
unsigned long lsw;
|
||||
unsigned long midw;
|
||||
unsigned long msw;
|
||||
unsigned long lsw;
|
||||
unsigned long midw;
|
||||
unsigned long msw;
|
||||
} Xsig;
|
||||
|
||||
asmlinkage void mul64(unsigned long long const *a, unsigned long long const *b,
|
||||
|
@ -33,12 +33,12 @@ asmlinkage void polynomial_Xsig(Xsig *, const unsigned long long *x,
|
|||
|
||||
asmlinkage void mul32_Xsig(Xsig *, const unsigned long mult);
|
||||
asmlinkage void mul64_Xsig(Xsig *, const unsigned long long *mult);
|
||||
asmlinkage void mul_Xsig_Xsig(Xsig *dest, const Xsig *mult);
|
||||
asmlinkage void mul_Xsig_Xsig(Xsig * dest, const Xsig * mult);
|
||||
|
||||
asmlinkage void shr_Xsig(Xsig *, const int n);
|
||||
asmlinkage int round_Xsig(Xsig *);
|
||||
asmlinkage int norm_Xsig(Xsig *);
|
||||
asmlinkage void div_Xsig(Xsig *x1, const Xsig *x2, const Xsig *dest);
|
||||
asmlinkage void div_Xsig(Xsig * x1, const Xsig * x2, const Xsig * dest);
|
||||
|
||||
/* Macro to extract the most significant 32 bits from a long long */
|
||||
#define LL_MSW(x) (((unsigned long *)&x)[1])
|
||||
|
@ -49,7 +49,6 @@ asmlinkage void div_Xsig(Xsig *x1, const Xsig *x2, const Xsig *dest);
|
|||
/* Macro to access the 8 ms bytes of an Xsig as a long long */
|
||||
#define XSIG_LL(x) (*(unsigned long long *)&x.midw)
|
||||
|
||||
|
||||
/*
|
||||
Need to run gcc with optimizations on to get these to
|
||||
actually be in-line.
|
||||
|
@ -63,59 +62,53 @@ asmlinkage void div_Xsig(Xsig *x1, const Xsig *x2, const Xsig *dest);
|
|||
static inline unsigned long mul_32_32(const unsigned long arg1,
|
||||
const unsigned long arg2)
|
||||
{
|
||||
int retval;
|
||||
asm volatile ("mull %2; movl %%edx,%%eax" \
|
||||
:"=a" (retval) \
|
||||
:"0" (arg1), "g" (arg2) \
|
||||
:"dx");
|
||||
return retval;
|
||||
int retval;
|
||||
asm volatile ("mull %2; movl %%edx,%%eax":"=a" (retval)
|
||||
:"0"(arg1), "g"(arg2)
|
||||
:"dx");
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
||||
/* Add the 12 byte Xsig x2 to Xsig dest, with no checks for overflow. */
|
||||
static inline void add_Xsig_Xsig(Xsig *dest, const Xsig *x2)
|
||||
static inline void add_Xsig_Xsig(Xsig * dest, const Xsig * x2)
|
||||
{
|
||||
asm volatile ("movl %1,%%edi; movl %2,%%esi;\n"
|
||||
"movl (%%esi),%%eax; addl %%eax,(%%edi);\n"
|
||||
"movl 4(%%esi),%%eax; adcl %%eax,4(%%edi);\n"
|
||||
"movl 8(%%esi),%%eax; adcl %%eax,8(%%edi);\n"
|
||||
:"=g" (*dest):"g" (dest), "g" (x2)
|
||||
:"ax","si","di");
|
||||
asm volatile ("movl %1,%%edi; movl %2,%%esi;\n"
|
||||
"movl (%%esi),%%eax; addl %%eax,(%%edi);\n"
|
||||
"movl 4(%%esi),%%eax; adcl %%eax,4(%%edi);\n"
|
||||
"movl 8(%%esi),%%eax; adcl %%eax,8(%%edi);\n":"=g"
|
||||
(*dest):"g"(dest), "g"(x2)
|
||||
:"ax", "si", "di");
|
||||
}
|
||||
|
||||
|
||||
/* Add the 12 byte Xsig x2 to Xsig dest, adjust exp if overflow occurs. */
|
||||
/* Note: the constraints in the asm statement didn't always work properly
|
||||
with gcc 2.5.8. Changing from using edi to using ecx got around the
|
||||
problem, but keep fingers crossed! */
|
||||
static inline void add_two_Xsig(Xsig *dest, const Xsig *x2, long int *exp)
|
||||
static inline void add_two_Xsig(Xsig * dest, const Xsig * x2, long int *exp)
|
||||
{
|
||||
asm volatile ("movl %2,%%ecx; movl %3,%%esi;\n"
|
||||
"movl (%%esi),%%eax; addl %%eax,(%%ecx);\n"
|
||||
"movl 4(%%esi),%%eax; adcl %%eax,4(%%ecx);\n"
|
||||
"movl 8(%%esi),%%eax; adcl %%eax,8(%%ecx);\n"
|
||||
"jnc 0f;\n"
|
||||
"rcrl 8(%%ecx); rcrl 4(%%ecx); rcrl (%%ecx)\n"
|
||||
"movl %4,%%ecx; incl (%%ecx)\n"
|
||||
"movl $1,%%eax; jmp 1f;\n"
|
||||
"0: xorl %%eax,%%eax;\n"
|
||||
"1:\n"
|
||||
:"=g" (*exp), "=g" (*dest)
|
||||
:"g" (dest), "g" (x2), "g" (exp)
|
||||
:"cx","si","ax");
|
||||
asm volatile ("movl %2,%%ecx; movl %3,%%esi;\n"
|
||||
"movl (%%esi),%%eax; addl %%eax,(%%ecx);\n"
|
||||
"movl 4(%%esi),%%eax; adcl %%eax,4(%%ecx);\n"
|
||||
"movl 8(%%esi),%%eax; adcl %%eax,8(%%ecx);\n"
|
||||
"jnc 0f;\n"
|
||||
"rcrl 8(%%ecx); rcrl 4(%%ecx); rcrl (%%ecx)\n"
|
||||
"movl %4,%%ecx; incl (%%ecx)\n"
|
||||
"movl $1,%%eax; jmp 1f;\n"
|
||||
"0: xorl %%eax,%%eax;\n" "1:\n":"=g" (*exp), "=g"(*dest)
|
||||
:"g"(dest), "g"(x2), "g"(exp)
|
||||
:"cx", "si", "ax");
|
||||
}
|
||||
|
||||
|
||||
/* Negate (subtract from 1.0) the 12 byte Xsig */
|
||||
/* This is faster in a loop on my 386 than using the "neg" instruction. */
|
||||
static inline void negate_Xsig(Xsig *x)
|
||||
static inline void negate_Xsig(Xsig * x)
|
||||
{
|
||||
asm volatile("movl %1,%%esi;\n"
|
||||
"xorl %%ecx,%%ecx;\n"
|
||||
"movl %%ecx,%%eax; subl (%%esi),%%eax; movl %%eax,(%%esi);\n"
|
||||
"movl %%ecx,%%eax; sbbl 4(%%esi),%%eax; movl %%eax,4(%%esi);\n"
|
||||
"movl %%ecx,%%eax; sbbl 8(%%esi),%%eax; movl %%eax,8(%%esi);\n"
|
||||
:"=g" (*x):"g" (x):"si","ax","cx");
|
||||
asm volatile ("movl %1,%%esi;\n"
|
||||
"xorl %%ecx,%%ecx;\n"
|
||||
"movl %%ecx,%%eax; subl (%%esi),%%eax; movl %%eax,(%%esi);\n"
|
||||
"movl %%ecx,%%eax; sbbl 4(%%esi),%%eax; movl %%eax,4(%%esi);\n"
|
||||
"movl %%ecx,%%eax; sbbl 8(%%esi),%%eax; movl %%eax,8(%%esi);\n":"=g"
|
||||
(*x):"g"(x):"si", "ax", "cx");
|
||||
}
|
||||
|
||||
#endif /* _POLY_H */
|
||||
|
|
|
@ -17,21 +17,19 @@
|
|||
#include "control_w.h"
|
||||
#include "poly.h"
|
||||
|
||||
|
||||
#define HIPOWER 11
|
||||
static const unsigned long long lterms[HIPOWER] =
|
||||
{
|
||||
0x0000000000000000LL, /* This term done separately as 12 bytes */
|
||||
0xf5fdeffc162c7543LL,
|
||||
0x1c6b08d704a0bfa6LL,
|
||||
0x0276556df749cc21LL,
|
||||
0x002bb0ffcf14f6b8LL,
|
||||
0x0002861225ef751cLL,
|
||||
0x00001ffcbfcd5422LL,
|
||||
0x00000162c005d5f1LL,
|
||||
0x0000000da96ccb1bLL,
|
||||
0x0000000078d1b897LL,
|
||||
0x000000000422b029LL
|
||||
static const unsigned long long lterms[HIPOWER] = {
|
||||
0x0000000000000000LL, /* This term done separately as 12 bytes */
|
||||
0xf5fdeffc162c7543LL,
|
||||
0x1c6b08d704a0bfa6LL,
|
||||
0x0276556df749cc21LL,
|
||||
0x002bb0ffcf14f6b8LL,
|
||||
0x0002861225ef751cLL,
|
||||
0x00001ffcbfcd5422LL,
|
||||
0x00000162c005d5f1LL,
|
||||
0x0000000da96ccb1bLL,
|
||||
0x0000000078d1b897LL,
|
||||
0x000000000422b029LL
|
||||
};
|
||||
|
||||
static const Xsig hiterm = MK_XSIG(0xb17217f7, 0xd1cf79ab, 0xc8a39194);
|
||||
|
@ -45,112 +43,103 @@ static const Xsig shiftterm2 = MK_XSIG(0xb504f333, 0xf9de6484, 0x597d89b3);
|
|||
static const Xsig shiftterm3 = MK_XSIG(0xd744fcca, 0xd69d6af4, 0x39a68bb9);
|
||||
|
||||
static const Xsig *shiftterm[] = { &shiftterm0, &shiftterm1,
|
||||
&shiftterm2, &shiftterm3 };
|
||||
|
||||
&shiftterm2, &shiftterm3
|
||||
};
|
||||
|
||||
/*--- poly_2xm1() -----------------------------------------------------------+
|
||||
| Requires st(0) which is TAG_Valid and < 1. |
|
||||
+---------------------------------------------------------------------------*/
|
||||
int poly_2xm1(u_char sign, FPU_REG *arg, FPU_REG *result)
|
||||
int poly_2xm1(u_char sign, FPU_REG * arg, FPU_REG * result)
|
||||
{
|
||||
long int exponent, shift;
|
||||
unsigned long long Xll;
|
||||
Xsig accumulator, Denom, argSignif;
|
||||
u_char tag;
|
||||
long int exponent, shift;
|
||||
unsigned long long Xll;
|
||||
Xsig accumulator, Denom, argSignif;
|
||||
u_char tag;
|
||||
|
||||
exponent = exponent16(arg);
|
||||
exponent = exponent16(arg);
|
||||
|
||||
#ifdef PARANOID
|
||||
if ( exponent >= 0 ) /* Don't want a |number| >= 1.0 */
|
||||
{
|
||||
/* Number negative, too large, or not Valid. */
|
||||
EXCEPTION(EX_INTERNAL|0x127);
|
||||
return 1;
|
||||
}
|
||||
if (exponent >= 0) { /* Don't want a |number| >= 1.0 */
|
||||
/* Number negative, too large, or not Valid. */
|
||||
EXCEPTION(EX_INTERNAL | 0x127);
|
||||
return 1;
|
||||
}
|
||||
#endif /* PARANOID */
|
||||
|
||||
argSignif.lsw = 0;
|
||||
XSIG_LL(argSignif) = Xll = significand(arg);
|
||||
argSignif.lsw = 0;
|
||||
XSIG_LL(argSignif) = Xll = significand(arg);
|
||||
|
||||
if ( exponent == -1 )
|
||||
{
|
||||
shift = (argSignif.msw & 0x40000000) ? 3 : 2;
|
||||
/* subtract 0.5 or 0.75 */
|
||||
exponent -= 2;
|
||||
XSIG_LL(argSignif) <<= 2;
|
||||
Xll <<= 2;
|
||||
}
|
||||
else if ( exponent == -2 )
|
||||
{
|
||||
shift = 1;
|
||||
/* subtract 0.25 */
|
||||
exponent--;
|
||||
XSIG_LL(argSignif) <<= 1;
|
||||
Xll <<= 1;
|
||||
}
|
||||
else
|
||||
shift = 0;
|
||||
if (exponent == -1) {
|
||||
shift = (argSignif.msw & 0x40000000) ? 3 : 2;
|
||||
/* subtract 0.5 or 0.75 */
|
||||
exponent -= 2;
|
||||
XSIG_LL(argSignif) <<= 2;
|
||||
Xll <<= 2;
|
||||
} else if (exponent == -2) {
|
||||
shift = 1;
|
||||
/* subtract 0.25 */
|
||||
exponent--;
|
||||
XSIG_LL(argSignif) <<= 1;
|
||||
Xll <<= 1;
|
||||
} else
|
||||
shift = 0;
|
||||
|
||||
if ( exponent < -2 )
|
||||
{
|
||||
/* Shift the argument right by the required places. */
|
||||
if ( FPU_shrx(&Xll, -2-exponent) >= 0x80000000U )
|
||||
Xll++; /* round up */
|
||||
}
|
||||
|
||||
accumulator.lsw = accumulator.midw = accumulator.msw = 0;
|
||||
polynomial_Xsig(&accumulator, &Xll, lterms, HIPOWER-1);
|
||||
mul_Xsig_Xsig(&accumulator, &argSignif);
|
||||
shr_Xsig(&accumulator, 3);
|
||||
|
||||
mul_Xsig_Xsig(&argSignif, &hiterm); /* The leading term */
|
||||
add_two_Xsig(&accumulator, &argSignif, &exponent);
|
||||
|
||||
if ( shift )
|
||||
{
|
||||
/* The argument is large, use the identity:
|
||||
f(x+a) = f(a) * (f(x) + 1) - 1;
|
||||
*/
|
||||
shr_Xsig(&accumulator, - exponent);
|
||||
accumulator.msw |= 0x80000000; /* add 1.0 */
|
||||
mul_Xsig_Xsig(&accumulator, shiftterm[shift]);
|
||||
accumulator.msw &= 0x3fffffff; /* subtract 1.0 */
|
||||
exponent = 1;
|
||||
}
|
||||
|
||||
if ( sign != SIGN_POS )
|
||||
{
|
||||
/* The argument is negative, use the identity:
|
||||
f(-x) = -f(x) / (1 + f(x))
|
||||
*/
|
||||
Denom.lsw = accumulator.lsw;
|
||||
XSIG_LL(Denom) = XSIG_LL(accumulator);
|
||||
if ( exponent < 0 )
|
||||
shr_Xsig(&Denom, - exponent);
|
||||
else if ( exponent > 0 )
|
||||
{
|
||||
/* exponent must be 1 here */
|
||||
XSIG_LL(Denom) <<= 1;
|
||||
if ( Denom.lsw & 0x80000000 )
|
||||
XSIG_LL(Denom) |= 1;
|
||||
(Denom.lsw) <<= 1;
|
||||
if (exponent < -2) {
|
||||
/* Shift the argument right by the required places. */
|
||||
if (FPU_shrx(&Xll, -2 - exponent) >= 0x80000000U)
|
||||
Xll++; /* round up */
|
||||
}
|
||||
Denom.msw |= 0x80000000; /* add 1.0 */
|
||||
div_Xsig(&accumulator, &Denom, &accumulator);
|
||||
}
|
||||
|
||||
/* Convert to 64 bit signed-compatible */
|
||||
exponent += round_Xsig(&accumulator);
|
||||
accumulator.lsw = accumulator.midw = accumulator.msw = 0;
|
||||
polynomial_Xsig(&accumulator, &Xll, lterms, HIPOWER - 1);
|
||||
mul_Xsig_Xsig(&accumulator, &argSignif);
|
||||
shr_Xsig(&accumulator, 3);
|
||||
|
||||
result = &st(0);
|
||||
significand(result) = XSIG_LL(accumulator);
|
||||
setexponent16(result, exponent);
|
||||
mul_Xsig_Xsig(&argSignif, &hiterm); /* The leading term */
|
||||
add_two_Xsig(&accumulator, &argSignif, &exponent);
|
||||
|
||||
tag = FPU_round(result, 1, 0, FULL_PRECISION, sign);
|
||||
if (shift) {
|
||||
/* The argument is large, use the identity:
|
||||
f(x+a) = f(a) * (f(x) + 1) - 1;
|
||||
*/
|
||||
shr_Xsig(&accumulator, -exponent);
|
||||
accumulator.msw |= 0x80000000; /* add 1.0 */
|
||||
mul_Xsig_Xsig(&accumulator, shiftterm[shift]);
|
||||
accumulator.msw &= 0x3fffffff; /* subtract 1.0 */
|
||||
exponent = 1;
|
||||
}
|
||||
|
||||
setsign(result, sign);
|
||||
FPU_settag0(tag);
|
||||
if (sign != SIGN_POS) {
|
||||
/* The argument is negative, use the identity:
|
||||
f(-x) = -f(x) / (1 + f(x))
|
||||
*/
|
||||
Denom.lsw = accumulator.lsw;
|
||||
XSIG_LL(Denom) = XSIG_LL(accumulator);
|
||||
if (exponent < 0)
|
||||
shr_Xsig(&Denom, -exponent);
|
||||
else if (exponent > 0) {
|
||||
/* exponent must be 1 here */
|
||||
XSIG_LL(Denom) <<= 1;
|
||||
if (Denom.lsw & 0x80000000)
|
||||
XSIG_LL(Denom) |= 1;
|
||||
(Denom.lsw) <<= 1;
|
||||
}
|
||||
Denom.msw |= 0x80000000; /* add 1.0 */
|
||||
div_Xsig(&accumulator, &Denom, &accumulator);
|
||||
}
|
||||
|
||||
return 0;
|
||||
/* Convert to 64 bit signed-compatible */
|
||||
exponent += round_Xsig(&accumulator);
|
||||
|
||||
result = &st(0);
|
||||
significand(result) = XSIG_LL(accumulator);
|
||||
setexponent16(result, exponent);
|
||||
|
||||
tag = FPU_round(result, 1, 0, FULL_PRECISION, sign);
|
||||
|
||||
setsign(result, sign);
|
||||
FPU_settag0(tag);
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
|
|
@ -18,28 +18,25 @@
|
|||
#include "control_w.h"
|
||||
#include "poly.h"
|
||||
|
||||
|
||||
#define HIPOWERon 6 /* odd poly, negative terms */
|
||||
static const unsigned long long oddnegterms[HIPOWERon] =
|
||||
{
|
||||
0x0000000000000000LL, /* Dummy (not for - 1.0) */
|
||||
0x015328437f756467LL,
|
||||
0x0005dda27b73dec6LL,
|
||||
0x0000226bf2bfb91aLL,
|
||||
0x000000ccc439c5f7LL,
|
||||
0x0000000355438407LL
|
||||
} ;
|
||||
static const unsigned long long oddnegterms[HIPOWERon] = {
|
||||
0x0000000000000000LL, /* Dummy (not for - 1.0) */
|
||||
0x015328437f756467LL,
|
||||
0x0005dda27b73dec6LL,
|
||||
0x0000226bf2bfb91aLL,
|
||||
0x000000ccc439c5f7LL,
|
||||
0x0000000355438407LL
|
||||
};
|
||||
|
||||
#define HIPOWERop 6 /* odd poly, positive terms */
|
||||
static const unsigned long long oddplterms[HIPOWERop] =
|
||||
{
|
||||
static const unsigned long long oddplterms[HIPOWERop] = {
|
||||
/* 0xaaaaaaaaaaaaaaabLL, transferred to fixedpterm[] */
|
||||
0x0db55a71875c9ac2LL,
|
||||
0x0029fce2d67880b0LL,
|
||||
0x0000dfd3908b4596LL,
|
||||
0x00000550fd61dab4LL,
|
||||
0x0000001c9422b3f9LL,
|
||||
0x000000003e3301e1LL
|
||||
0x0db55a71875c9ac2LL,
|
||||
0x0029fce2d67880b0LL,
|
||||
0x0000dfd3908b4596LL,
|
||||
0x00000550fd61dab4LL,
|
||||
0x0000001c9422b3f9LL,
|
||||
0x000000003e3301e1LL
|
||||
};
|
||||
|
||||
static const unsigned long long denomterm = 0xebd9b842c5c53a0eLL;
|
||||
|
@ -48,182 +45,164 @@ static const Xsig fixedpterm = MK_XSIG(0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa);
|
|||
|
||||
static const Xsig pi_signif = MK_XSIG(0xc90fdaa2, 0x2168c234, 0xc4c6628b);
|
||||
|
||||
|
||||
/*--- poly_atan() -----------------------------------------------------------+
|
||||
| |
|
||||
+---------------------------------------------------------------------------*/
|
||||
void poly_atan(FPU_REG *st0_ptr, u_char st0_tag,
|
||||
FPU_REG *st1_ptr, u_char st1_tag)
|
||||
void poly_atan(FPU_REG * st0_ptr, u_char st0_tag,
|
||||
FPU_REG * st1_ptr, u_char st1_tag)
|
||||
{
|
||||
u_char transformed, inverted,
|
||||
sign1, sign2;
|
||||
int exponent;
|
||||
long int dummy_exp;
|
||||
Xsig accumulator, Numer, Denom, accumulatore, argSignif,
|
||||
argSq, argSqSq;
|
||||
u_char tag;
|
||||
|
||||
sign1 = getsign(st0_ptr);
|
||||
sign2 = getsign(st1_ptr);
|
||||
if ( st0_tag == TAG_Valid )
|
||||
{
|
||||
exponent = exponent(st0_ptr);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* This gives non-compatible stack contents... */
|
||||
FPU_to_exp16(st0_ptr, st0_ptr);
|
||||
exponent = exponent16(st0_ptr);
|
||||
}
|
||||
if ( st1_tag == TAG_Valid )
|
||||
{
|
||||
exponent -= exponent(st1_ptr);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* This gives non-compatible stack contents... */
|
||||
FPU_to_exp16(st1_ptr, st1_ptr);
|
||||
exponent -= exponent16(st1_ptr);
|
||||
}
|
||||
u_char transformed, inverted, sign1, sign2;
|
||||
int exponent;
|
||||
long int dummy_exp;
|
||||
Xsig accumulator, Numer, Denom, accumulatore, argSignif, argSq, argSqSq;
|
||||
u_char tag;
|
||||
|
||||
if ( (exponent < 0) || ((exponent == 0) &&
|
||||
((st0_ptr->sigh < st1_ptr->sigh) ||
|
||||
((st0_ptr->sigh == st1_ptr->sigh) &&
|
||||
(st0_ptr->sigl < st1_ptr->sigl))) ) )
|
||||
{
|
||||
inverted = 1;
|
||||
Numer.lsw = Denom.lsw = 0;
|
||||
XSIG_LL(Numer) = significand(st0_ptr);
|
||||
XSIG_LL(Denom) = significand(st1_ptr);
|
||||
}
|
||||
else
|
||||
{
|
||||
inverted = 0;
|
||||
exponent = -exponent;
|
||||
Numer.lsw = Denom.lsw = 0;
|
||||
XSIG_LL(Numer) = significand(st1_ptr);
|
||||
XSIG_LL(Denom) = significand(st0_ptr);
|
||||
}
|
||||
div_Xsig(&Numer, &Denom, &argSignif);
|
||||
exponent += norm_Xsig(&argSignif);
|
||||
sign1 = getsign(st0_ptr);
|
||||
sign2 = getsign(st1_ptr);
|
||||
if (st0_tag == TAG_Valid) {
|
||||
exponent = exponent(st0_ptr);
|
||||
} else {
|
||||
/* This gives non-compatible stack contents... */
|
||||
FPU_to_exp16(st0_ptr, st0_ptr);
|
||||
exponent = exponent16(st0_ptr);
|
||||
}
|
||||
if (st1_tag == TAG_Valid) {
|
||||
exponent -= exponent(st1_ptr);
|
||||
} else {
|
||||
/* This gives non-compatible stack contents... */
|
||||
FPU_to_exp16(st1_ptr, st1_ptr);
|
||||
exponent -= exponent16(st1_ptr);
|
||||
}
|
||||
|
||||
if ( (exponent >= -1)
|
||||
|| ((exponent == -2) && (argSignif.msw > 0xd413ccd0)) )
|
||||
{
|
||||
/* The argument is greater than sqrt(2)-1 (=0.414213562...) */
|
||||
/* Convert the argument by an identity for atan */
|
||||
transformed = 1;
|
||||
if ((exponent < 0) || ((exponent == 0) &&
|
||||
((st0_ptr->sigh < st1_ptr->sigh) ||
|
||||
((st0_ptr->sigh == st1_ptr->sigh) &&
|
||||
(st0_ptr->sigl < st1_ptr->sigl))))) {
|
||||
inverted = 1;
|
||||
Numer.lsw = Denom.lsw = 0;
|
||||
XSIG_LL(Numer) = significand(st0_ptr);
|
||||
XSIG_LL(Denom) = significand(st1_ptr);
|
||||
} else {
|
||||
inverted = 0;
|
||||
exponent = -exponent;
|
||||
Numer.lsw = Denom.lsw = 0;
|
||||
XSIG_LL(Numer) = significand(st1_ptr);
|
||||
XSIG_LL(Denom) = significand(st0_ptr);
|
||||
}
|
||||
div_Xsig(&Numer, &Denom, &argSignif);
|
||||
exponent += norm_Xsig(&argSignif);
|
||||
|
||||
if ( exponent >= 0 )
|
||||
{
|
||||
if ((exponent >= -1)
|
||||
|| ((exponent == -2) && (argSignif.msw > 0xd413ccd0))) {
|
||||
/* The argument is greater than sqrt(2)-1 (=0.414213562...) */
|
||||
/* Convert the argument by an identity for atan */
|
||||
transformed = 1;
|
||||
|
||||
if (exponent >= 0) {
|
||||
#ifdef PARANOID
|
||||
if ( !( (exponent == 0) &&
|
||||
(argSignif.lsw == 0) && (argSignif.midw == 0) &&
|
||||
(argSignif.msw == 0x80000000) ) )
|
||||
{
|
||||
EXCEPTION(EX_INTERNAL|0x104); /* There must be a logic error */
|
||||
return;
|
||||
}
|
||||
if (!((exponent == 0) &&
|
||||
(argSignif.lsw == 0) && (argSignif.midw == 0) &&
|
||||
(argSignif.msw == 0x80000000))) {
|
||||
EXCEPTION(EX_INTERNAL | 0x104); /* There must be a logic error */
|
||||
return;
|
||||
}
|
||||
#endif /* PARANOID */
|
||||
argSignif.msw = 0; /* Make the transformed arg -> 0.0 */
|
||||
argSignif.msw = 0; /* Make the transformed arg -> 0.0 */
|
||||
} else {
|
||||
Numer.lsw = Denom.lsw = argSignif.lsw;
|
||||
XSIG_LL(Numer) = XSIG_LL(Denom) = XSIG_LL(argSignif);
|
||||
|
||||
if (exponent < -1)
|
||||
shr_Xsig(&Numer, -1 - exponent);
|
||||
negate_Xsig(&Numer);
|
||||
|
||||
shr_Xsig(&Denom, -exponent);
|
||||
Denom.msw |= 0x80000000;
|
||||
|
||||
div_Xsig(&Numer, &Denom, &argSignif);
|
||||
|
||||
exponent = -1 + norm_Xsig(&argSignif);
|
||||
}
|
||||
} else {
|
||||
transformed = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
Numer.lsw = Denom.lsw = argSignif.lsw;
|
||||
XSIG_LL(Numer) = XSIG_LL(Denom) = XSIG_LL(argSignif);
|
||||
|
||||
if ( exponent < -1 )
|
||||
shr_Xsig(&Numer, -1-exponent);
|
||||
negate_Xsig(&Numer);
|
||||
|
||||
shr_Xsig(&Denom, -exponent);
|
||||
Denom.msw |= 0x80000000;
|
||||
|
||||
div_Xsig(&Numer, &Denom, &argSignif);
|
||||
argSq.lsw = argSignif.lsw;
|
||||
argSq.midw = argSignif.midw;
|
||||
argSq.msw = argSignif.msw;
|
||||
mul_Xsig_Xsig(&argSq, &argSq);
|
||||
|
||||
exponent = -1 + norm_Xsig(&argSignif);
|
||||
argSqSq.lsw = argSq.lsw;
|
||||
argSqSq.midw = argSq.midw;
|
||||
argSqSq.msw = argSq.msw;
|
||||
mul_Xsig_Xsig(&argSqSq, &argSqSq);
|
||||
|
||||
accumulatore.lsw = argSq.lsw;
|
||||
XSIG_LL(accumulatore) = XSIG_LL(argSq);
|
||||
|
||||
shr_Xsig(&argSq, 2 * (-1 - exponent - 1));
|
||||
shr_Xsig(&argSqSq, 4 * (-1 - exponent - 1));
|
||||
|
||||
/* Now have argSq etc with binary point at the left
|
||||
.1xxxxxxxx */
|
||||
|
||||
/* Do the basic fixed point polynomial evaluation */
|
||||
accumulator.msw = accumulator.midw = accumulator.lsw = 0;
|
||||
polynomial_Xsig(&accumulator, &XSIG_LL(argSqSq),
|
||||
oddplterms, HIPOWERop - 1);
|
||||
mul64_Xsig(&accumulator, &XSIG_LL(argSq));
|
||||
negate_Xsig(&accumulator);
|
||||
polynomial_Xsig(&accumulator, &XSIG_LL(argSqSq), oddnegterms,
|
||||
HIPOWERon - 1);
|
||||
negate_Xsig(&accumulator);
|
||||
add_two_Xsig(&accumulator, &fixedpterm, &dummy_exp);
|
||||
|
||||
mul64_Xsig(&accumulatore, &denomterm);
|
||||
shr_Xsig(&accumulatore, 1 + 2 * (-1 - exponent));
|
||||
accumulatore.msw |= 0x80000000;
|
||||
|
||||
div_Xsig(&accumulator, &accumulatore, &accumulator);
|
||||
|
||||
mul_Xsig_Xsig(&accumulator, &argSignif);
|
||||
mul_Xsig_Xsig(&accumulator, &argSq);
|
||||
|
||||
shr_Xsig(&accumulator, 3);
|
||||
negate_Xsig(&accumulator);
|
||||
add_Xsig_Xsig(&accumulator, &argSignif);
|
||||
|
||||
if (transformed) {
|
||||
/* compute pi/4 - accumulator */
|
||||
shr_Xsig(&accumulator, -1 - exponent);
|
||||
negate_Xsig(&accumulator);
|
||||
add_Xsig_Xsig(&accumulator, &pi_signif);
|
||||
exponent = -1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
transformed = 0;
|
||||
}
|
||||
|
||||
argSq.lsw = argSignif.lsw; argSq.midw = argSignif.midw;
|
||||
argSq.msw = argSignif.msw;
|
||||
mul_Xsig_Xsig(&argSq, &argSq);
|
||||
|
||||
argSqSq.lsw = argSq.lsw; argSqSq.midw = argSq.midw; argSqSq.msw = argSq.msw;
|
||||
mul_Xsig_Xsig(&argSqSq, &argSqSq);
|
||||
if (inverted) {
|
||||
/* compute pi/2 - accumulator */
|
||||
shr_Xsig(&accumulator, -exponent);
|
||||
negate_Xsig(&accumulator);
|
||||
add_Xsig_Xsig(&accumulator, &pi_signif);
|
||||
exponent = 0;
|
||||
}
|
||||
|
||||
accumulatore.lsw = argSq.lsw;
|
||||
XSIG_LL(accumulatore) = XSIG_LL(argSq);
|
||||
if (sign1) {
|
||||
/* compute pi - accumulator */
|
||||
shr_Xsig(&accumulator, 1 - exponent);
|
||||
negate_Xsig(&accumulator);
|
||||
add_Xsig_Xsig(&accumulator, &pi_signif);
|
||||
exponent = 1;
|
||||
}
|
||||
|
||||
shr_Xsig(&argSq, 2*(-1-exponent-1));
|
||||
shr_Xsig(&argSqSq, 4*(-1-exponent-1));
|
||||
exponent += round_Xsig(&accumulator);
|
||||
|
||||
/* Now have argSq etc with binary point at the left
|
||||
.1xxxxxxxx */
|
||||
significand(st1_ptr) = XSIG_LL(accumulator);
|
||||
setexponent16(st1_ptr, exponent);
|
||||
|
||||
/* Do the basic fixed point polynomial evaluation */
|
||||
accumulator.msw = accumulator.midw = accumulator.lsw = 0;
|
||||
polynomial_Xsig(&accumulator, &XSIG_LL(argSqSq),
|
||||
oddplterms, HIPOWERop-1);
|
||||
mul64_Xsig(&accumulator, &XSIG_LL(argSq));
|
||||
negate_Xsig(&accumulator);
|
||||
polynomial_Xsig(&accumulator, &XSIG_LL(argSqSq), oddnegterms, HIPOWERon-1);
|
||||
negate_Xsig(&accumulator);
|
||||
add_two_Xsig(&accumulator, &fixedpterm, &dummy_exp);
|
||||
tag = FPU_round(st1_ptr, 1, 0, FULL_PRECISION, sign2);
|
||||
FPU_settagi(1, tag);
|
||||
|
||||
mul64_Xsig(&accumulatore, &denomterm);
|
||||
shr_Xsig(&accumulatore, 1 + 2*(-1-exponent));
|
||||
accumulatore.msw |= 0x80000000;
|
||||
|
||||
div_Xsig(&accumulator, &accumulatore, &accumulator);
|
||||
|
||||
mul_Xsig_Xsig(&accumulator, &argSignif);
|
||||
mul_Xsig_Xsig(&accumulator, &argSq);
|
||||
|
||||
shr_Xsig(&accumulator, 3);
|
||||
negate_Xsig(&accumulator);
|
||||
add_Xsig_Xsig(&accumulator, &argSignif);
|
||||
|
||||
if ( transformed )
|
||||
{
|
||||
/* compute pi/4 - accumulator */
|
||||
shr_Xsig(&accumulator, -1-exponent);
|
||||
negate_Xsig(&accumulator);
|
||||
add_Xsig_Xsig(&accumulator, &pi_signif);
|
||||
exponent = -1;
|
||||
}
|
||||
|
||||
if ( inverted )
|
||||
{
|
||||
/* compute pi/2 - accumulator */
|
||||
shr_Xsig(&accumulator, -exponent);
|
||||
negate_Xsig(&accumulator);
|
||||
add_Xsig_Xsig(&accumulator, &pi_signif);
|
||||
exponent = 0;
|
||||
}
|
||||
|
||||
if ( sign1 )
|
||||
{
|
||||
/* compute pi - accumulator */
|
||||
shr_Xsig(&accumulator, 1 - exponent);
|
||||
negate_Xsig(&accumulator);
|
||||
add_Xsig_Xsig(&accumulator, &pi_signif);
|
||||
exponent = 1;
|
||||
}
|
||||
|
||||
exponent += round_Xsig(&accumulator);
|
||||
|
||||
significand(st1_ptr) = XSIG_LL(accumulator);
|
||||
setexponent16(st1_ptr, exponent);
|
||||
|
||||
tag = FPU_round(st1_ptr, 1, 0, FULL_PRECISION, sign2);
|
||||
FPU_settagi(1, tag);
|
||||
|
||||
set_precision_flag_up(); /* We do not really know if up or down,
|
||||
use this as the default. */
|
||||
set_precision_flag_up(); /* We do not really know if up or down,
|
||||
use this as the default. */
|
||||
|
||||
}
|
||||
|
|
|
@ -10,7 +10,6 @@
|
|||
| |
|
||||
+---------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
#include "exception.h"
|
||||
#include "reg_constant.h"
|
||||
#include "fpu_emu.h"
|
||||
|
@ -18,255 +17,228 @@
|
|||
#include "control_w.h"
|
||||
#include "poly.h"
|
||||
|
||||
|
||||
static void log2_kernel(FPU_REG const *arg, u_char argsign,
|
||||
Xsig *accum_result, long int *expon);
|
||||
|
||||
Xsig * accum_result, long int *expon);
|
||||
|
||||
/*--- poly_l2() -------------------------------------------------------------+
|
||||
| Base 2 logarithm by a polynomial approximation. |
|
||||
+---------------------------------------------------------------------------*/
|
||||
void poly_l2(FPU_REG *st0_ptr, FPU_REG *st1_ptr, u_char st1_sign)
|
||||
void poly_l2(FPU_REG * st0_ptr, FPU_REG * st1_ptr, u_char st1_sign)
|
||||
{
|
||||
long int exponent, expon, expon_expon;
|
||||
Xsig accumulator, expon_accum, yaccum;
|
||||
u_char sign, argsign;
|
||||
FPU_REG x;
|
||||
int tag;
|
||||
long int exponent, expon, expon_expon;
|
||||
Xsig accumulator, expon_accum, yaccum;
|
||||
u_char sign, argsign;
|
||||
FPU_REG x;
|
||||
int tag;
|
||||
|
||||
exponent = exponent16(st0_ptr);
|
||||
exponent = exponent16(st0_ptr);
|
||||
|
||||
/* From st0_ptr, make a number > sqrt(2)/2 and < sqrt(2) */
|
||||
if ( st0_ptr->sigh > (unsigned)0xb504f334 )
|
||||
{
|
||||
/* Treat as sqrt(2)/2 < st0_ptr < 1 */
|
||||
significand(&x) = - significand(st0_ptr);
|
||||
setexponent16(&x, -1);
|
||||
exponent++;
|
||||
argsign = SIGN_NEG;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Treat as 1 <= st0_ptr < sqrt(2) */
|
||||
x.sigh = st0_ptr->sigh - 0x80000000;
|
||||
x.sigl = st0_ptr->sigl;
|
||||
setexponent16(&x, 0);
|
||||
argsign = SIGN_POS;
|
||||
}
|
||||
tag = FPU_normalize_nuo(&x);
|
||||
/* From st0_ptr, make a number > sqrt(2)/2 and < sqrt(2) */
|
||||
if (st0_ptr->sigh > (unsigned)0xb504f334) {
|
||||
/* Treat as sqrt(2)/2 < st0_ptr < 1 */
|
||||
significand(&x) = -significand(st0_ptr);
|
||||
setexponent16(&x, -1);
|
||||
exponent++;
|
||||
argsign = SIGN_NEG;
|
||||
} else {
|
||||
/* Treat as 1 <= st0_ptr < sqrt(2) */
|
||||
x.sigh = st0_ptr->sigh - 0x80000000;
|
||||
x.sigl = st0_ptr->sigl;
|
||||
setexponent16(&x, 0);
|
||||
argsign = SIGN_POS;
|
||||
}
|
||||
tag = FPU_normalize_nuo(&x);
|
||||
|
||||
if ( tag == TAG_Zero )
|
||||
{
|
||||
expon = 0;
|
||||
accumulator.msw = accumulator.midw = accumulator.lsw = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
log2_kernel(&x, argsign, &accumulator, &expon);
|
||||
}
|
||||
if (tag == TAG_Zero) {
|
||||
expon = 0;
|
||||
accumulator.msw = accumulator.midw = accumulator.lsw = 0;
|
||||
} else {
|
||||
log2_kernel(&x, argsign, &accumulator, &expon);
|
||||
}
|
||||
|
||||
if ( exponent < 0 )
|
||||
{
|
||||
sign = SIGN_NEG;
|
||||
exponent = -exponent;
|
||||
}
|
||||
else
|
||||
sign = SIGN_POS;
|
||||
expon_accum.msw = exponent; expon_accum.midw = expon_accum.lsw = 0;
|
||||
if ( exponent )
|
||||
{
|
||||
expon_expon = 31 + norm_Xsig(&expon_accum);
|
||||
shr_Xsig(&accumulator, expon_expon - expon);
|
||||
if (exponent < 0) {
|
||||
sign = SIGN_NEG;
|
||||
exponent = -exponent;
|
||||
} else
|
||||
sign = SIGN_POS;
|
||||
expon_accum.msw = exponent;
|
||||
expon_accum.midw = expon_accum.lsw = 0;
|
||||
if (exponent) {
|
||||
expon_expon = 31 + norm_Xsig(&expon_accum);
|
||||
shr_Xsig(&accumulator, expon_expon - expon);
|
||||
|
||||
if ( sign ^ argsign )
|
||||
negate_Xsig(&accumulator);
|
||||
add_Xsig_Xsig(&accumulator, &expon_accum);
|
||||
}
|
||||
else
|
||||
{
|
||||
expon_expon = expon;
|
||||
sign = argsign;
|
||||
}
|
||||
if (sign ^ argsign)
|
||||
negate_Xsig(&accumulator);
|
||||
add_Xsig_Xsig(&accumulator, &expon_accum);
|
||||
} else {
|
||||
expon_expon = expon;
|
||||
sign = argsign;
|
||||
}
|
||||
|
||||
yaccum.lsw = 0; XSIG_LL(yaccum) = significand(st1_ptr);
|
||||
mul_Xsig_Xsig(&accumulator, &yaccum);
|
||||
yaccum.lsw = 0;
|
||||
XSIG_LL(yaccum) = significand(st1_ptr);
|
||||
mul_Xsig_Xsig(&accumulator, &yaccum);
|
||||
|
||||
expon_expon += round_Xsig(&accumulator);
|
||||
expon_expon += round_Xsig(&accumulator);
|
||||
|
||||
if ( accumulator.msw == 0 )
|
||||
{
|
||||
FPU_copy_to_reg1(&CONST_Z, TAG_Zero);
|
||||
return;
|
||||
}
|
||||
if (accumulator.msw == 0) {
|
||||
FPU_copy_to_reg1(&CONST_Z, TAG_Zero);
|
||||
return;
|
||||
}
|
||||
|
||||
significand(st1_ptr) = XSIG_LL(accumulator);
|
||||
setexponent16(st1_ptr, expon_expon + exponent16(st1_ptr) + 1);
|
||||
significand(st1_ptr) = XSIG_LL(accumulator);
|
||||
setexponent16(st1_ptr, expon_expon + exponent16(st1_ptr) + 1);
|
||||
|
||||
tag = FPU_round(st1_ptr, 1, 0, FULL_PRECISION, sign ^ st1_sign);
|
||||
FPU_settagi(1, tag);
|
||||
tag = FPU_round(st1_ptr, 1, 0, FULL_PRECISION, sign ^ st1_sign);
|
||||
FPU_settagi(1, tag);
|
||||
|
||||
set_precision_flag_up(); /* 80486 appears to always do this */
|
||||
set_precision_flag_up(); /* 80486 appears to always do this */
|
||||
|
||||
return;
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*--- poly_l2p1() -----------------------------------------------------------+
|
||||
| Base 2 logarithm by a polynomial approximation. |
|
||||
| log2(x+1) |
|
||||
+---------------------------------------------------------------------------*/
|
||||
int poly_l2p1(u_char sign0, u_char sign1,
|
||||
FPU_REG *st0_ptr, FPU_REG *st1_ptr, FPU_REG *dest)
|
||||
int poly_l2p1(u_char sign0, u_char sign1,
|
||||
FPU_REG * st0_ptr, FPU_REG * st1_ptr, FPU_REG * dest)
|
||||
{
|
||||
u_char tag;
|
||||
long int exponent;
|
||||
Xsig accumulator, yaccum;
|
||||
u_char tag;
|
||||
long int exponent;
|
||||
Xsig accumulator, yaccum;
|
||||
|
||||
if ( exponent16(st0_ptr) < 0 )
|
||||
{
|
||||
log2_kernel(st0_ptr, sign0, &accumulator, &exponent);
|
||||
if (exponent16(st0_ptr) < 0) {
|
||||
log2_kernel(st0_ptr, sign0, &accumulator, &exponent);
|
||||
|
||||
yaccum.lsw = 0;
|
||||
XSIG_LL(yaccum) = significand(st1_ptr);
|
||||
mul_Xsig_Xsig(&accumulator, &yaccum);
|
||||
yaccum.lsw = 0;
|
||||
XSIG_LL(yaccum) = significand(st1_ptr);
|
||||
mul_Xsig_Xsig(&accumulator, &yaccum);
|
||||
|
||||
exponent += round_Xsig(&accumulator);
|
||||
exponent += round_Xsig(&accumulator);
|
||||
|
||||
exponent += exponent16(st1_ptr) + 1;
|
||||
if ( exponent < EXP_WAY_UNDER ) exponent = EXP_WAY_UNDER;
|
||||
exponent += exponent16(st1_ptr) + 1;
|
||||
if (exponent < EXP_WAY_UNDER)
|
||||
exponent = EXP_WAY_UNDER;
|
||||
|
||||
significand(dest) = XSIG_LL(accumulator);
|
||||
setexponent16(dest, exponent);
|
||||
significand(dest) = XSIG_LL(accumulator);
|
||||
setexponent16(dest, exponent);
|
||||
|
||||
tag = FPU_round(dest, 1, 0, FULL_PRECISION, sign0 ^ sign1);
|
||||
FPU_settagi(1, tag);
|
||||
tag = FPU_round(dest, 1, 0, FULL_PRECISION, sign0 ^ sign1);
|
||||
FPU_settagi(1, tag);
|
||||
|
||||
if ( tag == TAG_Valid )
|
||||
set_precision_flag_up(); /* 80486 appears to always do this */
|
||||
}
|
||||
else
|
||||
{
|
||||
/* The magnitude of st0_ptr is far too large. */
|
||||
if (tag == TAG_Valid)
|
||||
set_precision_flag_up(); /* 80486 appears to always do this */
|
||||
} else {
|
||||
/* The magnitude of st0_ptr is far too large. */
|
||||
|
||||
if ( sign0 != SIGN_POS )
|
||||
{
|
||||
/* Trying to get the log of a negative number. */
|
||||
#ifdef PECULIAR_486 /* Stupid 80486 doesn't worry about log(negative). */
|
||||
changesign(st1_ptr);
|
||||
if (sign0 != SIGN_POS) {
|
||||
/* Trying to get the log of a negative number. */
|
||||
#ifdef PECULIAR_486 /* Stupid 80486 doesn't worry about log(negative). */
|
||||
changesign(st1_ptr);
|
||||
#else
|
||||
if ( arith_invalid(1) < 0 )
|
||||
return 1;
|
||||
if (arith_invalid(1) < 0)
|
||||
return 1;
|
||||
#endif /* PECULIAR_486 */
|
||||
}
|
||||
|
||||
/* 80486 appears to do this */
|
||||
if (sign0 == SIGN_NEG)
|
||||
set_precision_flag_down();
|
||||
else
|
||||
set_precision_flag_up();
|
||||
}
|
||||
|
||||
/* 80486 appears to do this */
|
||||
if ( sign0 == SIGN_NEG )
|
||||
set_precision_flag_down();
|
||||
else
|
||||
set_precision_flag_up();
|
||||
}
|
||||
if (exponent(dest) <= EXP_UNDER)
|
||||
EXCEPTION(EX_Underflow);
|
||||
|
||||
if ( exponent(dest) <= EXP_UNDER )
|
||||
EXCEPTION(EX_Underflow);
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
#undef HIPOWER
|
||||
#define HIPOWER 10
|
||||
static const unsigned long long logterms[HIPOWER] =
|
||||
{
|
||||
0x2a8eca5705fc2ef0LL,
|
||||
0xf6384ee1d01febceLL,
|
||||
0x093bb62877cdf642LL,
|
||||
0x006985d8a9ec439bLL,
|
||||
0x0005212c4f55a9c8LL,
|
||||
0x00004326a16927f0LL,
|
||||
0x0000038d1d80a0e7LL,
|
||||
0x0000003141cc80c6LL,
|
||||
0x00000002b1668c9fLL,
|
||||
0x000000002c7a46aaLL
|
||||
static const unsigned long long logterms[HIPOWER] = {
|
||||
0x2a8eca5705fc2ef0LL,
|
||||
0xf6384ee1d01febceLL,
|
||||
0x093bb62877cdf642LL,
|
||||
0x006985d8a9ec439bLL,
|
||||
0x0005212c4f55a9c8LL,
|
||||
0x00004326a16927f0LL,
|
||||
0x0000038d1d80a0e7LL,
|
||||
0x0000003141cc80c6LL,
|
||||
0x00000002b1668c9fLL,
|
||||
0x000000002c7a46aaLL
|
||||
};
|
||||
|
||||
static const unsigned long leadterm = 0xb8000000;
|
||||
|
||||
|
||||
/*--- log2_kernel() ---------------------------------------------------------+
|
||||
| Base 2 logarithm by a polynomial approximation. |
|
||||
| log2(x+1) |
|
||||
+---------------------------------------------------------------------------*/
|
||||
static void log2_kernel(FPU_REG const *arg, u_char argsign, Xsig *accum_result,
|
||||
static void log2_kernel(FPU_REG const *arg, u_char argsign, Xsig * accum_result,
|
||||
long int *expon)
|
||||
{
|
||||
long int exponent, adj;
|
||||
unsigned long long Xsq;
|
||||
Xsig accumulator, Numer, Denom, argSignif, arg_signif;
|
||||
long int exponent, adj;
|
||||
unsigned long long Xsq;
|
||||
Xsig accumulator, Numer, Denom, argSignif, arg_signif;
|
||||
|
||||
exponent = exponent16(arg);
|
||||
Numer.lsw = Denom.lsw = 0;
|
||||
XSIG_LL(Numer) = XSIG_LL(Denom) = significand(arg);
|
||||
if ( argsign == SIGN_POS )
|
||||
{
|
||||
shr_Xsig(&Denom, 2 - (1 + exponent));
|
||||
Denom.msw |= 0x80000000;
|
||||
div_Xsig(&Numer, &Denom, &argSignif);
|
||||
}
|
||||
else
|
||||
{
|
||||
shr_Xsig(&Denom, 1 - (1 + exponent));
|
||||
negate_Xsig(&Denom);
|
||||
if ( Denom.msw & 0x80000000 )
|
||||
{
|
||||
div_Xsig(&Numer, &Denom, &argSignif);
|
||||
exponent ++;
|
||||
exponent = exponent16(arg);
|
||||
Numer.lsw = Denom.lsw = 0;
|
||||
XSIG_LL(Numer) = XSIG_LL(Denom) = significand(arg);
|
||||
if (argsign == SIGN_POS) {
|
||||
shr_Xsig(&Denom, 2 - (1 + exponent));
|
||||
Denom.msw |= 0x80000000;
|
||||
div_Xsig(&Numer, &Denom, &argSignif);
|
||||
} else {
|
||||
shr_Xsig(&Denom, 1 - (1 + exponent));
|
||||
negate_Xsig(&Denom);
|
||||
if (Denom.msw & 0x80000000) {
|
||||
div_Xsig(&Numer, &Denom, &argSignif);
|
||||
exponent++;
|
||||
} else {
|
||||
/* Denom must be 1.0 */
|
||||
argSignif.lsw = Numer.lsw;
|
||||
argSignif.midw = Numer.midw;
|
||||
argSignif.msw = Numer.msw;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Denom must be 1.0 */
|
||||
argSignif.lsw = Numer.lsw; argSignif.midw = Numer.midw;
|
||||
argSignif.msw = Numer.msw;
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef PECULIAR_486
|
||||
/* Should check here that |local_arg| is within the valid range */
|
||||
if ( exponent >= -2 )
|
||||
{
|
||||
if ( (exponent > -2) ||
|
||||
(argSignif.msw > (unsigned)0xafb0ccc0) )
|
||||
{
|
||||
/* The argument is too large */
|
||||
/* Should check here that |local_arg| is within the valid range */
|
||||
if (exponent >= -2) {
|
||||
if ((exponent > -2) || (argSignif.msw > (unsigned)0xafb0ccc0)) {
|
||||
/* The argument is too large */
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif /* PECULIAR_486 */
|
||||
|
||||
arg_signif.lsw = argSignif.lsw; XSIG_LL(arg_signif) = XSIG_LL(argSignif);
|
||||
adj = norm_Xsig(&argSignif);
|
||||
accumulator.lsw = argSignif.lsw; XSIG_LL(accumulator) = XSIG_LL(argSignif);
|
||||
mul_Xsig_Xsig(&accumulator, &accumulator);
|
||||
shr_Xsig(&accumulator, 2*(-1 - (1 + exponent + adj)));
|
||||
Xsq = XSIG_LL(accumulator);
|
||||
if ( accumulator.lsw & 0x80000000 )
|
||||
Xsq++;
|
||||
arg_signif.lsw = argSignif.lsw;
|
||||
XSIG_LL(arg_signif) = XSIG_LL(argSignif);
|
||||
adj = norm_Xsig(&argSignif);
|
||||
accumulator.lsw = argSignif.lsw;
|
||||
XSIG_LL(accumulator) = XSIG_LL(argSignif);
|
||||
mul_Xsig_Xsig(&accumulator, &accumulator);
|
||||
shr_Xsig(&accumulator, 2 * (-1 - (1 + exponent + adj)));
|
||||
Xsq = XSIG_LL(accumulator);
|
||||
if (accumulator.lsw & 0x80000000)
|
||||
Xsq++;
|
||||
|
||||
accumulator.msw = accumulator.midw = accumulator.lsw = 0;
|
||||
/* Do the basic fixed point polynomial evaluation */
|
||||
polynomial_Xsig(&accumulator, &Xsq, logterms, HIPOWER-1);
|
||||
accumulator.msw = accumulator.midw = accumulator.lsw = 0;
|
||||
/* Do the basic fixed point polynomial evaluation */
|
||||
polynomial_Xsig(&accumulator, &Xsq, logterms, HIPOWER - 1);
|
||||
|
||||
mul_Xsig_Xsig(&accumulator, &argSignif);
|
||||
shr_Xsig(&accumulator, 6 - adj);
|
||||
mul_Xsig_Xsig(&accumulator, &argSignif);
|
||||
shr_Xsig(&accumulator, 6 - adj);
|
||||
|
||||
mul32_Xsig(&arg_signif, leadterm);
|
||||
add_two_Xsig(&accumulator, &arg_signif, &exponent);
|
||||
mul32_Xsig(&arg_signif, leadterm);
|
||||
add_two_Xsig(&accumulator, &arg_signif, &exponent);
|
||||
|
||||
*expon = exponent + 1;
|
||||
accum_result->lsw = accumulator.lsw;
|
||||
accum_result->midw = accumulator.midw;
|
||||
accum_result->msw = accumulator.msw;
|
||||
*expon = exponent + 1;
|
||||
accum_result->lsw = accumulator.lsw;
|
||||
accum_result->midw = accumulator.midw;
|
||||
accum_result->msw = accumulator.msw;
|
||||
|
||||
}
|
||||
|
|
|
@ -11,7 +11,6 @@
|
|||
| |
|
||||
+---------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
#include "exception.h"
|
||||
#include "reg_constant.h"
|
||||
#include "fpu_emu.h"
|
||||
|
@ -19,379 +18,361 @@
|
|||
#include "control_w.h"
|
||||
#include "poly.h"
|
||||
|
||||
|
||||
#define N_COEFF_P 4
|
||||
#define N_COEFF_N 4
|
||||
|
||||
static const unsigned long long pos_terms_l[N_COEFF_P] =
|
||||
{
|
||||
0xaaaaaaaaaaaaaaabLL,
|
||||
0x00d00d00d00cf906LL,
|
||||
0x000006b99159a8bbLL,
|
||||
0x000000000d7392e6LL
|
||||
static const unsigned long long pos_terms_l[N_COEFF_P] = {
|
||||
0xaaaaaaaaaaaaaaabLL,
|
||||
0x00d00d00d00cf906LL,
|
||||
0x000006b99159a8bbLL,
|
||||
0x000000000d7392e6LL
|
||||
};
|
||||
|
||||
static const unsigned long long neg_terms_l[N_COEFF_N] =
|
||||
{
|
||||
0x2222222222222167LL,
|
||||
0x0002e3bc74aab624LL,
|
||||
0x0000000b09229062LL,
|
||||
0x00000000000c7973LL
|
||||
static const unsigned long long neg_terms_l[N_COEFF_N] = {
|
||||
0x2222222222222167LL,
|
||||
0x0002e3bc74aab624LL,
|
||||
0x0000000b09229062LL,
|
||||
0x00000000000c7973LL
|
||||
};
|
||||
|
||||
|
||||
|
||||
#define N_COEFF_PH 4
|
||||
#define N_COEFF_NH 4
|
||||
static const unsigned long long pos_terms_h[N_COEFF_PH] =
|
||||
{
|
||||
0x0000000000000000LL,
|
||||
0x05b05b05b05b0406LL,
|
||||
0x000049f93edd91a9LL,
|
||||
0x00000000c9c9ed62LL
|
||||
static const unsigned long long pos_terms_h[N_COEFF_PH] = {
|
||||
0x0000000000000000LL,
|
||||
0x05b05b05b05b0406LL,
|
||||
0x000049f93edd91a9LL,
|
||||
0x00000000c9c9ed62LL
|
||||
};
|
||||
|
||||
static const unsigned long long neg_terms_h[N_COEFF_NH] =
|
||||
{
|
||||
0xaaaaaaaaaaaaaa98LL,
|
||||
0x001a01a01a019064LL,
|
||||
0x0000008f76c68a77LL,
|
||||
0x0000000000d58f5eLL
|
||||
static const unsigned long long neg_terms_h[N_COEFF_NH] = {
|
||||
0xaaaaaaaaaaaaaa98LL,
|
||||
0x001a01a01a019064LL,
|
||||
0x0000008f76c68a77LL,
|
||||
0x0000000000d58f5eLL
|
||||
};
|
||||
|
||||
|
||||
/*--- poly_sine() -----------------------------------------------------------+
|
||||
| |
|
||||
+---------------------------------------------------------------------------*/
|
||||
void poly_sine(FPU_REG *st0_ptr)
|
||||
void poly_sine(FPU_REG * st0_ptr)
|
||||
{
|
||||
int exponent, echange;
|
||||
Xsig accumulator, argSqrd, argTo4;
|
||||
unsigned long fix_up, adj;
|
||||
unsigned long long fixed_arg;
|
||||
FPU_REG result;
|
||||
int exponent, echange;
|
||||
Xsig accumulator, argSqrd, argTo4;
|
||||
unsigned long fix_up, adj;
|
||||
unsigned long long fixed_arg;
|
||||
FPU_REG result;
|
||||
|
||||
exponent = exponent(st0_ptr);
|
||||
exponent = exponent(st0_ptr);
|
||||
|
||||
accumulator.lsw = accumulator.midw = accumulator.msw = 0;
|
||||
accumulator.lsw = accumulator.midw = accumulator.msw = 0;
|
||||
|
||||
/* Split into two ranges, for arguments below and above 1.0 */
|
||||
/* The boundary between upper and lower is approx 0.88309101259 */
|
||||
if ( (exponent < -1) || ((exponent == -1) && (st0_ptr->sigh <= 0xe21240aa)) )
|
||||
{
|
||||
/* The argument is <= 0.88309101259 */
|
||||
/* Split into two ranges, for arguments below and above 1.0 */
|
||||
/* The boundary between upper and lower is approx 0.88309101259 */
|
||||
if ((exponent < -1)
|
||||
|| ((exponent == -1) && (st0_ptr->sigh <= 0xe21240aa))) {
|
||||
/* The argument is <= 0.88309101259 */
|
||||
|
||||
argSqrd.msw = st0_ptr->sigh; argSqrd.midw = st0_ptr->sigl; argSqrd.lsw = 0;
|
||||
mul64_Xsig(&argSqrd, &significand(st0_ptr));
|
||||
shr_Xsig(&argSqrd, 2*(-1-exponent));
|
||||
argTo4.msw = argSqrd.msw; argTo4.midw = argSqrd.midw;
|
||||
argTo4.lsw = argSqrd.lsw;
|
||||
mul_Xsig_Xsig(&argTo4, &argTo4);
|
||||
argSqrd.msw = st0_ptr->sigh;
|
||||
argSqrd.midw = st0_ptr->sigl;
|
||||
argSqrd.lsw = 0;
|
||||
mul64_Xsig(&argSqrd, &significand(st0_ptr));
|
||||
shr_Xsig(&argSqrd, 2 * (-1 - exponent));
|
||||
argTo4.msw = argSqrd.msw;
|
||||
argTo4.midw = argSqrd.midw;
|
||||
argTo4.lsw = argSqrd.lsw;
|
||||
mul_Xsig_Xsig(&argTo4, &argTo4);
|
||||
|
||||
polynomial_Xsig(&accumulator, &XSIG_LL(argTo4), neg_terms_l,
|
||||
N_COEFF_N-1);
|
||||
mul_Xsig_Xsig(&accumulator, &argSqrd);
|
||||
negate_Xsig(&accumulator);
|
||||
polynomial_Xsig(&accumulator, &XSIG_LL(argTo4), neg_terms_l,
|
||||
N_COEFF_N - 1);
|
||||
mul_Xsig_Xsig(&accumulator, &argSqrd);
|
||||
negate_Xsig(&accumulator);
|
||||
|
||||
polynomial_Xsig(&accumulator, &XSIG_LL(argTo4), pos_terms_l,
|
||||
N_COEFF_P-1);
|
||||
polynomial_Xsig(&accumulator, &XSIG_LL(argTo4), pos_terms_l,
|
||||
N_COEFF_P - 1);
|
||||
|
||||
shr_Xsig(&accumulator, 2); /* Divide by four */
|
||||
accumulator.msw |= 0x80000000; /* Add 1.0 */
|
||||
shr_Xsig(&accumulator, 2); /* Divide by four */
|
||||
accumulator.msw |= 0x80000000; /* Add 1.0 */
|
||||
|
||||
mul64_Xsig(&accumulator, &significand(st0_ptr));
|
||||
mul64_Xsig(&accumulator, &significand(st0_ptr));
|
||||
mul64_Xsig(&accumulator, &significand(st0_ptr));
|
||||
mul64_Xsig(&accumulator, &significand(st0_ptr));
|
||||
mul64_Xsig(&accumulator, &significand(st0_ptr));
|
||||
mul64_Xsig(&accumulator, &significand(st0_ptr));
|
||||
|
||||
/* Divide by four, FPU_REG compatible, etc */
|
||||
exponent = 3*exponent;
|
||||
/* Divide by four, FPU_REG compatible, etc */
|
||||
exponent = 3 * exponent;
|
||||
|
||||
/* The minimum exponent difference is 3 */
|
||||
shr_Xsig(&accumulator, exponent(st0_ptr) - exponent);
|
||||
/* The minimum exponent difference is 3 */
|
||||
shr_Xsig(&accumulator, exponent(st0_ptr) - exponent);
|
||||
|
||||
negate_Xsig(&accumulator);
|
||||
XSIG_LL(accumulator) += significand(st0_ptr);
|
||||
negate_Xsig(&accumulator);
|
||||
XSIG_LL(accumulator) += significand(st0_ptr);
|
||||
|
||||
echange = round_Xsig(&accumulator);
|
||||
echange = round_Xsig(&accumulator);
|
||||
|
||||
setexponentpos(&result, exponent(st0_ptr) + echange);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* The argument is > 0.88309101259 */
|
||||
/* We use sin(st(0)) = cos(pi/2-st(0)) */
|
||||
setexponentpos(&result, exponent(st0_ptr) + echange);
|
||||
} else {
|
||||
/* The argument is > 0.88309101259 */
|
||||
/* We use sin(st(0)) = cos(pi/2-st(0)) */
|
||||
|
||||
fixed_arg = significand(st0_ptr);
|
||||
fixed_arg = significand(st0_ptr);
|
||||
|
||||
if ( exponent == 0 )
|
||||
{
|
||||
/* The argument is >= 1.0 */
|
||||
if (exponent == 0) {
|
||||
/* The argument is >= 1.0 */
|
||||
|
||||
/* Put the binary point at the left. */
|
||||
fixed_arg <<= 1;
|
||||
/* Put the binary point at the left. */
|
||||
fixed_arg <<= 1;
|
||||
}
|
||||
/* pi/2 in hex is: 1.921fb54442d18469 898CC51701B839A2 52049C1 */
|
||||
fixed_arg = 0x921fb54442d18469LL - fixed_arg;
|
||||
/* There is a special case which arises due to rounding, to fix here. */
|
||||
if (fixed_arg == 0xffffffffffffffffLL)
|
||||
fixed_arg = 0;
|
||||
|
||||
XSIG_LL(argSqrd) = fixed_arg;
|
||||
argSqrd.lsw = 0;
|
||||
mul64_Xsig(&argSqrd, &fixed_arg);
|
||||
|
||||
XSIG_LL(argTo4) = XSIG_LL(argSqrd);
|
||||
argTo4.lsw = argSqrd.lsw;
|
||||
mul_Xsig_Xsig(&argTo4, &argTo4);
|
||||
|
||||
polynomial_Xsig(&accumulator, &XSIG_LL(argTo4), neg_terms_h,
|
||||
N_COEFF_NH - 1);
|
||||
mul_Xsig_Xsig(&accumulator, &argSqrd);
|
||||
negate_Xsig(&accumulator);
|
||||
|
||||
polynomial_Xsig(&accumulator, &XSIG_LL(argTo4), pos_terms_h,
|
||||
N_COEFF_PH - 1);
|
||||
negate_Xsig(&accumulator);
|
||||
|
||||
mul64_Xsig(&accumulator, &fixed_arg);
|
||||
mul64_Xsig(&accumulator, &fixed_arg);
|
||||
|
||||
shr_Xsig(&accumulator, 3);
|
||||
negate_Xsig(&accumulator);
|
||||
|
||||
add_Xsig_Xsig(&accumulator, &argSqrd);
|
||||
|
||||
shr_Xsig(&accumulator, 1);
|
||||
|
||||
accumulator.lsw |= 1; /* A zero accumulator here would cause problems */
|
||||
negate_Xsig(&accumulator);
|
||||
|
||||
/* The basic computation is complete. Now fix the answer to
|
||||
compensate for the error due to the approximation used for
|
||||
pi/2
|
||||
*/
|
||||
|
||||
/* This has an exponent of -65 */
|
||||
fix_up = 0x898cc517;
|
||||
/* The fix-up needs to be improved for larger args */
|
||||
if (argSqrd.msw & 0xffc00000) {
|
||||
/* Get about 32 bit precision in these: */
|
||||
fix_up -= mul_32_32(0x898cc517, argSqrd.msw) / 6;
|
||||
}
|
||||
fix_up = mul_32_32(fix_up, LL_MSW(fixed_arg));
|
||||
|
||||
adj = accumulator.lsw; /* temp save */
|
||||
accumulator.lsw -= fix_up;
|
||||
if (accumulator.lsw > adj)
|
||||
XSIG_LL(accumulator)--;
|
||||
|
||||
echange = round_Xsig(&accumulator);
|
||||
|
||||
setexponentpos(&result, echange - 1);
|
||||
}
|
||||
/* pi/2 in hex is: 1.921fb54442d18469 898CC51701B839A2 52049C1 */
|
||||
fixed_arg = 0x921fb54442d18469LL - fixed_arg;
|
||||
/* There is a special case which arises due to rounding, to fix here. */
|
||||
if ( fixed_arg == 0xffffffffffffffffLL )
|
||||
fixed_arg = 0;
|
||||
|
||||
XSIG_LL(argSqrd) = fixed_arg; argSqrd.lsw = 0;
|
||||
mul64_Xsig(&argSqrd, &fixed_arg);
|
||||
|
||||
XSIG_LL(argTo4) = XSIG_LL(argSqrd); argTo4.lsw = argSqrd.lsw;
|
||||
mul_Xsig_Xsig(&argTo4, &argTo4);
|
||||
|
||||
polynomial_Xsig(&accumulator, &XSIG_LL(argTo4), neg_terms_h,
|
||||
N_COEFF_NH-1);
|
||||
mul_Xsig_Xsig(&accumulator, &argSqrd);
|
||||
negate_Xsig(&accumulator);
|
||||
|
||||
polynomial_Xsig(&accumulator, &XSIG_LL(argTo4), pos_terms_h,
|
||||
N_COEFF_PH-1);
|
||||
negate_Xsig(&accumulator);
|
||||
|
||||
mul64_Xsig(&accumulator, &fixed_arg);
|
||||
mul64_Xsig(&accumulator, &fixed_arg);
|
||||
|
||||
shr_Xsig(&accumulator, 3);
|
||||
negate_Xsig(&accumulator);
|
||||
|
||||
add_Xsig_Xsig(&accumulator, &argSqrd);
|
||||
|
||||
shr_Xsig(&accumulator, 1);
|
||||
|
||||
accumulator.lsw |= 1; /* A zero accumulator here would cause problems */
|
||||
negate_Xsig(&accumulator);
|
||||
|
||||
/* The basic computation is complete. Now fix the answer to
|
||||
compensate for the error due to the approximation used for
|
||||
pi/2
|
||||
*/
|
||||
|
||||
/* This has an exponent of -65 */
|
||||
fix_up = 0x898cc517;
|
||||
/* The fix-up needs to be improved for larger args */
|
||||
if ( argSqrd.msw & 0xffc00000 )
|
||||
{
|
||||
/* Get about 32 bit precision in these: */
|
||||
fix_up -= mul_32_32(0x898cc517, argSqrd.msw) / 6;
|
||||
}
|
||||
fix_up = mul_32_32(fix_up, LL_MSW(fixed_arg));
|
||||
|
||||
adj = accumulator.lsw; /* temp save */
|
||||
accumulator.lsw -= fix_up;
|
||||
if ( accumulator.lsw > adj )
|
||||
XSIG_LL(accumulator) --;
|
||||
|
||||
echange = round_Xsig(&accumulator);
|
||||
|
||||
setexponentpos(&result, echange - 1);
|
||||
}
|
||||
|
||||
significand(&result) = XSIG_LL(accumulator);
|
||||
setsign(&result, getsign(st0_ptr));
|
||||
FPU_copy_to_reg0(&result, TAG_Valid);
|
||||
significand(&result) = XSIG_LL(accumulator);
|
||||
setsign(&result, getsign(st0_ptr));
|
||||
FPU_copy_to_reg0(&result, TAG_Valid);
|
||||
|
||||
#ifdef PARANOID
|
||||
if ( (exponent(&result) >= 0)
|
||||
&& (significand(&result) > 0x8000000000000000LL) )
|
||||
{
|
||||
EXCEPTION(EX_INTERNAL|0x150);
|
||||
}
|
||||
if ((exponent(&result) >= 0)
|
||||
&& (significand(&result) > 0x8000000000000000LL)) {
|
||||
EXCEPTION(EX_INTERNAL | 0x150);
|
||||
}
|
||||
#endif /* PARANOID */
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*--- poly_cos() ------------------------------------------------------------+
|
||||
| |
|
||||
+---------------------------------------------------------------------------*/
|
||||
void poly_cos(FPU_REG *st0_ptr)
|
||||
void poly_cos(FPU_REG * st0_ptr)
|
||||
{
|
||||
FPU_REG result;
|
||||
long int exponent, exp2, echange;
|
||||
Xsig accumulator, argSqrd, fix_up, argTo4;
|
||||
unsigned long long fixed_arg;
|
||||
FPU_REG result;
|
||||
long int exponent, exp2, echange;
|
||||
Xsig accumulator, argSqrd, fix_up, argTo4;
|
||||
unsigned long long fixed_arg;
|
||||
|
||||
#ifdef PARANOID
|
||||
if ( (exponent(st0_ptr) > 0)
|
||||
|| ((exponent(st0_ptr) == 0)
|
||||
&& (significand(st0_ptr) > 0xc90fdaa22168c234LL)) )
|
||||
{
|
||||
EXCEPTION(EX_Invalid);
|
||||
FPU_copy_to_reg0(&CONST_QNaN, TAG_Special);
|
||||
return;
|
||||
}
|
||||
if ((exponent(st0_ptr) > 0)
|
||||
|| ((exponent(st0_ptr) == 0)
|
||||
&& (significand(st0_ptr) > 0xc90fdaa22168c234LL))) {
|
||||
EXCEPTION(EX_Invalid);
|
||||
FPU_copy_to_reg0(&CONST_QNaN, TAG_Special);
|
||||
return;
|
||||
}
|
||||
#endif /* PARANOID */
|
||||
|
||||
exponent = exponent(st0_ptr);
|
||||
exponent = exponent(st0_ptr);
|
||||
|
||||
accumulator.lsw = accumulator.midw = accumulator.msw = 0;
|
||||
accumulator.lsw = accumulator.midw = accumulator.msw = 0;
|
||||
|
||||
if ( (exponent < -1) || ((exponent == -1) && (st0_ptr->sigh <= 0xb00d6f54)) )
|
||||
{
|
||||
/* arg is < 0.687705 */
|
||||
if ((exponent < -1)
|
||||
|| ((exponent == -1) && (st0_ptr->sigh <= 0xb00d6f54))) {
|
||||
/* arg is < 0.687705 */
|
||||
|
||||
argSqrd.msw = st0_ptr->sigh; argSqrd.midw = st0_ptr->sigl;
|
||||
argSqrd.lsw = 0;
|
||||
mul64_Xsig(&argSqrd, &significand(st0_ptr));
|
||||
argSqrd.msw = st0_ptr->sigh;
|
||||
argSqrd.midw = st0_ptr->sigl;
|
||||
argSqrd.lsw = 0;
|
||||
mul64_Xsig(&argSqrd, &significand(st0_ptr));
|
||||
|
||||
if ( exponent < -1 )
|
||||
{
|
||||
/* shift the argument right by the required places */
|
||||
shr_Xsig(&argSqrd, 2*(-1-exponent));
|
||||
if (exponent < -1) {
|
||||
/* shift the argument right by the required places */
|
||||
shr_Xsig(&argSqrd, 2 * (-1 - exponent));
|
||||
}
|
||||
|
||||
argTo4.msw = argSqrd.msw;
|
||||
argTo4.midw = argSqrd.midw;
|
||||
argTo4.lsw = argSqrd.lsw;
|
||||
mul_Xsig_Xsig(&argTo4, &argTo4);
|
||||
|
||||
polynomial_Xsig(&accumulator, &XSIG_LL(argTo4), neg_terms_h,
|
||||
N_COEFF_NH - 1);
|
||||
mul_Xsig_Xsig(&accumulator, &argSqrd);
|
||||
negate_Xsig(&accumulator);
|
||||
|
||||
polynomial_Xsig(&accumulator, &XSIG_LL(argTo4), pos_terms_h,
|
||||
N_COEFF_PH - 1);
|
||||
negate_Xsig(&accumulator);
|
||||
|
||||
mul64_Xsig(&accumulator, &significand(st0_ptr));
|
||||
mul64_Xsig(&accumulator, &significand(st0_ptr));
|
||||
shr_Xsig(&accumulator, -2 * (1 + exponent));
|
||||
|
||||
shr_Xsig(&accumulator, 3);
|
||||
negate_Xsig(&accumulator);
|
||||
|
||||
add_Xsig_Xsig(&accumulator, &argSqrd);
|
||||
|
||||
shr_Xsig(&accumulator, 1);
|
||||
|
||||
/* It doesn't matter if accumulator is all zero here, the
|
||||
following code will work ok */
|
||||
negate_Xsig(&accumulator);
|
||||
|
||||
if (accumulator.lsw & 0x80000000)
|
||||
XSIG_LL(accumulator)++;
|
||||
if (accumulator.msw == 0) {
|
||||
/* The result is 1.0 */
|
||||
FPU_copy_to_reg0(&CONST_1, TAG_Valid);
|
||||
return;
|
||||
} else {
|
||||
significand(&result) = XSIG_LL(accumulator);
|
||||
|
||||
/* will be a valid positive nr with expon = -1 */
|
||||
setexponentpos(&result, -1);
|
||||
}
|
||||
} else {
|
||||
fixed_arg = significand(st0_ptr);
|
||||
|
||||
if (exponent == 0) {
|
||||
/* The argument is >= 1.0 */
|
||||
|
||||
/* Put the binary point at the left. */
|
||||
fixed_arg <<= 1;
|
||||
}
|
||||
/* pi/2 in hex is: 1.921fb54442d18469 898CC51701B839A2 52049C1 */
|
||||
fixed_arg = 0x921fb54442d18469LL - fixed_arg;
|
||||
/* There is a special case which arises due to rounding, to fix here. */
|
||||
if (fixed_arg == 0xffffffffffffffffLL)
|
||||
fixed_arg = 0;
|
||||
|
||||
exponent = -1;
|
||||
exp2 = -1;
|
||||
|
||||
/* A shift is needed here only for a narrow range of arguments,
|
||||
i.e. for fixed_arg approx 2^-32, but we pick up more... */
|
||||
if (!(LL_MSW(fixed_arg) & 0xffff0000)) {
|
||||
fixed_arg <<= 16;
|
||||
exponent -= 16;
|
||||
exp2 -= 16;
|
||||
}
|
||||
|
||||
XSIG_LL(argSqrd) = fixed_arg;
|
||||
argSqrd.lsw = 0;
|
||||
mul64_Xsig(&argSqrd, &fixed_arg);
|
||||
|
||||
if (exponent < -1) {
|
||||
/* shift the argument right by the required places */
|
||||
shr_Xsig(&argSqrd, 2 * (-1 - exponent));
|
||||
}
|
||||
|
||||
argTo4.msw = argSqrd.msw;
|
||||
argTo4.midw = argSqrd.midw;
|
||||
argTo4.lsw = argSqrd.lsw;
|
||||
mul_Xsig_Xsig(&argTo4, &argTo4);
|
||||
|
||||
polynomial_Xsig(&accumulator, &XSIG_LL(argTo4), neg_terms_l,
|
||||
N_COEFF_N - 1);
|
||||
mul_Xsig_Xsig(&accumulator, &argSqrd);
|
||||
negate_Xsig(&accumulator);
|
||||
|
||||
polynomial_Xsig(&accumulator, &XSIG_LL(argTo4), pos_terms_l,
|
||||
N_COEFF_P - 1);
|
||||
|
||||
shr_Xsig(&accumulator, 2); /* Divide by four */
|
||||
accumulator.msw |= 0x80000000; /* Add 1.0 */
|
||||
|
||||
mul64_Xsig(&accumulator, &fixed_arg);
|
||||
mul64_Xsig(&accumulator, &fixed_arg);
|
||||
mul64_Xsig(&accumulator, &fixed_arg);
|
||||
|
||||
/* Divide by four, FPU_REG compatible, etc */
|
||||
exponent = 3 * exponent;
|
||||
|
||||
/* The minimum exponent difference is 3 */
|
||||
shr_Xsig(&accumulator, exp2 - exponent);
|
||||
|
||||
negate_Xsig(&accumulator);
|
||||
XSIG_LL(accumulator) += fixed_arg;
|
||||
|
||||
/* The basic computation is complete. Now fix the answer to
|
||||
compensate for the error due to the approximation used for
|
||||
pi/2
|
||||
*/
|
||||
|
||||
/* This has an exponent of -65 */
|
||||
XSIG_LL(fix_up) = 0x898cc51701b839a2ll;
|
||||
fix_up.lsw = 0;
|
||||
|
||||
/* The fix-up needs to be improved for larger args */
|
||||
if (argSqrd.msw & 0xffc00000) {
|
||||
/* Get about 32 bit precision in these: */
|
||||
fix_up.msw -= mul_32_32(0x898cc517, argSqrd.msw) / 2;
|
||||
fix_up.msw += mul_32_32(0x898cc517, argTo4.msw) / 24;
|
||||
}
|
||||
|
||||
exp2 += norm_Xsig(&accumulator);
|
||||
shr_Xsig(&accumulator, 1); /* Prevent overflow */
|
||||
exp2++;
|
||||
shr_Xsig(&fix_up, 65 + exp2);
|
||||
|
||||
add_Xsig_Xsig(&accumulator, &fix_up);
|
||||
|
||||
echange = round_Xsig(&accumulator);
|
||||
|
||||
setexponentpos(&result, exp2 + echange);
|
||||
significand(&result) = XSIG_LL(accumulator);
|
||||
}
|
||||
|
||||
argTo4.msw = argSqrd.msw; argTo4.midw = argSqrd.midw;
|
||||
argTo4.lsw = argSqrd.lsw;
|
||||
mul_Xsig_Xsig(&argTo4, &argTo4);
|
||||
|
||||
polynomial_Xsig(&accumulator, &XSIG_LL(argTo4), neg_terms_h,
|
||||
N_COEFF_NH-1);
|
||||
mul_Xsig_Xsig(&accumulator, &argSqrd);
|
||||
negate_Xsig(&accumulator);
|
||||
|
||||
polynomial_Xsig(&accumulator, &XSIG_LL(argTo4), pos_terms_h,
|
||||
N_COEFF_PH-1);
|
||||
negate_Xsig(&accumulator);
|
||||
|
||||
mul64_Xsig(&accumulator, &significand(st0_ptr));
|
||||
mul64_Xsig(&accumulator, &significand(st0_ptr));
|
||||
shr_Xsig(&accumulator, -2*(1+exponent));
|
||||
|
||||
shr_Xsig(&accumulator, 3);
|
||||
negate_Xsig(&accumulator);
|
||||
|
||||
add_Xsig_Xsig(&accumulator, &argSqrd);
|
||||
|
||||
shr_Xsig(&accumulator, 1);
|
||||
|
||||
/* It doesn't matter if accumulator is all zero here, the
|
||||
following code will work ok */
|
||||
negate_Xsig(&accumulator);
|
||||
|
||||
if ( accumulator.lsw & 0x80000000 )
|
||||
XSIG_LL(accumulator) ++;
|
||||
if ( accumulator.msw == 0 )
|
||||
{
|
||||
/* The result is 1.0 */
|
||||
FPU_copy_to_reg0(&CONST_1, TAG_Valid);
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
significand(&result) = XSIG_LL(accumulator);
|
||||
|
||||
/* will be a valid positive nr with expon = -1 */
|
||||
setexponentpos(&result, -1);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
fixed_arg = significand(st0_ptr);
|
||||
|
||||
if ( exponent == 0 )
|
||||
{
|
||||
/* The argument is >= 1.0 */
|
||||
|
||||
/* Put the binary point at the left. */
|
||||
fixed_arg <<= 1;
|
||||
}
|
||||
/* pi/2 in hex is: 1.921fb54442d18469 898CC51701B839A2 52049C1 */
|
||||
fixed_arg = 0x921fb54442d18469LL - fixed_arg;
|
||||
/* There is a special case which arises due to rounding, to fix here. */
|
||||
if ( fixed_arg == 0xffffffffffffffffLL )
|
||||
fixed_arg = 0;
|
||||
|
||||
exponent = -1;
|
||||
exp2 = -1;
|
||||
|
||||
/* A shift is needed here only for a narrow range of arguments,
|
||||
i.e. for fixed_arg approx 2^-32, but we pick up more... */
|
||||
if ( !(LL_MSW(fixed_arg) & 0xffff0000) )
|
||||
{
|
||||
fixed_arg <<= 16;
|
||||
exponent -= 16;
|
||||
exp2 -= 16;
|
||||
}
|
||||
|
||||
XSIG_LL(argSqrd) = fixed_arg; argSqrd.lsw = 0;
|
||||
mul64_Xsig(&argSqrd, &fixed_arg);
|
||||
|
||||
if ( exponent < -1 )
|
||||
{
|
||||
/* shift the argument right by the required places */
|
||||
shr_Xsig(&argSqrd, 2*(-1-exponent));
|
||||
}
|
||||
|
||||
argTo4.msw = argSqrd.msw; argTo4.midw = argSqrd.midw;
|
||||
argTo4.lsw = argSqrd.lsw;
|
||||
mul_Xsig_Xsig(&argTo4, &argTo4);
|
||||
|
||||
polynomial_Xsig(&accumulator, &XSIG_LL(argTo4), neg_terms_l,
|
||||
N_COEFF_N-1);
|
||||
mul_Xsig_Xsig(&accumulator, &argSqrd);
|
||||
negate_Xsig(&accumulator);
|
||||
|
||||
polynomial_Xsig(&accumulator, &XSIG_LL(argTo4), pos_terms_l,
|
||||
N_COEFF_P-1);
|
||||
|
||||
shr_Xsig(&accumulator, 2); /* Divide by four */
|
||||
accumulator.msw |= 0x80000000; /* Add 1.0 */
|
||||
|
||||
mul64_Xsig(&accumulator, &fixed_arg);
|
||||
mul64_Xsig(&accumulator, &fixed_arg);
|
||||
mul64_Xsig(&accumulator, &fixed_arg);
|
||||
|
||||
/* Divide by four, FPU_REG compatible, etc */
|
||||
exponent = 3*exponent;
|
||||
|
||||
/* The minimum exponent difference is 3 */
|
||||
shr_Xsig(&accumulator, exp2 - exponent);
|
||||
|
||||
negate_Xsig(&accumulator);
|
||||
XSIG_LL(accumulator) += fixed_arg;
|
||||
|
||||
/* The basic computation is complete. Now fix the answer to
|
||||
compensate for the error due to the approximation used for
|
||||
pi/2
|
||||
*/
|
||||
|
||||
/* This has an exponent of -65 */
|
||||
XSIG_LL(fix_up) = 0x898cc51701b839a2ll;
|
||||
fix_up.lsw = 0;
|
||||
|
||||
/* The fix-up needs to be improved for larger args */
|
||||
if ( argSqrd.msw & 0xffc00000 )
|
||||
{
|
||||
/* Get about 32 bit precision in these: */
|
||||
fix_up.msw -= mul_32_32(0x898cc517, argSqrd.msw) / 2;
|
||||
fix_up.msw += mul_32_32(0x898cc517, argTo4.msw) / 24;
|
||||
}
|
||||
|
||||
exp2 += norm_Xsig(&accumulator);
|
||||
shr_Xsig(&accumulator, 1); /* Prevent overflow */
|
||||
exp2++;
|
||||
shr_Xsig(&fix_up, 65 + exp2);
|
||||
|
||||
add_Xsig_Xsig(&accumulator, &fix_up);
|
||||
|
||||
echange = round_Xsig(&accumulator);
|
||||
|
||||
setexponentpos(&result, exp2 + echange);
|
||||
significand(&result) = XSIG_LL(accumulator);
|
||||
}
|
||||
|
||||
FPU_copy_to_reg0(&result, TAG_Valid);
|
||||
FPU_copy_to_reg0(&result, TAG_Valid);
|
||||
|
||||
#ifdef PARANOID
|
||||
if ( (exponent(&result) >= 0)
|
||||
&& (significand(&result) > 0x8000000000000000LL) )
|
||||
{
|
||||
EXCEPTION(EX_INTERNAL|0x151);
|
||||
}
|
||||
if ((exponent(&result) >= 0)
|
||||
&& (significand(&result) > 0x8000000000000000LL)) {
|
||||
EXCEPTION(EX_INTERNAL | 0x151);
|
||||
}
|
||||
#endif /* PARANOID */
|
||||
|
||||
}
|
||||
|
|
|
@ -17,206 +17,196 @@
|
|||
#include "control_w.h"
|
||||
#include "poly.h"
|
||||
|
||||
|
||||
#define HiPOWERop 3 /* odd poly, positive terms */
|
||||
static const unsigned long long oddplterm[HiPOWERop] =
|
||||
{
|
||||
0x0000000000000000LL,
|
||||
0x0051a1cf08fca228LL,
|
||||
0x0000000071284ff7LL
|
||||
static const unsigned long long oddplterm[HiPOWERop] = {
|
||||
0x0000000000000000LL,
|
||||
0x0051a1cf08fca228LL,
|
||||
0x0000000071284ff7LL
|
||||
};
|
||||
|
||||
#define HiPOWERon 2 /* odd poly, negative terms */
|
||||
static const unsigned long long oddnegterm[HiPOWERon] =
|
||||
{
|
||||
0x1291a9a184244e80LL,
|
||||
0x0000583245819c21LL
|
||||
static const unsigned long long oddnegterm[HiPOWERon] = {
|
||||
0x1291a9a184244e80LL,
|
||||
0x0000583245819c21LL
|
||||
};
|
||||
|
||||
#define HiPOWERep 2 /* even poly, positive terms */
|
||||
static const unsigned long long evenplterm[HiPOWERep] =
|
||||
{
|
||||
0x0e848884b539e888LL,
|
||||
0x00003c7f18b887daLL
|
||||
static const unsigned long long evenplterm[HiPOWERep] = {
|
||||
0x0e848884b539e888LL,
|
||||
0x00003c7f18b887daLL
|
||||
};
|
||||
|
||||
#define HiPOWERen 2 /* even poly, negative terms */
|
||||
static const unsigned long long evennegterm[HiPOWERen] =
|
||||
{
|
||||
0xf1f0200fd51569ccLL,
|
||||
0x003afb46105c4432LL
|
||||
static const unsigned long long evennegterm[HiPOWERen] = {
|
||||
0xf1f0200fd51569ccLL,
|
||||
0x003afb46105c4432LL
|
||||
};
|
||||
|
||||
static const unsigned long long twothirds = 0xaaaaaaaaaaaaaaabLL;
|
||||
|
||||
|
||||
/*--- poly_tan() ------------------------------------------------------------+
|
||||
| |
|
||||
+---------------------------------------------------------------------------*/
|
||||
void poly_tan(FPU_REG *st0_ptr)
|
||||
void poly_tan(FPU_REG * st0_ptr)
|
||||
{
|
||||
long int exponent;
|
||||
int invert;
|
||||
Xsig argSq, argSqSq, accumulatoro, accumulatore, accum,
|
||||
argSignif, fix_up;
|
||||
unsigned long adj;
|
||||
long int exponent;
|
||||
int invert;
|
||||
Xsig argSq, argSqSq, accumulatoro, accumulatore, accum,
|
||||
argSignif, fix_up;
|
||||
unsigned long adj;
|
||||
|
||||
exponent = exponent(st0_ptr);
|
||||
exponent = exponent(st0_ptr);
|
||||
|
||||
#ifdef PARANOID
|
||||
if ( signnegative(st0_ptr) ) /* Can't hack a number < 0.0 */
|
||||
{ arith_invalid(0); return; } /* Need a positive number */
|
||||
if (signnegative(st0_ptr)) { /* Can't hack a number < 0.0 */
|
||||
arith_invalid(0);
|
||||
return;
|
||||
} /* Need a positive number */
|
||||
#endif /* PARANOID */
|
||||
|
||||
/* Split the problem into two domains, smaller and larger than pi/4 */
|
||||
if ( (exponent == 0) || ((exponent == -1) && (st0_ptr->sigh > 0xc90fdaa2)) )
|
||||
{
|
||||
/* The argument is greater than (approx) pi/4 */
|
||||
invert = 1;
|
||||
accum.lsw = 0;
|
||||
XSIG_LL(accum) = significand(st0_ptr);
|
||||
|
||||
if ( exponent == 0 )
|
||||
{
|
||||
/* The argument is >= 1.0 */
|
||||
/* Put the binary point at the left. */
|
||||
XSIG_LL(accum) <<= 1;
|
||||
}
|
||||
/* pi/2 in hex is: 1.921fb54442d18469 898CC51701B839A2 52049C1 */
|
||||
XSIG_LL(accum) = 0x921fb54442d18469LL - XSIG_LL(accum);
|
||||
/* This is a special case which arises due to rounding. */
|
||||
if ( XSIG_LL(accum) == 0xffffffffffffffffLL )
|
||||
{
|
||||
FPU_settag0(TAG_Valid);
|
||||
significand(st0_ptr) = 0x8a51e04daabda360LL;
|
||||
setexponent16(st0_ptr, (0x41 + EXTENDED_Ebias) | SIGN_Negative);
|
||||
return;
|
||||
/* Split the problem into two domains, smaller and larger than pi/4 */
|
||||
if ((exponent == 0)
|
||||
|| ((exponent == -1) && (st0_ptr->sigh > 0xc90fdaa2))) {
|
||||
/* The argument is greater than (approx) pi/4 */
|
||||
invert = 1;
|
||||
accum.lsw = 0;
|
||||
XSIG_LL(accum) = significand(st0_ptr);
|
||||
|
||||
if (exponent == 0) {
|
||||
/* The argument is >= 1.0 */
|
||||
/* Put the binary point at the left. */
|
||||
XSIG_LL(accum) <<= 1;
|
||||
}
|
||||
/* pi/2 in hex is: 1.921fb54442d18469 898CC51701B839A2 52049C1 */
|
||||
XSIG_LL(accum) = 0x921fb54442d18469LL - XSIG_LL(accum);
|
||||
/* This is a special case which arises due to rounding. */
|
||||
if (XSIG_LL(accum) == 0xffffffffffffffffLL) {
|
||||
FPU_settag0(TAG_Valid);
|
||||
significand(st0_ptr) = 0x8a51e04daabda360LL;
|
||||
setexponent16(st0_ptr,
|
||||
(0x41 + EXTENDED_Ebias) | SIGN_Negative);
|
||||
return;
|
||||
}
|
||||
|
||||
argSignif.lsw = accum.lsw;
|
||||
XSIG_LL(argSignif) = XSIG_LL(accum);
|
||||
exponent = -1 + norm_Xsig(&argSignif);
|
||||
} else {
|
||||
invert = 0;
|
||||
argSignif.lsw = 0;
|
||||
XSIG_LL(accum) = XSIG_LL(argSignif) = significand(st0_ptr);
|
||||
|
||||
if (exponent < -1) {
|
||||
/* shift the argument right by the required places */
|
||||
if (FPU_shrx(&XSIG_LL(accum), -1 - exponent) >=
|
||||
0x80000000U)
|
||||
XSIG_LL(accum)++; /* round up */
|
||||
}
|
||||
}
|
||||
|
||||
argSignif.lsw = accum.lsw;
|
||||
XSIG_LL(argSignif) = XSIG_LL(accum);
|
||||
exponent = -1 + norm_Xsig(&argSignif);
|
||||
}
|
||||
else
|
||||
{
|
||||
invert = 0;
|
||||
argSignif.lsw = 0;
|
||||
XSIG_LL(accum) = XSIG_LL(argSignif) = significand(st0_ptr);
|
||||
|
||||
if ( exponent < -1 )
|
||||
{
|
||||
/* shift the argument right by the required places */
|
||||
if ( FPU_shrx(&XSIG_LL(accum), -1-exponent) >= 0x80000000U )
|
||||
XSIG_LL(accum) ++; /* round up */
|
||||
XSIG_LL(argSq) = XSIG_LL(accum);
|
||||
argSq.lsw = accum.lsw;
|
||||
mul_Xsig_Xsig(&argSq, &argSq);
|
||||
XSIG_LL(argSqSq) = XSIG_LL(argSq);
|
||||
argSqSq.lsw = argSq.lsw;
|
||||
mul_Xsig_Xsig(&argSqSq, &argSqSq);
|
||||
|
||||
/* Compute the negative terms for the numerator polynomial */
|
||||
accumulatoro.msw = accumulatoro.midw = accumulatoro.lsw = 0;
|
||||
polynomial_Xsig(&accumulatoro, &XSIG_LL(argSqSq), oddnegterm,
|
||||
HiPOWERon - 1);
|
||||
mul_Xsig_Xsig(&accumulatoro, &argSq);
|
||||
negate_Xsig(&accumulatoro);
|
||||
/* Add the positive terms */
|
||||
polynomial_Xsig(&accumulatoro, &XSIG_LL(argSqSq), oddplterm,
|
||||
HiPOWERop - 1);
|
||||
|
||||
/* Compute the positive terms for the denominator polynomial */
|
||||
accumulatore.msw = accumulatore.midw = accumulatore.lsw = 0;
|
||||
polynomial_Xsig(&accumulatore, &XSIG_LL(argSqSq), evenplterm,
|
||||
HiPOWERep - 1);
|
||||
mul_Xsig_Xsig(&accumulatore, &argSq);
|
||||
negate_Xsig(&accumulatore);
|
||||
/* Add the negative terms */
|
||||
polynomial_Xsig(&accumulatore, &XSIG_LL(argSqSq), evennegterm,
|
||||
HiPOWERen - 1);
|
||||
/* Multiply by arg^2 */
|
||||
mul64_Xsig(&accumulatore, &XSIG_LL(argSignif));
|
||||
mul64_Xsig(&accumulatore, &XSIG_LL(argSignif));
|
||||
/* de-normalize and divide by 2 */
|
||||
shr_Xsig(&accumulatore, -2 * (1 + exponent) + 1);
|
||||
negate_Xsig(&accumulatore); /* This does 1 - accumulator */
|
||||
|
||||
/* Now find the ratio. */
|
||||
if (accumulatore.msw == 0) {
|
||||
/* accumulatoro must contain 1.0 here, (actually, 0) but it
|
||||
really doesn't matter what value we use because it will
|
||||
have negligible effect in later calculations
|
||||
*/
|
||||
XSIG_LL(accum) = 0x8000000000000000LL;
|
||||
accum.lsw = 0;
|
||||
} else {
|
||||
div_Xsig(&accumulatoro, &accumulatore, &accum);
|
||||
}
|
||||
}
|
||||
|
||||
XSIG_LL(argSq) = XSIG_LL(accum); argSq.lsw = accum.lsw;
|
||||
mul_Xsig_Xsig(&argSq, &argSq);
|
||||
XSIG_LL(argSqSq) = XSIG_LL(argSq); argSqSq.lsw = argSq.lsw;
|
||||
mul_Xsig_Xsig(&argSqSq, &argSqSq);
|
||||
/* Multiply by 1/3 * arg^3 */
|
||||
mul64_Xsig(&accum, &XSIG_LL(argSignif));
|
||||
mul64_Xsig(&accum, &XSIG_LL(argSignif));
|
||||
mul64_Xsig(&accum, &XSIG_LL(argSignif));
|
||||
mul64_Xsig(&accum, &twothirds);
|
||||
shr_Xsig(&accum, -2 * (exponent + 1));
|
||||
|
||||
/* Compute the negative terms for the numerator polynomial */
|
||||
accumulatoro.msw = accumulatoro.midw = accumulatoro.lsw = 0;
|
||||
polynomial_Xsig(&accumulatoro, &XSIG_LL(argSqSq), oddnegterm, HiPOWERon-1);
|
||||
mul_Xsig_Xsig(&accumulatoro, &argSq);
|
||||
negate_Xsig(&accumulatoro);
|
||||
/* Add the positive terms */
|
||||
polynomial_Xsig(&accumulatoro, &XSIG_LL(argSqSq), oddplterm, HiPOWERop-1);
|
||||
/* tan(arg) = arg + accum */
|
||||
add_two_Xsig(&accum, &argSignif, &exponent);
|
||||
|
||||
|
||||
/* Compute the positive terms for the denominator polynomial */
|
||||
accumulatore.msw = accumulatore.midw = accumulatore.lsw = 0;
|
||||
polynomial_Xsig(&accumulatore, &XSIG_LL(argSqSq), evenplterm, HiPOWERep-1);
|
||||
mul_Xsig_Xsig(&accumulatore, &argSq);
|
||||
negate_Xsig(&accumulatore);
|
||||
/* Add the negative terms */
|
||||
polynomial_Xsig(&accumulatore, &XSIG_LL(argSqSq), evennegterm, HiPOWERen-1);
|
||||
/* Multiply by arg^2 */
|
||||
mul64_Xsig(&accumulatore, &XSIG_LL(argSignif));
|
||||
mul64_Xsig(&accumulatore, &XSIG_LL(argSignif));
|
||||
/* de-normalize and divide by 2 */
|
||||
shr_Xsig(&accumulatore, -2*(1+exponent) + 1);
|
||||
negate_Xsig(&accumulatore); /* This does 1 - accumulator */
|
||||
if (invert) {
|
||||
/* We now have the value of tan(pi_2 - arg) where pi_2 is an
|
||||
approximation for pi/2
|
||||
*/
|
||||
/* The next step is to fix the answer to compensate for the
|
||||
error due to the approximation used for pi/2
|
||||
*/
|
||||
|
||||
/* Now find the ratio. */
|
||||
if ( accumulatore.msw == 0 )
|
||||
{
|
||||
/* accumulatoro must contain 1.0 here, (actually, 0) but it
|
||||
really doesn't matter what value we use because it will
|
||||
have negligible effect in later calculations
|
||||
*/
|
||||
XSIG_LL(accum) = 0x8000000000000000LL;
|
||||
accum.lsw = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
div_Xsig(&accumulatoro, &accumulatore, &accum);
|
||||
}
|
||||
/* This is (approx) delta, the error in our approx for pi/2
|
||||
(see above). It has an exponent of -65
|
||||
*/
|
||||
XSIG_LL(fix_up) = 0x898cc51701b839a2LL;
|
||||
fix_up.lsw = 0;
|
||||
|
||||
/* Multiply by 1/3 * arg^3 */
|
||||
mul64_Xsig(&accum, &XSIG_LL(argSignif));
|
||||
mul64_Xsig(&accum, &XSIG_LL(argSignif));
|
||||
mul64_Xsig(&accum, &XSIG_LL(argSignif));
|
||||
mul64_Xsig(&accum, &twothirds);
|
||||
shr_Xsig(&accum, -2*(exponent+1));
|
||||
if (exponent == 0)
|
||||
adj = 0xffffffff; /* We want approx 1.0 here, but
|
||||
this is close enough. */
|
||||
else if (exponent > -30) {
|
||||
adj = accum.msw >> -(exponent + 1); /* tan */
|
||||
adj = mul_32_32(adj, adj); /* tan^2 */
|
||||
} else
|
||||
adj = 0;
|
||||
adj = mul_32_32(0x898cc517, adj); /* delta * tan^2 */
|
||||
|
||||
/* tan(arg) = arg + accum */
|
||||
add_two_Xsig(&accum, &argSignif, &exponent);
|
||||
fix_up.msw += adj;
|
||||
if (!(fix_up.msw & 0x80000000)) { /* did fix_up overflow ? */
|
||||
/* Yes, we need to add an msb */
|
||||
shr_Xsig(&fix_up, 1);
|
||||
fix_up.msw |= 0x80000000;
|
||||
shr_Xsig(&fix_up, 64 + exponent);
|
||||
} else
|
||||
shr_Xsig(&fix_up, 65 + exponent);
|
||||
|
||||
if ( invert )
|
||||
{
|
||||
/* We now have the value of tan(pi_2 - arg) where pi_2 is an
|
||||
approximation for pi/2
|
||||
*/
|
||||
/* The next step is to fix the answer to compensate for the
|
||||
error due to the approximation used for pi/2
|
||||
*/
|
||||
add_two_Xsig(&accum, &fix_up, &exponent);
|
||||
|
||||
/* This is (approx) delta, the error in our approx for pi/2
|
||||
(see above). It has an exponent of -65
|
||||
*/
|
||||
XSIG_LL(fix_up) = 0x898cc51701b839a2LL;
|
||||
fix_up.lsw = 0;
|
||||
|
||||
if ( exponent == 0 )
|
||||
adj = 0xffffffff; /* We want approx 1.0 here, but
|
||||
this is close enough. */
|
||||
else if ( exponent > -30 )
|
||||
{
|
||||
adj = accum.msw >> -(exponent+1); /* tan */
|
||||
adj = mul_32_32(adj, adj); /* tan^2 */
|
||||
/* accum now contains tan(pi/2 - arg).
|
||||
Use tan(arg) = 1.0 / tan(pi/2 - arg)
|
||||
*/
|
||||
accumulatoro.lsw = accumulatoro.midw = 0;
|
||||
accumulatoro.msw = 0x80000000;
|
||||
div_Xsig(&accumulatoro, &accum, &accum);
|
||||
exponent = -exponent - 1;
|
||||
}
|
||||
else
|
||||
adj = 0;
|
||||
adj = mul_32_32(0x898cc517, adj); /* delta * tan^2 */
|
||||
|
||||
fix_up.msw += adj;
|
||||
if ( !(fix_up.msw & 0x80000000) ) /* did fix_up overflow ? */
|
||||
{
|
||||
/* Yes, we need to add an msb */
|
||||
shr_Xsig(&fix_up, 1);
|
||||
fix_up.msw |= 0x80000000;
|
||||
shr_Xsig(&fix_up, 64 + exponent);
|
||||
}
|
||||
else
|
||||
shr_Xsig(&fix_up, 65 + exponent);
|
||||
|
||||
add_two_Xsig(&accum, &fix_up, &exponent);
|
||||
|
||||
/* accum now contains tan(pi/2 - arg).
|
||||
Use tan(arg) = 1.0 / tan(pi/2 - arg)
|
||||
*/
|
||||
accumulatoro.lsw = accumulatoro.midw = 0;
|
||||
accumulatoro.msw = 0x80000000;
|
||||
div_Xsig(&accumulatoro, &accum, &accum);
|
||||
exponent = - exponent - 1;
|
||||
}
|
||||
|
||||
/* Transfer the result */
|
||||
round_Xsig(&accum);
|
||||
FPU_settag0(TAG_Valid);
|
||||
significand(st0_ptr) = XSIG_LL(accum);
|
||||
setexponent16(st0_ptr, exponent + EXTENDED_Ebias); /* Result is positive. */
|
||||
/* Transfer the result */
|
||||
round_Xsig(&accum);
|
||||
FPU_settag0(TAG_Valid);
|
||||
significand(st0_ptr) = XSIG_LL(accum);
|
||||
setexponent16(st0_ptr, exponent + EXTENDED_Ebias); /* Result is positive. */
|
||||
|
||||
}
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
static
|
||||
int add_sub_specials(FPU_REG const *a, u_char taga, u_char signa,
|
||||
FPU_REG const *b, u_char tagb, u_char signb,
|
||||
FPU_REG *dest, int deststnr, int control_w);
|
||||
FPU_REG * dest, int deststnr, int control_w);
|
||||
|
||||
/*
|
||||
Operates on st(0) and st(n), or on st(0) and temporary data.
|
||||
|
@ -35,340 +35,299 @@ int add_sub_specials(FPU_REG const *a, u_char taga, u_char signa,
|
|||
*/
|
||||
int FPU_add(FPU_REG const *b, u_char tagb, int deststnr, int control_w)
|
||||
{
|
||||
FPU_REG *a = &st(0);
|
||||
FPU_REG *dest = &st(deststnr);
|
||||
u_char signb = getsign(b);
|
||||
u_char taga = FPU_gettag0();
|
||||
u_char signa = getsign(a);
|
||||
u_char saved_sign = getsign(dest);
|
||||
int diff, tag, expa, expb;
|
||||
|
||||
if ( !(taga | tagb) )
|
||||
{
|
||||
expa = exponent(a);
|
||||
expb = exponent(b);
|
||||
FPU_REG *a = &st(0);
|
||||
FPU_REG *dest = &st(deststnr);
|
||||
u_char signb = getsign(b);
|
||||
u_char taga = FPU_gettag0();
|
||||
u_char signa = getsign(a);
|
||||
u_char saved_sign = getsign(dest);
|
||||
int diff, tag, expa, expb;
|
||||
|
||||
valid_add:
|
||||
/* Both registers are valid */
|
||||
if (!(signa ^ signb))
|
||||
{
|
||||
/* signs are the same */
|
||||
tag = FPU_u_add(a, b, dest, control_w, signa, expa, expb);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* The signs are different, so do a subtraction */
|
||||
diff = expa - expb;
|
||||
if (!diff)
|
||||
{
|
||||
diff = a->sigh - b->sigh; /* This works only if the ms bits
|
||||
are identical. */
|
||||
if (!diff)
|
||||
{
|
||||
diff = a->sigl > b->sigl;
|
||||
if (!diff)
|
||||
diff = -(a->sigl < b->sigl);
|
||||
if (!(taga | tagb)) {
|
||||
expa = exponent(a);
|
||||
expb = exponent(b);
|
||||
|
||||
valid_add:
|
||||
/* Both registers are valid */
|
||||
if (!(signa ^ signb)) {
|
||||
/* signs are the same */
|
||||
tag =
|
||||
FPU_u_add(a, b, dest, control_w, signa, expa, expb);
|
||||
} else {
|
||||
/* The signs are different, so do a subtraction */
|
||||
diff = expa - expb;
|
||||
if (!diff) {
|
||||
diff = a->sigh - b->sigh; /* This works only if the ms bits
|
||||
are identical. */
|
||||
if (!diff) {
|
||||
diff = a->sigl > b->sigl;
|
||||
if (!diff)
|
||||
diff = -(a->sigl < b->sigl);
|
||||
}
|
||||
}
|
||||
|
||||
if (diff > 0) {
|
||||
tag =
|
||||
FPU_u_sub(a, b, dest, control_w, signa,
|
||||
expa, expb);
|
||||
} else if (diff < 0) {
|
||||
tag =
|
||||
FPU_u_sub(b, a, dest, control_w, signb,
|
||||
expb, expa);
|
||||
} else {
|
||||
FPU_copy_to_regi(&CONST_Z, TAG_Zero, deststnr);
|
||||
/* sign depends upon rounding mode */
|
||||
setsign(dest, ((control_w & CW_RC) != RC_DOWN)
|
||||
? SIGN_POS : SIGN_NEG);
|
||||
return TAG_Zero;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (diff > 0)
|
||||
{
|
||||
tag = FPU_u_sub(a, b, dest, control_w, signa, expa, expb);
|
||||
}
|
||||
else if ( diff < 0 )
|
||||
{
|
||||
tag = FPU_u_sub(b, a, dest, control_w, signb, expb, expa);
|
||||
}
|
||||
else
|
||||
{
|
||||
FPU_copy_to_regi(&CONST_Z, TAG_Zero, deststnr);
|
||||
/* sign depends upon rounding mode */
|
||||
setsign(dest, ((control_w & CW_RC) != RC_DOWN)
|
||||
? SIGN_POS : SIGN_NEG);
|
||||
return TAG_Zero;
|
||||
}
|
||||
|
||||
if (tag < 0) {
|
||||
setsign(dest, saved_sign);
|
||||
return tag;
|
||||
}
|
||||
FPU_settagi(deststnr, tag);
|
||||
return tag;
|
||||
}
|
||||
|
||||
if ( tag < 0 )
|
||||
{
|
||||
setsign(dest, saved_sign);
|
||||
return tag;
|
||||
}
|
||||
FPU_settagi(deststnr, tag);
|
||||
return tag;
|
||||
}
|
||||
if (taga == TAG_Special)
|
||||
taga = FPU_Special(a);
|
||||
if (tagb == TAG_Special)
|
||||
tagb = FPU_Special(b);
|
||||
|
||||
if ( taga == TAG_Special )
|
||||
taga = FPU_Special(a);
|
||||
if ( tagb == TAG_Special )
|
||||
tagb = FPU_Special(b);
|
||||
|
||||
if ( ((taga == TAG_Valid) && (tagb == TW_Denormal))
|
||||
if (((taga == TAG_Valid) && (tagb == TW_Denormal))
|
||||
|| ((taga == TW_Denormal) && (tagb == TAG_Valid))
|
||||
|| ((taga == TW_Denormal) && (tagb == TW_Denormal)) )
|
||||
{
|
||||
FPU_REG x, y;
|
||||
|| ((taga == TW_Denormal) && (tagb == TW_Denormal))) {
|
||||
FPU_REG x, y;
|
||||
|
||||
if ( denormal_operand() < 0 )
|
||||
return FPU_Exception;
|
||||
if (denormal_operand() < 0)
|
||||
return FPU_Exception;
|
||||
|
||||
FPU_to_exp16(a, &x);
|
||||
FPU_to_exp16(b, &y);
|
||||
a = &x;
|
||||
b = &y;
|
||||
expa = exponent16(a);
|
||||
expb = exponent16(b);
|
||||
goto valid_add;
|
||||
}
|
||||
FPU_to_exp16(a, &x);
|
||||
FPU_to_exp16(b, &y);
|
||||
a = &x;
|
||||
b = &y;
|
||||
expa = exponent16(a);
|
||||
expb = exponent16(b);
|
||||
goto valid_add;
|
||||
}
|
||||
|
||||
if ( (taga == TW_NaN) || (tagb == TW_NaN) )
|
||||
{
|
||||
if ( deststnr == 0 )
|
||||
return real_2op_NaN(b, tagb, deststnr, a);
|
||||
else
|
||||
return real_2op_NaN(a, taga, deststnr, a);
|
||||
}
|
||||
if ((taga == TW_NaN) || (tagb == TW_NaN)) {
|
||||
if (deststnr == 0)
|
||||
return real_2op_NaN(b, tagb, deststnr, a);
|
||||
else
|
||||
return real_2op_NaN(a, taga, deststnr, a);
|
||||
}
|
||||
|
||||
return add_sub_specials(a, taga, signa, b, tagb, signb,
|
||||
dest, deststnr, control_w);
|
||||
return add_sub_specials(a, taga, signa, b, tagb, signb,
|
||||
dest, deststnr, control_w);
|
||||
}
|
||||
|
||||
|
||||
/* Subtract b from a. (a-b) -> dest */
|
||||
int FPU_sub(int flags, int rm, int control_w)
|
||||
{
|
||||
FPU_REG const *a, *b;
|
||||
FPU_REG *dest;
|
||||
u_char taga, tagb, signa, signb, saved_sign, sign;
|
||||
int diff, tag = 0, expa, expb, deststnr;
|
||||
FPU_REG const *a, *b;
|
||||
FPU_REG *dest;
|
||||
u_char taga, tagb, signa, signb, saved_sign, sign;
|
||||
int diff, tag = 0, expa, expb, deststnr;
|
||||
|
||||
a = &st(0);
|
||||
taga = FPU_gettag0();
|
||||
a = &st(0);
|
||||
taga = FPU_gettag0();
|
||||
|
||||
deststnr = 0;
|
||||
if ( flags & LOADED )
|
||||
{
|
||||
b = (FPU_REG *)rm;
|
||||
tagb = flags & 0x0f;
|
||||
}
|
||||
else
|
||||
{
|
||||
b = &st(rm);
|
||||
tagb = FPU_gettagi(rm);
|
||||
deststnr = 0;
|
||||
if (flags & LOADED) {
|
||||
b = (FPU_REG *) rm;
|
||||
tagb = flags & 0x0f;
|
||||
} else {
|
||||
b = &st(rm);
|
||||
tagb = FPU_gettagi(rm);
|
||||
|
||||
if ( flags & DEST_RM )
|
||||
deststnr = rm;
|
||||
}
|
||||
|
||||
signa = getsign(a);
|
||||
signb = getsign(b);
|
||||
|
||||
if ( flags & REV )
|
||||
{
|
||||
signa ^= SIGN_NEG;
|
||||
signb ^= SIGN_NEG;
|
||||
}
|
||||
|
||||
dest = &st(deststnr);
|
||||
saved_sign = getsign(dest);
|
||||
|
||||
if ( !(taga | tagb) )
|
||||
{
|
||||
expa = exponent(a);
|
||||
expb = exponent(b);
|
||||
|
||||
valid_subtract:
|
||||
/* Both registers are valid */
|
||||
|
||||
diff = expa - expb;
|
||||
|
||||
if (!diff)
|
||||
{
|
||||
diff = a->sigh - b->sigh; /* Works only if ms bits are identical */
|
||||
if (!diff)
|
||||
{
|
||||
diff = a->sigl > b->sigl;
|
||||
if (!diff)
|
||||
diff = -(a->sigl < b->sigl);
|
||||
}
|
||||
if (flags & DEST_RM)
|
||||
deststnr = rm;
|
||||
}
|
||||
|
||||
switch ( (((int)signa)*2 + signb) / SIGN_NEG )
|
||||
{
|
||||
case 0: /* P - P */
|
||||
case 3: /* N - N */
|
||||
if (diff > 0)
|
||||
{
|
||||
/* |a| > |b| */
|
||||
tag = FPU_u_sub(a, b, dest, control_w, signa, expa, expb);
|
||||
}
|
||||
else if ( diff == 0 )
|
||||
{
|
||||
FPU_copy_to_regi(&CONST_Z, TAG_Zero, deststnr);
|
||||
signa = getsign(a);
|
||||
signb = getsign(b);
|
||||
|
||||
/* sign depends upon rounding mode */
|
||||
setsign(dest, ((control_w & CW_RC) != RC_DOWN)
|
||||
? SIGN_POS : SIGN_NEG);
|
||||
return TAG_Zero;
|
||||
}
|
||||
else
|
||||
{
|
||||
sign = signa ^ SIGN_NEG;
|
||||
tag = FPU_u_sub(b, a, dest, control_w, sign, expb, expa);
|
||||
}
|
||||
break;
|
||||
case 1: /* P - N */
|
||||
tag = FPU_u_add(a, b, dest, control_w, SIGN_POS, expa, expb);
|
||||
break;
|
||||
case 2: /* N - P */
|
||||
tag = FPU_u_add(a, b, dest, control_w, SIGN_NEG, expa, expb);
|
||||
break;
|
||||
if (flags & REV) {
|
||||
signa ^= SIGN_NEG;
|
||||
signb ^= SIGN_NEG;
|
||||
}
|
||||
|
||||
dest = &st(deststnr);
|
||||
saved_sign = getsign(dest);
|
||||
|
||||
if (!(taga | tagb)) {
|
||||
expa = exponent(a);
|
||||
expb = exponent(b);
|
||||
|
||||
valid_subtract:
|
||||
/* Both registers are valid */
|
||||
|
||||
diff = expa - expb;
|
||||
|
||||
if (!diff) {
|
||||
diff = a->sigh - b->sigh; /* Works only if ms bits are identical */
|
||||
if (!diff) {
|
||||
diff = a->sigl > b->sigl;
|
||||
if (!diff)
|
||||
diff = -(a->sigl < b->sigl);
|
||||
}
|
||||
}
|
||||
|
||||
switch ((((int)signa) * 2 + signb) / SIGN_NEG) {
|
||||
case 0: /* P - P */
|
||||
case 3: /* N - N */
|
||||
if (diff > 0) {
|
||||
/* |a| > |b| */
|
||||
tag =
|
||||
FPU_u_sub(a, b, dest, control_w, signa,
|
||||
expa, expb);
|
||||
} else if (diff == 0) {
|
||||
FPU_copy_to_regi(&CONST_Z, TAG_Zero, deststnr);
|
||||
|
||||
/* sign depends upon rounding mode */
|
||||
setsign(dest, ((control_w & CW_RC) != RC_DOWN)
|
||||
? SIGN_POS : SIGN_NEG);
|
||||
return TAG_Zero;
|
||||
} else {
|
||||
sign = signa ^ SIGN_NEG;
|
||||
tag =
|
||||
FPU_u_sub(b, a, dest, control_w, sign, expb,
|
||||
expa);
|
||||
}
|
||||
break;
|
||||
case 1: /* P - N */
|
||||
tag =
|
||||
FPU_u_add(a, b, dest, control_w, SIGN_POS, expa,
|
||||
expb);
|
||||
break;
|
||||
case 2: /* N - P */
|
||||
tag =
|
||||
FPU_u_add(a, b, dest, control_w, SIGN_NEG, expa,
|
||||
expb);
|
||||
break;
|
||||
#ifdef PARANOID
|
||||
default:
|
||||
EXCEPTION(EX_INTERNAL|0x111);
|
||||
return -1;
|
||||
default:
|
||||
EXCEPTION(EX_INTERNAL | 0x111);
|
||||
return -1;
|
||||
#endif
|
||||
}
|
||||
if (tag < 0) {
|
||||
setsign(dest, saved_sign);
|
||||
return tag;
|
||||
}
|
||||
FPU_settagi(deststnr, tag);
|
||||
return tag;
|
||||
}
|
||||
if ( tag < 0 )
|
||||
{
|
||||
setsign(dest, saved_sign);
|
||||
return tag;
|
||||
}
|
||||
FPU_settagi(deststnr, tag);
|
||||
return tag;
|
||||
}
|
||||
|
||||
if ( taga == TAG_Special )
|
||||
taga = FPU_Special(a);
|
||||
if ( tagb == TAG_Special )
|
||||
tagb = FPU_Special(b);
|
||||
if (taga == TAG_Special)
|
||||
taga = FPU_Special(a);
|
||||
if (tagb == TAG_Special)
|
||||
tagb = FPU_Special(b);
|
||||
|
||||
if ( ((taga == TAG_Valid) && (tagb == TW_Denormal))
|
||||
if (((taga == TAG_Valid) && (tagb == TW_Denormal))
|
||||
|| ((taga == TW_Denormal) && (tagb == TAG_Valid))
|
||||
|| ((taga == TW_Denormal) && (tagb == TW_Denormal)) )
|
||||
{
|
||||
FPU_REG x, y;
|
||||
|| ((taga == TW_Denormal) && (tagb == TW_Denormal))) {
|
||||
FPU_REG x, y;
|
||||
|
||||
if ( denormal_operand() < 0 )
|
||||
return FPU_Exception;
|
||||
if (denormal_operand() < 0)
|
||||
return FPU_Exception;
|
||||
|
||||
FPU_to_exp16(a, &x);
|
||||
FPU_to_exp16(b, &y);
|
||||
a = &x;
|
||||
b = &y;
|
||||
expa = exponent16(a);
|
||||
expb = exponent16(b);
|
||||
FPU_to_exp16(a, &x);
|
||||
FPU_to_exp16(b, &y);
|
||||
a = &x;
|
||||
b = &y;
|
||||
expa = exponent16(a);
|
||||
expb = exponent16(b);
|
||||
|
||||
goto valid_subtract;
|
||||
}
|
||||
|
||||
if ( (taga == TW_NaN) || (tagb == TW_NaN) )
|
||||
{
|
||||
FPU_REG const *d1, *d2;
|
||||
if ( flags & REV )
|
||||
{
|
||||
d1 = b;
|
||||
d2 = a;
|
||||
goto valid_subtract;
|
||||
}
|
||||
else
|
||||
{
|
||||
d1 = a;
|
||||
d2 = b;
|
||||
}
|
||||
if ( flags & LOADED )
|
||||
return real_2op_NaN(b, tagb, deststnr, d1);
|
||||
if ( flags & DEST_RM )
|
||||
return real_2op_NaN(a, taga, deststnr, d2);
|
||||
else
|
||||
return real_2op_NaN(b, tagb, deststnr, d2);
|
||||
}
|
||||
|
||||
return add_sub_specials(a, taga, signa, b, tagb, signb ^ SIGN_NEG,
|
||||
dest, deststnr, control_w);
|
||||
if ((taga == TW_NaN) || (tagb == TW_NaN)) {
|
||||
FPU_REG const *d1, *d2;
|
||||
if (flags & REV) {
|
||||
d1 = b;
|
||||
d2 = a;
|
||||
} else {
|
||||
d1 = a;
|
||||
d2 = b;
|
||||
}
|
||||
if (flags & LOADED)
|
||||
return real_2op_NaN(b, tagb, deststnr, d1);
|
||||
if (flags & DEST_RM)
|
||||
return real_2op_NaN(a, taga, deststnr, d2);
|
||||
else
|
||||
return real_2op_NaN(b, tagb, deststnr, d2);
|
||||
}
|
||||
|
||||
return add_sub_specials(a, taga, signa, b, tagb, signb ^ SIGN_NEG,
|
||||
dest, deststnr, control_w);
|
||||
}
|
||||
|
||||
|
||||
static
|
||||
int add_sub_specials(FPU_REG const *a, u_char taga, u_char signa,
|
||||
FPU_REG const *b, u_char tagb, u_char signb,
|
||||
FPU_REG *dest, int deststnr, int control_w)
|
||||
FPU_REG * dest, int deststnr, int control_w)
|
||||
{
|
||||
if ( ((taga == TW_Denormal) || (tagb == TW_Denormal))
|
||||
&& (denormal_operand() < 0) )
|
||||
return FPU_Exception;
|
||||
if (((taga == TW_Denormal) || (tagb == TW_Denormal))
|
||||
&& (denormal_operand() < 0))
|
||||
return FPU_Exception;
|
||||
|
||||
if (taga == TAG_Zero)
|
||||
{
|
||||
if (tagb == TAG_Zero)
|
||||
{
|
||||
/* Both are zero, result will be zero. */
|
||||
u_char different_signs = signa ^ signb;
|
||||
if (taga == TAG_Zero) {
|
||||
if (tagb == TAG_Zero) {
|
||||
/* Both are zero, result will be zero. */
|
||||
u_char different_signs = signa ^ signb;
|
||||
|
||||
FPU_copy_to_regi(a, TAG_Zero, deststnr);
|
||||
if ( different_signs )
|
||||
{
|
||||
/* Signs are different. */
|
||||
/* Sign of answer depends upon rounding mode. */
|
||||
setsign(dest, ((control_w & CW_RC) != RC_DOWN)
|
||||
? SIGN_POS : SIGN_NEG);
|
||||
}
|
||||
else
|
||||
setsign(dest, signa); /* signa may differ from the sign of a. */
|
||||
return TAG_Zero;
|
||||
FPU_copy_to_regi(a, TAG_Zero, deststnr);
|
||||
if (different_signs) {
|
||||
/* Signs are different. */
|
||||
/* Sign of answer depends upon rounding mode. */
|
||||
setsign(dest, ((control_w & CW_RC) != RC_DOWN)
|
||||
? SIGN_POS : SIGN_NEG);
|
||||
} else
|
||||
setsign(dest, signa); /* signa may differ from the sign of a. */
|
||||
return TAG_Zero;
|
||||
} else {
|
||||
reg_copy(b, dest);
|
||||
if ((tagb == TW_Denormal) && (b->sigh & 0x80000000)) {
|
||||
/* A pseudoDenormal, convert it. */
|
||||
addexponent(dest, 1);
|
||||
tagb = TAG_Valid;
|
||||
} else if (tagb > TAG_Empty)
|
||||
tagb = TAG_Special;
|
||||
setsign(dest, signb); /* signb may differ from the sign of b. */
|
||||
FPU_settagi(deststnr, tagb);
|
||||
return tagb;
|
||||
}
|
||||
} else if (tagb == TAG_Zero) {
|
||||
reg_copy(a, dest);
|
||||
if ((taga == TW_Denormal) && (a->sigh & 0x80000000)) {
|
||||
/* A pseudoDenormal */
|
||||
addexponent(dest, 1);
|
||||
taga = TAG_Valid;
|
||||
} else if (taga > TAG_Empty)
|
||||
taga = TAG_Special;
|
||||
setsign(dest, signa); /* signa may differ from the sign of a. */
|
||||
FPU_settagi(deststnr, taga);
|
||||
return taga;
|
||||
} else if (taga == TW_Infinity) {
|
||||
if ((tagb != TW_Infinity) || (signa == signb)) {
|
||||
FPU_copy_to_regi(a, TAG_Special, deststnr);
|
||||
setsign(dest, signa); /* signa may differ from the sign of a. */
|
||||
return taga;
|
||||
}
|
||||
/* Infinity-Infinity is undefined. */
|
||||
return arith_invalid(deststnr);
|
||||
} else if (tagb == TW_Infinity) {
|
||||
FPU_copy_to_regi(b, TAG_Special, deststnr);
|
||||
setsign(dest, signb); /* signb may differ from the sign of b. */
|
||||
return tagb;
|
||||
}
|
||||
else
|
||||
{
|
||||
reg_copy(b, dest);
|
||||
if ( (tagb == TW_Denormal) && (b->sigh & 0x80000000) )
|
||||
{
|
||||
/* A pseudoDenormal, convert it. */
|
||||
addexponent(dest, 1);
|
||||
tagb = TAG_Valid;
|
||||
}
|
||||
else if ( tagb > TAG_Empty )
|
||||
tagb = TAG_Special;
|
||||
setsign(dest, signb); /* signb may differ from the sign of b. */
|
||||
FPU_settagi(deststnr, tagb);
|
||||
return tagb;
|
||||
}
|
||||
}
|
||||
else if (tagb == TAG_Zero)
|
||||
{
|
||||
reg_copy(a, dest);
|
||||
if ( (taga == TW_Denormal) && (a->sigh & 0x80000000) )
|
||||
{
|
||||
/* A pseudoDenormal */
|
||||
addexponent(dest, 1);
|
||||
taga = TAG_Valid;
|
||||
}
|
||||
else if ( taga > TAG_Empty )
|
||||
taga = TAG_Special;
|
||||
setsign(dest, signa); /* signa may differ from the sign of a. */
|
||||
FPU_settagi(deststnr, taga);
|
||||
return taga;
|
||||
}
|
||||
else if (taga == TW_Infinity)
|
||||
{
|
||||
if ( (tagb != TW_Infinity) || (signa == signb) )
|
||||
{
|
||||
FPU_copy_to_regi(a, TAG_Special, deststnr);
|
||||
setsign(dest, signa); /* signa may differ from the sign of a. */
|
||||
return taga;
|
||||
}
|
||||
/* Infinity-Infinity is undefined. */
|
||||
return arith_invalid(deststnr);
|
||||
}
|
||||
else if (tagb == TW_Infinity)
|
||||
{
|
||||
FPU_copy_to_regi(b, TAG_Special, deststnr);
|
||||
setsign(dest, signb); /* signb may differ from the sign of b. */
|
||||
return tagb;
|
||||
}
|
||||
|
||||
#ifdef PARANOID
|
||||
EXCEPTION(EX_INTERNAL|0x101);
|
||||
EXCEPTION(EX_INTERNAL | 0x101);
|
||||
#endif
|
||||
|
||||
return FPU_Exception;
|
||||
return FPU_Exception;
|
||||
}
|
||||
|
||||
|
|
|
@ -20,362 +20,331 @@
|
|||
#include "control_w.h"
|
||||
#include "status_w.h"
|
||||
|
||||
|
||||
static int compare(FPU_REG const *b, int tagb)
|
||||
{
|
||||
int diff, exp0, expb;
|
||||
u_char st0_tag;
|
||||
FPU_REG *st0_ptr;
|
||||
FPU_REG x, y;
|
||||
u_char st0_sign, signb = getsign(b);
|
||||
int diff, exp0, expb;
|
||||
u_char st0_tag;
|
||||
FPU_REG *st0_ptr;
|
||||
FPU_REG x, y;
|
||||
u_char st0_sign, signb = getsign(b);
|
||||
|
||||
st0_ptr = &st(0);
|
||||
st0_tag = FPU_gettag0();
|
||||
st0_sign = getsign(st0_ptr);
|
||||
st0_ptr = &st(0);
|
||||
st0_tag = FPU_gettag0();
|
||||
st0_sign = getsign(st0_ptr);
|
||||
|
||||
if ( tagb == TAG_Special )
|
||||
tagb = FPU_Special(b);
|
||||
if ( st0_tag == TAG_Special )
|
||||
st0_tag = FPU_Special(st0_ptr);
|
||||
if (tagb == TAG_Special)
|
||||
tagb = FPU_Special(b);
|
||||
if (st0_tag == TAG_Special)
|
||||
st0_tag = FPU_Special(st0_ptr);
|
||||
|
||||
if ( ((st0_tag != TAG_Valid) && (st0_tag != TW_Denormal))
|
||||
|| ((tagb != TAG_Valid) && (tagb != TW_Denormal)) )
|
||||
{
|
||||
if ( st0_tag == TAG_Zero )
|
||||
{
|
||||
if ( tagb == TAG_Zero ) return COMP_A_eq_B;
|
||||
if ( tagb == TAG_Valid )
|
||||
return ((signb == SIGN_POS) ? COMP_A_lt_B : COMP_A_gt_B);
|
||||
if ( tagb == TW_Denormal )
|
||||
return ((signb == SIGN_POS) ? COMP_A_lt_B : COMP_A_gt_B)
|
||||
| COMP_Denormal;
|
||||
}
|
||||
else if ( tagb == TAG_Zero )
|
||||
{
|
||||
if ( st0_tag == TAG_Valid )
|
||||
return ((st0_sign == SIGN_POS) ? COMP_A_gt_B : COMP_A_lt_B);
|
||||
if ( st0_tag == TW_Denormal )
|
||||
return ((st0_sign == SIGN_POS) ? COMP_A_gt_B : COMP_A_lt_B)
|
||||
| COMP_Denormal;
|
||||
if (((st0_tag != TAG_Valid) && (st0_tag != TW_Denormal))
|
||||
|| ((tagb != TAG_Valid) && (tagb != TW_Denormal))) {
|
||||
if (st0_tag == TAG_Zero) {
|
||||
if (tagb == TAG_Zero)
|
||||
return COMP_A_eq_B;
|
||||
if (tagb == TAG_Valid)
|
||||
return ((signb ==
|
||||
SIGN_POS) ? COMP_A_lt_B : COMP_A_gt_B);
|
||||
if (tagb == TW_Denormal)
|
||||
return ((signb ==
|
||||
SIGN_POS) ? COMP_A_lt_B : COMP_A_gt_B)
|
||||
| COMP_Denormal;
|
||||
} else if (tagb == TAG_Zero) {
|
||||
if (st0_tag == TAG_Valid)
|
||||
return ((st0_sign ==
|
||||
SIGN_POS) ? COMP_A_gt_B : COMP_A_lt_B);
|
||||
if (st0_tag == TW_Denormal)
|
||||
return ((st0_sign ==
|
||||
SIGN_POS) ? COMP_A_gt_B : COMP_A_lt_B)
|
||||
| COMP_Denormal;
|
||||
}
|
||||
|
||||
if (st0_tag == TW_Infinity) {
|
||||
if ((tagb == TAG_Valid) || (tagb == TAG_Zero))
|
||||
return ((st0_sign ==
|
||||
SIGN_POS) ? COMP_A_gt_B : COMP_A_lt_B);
|
||||
else if (tagb == TW_Denormal)
|
||||
return ((st0_sign ==
|
||||
SIGN_POS) ? COMP_A_gt_B : COMP_A_lt_B)
|
||||
| COMP_Denormal;
|
||||
else if (tagb == TW_Infinity) {
|
||||
/* The 80486 book says that infinities can be equal! */
|
||||
return (st0_sign == signb) ? COMP_A_eq_B :
|
||||
((st0_sign ==
|
||||
SIGN_POS) ? COMP_A_gt_B : COMP_A_lt_B);
|
||||
}
|
||||
/* Fall through to the NaN code */
|
||||
} else if (tagb == TW_Infinity) {
|
||||
if ((st0_tag == TAG_Valid) || (st0_tag == TAG_Zero))
|
||||
return ((signb ==
|
||||
SIGN_POS) ? COMP_A_lt_B : COMP_A_gt_B);
|
||||
if (st0_tag == TW_Denormal)
|
||||
return ((signb ==
|
||||
SIGN_POS) ? COMP_A_lt_B : COMP_A_gt_B)
|
||||
| COMP_Denormal;
|
||||
/* Fall through to the NaN code */
|
||||
}
|
||||
|
||||
/* The only possibility now should be that one of the arguments
|
||||
is a NaN */
|
||||
if ((st0_tag == TW_NaN) || (tagb == TW_NaN)) {
|
||||
int signalling = 0, unsupported = 0;
|
||||
if (st0_tag == TW_NaN) {
|
||||
signalling =
|
||||
(st0_ptr->sigh & 0xc0000000) == 0x80000000;
|
||||
unsupported = !((exponent(st0_ptr) == EXP_OVER)
|
||||
&& (st0_ptr->
|
||||
sigh & 0x80000000));
|
||||
}
|
||||
if (tagb == TW_NaN) {
|
||||
signalling |=
|
||||
(b->sigh & 0xc0000000) == 0x80000000;
|
||||
unsupported |= !((exponent(b) == EXP_OVER)
|
||||
&& (b->sigh & 0x80000000));
|
||||
}
|
||||
if (signalling || unsupported)
|
||||
return COMP_No_Comp | COMP_SNaN | COMP_NaN;
|
||||
else
|
||||
/* Neither is a signaling NaN */
|
||||
return COMP_No_Comp | COMP_NaN;
|
||||
}
|
||||
|
||||
EXCEPTION(EX_Invalid);
|
||||
}
|
||||
|
||||
if ( st0_tag == TW_Infinity )
|
||||
{
|
||||
if ( (tagb == TAG_Valid) || (tagb == TAG_Zero) )
|
||||
return ((st0_sign == SIGN_POS) ? COMP_A_gt_B : COMP_A_lt_B);
|
||||
else if ( tagb == TW_Denormal )
|
||||
return ((st0_sign == SIGN_POS) ? COMP_A_gt_B : COMP_A_lt_B)
|
||||
| COMP_Denormal;
|
||||
else if ( tagb == TW_Infinity )
|
||||
{
|
||||
/* The 80486 book says that infinities can be equal! */
|
||||
return (st0_sign == signb) ? COMP_A_eq_B :
|
||||
((st0_sign == SIGN_POS) ? COMP_A_gt_B : COMP_A_lt_B);
|
||||
}
|
||||
/* Fall through to the NaN code */
|
||||
}
|
||||
else if ( tagb == TW_Infinity )
|
||||
{
|
||||
if ( (st0_tag == TAG_Valid) || (st0_tag == TAG_Zero) )
|
||||
return ((signb == SIGN_POS) ? COMP_A_lt_B : COMP_A_gt_B);
|
||||
if ( st0_tag == TW_Denormal )
|
||||
return ((signb == SIGN_POS) ? COMP_A_lt_B : COMP_A_gt_B)
|
||||
| COMP_Denormal;
|
||||
/* Fall through to the NaN code */
|
||||
if (st0_sign != signb) {
|
||||
return ((st0_sign == SIGN_POS) ? COMP_A_gt_B : COMP_A_lt_B)
|
||||
| (((st0_tag == TW_Denormal) || (tagb == TW_Denormal)) ?
|
||||
COMP_Denormal : 0);
|
||||
}
|
||||
|
||||
/* The only possibility now should be that one of the arguments
|
||||
is a NaN */
|
||||
if ( (st0_tag == TW_NaN) || (tagb == TW_NaN) )
|
||||
{
|
||||
int signalling = 0, unsupported = 0;
|
||||
if ( st0_tag == TW_NaN )
|
||||
{
|
||||
signalling = (st0_ptr->sigh & 0xc0000000) == 0x80000000;
|
||||
unsupported = !((exponent(st0_ptr) == EXP_OVER)
|
||||
&& (st0_ptr->sigh & 0x80000000));
|
||||
}
|
||||
if ( tagb == TW_NaN )
|
||||
{
|
||||
signalling |= (b->sigh & 0xc0000000) == 0x80000000;
|
||||
unsupported |= !((exponent(b) == EXP_OVER)
|
||||
&& (b->sigh & 0x80000000));
|
||||
}
|
||||
if ( signalling || unsupported )
|
||||
return COMP_No_Comp | COMP_SNaN | COMP_NaN;
|
||||
else
|
||||
/* Neither is a signaling NaN */
|
||||
return COMP_No_Comp | COMP_NaN;
|
||||
if ((st0_tag == TW_Denormal) || (tagb == TW_Denormal)) {
|
||||
FPU_to_exp16(st0_ptr, &x);
|
||||
FPU_to_exp16(b, &y);
|
||||
st0_ptr = &x;
|
||||
b = &y;
|
||||
exp0 = exponent16(st0_ptr);
|
||||
expb = exponent16(b);
|
||||
} else {
|
||||
exp0 = exponent(st0_ptr);
|
||||
expb = exponent(b);
|
||||
}
|
||||
|
||||
EXCEPTION(EX_Invalid);
|
||||
}
|
||||
|
||||
if (st0_sign != signb)
|
||||
{
|
||||
return ((st0_sign == SIGN_POS) ? COMP_A_gt_B : COMP_A_lt_B)
|
||||
| ( ((st0_tag == TW_Denormal) || (tagb == TW_Denormal)) ?
|
||||
COMP_Denormal : 0);
|
||||
}
|
||||
|
||||
if ( (st0_tag == TW_Denormal) || (tagb == TW_Denormal) )
|
||||
{
|
||||
FPU_to_exp16(st0_ptr, &x);
|
||||
FPU_to_exp16(b, &y);
|
||||
st0_ptr = &x;
|
||||
b = &y;
|
||||
exp0 = exponent16(st0_ptr);
|
||||
expb = exponent16(b);
|
||||
}
|
||||
else
|
||||
{
|
||||
exp0 = exponent(st0_ptr);
|
||||
expb = exponent(b);
|
||||
}
|
||||
|
||||
#ifdef PARANOID
|
||||
if (!(st0_ptr->sigh & 0x80000000)) EXCEPTION(EX_Invalid);
|
||||
if (!(b->sigh & 0x80000000)) EXCEPTION(EX_Invalid);
|
||||
if (!(st0_ptr->sigh & 0x80000000))
|
||||
EXCEPTION(EX_Invalid);
|
||||
if (!(b->sigh & 0x80000000))
|
||||
EXCEPTION(EX_Invalid);
|
||||
#endif /* PARANOID */
|
||||
|
||||
diff = exp0 - expb;
|
||||
if ( diff == 0 )
|
||||
{
|
||||
diff = st0_ptr->sigh - b->sigh; /* Works only if ms bits are
|
||||
identical */
|
||||
if ( diff == 0 )
|
||||
{
|
||||
diff = st0_ptr->sigl > b->sigl;
|
||||
if ( diff == 0 )
|
||||
diff = -(st0_ptr->sigl < b->sigl);
|
||||
diff = exp0 - expb;
|
||||
if (diff == 0) {
|
||||
diff = st0_ptr->sigh - b->sigh; /* Works only if ms bits are
|
||||
identical */
|
||||
if (diff == 0) {
|
||||
diff = st0_ptr->sigl > b->sigl;
|
||||
if (diff == 0)
|
||||
diff = -(st0_ptr->sigl < b->sigl);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( diff > 0 )
|
||||
{
|
||||
return ((st0_sign == SIGN_POS) ? COMP_A_gt_B : COMP_A_lt_B)
|
||||
| ( ((st0_tag == TW_Denormal) || (tagb == TW_Denormal)) ?
|
||||
COMP_Denormal : 0);
|
||||
}
|
||||
if ( diff < 0 )
|
||||
{
|
||||
return ((st0_sign == SIGN_POS) ? COMP_A_lt_B : COMP_A_gt_B)
|
||||
| ( ((st0_tag == TW_Denormal) || (tagb == TW_Denormal)) ?
|
||||
COMP_Denormal : 0);
|
||||
}
|
||||
if (diff > 0) {
|
||||
return ((st0_sign == SIGN_POS) ? COMP_A_gt_B : COMP_A_lt_B)
|
||||
| (((st0_tag == TW_Denormal) || (tagb == TW_Denormal)) ?
|
||||
COMP_Denormal : 0);
|
||||
}
|
||||
if (diff < 0) {
|
||||
return ((st0_sign == SIGN_POS) ? COMP_A_lt_B : COMP_A_gt_B)
|
||||
| (((st0_tag == TW_Denormal) || (tagb == TW_Denormal)) ?
|
||||
COMP_Denormal : 0);
|
||||
}
|
||||
|
||||
return COMP_A_eq_B
|
||||
| ( ((st0_tag == TW_Denormal) || (tagb == TW_Denormal)) ?
|
||||
COMP_Denormal : 0);
|
||||
return COMP_A_eq_B
|
||||
| (((st0_tag == TW_Denormal) || (tagb == TW_Denormal)) ?
|
||||
COMP_Denormal : 0);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/* This function requires that st(0) is not empty */
|
||||
int FPU_compare_st_data(FPU_REG const *loaded_data, u_char loaded_tag)
|
||||
{
|
||||
int f = 0, c;
|
||||
int f = 0, c;
|
||||
|
||||
c = compare(loaded_data, loaded_tag);
|
||||
c = compare(loaded_data, loaded_tag);
|
||||
|
||||
if (c & COMP_NaN)
|
||||
{
|
||||
EXCEPTION(EX_Invalid);
|
||||
f = SW_C3 | SW_C2 | SW_C0;
|
||||
}
|
||||
else
|
||||
switch (c & 7)
|
||||
{
|
||||
case COMP_A_lt_B:
|
||||
f = SW_C0;
|
||||
break;
|
||||
case COMP_A_eq_B:
|
||||
f = SW_C3;
|
||||
break;
|
||||
case COMP_A_gt_B:
|
||||
f = 0;
|
||||
break;
|
||||
case COMP_No_Comp:
|
||||
f = SW_C3 | SW_C2 | SW_C0;
|
||||
break;
|
||||
if (c & COMP_NaN) {
|
||||
EXCEPTION(EX_Invalid);
|
||||
f = SW_C3 | SW_C2 | SW_C0;
|
||||
} else
|
||||
switch (c & 7) {
|
||||
case COMP_A_lt_B:
|
||||
f = SW_C0;
|
||||
break;
|
||||
case COMP_A_eq_B:
|
||||
f = SW_C3;
|
||||
break;
|
||||
case COMP_A_gt_B:
|
||||
f = 0;
|
||||
break;
|
||||
case COMP_No_Comp:
|
||||
f = SW_C3 | SW_C2 | SW_C0;
|
||||
break;
|
||||
#ifdef PARANOID
|
||||
default:
|
||||
EXCEPTION(EX_INTERNAL|0x121);
|
||||
f = SW_C3 | SW_C2 | SW_C0;
|
||||
break;
|
||||
default:
|
||||
EXCEPTION(EX_INTERNAL | 0x121);
|
||||
f = SW_C3 | SW_C2 | SW_C0;
|
||||
break;
|
||||
#endif /* PARANOID */
|
||||
}
|
||||
setcc(f);
|
||||
if (c & COMP_Denormal)
|
||||
{
|
||||
return denormal_operand() < 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
setcc(f);
|
||||
if (c & COMP_Denormal) {
|
||||
return denormal_operand() < 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static int compare_st_st(int nr)
|
||||
{
|
||||
int f = 0, c;
|
||||
FPU_REG *st_ptr;
|
||||
int f = 0, c;
|
||||
FPU_REG *st_ptr;
|
||||
|
||||
if ( !NOT_EMPTY(0) || !NOT_EMPTY(nr) )
|
||||
{
|
||||
setcc(SW_C3 | SW_C2 | SW_C0);
|
||||
/* Stack fault */
|
||||
EXCEPTION(EX_StackUnder);
|
||||
return !(control_word & CW_Invalid);
|
||||
}
|
||||
if (!NOT_EMPTY(0) || !NOT_EMPTY(nr)) {
|
||||
setcc(SW_C3 | SW_C2 | SW_C0);
|
||||
/* Stack fault */
|
||||
EXCEPTION(EX_StackUnder);
|
||||
return !(control_word & CW_Invalid);
|
||||
}
|
||||
|
||||
st_ptr = &st(nr);
|
||||
c = compare(st_ptr, FPU_gettagi(nr));
|
||||
if (c & COMP_NaN)
|
||||
{
|
||||
setcc(SW_C3 | SW_C2 | SW_C0);
|
||||
EXCEPTION(EX_Invalid);
|
||||
return !(control_word & CW_Invalid);
|
||||
}
|
||||
else
|
||||
switch (c & 7)
|
||||
{
|
||||
case COMP_A_lt_B:
|
||||
f = SW_C0;
|
||||
break;
|
||||
case COMP_A_eq_B:
|
||||
f = SW_C3;
|
||||
break;
|
||||
case COMP_A_gt_B:
|
||||
f = 0;
|
||||
break;
|
||||
case COMP_No_Comp:
|
||||
f = SW_C3 | SW_C2 | SW_C0;
|
||||
break;
|
||||
st_ptr = &st(nr);
|
||||
c = compare(st_ptr, FPU_gettagi(nr));
|
||||
if (c & COMP_NaN) {
|
||||
setcc(SW_C3 | SW_C2 | SW_C0);
|
||||
EXCEPTION(EX_Invalid);
|
||||
return !(control_word & CW_Invalid);
|
||||
} else
|
||||
switch (c & 7) {
|
||||
case COMP_A_lt_B:
|
||||
f = SW_C0;
|
||||
break;
|
||||
case COMP_A_eq_B:
|
||||
f = SW_C3;
|
||||
break;
|
||||
case COMP_A_gt_B:
|
||||
f = 0;
|
||||
break;
|
||||
case COMP_No_Comp:
|
||||
f = SW_C3 | SW_C2 | SW_C0;
|
||||
break;
|
||||
#ifdef PARANOID
|
||||
default:
|
||||
EXCEPTION(EX_INTERNAL|0x122);
|
||||
f = SW_C3 | SW_C2 | SW_C0;
|
||||
break;
|
||||
default:
|
||||
EXCEPTION(EX_INTERNAL | 0x122);
|
||||
f = SW_C3 | SW_C2 | SW_C0;
|
||||
break;
|
||||
#endif /* PARANOID */
|
||||
}
|
||||
setcc(f);
|
||||
if (c & COMP_Denormal)
|
||||
{
|
||||
return denormal_operand() < 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
setcc(f);
|
||||
if (c & COMP_Denormal) {
|
||||
return denormal_operand() < 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static int compare_u_st_st(int nr)
|
||||
{
|
||||
int f = 0, c;
|
||||
FPU_REG *st_ptr;
|
||||
int f = 0, c;
|
||||
FPU_REG *st_ptr;
|
||||
|
||||
if ( !NOT_EMPTY(0) || !NOT_EMPTY(nr) )
|
||||
{
|
||||
setcc(SW_C3 | SW_C2 | SW_C0);
|
||||
/* Stack fault */
|
||||
EXCEPTION(EX_StackUnder);
|
||||
return !(control_word & CW_Invalid);
|
||||
}
|
||||
|
||||
st_ptr = &st(nr);
|
||||
c = compare(st_ptr, FPU_gettagi(nr));
|
||||
if (c & COMP_NaN)
|
||||
{
|
||||
setcc(SW_C3 | SW_C2 | SW_C0);
|
||||
if (c & COMP_SNaN) /* This is the only difference between
|
||||
un-ordered and ordinary comparisons */
|
||||
{
|
||||
EXCEPTION(EX_Invalid);
|
||||
return !(control_word & CW_Invalid);
|
||||
if (!NOT_EMPTY(0) || !NOT_EMPTY(nr)) {
|
||||
setcc(SW_C3 | SW_C2 | SW_C0);
|
||||
/* Stack fault */
|
||||
EXCEPTION(EX_StackUnder);
|
||||
return !(control_word & CW_Invalid);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
switch (c & 7)
|
||||
{
|
||||
case COMP_A_lt_B:
|
||||
f = SW_C0;
|
||||
break;
|
||||
case COMP_A_eq_B:
|
||||
f = SW_C3;
|
||||
break;
|
||||
case COMP_A_gt_B:
|
||||
f = 0;
|
||||
break;
|
||||
case COMP_No_Comp:
|
||||
f = SW_C3 | SW_C2 | SW_C0;
|
||||
break;
|
||||
|
||||
st_ptr = &st(nr);
|
||||
c = compare(st_ptr, FPU_gettagi(nr));
|
||||
if (c & COMP_NaN) {
|
||||
setcc(SW_C3 | SW_C2 | SW_C0);
|
||||
if (c & COMP_SNaN) { /* This is the only difference between
|
||||
un-ordered and ordinary comparisons */
|
||||
EXCEPTION(EX_Invalid);
|
||||
return !(control_word & CW_Invalid);
|
||||
}
|
||||
return 0;
|
||||
} else
|
||||
switch (c & 7) {
|
||||
case COMP_A_lt_B:
|
||||
f = SW_C0;
|
||||
break;
|
||||
case COMP_A_eq_B:
|
||||
f = SW_C3;
|
||||
break;
|
||||
case COMP_A_gt_B:
|
||||
f = 0;
|
||||
break;
|
||||
case COMP_No_Comp:
|
||||
f = SW_C3 | SW_C2 | SW_C0;
|
||||
break;
|
||||
#ifdef PARANOID
|
||||
default:
|
||||
EXCEPTION(EX_INTERNAL|0x123);
|
||||
f = SW_C3 | SW_C2 | SW_C0;
|
||||
break;
|
||||
#endif /* PARANOID */
|
||||
}
|
||||
setcc(f);
|
||||
if (c & COMP_Denormal)
|
||||
{
|
||||
return denormal_operand() < 0;
|
||||
}
|
||||
return 0;
|
||||
default:
|
||||
EXCEPTION(EX_INTERNAL | 0x123);
|
||||
f = SW_C3 | SW_C2 | SW_C0;
|
||||
break;
|
||||
#endif /* PARANOID */
|
||||
}
|
||||
setcc(f);
|
||||
if (c & COMP_Denormal) {
|
||||
return denormal_operand() < 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
||||
void fcom_st(void)
|
||||
{
|
||||
/* fcom st(i) */
|
||||
compare_st_st(FPU_rm);
|
||||
/* fcom st(i) */
|
||||
compare_st_st(FPU_rm);
|
||||
}
|
||||
|
||||
|
||||
void fcompst(void)
|
||||
{
|
||||
/* fcomp st(i) */
|
||||
if ( !compare_st_st(FPU_rm) )
|
||||
FPU_pop();
|
||||
/* fcomp st(i) */
|
||||
if (!compare_st_st(FPU_rm))
|
||||
FPU_pop();
|
||||
}
|
||||
|
||||
|
||||
void fcompp(void)
|
||||
{
|
||||
/* fcompp */
|
||||
if (FPU_rm != 1)
|
||||
{
|
||||
FPU_illegal();
|
||||
return;
|
||||
}
|
||||
if ( !compare_st_st(1) )
|
||||
poppop();
|
||||
/* fcompp */
|
||||
if (FPU_rm != 1) {
|
||||
FPU_illegal();
|
||||
return;
|
||||
}
|
||||
if (!compare_st_st(1))
|
||||
poppop();
|
||||
}
|
||||
|
||||
|
||||
void fucom_(void)
|
||||
{
|
||||
/* fucom st(i) */
|
||||
compare_u_st_st(FPU_rm);
|
||||
/* fucom st(i) */
|
||||
compare_u_st_st(FPU_rm);
|
||||
|
||||
}
|
||||
|
||||
|
||||
void fucomp(void)
|
||||
{
|
||||
/* fucomp st(i) */
|
||||
if ( !compare_u_st_st(FPU_rm) )
|
||||
FPU_pop();
|
||||
/* fucomp st(i) */
|
||||
if (!compare_u_st_st(FPU_rm))
|
||||
FPU_pop();
|
||||
}
|
||||
|
||||
|
||||
void fucompp(void)
|
||||
{
|
||||
/* fucompp */
|
||||
if (FPU_rm == 1)
|
||||
{
|
||||
if ( !compare_u_st_st(1) )
|
||||
poppop();
|
||||
}
|
||||
else
|
||||
FPU_illegal();
|
||||
/* fucompp */
|
||||
if (FPU_rm == 1) {
|
||||
if (!compare_u_st_st(1))
|
||||
poppop();
|
||||
} else
|
||||
FPU_illegal();
|
||||
}
|
||||
|
|
|
@ -16,29 +16,28 @@
|
|||
#include "reg_constant.h"
|
||||
#include "control_w.h"
|
||||
|
||||
|
||||
#define MAKE_REG(s,e,l,h) { l, h, \
|
||||
((EXTENDED_Ebias+(e)) | ((SIGN_##s != 0)*0x8000)) }
|
||||
|
||||
FPU_REG const CONST_1 = MAKE_REG(POS, 0, 0x00000000, 0x80000000);
|
||||
FPU_REG const CONST_1 = MAKE_REG(POS, 0, 0x00000000, 0x80000000);
|
||||
#if 0
|
||||
FPU_REG const CONST_2 = MAKE_REG(POS, 1, 0x00000000, 0x80000000);
|
||||
FPU_REG const CONST_2 = MAKE_REG(POS, 1, 0x00000000, 0x80000000);
|
||||
FPU_REG const CONST_HALF = MAKE_REG(POS, -1, 0x00000000, 0x80000000);
|
||||
#endif /* 0 */
|
||||
static FPU_REG const CONST_L2T = MAKE_REG(POS, 1, 0xcd1b8afe, 0xd49a784b);
|
||||
static FPU_REG const CONST_L2E = MAKE_REG(POS, 0, 0x5c17f0bc, 0xb8aa3b29);
|
||||
FPU_REG const CONST_PI = MAKE_REG(POS, 1, 0x2168c235, 0xc90fdaa2);
|
||||
FPU_REG const CONST_PI2 = MAKE_REG(POS, 0, 0x2168c235, 0xc90fdaa2);
|
||||
FPU_REG const CONST_PI4 = MAKE_REG(POS, -1, 0x2168c235, 0xc90fdaa2);
|
||||
static FPU_REG const CONST_LG2 = MAKE_REG(POS, -2, 0xfbcff799, 0x9a209a84);
|
||||
static FPU_REG const CONST_LN2 = MAKE_REG(POS, -1, 0xd1cf79ac, 0xb17217f7);
|
||||
#endif /* 0 */
|
||||
static FPU_REG const CONST_L2T = MAKE_REG(POS, 1, 0xcd1b8afe, 0xd49a784b);
|
||||
static FPU_REG const CONST_L2E = MAKE_REG(POS, 0, 0x5c17f0bc, 0xb8aa3b29);
|
||||
FPU_REG const CONST_PI = MAKE_REG(POS, 1, 0x2168c235, 0xc90fdaa2);
|
||||
FPU_REG const CONST_PI2 = MAKE_REG(POS, 0, 0x2168c235, 0xc90fdaa2);
|
||||
FPU_REG const CONST_PI4 = MAKE_REG(POS, -1, 0x2168c235, 0xc90fdaa2);
|
||||
static FPU_REG const CONST_LG2 = MAKE_REG(POS, -2, 0xfbcff799, 0x9a209a84);
|
||||
static FPU_REG const CONST_LN2 = MAKE_REG(POS, -1, 0xd1cf79ac, 0xb17217f7);
|
||||
|
||||
/* Extra bits to take pi/2 to more than 128 bits precision. */
|
||||
FPU_REG const CONST_PI2extra = MAKE_REG(NEG, -66,
|
||||
0xfc8f8cbb, 0xece675d1);
|
||||
0xfc8f8cbb, 0xece675d1);
|
||||
|
||||
/* Only the sign (and tag) is used in internal zeroes */
|
||||
FPU_REG const CONST_Z = MAKE_REG(POS, EXP_UNDER, 0x0, 0x0);
|
||||
FPU_REG const CONST_Z = MAKE_REG(POS, EXP_UNDER, 0x0, 0x0);
|
||||
|
||||
/* Only the sign and significand (and tag) are used in internal NaNs */
|
||||
/* The 80486 never generates one of these
|
||||
|
@ -48,24 +47,22 @@ FPU_REG const CONST_SNAN = MAKE_REG(POS, EXP_OVER, 0x00000001, 0x80000000);
|
|||
FPU_REG const CONST_QNaN = MAKE_REG(NEG, EXP_OVER, 0x00000000, 0xC0000000);
|
||||
|
||||
/* Only the sign (and tag) is used in internal infinities */
|
||||
FPU_REG const CONST_INF = MAKE_REG(POS, EXP_OVER, 0x00000000, 0x80000000);
|
||||
|
||||
FPU_REG const CONST_INF = MAKE_REG(POS, EXP_OVER, 0x00000000, 0x80000000);
|
||||
|
||||
static void fld_const(FPU_REG const *c, int adj, u_char tag)
|
||||
{
|
||||
FPU_REG *st_new_ptr;
|
||||
FPU_REG *st_new_ptr;
|
||||
|
||||
if ( STACK_OVERFLOW )
|
||||
{
|
||||
FPU_stack_overflow();
|
||||
return;
|
||||
}
|
||||
push();
|
||||
reg_copy(c, st_new_ptr);
|
||||
st_new_ptr->sigl += adj; /* For all our fldxxx constants, we don't need to
|
||||
borrow or carry. */
|
||||
FPU_settag0(tag);
|
||||
clear_C1();
|
||||
if (STACK_OVERFLOW) {
|
||||
FPU_stack_overflow();
|
||||
return;
|
||||
}
|
||||
push();
|
||||
reg_copy(c, st_new_ptr);
|
||||
st_new_ptr->sigl += adj; /* For all our fldxxx constants, we don't need to
|
||||
borrow or carry. */
|
||||
FPU_settag0(tag);
|
||||
clear_C1();
|
||||
}
|
||||
|
||||
/* A fast way to find out whether x is one of RC_DOWN or RC_CHOP
|
||||
|
@ -75,46 +72,46 @@ static void fld_const(FPU_REG const *c, int adj, u_char tag)
|
|||
|
||||
static void fld1(int rc)
|
||||
{
|
||||
fld_const(&CONST_1, 0, TAG_Valid);
|
||||
fld_const(&CONST_1, 0, TAG_Valid);
|
||||
}
|
||||
|
||||
static void fldl2t(int rc)
|
||||
{
|
||||
fld_const(&CONST_L2T, (rc == RC_UP) ? 1 : 0, TAG_Valid);
|
||||
fld_const(&CONST_L2T, (rc == RC_UP) ? 1 : 0, TAG_Valid);
|
||||
}
|
||||
|
||||
static void fldl2e(int rc)
|
||||
{
|
||||
fld_const(&CONST_L2E, DOWN_OR_CHOP(rc) ? -1 : 0, TAG_Valid);
|
||||
fld_const(&CONST_L2E, DOWN_OR_CHOP(rc) ? -1 : 0, TAG_Valid);
|
||||
}
|
||||
|
||||
static void fldpi(int rc)
|
||||
{
|
||||
fld_const(&CONST_PI, DOWN_OR_CHOP(rc) ? -1 : 0, TAG_Valid);
|
||||
fld_const(&CONST_PI, DOWN_OR_CHOP(rc) ? -1 : 0, TAG_Valid);
|
||||
}
|
||||
|
||||
static void fldlg2(int rc)
|
||||
{
|
||||
fld_const(&CONST_LG2, DOWN_OR_CHOP(rc) ? -1 : 0, TAG_Valid);
|
||||
fld_const(&CONST_LG2, DOWN_OR_CHOP(rc) ? -1 : 0, TAG_Valid);
|
||||
}
|
||||
|
||||
static void fldln2(int rc)
|
||||
{
|
||||
fld_const(&CONST_LN2, DOWN_OR_CHOP(rc) ? -1 : 0, TAG_Valid);
|
||||
fld_const(&CONST_LN2, DOWN_OR_CHOP(rc) ? -1 : 0, TAG_Valid);
|
||||
}
|
||||
|
||||
static void fldz(int rc)
|
||||
{
|
||||
fld_const(&CONST_Z, 0, TAG_Zero);
|
||||
fld_const(&CONST_Z, 0, TAG_Zero);
|
||||
}
|
||||
|
||||
typedef void (*FUNC_RC)(int);
|
||||
typedef void (*FUNC_RC) (int);
|
||||
|
||||
static FUNC_RC constants_table[] = {
|
||||
fld1, fldl2t, fldl2e, fldpi, fldlg2, fldln2, fldz, (FUNC_RC)FPU_illegal
|
||||
fld1, fldl2t, fldl2e, fldpi, fldlg2, fldln2, fldz, (FUNC_RC) FPU_illegal
|
||||
};
|
||||
|
||||
void fconst(void)
|
||||
{
|
||||
(constants_table[FPU_rm])(control_word & CW_RC);
|
||||
(constants_table[FPU_rm]) (control_word & CW_RC);
|
||||
}
|
||||
|
|
|
@ -13,41 +13,34 @@
|
|||
#include "exception.h"
|
||||
#include "fpu_emu.h"
|
||||
|
||||
|
||||
int FPU_to_exp16(FPU_REG const *a, FPU_REG *x)
|
||||
int FPU_to_exp16(FPU_REG const *a, FPU_REG * x)
|
||||
{
|
||||
int sign = getsign(a);
|
||||
int sign = getsign(a);
|
||||
|
||||
*(long long *)&(x->sigl) = *(const long long *)&(a->sigl);
|
||||
*(long long *)&(x->sigl) = *(const long long *)&(a->sigl);
|
||||
|
||||
/* Set up the exponent as a 16 bit quantity. */
|
||||
setexponent16(x, exponent(a));
|
||||
/* Set up the exponent as a 16 bit quantity. */
|
||||
setexponent16(x, exponent(a));
|
||||
|
||||
if ( exponent16(x) == EXP_UNDER )
|
||||
{
|
||||
/* The number is a de-normal or pseudodenormal. */
|
||||
/* We only deal with the significand and exponent. */
|
||||
if (exponent16(x) == EXP_UNDER) {
|
||||
/* The number is a de-normal or pseudodenormal. */
|
||||
/* We only deal with the significand and exponent. */
|
||||
|
||||
if (x->sigh & 0x80000000)
|
||||
{
|
||||
/* Is a pseudodenormal. */
|
||||
/* This is non-80486 behaviour because the number
|
||||
loses its 'denormal' identity. */
|
||||
addexponent(x, 1);
|
||||
if (x->sigh & 0x80000000) {
|
||||
/* Is a pseudodenormal. */
|
||||
/* This is non-80486 behaviour because the number
|
||||
loses its 'denormal' identity. */
|
||||
addexponent(x, 1);
|
||||
} else {
|
||||
/* Is a denormal. */
|
||||
addexponent(x, 1);
|
||||
FPU_normalize_nuo(x);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Is a denormal. */
|
||||
addexponent(x, 1);
|
||||
FPU_normalize_nuo(x);
|
||||
|
||||
if (!(x->sigh & 0x80000000)) {
|
||||
EXCEPTION(EX_INTERNAL | 0x180);
|
||||
}
|
||||
}
|
||||
|
||||
if ( !(x->sigh & 0x80000000) )
|
||||
{
|
||||
EXCEPTION(EX_INTERNAL | 0x180);
|
||||
}
|
||||
|
||||
return sign;
|
||||
return sign;
|
||||
}
|
||||
|
||||
|
|
|
@ -26,182 +26,157 @@
|
|||
*/
|
||||
int FPU_div(int flags, int rm, int control_w)
|
||||
{
|
||||
FPU_REG x, y;
|
||||
FPU_REG const *a, *b, *st0_ptr, *st_ptr;
|
||||
FPU_REG *dest;
|
||||
u_char taga, tagb, signa, signb, sign, saved_sign;
|
||||
int tag, deststnr;
|
||||
FPU_REG x, y;
|
||||
FPU_REG const *a, *b, *st0_ptr, *st_ptr;
|
||||
FPU_REG *dest;
|
||||
u_char taga, tagb, signa, signb, sign, saved_sign;
|
||||
int tag, deststnr;
|
||||
|
||||
if ( flags & DEST_RM )
|
||||
deststnr = rm;
|
||||
else
|
||||
deststnr = 0;
|
||||
if (flags & DEST_RM)
|
||||
deststnr = rm;
|
||||
else
|
||||
deststnr = 0;
|
||||
|
||||
if ( flags & REV )
|
||||
{
|
||||
b = &st(0);
|
||||
st0_ptr = b;
|
||||
tagb = FPU_gettag0();
|
||||
if ( flags & LOADED )
|
||||
{
|
||||
a = (FPU_REG *)rm;
|
||||
taga = flags & 0x0f;
|
||||
if (flags & REV) {
|
||||
b = &st(0);
|
||||
st0_ptr = b;
|
||||
tagb = FPU_gettag0();
|
||||
if (flags & LOADED) {
|
||||
a = (FPU_REG *) rm;
|
||||
taga = flags & 0x0f;
|
||||
} else {
|
||||
a = &st(rm);
|
||||
st_ptr = a;
|
||||
taga = FPU_gettagi(rm);
|
||||
}
|
||||
} else {
|
||||
a = &st(0);
|
||||
st0_ptr = a;
|
||||
taga = FPU_gettag0();
|
||||
if (flags & LOADED) {
|
||||
b = (FPU_REG *) rm;
|
||||
tagb = flags & 0x0f;
|
||||
} else {
|
||||
b = &st(rm);
|
||||
st_ptr = b;
|
||||
tagb = FPU_gettagi(rm);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
a = &st(rm);
|
||||
st_ptr = a;
|
||||
taga = FPU_gettagi(rm);
|
||||
|
||||
signa = getsign(a);
|
||||
signb = getsign(b);
|
||||
|
||||
sign = signa ^ signb;
|
||||
|
||||
dest = &st(deststnr);
|
||||
saved_sign = getsign(dest);
|
||||
|
||||
if (!(taga | tagb)) {
|
||||
/* Both regs Valid, this should be the most common case. */
|
||||
reg_copy(a, &x);
|
||||
reg_copy(b, &y);
|
||||
setpositive(&x);
|
||||
setpositive(&y);
|
||||
tag = FPU_u_div(&x, &y, dest, control_w, sign);
|
||||
|
||||
if (tag < 0)
|
||||
return tag;
|
||||
|
||||
FPU_settagi(deststnr, tag);
|
||||
return tag;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
a = &st(0);
|
||||
st0_ptr = a;
|
||||
taga = FPU_gettag0();
|
||||
if ( flags & LOADED )
|
||||
{
|
||||
b = (FPU_REG *)rm;
|
||||
tagb = flags & 0x0f;
|
||||
}
|
||||
else
|
||||
{
|
||||
b = &st(rm);
|
||||
st_ptr = b;
|
||||
tagb = FPU_gettagi(rm);
|
||||
}
|
||||
}
|
||||
|
||||
signa = getsign(a);
|
||||
signb = getsign(b);
|
||||
if (taga == TAG_Special)
|
||||
taga = FPU_Special(a);
|
||||
if (tagb == TAG_Special)
|
||||
tagb = FPU_Special(b);
|
||||
|
||||
sign = signa ^ signb;
|
||||
|
||||
dest = &st(deststnr);
|
||||
saved_sign = getsign(dest);
|
||||
|
||||
if ( !(taga | tagb) )
|
||||
{
|
||||
/* Both regs Valid, this should be the most common case. */
|
||||
reg_copy(a, &x);
|
||||
reg_copy(b, &y);
|
||||
setpositive(&x);
|
||||
setpositive(&y);
|
||||
tag = FPU_u_div(&x, &y, dest, control_w, sign);
|
||||
|
||||
if ( tag < 0 )
|
||||
return tag;
|
||||
|
||||
FPU_settagi(deststnr, tag);
|
||||
return tag;
|
||||
}
|
||||
|
||||
if ( taga == TAG_Special )
|
||||
taga = FPU_Special(a);
|
||||
if ( tagb == TAG_Special )
|
||||
tagb = FPU_Special(b);
|
||||
|
||||
if ( ((taga == TAG_Valid) && (tagb == TW_Denormal))
|
||||
if (((taga == TAG_Valid) && (tagb == TW_Denormal))
|
||||
|| ((taga == TW_Denormal) && (tagb == TAG_Valid))
|
||||
|| ((taga == TW_Denormal) && (tagb == TW_Denormal)) )
|
||||
{
|
||||
if ( denormal_operand() < 0 )
|
||||
return FPU_Exception;
|
||||
|| ((taga == TW_Denormal) && (tagb == TW_Denormal))) {
|
||||
if (denormal_operand() < 0)
|
||||
return FPU_Exception;
|
||||
|
||||
FPU_to_exp16(a, &x);
|
||||
FPU_to_exp16(b, &y);
|
||||
tag = FPU_u_div(&x, &y, dest, control_w, sign);
|
||||
if ( tag < 0 )
|
||||
return tag;
|
||||
FPU_to_exp16(a, &x);
|
||||
FPU_to_exp16(b, &y);
|
||||
tag = FPU_u_div(&x, &y, dest, control_w, sign);
|
||||
if (tag < 0)
|
||||
return tag;
|
||||
|
||||
FPU_settagi(deststnr, tag);
|
||||
return tag;
|
||||
}
|
||||
else if ( (taga <= TW_Denormal) && (tagb <= TW_Denormal) )
|
||||
{
|
||||
if ( tagb != TAG_Zero )
|
||||
{
|
||||
/* Want to find Zero/Valid */
|
||||
if ( tagb == TW_Denormal )
|
||||
{
|
||||
if ( denormal_operand() < 0 )
|
||||
return FPU_Exception;
|
||||
}
|
||||
FPU_settagi(deststnr, tag);
|
||||
return tag;
|
||||
} else if ((taga <= TW_Denormal) && (tagb <= TW_Denormal)) {
|
||||
if (tagb != TAG_Zero) {
|
||||
/* Want to find Zero/Valid */
|
||||
if (tagb == TW_Denormal) {
|
||||
if (denormal_operand() < 0)
|
||||
return FPU_Exception;
|
||||
}
|
||||
|
||||
/* The result is zero. */
|
||||
FPU_copy_to_regi(&CONST_Z, TAG_Zero, deststnr);
|
||||
setsign(dest, sign);
|
||||
return TAG_Zero;
|
||||
/* The result is zero. */
|
||||
FPU_copy_to_regi(&CONST_Z, TAG_Zero, deststnr);
|
||||
setsign(dest, sign);
|
||||
return TAG_Zero;
|
||||
}
|
||||
/* We have an exception condition, either 0/0 or Valid/Zero. */
|
||||
if (taga == TAG_Zero) {
|
||||
/* 0/0 */
|
||||
return arith_invalid(deststnr);
|
||||
}
|
||||
/* Valid/Zero */
|
||||
return FPU_divide_by_zero(deststnr, sign);
|
||||
}
|
||||
/* We have an exception condition, either 0/0 or Valid/Zero. */
|
||||
if ( taga == TAG_Zero )
|
||||
{
|
||||
/* 0/0 */
|
||||
return arith_invalid(deststnr);
|
||||
}
|
||||
/* Valid/Zero */
|
||||
return FPU_divide_by_zero(deststnr, sign);
|
||||
}
|
||||
/* Must have infinities, NaNs, etc */
|
||||
else if ( (taga == TW_NaN) || (tagb == TW_NaN) )
|
||||
{
|
||||
if ( flags & LOADED )
|
||||
return real_2op_NaN((FPU_REG *)rm, flags & 0x0f, 0, st0_ptr);
|
||||
/* Must have infinities, NaNs, etc */
|
||||
else if ((taga == TW_NaN) || (tagb == TW_NaN)) {
|
||||
if (flags & LOADED)
|
||||
return real_2op_NaN((FPU_REG *) rm, flags & 0x0f, 0,
|
||||
st0_ptr);
|
||||
|
||||
if ( flags & DEST_RM )
|
||||
{
|
||||
int tag;
|
||||
tag = FPU_gettag0();
|
||||
if ( tag == TAG_Special )
|
||||
tag = FPU_Special(st0_ptr);
|
||||
return real_2op_NaN(st0_ptr, tag, rm, (flags & REV) ? st0_ptr : &st(rm));
|
||||
}
|
||||
else
|
||||
{
|
||||
int tag;
|
||||
tag = FPU_gettagi(rm);
|
||||
if ( tag == TAG_Special )
|
||||
tag = FPU_Special(&st(rm));
|
||||
return real_2op_NaN(&st(rm), tag, 0, (flags & REV) ? st0_ptr : &st(rm));
|
||||
}
|
||||
}
|
||||
else if (taga == TW_Infinity)
|
||||
{
|
||||
if (tagb == TW_Infinity)
|
||||
{
|
||||
/* infinity/infinity */
|
||||
return arith_invalid(deststnr);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* tagb must be Valid or Zero */
|
||||
if ( (tagb == TW_Denormal) && (denormal_operand() < 0) )
|
||||
return FPU_Exception;
|
||||
|
||||
/* Infinity divided by Zero or Valid does
|
||||
not raise and exception, but returns Infinity */
|
||||
FPU_copy_to_regi(a, TAG_Special, deststnr);
|
||||
setsign(dest, sign);
|
||||
return taga;
|
||||
}
|
||||
}
|
||||
else if (tagb == TW_Infinity)
|
||||
{
|
||||
if ( (taga == TW_Denormal) && (denormal_operand() < 0) )
|
||||
return FPU_Exception;
|
||||
if (flags & DEST_RM) {
|
||||
int tag;
|
||||
tag = FPU_gettag0();
|
||||
if (tag == TAG_Special)
|
||||
tag = FPU_Special(st0_ptr);
|
||||
return real_2op_NaN(st0_ptr, tag, rm,
|
||||
(flags & REV) ? st0_ptr : &st(rm));
|
||||
} else {
|
||||
int tag;
|
||||
tag = FPU_gettagi(rm);
|
||||
if (tag == TAG_Special)
|
||||
tag = FPU_Special(&st(rm));
|
||||
return real_2op_NaN(&st(rm), tag, 0,
|
||||
(flags & REV) ? st0_ptr : &st(rm));
|
||||
}
|
||||
} else if (taga == TW_Infinity) {
|
||||
if (tagb == TW_Infinity) {
|
||||
/* infinity/infinity */
|
||||
return arith_invalid(deststnr);
|
||||
} else {
|
||||
/* tagb must be Valid or Zero */
|
||||
if ((tagb == TW_Denormal) && (denormal_operand() < 0))
|
||||
return FPU_Exception;
|
||||
|
||||
/* The result is zero. */
|
||||
FPU_copy_to_regi(&CONST_Z, TAG_Zero, deststnr);
|
||||
setsign(dest, sign);
|
||||
return TAG_Zero;
|
||||
}
|
||||
/* Infinity divided by Zero or Valid does
|
||||
not raise and exception, but returns Infinity */
|
||||
FPU_copy_to_regi(a, TAG_Special, deststnr);
|
||||
setsign(dest, sign);
|
||||
return taga;
|
||||
}
|
||||
} else if (tagb == TW_Infinity) {
|
||||
if ((taga == TW_Denormal) && (denormal_operand() < 0))
|
||||
return FPU_Exception;
|
||||
|
||||
/* The result is zero. */
|
||||
FPU_copy_to_regi(&CONST_Z, TAG_Zero, deststnr);
|
||||
setsign(dest, sign);
|
||||
return TAG_Zero;
|
||||
}
|
||||
#ifdef PARANOID
|
||||
else
|
||||
{
|
||||
EXCEPTION(EX_INTERNAL|0x102);
|
||||
return FPU_Exception;
|
||||
}
|
||||
#endif /* PARANOID */
|
||||
else {
|
||||
EXCEPTION(EX_INTERNAL | 0x102);
|
||||
return FPU_Exception;
|
||||
}
|
||||
#endif /* PARANOID */
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -20,7 +20,6 @@
|
|||
#include "reg_constant.h"
|
||||
#include "fpu_system.h"
|
||||
|
||||
|
||||
/*
|
||||
Multiply two registers to give a register result.
|
||||
The sources are st(deststnr) and (b,tagb,signb).
|
||||
|
@ -29,104 +28,88 @@
|
|||
/* This routine must be called with non-empty source registers */
|
||||
int FPU_mul(FPU_REG const *b, u_char tagb, int deststnr, int control_w)
|
||||
{
|
||||
FPU_REG *a = &st(deststnr);
|
||||
FPU_REG *dest = a;
|
||||
u_char taga = FPU_gettagi(deststnr);
|
||||
u_char saved_sign = getsign(dest);
|
||||
u_char sign = (getsign(a) ^ getsign(b));
|
||||
int tag;
|
||||
FPU_REG *a = &st(deststnr);
|
||||
FPU_REG *dest = a;
|
||||
u_char taga = FPU_gettagi(deststnr);
|
||||
u_char saved_sign = getsign(dest);
|
||||
u_char sign = (getsign(a) ^ getsign(b));
|
||||
int tag;
|
||||
|
||||
if (!(taga | tagb)) {
|
||||
/* Both regs Valid, this should be the most common case. */
|
||||
|
||||
if ( !(taga | tagb) )
|
||||
{
|
||||
/* Both regs Valid, this should be the most common case. */
|
||||
|
||||
tag = FPU_u_mul(a, b, dest, control_w, sign, exponent(a) + exponent(b));
|
||||
if ( tag < 0 )
|
||||
{
|
||||
setsign(dest, saved_sign);
|
||||
return tag;
|
||||
tag =
|
||||
FPU_u_mul(a, b, dest, control_w, sign,
|
||||
exponent(a) + exponent(b));
|
||||
if (tag < 0) {
|
||||
setsign(dest, saved_sign);
|
||||
return tag;
|
||||
}
|
||||
FPU_settagi(deststnr, tag);
|
||||
return tag;
|
||||
}
|
||||
FPU_settagi(deststnr, tag);
|
||||
return tag;
|
||||
}
|
||||
|
||||
if ( taga == TAG_Special )
|
||||
taga = FPU_Special(a);
|
||||
if ( tagb == TAG_Special )
|
||||
tagb = FPU_Special(b);
|
||||
if (taga == TAG_Special)
|
||||
taga = FPU_Special(a);
|
||||
if (tagb == TAG_Special)
|
||||
tagb = FPU_Special(b);
|
||||
|
||||
if ( ((taga == TAG_Valid) && (tagb == TW_Denormal))
|
||||
if (((taga == TAG_Valid) && (tagb == TW_Denormal))
|
||||
|| ((taga == TW_Denormal) && (tagb == TAG_Valid))
|
||||
|| ((taga == TW_Denormal) && (tagb == TW_Denormal)) )
|
||||
{
|
||||
FPU_REG x, y;
|
||||
if ( denormal_operand() < 0 )
|
||||
return FPU_Exception;
|
||||
|| ((taga == TW_Denormal) && (tagb == TW_Denormal))) {
|
||||
FPU_REG x, y;
|
||||
if (denormal_operand() < 0)
|
||||
return FPU_Exception;
|
||||
|
||||
FPU_to_exp16(a, &x);
|
||||
FPU_to_exp16(b, &y);
|
||||
tag = FPU_u_mul(&x, &y, dest, control_w, sign,
|
||||
exponent16(&x) + exponent16(&y));
|
||||
if ( tag < 0 )
|
||||
{
|
||||
setsign(dest, saved_sign);
|
||||
return tag;
|
||||
FPU_to_exp16(a, &x);
|
||||
FPU_to_exp16(b, &y);
|
||||
tag = FPU_u_mul(&x, &y, dest, control_w, sign,
|
||||
exponent16(&x) + exponent16(&y));
|
||||
if (tag < 0) {
|
||||
setsign(dest, saved_sign);
|
||||
return tag;
|
||||
}
|
||||
FPU_settagi(deststnr, tag);
|
||||
return tag;
|
||||
} else if ((taga <= TW_Denormal) && (tagb <= TW_Denormal)) {
|
||||
if (((tagb == TW_Denormal) || (taga == TW_Denormal))
|
||||
&& (denormal_operand() < 0))
|
||||
return FPU_Exception;
|
||||
|
||||
/* Must have either both arguments == zero, or
|
||||
one valid and the other zero.
|
||||
The result is therefore zero. */
|
||||
FPU_copy_to_regi(&CONST_Z, TAG_Zero, deststnr);
|
||||
/* The 80486 book says that the answer is +0, but a real
|
||||
80486 behaves this way.
|
||||
IEEE-754 apparently says it should be this way. */
|
||||
setsign(dest, sign);
|
||||
return TAG_Zero;
|
||||
}
|
||||
/* Must have infinities, NaNs, etc */
|
||||
else if ((taga == TW_NaN) || (tagb == TW_NaN)) {
|
||||
return real_2op_NaN(b, tagb, deststnr, &st(0));
|
||||
} else if (((taga == TW_Infinity) && (tagb == TAG_Zero))
|
||||
|| ((tagb == TW_Infinity) && (taga == TAG_Zero))) {
|
||||
return arith_invalid(deststnr); /* Zero*Infinity is invalid */
|
||||
} else if (((taga == TW_Denormal) || (tagb == TW_Denormal))
|
||||
&& (denormal_operand() < 0)) {
|
||||
return FPU_Exception;
|
||||
} else if (taga == TW_Infinity) {
|
||||
FPU_copy_to_regi(a, TAG_Special, deststnr);
|
||||
setsign(dest, sign);
|
||||
return TAG_Special;
|
||||
} else if (tagb == TW_Infinity) {
|
||||
FPU_copy_to_regi(b, TAG_Special, deststnr);
|
||||
setsign(dest, sign);
|
||||
return TAG_Special;
|
||||
}
|
||||
FPU_settagi(deststnr, tag);
|
||||
return tag;
|
||||
}
|
||||
else if ( (taga <= TW_Denormal) && (tagb <= TW_Denormal) )
|
||||
{
|
||||
if ( ((tagb == TW_Denormal) || (taga == TW_Denormal))
|
||||
&& (denormal_operand() < 0) )
|
||||
return FPU_Exception;
|
||||
|
||||
/* Must have either both arguments == zero, or
|
||||
one valid and the other zero.
|
||||
The result is therefore zero. */
|
||||
FPU_copy_to_regi(&CONST_Z, TAG_Zero, deststnr);
|
||||
/* The 80486 book says that the answer is +0, but a real
|
||||
80486 behaves this way.
|
||||
IEEE-754 apparently says it should be this way. */
|
||||
setsign(dest, sign);
|
||||
return TAG_Zero;
|
||||
}
|
||||
/* Must have infinities, NaNs, etc */
|
||||
else if ( (taga == TW_NaN) || (tagb == TW_NaN) )
|
||||
{
|
||||
return real_2op_NaN(b, tagb, deststnr, &st(0));
|
||||
}
|
||||
else if ( ((taga == TW_Infinity) && (tagb == TAG_Zero))
|
||||
|| ((tagb == TW_Infinity) && (taga == TAG_Zero)) )
|
||||
{
|
||||
return arith_invalid(deststnr); /* Zero*Infinity is invalid */
|
||||
}
|
||||
else if ( ((taga == TW_Denormal) || (tagb == TW_Denormal))
|
||||
&& (denormal_operand() < 0) )
|
||||
{
|
||||
return FPU_Exception;
|
||||
}
|
||||
else if (taga == TW_Infinity)
|
||||
{
|
||||
FPU_copy_to_regi(a, TAG_Special, deststnr);
|
||||
setsign(dest, sign);
|
||||
return TAG_Special;
|
||||
}
|
||||
else if (tagb == TW_Infinity)
|
||||
{
|
||||
FPU_copy_to_regi(b, TAG_Special, deststnr);
|
||||
setsign(dest, sign);
|
||||
return TAG_Special;
|
||||
}
|
||||
|
||||
#ifdef PARANOID
|
||||
else
|
||||
{
|
||||
EXCEPTION(EX_INTERNAL|0x102);
|
||||
return FPU_Exception;
|
||||
}
|
||||
#endif /* PARANOID */
|
||||
else {
|
||||
EXCEPTION(EX_INTERNAL | 0x102);
|
||||
return FPU_Exception;
|
||||
}
|
||||
#endif /* PARANOID */
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
#ifndef _STATUS_H_
|
||||
#define _STATUS_H_
|
||||
|
||||
#include "fpu_emu.h" /* for definition of PECULIAR_486 */
|
||||
#include "fpu_emu.h" /* for definition of PECULIAR_486 */
|
||||
|
||||
#ifdef __ASSEMBLY__
|
||||
#define Const__(x) $##x
|
||||
|
@ -34,7 +34,7 @@
|
|||
#define SW_Denorm_Op Const__(0x0002) /* denormalized operand */
|
||||
#define SW_Invalid Const__(0x0001) /* invalid operation */
|
||||
|
||||
#define SW_Exc_Mask Const__(0x27f) /* Status word exception bit mask */
|
||||
#define SW_Exc_Mask Const__(0x27f) /* Status word exception bit mask */
|
||||
|
||||
#ifndef __ASSEMBLY__
|
||||
|
||||
|
@ -50,8 +50,8 @@
|
|||
((partial_status & ~SW_Top & 0xffff) | ((top << SW_Top_Shift) & SW_Top))
|
||||
static inline void setcc(int cc)
|
||||
{
|
||||
partial_status &= ~(SW_C0|SW_C1|SW_C2|SW_C3);
|
||||
partial_status |= (cc) & (SW_C0|SW_C1|SW_C2|SW_C3);
|
||||
partial_status &= ~(SW_C0 | SW_C1 | SW_C2 | SW_C3);
|
||||
partial_status |= (cc) & (SW_C0 | SW_C1 | SW_C2 | SW_C3);
|
||||
}
|
||||
|
||||
#ifdef PECULIAR_486
|
||||
|
|
Загрузка…
Ссылка в новой задаче