- update sector count before calling write completion function (SF patch #2144692)
[bochs-mirror.git] / cpu / 3dnow.cc
blob50214b52fb1681d164ce508692644d4a965c5d71
1 /////////////////////////////////////////////////////////////////////////
2 // $Id: 3dnow.cc,v 1.26 2008/10/08 10:51:37 sshwarts Exp $
3 /////////////////////////////////////////////////////////////////////////
4 //
5 // Copyright (c) 2002 Stanislav Shwartsman
6 // Written by Stanislav Shwartsman [sshwarts at sourceforge net]
7 //
8 // This library is free software; you can redistribute it and/or
9 // modify it under the terms of the GNU Lesser General Public
10 // License as published by the Free Software Foundation; either
11 // version 2 of the License, or (at your option) any later version.
13 // This library is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 // Lesser General Public License for more details.
18 // You should have received a copy of the GNU Lesser General Public
19 // License along with this library; if not, write to the Free Software
20 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 /////////////////////////////////////////////////////////////////////////
24 #define NEED_CPU_REG_SHORTCUTS 1
25 #include "bochs.h"
26 #include "cpu.h"
27 #define LOG_THIS BX_CPU_THIS_PTR
29 #if BX_SUPPORT_3DNOW
31 BX_CPP_INLINE void prepare_softfloat_status_word(float_status_t &status, int rounding_mode)
33 status.float_exception_flags = 0; // clear exceptions before execution
34 status.float_nan_handling_mode = float_first_operand_nan;
35 status.float_rounding_mode = rounding_mode;
36 status.flush_underflow_to_zero = 0;
39 void BX_CPP_AttrRegparmN(1) BX_CPU_C::PFPNACC_PqQq(bxInstruction_c *i)
41 BX_PANIC(("PFPNACC_PqQq: 3DNow! instruction still not implemented"));
44 /* 0F 0F /r 0C */
45 void BX_CPP_AttrRegparmN(1) BX_CPU_C::PI2FW_PqQq(bxInstruction_c *i)
47 BxPackedMmxRegister result, op;
49 BX_CPU_THIS_PTR prepareMMX();
51 /* op is a register or memory reference */
52 if (i->modC0()) {
53 op = BX_READ_MMX_REG(i->rm());
55 else {
56 bx_address eaddr = BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
57 /* pointer, segment address pair */
58 MMXUQ(op) = read_virtual_qword(i->seg(), eaddr);
61 BX_CPU_THIS_PTR prepareFPU2MMX(); /* FPU2MMX transition */
63 float_status_t status_word;
64 prepare_softfloat_status_word(status_word, float_round_to_zero);
66 MMXUD0(result) =
67 int32_to_float32((Bit32s)(MMXSW0(op)), status_word);
68 MMXUD1(result) =
69 int32_to_float32((Bit32s)(MMXSW2(op)), status_word);
71 /* now write result back to destination */
72 BX_WRITE_MMX_REG(i->nnn(), result);
75 /* 0F 0F /r 0D */
76 void BX_CPP_AttrRegparmN(1) BX_CPU_C::PI2FD_PqQq(bxInstruction_c *i)
78 BxPackedMmxRegister result, op;
80 BX_CPU_THIS_PTR prepareMMX();
82 /* op is a register or memory reference */
83 if (i->modC0()) {
84 op = BX_READ_MMX_REG(i->rm());
86 else {
87 bx_address eaddr = BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
88 /* pointer, segment address pair */
89 MMXUQ(op) = read_virtual_qword(i->seg(), eaddr);
92 BX_CPU_THIS_PTR prepareFPU2MMX(); /* FPU2MMX transition */
94 float_status_t status_word;
95 prepare_softfloat_status_word(status_word, float_round_to_zero);
97 MMXUD0(result) =
98 int32_to_float32(MMXSD0(op), status_word);
99 MMXUD1(result) =
100 int32_to_float32(MMXSD1(op), status_word);
102 /* now write result back to destination */
103 BX_WRITE_MMX_REG(i->nnn(), result);
106 void BX_CPP_AttrRegparmN(1) BX_CPU_C::PF2IW_PqQq(bxInstruction_c *i)
108 BX_PANIC(("PF2IW_PqQq: 3DNow! instruction still not implemented"));
111 /* 0F 0F /r 1D */
112 void BX_CPP_AttrRegparmN(1) BX_CPU_C::PF2ID_PqQq(bxInstruction_c *i)
114 BxPackedMmxRegister result, op;
116 BX_CPU_THIS_PTR prepareMMX();
118 /* op is a register or memory reference */
119 if (i->modC0()) {
120 op = BX_READ_MMX_REG(i->rm());
122 else {
123 bx_address eaddr = BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
124 /* pointer, segment address pair */
125 MMXUQ(op) = read_virtual_qword(i->seg(), eaddr);
128 BX_CPU_THIS_PTR prepareFPU2MMX(); /* FPU2MMX transition */
130 float_status_t status_word;
131 prepare_softfloat_status_word(status_word, float_round_to_zero);
133 MMXSD0(result) =
134 float32_to_int32_round_to_zero(MMXUD0(op), status_word);
135 MMXSD1(result) =
136 float32_to_int32_round_to_zero(MMXUD1(op), status_word);
138 /* now write result back to destination */
139 BX_WRITE_MMX_REG(i->nnn(), result);
142 void BX_CPP_AttrRegparmN(1) BX_CPU_C::PFNACC_PqQq(bxInstruction_c *i)
144 BX_PANIC(("PFNACC_PqQq: 3DNow! instruction still not implemented"));
147 void BX_CPP_AttrRegparmN(1) BX_CPU_C::PFCMPGE_PqQq(bxInstruction_c *i)
149 BX_PANIC(("PFCMPGE_PqQq: 3DNow! instruction still not implemented"));
152 void BX_CPP_AttrRegparmN(1) BX_CPU_C::PFMIN_PqQq(bxInstruction_c *i)
154 BX_PANIC(("PFMIN_PqQq: 3DNow! instruction still not implemented"));
157 void BX_CPP_AttrRegparmN(1) BX_CPU_C::PFRCP_PqQq(bxInstruction_c *i)
159 BX_PANIC(("PFRCP_PqQq: 3DNow! instruction still not implemented"));
162 void BX_CPP_AttrRegparmN(1) BX_CPU_C::PFRSQRT_PqQq(bxInstruction_c *i)
164 BX_PANIC(("PFRSQRT_PqQq: 3DNow! instruction still not implemented"));
167 void BX_CPP_AttrRegparmN(1) BX_CPU_C::PFSUB_PqQq(bxInstruction_c *i)
169 BX_PANIC(("PFSUB_PqQq: 3DNow! instruction still not implemented"));
172 void BX_CPP_AttrRegparmN(1) BX_CPU_C::PFADD_PqQq(bxInstruction_c *i)
174 BX_PANIC(("PFADD_PqQq: 3DNow! instruction still not implemented"));
177 void BX_CPP_AttrRegparmN(1) BX_CPU_C::PFCMPGT_PqQq(bxInstruction_c *i)
179 BX_PANIC(("PFCMPGT_PqQq: 3DNow! instruction still not implemented"));
182 void BX_CPP_AttrRegparmN(1) BX_CPU_C::PFMAX_PqQq(bxInstruction_c *i)
184 BX_PANIC(("PFMAX_PqQq: 3DNow! instruction still not implemented"));
187 void BX_CPP_AttrRegparmN(1) BX_CPU_C::PFRCPIT1_PqQq(bxInstruction_c *i)
189 BX_PANIC(("PFRCPIT1_PqQq: 3DNow! instruction still not implemented"));
192 void BX_CPP_AttrRegparmN(1) BX_CPU_C::PFRSQIT1_PqQq(bxInstruction_c *i)
194 BX_PANIC(("PFRSQIT1_PqQq: 3DNow! instruction still not implemented"));
197 void BX_CPP_AttrRegparmN(1) BX_CPU_C::PFSUBR_PqQq(bxInstruction_c *i)
199 BX_PANIC(("PFSUBR_PqQq: 3DNow! instruction still not implemented"));
202 void BX_CPP_AttrRegparmN(1) BX_CPU_C::PFACC_PqQq(bxInstruction_c *i)
204 BX_PANIC(("PFACC_PqQq: 3DNow! instruction still not implemented"));
207 void BX_CPP_AttrRegparmN(1) BX_CPU_C::PFCMPEQ_PqQq(bxInstruction_c *i)
209 BX_PANIC(("PFCMPEQ_PqQq: 3DNow! instruction still not implemented"));
212 void BX_CPP_AttrRegparmN(1) BX_CPU_C::PFMUL_PqQq(bxInstruction_c *i)
214 BX_PANIC(("PFMUL_PqQq: 3DNow! instruction still not implemented"));
217 void BX_CPP_AttrRegparmN(1) BX_CPU_C::PFRCPIT2_PqQq(bxInstruction_c *i)
219 BX_PANIC(("PFRCPIT2_PqQq: 3DNow! instruction still not implemented"));
222 /* 0F 0F /r B7 */
223 void BX_CPP_AttrRegparmN(1) BX_CPU_C::PMULHRW_PqQq(bxInstruction_c *i)
225 BX_CPU_THIS_PTR prepareMMX();
227 BxPackedMmxRegister op1 = BX_READ_MMX_REG(i->nnn()), op2, result;
229 /* op2 is a register or memory reference */
230 if (i->modC0()) {
231 op2 = BX_READ_MMX_REG(i->rm());
233 else {
234 bx_address eaddr = BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
235 /* pointer, segment address pair */
236 MMXUQ(op2) = read_virtual_qword(i->seg(), eaddr);
239 BX_CPU_THIS_PTR prepareFPU2MMX(); /* FPU2MMX transition */
241 Bit32s product1 = Bit32s(MMXSW0(op1)) * Bit32s(MMXSW0(op2)) + 0x8000;
242 Bit32s product2 = Bit32s(MMXSW1(op1)) * Bit32s(MMXSW1(op2)) + 0x8000;
243 Bit32s product3 = Bit32s(MMXSW2(op1)) * Bit32s(MMXSW2(op2)) + 0x8000;
244 Bit32s product4 = Bit32s(MMXSW3(op1)) * Bit32s(MMXSW3(op2)) + 0x8000;
246 MMXUW0(result) = Bit16u(product1 >> 16);
247 MMXUW1(result) = Bit16u(product2 >> 16);
248 MMXUW2(result) = Bit16u(product3 >> 16);
249 MMXUW3(result) = Bit16u(product4 >> 16);
251 /* now write result back to destination */
252 BX_WRITE_MMX_REG(i->nnn(), result);
255 /* 0F 0F /r BB */
256 void BX_CPP_AttrRegparmN(1) BX_CPU_C::PSWAPD_PqQq(bxInstruction_c *i)
258 BX_CPU_THIS_PTR prepareMMX();
260 BxPackedMmxRegister result, op;
262 /* op is a register or memory reference */
263 if (i->modC0()) {
264 op = BX_READ_MMX_REG(i->rm());
266 else {
267 bx_address eaddr = BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
268 /* pointer, segment address pair */
269 MMXUQ(op) = read_virtual_qword(i->seg(), eaddr);
272 BX_CPU_THIS_PTR prepareFPU2MMX(); /* FPU2MMX transition */
274 MMXUD0(result) = MMXUD1(op);
275 MMXUD1(result) = MMXUD0(op);
277 /* now write result back to destination */
278 BX_WRITE_MMX_REG(i->nnn(), result);
281 #endif