2 * Copyright (c) 2012-2014 Bastian Koppelmann C-Lab/University Paderborn
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
19 #include "qemu/host-utils.h"
20 #include "exec/helper-proto.h"
21 #include "exec/cpu_ldst.h"
23 /* Addressing mode helper */
25 static uint16_t reverse16(uint16_t val
)
27 uint8_t high
= (uint8_t)(val
>> 8);
28 uint8_t low
= (uint8_t)(val
& 0xff);
32 rl
= (uint16_t)((high
* 0x0202020202ULL
& 0x010884422010ULL
) % 1023);
33 rh
= (uint16_t)((low
* 0x0202020202ULL
& 0x010884422010ULL
) % 1023);
35 return (rh
<< 8) | rl
;
38 uint32_t helper_br_update(uint32_t reg
)
40 uint32_t index
= reg
& 0xffff;
41 uint32_t incr
= reg
>> 16;
42 uint32_t new_index
= reverse16(reverse16(index
) + reverse16(incr
));
43 return reg
- index
+ new_index
;
46 uint32_t helper_circ_update(uint32_t reg
, uint32_t off
)
48 uint32_t index
= reg
& 0xffff;
49 uint32_t length
= reg
>> 16;
50 int32_t new_index
= index
+ off
;
56 return reg
- index
+ new_index
;
59 static uint32_t ssov32(CPUTriCoreState
*env
, int64_t arg
)
62 int64_t max_pos
= INT32_MAX
;
63 int64_t max_neg
= INT32_MIN
;
65 env
->PSW_USB_V
= (1 << 31);
66 env
->PSW_USB_SV
= (1 << 31);
67 ret
= (target_ulong
)max_pos
;
70 env
->PSW_USB_V
= (1 << 31);
71 env
->PSW_USB_SV
= (1 << 31);
72 ret
= (target_ulong
)max_neg
;
75 ret
= (target_ulong
)arg
;
78 env
->PSW_USB_AV
= arg
^ arg
* 2u;
79 env
->PSW_USB_SAV
|= env
->PSW_USB_AV
;
83 static uint32_t suov32_pos(CPUTriCoreState
*env
, uint64_t arg
)
86 uint64_t max_pos
= UINT32_MAX
;
88 env
->PSW_USB_V
= (1 << 31);
89 env
->PSW_USB_SV
= (1 << 31);
90 ret
= (target_ulong
)max_pos
;
93 ret
= (target_ulong
)arg
;
95 env
->PSW_USB_AV
= arg
^ arg
* 2u;
96 env
->PSW_USB_SAV
|= env
->PSW_USB_AV
;
100 static uint32_t suov32_neg(CPUTriCoreState
*env
, int64_t arg
)
105 env
->PSW_USB_V
= (1 << 31);
106 env
->PSW_USB_SV
= (1 << 31);
110 ret
= (target_ulong
)arg
;
112 env
->PSW_USB_AV
= arg
^ arg
* 2u;
113 env
->PSW_USB_SAV
|= env
->PSW_USB_AV
;
117 static uint32_t ssov16(CPUTriCoreState
*env
, int32_t hw0
, int32_t hw1
)
119 int32_t max_pos
= INT16_MAX
;
120 int32_t max_neg
= INT16_MIN
;
124 av0
= hw0
^ hw0
* 2u;
126 env
->PSW_USB_V
= (1 << 31);
128 } else if (hw0
< max_neg
) {
129 env
->PSW_USB_V
= (1 << 31);
133 av1
= hw1
^ hw1
* 2u;
135 env
->PSW_USB_V
= (1 << 31);
137 } else if (hw1
< max_neg
) {
138 env
->PSW_USB_V
= (1 << 31);
142 env
->PSW_USB_SV
|= env
->PSW_USB_V
;
143 env
->PSW_USB_AV
= (av0
| av1
) << 16;
144 env
->PSW_USB_SAV
|= env
->PSW_USB_AV
;
145 return (hw0
& 0xffff) | (hw1
<< 16);
148 static uint32_t suov16(CPUTriCoreState
*env
, int32_t hw0
, int32_t hw1
)
150 int32_t max_pos
= UINT16_MAX
;
154 av0
= hw0
^ hw0
* 2u;
156 env
->PSW_USB_V
= (1 << 31);
158 } else if (hw0
< 0) {
159 env
->PSW_USB_V
= (1 << 31);
163 av1
= hw1
^ hw1
* 2u;
165 env
->PSW_USB_V
= (1 << 31);
167 } else if (hw1
< 0) {
168 env
->PSW_USB_V
= (1 << 31);
172 env
->PSW_USB_SV
|= env
->PSW_USB_V
;
173 env
->PSW_USB_AV
= (av0
| av1
) << 16;
174 env
->PSW_USB_SAV
|= env
->PSW_USB_AV
;
175 return (hw0
& 0xffff) | (hw1
<< 16);
178 target_ulong
helper_add_ssov(CPUTriCoreState
*env
, target_ulong r1
,
181 int64_t t1
= sextract64(r1
, 0, 32);
182 int64_t t2
= sextract64(r2
, 0, 32);
183 int64_t result
= t1
+ t2
;
184 return ssov32(env
, result
);
187 uint64_t helper_add64_ssov(CPUTriCoreState
*env
, uint64_t r1
, uint64_t r2
)
193 ovf
= (result
^ r1
) & ~(r1
^ r2
);
194 env
->PSW_USB_AV
= (result
^ result
* 2u) >> 32;
195 env
->PSW_USB_SAV
|= env
->PSW_USB_AV
;
197 env
->PSW_USB_V
= (1 << 31);
198 env
->PSW_USB_SV
= (1 << 31);
199 /* ext_ret > MAX_INT */
200 if ((int64_t)r1
>= 0) {
202 /* ext_ret < MIN_INT */
212 target_ulong
helper_add_h_ssov(CPUTriCoreState
*env
, target_ulong r1
,
215 int32_t ret_hw0
, ret_hw1
;
217 ret_hw0
= sextract32(r1
, 0, 16) + sextract32(r2
, 0, 16);
218 ret_hw1
= sextract32(r1
, 16, 16) + sextract32(r2
, 16, 16);
219 return ssov16(env
, ret_hw0
, ret_hw1
);
222 uint32_t helper_addr_h_ssov(CPUTriCoreState
*env
, uint64_t r1
, uint32_t r2_l
,
225 int64_t mul_res0
= sextract64(r1
, 0, 32);
226 int64_t mul_res1
= sextract64(r1
, 32, 32);
227 int64_t r2_low
= sextract64(r2_l
, 0, 32);
228 int64_t r2_high
= sextract64(r2_h
, 0, 32);
229 int64_t result0
, result1
;
235 result0
= r2_low
+ mul_res0
+ 0x8000;
236 result1
= r2_high
+ mul_res1
+ 0x8000;
239 avf0
= result0
^ avf0
;
241 avf1
= result1
^ avf1
;
243 if (result0
> INT32_MAX
) {
246 } else if (result0
< INT32_MIN
) {
251 if (result1
> INT32_MAX
) {
254 } else if (result1
< INT32_MIN
) {
259 env
->PSW_USB_V
= ovf0
| ovf1
;
260 env
->PSW_USB_SV
|= env
->PSW_USB_V
;
262 env
->PSW_USB_AV
= avf0
| avf1
;
263 env
->PSW_USB_SAV
|= env
->PSW_USB_AV
;
265 return (result1
& 0xffff0000ULL
) | ((result0
>> 16) & 0xffffULL
);
269 target_ulong
helper_add_suov(CPUTriCoreState
*env
, target_ulong r1
,
272 int64_t t1
= extract64(r1
, 0, 32);
273 int64_t t2
= extract64(r2
, 0, 32);
274 int64_t result
= t1
+ t2
;
275 return suov32_pos(env
, result
);
278 target_ulong
helper_add_h_suov(CPUTriCoreState
*env
, target_ulong r1
,
281 int32_t ret_hw0
, ret_hw1
;
283 ret_hw0
= extract32(r1
, 0, 16) + extract32(r2
, 0, 16);
284 ret_hw1
= extract32(r1
, 16, 16) + extract32(r2
, 16, 16);
285 return suov16(env
, ret_hw0
, ret_hw1
);
288 target_ulong
helper_sub_ssov(CPUTriCoreState
*env
, target_ulong r1
,
291 int64_t t1
= sextract64(r1
, 0, 32);
292 int64_t t2
= sextract64(r2
, 0, 32);
293 int64_t result
= t1
- t2
;
294 return ssov32(env
, result
);
297 target_ulong
helper_sub_h_ssov(CPUTriCoreState
*env
, target_ulong r1
,
300 int32_t ret_hw0
, ret_hw1
;
302 ret_hw0
= sextract32(r1
, 0, 16) - sextract32(r2
, 0, 16);
303 ret_hw1
= sextract32(r1
, 16, 16) - sextract32(r2
, 16, 16);
304 return ssov16(env
, ret_hw0
, ret_hw1
);
307 target_ulong
helper_sub_suov(CPUTriCoreState
*env
, target_ulong r1
,
310 int64_t t1
= extract64(r1
, 0, 32);
311 int64_t t2
= extract64(r2
, 0, 32);
312 int64_t result
= t1
- t2
;
313 return suov32_neg(env
, result
);
316 target_ulong
helper_sub_h_suov(CPUTriCoreState
*env
, target_ulong r1
,
319 int32_t ret_hw0
, ret_hw1
;
321 ret_hw0
= extract32(r1
, 0, 16) - extract32(r2
, 0, 16);
322 ret_hw1
= extract32(r1
, 16, 16) - extract32(r2
, 16, 16);
323 return suov16(env
, ret_hw0
, ret_hw1
);
326 target_ulong
helper_mul_ssov(CPUTriCoreState
*env
, target_ulong r1
,
329 int64_t t1
= sextract64(r1
, 0, 32);
330 int64_t t2
= sextract64(r2
, 0, 32);
331 int64_t result
= t1
* t2
;
332 return ssov32(env
, result
);
335 target_ulong
helper_mul_suov(CPUTriCoreState
*env
, target_ulong r1
,
338 int64_t t1
= extract64(r1
, 0, 32);
339 int64_t t2
= extract64(r2
, 0, 32);
340 int64_t result
= t1
* t2
;
342 return suov32_pos(env
, result
);
345 target_ulong
helper_sha_ssov(CPUTriCoreState
*env
, target_ulong r1
,
348 int64_t t1
= sextract64(r1
, 0, 32);
349 int32_t t2
= sextract64(r2
, 0, 6);
358 return ssov32(env
, result
);
361 uint32_t helper_abs_ssov(CPUTriCoreState
*env
, target_ulong r1
)
364 result
= ((int32_t)r1
>= 0) ? r1
: (0 - r1
);
365 return ssov32(env
, result
);
368 uint32_t helper_abs_h_ssov(CPUTriCoreState
*env
, target_ulong r1
)
370 int32_t ret_h0
, ret_h1
;
372 ret_h0
= sextract32(r1
, 0, 16);
373 ret_h0
= (ret_h0
>= 0) ? ret_h0
: (0 - ret_h0
);
375 ret_h1
= sextract32(r1
, 16, 16);
376 ret_h1
= (ret_h1
>= 0) ? ret_h1
: (0 - ret_h1
);
378 return ssov16(env
, ret_h0
, ret_h1
);
381 target_ulong
helper_absdif_ssov(CPUTriCoreState
*env
, target_ulong r1
,
384 int64_t t1
= sextract64(r1
, 0, 32);
385 int64_t t2
= sextract64(r2
, 0, 32);
393 return ssov32(env
, result
);
396 uint32_t helper_absdif_h_ssov(CPUTriCoreState
*env
, target_ulong r1
,
400 int32_t ret_h0
, ret_h1
;
402 t1
= sextract32(r1
, 0, 16);
403 t2
= sextract32(r2
, 0, 16);
410 t1
= sextract32(r1
, 16, 16);
411 t2
= sextract32(r2
, 16, 16);
418 return ssov16(env
, ret_h0
, ret_h1
);
421 target_ulong
helper_madd32_ssov(CPUTriCoreState
*env
, target_ulong r1
,
422 target_ulong r2
, target_ulong r3
)
424 int64_t t1
= sextract64(r1
, 0, 32);
425 int64_t t2
= sextract64(r2
, 0, 32);
426 int64_t t3
= sextract64(r3
, 0, 32);
429 result
= t2
+ (t1
* t3
);
430 return ssov32(env
, result
);
433 target_ulong
helper_madd32_suov(CPUTriCoreState
*env
, target_ulong r1
,
434 target_ulong r2
, target_ulong r3
)
436 uint64_t t1
= extract64(r1
, 0, 32);
437 uint64_t t2
= extract64(r2
, 0, 32);
438 uint64_t t3
= extract64(r3
, 0, 32);
441 result
= t2
+ (t1
* t3
);
442 return suov32_pos(env
, result
);
445 uint64_t helper_madd64_ssov(CPUTriCoreState
*env
, target_ulong r1
,
446 uint64_t r2
, target_ulong r3
)
449 int64_t t1
= sextract64(r1
, 0, 32);
450 int64_t t3
= sextract64(r3
, 0, 32);
455 ovf
= (ret
^ mul
) & ~(mul
^ r2
);
458 env
->PSW_USB_AV
= t1
^ t1
* 2u;
459 env
->PSW_USB_SAV
|= env
->PSW_USB_AV
;
461 if ((int64_t)ovf
< 0) {
462 env
->PSW_USB_V
= (1 << 31);
463 env
->PSW_USB_SV
= (1 << 31);
464 /* ext_ret > MAX_INT */
467 /* ext_ret < MIN_INT */
479 helper_madd32_q_add_ssov(CPUTriCoreState
*env
, uint64_t r1
, uint64_t r2
)
485 env
->PSW_USB_AV
= (result
^ result
* 2u);
486 env
->PSW_USB_SAV
|= env
->PSW_USB_AV
;
488 /* we do the saturation by hand, since we produce an overflow on the host
489 if the mul before was (0x80000000 * 0x80000000) << 1). If this is the
490 case, we flip the saturated value. */
491 if (r2
== 0x8000000000000000LL
) {
492 if (result
> 0x7fffffffLL
) {
493 env
->PSW_USB_V
= (1 << 31);
494 env
->PSW_USB_SV
= (1 << 31);
496 } else if (result
< -0x80000000LL
) {
497 env
->PSW_USB_V
= (1 << 31);
498 env
->PSW_USB_SV
= (1 << 31);
504 if (result
> 0x7fffffffLL
) {
505 env
->PSW_USB_V
= (1 << 31);
506 env
->PSW_USB_SV
= (1 << 31);
508 } else if (result
< -0x80000000LL
) {
509 env
->PSW_USB_V
= (1 << 31);
510 env
->PSW_USB_SV
= (1 << 31);
516 return (uint32_t)result
;
519 uint64_t helper_madd64_q_ssov(CPUTriCoreState
*env
, uint64_t r1
, uint32_t r2
,
520 uint32_t r3
, uint32_t n
)
522 int64_t t1
= (int64_t)r1
;
523 int64_t t2
= sextract64(r2
, 0, 32);
524 int64_t t3
= sextract64(r3
, 0, 32);
528 mul
= (t2
* t3
) << n
;
531 env
->PSW_USB_AV
= (result
^ result
* 2u) >> 32;
532 env
->PSW_USB_SAV
|= env
->PSW_USB_AV
;
534 ovf
= (result
^ mul
) & ~(mul
^ t1
);
535 /* we do the saturation by hand, since we produce an overflow on the host
536 if the mul was (0x80000000 * 0x80000000) << 1). If this is the
537 case, we flip the saturated value. */
538 if ((r2
== 0x80000000) && (r3
== 0x80000000) && (n
== 1)) {
540 env
->PSW_USB_V
= (1 << 31);
541 env
->PSW_USB_SV
= (1 << 31);
542 /* ext_ret > MAX_INT */
545 /* ext_ret < MIN_INT */
554 env
->PSW_USB_V
= (1 << 31);
555 env
->PSW_USB_SV
= (1 << 31);
556 /* ext_ret > MAX_INT */
559 /* ext_ret < MIN_INT */
567 return (uint64_t)result
;
570 uint32_t helper_maddr_q_ssov(CPUTriCoreState
*env
, uint32_t r1
, uint32_t r2
,
571 uint32_t r3
, uint32_t n
)
573 int64_t t1
= sextract64(r1
, 0, 32);
574 int64_t t2
= sextract64(r2
, 0, 32);
575 int64_t t3
= sextract64(r3
, 0, 32);
578 if ((t2
== -0x8000ll
) && (t3
== -0x8000ll
) && (n
== 1)) {
581 mul
= (t2
* t3
) << n
;
584 ret
= t1
+ mul
+ 0x8000;
586 env
->PSW_USB_AV
= ret
^ ret
* 2u;
587 env
->PSW_USB_SAV
|= env
->PSW_USB_AV
;
589 if (ret
> 0x7fffffffll
) {
590 env
->PSW_USB_V
= (1 << 31);
591 env
->PSW_USB_SV
|= env
->PSW_USB_V
;
593 } else if (ret
< -0x80000000ll
) {
594 env
->PSW_USB_V
= (1 << 31);
595 env
->PSW_USB_SV
|= env
->PSW_USB_V
;
600 return ret
& 0xffff0000ll
;
603 uint64_t helper_madd64_suov(CPUTriCoreState
*env
, target_ulong r1
,
604 uint64_t r2
, target_ulong r3
)
607 uint64_t t1
= extract64(r1
, 0, 32);
608 uint64_t t3
= extract64(r3
, 0, 32);
614 env
->PSW_USB_AV
= t1
^ t1
* 2u;
615 env
->PSW_USB_SAV
|= env
->PSW_USB_AV
;
618 env
->PSW_USB_V
= (1 << 31);
619 env
->PSW_USB_SV
= (1 << 31);
628 target_ulong
helper_msub32_ssov(CPUTriCoreState
*env
, target_ulong r1
,
629 target_ulong r2
, target_ulong r3
)
631 int64_t t1
= sextract64(r1
, 0, 32);
632 int64_t t2
= sextract64(r2
, 0, 32);
633 int64_t t3
= sextract64(r3
, 0, 32);
636 result
= t2
- (t1
* t3
);
637 return ssov32(env
, result
);
640 target_ulong
helper_msub32_suov(CPUTriCoreState
*env
, target_ulong r1
,
641 target_ulong r2
, target_ulong r3
)
643 uint64_t t1
= extract64(r1
, 0, 32);
644 uint64_t t2
= extract64(r2
, 0, 32);
645 uint64_t t3
= extract64(r3
, 0, 32);
652 env
->PSW_USB_AV
= result
^ result
* 2u;
653 env
->PSW_USB_SAV
|= env
->PSW_USB_AV
;
654 /* we calculate ovf by hand here, because the multiplication can overflow on
655 the host, which would give false results if we compare to less than
658 env
->PSW_USB_V
= (1 << 31);
659 env
->PSW_USB_SV
= (1 << 31);
667 uint64_t helper_msub64_ssov(CPUTriCoreState
*env
, target_ulong r1
,
668 uint64_t r2
, target_ulong r3
)
671 int64_t t1
= sextract64(r1
, 0, 32);
672 int64_t t3
= sextract64(r3
, 0, 32);
677 ovf
= (ret
^ r2
) & (mul
^ r2
);
680 env
->PSW_USB_AV
= t1
^ t1
* 2u;
681 env
->PSW_USB_SAV
|= env
->PSW_USB_AV
;
683 if ((int64_t)ovf
< 0) {
684 env
->PSW_USB_V
= (1 << 31);
685 env
->PSW_USB_SV
= (1 << 31);
686 /* ext_ret > MAX_INT */
689 /* ext_ret < MIN_INT */
699 uint64_t helper_msub64_suov(CPUTriCoreState
*env
, target_ulong r1
,
700 uint64_t r2
, target_ulong r3
)
703 uint64_t t1
= extract64(r1
, 0, 32);
704 uint64_t t3
= extract64(r3
, 0, 32);
710 env
->PSW_USB_AV
= t1
^ t1
* 2u;
711 env
->PSW_USB_SAV
|= env
->PSW_USB_AV
;
714 env
->PSW_USB_V
= (1 << 31);
715 env
->PSW_USB_SV
= (1 << 31);
724 uint32_t helper_abs_b(CPUTriCoreState
*env
, target_ulong arg
)
731 for (i
= 0; i
< 4; i
++) {
732 b
= sextract32(arg
, i
* 8, 8);
733 b
= (b
>= 0) ? b
: (0 - b
);
734 ovf
|= (b
> 0x7F) || (b
< -0x80);
736 ret
|= (b
& 0xff) << (i
* 8);
739 env
->PSW_USB_V
= ovf
<< 31;
740 env
->PSW_USB_SV
|= env
->PSW_USB_V
;
741 env
->PSW_USB_AV
= avf
<< 24;
742 env
->PSW_USB_SAV
|= env
->PSW_USB_AV
;
747 uint32_t helper_abs_h(CPUTriCoreState
*env
, target_ulong arg
)
754 for (i
= 0; i
< 2; i
++) {
755 h
= sextract32(arg
, i
* 16, 16);
756 h
= (h
>= 0) ? h
: (0 - h
);
757 ovf
|= (h
> 0x7FFF) || (h
< -0x8000);
759 ret
|= (h
& 0xffff) << (i
* 16);
762 env
->PSW_USB_V
= ovf
<< 31;
763 env
->PSW_USB_SV
|= env
->PSW_USB_V
;
764 env
->PSW_USB_AV
= avf
<< 16;
765 env
->PSW_USB_SAV
|= env
->PSW_USB_AV
;
770 uint32_t helper_absdif_b(CPUTriCoreState
*env
, target_ulong r1
, target_ulong r2
)
778 for (i
= 0; i
< 4; i
++) {
779 extr_r2
= sextract32(r2
, i
* 8, 8);
780 b
= sextract32(r1
, i
* 8, 8);
781 b
= (b
> extr_r2
) ? (b
- extr_r2
) : (extr_r2
- b
);
782 ovf
|= (b
> 0x7F) || (b
< -0x80);
784 ret
|= (b
& 0xff) << (i
* 8);
787 env
->PSW_USB_V
= ovf
<< 31;
788 env
->PSW_USB_SV
|= env
->PSW_USB_V
;
789 env
->PSW_USB_AV
= avf
<< 24;
790 env
->PSW_USB_SAV
|= env
->PSW_USB_AV
;
794 uint32_t helper_absdif_h(CPUTriCoreState
*env
, target_ulong r1
, target_ulong r2
)
802 for (i
= 0; i
< 2; i
++) {
803 extr_r2
= sextract32(r2
, i
* 16, 16);
804 h
= sextract32(r1
, i
* 16, 16);
805 h
= (h
> extr_r2
) ? (h
- extr_r2
) : (extr_r2
- h
);
806 ovf
|= (h
> 0x7FFF) || (h
< -0x8000);
808 ret
|= (h
& 0xffff) << (i
* 16);
811 env
->PSW_USB_V
= ovf
<< 31;
812 env
->PSW_USB_SV
|= env
->PSW_USB_V
;
813 env
->PSW_USB_AV
= avf
<< 16;
814 env
->PSW_USB_SAV
|= env
->PSW_USB_AV
;
819 uint32_t helper_addr_h(CPUTriCoreState
*env
, uint64_t r1
, uint32_t r2_l
,
822 int64_t mul_res0
= sextract64(r1
, 0, 32);
823 int64_t mul_res1
= sextract64(r1
, 32, 32);
824 int64_t r2_low
= sextract64(r2_l
, 0, 32);
825 int64_t r2_high
= sextract64(r2_h
, 0, 32);
826 int64_t result0
, result1
;
832 result0
= r2_low
+ mul_res0
+ 0x8000;
833 result1
= r2_high
+ mul_res1
+ 0x8000;
835 if ((result0
> INT32_MAX
) || (result0
< INT32_MIN
)) {
839 if ((result1
> INT32_MAX
) || (result1
< INT32_MIN
)) {
843 env
->PSW_USB_V
= ovf0
| ovf1
;
844 env
->PSW_USB_SV
|= env
->PSW_USB_V
;
847 avf0
= result0
^ avf0
;
849 avf1
= result1
^ avf1
;
851 env
->PSW_USB_AV
= avf0
| avf1
;
852 env
->PSW_USB_SAV
|= env
->PSW_USB_AV
;
854 return (result1
& 0xffff0000ULL
) | ((result0
>> 16) & 0xffffULL
);
857 uint32_t helper_maddr_q(CPUTriCoreState
*env
, uint32_t r1
, uint32_t r2
,
858 uint32_t r3
, uint32_t n
)
860 int64_t t1
= sextract64(r1
, 0, 32);
861 int64_t t2
= sextract64(r2
, 0, 32);
862 int64_t t3
= sextract64(r3
, 0, 32);
865 if ((t2
== -0x8000ll
) && (t3
== -0x8000ll
) && (n
== 1)) {
868 mul
= (t2
* t3
) << n
;
871 ret
= t1
+ mul
+ 0x8000;
873 if ((ret
> 0x7fffffffll
) || (ret
< -0x80000000ll
)) {
874 env
->PSW_USB_V
= (1 << 31);
875 env
->PSW_USB_SV
|= env
->PSW_USB_V
;
879 env
->PSW_USB_AV
= ret
^ ret
* 2u;
880 env
->PSW_USB_SAV
|= env
->PSW_USB_AV
;
882 return ret
& 0xffff0000ll
;
885 uint32_t helper_add_b(CPUTriCoreState
*env
, target_ulong r1
, target_ulong r2
)
888 int32_t extr_r1
, extr_r2
;
893 for (i
= 0; i
< 4; i
++) {
894 extr_r1
= sextract32(r1
, i
* 8, 8);
895 extr_r2
= sextract32(r2
, i
* 8, 8);
897 b
= extr_r1
+ extr_r2
;
898 ovf
|= ((b
> 0x7f) || (b
< -0x80));
900 ret
|= ((b
& 0xff) << (i
*8));
903 env
->PSW_USB_V
= (ovf
<< 31);
904 env
->PSW_USB_SV
|= env
->PSW_USB_V
;
905 env
->PSW_USB_AV
= avf
<< 24;
906 env
->PSW_USB_SAV
|= env
->PSW_USB_AV
;
911 uint32_t helper_add_h(CPUTriCoreState
*env
, target_ulong r1
, target_ulong r2
)
914 int32_t extr_r1
, extr_r2
;
919 for (i
= 0; i
< 2; i
++) {
920 extr_r1
= sextract32(r1
, i
* 16, 16);
921 extr_r2
= sextract32(r2
, i
* 16, 16);
922 h
= extr_r1
+ extr_r2
;
923 ovf
|= ((h
> 0x7fff) || (h
< -0x8000));
925 ret
|= (h
& 0xffff) << (i
* 16);
928 env
->PSW_USB_V
= (ovf
<< 31);
929 env
->PSW_USB_SV
|= env
->PSW_USB_V
;
930 env
->PSW_USB_AV
= (avf
<< 16);
931 env
->PSW_USB_SAV
|= env
->PSW_USB_AV
;
936 uint32_t helper_sub_b(CPUTriCoreState
*env
, target_ulong r1
, target_ulong r2
)
939 int32_t extr_r1
, extr_r2
;
944 for (i
= 0; i
< 4; i
++) {
945 extr_r1
= sextract32(r1
, i
* 8, 8);
946 extr_r2
= sextract32(r2
, i
* 8, 8);
948 b
= extr_r1
- extr_r2
;
949 ovf
|= ((b
> 0x7f) || (b
< -0x80));
951 ret
|= ((b
& 0xff) << (i
*8));
954 env
->PSW_USB_V
= (ovf
<< 31);
955 env
->PSW_USB_SV
|= env
->PSW_USB_V
;
956 env
->PSW_USB_AV
= avf
<< 24;
957 env
->PSW_USB_SAV
|= env
->PSW_USB_AV
;
962 uint32_t helper_sub_h(CPUTriCoreState
*env
, target_ulong r1
, target_ulong r2
)
965 int32_t extr_r1
, extr_r2
;
970 for (i
= 0; i
< 2; i
++) {
971 extr_r1
= sextract32(r1
, i
* 16, 16);
972 extr_r2
= sextract32(r2
, i
* 16, 16);
973 h
= extr_r1
- extr_r2
;
974 ovf
|= ((h
> 0x7fff) || (h
< -0x8000));
976 ret
|= (h
& 0xffff) << (i
* 16);
979 env
->PSW_USB_V
= (ovf
<< 31);
980 env
->PSW_USB_SV
|= env
->PSW_USB_V
;
981 env
->PSW_USB_AV
= avf
<< 16;
982 env
->PSW_USB_SAV
|= env
->PSW_USB_AV
;
987 uint32_t helper_eq_b(target_ulong r1
, target_ulong r2
)
994 for (i
= 0; i
< 4; i
++) {
995 if ((r1
& msk
) == (r2
& msk
)) {
1004 uint32_t helper_eq_h(target_ulong r1
, target_ulong r2
)
1008 if ((r1
& 0xffff) == (r2
& 0xffff)) {
1012 if ((r1
& 0xffff0000) == (r2
& 0xffff0000)) {
1019 uint32_t helper_eqany_b(target_ulong r1
, target_ulong r2
)
1024 for (i
= 0; i
< 4; i
++) {
1025 ret
|= (sextract32(r1
, i
* 8, 8) == sextract32(r2
, i
* 8, 8));
1031 uint32_t helper_eqany_h(target_ulong r1
, target_ulong r2
)
1035 ret
= (sextract32(r1
, 0, 16) == sextract32(r2
, 0, 16));
1036 ret
|= (sextract32(r1
, 16, 16) == sextract32(r2
, 16, 16));
1041 uint32_t helper_lt_b(target_ulong r1
, target_ulong r2
)
1046 for (i
= 0; i
< 4; i
++) {
1047 if (sextract32(r1
, i
* 8, 8) < sextract32(r2
, i
* 8, 8)) {
1048 ret
|= (0xff << (i
* 8));
1055 uint32_t helper_lt_bu(target_ulong r1
, target_ulong r2
)
1060 for (i
= 0; i
< 4; i
++) {
1061 if (extract32(r1
, i
* 8, 8) < extract32(r2
, i
* 8, 8)) {
1062 ret
|= (0xff << (i
* 8));
1069 uint32_t helper_lt_h(target_ulong r1
, target_ulong r2
)
1073 if (sextract32(r1
, 0, 16) < sextract32(r2
, 0, 16)) {
1077 if (sextract32(r1
, 16, 16) < sextract32(r2
, 16, 16)) {
1084 uint32_t helper_lt_hu(target_ulong r1
, target_ulong r2
)
1088 if (extract32(r1
, 0, 16) < extract32(r2
, 0, 16)) {
1092 if (extract32(r1
, 16, 16) < extract32(r2
, 16, 16)) {
1099 #define EXTREMA_H_B(name, op) \
1100 uint32_t helper_##name ##_b(target_ulong r1, target_ulong r2) \
1102 int32_t i, extr_r1, extr_r2; \
1105 for (i = 0; i < 4; i++) { \
1106 extr_r1 = sextract32(r1, i * 8, 8); \
1107 extr_r2 = sextract32(r2, i * 8, 8); \
1108 extr_r1 = (extr_r1 op extr_r2) ? extr_r1 : extr_r2; \
1109 ret |= (extr_r1 & 0xff) << (i * 8); \
1114 uint32_t helper_##name ##_bu(target_ulong r1, target_ulong r2)\
1117 uint32_t extr_r1, extr_r2; \
1120 for (i = 0; i < 4; i++) { \
1121 extr_r1 = extract32(r1, i * 8, 8); \
1122 extr_r2 = extract32(r2, i * 8, 8); \
1123 extr_r1 = (extr_r1 op extr_r2) ? extr_r1 : extr_r2; \
1124 ret |= (extr_r1 & 0xff) << (i * 8); \
1129 uint32_t helper_##name ##_h(target_ulong r1, target_ulong r2) \
1131 int32_t extr_r1, extr_r2; \
1134 extr_r1 = sextract32(r1, 0, 16); \
1135 extr_r2 = sextract32(r2, 0, 16); \
1136 ret = (extr_r1 op extr_r2) ? extr_r1 : extr_r2; \
1137 ret = ret & 0xffff; \
1139 extr_r1 = sextract32(r1, 16, 16); \
1140 extr_r2 = sextract32(r2, 16, 16); \
1141 extr_r1 = (extr_r1 op extr_r2) ? extr_r1 : extr_r2; \
1142 ret |= extr_r1 << 16; \
1147 uint32_t helper_##name ##_hu(target_ulong r1, target_ulong r2)\
1149 uint32_t extr_r1, extr_r2; \
1152 extr_r1 = extract32(r1, 0, 16); \
1153 extr_r2 = extract32(r2, 0, 16); \
1154 ret = (extr_r1 op extr_r2) ? extr_r1 : extr_r2; \
1155 ret = ret & 0xffff; \
1157 extr_r1 = extract32(r1, 16, 16); \
1158 extr_r2 = extract32(r2, 16, 16); \
1159 extr_r1 = (extr_r1 op extr_r2) ? extr_r1 : extr_r2; \
1160 ret |= extr_r1 << (16); \
1165 uint64_t helper_ix##name(uint64_t r1, uint32_t r2) \
1167 int64_t r2l, r2h, r1hl; \
1170 ret = ((r1 + 2) & 0xffff); \
1171 r2l = sextract64(r2, 0, 16); \
1172 r2h = sextract64(r2, 16, 16); \
1173 r1hl = sextract64(r1, 32, 16); \
1175 if ((r2l op ## = r2h) && (r2l op r1hl)) { \
1176 ret |= (r2l & 0xffff) << 32; \
1177 ret |= extract64(r1, 0, 16) << 16; \
1178 } else if ((r2h op r2l) && (r2h op r1hl)) { \
1179 ret |= extract64(r2, 16, 16) << 32; \
1180 ret |= extract64(r1 + 1, 0, 16) << 16; \
1182 ret |= r1 & 0xffffffff0000ull; \
1187 uint64_t helper_ix##name ##_u(uint64_t r1, uint32_t r2) \
1189 int64_t r2l, r2h, r1hl; \
1192 ret = ((r1 + 2) & 0xffff); \
1193 r2l = extract64(r2, 0, 16); \
1194 r2h = extract64(r2, 16, 16); \
1195 r1hl = extract64(r1, 32, 16); \
1197 if ((r2l op ## = r2h) && (r2l op r1hl)) { \
1198 ret |= (r2l & 0xffff) << 32; \
1199 ret |= extract64(r1, 0, 16) << 16; \
1200 } else if ((r2h op r2l) && (r2h op r1hl)) { \
1201 ret |= extract64(r2, 16, 16) << 32; \
1202 ret |= extract64(r1 + 1, 0, 16) << 16; \
1204 ret |= r1 & 0xffffffff0000ull; \
1214 uint32_t helper_clo(target_ulong r1
)
1219 uint32_t helper_clo_h(target_ulong r1
)
1221 uint32_t ret_hw0
= extract32(r1
, 0, 16);
1222 uint32_t ret_hw1
= extract32(r1
, 16, 16);
1224 ret_hw0
= clo32(ret_hw0
<< 16);
1225 ret_hw1
= clo32(ret_hw1
<< 16);
1234 return ret_hw0
| (ret_hw1
<< 16);
1237 uint32_t helper_clz(target_ulong r1
)
1242 uint32_t helper_clz_h(target_ulong r1
)
1244 uint32_t ret_hw0
= extract32(r1
, 0, 16);
1245 uint32_t ret_hw1
= extract32(r1
, 16, 16);
1247 ret_hw0
= clz32(ret_hw0
<< 16);
1248 ret_hw1
= clz32(ret_hw1
<< 16);
1257 return ret_hw0
| (ret_hw1
<< 16);
1260 uint32_t helper_cls(target_ulong r1
)
1265 uint32_t helper_cls_h(target_ulong r1
)
1267 uint32_t ret_hw0
= extract32(r1
, 0, 16);
1268 uint32_t ret_hw1
= extract32(r1
, 16, 16);
1270 ret_hw0
= clrsb32(ret_hw0
<< 16);
1271 ret_hw1
= clrsb32(ret_hw1
<< 16);
1280 return ret_hw0
| (ret_hw1
<< 16);
1283 uint32_t helper_sh(target_ulong r1
, target_ulong r2
)
1285 int32_t shift_count
= sextract32(r2
, 0, 6);
1287 if (shift_count
== -32) {
1289 } else if (shift_count
< 0) {
1290 return r1
>> -shift_count
;
1292 return r1
<< shift_count
;
1296 uint32_t helper_sh_h(target_ulong r1
, target_ulong r2
)
1298 int32_t ret_hw0
, ret_hw1
;
1299 int32_t shift_count
;
1301 shift_count
= sextract32(r2
, 0, 5);
1303 if (shift_count
== -16) {
1305 } else if (shift_count
< 0) {
1306 ret_hw0
= extract32(r1
, 0, 16) >> -shift_count
;
1307 ret_hw1
= extract32(r1
, 16, 16) >> -shift_count
;
1308 return (ret_hw0
& 0xffff) | (ret_hw1
<< 16);
1310 ret_hw0
= extract32(r1
, 0, 16) << shift_count
;
1311 ret_hw1
= extract32(r1
, 16, 16) << shift_count
;
1312 return (ret_hw0
& 0xffff) | (ret_hw1
<< 16);
1316 uint32_t helper_sha(CPUTriCoreState
*env
, target_ulong r1
, target_ulong r2
)
1318 int32_t shift_count
;
1322 shift_count
= sextract32(r2
, 0, 6);
1323 t1
= sextract32(r1
, 0, 32);
1325 if (shift_count
== 0) {
1326 env
->PSW_USB_C
= env
->PSW_USB_V
= 0;
1328 } else if (shift_count
== -32) {
1329 env
->PSW_USB_C
= r1
;
1332 } else if (shift_count
> 0) {
1333 result
= t1
<< shift_count
;
1335 env
->PSW_USB_C
= ((result
& 0xffffffff00000000ULL
) != 0);
1337 env
->PSW_USB_V
= (((result
> 0x7fffffffLL
) ||
1338 (result
< -0x80000000LL
)) << 31);
1340 env
->PSW_USB_SV
|= env
->PSW_USB_V
;
1341 ret
= (uint32_t)result
;
1344 env
->PSW_USB_C
= (r1
& ((1 << -shift_count
) - 1));
1345 ret
= t1
>> -shift_count
;
1348 env
->PSW_USB_AV
= ret
^ ret
* 2u;
1349 env
->PSW_USB_SAV
|= env
->PSW_USB_AV
;
1354 uint32_t helper_sha_h(target_ulong r1
, target_ulong r2
)
1356 int32_t shift_count
;
1357 int32_t ret_hw0
, ret_hw1
;
1359 shift_count
= sextract32(r2
, 0, 5);
1361 if (shift_count
== 0) {
1363 } else if (shift_count
< 0) {
1364 ret_hw0
= sextract32(r1
, 0, 16) >> -shift_count
;
1365 ret_hw1
= sextract32(r1
, 16, 16) >> -shift_count
;
1366 return (ret_hw0
& 0xffff) | (ret_hw1
<< 16);
1368 ret_hw0
= sextract32(r1
, 0, 16) << shift_count
;
1369 ret_hw1
= sextract32(r1
, 16, 16) << shift_count
;
1370 return (ret_hw0
& 0xffff) | (ret_hw1
<< 16);
1374 uint32_t helper_bmerge(target_ulong r1
, target_ulong r2
)
1379 for (i
= 0; i
< 16; i
++) {
1380 ret
|= (r1
& 1) << (2 * i
+ 1);
1381 ret
|= (r2
& 1) << (2 * i
);
1388 uint64_t helper_bsplit(uint32_t r1
)
1394 for (i
= 0; i
< 32; i
= i
+ 2) {
1396 ret
|= (r1
& 1) << (i
/2);
1399 ret
|= (uint64_t)(r1
& 1) << (i
/2 + 32);
1405 uint32_t helper_parity(target_ulong r1
)
1412 for (i
= 0; i
< 8; i
++) {
1418 for (i
= 0; i
< 8; i
++) {
1425 for (i
= 0; i
< 8; i
++) {
1432 for (i
= 0; i
< 8; i
++) {
1441 uint32_t helper_pack(uint32_t carry
, uint32_t r1_low
, uint32_t r1_high
,
1445 int32_t fp_exp
, fp_frac
, temp_exp
, fp_exp_frac
;
1446 int32_t int_exp
= r1_high
;
1447 int32_t int_mant
= r1_low
;
1448 uint32_t flag_rnd
= (int_mant
& (1 << 7)) && (
1449 (int_mant
& (1 << 8)) ||
1450 (int_mant
& 0x7f) ||
1452 if (((int_mant
& (1<<31)) == 0) && (int_exp
== 255)) {
1454 fp_frac
= extract32(int_mant
, 8, 23);
1455 } else if ((int_mant
& (1<<31)) && (int_exp
>= 127)) {
1458 } else if ((int_mant
& (1<<31)) && (int_exp
<= -128)) {
1461 } else if (int_mant
== 0) {
1465 if (((int_mant
& (1 << 31)) == 0)) {
1468 temp_exp
= int_exp
+ 128;
1470 fp_exp_frac
= (((temp_exp
& 0xff) << 23) |
1471 extract32(int_mant
, 8, 23))
1473 fp_exp
= extract32(fp_exp_frac
, 23, 8);
1474 fp_frac
= extract32(fp_exp_frac
, 0, 23);
1476 ret
= r2
& (1 << 31);
1477 ret
= ret
+ (fp_exp
<< 23);
1478 ret
= ret
+ (fp_frac
& 0x7fffff);
1483 uint64_t helper_unpack(target_ulong arg1
)
1485 int32_t fp_exp
= extract32(arg1
, 23, 8);
1486 int32_t fp_frac
= extract32(arg1
, 0, 23);
1488 int32_t int_exp
, int_mant
;
1490 if (fp_exp
== 255) {
1492 int_mant
= (fp_frac
<< 7);
1493 } else if ((fp_exp
== 0) && (fp_frac
== 0)) {
1496 } else if ((fp_exp
== 0) && (fp_frac
!= 0)) {
1498 int_mant
= (fp_frac
<< 7);
1500 int_exp
= fp_exp
- 127;
1501 int_mant
= (fp_frac
<< 7);
1502 int_mant
|= (1 << 30);
1511 uint64_t helper_dvinit_b_13(CPUTriCoreState
*env
, uint32_t r1
, uint32_t r2
)
1514 int32_t abs_sig_dividend
, abs_base_dividend
, abs_divisor
;
1515 int32_t quotient_sign
;
1517 ret
= sextract32(r1
, 0, 32);
1520 if (!((r1
& 0x80000000) == (r2
& 0x80000000))) {
1525 abs_sig_dividend
= abs(r1
) >> 7;
1526 abs_base_dividend
= abs(r1
) & 0x7f;
1527 abs_divisor
= abs(r1
);
1530 if ((quotient_sign
) && (abs_divisor
)) {
1531 env
->PSW_USB_V
= (((abs_sig_dividend
== abs_divisor
) &&
1532 (abs_base_dividend
>= abs_divisor
)) ||
1533 (abs_sig_dividend
> abs_divisor
));
1535 env
->PSW_USB_V
= (abs_sig_dividend
>= abs_divisor
);
1537 env
->PSW_USB_V
= env
->PSW_USB_V
<< 31;
1538 env
->PSW_USB_SV
|= env
->PSW_USB_V
;
1539 env
->PSW_USB_AV
= 0;
1544 uint64_t helper_dvinit_b_131(CPUTriCoreState
*env
, uint32_t r1
, uint32_t r2
)
1546 uint64_t ret
= sextract32(r1
, 0, 32);
1549 if (!((r1
& 0x80000000) == (r2
& 0x80000000))) {
1553 env
->PSW_USB_V
= ((r2
== 0) || ((r2
== 0xffffffff) && (r1
== 0xffffff80)));
1554 env
->PSW_USB_V
= env
->PSW_USB_V
<< 31;
1555 env
->PSW_USB_SV
|= env
->PSW_USB_V
;
1556 env
->PSW_USB_AV
= 0;
1561 uint64_t helper_dvinit_h_13(CPUTriCoreState
*env
, uint32_t r1
, uint32_t r2
)
1564 int32_t abs_sig_dividend
, abs_base_dividend
, abs_divisor
;
1565 int32_t quotient_sign
;
1567 ret
= sextract32(r1
, 0, 32);
1570 if (!((r1
& 0x80000000) == (r2
& 0x80000000))) {
1575 abs_sig_dividend
= abs(r1
) >> 7;
1576 abs_base_dividend
= abs(r1
) & 0x7f;
1577 abs_divisor
= abs(r1
);
1580 if ((quotient_sign
) && (abs_divisor
)) {
1581 env
->PSW_USB_V
= (((abs_sig_dividend
== abs_divisor
) &&
1582 (abs_base_dividend
>= abs_divisor
)) ||
1583 (abs_sig_dividend
> abs_divisor
));
1585 env
->PSW_USB_V
= (abs_sig_dividend
>= abs_divisor
);
1587 env
->PSW_USB_V
= env
->PSW_USB_V
<< 31;
1588 env
->PSW_USB_SV
|= env
->PSW_USB_V
;
1589 env
->PSW_USB_AV
= 0;
1594 uint64_t helper_dvinit_h_131(CPUTriCoreState
*env
, uint32_t r1
, uint32_t r2
)
1596 uint64_t ret
= sextract32(r1
, 0, 32);
1599 if (!((r1
& 0x80000000) == (r2
& 0x80000000))) {
1603 env
->PSW_USB_V
= ((r2
== 0) || ((r2
== 0xffffffff) && (r1
== 0xffff8000)));
1604 env
->PSW_USB_V
= env
->PSW_USB_V
<< 31;
1605 env
->PSW_USB_SV
|= env
->PSW_USB_V
;
1606 env
->PSW_USB_AV
= 0;
1611 uint64_t helper_dvadj(uint64_t r1
, uint32_t r2
)
1613 int32_t x_sign
= (r1
>> 63);
1614 int32_t q_sign
= x_sign
^ (r2
>> 31);
1615 int32_t eq_pos
= x_sign
& ((r1
>> 32) == r2
);
1616 int32_t eq_neg
= x_sign
& ((r1
>> 32) == -r2
);
1618 uint64_t ret
, remainder
;
1620 if ((q_sign
& ~eq_neg
) | eq_pos
) {
1621 quotient
= (r1
+ 1) & 0xffffffff;
1623 quotient
= r1
& 0xffffffff;
1626 if (eq_pos
| eq_neg
) {
1629 remainder
= (r1
& 0xffffffff00000000ull
);
1631 ret
= remainder
|quotient
;
1635 uint64_t helper_dvstep(uint64_t r1
, uint32_t r2
)
1637 int32_t dividend_sign
= extract64(r1
, 63, 1);
1638 int32_t divisor_sign
= extract32(r2
, 31, 1);
1639 int32_t quotient_sign
= (dividend_sign
!= divisor_sign
);
1640 int32_t addend
, dividend_quotient
, remainder
;
1643 if (quotient_sign
) {
1648 dividend_quotient
= (int32_t)r1
;
1649 remainder
= (int32_t)(r1
>> 32);
1651 for (i
= 0; i
< 8; i
++) {
1652 remainder
= (remainder
<< 1) | extract32(dividend_quotient
, 31, 1);
1653 dividend_quotient
<<= 1;
1654 temp
= remainder
+ addend
;
1655 if ((temp
< 0) == dividend_sign
) {
1658 if (((temp
< 0) == dividend_sign
)) {
1659 dividend_quotient
= dividend_quotient
| !quotient_sign
;
1661 dividend_quotient
= dividend_quotient
| quotient_sign
;
1664 return ((uint64_t)remainder
<< 32) | (uint32_t)dividend_quotient
;
1667 uint64_t helper_dvstep_u(uint64_t r1
, uint32_t r2
)
1669 int32_t dividend_quotient
= extract64(r1
, 0, 32);
1670 int64_t remainder
= extract64(r1
, 32, 32);
1673 for (i
= 0; i
< 8; i
++) {
1674 remainder
= (remainder
<< 1) | extract32(dividend_quotient
, 31, 1);
1675 dividend_quotient
<<= 1;
1676 temp
= (remainder
& 0xffffffff) - r2
;
1680 dividend_quotient
= dividend_quotient
| !(temp
< 0);
1682 return ((uint64_t)remainder
<< 32) | (uint32_t)dividend_quotient
;
1685 uint64_t helper_mul_h(uint32_t arg00
, uint32_t arg01
,
1686 uint32_t arg10
, uint32_t arg11
, uint32_t n
)
1689 uint32_t result0
, result1
;
1691 int32_t sc1
= ((arg00
& 0xffff) == 0x8000) &&
1692 ((arg10
& 0xffff) == 0x8000) && (n
== 1);
1693 int32_t sc0
= ((arg01
& 0xffff) == 0x8000) &&
1694 ((arg11
& 0xffff) == 0x8000) && (n
== 1);
1696 result1
= 0x7fffffff;
1698 result1
= (((uint32_t)(arg00
* arg10
)) << n
);
1701 result0
= 0x7fffffff;
1703 result0
= (((uint32_t)(arg01
* arg11
)) << n
);
1705 ret
= (((uint64_t)result1
<< 32)) | result0
;
1709 uint64_t helper_mulm_h(uint32_t arg00
, uint32_t arg01
,
1710 uint32_t arg10
, uint32_t arg11
, uint32_t n
)
1713 int64_t result0
, result1
;
1715 int32_t sc1
= ((arg00
& 0xffff) == 0x8000) &&
1716 ((arg10
& 0xffff) == 0x8000) && (n
== 1);
1717 int32_t sc0
= ((arg01
& 0xffff) == 0x8000) &&
1718 ((arg11
& 0xffff) == 0x8000) && (n
== 1);
1721 result1
= 0x7fffffff;
1723 result1
= (((int32_t)arg00
* (int32_t)arg10
) << n
);
1726 result0
= 0x7fffffff;
1728 result0
= (((int32_t)arg01
* (int32_t)arg11
) << n
);
1730 ret
= (result1
+ result0
);
1734 uint32_t helper_mulr_h(uint32_t arg00
, uint32_t arg01
,
1735 uint32_t arg10
, uint32_t arg11
, uint32_t n
)
1737 uint32_t result0
, result1
;
1739 int32_t sc1
= ((arg00
& 0xffff) == 0x8000) &&
1740 ((arg10
& 0xffff) == 0x8000) && (n
== 1);
1741 int32_t sc0
= ((arg01
& 0xffff) == 0x8000) &&
1742 ((arg11
& 0xffff) == 0x8000) && (n
== 1);
1745 result1
= 0x7fffffff;
1747 result1
= ((arg00
* arg10
) << n
) + 0x8000;
1750 result0
= 0x7fffffff;
1752 result0
= ((arg01
* arg11
) << n
) + 0x8000;
1754 return (result1
& 0xffff0000) | (result0
>> 16);
1757 /* context save area (CSA) related helpers */
1759 static int cdc_increment(target_ulong
*psw
)
1761 if ((*psw
& MASK_PSW_CDC
) == 0x7f) {
1766 /* check for overflow */
1767 int lo
= clo32((*psw
& MASK_PSW_CDC
) << (32 - 7));
1768 int mask
= (1u << (7 - lo
)) - 1;
1769 int count
= *psw
& mask
;
1777 static int cdc_decrement(target_ulong
*psw
)
1779 if ((*psw
& MASK_PSW_CDC
) == 0x7f) {
1782 /* check for underflow */
1783 int lo
= clo32((*psw
& MASK_PSW_CDC
) << (32 - 7));
1784 int mask
= (1u << (7 - lo
)) - 1;
1785 int count
= *psw
& mask
;
1793 static bool cdc_zero(target_ulong
*psw
)
1795 int cdc
= *psw
& MASK_PSW_CDC
;
1796 /* Returns TRUE if PSW.CDC.COUNT == 0 or if PSW.CDC ==
1797 7'b1111111, otherwise returns FALSE. */
1801 /* find CDC.COUNT */
1802 int lo
= clo32((*psw
& MASK_PSW_CDC
) << (32 - 7));
1803 int mask
= (1u << (7 - lo
)) - 1;
1804 int count
= *psw
& mask
;
1808 static void save_context_upper(CPUTriCoreState
*env
, int ea
)
1810 cpu_stl_data(env
, ea
, env
->PCXI
);
1811 cpu_stl_data(env
, ea
+4, env
->PSW
);
1812 cpu_stl_data(env
, ea
+8, env
->gpr_a
[10]);
1813 cpu_stl_data(env
, ea
+12, env
->gpr_a
[11]);
1814 cpu_stl_data(env
, ea
+16, env
->gpr_d
[8]);
1815 cpu_stl_data(env
, ea
+20, env
->gpr_d
[9]);
1816 cpu_stl_data(env
, ea
+24, env
->gpr_d
[10]);
1817 cpu_stl_data(env
, ea
+28, env
->gpr_d
[11]);
1818 cpu_stl_data(env
, ea
+32, env
->gpr_a
[12]);
1819 cpu_stl_data(env
, ea
+36, env
->gpr_a
[13]);
1820 cpu_stl_data(env
, ea
+40, env
->gpr_a
[14]);
1821 cpu_stl_data(env
, ea
+44, env
->gpr_a
[15]);
1822 cpu_stl_data(env
, ea
+48, env
->gpr_d
[12]);
1823 cpu_stl_data(env
, ea
+52, env
->gpr_d
[13]);
1824 cpu_stl_data(env
, ea
+56, env
->gpr_d
[14]);
1825 cpu_stl_data(env
, ea
+60, env
->gpr_d
[15]);
1828 static void save_context_lower(CPUTriCoreState
*env
, int ea
)
1830 cpu_stl_data(env
, ea
, env
->PCXI
);
1831 cpu_stl_data(env
, ea
+4, env
->gpr_a
[11]);
1832 cpu_stl_data(env
, ea
+8, env
->gpr_a
[2]);
1833 cpu_stl_data(env
, ea
+12, env
->gpr_a
[3]);
1834 cpu_stl_data(env
, ea
+16, env
->gpr_d
[0]);
1835 cpu_stl_data(env
, ea
+20, env
->gpr_d
[1]);
1836 cpu_stl_data(env
, ea
+24, env
->gpr_d
[2]);
1837 cpu_stl_data(env
, ea
+28, env
->gpr_d
[3]);
1838 cpu_stl_data(env
, ea
+32, env
->gpr_a
[4]);
1839 cpu_stl_data(env
, ea
+36, env
->gpr_a
[5]);
1840 cpu_stl_data(env
, ea
+40, env
->gpr_a
[6]);
1841 cpu_stl_data(env
, ea
+44, env
->gpr_a
[7]);
1842 cpu_stl_data(env
, ea
+48, env
->gpr_d
[4]);
1843 cpu_stl_data(env
, ea
+52, env
->gpr_d
[5]);
1844 cpu_stl_data(env
, ea
+56, env
->gpr_d
[6]);
1845 cpu_stl_data(env
, ea
+60, env
->gpr_d
[7]);
1848 static void restore_context_upper(CPUTriCoreState
*env
, int ea
,
1849 target_ulong
*new_PCXI
, target_ulong
*new_PSW
)
1851 *new_PCXI
= cpu_ldl_data(env
, ea
);
1852 *new_PSW
= cpu_ldl_data(env
, ea
+4);
1853 env
->gpr_a
[10] = cpu_ldl_data(env
, ea
+8);
1854 env
->gpr_a
[11] = cpu_ldl_data(env
, ea
+12);
1855 env
->gpr_d
[8] = cpu_ldl_data(env
, ea
+16);
1856 env
->gpr_d
[9] = cpu_ldl_data(env
, ea
+20);
1857 env
->gpr_d
[10] = cpu_ldl_data(env
, ea
+24);
1858 env
->gpr_d
[11] = cpu_ldl_data(env
, ea
+28);
1859 env
->gpr_a
[12] = cpu_ldl_data(env
, ea
+32);
1860 env
->gpr_a
[13] = cpu_ldl_data(env
, ea
+36);
1861 env
->gpr_a
[14] = cpu_ldl_data(env
, ea
+40);
1862 env
->gpr_a
[15] = cpu_ldl_data(env
, ea
+44);
1863 env
->gpr_d
[12] = cpu_ldl_data(env
, ea
+48);
1864 env
->gpr_d
[13] = cpu_ldl_data(env
, ea
+52);
1865 env
->gpr_d
[14] = cpu_ldl_data(env
, ea
+56);
1866 env
->gpr_d
[15] = cpu_ldl_data(env
, ea
+60);
1869 static void restore_context_lower(CPUTriCoreState
*env
, int ea
,
1870 target_ulong
*ra
, target_ulong
*pcxi
)
1872 *pcxi
= cpu_ldl_data(env
, ea
);
1873 *ra
= cpu_ldl_data(env
, ea
+4);
1874 env
->gpr_a
[2] = cpu_ldl_data(env
, ea
+8);
1875 env
->gpr_a
[3] = cpu_ldl_data(env
, ea
+12);
1876 env
->gpr_d
[0] = cpu_ldl_data(env
, ea
+16);
1877 env
->gpr_d
[1] = cpu_ldl_data(env
, ea
+20);
1878 env
->gpr_d
[2] = cpu_ldl_data(env
, ea
+24);
1879 env
->gpr_d
[3] = cpu_ldl_data(env
, ea
+28);
1880 env
->gpr_a
[4] = cpu_ldl_data(env
, ea
+32);
1881 env
->gpr_a
[5] = cpu_ldl_data(env
, ea
+36);
1882 env
->gpr_a
[6] = cpu_ldl_data(env
, ea
+40);
1883 env
->gpr_a
[7] = cpu_ldl_data(env
, ea
+44);
1884 env
->gpr_d
[4] = cpu_ldl_data(env
, ea
+48);
1885 env
->gpr_d
[5] = cpu_ldl_data(env
, ea
+52);
1886 env
->gpr_d
[6] = cpu_ldl_data(env
, ea
+56);
1887 env
->gpr_d
[7] = cpu_ldl_data(env
, ea
+60);
1890 void helper_call(CPUTriCoreState
*env
, uint32_t next_pc
)
1892 target_ulong tmp_FCX
;
1894 target_ulong new_FCX
;
1897 psw
= psw_read(env
);
1898 /* if (FCX == 0) trap(FCU); */
1899 if (env
->FCX
== 0) {
1902 /* if (PSW.CDE) then if (cdc_increment()) then trap(CDO); */
1903 if (psw
& MASK_PSW_CDE
) {
1904 if (cdc_increment(&psw
)) {
1909 psw
|= MASK_PSW_CDE
;
1910 /* tmp_FCX = FCX; */
1912 /* EA = {FCX.FCXS, 6'b0, FCX.FCXO, 6'b0}; */
1913 ea
= ((env
->FCX
& MASK_FCX_FCXS
) << 12) +
1914 ((env
->FCX
& MASK_FCX_FCXO
) << 6);
1915 /* new_FCX = M(EA, word); */
1916 new_FCX
= cpu_ldl_data(env
, ea
);
1917 /* M(EA, 16 * word) = {PCXI, PSW, A[10], A[11], D[8], D[9], D[10], D[11],
1918 A[12], A[13], A[14], A[15], D[12], D[13], D[14],
1920 save_context_upper(env
, ea
);
1922 /* PCXI.PCPN = ICR.CCPN; */
1923 env
->PCXI
= (env
->PCXI
& 0xffffff) +
1924 ((env
->ICR
& MASK_ICR_CCPN
) << 24);
1925 /* PCXI.PIE = ICR.IE; */
1926 env
->PCXI
= ((env
->PCXI
& ~MASK_PCXI_PIE
) +
1927 ((env
->ICR
& MASK_ICR_IE
) << 15));
1929 env
->PCXI
|= MASK_PCXI_UL
;
1931 /* PCXI[19: 0] = FCX[19: 0]; */
1932 env
->PCXI
= (env
->PCXI
& 0xfff00000) + (env
->FCX
& 0xfffff);
1933 /* FCX[19: 0] = new_FCX[19: 0]; */
1934 env
->FCX
= (env
->FCX
& 0xfff00000) + (new_FCX
& 0xfffff);
1935 /* A[11] = next_pc[31: 0]; */
1936 env
->gpr_a
[11] = next_pc
;
1938 /* if (tmp_FCX == LCX) trap(FCD);*/
1939 if (tmp_FCX
== env
->LCX
) {
1942 psw_write(env
, psw
);
1945 void helper_ret(CPUTriCoreState
*env
)
1948 target_ulong new_PCXI
;
1949 target_ulong new_PSW
, psw
;
1951 psw
= psw_read(env
);
1952 /* if (PSW.CDE) then if (cdc_decrement()) then trap(CDU);*/
1953 if (env
->PSW
& MASK_PSW_CDE
) {
1954 if (cdc_decrement(&(env
->PSW
))) {
1958 /* if (PCXI[19: 0] == 0) then trap(CSU); */
1959 if ((env
->PCXI
& 0xfffff) == 0) {
1962 /* if (PCXI.UL == 0) then trap(CTYP); */
1963 if ((env
->PCXI
& MASK_PCXI_UL
) == 0) {
1966 /* PC = {A11 [31: 1], 1’b0}; */
1967 env
->PC
= env
->gpr_a
[11] & 0xfffffffe;
1969 /* EA = {PCXI.PCXS, 6'b0, PCXI.PCXO, 6'b0}; */
1970 ea
= ((env
->PCXI
& MASK_PCXI_PCXS
) << 12) +
1971 ((env
->PCXI
& MASK_PCXI_PCXO
) << 6);
1972 /* {new_PCXI, new_PSW, A[10], A[11], D[8], D[9], D[10], D[11], A[12],
1973 A[13], A[14], A[15], D[12], D[13], D[14], D[15]} = M(EA, 16 * word); */
1974 restore_context_upper(env
, ea
, &new_PCXI
, &new_PSW
);
1975 /* M(EA, word) = FCX; */
1976 cpu_stl_data(env
, ea
, env
->FCX
);
1977 /* FCX[19: 0] = PCXI[19: 0]; */
1978 env
->FCX
= (env
->FCX
& 0xfff00000) + (env
->PCXI
& 0x000fffff);
1979 /* PCXI = new_PCXI; */
1980 env
->PCXI
= new_PCXI
;
1982 if (tricore_feature(env
, TRICORE_FEATURE_13
)) {
1984 psw_write(env
, new_PSW
);
1986 /* PSW = {new_PSW[31:26], PSW[25:24], new_PSW[23:0]}; */
1987 psw_write(env
, (new_PSW
& ~(0x3000000)) + (psw
& (0x3000000)));
1991 void helper_bisr(CPUTriCoreState
*env
, uint32_t const9
)
1993 target_ulong tmp_FCX
;
1995 target_ulong new_FCX
;
1997 if (env
->FCX
== 0) {
2002 ea
= ((env
->FCX
& 0xf0000) << 12) + ((env
->FCX
& 0xffff) << 6);
2004 /* new_FCX = M(EA, word); */
2005 new_FCX
= cpu_ldl_data(env
, ea
);
2006 /* M(EA, 16 * word) = {PCXI, A[11], A[2], A[3], D[0], D[1], D[2], D[3], A[4]
2007 , A[5], A[6], A[7], D[4], D[5], D[6], D[7]}; */
2008 save_context_lower(env
, ea
);
2011 /* PCXI.PCPN = ICR.CCPN */
2012 env
->PCXI
= (env
->PCXI
& 0xffffff) +
2013 ((env
->ICR
& MASK_ICR_CCPN
) << 24);
2014 /* PCXI.PIE = ICR.IE */
2015 env
->PCXI
= ((env
->PCXI
& ~MASK_PCXI_PIE
) +
2016 ((env
->ICR
& MASK_ICR_IE
) << 15));
2018 env
->PCXI
&= ~(MASK_PCXI_UL
);
2019 /* PCXI[19: 0] = FCX[19: 0] */
2020 env
->PCXI
= (env
->PCXI
& 0xfff00000) + (env
->FCX
& 0xfffff);
2021 /* FXC[19: 0] = new_FCX[19: 0] */
2022 env
->FCX
= (env
->FCX
& 0xfff00000) + (new_FCX
& 0xfffff);
2024 env
->ICR
|= MASK_ICR_IE
;
2026 env
->ICR
|= const9
; /* ICR.CCPN = const9[7: 0];*/
2028 if (tmp_FCX
== env
->LCX
) {
2033 void helper_rfe(CPUTriCoreState
*env
)
2036 target_ulong new_PCXI
;
2037 target_ulong new_PSW
;
2038 /* if (PCXI[19: 0] == 0) then trap(CSU); */
2039 if ((env
->PCXI
& 0xfffff) == 0) {
2040 /* raise csu trap */
2042 /* if (PCXI.UL == 0) then trap(CTYP); */
2043 if ((env
->PCXI
& MASK_PCXI_UL
) == 0) {
2044 /* raise CTYP trap */
2046 /* if (!cdc_zero() AND PSW.CDE) then trap(NEST); */
2047 if (!cdc_zero(&(env
->PSW
)) && (env
->PSW
& MASK_PSW_CDE
)) {
2048 /* raise MNG trap */
2050 /* ICR.IE = PCXI.PIE; */
2051 env
->ICR
= (env
->ICR
& ~MASK_ICR_IE
) + ((env
->PCXI
& MASK_PCXI_PIE
) >> 15);
2052 /* ICR.CCPN = PCXI.PCPN; */
2053 env
->ICR
= (env
->ICR
& ~MASK_ICR_CCPN
) +
2054 ((env
->PCXI
& MASK_PCXI_PCPN
) >> 24);
2055 /*EA = {PCXI.PCXS, 6'b0, PCXI.PCXO, 6'b0};*/
2056 ea
= ((env
->PCXI
& MASK_PCXI_PCXS
) << 12) +
2057 ((env
->PCXI
& MASK_PCXI_PCXO
) << 6);
2058 /*{new_PCXI, PSW, A[10], A[11], D[8], D[9], D[10], D[11], A[12],
2059 A[13], A[14], A[15], D[12], D[13], D[14], D[15]} = M(EA, 16 * word); */
2060 restore_context_upper(env
, ea
, &new_PCXI
, &new_PSW
);
2061 /* M(EA, word) = FCX;*/
2062 cpu_stl_data(env
, ea
, env
->FCX
);
2063 /* FCX[19: 0] = PCXI[19: 0]; */
2064 env
->FCX
= (env
->FCX
& 0xfff00000) + (env
->PCXI
& 0x000fffff);
2065 /* PCXI = new_PCXI; */
2066 env
->PCXI
= new_PCXI
;
2068 psw_write(env
, new_PSW
);
2071 void helper_ldlcx(CPUTriCoreState
*env
, uint32_t ea
)
2074 /* insn doesn't load PCXI and RA */
2075 restore_context_lower(env
, ea
, &dummy
, &dummy
);
2078 void helper_lducx(CPUTriCoreState
*env
, uint32_t ea
)
2081 /* insn doesn't load PCXI and PSW */
2082 restore_context_upper(env
, ea
, &dummy
, &dummy
);
2085 void helper_stlcx(CPUTriCoreState
*env
, uint32_t ea
)
2087 save_context_lower(env
, ea
);
2090 void helper_stucx(CPUTriCoreState
*env
, uint32_t ea
)
2092 save_context_upper(env
, ea
);
2095 void helper_psw_write(CPUTriCoreState
*env
, uint32_t arg
)
2097 psw_write(env
, arg
);
2100 uint32_t helper_psw_read(CPUTriCoreState
*env
)
2102 return psw_read(env
);
2106 static inline void QEMU_NORETURN
do_raise_exception_err(CPUTriCoreState
*env
,
2111 CPUState
*cs
= CPU(tricore_env_get_cpu(env
));
2112 cs
->exception_index
= exception
;
2113 env
->error_code
= error_code
;
2116 /* now we have a real cpu fault */
2117 cpu_restore_state(cs
, pc
);
2123 void tlb_fill(CPUState
*cs
, target_ulong addr
, int is_write
, int mmu_idx
,
2127 ret
= cpu_tricore_handle_mmu_fault(cs
, addr
, is_write
, mmu_idx
);
2129 TriCoreCPU
*cpu
= TRICORE_CPU(cs
);
2130 CPUTriCoreState
*env
= &cpu
->env
;
2131 do_raise_exception_err(env
, cs
->exception_index
,
2132 env
->error_code
, retaddr
);