2011-08-27 17:47:16 +04:00
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
|
|
// $Id$
|
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
2012-08-01 18:56:51 +04:00
|
|
|
// Copyright (c) 2011-2012 Stanislav Shwartsman
|
2011-10-20 18:06:12 +04:00
|
|
|
// Written by Stanislav Shwartsman [sshwarts at sourceforge net]
|
2011-08-27 17:47:16 +04:00
|
|
|
//
|
|
|
|
// 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
|
|
|
|
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA B 02110-1301 USA
|
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#define NEED_CPU_REG_SHORTCUTS 1
|
|
|
|
#include "bochs.h"
|
|
|
|
#include "cpu.h"
|
|
|
|
#define LOG_THIS BX_CPU_THIS_PTR
|
|
|
|
|
|
|
|
#if BX_SUPPORT_AVX
|
|
|
|
|
|
|
|
BX_INSF_TYPE BX_CPP_AttrRegparmN(1) BX_CPU_C::ANDN_GdBdEdR(bxInstruction_c *i)
|
|
|
|
{
|
2012-08-05 17:52:40 +04:00
|
|
|
Bit32u op1_32 = BX_READ_32BIT_REG(i->src1());
|
|
|
|
Bit32u op2_32 = BX_READ_32BIT_REG(i->src2());
|
2011-08-27 17:47:16 +04:00
|
|
|
|
2012-08-05 17:52:40 +04:00
|
|
|
op1_32 = ~op1_32 & op2_32;
|
2011-08-27 17:47:16 +04:00
|
|
|
|
2011-11-27 17:23:26 +04:00
|
|
|
SET_FLAGS_OSZAxC_LOGIC_32(op1_32); // keep PF unchanged
|
2011-08-27 17:47:16 +04:00
|
|
|
|
2012-08-05 17:52:40 +04:00
|
|
|
BX_WRITE_32BIT_REGZ(i->dst(), op1_32);
|
2011-08-27 17:47:16 +04:00
|
|
|
|
|
|
|
BX_NEXT_INSTR(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
BX_INSF_TYPE BX_CPP_AttrRegparmN(1) BX_CPU_C::MULX_GdBdEdR(bxInstruction_c *i)
|
|
|
|
{
|
|
|
|
Bit32u op1_32 = EDX;
|
2012-08-05 17:52:40 +04:00
|
|
|
Bit32u op2_32 = BX_READ_32BIT_REG(i->src2());
|
2011-08-27 17:47:16 +04:00
|
|
|
Bit64u product_64 = ((Bit64u) op1_32) * ((Bit64u) op2_32);
|
|
|
|
|
2012-08-05 17:52:40 +04:00
|
|
|
BX_WRITE_32BIT_REGZ(i->src1(), GET32L(product_64));
|
|
|
|
BX_WRITE_32BIT_REGZ(i->dst(), GET32H(product_64));
|
2011-08-27 17:47:16 +04:00
|
|
|
|
|
|
|
BX_NEXT_INSTR(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
BX_INSF_TYPE BX_CPP_AttrRegparmN(1) BX_CPU_C::BLSI_BdEdR(bxInstruction_c *i)
|
|
|
|
{
|
2012-08-05 17:52:40 +04:00
|
|
|
Bit32u op1_32 = BX_READ_32BIT_REG(i->src());
|
2011-11-27 17:23:26 +04:00
|
|
|
bx_bool tmpCF = (op1_32 != 0);
|
2011-08-27 17:47:16 +04:00
|
|
|
|
|
|
|
op1_32 = (-op1_32) & op1_32;
|
|
|
|
|
2011-11-27 17:23:26 +04:00
|
|
|
SET_FLAGS_OSZAxC_LOGIC_32(op1_32); // keep PF unchanged
|
2011-08-27 17:47:16 +04:00
|
|
|
set_CF(tmpCF);
|
|
|
|
|
2012-08-05 17:52:40 +04:00
|
|
|
BX_WRITE_32BIT_REGZ(i->dst(), op1_32);
|
2011-08-27 17:47:16 +04:00
|
|
|
|
|
|
|
BX_NEXT_INSTR(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
BX_INSF_TYPE BX_CPP_AttrRegparmN(1) BX_CPU_C::BLSMSK_BdEdR(bxInstruction_c *i)
|
|
|
|
{
|
2012-08-05 17:52:40 +04:00
|
|
|
Bit32u op1_32 = BX_READ_32BIT_REG(i->src());
|
2011-08-27 17:47:16 +04:00
|
|
|
bx_bool tmpCF = (op1_32 == 0);
|
|
|
|
|
|
|
|
op1_32 = (op1_32-1) ^ op1_32;
|
|
|
|
|
2011-11-27 17:23:26 +04:00
|
|
|
SET_FLAGS_OSZAxC_LOGIC_32(op1_32); // keep PF unchanged
|
2011-08-27 17:47:16 +04:00
|
|
|
set_CF(tmpCF);
|
|
|
|
|
2012-08-05 17:52:40 +04:00
|
|
|
BX_WRITE_32BIT_REGZ(i->dst(), op1_32);
|
2011-08-27 17:47:16 +04:00
|
|
|
|
|
|
|
BX_NEXT_INSTR(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
BX_INSF_TYPE BX_CPP_AttrRegparmN(1) BX_CPU_C::BLSR_BdEdR(bxInstruction_c *i)
|
|
|
|
{
|
2012-08-05 17:52:40 +04:00
|
|
|
Bit32u op1_32 = BX_READ_32BIT_REG(i->src());
|
2011-08-27 17:47:16 +04:00
|
|
|
bx_bool tmpCF = (op1_32 == 0);
|
|
|
|
|
|
|
|
op1_32 = (op1_32-1) & op1_32;
|
|
|
|
|
2011-11-27 17:23:26 +04:00
|
|
|
SET_FLAGS_OSZAxC_LOGIC_32(op1_32); // keep PF unchanged
|
2011-08-27 17:47:16 +04:00
|
|
|
set_CF(tmpCF);
|
|
|
|
|
2012-08-05 17:52:40 +04:00
|
|
|
BX_WRITE_32BIT_REGZ(i->dst(), op1_32);
|
2011-08-27 17:47:16 +04:00
|
|
|
|
|
|
|
BX_NEXT_INSTR(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
BX_INSF_TYPE BX_CPP_AttrRegparmN(1) BX_CPU_C::RORX_GdEdIbR(bxInstruction_c *i)
|
|
|
|
{
|
2012-08-05 17:52:40 +04:00
|
|
|
Bit32u op1_32 = BX_READ_32BIT_REG(i->src());
|
2011-08-27 17:47:16 +04:00
|
|
|
|
|
|
|
unsigned count = i->Ib() & 0x1f;
|
|
|
|
if (count) {
|
|
|
|
op1_32 = (op1_32 >> count) | (op1_32 << (32 - count));
|
|
|
|
}
|
|
|
|
|
2012-08-05 17:52:40 +04:00
|
|
|
BX_WRITE_32BIT_REGZ(i->dst(), op1_32);
|
2011-08-27 17:47:16 +04:00
|
|
|
|
|
|
|
BX_NEXT_INSTR(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
BX_INSF_TYPE BX_CPP_AttrRegparmN(1) BX_CPU_C::SHRX_GdEdBdR(bxInstruction_c *i)
|
|
|
|
{
|
2012-08-05 17:52:40 +04:00
|
|
|
Bit32u op1_32 = BX_READ_32BIT_REG(i->src1());
|
2011-08-27 17:47:16 +04:00
|
|
|
|
2012-08-05 17:52:40 +04:00
|
|
|
unsigned count = BX_READ_32BIT_REG(i->src2()) & 0x1f;
|
2011-08-27 17:47:16 +04:00
|
|
|
if (count)
|
|
|
|
op1_32 >>= count;
|
|
|
|
|
2012-08-05 17:52:40 +04:00
|
|
|
BX_WRITE_32BIT_REGZ(i->dst(), op1_32);
|
2011-08-27 17:47:16 +04:00
|
|
|
|
|
|
|
BX_NEXT_INSTR(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
BX_INSF_TYPE BX_CPP_AttrRegparmN(1) BX_CPU_C::SARX_GdEdBdR(bxInstruction_c *i)
|
|
|
|
{
|
2012-08-05 17:52:40 +04:00
|
|
|
Bit32u op1_32 = BX_READ_32BIT_REG(i->src1());
|
2011-08-27 17:47:16 +04:00
|
|
|
|
2012-08-05 17:52:40 +04:00
|
|
|
unsigned count = BX_READ_32BIT_REG(i->src2()) & 0x1f;
|
2011-08-27 17:47:16 +04:00
|
|
|
if (count) {
|
|
|
|
/* count < 32, since only lower 5 bits used */
|
|
|
|
op1_32 = ((Bit32s) op1_32) >> count;
|
|
|
|
}
|
|
|
|
|
2012-08-05 17:52:40 +04:00
|
|
|
BX_WRITE_32BIT_REGZ(i->dst(), op1_32);
|
2011-08-27 17:47:16 +04:00
|
|
|
|
|
|
|
BX_NEXT_INSTR(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
BX_INSF_TYPE BX_CPP_AttrRegparmN(1) BX_CPU_C::SHLX_GdEdBdR(bxInstruction_c *i)
|
|
|
|
{
|
2012-08-05 17:52:40 +04:00
|
|
|
Bit32u op1_32 = BX_READ_32BIT_REG(i->src1());
|
2011-08-27 17:47:16 +04:00
|
|
|
|
2012-08-05 17:52:40 +04:00
|
|
|
unsigned count = BX_READ_32BIT_REG(i->src2()) & 0x1f;
|
2011-08-27 17:47:16 +04:00
|
|
|
if (count)
|
|
|
|
op1_32 <<= count;
|
|
|
|
|
2012-08-05 17:52:40 +04:00
|
|
|
BX_WRITE_32BIT_REGZ(i->dst(), op1_32);
|
2011-08-27 17:47:16 +04:00
|
|
|
|
|
|
|
BX_NEXT_INSTR(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
BX_INSF_TYPE BX_CPP_AttrRegparmN(1) BX_CPU_C::BEXTR_GdEdBdR(bxInstruction_c *i)
|
|
|
|
{
|
2012-08-05 17:52:40 +04:00
|
|
|
Bit16u control = BX_READ_16BIT_REG(i->src2());
|
2011-08-27 17:47:16 +04:00
|
|
|
unsigned start = control & 0xff;
|
|
|
|
unsigned len = control >> 8;
|
|
|
|
Bit32u op1_32 = 0;
|
|
|
|
|
|
|
|
if (start < 32 && len > 0) {
|
2012-08-05 17:52:40 +04:00
|
|
|
op1_32 = BX_READ_32BIT_REG(i->src1());
|
2011-08-27 17:47:16 +04:00
|
|
|
op1_32 >>= start;
|
|
|
|
|
|
|
|
if (len < 32) {
|
|
|
|
Bit32u extract_mask = (1 << len) - 1;
|
|
|
|
op1_32 &= extract_mask;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-29 23:50:26 +04:00
|
|
|
SET_FLAGS_OSZAPC_LOGIC_32(op1_32);
|
2011-08-27 17:47:16 +04:00
|
|
|
|
2012-08-05 17:52:40 +04:00
|
|
|
BX_WRITE_32BIT_REGZ(i->dst(), op1_32);
|
2011-08-27 17:47:16 +04:00
|
|
|
|
|
|
|
BX_NEXT_INSTR(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
BX_INSF_TYPE BX_CPP_AttrRegparmN(1) BX_CPU_C::BZHI_GdEdBdR(bxInstruction_c *i)
|
|
|
|
{
|
2012-08-05 17:52:40 +04:00
|
|
|
unsigned control = BX_READ_16BIT_REG(i->src1()) & 0xff;
|
2011-08-27 17:47:16 +04:00
|
|
|
bx_bool tmpCF = 0;
|
2012-08-05 17:52:40 +04:00
|
|
|
Bit32u op1_32 = BX_READ_32BIT_REG(i->src2());
|
2011-08-27 17:47:16 +04:00
|
|
|
|
|
|
|
if (control < 32) {
|
|
|
|
Bit32u mask = (1 << control) - 1;
|
|
|
|
op1_32 &= mask;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
tmpCF = 1;
|
|
|
|
}
|
|
|
|
|
2011-11-27 17:23:26 +04:00
|
|
|
SET_FLAGS_OSZAxC_LOGIC_32(op1_32); // keep PF unchanged
|
2011-08-27 17:47:16 +04:00
|
|
|
set_CF(tmpCF);
|
|
|
|
|
2012-08-05 17:52:40 +04:00
|
|
|
BX_WRITE_32BIT_REGZ(i->dst(), op1_32);
|
2011-08-27 17:47:16 +04:00
|
|
|
|
|
|
|
BX_NEXT_INSTR(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
BX_INSF_TYPE BX_CPP_AttrRegparmN(1) BX_CPU_C::PEXT_GdEdBdR(bxInstruction_c *i)
|
|
|
|
{
|
2012-08-05 17:52:40 +04:00
|
|
|
Bit32u op1_32 = BX_READ_32BIT_REG(i->src1());
|
|
|
|
Bit32u op2_32 = BX_READ_32BIT_REG(i->src2()), result_32 = 0;
|
2011-08-27 17:47:16 +04:00
|
|
|
|
|
|
|
Bit32u wr_mask = 0x1;
|
|
|
|
|
|
|
|
for (; op2_32 != 0; op2_32 >>= 1)
|
|
|
|
{
|
|
|
|
if (op2_32 & 0x1) {
|
|
|
|
if (op1_32 & 0x1) result_32 |= wr_mask;
|
|
|
|
wr_mask <<= 1;
|
|
|
|
}
|
|
|
|
op1_32 >>= 1;
|
|
|
|
}
|
|
|
|
|
2012-08-05 17:52:40 +04:00
|
|
|
BX_WRITE_32BIT_REGZ(i->dst(), result_32);
|
2011-08-27 17:47:16 +04:00
|
|
|
|
|
|
|
BX_NEXT_INSTR(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
BX_INSF_TYPE BX_CPP_AttrRegparmN(1) BX_CPU_C::PDEP_GdEdBdR(bxInstruction_c *i)
|
|
|
|
{
|
2012-08-05 17:52:40 +04:00
|
|
|
Bit32u op1_32 = BX_READ_32BIT_REG(i->src1());
|
|
|
|
Bit32u op2_32 = BX_READ_32BIT_REG(i->src2()), result_32 = 0;
|
2011-08-27 17:47:16 +04:00
|
|
|
|
|
|
|
Bit32u wr_mask = 0x1;
|
|
|
|
|
|
|
|
for (; op2_32 != 0; op2_32 >>= 1)
|
|
|
|
{
|
|
|
|
if (op2_32 & 0x1) {
|
|
|
|
if (op1_32 & 0x1) result_32 |= wr_mask;
|
|
|
|
op1_32 >>= 1;
|
|
|
|
}
|
|
|
|
wr_mask <<= 1;
|
|
|
|
}
|
|
|
|
|
2012-08-05 17:52:40 +04:00
|
|
|
BX_WRITE_32BIT_REGZ(i->dst(), result_32);
|
2011-08-27 17:47:16 +04:00
|
|
|
|
|
|
|
BX_NEXT_INSTR(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
2012-07-12 18:51:54 +04:00
|
|
|
|
|
|
|
BX_INSF_TYPE BX_CPP_AttrRegparmN(1) BX_CPU_C::ADCX_GdEdR(bxInstruction_c *i)
|
|
|
|
{
|
2012-08-05 17:52:40 +04:00
|
|
|
Bit32u op1_32 = BX_READ_32BIT_REG(i->dst());
|
|
|
|
Bit32u op2_32 = BX_READ_32BIT_REG(i->src());
|
2012-07-12 18:51:54 +04:00
|
|
|
Bit32u sum_32 = op1_32 + op2_32 + getB_CF();
|
|
|
|
|
2012-08-05 17:52:40 +04:00
|
|
|
BX_WRITE_32BIT_REGZ(i->dst(), sum_32);
|
2012-07-12 18:51:54 +04:00
|
|
|
|
|
|
|
Bit32u carry_out = ADD_COUT_VEC(op1_32, op2_32, sum_32);
|
|
|
|
set_CF(carry_out >> 31);
|
|
|
|
|
|
|
|
BX_NEXT_INSTR(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
BX_INSF_TYPE BX_CPP_AttrRegparmN(1) BX_CPU_C::ADOX_GdEdR(bxInstruction_c *i)
|
|
|
|
{
|
2012-08-05 17:52:40 +04:00
|
|
|
Bit32u op1_32 = BX_READ_32BIT_REG(i->dst());
|
|
|
|
Bit32u op2_32 = BX_READ_32BIT_REG(i->src());
|
2012-07-12 18:51:54 +04:00
|
|
|
Bit32u sum_32 = op1_32 + op2_32 + getB_OF();
|
|
|
|
|
2012-08-05 17:52:40 +04:00
|
|
|
BX_WRITE_32BIT_REGZ(i->dst(), sum_32);
|
2012-07-12 18:51:54 +04:00
|
|
|
|
|
|
|
Bit32u overflow = GET_ADD_OVERFLOW(op1_32, op2_32, sum_32, 0x80000000);
|
|
|
|
set_OF(!!overflow);
|
|
|
|
|
|
|
|
BX_NEXT_INSTR(i);
|
|
|
|
}
|