2 * Helpers for lazy condition code handling
4 * Copyright (c) 2003-2005 Fabrice Bellard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
23 static uint32_t compute_all_flags(CPUSPARCState *env)
25 return env->psr & PSR_ICC;
28 static uint32_t compute_C_flags(CPUSPARCState *env)
30 return env->psr & PSR_CARRY;
33 static inline uint32_t get_NZ_icc(int32_t dst)
46 static uint32_t compute_all_flags_xcc(CPUSPARCState *env)
48 return env->xcc & PSR_ICC;
51 static uint32_t compute_C_flags_xcc(CPUSPARCState *env)
53 return env->xcc & PSR_CARRY;
56 static inline uint32_t get_NZ_xcc(target_long dst)
69 static inline uint32_t get_V_div_icc(target_ulong src2)
79 static uint32_t compute_all_div(CPUSPARCState *env)
83 ret = get_NZ_icc(CC_DST);
84 ret |= get_V_div_icc(CC_SRC2);
88 static uint32_t compute_C_div(CPUSPARCState *env)
93 static inline uint32_t get_C_add_icc(uint32_t dst, uint32_t src1)
103 static inline uint32_t get_C_addx_icc(uint32_t dst, uint32_t src1,
108 if (((src1 & src2) | (~dst & (src1 | src2))) & (1U << 31)) {
114 static inline uint32_t get_V_add_icc(uint32_t dst, uint32_t src1,
119 if (((src1 ^ src2 ^ -1) & (src1 ^ dst)) & (1U << 31)) {
125 #ifdef TARGET_SPARC64
126 static inline uint32_t get_C_add_xcc(target_ulong dst, target_ulong src1)
136 static inline uint32_t get_C_addx_xcc(target_ulong dst, target_ulong src1,
141 if (((src1 & src2) | (~dst & (src1 | src2))) & (1ULL << 63)) {
147 static inline uint32_t get_V_add_xcc(target_ulong dst, target_ulong src1,
152 if (((src1 ^ src2 ^ -1) & (src1 ^ dst)) & (1ULL << 63)) {
158 static uint32_t compute_all_add_xcc(CPUSPARCState *env)
162 ret = get_NZ_xcc(CC_DST);
163 ret |= get_C_add_xcc(CC_DST, CC_SRC);
164 ret |= get_V_add_xcc(CC_DST, CC_SRC, CC_SRC2);
168 static uint32_t compute_C_add_xcc(CPUSPARCState *env)
170 return get_C_add_xcc(CC_DST, CC_SRC);
174 static uint32_t compute_all_add(CPUSPARCState *env)
178 ret = get_NZ_icc(CC_DST);
179 ret |= get_C_add_icc(CC_DST, CC_SRC);
180 ret |= get_V_add_icc(CC_DST, CC_SRC, CC_SRC2);
184 static uint32_t compute_C_add(CPUSPARCState *env)
186 return get_C_add_icc(CC_DST, CC_SRC);
189 #ifdef TARGET_SPARC64
190 static uint32_t compute_all_addx_xcc(CPUSPARCState *env)
194 ret = get_NZ_xcc(CC_DST);
195 ret |= get_C_addx_xcc(CC_DST, CC_SRC, CC_SRC2);
196 ret |= get_V_add_xcc(CC_DST, CC_SRC, CC_SRC2);
200 static uint32_t compute_C_addx_xcc(CPUSPARCState *env)
204 ret = get_C_addx_xcc(CC_DST, CC_SRC, CC_SRC2);
209 static uint32_t compute_all_addx(CPUSPARCState *env)
213 ret = get_NZ_icc(CC_DST);
214 ret |= get_C_addx_icc(CC_DST, CC_SRC, CC_SRC2);
215 ret |= get_V_add_icc(CC_DST, CC_SRC, CC_SRC2);
219 static uint32_t compute_C_addx(CPUSPARCState *env)
223 ret = get_C_addx_icc(CC_DST, CC_SRC, CC_SRC2);
227 static inline uint32_t get_V_tag_icc(target_ulong src1, target_ulong src2)
231 if ((src1 | src2) & 0x3) {
237 static uint32_t compute_all_tadd(CPUSPARCState *env)
241 ret = get_NZ_icc(CC_DST);
242 ret |= get_C_add_icc(CC_DST, CC_SRC);
243 ret |= get_V_add_icc(CC_DST, CC_SRC, CC_SRC2);
244 ret |= get_V_tag_icc(CC_SRC, CC_SRC2);
248 static uint32_t compute_all_taddtv(CPUSPARCState *env)
252 ret = get_NZ_icc(CC_DST);
253 ret |= get_C_add_icc(CC_DST, CC_SRC);
257 static inline uint32_t get_C_sub_icc(uint32_t src1, uint32_t src2)
267 static inline uint32_t get_C_subx_icc(uint32_t dst, uint32_t src1,
272 if (((~src1 & src2) | (dst & (~src1 | src2))) & (1U << 31)) {
278 static inline uint32_t get_V_sub_icc(uint32_t dst, uint32_t src1,
283 if (((src1 ^ src2) & (src1 ^ dst)) & (1U << 31)) {
290 #ifdef TARGET_SPARC64
291 static inline uint32_t get_C_sub_xcc(target_ulong src1, target_ulong src2)
301 static inline uint32_t get_C_subx_xcc(target_ulong dst, target_ulong src1,
306 if (((~src1 & src2) | (dst & (~src1 | src2))) & (1ULL << 63)) {
312 static inline uint32_t get_V_sub_xcc(target_ulong dst, target_ulong src1,
317 if (((src1 ^ src2) & (src1 ^ dst)) & (1ULL << 63)) {
323 static uint32_t compute_all_sub_xcc(CPUSPARCState *env)
327 ret = get_NZ_xcc(CC_DST);
328 ret |= get_C_sub_xcc(CC_SRC, CC_SRC2);
329 ret |= get_V_sub_xcc(CC_DST, CC_SRC, CC_SRC2);
333 static uint32_t compute_C_sub_xcc(CPUSPARCState *env)
335 return get_C_sub_xcc(CC_SRC, CC_SRC2);
339 static uint32_t compute_all_sub(CPUSPARCState *env)
343 ret = get_NZ_icc(CC_DST);
344 ret |= get_C_sub_icc(CC_SRC, CC_SRC2);
345 ret |= get_V_sub_icc(CC_DST, CC_SRC, CC_SRC2);
349 static uint32_t compute_C_sub(CPUSPARCState *env)
351 return get_C_sub_icc(CC_SRC, CC_SRC2);
354 #ifdef TARGET_SPARC64
355 static uint32_t compute_all_subx_xcc(CPUSPARCState *env)
359 ret = get_NZ_xcc(CC_DST);
360 ret |= get_C_subx_xcc(CC_DST, CC_SRC, CC_SRC2);
361 ret |= get_V_sub_xcc(CC_DST, CC_SRC, CC_SRC2);
365 static uint32_t compute_C_subx_xcc(CPUSPARCState *env)
369 ret = get_C_subx_xcc(CC_DST, CC_SRC, CC_SRC2);
374 static uint32_t compute_all_subx(CPUSPARCState *env)
378 ret = get_NZ_icc(CC_DST);
379 ret |= get_C_subx_icc(CC_DST, CC_SRC, CC_SRC2);
380 ret |= get_V_sub_icc(CC_DST, CC_SRC, CC_SRC2);
384 static uint32_t compute_C_subx(CPUSPARCState *env)
388 ret = get_C_subx_icc(CC_DST, CC_SRC, CC_SRC2);
392 static uint32_t compute_all_tsub(CPUSPARCState *env)
396 ret = get_NZ_icc(CC_DST);
397 ret |= get_C_sub_icc(CC_SRC, CC_SRC2);
398 ret |= get_V_sub_icc(CC_DST, CC_SRC, CC_SRC2);
399 ret |= get_V_tag_icc(CC_SRC, CC_SRC2);
403 static uint32_t compute_all_tsubtv(CPUSPARCState *env)
407 ret = get_NZ_icc(CC_DST);
408 ret |= get_C_sub_icc(CC_SRC, CC_SRC2);
412 static uint32_t compute_all_logic(CPUSPARCState *env)
414 return get_NZ_icc(CC_DST);
417 static uint32_t compute_C_logic(CPUSPARCState *env)
422 #ifdef TARGET_SPARC64
423 static uint32_t compute_all_logic_xcc(CPUSPARCState *env)
425 return get_NZ_xcc(CC_DST);
429 typedef struct CCTable {
430 uint32_t (*compute_all)(CPUSPARCState *env); /* return all the flags */
431 uint32_t (*compute_c)(CPUSPARCState *env); /* return the C flag */
434 static const CCTable icc_table[CC_OP_NB] = {
435 /* CC_OP_DYNAMIC should never happen */
436 [CC_OP_FLAGS] = { compute_all_flags, compute_C_flags },
437 [CC_OP_DIV] = { compute_all_div, compute_C_div },
438 [CC_OP_ADD] = { compute_all_add, compute_C_add },
439 [CC_OP_ADDX] = { compute_all_addx, compute_C_addx },
440 [CC_OP_TADD] = { compute_all_tadd, compute_C_add },
441 [CC_OP_TADDTV] = { compute_all_taddtv, compute_C_add },
442 [CC_OP_SUB] = { compute_all_sub, compute_C_sub },
443 [CC_OP_SUBX] = { compute_all_subx, compute_C_subx },
444 [CC_OP_TSUB] = { compute_all_tsub, compute_C_sub },
445 [CC_OP_TSUBTV] = { compute_all_tsubtv, compute_C_sub },
446 [CC_OP_LOGIC] = { compute_all_logic, compute_C_logic },
449 #ifdef TARGET_SPARC64
450 static const CCTable xcc_table[CC_OP_NB] = {
451 /* CC_OP_DYNAMIC should never happen */
452 [CC_OP_FLAGS] = { compute_all_flags_xcc, compute_C_flags_xcc },
453 [CC_OP_DIV] = { compute_all_logic_xcc, compute_C_logic },
454 [CC_OP_ADD] = { compute_all_add_xcc, compute_C_add_xcc },
455 [CC_OP_ADDX] = { compute_all_addx_xcc, compute_C_addx_xcc },
456 [CC_OP_TADD] = { compute_all_add_xcc, compute_C_add_xcc },
457 [CC_OP_TADDTV] = { compute_all_add_xcc, compute_C_add_xcc },
458 [CC_OP_SUB] = { compute_all_sub_xcc, compute_C_sub_xcc },
459 [CC_OP_SUBX] = { compute_all_subx_xcc, compute_C_subx_xcc },
460 [CC_OP_TSUB] = { compute_all_sub_xcc, compute_C_sub_xcc },
461 [CC_OP_TSUBTV] = { compute_all_sub_xcc, compute_C_sub_xcc },
462 [CC_OP_LOGIC] = { compute_all_logic_xcc, compute_C_logic },
466 void helper_compute_psr(CPUSPARCState *env)
470 new_psr = icc_table[CC_OP].compute_all(env);
472 #ifdef TARGET_SPARC64
473 new_psr = xcc_table[CC_OP].compute_all(env);
479 uint32_t helper_compute_C_icc(CPUSPARCState *env)
483 ret = icc_table[CC_OP].compute_c(env) >> PSR_CARRY_SHIFT;