Author: aandrejevic Date: Tue Aug 13 17:06:15 2013 New Revision: 59725
URL: http://svn.reactos.org/svn/reactos?rev=59725&view=rev Log: [SOFTX86] Fix carry/overflow flag computation for ADD instructions.
Modified: branches/ntvdm/lib/3rdparty/softx86/softx86/add.c
Modified: branches/ntvdm/lib/3rdparty/softx86/softx86/add.c URL: http://svn.reactos.org/svn/reactos/branches/ntvdm/lib/3rdparty/softx86/softx... ============================================================================== --- branches/ntvdm/lib/3rdparty/softx86/softx86/add.c [iso-8859-1] (original) +++ branches/ntvdm/lib/3rdparty/softx86/softx86/add.c [iso-8859-1] Tue Aug 13 17:06:15 2013 @@ -35,13 +35,16 @@ /* peform the addition */ ret = src + val;
-/* if carry/overflow */ - if (ret < src) - ctx->state->reg_flags.val |= - (SX86_CPUFLAG_CARRY | SX86_CPUFLAG_OVERFLOW); - else - ctx->state->reg_flags.val &= - ~(SX86_CPUFLAG_CARRY | SX86_CPUFLAG_OVERFLOW); +/* if carry */ + if ((ret < src) || (ret < val)) ctx->state->reg_flags.val |= SX86_CPUFLAG_CARRY; + else ctx->state->reg_flags.val &= ~SX86_CPUFLAG_CARRY; + +/* if overflow */ + if (((src & 0x80) == (val & 0x80)) && ((src & 0x80) != (ret & 0x80))) + { + ctx->state->reg_flags.val |= SX86_CPUFLAG_OVERFLOW; + } + else ctx->state->reg_flags.val &= ~SX86_CPUFLAG_OVERFLOW;
/* if result treated as signed value is negative */ if (ret & 0x80) ctx->state->reg_flags.val |= SX86_CPUFLAG_SIGN; @@ -79,13 +82,16 @@ /* peform the addition */ ret = src + val;
-/* if carry/overflow */ - if (ret < src) - ctx->state->reg_flags.val |= - (SX86_CPUFLAG_CARRY | SX86_CPUFLAG_OVERFLOW); - else - ctx->state->reg_flags.val &= - ~(SX86_CPUFLAG_CARRY | SX86_CPUFLAG_OVERFLOW); +/* if carry */ + if ((ret < src) || (ret < val)) ctx->state->reg_flags.val |= SX86_CPUFLAG_CARRY; + else ctx->state->reg_flags.val &= ~SX86_CPUFLAG_CARRY; + +/* if overflow */ + if (((src & 0x8000) == (val & 0x8000)) && ((src & 0x8000) != (ret & 0x8000))) + { + ctx->state->reg_flags.val |= SX86_CPUFLAG_OVERFLOW; + } + else ctx->state->reg_flags.val &= ~SX86_CPUFLAG_OVERFLOW;
/* if result treated as signed value is negative */ if (ret & 0x8000) @@ -125,13 +131,17 @@ /* peform the addition */ ret = src + val;
-/* if carry/overflow */ - if (ret < src) - ctx->state->reg_flags.val |= - (SX86_CPUFLAG_CARRY | SX86_CPUFLAG_OVERFLOW); - else - ctx->state->reg_flags.val &= - ~(SX86_CPUFLAG_CARRY | SX86_CPUFLAG_OVERFLOW); +/* if carry */ + if ((ret < src) || (ret < val)) ctx->state->reg_flags.val |= SX86_CPUFLAG_CARRY; + else ctx->state->reg_flags.val &= ~SX86_CPUFLAG_CARRY; + +/* if overflow */ + if (((src & 0x80000000) == (val & 0x80000000)) + && ((src & 0x80000000) != (ret & 0x80000000))) + { + ctx->state->reg_flags.val |= SX86_CPUFLAG_OVERFLOW; + } + else ctx->state->reg_flags.val &= ~SX86_CPUFLAG_OVERFLOW;
/* if result treated as signed value is negative */ if (ret & 0x80000000)