From 91b00d98a5973d47b831495f5c668bbb185c7a15 Mon Sep 17 00:00:00 2001 From: Nilay Vaish Date: Tue, 15 Jan 2013 07:43:19 -0600 Subject: [PATCH] x86: implement fabs, fchs instructions --- src/arch/x86/isa/decoder/x87.isa | 4 ++-- .../isa/insts/x87/arithmetic/change_sign.py | 10 ++++++++-- src/arch/x86/isa/microops/fpop.isa | 8 ++++++++ src/arch/x86/isa/operands.isa | 4 ++++ src/arch/x86/regs/misc.hh | 19 +++++++++++++++++++ 5 files changed, 41 insertions(+), 4 deletions(-) diff --git a/src/arch/x86/isa/decoder/x87.isa b/src/arch/x86/isa/decoder/x87.isa index 3af68cd54..f278dc2f8 100644 --- a/src/arch/x86/isa/decoder/x87.isa +++ b/src/arch/x86/isa/decoder/x87.isa @@ -68,8 +68,8 @@ format WarnUnimpl { } 0x4: decode MODRM_MOD { 0x3: decode MODRM_RM { - 0x0: fchs(); - 0x1: fabs(); + 0x0: Inst::FCHS(); + 0x1: Inst::FABS(); 0x4: ftst(); 0x5: fxam(); default: Inst::UD2(); diff --git a/src/arch/x86/isa/insts/x87/arithmetic/change_sign.py b/src/arch/x86/isa/insts/x87/arithmetic/change_sign.py index 059fb1ef1..779f1b5b2 100644 --- a/src/arch/x86/isa/insts/x87/arithmetic/change_sign.py +++ b/src/arch/x86/isa/insts/x87/arithmetic/change_sign.py @@ -36,6 +36,12 @@ # Authors: Gabe Black microcode = ''' -# FABS -# FCHS + +def macroop FABS { + absfp st(0), st(0) +}; + +def macroop FCHS { + chsfp st(0), st(0) +}; ''' diff --git a/src/arch/x86/isa/microops/fpop.isa b/src/arch/x86/isa/microops/fpop.isa index f6cbd2036..b9aceea09 100644 --- a/src/arch/x86/isa/microops/fpop.isa +++ b/src/arch/x86/isa/microops/fpop.isa @@ -331,4 +331,12 @@ let {{ else if(FpSrcReg1 == FpSrcReg2) ccFlagBits = ccFlagBits | ZFBit; ''' + + class absfp(FpUnaryOp): + code = 'FpDestReg = fabs(FpSrcReg1);' + flag_code = 'FSW &= (~CC1Bit);' + + class chsfp(FpUnaryOp): + code = 'FpDestReg = (-1) * (FpSrcReg1);' + flag_code = 'FSW &= (~CC1Bit);' }}; diff --git a/src/arch/x86/isa/operands.isa b/src/arch/x86/isa/operands.isa index 05b127e37..bc6d1886c 100644 --- a/src/arch/x86/isa/operands.isa +++ b/src/arch/x86/isa/operands.isa @@ -158,7 +158,11 @@ def operands {{ # These register should needs to be more protected so that later # instructions don't map their indexes with an old value. 'nccFlagBits': controlReg('MISCREG_RFLAGS', 65), + + # Registers related to the state of x87 floating point unit. 'TOP': controlReg('MISCREG_X87_TOP', 66, ctype='ub'), + 'FSW': controlReg('MISCREG_FSW', 67, ctype='uw'), + # The segment base as used by memory instructions. 'SegBase': controlReg('MISCREG_SEG_EFF_BASE(segment)', 70), diff --git a/src/arch/x86/regs/misc.hh b/src/arch/x86/regs/misc.hh index 697c81fc9..5887e7486 100644 --- a/src/arch/x86/regs/misc.hh +++ b/src/arch/x86/regs/misc.hh @@ -79,6 +79,25 @@ namespace X86ISA IDBit = 1 << 21 }; + enum X87StatusBit { + // Exception Flags + IEBit = 1 << 0, + DEBit = 1 << 1, + ZEBit = 1 << 2, + OEBit = 1 << 3, + UEBit = 1 << 4, + PEBit = 1 << 5, + + // !Exception Flags + StackFaultBit = 1 << 6, + ErrSummaryBit = 1 << 7, + CC0Bit = 1 << 8, + CC1Bit = 1 << 9, + CC2Bit = 1 << 10, + CC3Bit = 1 << 14, + BusyBit = 1 << 15, + }; + enum MiscRegIndex { // Control registers -- 2.30.2