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/>.
20 #include "qemu/osdep.h"
22 #include "exec/helper-proto.h"
24 static uint32_t compute_all_flags(CPUSPARCState
*env
)
26 return env
->psr
& PSR_ICC
;
29 static uint32_t compute_C_flags(CPUSPARCState
*env
)
31 return env
->psr
& PSR_CARRY
;
34 static inline uint32_t get_NZ_icc(int32_t dst
)
47 static uint32_t compute_all_flags_xcc(CPUSPARCState
*env
)
49 return env
->xcc
& PSR_ICC
;
52 static uint32_t compute_C_flags_xcc(CPUSPARCState
*env
)
54 return env
->xcc
& PSR_CARRY
;
57 static inline uint32_t get_NZ_xcc(target_long dst
)
70 static inline uint32_t get_V_div_icc(target_ulong src2
)
80 static uint32_t compute_all_div(CPUSPARCState
*env
)
84 ret
= get_NZ_icc(CC_DST
);
85 ret
|= get_V_div_icc(CC_SRC2
);
89 static uint32_t compute_C_div(CPUSPARCState
*env
)
94 static inline uint32_t get_C_add_icc(uint32_t dst
, uint32_t src1
)
104 static inline uint32_t get_C_addx_icc(uint32_t dst
, uint32_t src1
,
109 if (((src1
& src2
) | (~dst
& (src1
| src2
))) & (1U << 31)) {
115 static inline uint32_t get_V_add_icc(uint32_t dst
, uint32_t src1
,
120 if (((src1
^ src2
^ -1) & (src1
^ dst
)) & (1U << 31)) {
126 #ifdef TARGET_SPARC64
127 static inline uint32_t get_C_add_xcc(target_ulong dst
, target_ulong src1
)
137 static inline uint32_t get_C_addx_xcc(target_ulong dst
, target_ulong src1
,
142 if (((src1
& src2
) | (~dst
& (src1
| src2
))) & (1ULL << 63)) {
148 static inline uint32_t get_V_add_xcc(target_ulong dst
, target_ulong src1
,
153 if (((src1
^ src2
^ -1) & (src1
^ dst
)) & (1ULL << 63)) {
159 static uint32_t compute_all_add_xcc(CPUSPARCState
*env
)
163 ret
= get_NZ_xcc(CC_DST
);
164 ret
|= get_C_add_xcc(CC_DST
, CC_SRC
);
165 ret
|= get_V_add_xcc(CC_DST
, CC_SRC
, CC_SRC2
);
169 static uint32_t compute_C_add_xcc(CPUSPARCState
*env
)
171 return get_C_add_xcc(CC_DST
, CC_SRC
);
175 static uint32_t compute_all_add(CPUSPARCState
*env
)
179 ret
= get_NZ_icc(CC_DST
);
180 ret
|= get_C_add_icc(CC_DST
, CC_SRC
);
181 ret
|= get_V_add_icc(CC_DST
, CC_SRC
, CC_SRC2
);
185 static uint32_t compute_C_add(CPUSPARCState
*env
)
187 return get_C_add_icc(CC_DST
, CC_SRC
);
190 #ifdef TARGET_SPARC64
191 static uint32_t compute_all_addx_xcc(CPUSPARCState
*env
)
195 ret
= get_NZ_xcc(CC_DST
);
196 ret
|= get_C_addx_xcc(CC_DST
, CC_SRC
, CC_SRC2
);
197 ret
|= get_V_add_xcc(CC_DST
, CC_SRC
, CC_SRC2
);
201 static uint32_t compute_C_addx_xcc(CPUSPARCState
*env
)
205 ret
= get_C_addx_xcc(CC_DST
, CC_SRC
, CC_SRC2
);
210 static uint32_t compute_all_addx(CPUSPARCState
*env
)
214 ret
= get_NZ_icc(CC_DST
);
215 ret
|= get_C_addx_icc(CC_DST
, CC_SRC
, CC_SRC2
);
216 ret
|= get_V_add_icc(CC_DST
, CC_SRC
, CC_SRC2
);
220 static uint32_t compute_C_addx(CPUSPARCState
*env
)
224 ret
= get_C_addx_icc(CC_DST
, CC_SRC
, CC_SRC2
);
228 static inline uint32_t get_V_tag_icc(target_ulong src1
, target_ulong src2
)
232 if ((src1
| src2
) & 0x3) {
238 static uint32_t compute_all_tadd(CPUSPARCState
*env
)
242 ret
= get_NZ_icc(CC_DST
);
243 ret
|= get_C_add_icc(CC_DST
, CC_SRC
);
244 ret
|= get_V_add_icc(CC_DST
, CC_SRC
, CC_SRC2
);
245 ret
|= get_V_tag_icc(CC_SRC
, CC_SRC2
);
249 static uint32_t compute_all_taddtv(CPUSPARCState
*env
)
253 ret
= get_NZ_icc(CC_DST
);
254 ret
|= get_C_add_icc(CC_DST
, CC_SRC
);
258 static inline uint32_t get_C_sub_icc(uint32_t src1
, uint32_t src2
)
268 static inline uint32_t get_C_subx_icc(uint32_t dst
, uint32_t src1
,
273 if (((~src1
& src2
) | (dst
& (~src1
| src2
))) & (1U << 31)) {
279 static inline uint32_t get_V_sub_icc(uint32_t dst
, uint32_t src1
,
284 if (((src1
^ src2
) & (src1
^ dst
)) & (1U << 31)) {
291 #ifdef TARGET_SPARC64
292 static inline uint32_t get_C_sub_xcc(target_ulong src1
, target_ulong src2
)
302 static inline uint32_t get_C_subx_xcc(target_ulong dst
, target_ulong src1
,
307 if (((~src1
& src2
) | (dst
& (~src1
| src2
))) & (1ULL << 63)) {
313 static inline uint32_t get_V_sub_xcc(target_ulong dst
, target_ulong src1
,
318 if (((src1
^ src2
) & (src1
^ dst
)) & (1ULL << 63)) {
324 static uint32_t compute_all_sub_xcc(CPUSPARCState
*env
)
328 ret
= get_NZ_xcc(CC_DST
);
329 ret
|= get_C_sub_xcc(CC_SRC
, CC_SRC2
);
330 ret
|= get_V_sub_xcc(CC_DST
, CC_SRC
, CC_SRC2
);
334 static uint32_t compute_C_sub_xcc(CPUSPARCState
*env
)
336 return get_C_sub_xcc(CC_SRC
, CC_SRC2
);
340 static uint32_t compute_all_sub(CPUSPARCState
*env
)
344 ret
= get_NZ_icc(CC_DST
);
345 ret
|= get_C_sub_icc(CC_SRC
, CC_SRC2
);
346 ret
|= get_V_sub_icc(CC_DST
, CC_SRC
, CC_SRC2
);
350 static uint32_t compute_C_sub(CPUSPARCState
*env
)
352 return get_C_sub_icc(CC_SRC
, CC_SRC2
);
355 #ifdef TARGET_SPARC64
356 static uint32_t compute_all_subx_xcc(CPUSPARCState
*env
)
360 ret
= get_NZ_xcc(CC_DST
);
361 ret
|= get_C_subx_xcc(CC_DST
, CC_SRC
, CC_SRC2
);
362 ret
|= get_V_sub_xcc(CC_DST
, CC_SRC
, CC_SRC2
);
366 static uint32_t compute_C_subx_xcc(CPUSPARCState
*env
)
370 ret
= get_C_subx_xcc(CC_DST
, CC_SRC
, CC_SRC2
);
375 static uint32_t compute_all_subx(CPUSPARCState
*env
)
379 ret
= get_NZ_icc(CC_DST
);
380 ret
|= get_C_subx_icc(CC_DST
, CC_SRC
, CC_SRC2
);
381 ret
|= get_V_sub_icc(CC_DST
, CC_SRC
, CC_SRC2
);
385 static uint32_t compute_C_subx(CPUSPARCState
*env
)
389 ret
= get_C_subx_icc(CC_DST
, CC_SRC
, CC_SRC2
);
393 static uint32_t compute_all_tsub(CPUSPARCState
*env
)
397 ret
= get_NZ_icc(CC_DST
);
398 ret
|= get_C_sub_icc(CC_SRC
, CC_SRC2
);
399 ret
|= get_V_sub_icc(CC_DST
, CC_SRC
, CC_SRC2
);
400 ret
|= get_V_tag_icc(CC_SRC
, CC_SRC2
);
404 static uint32_t compute_all_tsubtv(CPUSPARCState
*env
)
408 ret
= get_NZ_icc(CC_DST
);
409 ret
|= get_C_sub_icc(CC_SRC
, CC_SRC2
);
413 static uint32_t compute_all_logic(CPUSPARCState
*env
)
415 return get_NZ_icc(CC_DST
);
418 static uint32_t compute_C_logic(CPUSPARCState
*env
)
423 #ifdef TARGET_SPARC64
424 static uint32_t compute_all_logic_xcc(CPUSPARCState
*env
)
426 return get_NZ_xcc(CC_DST
);
430 typedef struct CCTable
{
431 uint32_t (*compute_all
)(CPUSPARCState
*env
); /* return all the flags */
432 uint32_t (*compute_c
)(CPUSPARCState
*env
); /* return the C flag */
435 static const CCTable icc_table
[CC_OP_NB
] = {
436 /* CC_OP_DYNAMIC should never happen */
437 [CC_OP_FLAGS
] = { compute_all_flags
, compute_C_flags
},
438 [CC_OP_DIV
] = { compute_all_div
, compute_C_div
},
439 [CC_OP_ADD
] = { compute_all_add
, compute_C_add
},
440 [CC_OP_ADDX
] = { compute_all_addx
, compute_C_addx
},
441 [CC_OP_TADD
] = { compute_all_tadd
, compute_C_add
},
442 [CC_OP_TADDTV
] = { compute_all_taddtv
, compute_C_add
},
443 [CC_OP_SUB
] = { compute_all_sub
, compute_C_sub
},
444 [CC_OP_SUBX
] = { compute_all_subx
, compute_C_subx
},
445 [CC_OP_TSUB
] = { compute_all_tsub
, compute_C_sub
},
446 [CC_OP_TSUBTV
] = { compute_all_tsubtv
, compute_C_sub
},
447 [CC_OP_LOGIC
] = { compute_all_logic
, compute_C_logic
},
450 #ifdef TARGET_SPARC64
451 static const CCTable xcc_table
[CC_OP_NB
] = {
452 /* CC_OP_DYNAMIC should never happen */
453 [CC_OP_FLAGS
] = { compute_all_flags_xcc
, compute_C_flags_xcc
},
454 [CC_OP_DIV
] = { compute_all_logic_xcc
, compute_C_logic
},
455 [CC_OP_ADD
] = { compute_all_add_xcc
, compute_C_add_xcc
},
456 [CC_OP_ADDX
] = { compute_all_addx_xcc
, compute_C_addx_xcc
},
457 [CC_OP_TADD
] = { compute_all_add_xcc
, compute_C_add_xcc
},
458 [CC_OP_TADDTV
] = { compute_all_add_xcc
, compute_C_add_xcc
},
459 [CC_OP_SUB
] = { compute_all_sub_xcc
, compute_C_sub_xcc
},
460 [CC_OP_SUBX
] = { compute_all_subx_xcc
, compute_C_subx_xcc
},
461 [CC_OP_TSUB
] = { compute_all_sub_xcc
, compute_C_sub_xcc
},
462 [CC_OP_TSUBTV
] = { compute_all_sub_xcc
, compute_C_sub_xcc
},
463 [CC_OP_LOGIC
] = { compute_all_logic_xcc
, compute_C_logic
},
467 void helper_compute_psr(CPUSPARCState
*env
)
471 new_psr
= icc_table
[CC_OP
].compute_all(env
);
473 #ifdef TARGET_SPARC64
474 new_psr
= xcc_table
[CC_OP
].compute_all(env
);
480 uint32_t helper_compute_C_icc(CPUSPARCState
*env
)
484 ret
= icc_table
[CC_OP
].compute_c(env
) >> PSR_CARRY_SHIFT
;