Version:
~
[ SVN-2014-01-05 ] ~
[ 2.6.2 ] ~
** Warning: Cannot open xref database.
1 /////////////////////////////////////////////////////////////////////////
2 // $Id: lazy_flags.h 11405 2012-09-06 19:49:14Z sshwarts $
3 /////////////////////////////////////////////////////////////////////////
4 //
5 // Copyright (C) 2001-2011 The Bochs Project
6 //
7 // This library is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU Lesser General Public
9 // License as published by the Free Software Foundation; either
10 // version 2 of the License, or (at your option) any later version.
11 //
12 // This library is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 // Lesser General Public License for more details.
16 //
17 // You should have received a copy of the GNU Lesser General Public
18 // License along with this library; if not, write to the Free Software
19 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 //
21 /////////////////////////////////////////////////////////////////////////
22
23 #ifndef BX_LAZY_FLAGS_DEF
24 #define BX_LAZY_FLAGS_DEF
25
26 #if BX_SUPPORT_X86_64
27 #define BX_LF_SIGN_BIT 63
28 #else
29 #define BX_LF_SIGN_BIT 31
30 #endif
31
32 typedef struct {
33 bx_address result;
34 bx_address auxbits;
35 } bx_lf_flags_entry;
36
37 // These are the lazy flags bits in oszapc.auxbits which hold lazy state
38 // of zero flag, adjust flag, carry flag, and overflow flag.
39
40 #define LF_BIT_SD (0) /* lazy Sign Flag Delta */
41 #define LF_BIT_AF (3) /* lazy Adjust flag */
42 #define LF_BIT_PDB (8) /* lazy Parity Delta Byte (8 bits) */
43 #define LF_BIT_CF (31) /* lazy Carry Flag */
44 #define LF_BIT_PO (30) /* lazy Partial Overflow = CF ^ OF */
45
46 #define LF_MASK_SD (0x01 << LF_BIT_SD)
47 #define LF_MASK_AF (0x01 << LF_BIT_AF)
48 #define LF_MASK_PDB (0xFF << LF_BIT_PDB)
49 #define LF_MASK_CF (0x01 << LF_BIT_CF)
50 #define LF_MASK_PO (0x01 << LF_BIT_PO)
51
52 #define ADD_COUT_VEC(op1, op2, result) \
53 (((op1) & (op2)) | (((op1) | (op2)) & (~(result))))
54
55 #define SUB_COUT_VEC(op1, op2, result) \
56 (((~(op1)) & (op2)) | (((~(op1)) ^ (op2)) & (result)))
57
58 #define GET_ADD_OVERFLOW(op1, op2, result, mask) \
59 ((((op1) ^ (result)) & ((op2) ^ (result))) & (mask))
60
61 // *******************
62 // OSZAPC
63 // *******************
64
65 /* size, carries, result */
66 #define SET_FLAGS_OSZAPC_SIZE(size, lf_carries, lf_result) { \
67 bx_address temp = ((lf_carries) & (LF_MASK_AF)) | \
68 (((lf_carries) >> (size - 2)) << LF_BIT_PO); \
69 BX_CPU_THIS_PTR oszapc.result = (bx_address)(Bit##size##s)(lf_result); \
70 if ((size) == 32) temp = ((lf_carries) & ~(LF_MASK_PDB | LF_MASK_SD)); \
71 if ((size) == 16) temp = ((lf_carries) & (LF_MASK_AF)) | ((lf_carries) << 16); \
72 if ((size) == 8) temp = ((lf_carries) & (LF_MASK_AF)) | ((lf_carries) << 24); \
73 BX_CPU_THIS_PTR oszapc.auxbits = (bx_address)(Bit32u)temp; \
74 }
75
76 /* carries, result */
77 #define SET_FLAGS_OSZAPC_8(carries, result) \
78 SET_FLAGS_OSZAPC_SIZE(8, carries, result)
79 #define SET_FLAGS_OSZAPC_16(carries, result) \
80 SET_FLAGS_OSZAPC_SIZE(16, carries, result)
81 #define SET_FLAGS_OSZAPC_32(carries, result) \
82 SET_FLAGS_OSZAPC_SIZE(32, carries, result)
83 #if BX_SUPPORT_X86_64
84 #define SET_FLAGS_OSZAPC_64(carries, result) \
85 SET_FLAGS_OSZAPC_SIZE(64, carries, result)
86 #endif
87
88 /* result */
89 #define SET_FLAGS_OSZAPC_LOGIC_8(result_8) \
90 SET_FLAGS_OSZAPC_8(0, (result_8))
91 #define SET_FLAGS_OSZAPC_LOGIC_16(result_16) \
92 SET_FLAGS_OSZAPC_16(0, (result_16))
93 #define SET_FLAGS_OSZAPC_LOGIC_32(result_32) \
94 SET_FLAGS_OSZAPC_32(0, (result_32))
95 #if BX_SUPPORT_X86_64
96 #define SET_FLAGS_OSZAPC_LOGIC_64(result_64) \
97 SET_FLAGS_OSZAPC_64(BX_CONST64(0), (result_64))
98 #endif
99
100 /* op1, op2, result */
101 #define SET_FLAGS_OSZAPC_ADD_8(op1_8, op2_8, sum_8) \
102 SET_FLAGS_OSZAPC_8(ADD_COUT_VEC((op1_8), (op2_8), (sum_8)), (sum_8))
103 #define SET_FLAGS_OSZAPC_ADD_16(op1_16, op2_16, sum_16) \
104 SET_FLAGS_OSZAPC_16(ADD_COUT_VEC((op1_16), (op2_16), (sum_16)), (sum_16))
105 #define SET_FLAGS_OSZAPC_ADD_32(op1_32, op2_32, sum_32) \
106 SET_FLAGS_OSZAPC_32(ADD_COUT_VEC((op1_32), (op2_32), (sum_32)), (sum_32))
107 #if BX_SUPPORT_X86_64
108 #define SET_FLAGS_OSZAPC_ADD_64(op1_64, op2_64, sum_64) \
109 SET_FLAGS_OSZAPC_64(ADD_COUT_VEC((op1_64), (op2_64), (sum_64)), (sum_64))
110 #endif
111
112 /* op1, op2, result */
113 #define SET_FLAGS_OSZAPC_SUB_8(op1_8, op2_8, diff_8) \
114 SET_FLAGS_OSZAPC_8(SUB_COUT_VEC((op1_8), (op2_8), (diff_8)), (diff_8))
115 #define SET_FLAGS_OSZAPC_SUB_16(op1_16, op2_16, diff_16) \
116 SET_FLAGS_OSZAPC_16(SUB_COUT_VEC((op1_16), (op2_16), (diff_16)), (diff_16))
117 #define SET_FLAGS_OSZAPC_SUB_32(op1_32, op2_32, diff_32) \
118 SET_FLAGS_OSZAPC_32(SUB_COUT_VEC((op1_32), (op2_32), (diff_32)), (diff_32))
119 #if BX_SUPPORT_X86_64
120 #define SET_FLAGS_OSZAPC_SUB_64(op1_64, op2_64, diff_64) \
121 SET_FLAGS_OSZAPC_64(SUB_COUT_VEC((op1_64), (op2_64), (diff_64)), (diff_64))
122 #endif
123
124 // *******************
125 // OSZAP
126 // *******************
127
128 /* size, carries, result */
129 #define SET_FLAGS_OSZAP_SIZE(size, lf_carries, lf_result) { \
130 bx_address temp = ((lf_carries) & (LF_MASK_AF)) | \
131 (((lf_carries) >> (size - 2)) << LF_BIT_PO); \
132 if ((size) == 32) temp = ((lf_carries) & ~(LF_MASK_PDB | LF_MASK_SD)); \
133 if ((size) == 16) temp = ((lf_carries) & (LF_MASK_AF)) | ((lf_carries) << 16); \
134 if ((size) == 8) temp = ((lf_carries) & (LF_MASK_AF)) | ((lf_carries) << 24); \
135 BX_CPU_THIS_PTR oszapc.result = (bx_address)(Bit##size##s)(lf_result); \
136 bx_address delta_c = (BX_CPU_THIS_PTR oszapc.auxbits ^ temp) & LF_MASK_CF; \
137 delta_c ^= (delta_c >> 1); \
138 BX_CPU_THIS_PTR oszapc.auxbits = (bx_address)(Bit32u)(temp ^ delta_c); \
139 }
140
141 /* carries, result */
142 #define SET_FLAGS_OSZAP_8(carries, result) \
143 SET_FLAGS_OSZAP_SIZE(8, carries, result)
144 #define SET_FLAGS_OSZAP_16(carries, result) \
145 SET_FLAGS_OSZAP_SIZE(16, carries, result)
146 #define SET_FLAGS_OSZAP_32(carries, result) \
147 SET_FLAGS_OSZAP_SIZE(32, carries, result)
148 #if BX_SUPPORT_X86_64
149 #define SET_FLAGS_OSZAP_64(carries, result) \
150 SET_FLAGS_OSZAP_SIZE(64, carries, result)
151 #endif
152
153 /* op1, op2, result */
154 #define SET_FLAGS_OSZAP_ADD_8(op1_8, op2_8, sum_8) \
155 SET_FLAGS_OSZAP_8(ADD_COUT_VEC((op1_8), (op2_8), (sum_8)), (sum_8))
156 #define SET_FLAGS_OSZAP_ADD_16(op1_16, op2_16, sum_16) \
157 SET_FLAGS_OSZAP_16(ADD_COUT_VEC((op1_16), (op2_16), (sum_16)), (sum_16))
158 #define SET_FLAGS_OSZAP_ADD_32(op1_32, op2_32, sum_32) \
159 SET_FLAGS_OSZAP_32(ADD_COUT_VEC((op1_32), (op2_32), (sum_32)), (sum_32))
160 #if BX_SUPPORT_X86_64
161 #define SET_FLAGS_OSZAP_ADD_64(op1_64, op2_64, sum_64) \
162 SET_FLAGS_OSZAP_64(ADD_COUT_VEC((op1_64), (op2_64), (sum_64)), (sum_64))
163 #endif
164
165 /* op1, op2, result */
166 #define SET_FLAGS_OSZAP_SUB_8(op1_8, op2_8, diff_8) \
167 SET_FLAGS_OSZAP_8(SUB_COUT_VEC((op1_8), (op2_8), (diff_8)), (diff_8))
168 #define SET_FLAGS_OSZAP_SUB_16(op1_16, op2_16, diff_16) \
169 SET_FLAGS_OSZAP_16(SUB_COUT_VEC((op1_16), (op2_16), (diff_16)), (diff_16))
170 #define SET_FLAGS_OSZAP_SUB_32(op1_32, op2_32, diff_32) \
171 SET_FLAGS_OSZAP_32(SUB_COUT_VEC((op1_32), (op2_32), (diff_32)), (diff_32))
172 #if BX_SUPPORT_X86_64
173 #define SET_FLAGS_OSZAP_SUB_64(op1_64, op2_64, diff_64) \
174 SET_FLAGS_OSZAP_64(SUB_COUT_VEC((op1_64), (op2_64), (diff_64)), (diff_64))
175 #endif
176
177 // *******************
178 // OSZAxC
179 // *******************
180
181 /* size, carries, result */
182 #define SET_FLAGS_OSZAxC_LOGIC_SIZE(size, lf_result) { \
183 bx_bool saved_PF = getB_PF(); \
184 SET_FLAGS_OSZAPC_SIZE(size, (Bit##size##u)(0), lf_result); \
185 set_PF(saved_PF); \
186 }
187
188 /* result */
189 #define SET_FLAGS_OSZAxC_LOGIC_32(result_32) \
190 SET_FLAGS_OSZAxC_LOGIC_SIZE(32, (result_32))
191 #if BX_SUPPORT_X86_64
192 #define SET_FLAGS_OSZAxC_LOGIC_64(result_64) \
193 SET_FLAGS_OSZAxC_LOGIC_SIZE(64, (result_64))
194 #endif
195
196 #endif // BX_LAZY_FLAGS_DEF
197
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.