2007-12-07 13:59:18 +03:00
|
|
|
/////////////////////////////////////////////////////////////////////////
|
2009-01-16 21:18:59 +03:00
|
|
|
// $Id: bit16.cc,v 1.16 2009-01-16 18:18:58 sshwarts Exp $
|
2007-12-07 13:59:18 +03:00
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// Copyright (C) 2001 MandrakeSoft S.A.
|
|
|
|
//
|
|
|
|
// MandrakeSoft S.A.
|
|
|
|
// 43, rue d'Aboukir
|
|
|
|
// 75002 Paris - France
|
|
|
|
// http://www.linux-mandrake.com/
|
|
|
|
// http://www.mandrakesoft.com/
|
|
|
|
//
|
|
|
|
// This library is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU Lesser General Public
|
|
|
|
// License as published by the Free Software Foundation; either
|
|
|
|
// version 2 of the License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This library is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
// Lesser General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Lesser General Public
|
|
|
|
// License along with this library; if not, write to the Free Software
|
2009-01-16 21:18:59 +03:00
|
|
|
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA B 02110-1301 USA
|
2007-12-07 13:59:18 +03:00
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#define NEED_CPU_REG_SHORTCUTS 1
|
|
|
|
#include "bochs.h"
|
|
|
|
#include "cpu.h"
|
|
|
|
#define LOG_THIS BX_CPU_THIS_PTR
|
|
|
|
|
|
|
|
#if BX_CPU_LEVEL >= 3
|
|
|
|
|
2008-08-10 23:34:28 +04:00
|
|
|
void BX_CPP_AttrRegparmN(1) BX_CPU_C::BSF_GwEwR(bxInstruction_c *i)
|
2007-12-07 13:59:18 +03:00
|
|
|
{
|
2008-08-10 23:34:28 +04:00
|
|
|
Bit16u op2_16 = BX_READ_16BIT_REG(i->rm());
|
2007-12-07 13:59:18 +03:00
|
|
|
|
|
|
|
if (op2_16 == 0) {
|
|
|
|
assert_ZF(); /* op1_16 undefined */
|
|
|
|
}
|
2008-07-13 14:44:34 +04:00
|
|
|
else {
|
2008-08-10 23:34:28 +04:00
|
|
|
Bit16u op1_16 = 0;
|
2008-07-13 14:44:34 +04:00
|
|
|
while ((op2_16 & 0x01) == 0) {
|
|
|
|
op1_16++;
|
|
|
|
op2_16 >>= 1;
|
|
|
|
}
|
2007-12-07 13:59:18 +03:00
|
|
|
|
2008-07-13 14:44:34 +04:00
|
|
|
SET_FLAGS_OSZAPC_LOGIC_16(op1_16);
|
|
|
|
clear_ZF();
|
2007-12-07 13:59:18 +03:00
|
|
|
|
2008-07-13 14:44:34 +04:00
|
|
|
/* now write result back to destination */
|
|
|
|
BX_WRITE_16BIT_REG(i->nnn(), op1_16);
|
|
|
|
}
|
2007-12-07 13:59:18 +03:00
|
|
|
}
|
|
|
|
|
2008-08-10 23:34:28 +04:00
|
|
|
void BX_CPP_AttrRegparmN(1) BX_CPU_C::BSR_GwEwR(bxInstruction_c *i)
|
2007-12-07 13:59:18 +03:00
|
|
|
{
|
2008-08-10 23:34:28 +04:00
|
|
|
Bit16u op2_16 = BX_READ_16BIT_REG(i->rm());
|
2007-12-07 13:59:18 +03:00
|
|
|
|
|
|
|
if (op2_16 == 0) {
|
|
|
|
assert_ZF(); /* op1_16 undefined */
|
|
|
|
}
|
2008-07-13 14:44:34 +04:00
|
|
|
else {
|
2008-08-10 23:34:28 +04:00
|
|
|
Bit16u op1_16 = 15;
|
2008-07-13 14:44:34 +04:00
|
|
|
while ((op2_16 & 0x8000) == 0) {
|
|
|
|
op1_16--;
|
|
|
|
op2_16 <<= 1;
|
|
|
|
}
|
2007-12-07 13:59:18 +03:00
|
|
|
|
2008-07-13 14:44:34 +04:00
|
|
|
SET_FLAGS_OSZAPC_LOGIC_16(op1_16);
|
|
|
|
clear_ZF();
|
2007-12-07 13:59:18 +03:00
|
|
|
|
2008-07-13 14:44:34 +04:00
|
|
|
/* now write result back to destination */
|
|
|
|
BX_WRITE_16BIT_REG(i->nnn(), op1_16);
|
|
|
|
}
|
2007-12-07 13:59:18 +03:00
|
|
|
}
|
|
|
|
|
2008-03-23 00:29:41 +03:00
|
|
|
void BX_CPP_AttrRegparmN(1) BX_CPU_C::BT_EwGwM(bxInstruction_c *i)
|
2007-12-07 13:59:18 +03:00
|
|
|
{
|
|
|
|
bx_address op1_addr;
|
|
|
|
Bit16u op1_16, op2_16, index;
|
|
|
|
Bit32s displacement32;
|
|
|
|
|
2008-08-08 13:22:49 +04:00
|
|
|
bx_address eaddr = BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
|
2008-01-10 22:37:56 +03:00
|
|
|
|
2007-12-07 13:59:18 +03:00
|
|
|
op2_16 = BX_READ_16BIT_REG(i->nnn());
|
|
|
|
index = op2_16 & 0x0f;
|
|
|
|
displacement32 = ((Bit16s) (op2_16&0xfff0)) / 16;
|
2008-08-08 13:22:49 +04:00
|
|
|
op1_addr = eaddr + 2 * displacement32;
|
2008-04-25 11:40:51 +04:00
|
|
|
if (! i->as32L())
|
|
|
|
op1_addr = (Bit16u) op1_addr;
|
|
|
|
#if BX_SUPPORT_X86_64
|
|
|
|
else if (! i->as64L())
|
|
|
|
op1_addr = (Bit32u) op1_addr;
|
|
|
|
#endif
|
2007-12-07 13:59:18 +03:00
|
|
|
|
|
|
|
/* pointer, segment address pair */
|
2007-12-20 23:58:38 +03:00
|
|
|
op1_16 = read_virtual_word(i->seg(), op1_addr);
|
2007-12-07 13:59:18 +03:00
|
|
|
|
|
|
|
set_CF((op1_16 >> index) & 0x01);
|
|
|
|
}
|
|
|
|
|
2008-03-23 00:29:41 +03:00
|
|
|
void BX_CPP_AttrRegparmN(1) BX_CPU_C::BT_EwGwR(bxInstruction_c *i)
|
2007-12-07 13:59:18 +03:00
|
|
|
{
|
|
|
|
Bit16u op1_16, op2_16;
|
|
|
|
|
|
|
|
op1_16 = BX_READ_16BIT_REG(i->rm());
|
|
|
|
op2_16 = BX_READ_16BIT_REG(i->nnn());
|
|
|
|
op2_16 &= 0x0f;
|
|
|
|
set_CF((op1_16 >> op2_16) & 0x01);
|
|
|
|
}
|
|
|
|
|
2008-03-23 00:29:41 +03:00
|
|
|
void BX_CPP_AttrRegparmN(1) BX_CPU_C::BTS_EwGwM(bxInstruction_c *i)
|
2007-12-07 13:59:18 +03:00
|
|
|
{
|
|
|
|
bx_address op1_addr;
|
2007-12-23 20:21:28 +03:00
|
|
|
Bit16u op1_16, op2_16, index;
|
2007-12-07 13:59:18 +03:00
|
|
|
Bit32s displacement32;
|
2007-12-23 20:21:28 +03:00
|
|
|
bx_bool bit_i;
|
2007-12-07 13:59:18 +03:00
|
|
|
|
2008-08-08 13:22:49 +04:00
|
|
|
bx_address eaddr = BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
|
2008-01-10 22:37:56 +03:00
|
|
|
|
2007-12-07 13:59:18 +03:00
|
|
|
op2_16 = BX_READ_16BIT_REG(i->nnn());
|
|
|
|
index = op2_16 & 0x0f;
|
|
|
|
displacement32 = ((Bit16s) (op2_16 & 0xfff0)) / 16;
|
2008-08-08 13:22:49 +04:00
|
|
|
op1_addr = eaddr + 2 * displacement32;
|
2008-04-25 11:40:51 +04:00
|
|
|
if (! i->as32L())
|
|
|
|
op1_addr = (Bit16u) op1_addr;
|
|
|
|
#if BX_SUPPORT_X86_64
|
|
|
|
else if (! i->as64L())
|
|
|
|
op1_addr = (Bit32u) op1_addr;
|
|
|
|
#endif
|
2007-12-07 13:59:18 +03:00
|
|
|
|
|
|
|
/* pointer, segment address pair */
|
2007-12-20 23:58:38 +03:00
|
|
|
op1_16 = read_RMW_virtual_word(i->seg(), op1_addr);
|
2007-12-07 13:59:18 +03:00
|
|
|
bit_i = (op1_16 >> index) & 0x01;
|
|
|
|
op1_16 |= (((Bit16u) 1) << index);
|
|
|
|
write_RMW_virtual_word(op1_16);
|
|
|
|
|
|
|
|
set_CF(bit_i);
|
|
|
|
}
|
|
|
|
|
2008-03-23 00:29:41 +03:00
|
|
|
void BX_CPP_AttrRegparmN(1) BX_CPU_C::BTS_EwGwR(bxInstruction_c *i)
|
2007-12-07 13:59:18 +03:00
|
|
|
{
|
|
|
|
Bit16u op1_16, op2_16;
|
|
|
|
|
|
|
|
op1_16 = BX_READ_16BIT_REG(i->rm());
|
|
|
|
op2_16 = BX_READ_16BIT_REG(i->nnn());
|
|
|
|
op2_16 &= 0x0f;
|
|
|
|
set_CF((op1_16 >> op2_16) & 0x01);
|
|
|
|
op1_16 |= (((Bit16u) 1) << op2_16);
|
|
|
|
|
|
|
|
/* now write result back to the destination */
|
|
|
|
BX_WRITE_16BIT_REG(i->rm(), op1_16);
|
|
|
|
}
|
|
|
|
|
2008-03-23 00:29:41 +03:00
|
|
|
void BX_CPP_AttrRegparmN(1) BX_CPU_C::BTR_EwGwM(bxInstruction_c *i)
|
2007-12-07 13:59:18 +03:00
|
|
|
{
|
|
|
|
bx_address op1_addr;
|
|
|
|
Bit16u op1_16, op2_16, index;
|
|
|
|
Bit32s displacement32;
|
|
|
|
|
2008-08-08 13:22:49 +04:00
|
|
|
bx_address eaddr = BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
|
2008-01-10 22:37:56 +03:00
|
|
|
|
2007-12-07 13:59:18 +03:00
|
|
|
op2_16 = BX_READ_16BIT_REG(i->nnn());
|
|
|
|
index = op2_16 & 0x0f;
|
|
|
|
displacement32 = ((Bit16s) (op2_16&0xfff0)) / 16;
|
2008-08-08 13:22:49 +04:00
|
|
|
op1_addr = eaddr + 2 * displacement32;
|
2008-04-25 11:40:51 +04:00
|
|
|
if (! i->as32L())
|
|
|
|
op1_addr = (Bit16u) op1_addr;
|
|
|
|
#if BX_SUPPORT_X86_64
|
|
|
|
else if (! i->as64L())
|
|
|
|
op1_addr = (Bit32u) op1_addr;
|
|
|
|
#endif
|
2007-12-07 13:59:18 +03:00
|
|
|
|
|
|
|
/* pointer, segment address pair */
|
2007-12-20 23:58:38 +03:00
|
|
|
op1_16 = read_RMW_virtual_word(i->seg(), op1_addr);
|
2007-12-07 13:59:18 +03:00
|
|
|
bx_bool temp_cf = (op1_16 >> index) & 0x01;
|
|
|
|
op1_16 &= ~(((Bit16u) 1) << index);
|
|
|
|
|
|
|
|
/* now write back to destination */
|
|
|
|
write_RMW_virtual_word(op1_16);
|
|
|
|
|
|
|
|
set_CF(temp_cf);
|
|
|
|
}
|
|
|
|
|
2008-03-23 00:29:41 +03:00
|
|
|
void BX_CPP_AttrRegparmN(1) BX_CPU_C::BTR_EwGwR(bxInstruction_c *i)
|
2007-12-07 13:59:18 +03:00
|
|
|
{
|
|
|
|
Bit16u op1_16, op2_16;
|
|
|
|
|
|
|
|
op1_16 = BX_READ_16BIT_REG(i->rm());
|
|
|
|
op2_16 = BX_READ_16BIT_REG(i->nnn());
|
|
|
|
op2_16 &= 0x0f;
|
|
|
|
set_CF((op1_16 >> op2_16) & 0x01);
|
|
|
|
op1_16 &= ~(((Bit16u) 1) << op2_16);
|
|
|
|
|
|
|
|
/* now write result back to the destination */
|
|
|
|
BX_WRITE_16BIT_REG(i->rm(), op1_16);
|
|
|
|
}
|
|
|
|
|
2008-03-23 00:29:41 +03:00
|
|
|
void BX_CPP_AttrRegparmN(1) BX_CPU_C::BTC_EwGwM(bxInstruction_c *i)
|
2007-12-07 13:59:18 +03:00
|
|
|
{
|
|
|
|
bx_address op1_addr;
|
|
|
|
Bit16u op1_16, op2_16, index_16;
|
|
|
|
Bit16s displacement16;
|
|
|
|
|
2008-08-08 13:22:49 +04:00
|
|
|
bx_address eaddr = BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
|
2008-01-10 22:37:56 +03:00
|
|
|
|
2007-12-07 13:59:18 +03:00
|
|
|
op2_16 = BX_READ_16BIT_REG(i->nnn());
|
|
|
|
index_16 = op2_16 & 0x0f;
|
|
|
|
displacement16 = ((Bit16s) (op2_16 & 0xfff0)) / 16;
|
2008-08-08 13:22:49 +04:00
|
|
|
op1_addr = eaddr + 2 * displacement16;
|
2008-04-25 11:40:51 +04:00
|
|
|
if (! i->as32L())
|
|
|
|
op1_addr = (Bit16u) op1_addr;
|
|
|
|
#if BX_SUPPORT_X86_64
|
|
|
|
else if (! i->as64L())
|
|
|
|
op1_addr = (Bit32u) op1_addr;
|
|
|
|
#endif
|
2007-12-07 13:59:18 +03:00
|
|
|
|
2008-04-25 11:40:51 +04:00
|
|
|
op1_16 = read_RMW_virtual_word(i->seg(), op1_addr);
|
2007-12-07 13:59:18 +03:00
|
|
|
bx_bool temp_CF = (op1_16 >> index_16) & 0x01;
|
|
|
|
op1_16 ^= (((Bit16u) 1) << index_16); /* toggle bit */
|
|
|
|
write_RMW_virtual_word(op1_16);
|
|
|
|
|
|
|
|
set_CF(temp_CF);
|
|
|
|
}
|
|
|
|
|
2008-03-23 00:29:41 +03:00
|
|
|
void BX_CPP_AttrRegparmN(1) BX_CPU_C::BTC_EwGwR(bxInstruction_c *i)
|
2007-12-07 13:59:18 +03:00
|
|
|
{
|
|
|
|
Bit16u op1_16, op2_16;
|
|
|
|
|
|
|
|
op1_16 = BX_READ_16BIT_REG(i->rm());
|
|
|
|
op2_16 = BX_READ_16BIT_REG(i->nnn());
|
|
|
|
op2_16 &= 0x0f;
|
|
|
|
|
|
|
|
bx_bool temp_CF = (op1_16 >> op2_16) & 0x01;
|
|
|
|
op1_16 ^= (((Bit16u) 1) << op2_16); /* toggle bit */
|
|
|
|
BX_WRITE_16BIT_REG(i->rm(), op1_16);
|
|
|
|
|
|
|
|
set_CF(temp_CF);
|
|
|
|
}
|
|
|
|
|
2008-03-23 00:29:41 +03:00
|
|
|
void BX_CPP_AttrRegparmN(1) BX_CPU_C::BT_EwIbM(bxInstruction_c *i)
|
2007-12-07 13:59:18 +03:00
|
|
|
{
|
2008-08-08 13:22:49 +04:00
|
|
|
bx_address eaddr = BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
|
2008-01-10 22:37:56 +03:00
|
|
|
|
2008-08-08 13:22:49 +04:00
|
|
|
Bit16u op1_16 = read_virtual_word(i->seg(), eaddr);
|
2007-12-20 23:58:38 +03:00
|
|
|
Bit8u op2_8 = i->Ib() & 0xf;
|
2007-12-07 13:59:18 +03:00
|
|
|
|
|
|
|
set_CF((op1_16 >> op2_8) & 0x01);
|
|
|
|
}
|
|
|
|
|
2008-03-23 00:29:41 +03:00
|
|
|
void BX_CPP_AttrRegparmN(1) BX_CPU_C::BT_EwIbR(bxInstruction_c *i)
|
2007-12-07 13:59:18 +03:00
|
|
|
{
|
|
|
|
Bit16u op1_16 = BX_READ_16BIT_REG(i->rm());
|
|
|
|
Bit8u op2_8 = i->Ib() & 0xf;
|
|
|
|
|
|
|
|
set_CF((op1_16 >> op2_8) & 0x01);
|
|
|
|
}
|
|
|
|
|
2008-03-23 00:29:41 +03:00
|
|
|
void BX_CPP_AttrRegparmN(1) BX_CPU_C::BTS_EwIbM(bxInstruction_c *i)
|
2007-12-07 13:59:18 +03:00
|
|
|
{
|
|
|
|
Bit8u op2_8 = i->Ib() & 0xf;
|
|
|
|
|
2008-08-08 13:22:49 +04:00
|
|
|
bx_address eaddr = BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
|
2008-01-10 22:37:56 +03:00
|
|
|
|
2008-08-08 13:22:49 +04:00
|
|
|
Bit16u op1_16 = read_RMW_virtual_word(i->seg(), eaddr);
|
2007-12-07 13:59:18 +03:00
|
|
|
bx_bool temp_CF = (op1_16 >> op2_8) & 0x01;
|
|
|
|
op1_16 |= (((Bit16u) 1) << op2_8);
|
|
|
|
write_RMW_virtual_word(op1_16);
|
|
|
|
|
|
|
|
set_CF(temp_CF);
|
|
|
|
}
|
|
|
|
|
2008-03-23 00:29:41 +03:00
|
|
|
void BX_CPP_AttrRegparmN(1) BX_CPU_C::BTS_EwIbR(bxInstruction_c *i)
|
2007-12-07 13:59:18 +03:00
|
|
|
{
|
|
|
|
Bit8u op2_8 = i->Ib() & 0xf;
|
|
|
|
|
2007-12-20 23:58:38 +03:00
|
|
|
Bit16u op1_16 = BX_READ_16BIT_REG(i->rm());
|
2007-12-07 13:59:18 +03:00
|
|
|
bx_bool temp_CF = (op1_16 >> op2_8) & 0x01;
|
|
|
|
op1_16 |= (((Bit16u) 1) << op2_8);
|
|
|
|
BX_WRITE_16BIT_REG(i->rm(), op1_16);
|
|
|
|
|
|
|
|
set_CF(temp_CF);
|
|
|
|
}
|
|
|
|
|
2008-03-23 00:29:41 +03:00
|
|
|
void BX_CPP_AttrRegparmN(1) BX_CPU_C::BTC_EwIbM(bxInstruction_c *i)
|
2007-12-07 13:59:18 +03:00
|
|
|
{
|
|
|
|
Bit8u op2_8 = i->Ib() & 0xf;
|
|
|
|
|
2008-08-08 13:22:49 +04:00
|
|
|
bx_address eaddr = BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
|
2008-01-10 22:37:56 +03:00
|
|
|
|
2008-08-08 13:22:49 +04:00
|
|
|
Bit16u op1_16 = read_RMW_virtual_word(i->seg(), eaddr);
|
2007-12-07 13:59:18 +03:00
|
|
|
bx_bool temp_CF = (op1_16 >> op2_8) & 0x01;
|
|
|
|
op1_16 ^= (((Bit16u) 1) << op2_8); /* toggle bit */
|
|
|
|
write_RMW_virtual_word(op1_16);
|
|
|
|
|
|
|
|
set_CF(temp_CF);
|
|
|
|
}
|
|
|
|
|
2008-03-23 00:29:41 +03:00
|
|
|
void BX_CPP_AttrRegparmN(1) BX_CPU_C::BTC_EwIbR(bxInstruction_c *i)
|
2007-12-07 13:59:18 +03:00
|
|
|
{
|
|
|
|
Bit8u op2_8 = i->Ib() & 0xf;
|
|
|
|
|
2007-12-20 23:58:38 +03:00
|
|
|
Bit16u op1_16 = BX_READ_16BIT_REG(i->rm());
|
2007-12-07 13:59:18 +03:00
|
|
|
bx_bool temp_CF = (op1_16 >> op2_8) & 0x01;
|
|
|
|
op1_16 ^= (((Bit16u) 1) << op2_8); /* toggle bit */
|
|
|
|
BX_WRITE_16BIT_REG(i->rm(), op1_16);
|
|
|
|
|
|
|
|
set_CF(temp_CF);
|
|
|
|
}
|
|
|
|
|
2008-03-23 00:29:41 +03:00
|
|
|
void BX_CPP_AttrRegparmN(1) BX_CPU_C::BTR_EwIbM(bxInstruction_c *i)
|
2007-12-07 13:59:18 +03:00
|
|
|
{
|
|
|
|
Bit8u op2_8 = i->Ib() & 0xf;
|
|
|
|
|
2008-08-08 13:22:49 +04:00
|
|
|
bx_address eaddr = BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
|
2008-01-10 22:37:56 +03:00
|
|
|
|
2008-08-08 13:22:49 +04:00
|
|
|
Bit16u op1_16 = read_RMW_virtual_word(i->seg(), eaddr);
|
2007-12-07 13:59:18 +03:00
|
|
|
bx_bool temp_CF = (op1_16 >> op2_8) & 0x01;
|
|
|
|
op1_16 &= ~(((Bit16u) 1) << op2_8);
|
|
|
|
write_RMW_virtual_word(op1_16);
|
|
|
|
|
|
|
|
set_CF(temp_CF);
|
|
|
|
}
|
|
|
|
|
2008-03-23 00:29:41 +03:00
|
|
|
void BX_CPP_AttrRegparmN(1) BX_CPU_C::BTR_EwIbR(bxInstruction_c *i)
|
2007-12-07 13:59:18 +03:00
|
|
|
{
|
|
|
|
Bit8u op2_8 = i->Ib() & 0xf;
|
|
|
|
|
2007-12-20 23:58:38 +03:00
|
|
|
Bit16u op1_16 = BX_READ_16BIT_REG(i->rm());
|
2007-12-07 13:59:18 +03:00
|
|
|
bx_bool temp_CF = (op1_16 >> op2_8) & 0x01;
|
|
|
|
op1_16 &= ~(((Bit16u) 1) << op2_8);
|
|
|
|
BX_WRITE_16BIT_REG(i->rm(), op1_16);
|
|
|
|
|
|
|
|
set_CF(temp_CF);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 0F B8 */
|
2008-08-11 01:16:12 +04:00
|
|
|
void BX_CPP_AttrRegparmN(1) BX_CPU_C::POPCNT_GwEwR(bxInstruction_c *i)
|
2007-12-07 13:59:18 +03:00
|
|
|
{
|
2008-08-11 22:53:24 +04:00
|
|
|
#if BX_SUPPORT_POPCNT || (BX_SUPPORT_SSE > 4) || (BX_SUPPORT_SSE >= 4 && BX_SUPPORT_SSE_EXTENSION > 0)
|
2008-08-11 01:16:12 +04:00
|
|
|
Bit16u op2_16 = BX_READ_16BIT_REG(i->rm());
|
2007-12-07 13:59:18 +03:00
|
|
|
|
2008-08-11 01:16:12 +04:00
|
|
|
Bit16u op1_16 = 0;
|
2007-12-07 13:59:18 +03:00
|
|
|
while (op2_16 != 0) {
|
|
|
|
if (op2_16 & 1) op1_16++;
|
|
|
|
op2_16 >>= 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
Bit32u flags = op1_16 ? 0 : EFlagsZFMask;
|
|
|
|
setEFlagsOSZAPC(flags);
|
|
|
|
|
|
|
|
/* now write result back to destination */
|
|
|
|
BX_WRITE_16BIT_REG(i->nnn(), op1_16);
|
|
|
|
#else
|
|
|
|
BX_INFO(("POPCNT_GwEw: required POPCNT support, use --enable-popcnt option"));
|
2008-07-13 19:35:10 +04:00
|
|
|
exception(BX_UD_EXCEPTION, 0, 0);
|
2007-12-07 13:59:18 +03:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // (BX_CPU_LEVEL >= 3)
|