target-mips: add mips32r6-generic CPU definition
[qemu/ar7.git] / target-tricore / op_helper.c
blob10ed541dfd665833a63760141bbbf3c37fbe2d09
1 /*
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/>.
17 #include <stdlib.h>
18 #include "cpu.h"
19 #include "qemu/host-utils.h"
20 #include "exec/helper-proto.h"
21 #include "exec/cpu_ldst.h"
22 #include <zlib.h> /* for crc32 */
24 /* Addressing mode helper */
26 static uint16_t reverse16(uint16_t val)
28 uint8_t high = (uint8_t)(val >> 8);
29 uint8_t low = (uint8_t)(val & 0xff);
31 uint16_t rh, rl;
33 rl = (uint16_t)((high * 0x0202020202ULL & 0x010884422010ULL) % 1023);
34 rh = (uint16_t)((low * 0x0202020202ULL & 0x010884422010ULL) % 1023);
36 return (rh << 8) | rl;
39 uint32_t helper_br_update(uint32_t reg)
41 uint32_t index = reg & 0xffff;
42 uint32_t incr = reg >> 16;
43 uint32_t new_index = reverse16(reverse16(index) + reverse16(incr));
44 return reg - index + new_index;
47 uint32_t helper_circ_update(uint32_t reg, uint32_t off)
49 uint32_t index = reg & 0xffff;
50 uint32_t length = reg >> 16;
51 int32_t new_index = index + off;
52 if (new_index < 0) {
53 new_index += length;
54 } else {
55 new_index %= length;
57 return reg - index + new_index;
60 static uint32_t ssov32(CPUTriCoreState *env, int64_t arg)
62 uint32_t ret;
63 int64_t max_pos = INT32_MAX;
64 int64_t max_neg = INT32_MIN;
65 if (arg > max_pos) {
66 env->PSW_USB_V = (1 << 31);
67 env->PSW_USB_SV = (1 << 31);
68 ret = (target_ulong)max_pos;
69 } else {
70 if (arg < max_neg) {
71 env->PSW_USB_V = (1 << 31);
72 env->PSW_USB_SV = (1 << 31);
73 ret = (target_ulong)max_neg;
74 } else {
75 env->PSW_USB_V = 0;
76 ret = (target_ulong)arg;
79 env->PSW_USB_AV = arg ^ arg * 2u;
80 env->PSW_USB_SAV |= env->PSW_USB_AV;
81 return ret;
84 static uint32_t suov32_pos(CPUTriCoreState *env, uint64_t arg)
86 uint32_t ret;
87 uint64_t max_pos = UINT32_MAX;
88 if (arg > max_pos) {
89 env->PSW_USB_V = (1 << 31);
90 env->PSW_USB_SV = (1 << 31);
91 ret = (target_ulong)max_pos;
92 } else {
93 env->PSW_USB_V = 0;
94 ret = (target_ulong)arg;
96 env->PSW_USB_AV = arg ^ arg * 2u;
97 env->PSW_USB_SAV |= env->PSW_USB_AV;
98 return ret;
101 static uint32_t suov32_neg(CPUTriCoreState *env, int64_t arg)
103 uint32_t ret;
105 if (arg < 0) {
106 env->PSW_USB_V = (1 << 31);
107 env->PSW_USB_SV = (1 << 31);
108 ret = 0;
109 } else {
110 env->PSW_USB_V = 0;
111 ret = (target_ulong)arg;
113 env->PSW_USB_AV = arg ^ arg * 2u;
114 env->PSW_USB_SAV |= env->PSW_USB_AV;
115 return ret;
118 static uint32_t ssov16(CPUTriCoreState *env, int32_t hw0, int32_t hw1)
120 int32_t max_pos = INT16_MAX;
121 int32_t max_neg = INT16_MIN;
122 int32_t av0, av1;
124 env->PSW_USB_V = 0;
125 av0 = hw0 ^ hw0 * 2u;
126 if (hw0 > max_pos) {
127 env->PSW_USB_V = (1 << 31);
128 hw0 = max_pos;
129 } else if (hw0 < max_neg) {
130 env->PSW_USB_V = (1 << 31);
131 hw0 = max_neg;
134 av1 = hw1 ^ hw1 * 2u;
135 if (hw1 > max_pos) {
136 env->PSW_USB_V = (1 << 31);
137 hw1 = max_pos;
138 } else if (hw1 < max_neg) {
139 env->PSW_USB_V = (1 << 31);
140 hw1 = max_neg;
143 env->PSW_USB_SV |= env->PSW_USB_V;
144 env->PSW_USB_AV = (av0 | av1) << 16;
145 env->PSW_USB_SAV |= env->PSW_USB_AV;
146 return (hw0 & 0xffff) | (hw1 << 16);
149 static uint32_t suov16(CPUTriCoreState *env, int32_t hw0, int32_t hw1)
151 int32_t max_pos = UINT16_MAX;
152 int32_t av0, av1;
154 env->PSW_USB_V = 0;
155 av0 = hw0 ^ hw0 * 2u;
156 if (hw0 > max_pos) {
157 env->PSW_USB_V = (1 << 31);
158 hw0 = max_pos;
159 } else if (hw0 < 0) {
160 env->PSW_USB_V = (1 << 31);
161 hw0 = 0;
164 av1 = hw1 ^ hw1 * 2u;
165 if (hw1 > max_pos) {
166 env->PSW_USB_V = (1 << 31);
167 hw1 = max_pos;
168 } else if (hw1 < 0) {
169 env->PSW_USB_V = (1 << 31);
170 hw1 = 0;
173 env->PSW_USB_SV |= env->PSW_USB_V;
174 env->PSW_USB_AV = (av0 | av1) << 16;
175 env->PSW_USB_SAV |= env->PSW_USB_AV;
176 return (hw0 & 0xffff) | (hw1 << 16);
179 target_ulong helper_add_ssov(CPUTriCoreState *env, target_ulong r1,
180 target_ulong r2)
182 int64_t t1 = sextract64(r1, 0, 32);
183 int64_t t2 = sextract64(r2, 0, 32);
184 int64_t result = t1 + t2;
185 return ssov32(env, result);
188 uint64_t helper_add64_ssov(CPUTriCoreState *env, uint64_t r1, uint64_t r2)
190 uint64_t result;
191 int64_t ovf;
193 result = r1 + r2;
194 ovf = (result ^ r1) & ~(r1 ^ r2);
195 env->PSW_USB_AV = (result ^ result * 2u) >> 32;
196 env->PSW_USB_SAV |= env->PSW_USB_AV;
197 if (ovf < 0) {
198 env->PSW_USB_V = (1 << 31);
199 env->PSW_USB_SV = (1 << 31);
200 /* ext_ret > MAX_INT */
201 if ((int64_t)r1 >= 0) {
202 result = INT64_MAX;
203 /* ext_ret < MIN_INT */
204 } else {
205 result = INT64_MIN;
207 } else {
208 env->PSW_USB_V = 0;
210 return result;
213 target_ulong helper_add_h_ssov(CPUTriCoreState *env, target_ulong r1,
214 target_ulong r2)
216 int32_t ret_hw0, ret_hw1;
218 ret_hw0 = sextract32(r1, 0, 16) + sextract32(r2, 0, 16);
219 ret_hw1 = sextract32(r1, 16, 16) + sextract32(r2, 16, 16);
220 return ssov16(env, ret_hw0, ret_hw1);
223 uint32_t helper_addr_h_ssov(CPUTriCoreState *env, uint64_t r1, uint32_t r2_l,
224 uint32_t r2_h)
226 int64_t mul_res0 = sextract64(r1, 0, 32);
227 int64_t mul_res1 = sextract64(r1, 32, 32);
228 int64_t r2_low = sextract64(r2_l, 0, 32);
229 int64_t r2_high = sextract64(r2_h, 0, 32);
230 int64_t result0, result1;
231 uint32_t ovf0, ovf1;
232 uint32_t avf0, avf1;
234 ovf0 = ovf1 = 0;
236 result0 = r2_low + mul_res0 + 0x8000;
237 result1 = r2_high + mul_res1 + 0x8000;
239 avf0 = result0 * 2u;
240 avf0 = result0 ^ avf0;
241 avf1 = result1 * 2u;
242 avf1 = result1 ^ avf1;
244 if (result0 > INT32_MAX) {
245 ovf0 = (1 << 31);
246 result0 = INT32_MAX;
247 } else if (result0 < INT32_MIN) {
248 ovf0 = (1 << 31);
249 result0 = INT32_MIN;
252 if (result1 > INT32_MAX) {
253 ovf1 = (1 << 31);
254 result1 = INT32_MAX;
255 } else if (result1 < INT32_MIN) {
256 ovf1 = (1 << 31);
257 result1 = INT32_MIN;
260 env->PSW_USB_V = ovf0 | ovf1;
261 env->PSW_USB_SV |= env->PSW_USB_V;
263 env->PSW_USB_AV = avf0 | avf1;
264 env->PSW_USB_SAV |= env->PSW_USB_AV;
266 return (result1 & 0xffff0000ULL) | ((result0 >> 16) & 0xffffULL);
269 uint32_t helper_addsur_h_ssov(CPUTriCoreState *env, uint64_t r1, uint32_t r2_l,
270 uint32_t r2_h)
272 int64_t mul_res0 = sextract64(r1, 0, 32);
273 int64_t mul_res1 = sextract64(r1, 32, 32);
274 int64_t r2_low = sextract64(r2_l, 0, 32);
275 int64_t r2_high = sextract64(r2_h, 0, 32);
276 int64_t result0, result1;
277 uint32_t ovf0, ovf1;
278 uint32_t avf0, avf1;
280 ovf0 = ovf1 = 0;
282 result0 = r2_low - mul_res0 + 0x8000;
283 result1 = r2_high + mul_res1 + 0x8000;
285 avf0 = result0 * 2u;
286 avf0 = result0 ^ avf0;
287 avf1 = result1 * 2u;
288 avf1 = result1 ^ avf1;
290 if (result0 > INT32_MAX) {
291 ovf0 = (1 << 31);
292 result0 = INT32_MAX;
293 } else if (result0 < INT32_MIN) {
294 ovf0 = (1 << 31);
295 result0 = INT32_MIN;
298 if (result1 > INT32_MAX) {
299 ovf1 = (1 << 31);
300 result1 = INT32_MAX;
301 } else if (result1 < INT32_MIN) {
302 ovf1 = (1 << 31);
303 result1 = INT32_MIN;
306 env->PSW_USB_V = ovf0 | ovf1;
307 env->PSW_USB_SV |= env->PSW_USB_V;
309 env->PSW_USB_AV = avf0 | avf1;
310 env->PSW_USB_SAV |= env->PSW_USB_AV;
312 return (result1 & 0xffff0000ULL) | ((result0 >> 16) & 0xffffULL);
316 target_ulong helper_add_suov(CPUTriCoreState *env, target_ulong r1,
317 target_ulong r2)
319 int64_t t1 = extract64(r1, 0, 32);
320 int64_t t2 = extract64(r2, 0, 32);
321 int64_t result = t1 + t2;
322 return suov32_pos(env, result);
325 target_ulong helper_add_h_suov(CPUTriCoreState *env, target_ulong r1,
326 target_ulong r2)
328 int32_t ret_hw0, ret_hw1;
330 ret_hw0 = extract32(r1, 0, 16) + extract32(r2, 0, 16);
331 ret_hw1 = extract32(r1, 16, 16) + extract32(r2, 16, 16);
332 return suov16(env, ret_hw0, ret_hw1);
335 target_ulong helper_sub_ssov(CPUTriCoreState *env, target_ulong r1,
336 target_ulong r2)
338 int64_t t1 = sextract64(r1, 0, 32);
339 int64_t t2 = sextract64(r2, 0, 32);
340 int64_t result = t1 - t2;
341 return ssov32(env, result);
344 uint64_t helper_sub64_ssov(CPUTriCoreState *env, uint64_t r1, uint64_t r2)
346 uint64_t result;
347 int64_t ovf;
349 result = r1 - r2;
350 ovf = (result ^ r1) & (r1 ^ r2);
351 env->PSW_USB_AV = (result ^ result * 2u) >> 32;
352 env->PSW_USB_SAV |= env->PSW_USB_AV;
353 if (ovf < 0) {
354 env->PSW_USB_V = (1 << 31);
355 env->PSW_USB_SV = (1 << 31);
356 /* ext_ret > MAX_INT */
357 if ((int64_t)r1 >= 0) {
358 result = INT64_MAX;
359 /* ext_ret < MIN_INT */
360 } else {
361 result = INT64_MIN;
363 } else {
364 env->PSW_USB_V = 0;
366 return result;
369 target_ulong helper_sub_h_ssov(CPUTriCoreState *env, target_ulong r1,
370 target_ulong r2)
372 int32_t ret_hw0, ret_hw1;
374 ret_hw0 = sextract32(r1, 0, 16) - sextract32(r2, 0, 16);
375 ret_hw1 = sextract32(r1, 16, 16) - sextract32(r2, 16, 16);
376 return ssov16(env, ret_hw0, ret_hw1);
379 uint32_t helper_subr_h_ssov(CPUTriCoreState *env, uint64_t r1, uint32_t r2_l,
380 uint32_t r2_h)
382 int64_t mul_res0 = sextract64(r1, 0, 32);
383 int64_t mul_res1 = sextract64(r1, 32, 32);
384 int64_t r2_low = sextract64(r2_l, 0, 32);
385 int64_t r2_high = sextract64(r2_h, 0, 32);
386 int64_t result0, result1;
387 uint32_t ovf0, ovf1;
388 uint32_t avf0, avf1;
390 ovf0 = ovf1 = 0;
392 result0 = r2_low - mul_res0 + 0x8000;
393 result1 = r2_high - mul_res1 + 0x8000;
395 avf0 = result0 * 2u;
396 avf0 = result0 ^ avf0;
397 avf1 = result1 * 2u;
398 avf1 = result1 ^ avf1;
400 if (result0 > INT32_MAX) {
401 ovf0 = (1 << 31);
402 result0 = INT32_MAX;
403 } else if (result0 < INT32_MIN) {
404 ovf0 = (1 << 31);
405 result0 = INT32_MIN;
408 if (result1 > INT32_MAX) {
409 ovf1 = (1 << 31);
410 result1 = INT32_MAX;
411 } else if (result1 < INT32_MIN) {
412 ovf1 = (1 << 31);
413 result1 = INT32_MIN;
416 env->PSW_USB_V = ovf0 | ovf1;
417 env->PSW_USB_SV |= env->PSW_USB_V;
419 env->PSW_USB_AV = avf0 | avf1;
420 env->PSW_USB_SAV |= env->PSW_USB_AV;
422 return (result1 & 0xffff0000ULL) | ((result0 >> 16) & 0xffffULL);
425 uint32_t helper_subadr_h_ssov(CPUTriCoreState *env, uint64_t r1, uint32_t r2_l,
426 uint32_t r2_h)
428 int64_t mul_res0 = sextract64(r1, 0, 32);
429 int64_t mul_res1 = sextract64(r1, 32, 32);
430 int64_t r2_low = sextract64(r2_l, 0, 32);
431 int64_t r2_high = sextract64(r2_h, 0, 32);
432 int64_t result0, result1;
433 uint32_t ovf0, ovf1;
434 uint32_t avf0, avf1;
436 ovf0 = ovf1 = 0;
438 result0 = r2_low + mul_res0 + 0x8000;
439 result1 = r2_high - mul_res1 + 0x8000;
441 avf0 = result0 * 2u;
442 avf0 = result0 ^ avf0;
443 avf1 = result1 * 2u;
444 avf1 = result1 ^ avf1;
446 if (result0 > INT32_MAX) {
447 ovf0 = (1 << 31);
448 result0 = INT32_MAX;
449 } else if (result0 < INT32_MIN) {
450 ovf0 = (1 << 31);
451 result0 = INT32_MIN;
454 if (result1 > INT32_MAX) {
455 ovf1 = (1 << 31);
456 result1 = INT32_MAX;
457 } else if (result1 < INT32_MIN) {
458 ovf1 = (1 << 31);
459 result1 = INT32_MIN;
462 env->PSW_USB_V = ovf0 | ovf1;
463 env->PSW_USB_SV |= env->PSW_USB_V;
465 env->PSW_USB_AV = avf0 | avf1;
466 env->PSW_USB_SAV |= env->PSW_USB_AV;
468 return (result1 & 0xffff0000ULL) | ((result0 >> 16) & 0xffffULL);
471 target_ulong helper_sub_suov(CPUTriCoreState *env, target_ulong r1,
472 target_ulong r2)
474 int64_t t1 = extract64(r1, 0, 32);
475 int64_t t2 = extract64(r2, 0, 32);
476 int64_t result = t1 - t2;
477 return suov32_neg(env, result);
480 target_ulong helper_sub_h_suov(CPUTriCoreState *env, target_ulong r1,
481 target_ulong r2)
483 int32_t ret_hw0, ret_hw1;
485 ret_hw0 = extract32(r1, 0, 16) - extract32(r2, 0, 16);
486 ret_hw1 = extract32(r1, 16, 16) - extract32(r2, 16, 16);
487 return suov16(env, ret_hw0, ret_hw1);
490 target_ulong helper_mul_ssov(CPUTriCoreState *env, target_ulong r1,
491 target_ulong r2)
493 int64_t t1 = sextract64(r1, 0, 32);
494 int64_t t2 = sextract64(r2, 0, 32);
495 int64_t result = t1 * t2;
496 return ssov32(env, result);
499 target_ulong helper_mul_suov(CPUTriCoreState *env, target_ulong r1,
500 target_ulong r2)
502 int64_t t1 = extract64(r1, 0, 32);
503 int64_t t2 = extract64(r2, 0, 32);
504 int64_t result = t1 * t2;
506 return suov32_pos(env, result);
509 target_ulong helper_sha_ssov(CPUTriCoreState *env, target_ulong r1,
510 target_ulong r2)
512 int64_t t1 = sextract64(r1, 0, 32);
513 int32_t t2 = sextract64(r2, 0, 6);
514 int64_t result;
515 if (t2 == 0) {
516 result = t1;
517 } else if (t2 > 0) {
518 result = t1 << t2;
519 } else {
520 result = t1 >> -t2;
522 return ssov32(env, result);
525 uint32_t helper_abs_ssov(CPUTriCoreState *env, target_ulong r1)
527 target_ulong result;
528 result = ((int32_t)r1 >= 0) ? r1 : (0 - r1);
529 return ssov32(env, result);
532 uint32_t helper_abs_h_ssov(CPUTriCoreState *env, target_ulong r1)
534 int32_t ret_h0, ret_h1;
536 ret_h0 = sextract32(r1, 0, 16);
537 ret_h0 = (ret_h0 >= 0) ? ret_h0 : (0 - ret_h0);
539 ret_h1 = sextract32(r1, 16, 16);
540 ret_h1 = (ret_h1 >= 0) ? ret_h1 : (0 - ret_h1);
542 return ssov16(env, ret_h0, ret_h1);
545 target_ulong helper_absdif_ssov(CPUTriCoreState *env, target_ulong r1,
546 target_ulong r2)
548 int64_t t1 = sextract64(r1, 0, 32);
549 int64_t t2 = sextract64(r2, 0, 32);
550 int64_t result;
552 if (t1 > t2) {
553 result = t1 - t2;
554 } else {
555 result = t2 - t1;
557 return ssov32(env, result);
560 uint32_t helper_absdif_h_ssov(CPUTriCoreState *env, target_ulong r1,
561 target_ulong r2)
563 int32_t t1, t2;
564 int32_t ret_h0, ret_h1;
566 t1 = sextract32(r1, 0, 16);
567 t2 = sextract32(r2, 0, 16);
568 if (t1 > t2) {
569 ret_h0 = t1 - t2;
570 } else {
571 ret_h0 = t2 - t1;
574 t1 = sextract32(r1, 16, 16);
575 t2 = sextract32(r2, 16, 16);
576 if (t1 > t2) {
577 ret_h1 = t1 - t2;
578 } else {
579 ret_h1 = t2 - t1;
582 return ssov16(env, ret_h0, ret_h1);
585 target_ulong helper_madd32_ssov(CPUTriCoreState *env, target_ulong r1,
586 target_ulong r2, target_ulong r3)
588 int64_t t1 = sextract64(r1, 0, 32);
589 int64_t t2 = sextract64(r2, 0, 32);
590 int64_t t3 = sextract64(r3, 0, 32);
591 int64_t result;
593 result = t2 + (t1 * t3);
594 return ssov32(env, result);
597 target_ulong helper_madd32_suov(CPUTriCoreState *env, target_ulong r1,
598 target_ulong r2, target_ulong r3)
600 uint64_t t1 = extract64(r1, 0, 32);
601 uint64_t t2 = extract64(r2, 0, 32);
602 uint64_t t3 = extract64(r3, 0, 32);
603 int64_t result;
605 result = t2 + (t1 * t3);
606 return suov32_pos(env, result);
609 uint64_t helper_madd64_ssov(CPUTriCoreState *env, target_ulong r1,
610 uint64_t r2, target_ulong r3)
612 uint64_t ret, ovf;
613 int64_t t1 = sextract64(r1, 0, 32);
614 int64_t t3 = sextract64(r3, 0, 32);
615 int64_t mul;
617 mul = t1 * t3;
618 ret = mul + r2;
619 ovf = (ret ^ mul) & ~(mul ^ r2);
621 t1 = ret >> 32;
622 env->PSW_USB_AV = t1 ^ t1 * 2u;
623 env->PSW_USB_SAV |= env->PSW_USB_AV;
625 if ((int64_t)ovf < 0) {
626 env->PSW_USB_V = (1 << 31);
627 env->PSW_USB_SV = (1 << 31);
628 /* ext_ret > MAX_INT */
629 if (mul >= 0) {
630 ret = INT64_MAX;
631 /* ext_ret < MIN_INT */
632 } else {
633 ret = INT64_MIN;
635 } else {
636 env->PSW_USB_V = 0;
639 return ret;
642 uint32_t
643 helper_madd32_q_add_ssov(CPUTriCoreState *env, uint64_t r1, uint64_t r2)
645 int64_t result;
647 result = (r1 + r2);
649 env->PSW_USB_AV = (result ^ result * 2u);
650 env->PSW_USB_SAV |= env->PSW_USB_AV;
652 /* we do the saturation by hand, since we produce an overflow on the host
653 if the mul before was (0x80000000 * 0x80000000) << 1). If this is the
654 case, we flip the saturated value. */
655 if (r2 == 0x8000000000000000LL) {
656 if (result > 0x7fffffffLL) {
657 env->PSW_USB_V = (1 << 31);
658 env->PSW_USB_SV = (1 << 31);
659 result = INT32_MIN;
660 } else if (result < -0x80000000LL) {
661 env->PSW_USB_V = (1 << 31);
662 env->PSW_USB_SV = (1 << 31);
663 result = INT32_MAX;
664 } else {
665 env->PSW_USB_V = 0;
667 } else {
668 if (result > 0x7fffffffLL) {
669 env->PSW_USB_V = (1 << 31);
670 env->PSW_USB_SV = (1 << 31);
671 result = INT32_MAX;
672 } else if (result < -0x80000000LL) {
673 env->PSW_USB_V = (1 << 31);
674 env->PSW_USB_SV = (1 << 31);
675 result = INT32_MIN;
676 } else {
677 env->PSW_USB_V = 0;
680 return (uint32_t)result;
683 uint64_t helper_madd64_q_ssov(CPUTriCoreState *env, uint64_t r1, uint32_t r2,
684 uint32_t r3, uint32_t n)
686 int64_t t1 = (int64_t)r1;
687 int64_t t2 = sextract64(r2, 0, 32);
688 int64_t t3 = sextract64(r3, 0, 32);
689 int64_t result, mul;
690 int64_t ovf;
692 mul = (t2 * t3) << n;
693 result = mul + t1;
695 env->PSW_USB_AV = (result ^ result * 2u) >> 32;
696 env->PSW_USB_SAV |= env->PSW_USB_AV;
698 ovf = (result ^ mul) & ~(mul ^ t1);
699 /* we do the saturation by hand, since we produce an overflow on the host
700 if the mul was (0x80000000 * 0x80000000) << 1). If this is the
701 case, we flip the saturated value. */
702 if ((r2 == 0x80000000) && (r3 == 0x80000000) && (n == 1)) {
703 if (ovf >= 0) {
704 env->PSW_USB_V = (1 << 31);
705 env->PSW_USB_SV = (1 << 31);
706 /* ext_ret > MAX_INT */
707 if (mul < 0) {
708 result = INT64_MAX;
709 /* ext_ret < MIN_INT */
710 } else {
711 result = INT64_MIN;
713 } else {
714 env->PSW_USB_V = 0;
716 } else {
717 if (ovf < 0) {
718 env->PSW_USB_V = (1 << 31);
719 env->PSW_USB_SV = (1 << 31);
720 /* ext_ret > MAX_INT */
721 if (mul >= 0) {
722 result = INT64_MAX;
723 /* ext_ret < MIN_INT */
724 } else {
725 result = INT64_MIN;
727 } else {
728 env->PSW_USB_V = 0;
731 return (uint64_t)result;
734 uint32_t helper_maddr_q_ssov(CPUTriCoreState *env, uint32_t r1, uint32_t r2,
735 uint32_t r3, uint32_t n)
737 int64_t t1 = sextract64(r1, 0, 32);
738 int64_t t2 = sextract64(r2, 0, 32);
739 int64_t t3 = sextract64(r3, 0, 32);
740 int64_t mul, ret;
742 if ((t2 == -0x8000ll) && (t3 == -0x8000ll) && (n == 1)) {
743 mul = 0x7fffffff;
744 } else {
745 mul = (t2 * t3) << n;
748 ret = t1 + mul + 0x8000;
750 env->PSW_USB_AV = ret ^ ret * 2u;
751 env->PSW_USB_SAV |= env->PSW_USB_AV;
753 if (ret > 0x7fffffffll) {
754 env->PSW_USB_V = (1 << 31);
755 env->PSW_USB_SV |= env->PSW_USB_V;
756 ret = INT32_MAX;
757 } else if (ret < -0x80000000ll) {
758 env->PSW_USB_V = (1 << 31);
759 env->PSW_USB_SV |= env->PSW_USB_V;
760 ret = INT32_MIN;
761 } else {
762 env->PSW_USB_V = 0;
764 return ret & 0xffff0000ll;
767 uint64_t helper_madd64_suov(CPUTriCoreState *env, target_ulong r1,
768 uint64_t r2, target_ulong r3)
770 uint64_t ret, mul;
771 uint64_t t1 = extract64(r1, 0, 32);
772 uint64_t t3 = extract64(r3, 0, 32);
774 mul = t1 * t3;
775 ret = mul + r2;
777 t1 = ret >> 32;
778 env->PSW_USB_AV = t1 ^ t1 * 2u;
779 env->PSW_USB_SAV |= env->PSW_USB_AV;
781 if (ret < r2) {
782 env->PSW_USB_V = (1 << 31);
783 env->PSW_USB_SV = (1 << 31);
784 /* saturate */
785 ret = UINT64_MAX;
786 } else {
787 env->PSW_USB_V = 0;
789 return ret;
792 target_ulong helper_msub32_ssov(CPUTriCoreState *env, target_ulong r1,
793 target_ulong r2, target_ulong r3)
795 int64_t t1 = sextract64(r1, 0, 32);
796 int64_t t2 = sextract64(r2, 0, 32);
797 int64_t t3 = sextract64(r3, 0, 32);
798 int64_t result;
800 result = t2 - (t1 * t3);
801 return ssov32(env, result);
804 target_ulong helper_msub32_suov(CPUTriCoreState *env, target_ulong r1,
805 target_ulong r2, target_ulong r3)
807 uint64_t t1 = extract64(r1, 0, 32);
808 uint64_t t2 = extract64(r2, 0, 32);
809 uint64_t t3 = extract64(r3, 0, 32);
810 uint64_t result;
811 uint64_t mul;
813 mul = (t1 * t3);
814 result = t2 - mul;
816 env->PSW_USB_AV = result ^ result * 2u;
817 env->PSW_USB_SAV |= env->PSW_USB_AV;
818 /* we calculate ovf by hand here, because the multiplication can overflow on
819 the host, which would give false results if we compare to less than
820 zero */
821 if (mul > t2) {
822 env->PSW_USB_V = (1 << 31);
823 env->PSW_USB_SV = (1 << 31);
824 result = 0;
825 } else {
826 env->PSW_USB_V = 0;
828 return result;
831 uint64_t helper_msub64_ssov(CPUTriCoreState *env, target_ulong r1,
832 uint64_t r2, target_ulong r3)
834 uint64_t ret, ovf;
835 int64_t t1 = sextract64(r1, 0, 32);
836 int64_t t3 = sextract64(r3, 0, 32);
837 int64_t mul;
839 mul = t1 * t3;
840 ret = r2 - mul;
841 ovf = (ret ^ r2) & (mul ^ r2);
843 t1 = ret >> 32;
844 env->PSW_USB_AV = t1 ^ t1 * 2u;
845 env->PSW_USB_SAV |= env->PSW_USB_AV;
847 if ((int64_t)ovf < 0) {
848 env->PSW_USB_V = (1 << 31);
849 env->PSW_USB_SV = (1 << 31);
850 /* ext_ret > MAX_INT */
851 if (mul < 0) {
852 ret = INT64_MAX;
853 /* ext_ret < MIN_INT */
854 } else {
855 ret = INT64_MIN;
857 } else {
858 env->PSW_USB_V = 0;
860 return ret;
863 uint64_t helper_msub64_suov(CPUTriCoreState *env, target_ulong r1,
864 uint64_t r2, target_ulong r3)
866 uint64_t ret, mul;
867 uint64_t t1 = extract64(r1, 0, 32);
868 uint64_t t3 = extract64(r3, 0, 32);
870 mul = t1 * t3;
871 ret = r2 - mul;
873 t1 = ret >> 32;
874 env->PSW_USB_AV = t1 ^ t1 * 2u;
875 env->PSW_USB_SAV |= env->PSW_USB_AV;
877 if (ret > r2) {
878 env->PSW_USB_V = (1 << 31);
879 env->PSW_USB_SV = (1 << 31);
880 /* saturate */
881 ret = 0;
882 } else {
883 env->PSW_USB_V = 0;
885 return ret;
888 uint32_t
889 helper_msub32_q_sub_ssov(CPUTriCoreState *env, uint64_t r1, uint64_t r2)
891 int64_t result;
892 int64_t t1 = (int64_t)r1;
893 int64_t t2 = (int64_t)r2;
895 result = t1 - t2;
897 env->PSW_USB_AV = (result ^ result * 2u);
898 env->PSW_USB_SAV |= env->PSW_USB_AV;
900 /* we do the saturation by hand, since we produce an overflow on the host
901 if the mul before was (0x80000000 * 0x80000000) << 1). If this is the
902 case, we flip the saturated value. */
903 if (r2 == 0x8000000000000000LL) {
904 if (result > 0x7fffffffLL) {
905 env->PSW_USB_V = (1 << 31);
906 env->PSW_USB_SV = (1 << 31);
907 result = INT32_MIN;
908 } else if (result < -0x80000000LL) {
909 env->PSW_USB_V = (1 << 31);
910 env->PSW_USB_SV = (1 << 31);
911 result = INT32_MAX;
912 } else {
913 env->PSW_USB_V = 0;
915 } else {
916 if (result > 0x7fffffffLL) {
917 env->PSW_USB_V = (1 << 31);
918 env->PSW_USB_SV = (1 << 31);
919 result = INT32_MAX;
920 } else if (result < -0x80000000LL) {
921 env->PSW_USB_V = (1 << 31);
922 env->PSW_USB_SV = (1 << 31);
923 result = INT32_MIN;
924 } else {
925 env->PSW_USB_V = 0;
928 return (uint32_t)result;
931 uint64_t helper_msub64_q_ssov(CPUTriCoreState *env, uint64_t r1, uint32_t r2,
932 uint32_t r3, uint32_t n)
934 int64_t t1 = (int64_t)r1;
935 int64_t t2 = sextract64(r2, 0, 32);
936 int64_t t3 = sextract64(r3, 0, 32);
937 int64_t result, mul;
938 int64_t ovf;
940 mul = (t2 * t3) << n;
941 result = t1 - mul;
943 env->PSW_USB_AV = (result ^ result * 2u) >> 32;
944 env->PSW_USB_SAV |= env->PSW_USB_AV;
946 ovf = (result ^ t1) & (t1 ^ mul);
947 /* we do the saturation by hand, since we produce an overflow on the host
948 if the mul before was (0x80000000 * 0x80000000) << 1). If this is the
949 case, we flip the saturated value. */
950 if (mul == 0x8000000000000000LL) {
951 if (ovf >= 0) {
952 env->PSW_USB_V = (1 << 31);
953 env->PSW_USB_SV = (1 << 31);
954 /* ext_ret > MAX_INT */
955 if (mul >= 0) {
956 result = INT64_MAX;
957 /* ext_ret < MIN_INT */
958 } else {
959 result = INT64_MIN;
962 } else {
963 if (ovf < 0) {
964 env->PSW_USB_V = (1 << 31);
965 env->PSW_USB_SV = (1 << 31);
966 /* ext_ret > MAX_INT */
967 if (mul < 0) {
968 result = INT64_MAX;
969 /* ext_ret < MIN_INT */
970 } else {
971 result = INT64_MIN;
973 } else {
974 env->PSW_USB_V = 0;
978 return (uint64_t)result;
981 uint32_t helper_msubr_q_ssov(CPUTriCoreState *env, uint32_t r1, uint32_t r2,
982 uint32_t r3, uint32_t n)
984 int64_t t1 = sextract64(r1, 0, 32);
985 int64_t t2 = sextract64(r2, 0, 32);
986 int64_t t3 = sextract64(r3, 0, 32);
987 int64_t mul, ret;
989 if ((t2 == -0x8000ll) && (t3 == -0x8000ll) && (n == 1)) {
990 mul = 0x7fffffff;
991 } else {
992 mul = (t2 * t3) << n;
995 ret = t1 - mul + 0x8000;
997 env->PSW_USB_AV = ret ^ ret * 2u;
998 env->PSW_USB_SAV |= env->PSW_USB_AV;
1000 if (ret > 0x7fffffffll) {
1001 env->PSW_USB_V = (1 << 31);
1002 env->PSW_USB_SV |= env->PSW_USB_V;
1003 ret = INT32_MAX;
1004 } else if (ret < -0x80000000ll) {
1005 env->PSW_USB_V = (1 << 31);
1006 env->PSW_USB_SV |= env->PSW_USB_V;
1007 ret = INT32_MIN;
1008 } else {
1009 env->PSW_USB_V = 0;
1011 return ret & 0xffff0000ll;
1014 uint32_t helper_abs_b(CPUTriCoreState *env, target_ulong arg)
1016 int32_t b, i;
1017 int32_t ovf = 0;
1018 int32_t avf = 0;
1019 int32_t ret = 0;
1021 for (i = 0; i < 4; i++) {
1022 b = sextract32(arg, i * 8, 8);
1023 b = (b >= 0) ? b : (0 - b);
1024 ovf |= (b > 0x7F) || (b < -0x80);
1025 avf |= b ^ b * 2u;
1026 ret |= (b & 0xff) << (i * 8);
1029 env->PSW_USB_V = ovf << 31;
1030 env->PSW_USB_SV |= env->PSW_USB_V;
1031 env->PSW_USB_AV = avf << 24;
1032 env->PSW_USB_SAV |= env->PSW_USB_AV;
1034 return ret;
1037 uint32_t helper_abs_h(CPUTriCoreState *env, target_ulong arg)
1039 int32_t h, i;
1040 int32_t ovf = 0;
1041 int32_t avf = 0;
1042 int32_t ret = 0;
1044 for (i = 0; i < 2; i++) {
1045 h = sextract32(arg, i * 16, 16);
1046 h = (h >= 0) ? h : (0 - h);
1047 ovf |= (h > 0x7FFF) || (h < -0x8000);
1048 avf |= h ^ h * 2u;
1049 ret |= (h & 0xffff) << (i * 16);
1052 env->PSW_USB_V = ovf << 31;
1053 env->PSW_USB_SV |= env->PSW_USB_V;
1054 env->PSW_USB_AV = avf << 16;
1055 env->PSW_USB_SAV |= env->PSW_USB_AV;
1057 return ret;
1060 uint32_t helper_absdif_b(CPUTriCoreState *env, target_ulong r1, target_ulong r2)
1062 int32_t b, i;
1063 int32_t extr_r2;
1064 int32_t ovf = 0;
1065 int32_t avf = 0;
1066 int32_t ret = 0;
1068 for (i = 0; i < 4; i++) {
1069 extr_r2 = sextract32(r2, i * 8, 8);
1070 b = sextract32(r1, i * 8, 8);
1071 b = (b > extr_r2) ? (b - extr_r2) : (extr_r2 - b);
1072 ovf |= (b > 0x7F) || (b < -0x80);
1073 avf |= b ^ b * 2u;
1074 ret |= (b & 0xff) << (i * 8);
1077 env->PSW_USB_V = ovf << 31;
1078 env->PSW_USB_SV |= env->PSW_USB_V;
1079 env->PSW_USB_AV = avf << 24;
1080 env->PSW_USB_SAV |= env->PSW_USB_AV;
1081 return ret;
1084 uint32_t helper_absdif_h(CPUTriCoreState *env, target_ulong r1, target_ulong r2)
1086 int32_t h, i;
1087 int32_t extr_r2;
1088 int32_t ovf = 0;
1089 int32_t avf = 0;
1090 int32_t ret = 0;
1092 for (i = 0; i < 2; i++) {
1093 extr_r2 = sextract32(r2, i * 16, 16);
1094 h = sextract32(r1, i * 16, 16);
1095 h = (h > extr_r2) ? (h - extr_r2) : (extr_r2 - h);
1096 ovf |= (h > 0x7FFF) || (h < -0x8000);
1097 avf |= h ^ h * 2u;
1098 ret |= (h & 0xffff) << (i * 16);
1101 env->PSW_USB_V = ovf << 31;
1102 env->PSW_USB_SV |= env->PSW_USB_V;
1103 env->PSW_USB_AV = avf << 16;
1104 env->PSW_USB_SAV |= env->PSW_USB_AV;
1106 return ret;
1109 uint32_t helper_addr_h(CPUTriCoreState *env, uint64_t r1, uint32_t r2_l,
1110 uint32_t r2_h)
1112 int64_t mul_res0 = sextract64(r1, 0, 32);
1113 int64_t mul_res1 = sextract64(r1, 32, 32);
1114 int64_t r2_low = sextract64(r2_l, 0, 32);
1115 int64_t r2_high = sextract64(r2_h, 0, 32);
1116 int64_t result0, result1;
1117 uint32_t ovf0, ovf1;
1118 uint32_t avf0, avf1;
1120 ovf0 = ovf1 = 0;
1122 result0 = r2_low + mul_res0 + 0x8000;
1123 result1 = r2_high + mul_res1 + 0x8000;
1125 if ((result0 > INT32_MAX) || (result0 < INT32_MIN)) {
1126 ovf0 = (1 << 31);
1129 if ((result1 > INT32_MAX) || (result1 < INT32_MIN)) {
1130 ovf1 = (1 << 31);
1133 env->PSW_USB_V = ovf0 | ovf1;
1134 env->PSW_USB_SV |= env->PSW_USB_V;
1136 avf0 = result0 * 2u;
1137 avf0 = result0 ^ avf0;
1138 avf1 = result1 * 2u;
1139 avf1 = result1 ^ avf1;
1141 env->PSW_USB_AV = avf0 | avf1;
1142 env->PSW_USB_SAV |= env->PSW_USB_AV;
1144 return (result1 & 0xffff0000ULL) | ((result0 >> 16) & 0xffffULL);
1147 uint32_t helper_addsur_h(CPUTriCoreState *env, uint64_t r1, uint32_t r2_l,
1148 uint32_t r2_h)
1150 int64_t mul_res0 = sextract64(r1, 0, 32);
1151 int64_t mul_res1 = sextract64(r1, 32, 32);
1152 int64_t r2_low = sextract64(r2_l, 0, 32);
1153 int64_t r2_high = sextract64(r2_h, 0, 32);
1154 int64_t result0, result1;
1155 uint32_t ovf0, ovf1;
1156 uint32_t avf0, avf1;
1158 ovf0 = ovf1 = 0;
1160 result0 = r2_low - mul_res0 + 0x8000;
1161 result1 = r2_high + mul_res1 + 0x8000;
1163 if ((result0 > INT32_MAX) || (result0 < INT32_MIN)) {
1164 ovf0 = (1 << 31);
1167 if ((result1 > INT32_MAX) || (result1 < INT32_MIN)) {
1168 ovf1 = (1 << 31);
1171 env->PSW_USB_V = ovf0 | ovf1;
1172 env->PSW_USB_SV |= env->PSW_USB_V;
1174 avf0 = result0 * 2u;
1175 avf0 = result0 ^ avf0;
1176 avf1 = result1 * 2u;
1177 avf1 = result1 ^ avf1;
1179 env->PSW_USB_AV = avf0 | avf1;
1180 env->PSW_USB_SAV |= env->PSW_USB_AV;
1182 return (result1 & 0xffff0000ULL) | ((result0 >> 16) & 0xffffULL);
1185 uint32_t helper_maddr_q(CPUTriCoreState *env, uint32_t r1, uint32_t r2,
1186 uint32_t r3, uint32_t n)
1188 int64_t t1 = sextract64(r1, 0, 32);
1189 int64_t t2 = sextract64(r2, 0, 32);
1190 int64_t t3 = sextract64(r3, 0, 32);
1191 int64_t mul, ret;
1193 if ((t2 == -0x8000ll) && (t3 == -0x8000ll) && (n == 1)) {
1194 mul = 0x7fffffff;
1195 } else {
1196 mul = (t2 * t3) << n;
1199 ret = t1 + mul + 0x8000;
1201 if ((ret > 0x7fffffffll) || (ret < -0x80000000ll)) {
1202 env->PSW_USB_V = (1 << 31);
1203 env->PSW_USB_SV |= env->PSW_USB_V;
1204 } else {
1205 env->PSW_USB_V = 0;
1207 env->PSW_USB_AV = ret ^ ret * 2u;
1208 env->PSW_USB_SAV |= env->PSW_USB_AV;
1210 return ret & 0xffff0000ll;
1213 uint32_t helper_add_b(CPUTriCoreState *env, target_ulong r1, target_ulong r2)
1215 int32_t b, i;
1216 int32_t extr_r1, extr_r2;
1217 int32_t ovf = 0;
1218 int32_t avf = 0;
1219 uint32_t ret = 0;
1221 for (i = 0; i < 4; i++) {
1222 extr_r1 = sextract32(r1, i * 8, 8);
1223 extr_r2 = sextract32(r2, i * 8, 8);
1225 b = extr_r1 + extr_r2;
1226 ovf |= ((b > 0x7f) || (b < -0x80));
1227 avf |= b ^ b * 2u;
1228 ret |= ((b & 0xff) << (i*8));
1231 env->PSW_USB_V = (ovf << 31);
1232 env->PSW_USB_SV |= env->PSW_USB_V;
1233 env->PSW_USB_AV = avf << 24;
1234 env->PSW_USB_SAV |= env->PSW_USB_AV;
1236 return ret;
1239 uint32_t helper_add_h(CPUTriCoreState *env, target_ulong r1, target_ulong r2)
1241 int32_t h, i;
1242 int32_t extr_r1, extr_r2;
1243 int32_t ovf = 0;
1244 int32_t avf = 0;
1245 int32_t ret = 0;
1247 for (i = 0; i < 2; i++) {
1248 extr_r1 = sextract32(r1, i * 16, 16);
1249 extr_r2 = sextract32(r2, i * 16, 16);
1250 h = extr_r1 + extr_r2;
1251 ovf |= ((h > 0x7fff) || (h < -0x8000));
1252 avf |= h ^ h * 2u;
1253 ret |= (h & 0xffff) << (i * 16);
1256 env->PSW_USB_V = (ovf << 31);
1257 env->PSW_USB_SV |= env->PSW_USB_V;
1258 env->PSW_USB_AV = (avf << 16);
1259 env->PSW_USB_SAV |= env->PSW_USB_AV;
1261 return ret;
1264 uint32_t helper_subr_h(CPUTriCoreState *env, uint64_t r1, uint32_t r2_l,
1265 uint32_t r2_h)
1267 int64_t mul_res0 = sextract64(r1, 0, 32);
1268 int64_t mul_res1 = sextract64(r1, 32, 32);
1269 int64_t r2_low = sextract64(r2_l, 0, 32);
1270 int64_t r2_high = sextract64(r2_h, 0, 32);
1271 int64_t result0, result1;
1272 uint32_t ovf0, ovf1;
1273 uint32_t avf0, avf1;
1275 ovf0 = ovf1 = 0;
1277 result0 = r2_low - mul_res0 + 0x8000;
1278 result1 = r2_high - mul_res1 + 0x8000;
1280 if ((result0 > INT32_MAX) || (result0 < INT32_MIN)) {
1281 ovf0 = (1 << 31);
1284 if ((result1 > INT32_MAX) || (result1 < INT32_MIN)) {
1285 ovf1 = (1 << 31);
1288 env->PSW_USB_V = ovf0 | ovf1;
1289 env->PSW_USB_SV |= env->PSW_USB_V;
1291 avf0 = result0 * 2u;
1292 avf0 = result0 ^ avf0;
1293 avf1 = result1 * 2u;
1294 avf1 = result1 ^ avf1;
1296 env->PSW_USB_AV = avf0 | avf1;
1297 env->PSW_USB_SAV |= env->PSW_USB_AV;
1299 return (result1 & 0xffff0000ULL) | ((result0 >> 16) & 0xffffULL);
1302 uint32_t helper_subadr_h(CPUTriCoreState *env, uint64_t r1, uint32_t r2_l,
1303 uint32_t r2_h)
1305 int64_t mul_res0 = sextract64(r1, 0, 32);
1306 int64_t mul_res1 = sextract64(r1, 32, 32);
1307 int64_t r2_low = sextract64(r2_l, 0, 32);
1308 int64_t r2_high = sextract64(r2_h, 0, 32);
1309 int64_t result0, result1;
1310 uint32_t ovf0, ovf1;
1311 uint32_t avf0, avf1;
1313 ovf0 = ovf1 = 0;
1315 result0 = r2_low + mul_res0 + 0x8000;
1316 result1 = r2_high - mul_res1 + 0x8000;
1318 if ((result0 > INT32_MAX) || (result0 < INT32_MIN)) {
1319 ovf0 = (1 << 31);
1322 if ((result1 > INT32_MAX) || (result1 < INT32_MIN)) {
1323 ovf1 = (1 << 31);
1326 env->PSW_USB_V = ovf0 | ovf1;
1327 env->PSW_USB_SV |= env->PSW_USB_V;
1329 avf0 = result0 * 2u;
1330 avf0 = result0 ^ avf0;
1331 avf1 = result1 * 2u;
1332 avf1 = result1 ^ avf1;
1334 env->PSW_USB_AV = avf0 | avf1;
1335 env->PSW_USB_SAV |= env->PSW_USB_AV;
1337 return (result1 & 0xffff0000ULL) | ((result0 >> 16) & 0xffffULL);
1340 uint32_t helper_msubr_q(CPUTriCoreState *env, uint32_t r1, uint32_t r2,
1341 uint32_t r3, uint32_t n)
1343 int64_t t1 = sextract64(r1, 0, 32);
1344 int64_t t2 = sextract64(r2, 0, 32);
1345 int64_t t3 = sextract64(r3, 0, 32);
1346 int64_t mul, ret;
1348 if ((t2 == -0x8000ll) && (t3 == -0x8000ll) && (n == 1)) {
1349 mul = 0x7fffffff;
1350 } else {
1351 mul = (t2 * t3) << n;
1354 ret = t1 - mul + 0x8000;
1356 if ((ret > 0x7fffffffll) || (ret < -0x80000000ll)) {
1357 env->PSW_USB_V = (1 << 31);
1358 env->PSW_USB_SV |= env->PSW_USB_V;
1359 } else {
1360 env->PSW_USB_V = 0;
1362 env->PSW_USB_AV = ret ^ ret * 2u;
1363 env->PSW_USB_SAV |= env->PSW_USB_AV;
1365 return ret & 0xffff0000ll;
1368 uint32_t helper_sub_b(CPUTriCoreState *env, target_ulong r1, target_ulong r2)
1370 int32_t b, i;
1371 int32_t extr_r1, extr_r2;
1372 int32_t ovf = 0;
1373 int32_t avf = 0;
1374 uint32_t ret = 0;
1376 for (i = 0; i < 4; i++) {
1377 extr_r1 = sextract32(r1, i * 8, 8);
1378 extr_r2 = sextract32(r2, i * 8, 8);
1380 b = extr_r1 - extr_r2;
1381 ovf |= ((b > 0x7f) || (b < -0x80));
1382 avf |= b ^ b * 2u;
1383 ret |= ((b & 0xff) << (i*8));
1386 env->PSW_USB_V = (ovf << 31);
1387 env->PSW_USB_SV |= env->PSW_USB_V;
1388 env->PSW_USB_AV = avf << 24;
1389 env->PSW_USB_SAV |= env->PSW_USB_AV;
1391 return ret;
1394 uint32_t helper_sub_h(CPUTriCoreState *env, target_ulong r1, target_ulong r2)
1396 int32_t h, i;
1397 int32_t extr_r1, extr_r2;
1398 int32_t ovf = 0;
1399 int32_t avf = 0;
1400 int32_t ret = 0;
1402 for (i = 0; i < 2; i++) {
1403 extr_r1 = sextract32(r1, i * 16, 16);
1404 extr_r2 = sextract32(r2, i * 16, 16);
1405 h = extr_r1 - extr_r2;
1406 ovf |= ((h > 0x7fff) || (h < -0x8000));
1407 avf |= h ^ h * 2u;
1408 ret |= (h & 0xffff) << (i * 16);
1411 env->PSW_USB_V = (ovf << 31);
1412 env->PSW_USB_SV |= env->PSW_USB_V;
1413 env->PSW_USB_AV = avf << 16;
1414 env->PSW_USB_SAV |= env->PSW_USB_AV;
1416 return ret;
1419 uint32_t helper_eq_b(target_ulong r1, target_ulong r2)
1421 int32_t ret;
1422 int32_t i, msk;
1424 ret = 0;
1425 msk = 0xff;
1426 for (i = 0; i < 4; i++) {
1427 if ((r1 & msk) == (r2 & msk)) {
1428 ret |= msk;
1430 msk = msk << 8;
1433 return ret;
1436 uint32_t helper_eq_h(target_ulong r1, target_ulong r2)
1438 int32_t ret = 0;
1440 if ((r1 & 0xffff) == (r2 & 0xffff)) {
1441 ret = 0xffff;
1444 if ((r1 & 0xffff0000) == (r2 & 0xffff0000)) {
1445 ret |= 0xffff0000;
1448 return ret;
1451 uint32_t helper_eqany_b(target_ulong r1, target_ulong r2)
1453 int32_t i;
1454 uint32_t ret = 0;
1456 for (i = 0; i < 4; i++) {
1457 ret |= (sextract32(r1, i * 8, 8) == sextract32(r2, i * 8, 8));
1460 return ret;
1463 uint32_t helper_eqany_h(target_ulong r1, target_ulong r2)
1465 uint32_t ret;
1467 ret = (sextract32(r1, 0, 16) == sextract32(r2, 0, 16));
1468 ret |= (sextract32(r1, 16, 16) == sextract32(r2, 16, 16));
1470 return ret;
1473 uint32_t helper_lt_b(target_ulong r1, target_ulong r2)
1475 int32_t i;
1476 uint32_t ret = 0;
1478 for (i = 0; i < 4; i++) {
1479 if (sextract32(r1, i * 8, 8) < sextract32(r2, i * 8, 8)) {
1480 ret |= (0xff << (i * 8));
1484 return ret;
1487 uint32_t helper_lt_bu(target_ulong r1, target_ulong r2)
1489 int32_t i;
1490 uint32_t ret = 0;
1492 for (i = 0; i < 4; i++) {
1493 if (extract32(r1, i * 8, 8) < extract32(r2, i * 8, 8)) {
1494 ret |= (0xff << (i * 8));
1498 return ret;
1501 uint32_t helper_lt_h(target_ulong r1, target_ulong r2)
1503 uint32_t ret = 0;
1505 if (sextract32(r1, 0, 16) < sextract32(r2, 0, 16)) {
1506 ret |= 0xffff;
1509 if (sextract32(r1, 16, 16) < sextract32(r2, 16, 16)) {
1510 ret |= 0xffff0000;
1513 return ret;
1516 uint32_t helper_lt_hu(target_ulong r1, target_ulong r2)
1518 uint32_t ret = 0;
1520 if (extract32(r1, 0, 16) < extract32(r2, 0, 16)) {
1521 ret |= 0xffff;
1524 if (extract32(r1, 16, 16) < extract32(r2, 16, 16)) {
1525 ret |= 0xffff0000;
1528 return ret;
1531 #define EXTREMA_H_B(name, op) \
1532 uint32_t helper_##name ##_b(target_ulong r1, target_ulong r2) \
1534 int32_t i, extr_r1, extr_r2; \
1535 uint32_t ret = 0; \
1537 for (i = 0; i < 4; i++) { \
1538 extr_r1 = sextract32(r1, i * 8, 8); \
1539 extr_r2 = sextract32(r2, i * 8, 8); \
1540 extr_r1 = (extr_r1 op extr_r2) ? extr_r1 : extr_r2; \
1541 ret |= (extr_r1 & 0xff) << (i * 8); \
1543 return ret; \
1546 uint32_t helper_##name ##_bu(target_ulong r1, target_ulong r2)\
1548 int32_t i; \
1549 uint32_t extr_r1, extr_r2; \
1550 uint32_t ret = 0; \
1552 for (i = 0; i < 4; i++) { \
1553 extr_r1 = extract32(r1, i * 8, 8); \
1554 extr_r2 = extract32(r2, i * 8, 8); \
1555 extr_r1 = (extr_r1 op extr_r2) ? extr_r1 : extr_r2; \
1556 ret |= (extr_r1 & 0xff) << (i * 8); \
1558 return ret; \
1561 uint32_t helper_##name ##_h(target_ulong r1, target_ulong r2) \
1563 int32_t extr_r1, extr_r2; \
1564 uint32_t ret = 0; \
1566 extr_r1 = sextract32(r1, 0, 16); \
1567 extr_r2 = sextract32(r2, 0, 16); \
1568 ret = (extr_r1 op extr_r2) ? extr_r1 : extr_r2; \
1569 ret = ret & 0xffff; \
1571 extr_r1 = sextract32(r1, 16, 16); \
1572 extr_r2 = sextract32(r2, 16, 16); \
1573 extr_r1 = (extr_r1 op extr_r2) ? extr_r1 : extr_r2; \
1574 ret |= extr_r1 << 16; \
1576 return ret; \
1579 uint32_t helper_##name ##_hu(target_ulong r1, target_ulong r2)\
1581 uint32_t extr_r1, extr_r2; \
1582 uint32_t ret = 0; \
1584 extr_r1 = extract32(r1, 0, 16); \
1585 extr_r2 = extract32(r2, 0, 16); \
1586 ret = (extr_r1 op extr_r2) ? extr_r1 : extr_r2; \
1587 ret = ret & 0xffff; \
1589 extr_r1 = extract32(r1, 16, 16); \
1590 extr_r2 = extract32(r2, 16, 16); \
1591 extr_r1 = (extr_r1 op extr_r2) ? extr_r1 : extr_r2; \
1592 ret |= extr_r1 << (16); \
1594 return ret; \
1597 uint64_t helper_ix##name(uint64_t r1, uint32_t r2) \
1599 int64_t r2l, r2h, r1hl; \
1600 uint64_t ret = 0; \
1602 ret = ((r1 + 2) & 0xffff); \
1603 r2l = sextract64(r2, 0, 16); \
1604 r2h = sextract64(r2, 16, 16); \
1605 r1hl = sextract64(r1, 32, 16); \
1607 if ((r2l op ## = r2h) && (r2l op r1hl)) { \
1608 ret |= (r2l & 0xffff) << 32; \
1609 ret |= extract64(r1, 0, 16) << 16; \
1610 } else if ((r2h op r2l) && (r2h op r1hl)) { \
1611 ret |= extract64(r2, 16, 16) << 32; \
1612 ret |= extract64(r1 + 1, 0, 16) << 16; \
1613 } else { \
1614 ret |= r1 & 0xffffffff0000ull; \
1616 return ret; \
1619 uint64_t helper_ix##name ##_u(uint64_t r1, uint32_t r2) \
1621 int64_t r2l, r2h, r1hl; \
1622 uint64_t ret = 0; \
1624 ret = ((r1 + 2) & 0xffff); \
1625 r2l = extract64(r2, 0, 16); \
1626 r2h = extract64(r2, 16, 16); \
1627 r1hl = extract64(r1, 32, 16); \
1629 if ((r2l op ## = r2h) && (r2l op r1hl)) { \
1630 ret |= (r2l & 0xffff) << 32; \
1631 ret |= extract64(r1, 0, 16) << 16; \
1632 } else if ((r2h op r2l) && (r2h op r1hl)) { \
1633 ret |= extract64(r2, 16, 16) << 32; \
1634 ret |= extract64(r1 + 1, 0, 16) << 16; \
1635 } else { \
1636 ret |= r1 & 0xffffffff0000ull; \
1638 return ret; \
1641 EXTREMA_H_B(max, >)
1642 EXTREMA_H_B(min, <)
1644 #undef EXTREMA_H_B
1646 uint32_t helper_clo(target_ulong r1)
1648 return clo32(r1);
1651 uint32_t helper_clo_h(target_ulong r1)
1653 uint32_t ret_hw0 = extract32(r1, 0, 16);
1654 uint32_t ret_hw1 = extract32(r1, 16, 16);
1656 ret_hw0 = clo32(ret_hw0 << 16);
1657 ret_hw1 = clo32(ret_hw1 << 16);
1659 if (ret_hw0 > 16) {
1660 ret_hw0 = 16;
1662 if (ret_hw1 > 16) {
1663 ret_hw1 = 16;
1666 return ret_hw0 | (ret_hw1 << 16);
1669 uint32_t helper_clz(target_ulong r1)
1671 return clz32(r1);
1674 uint32_t helper_clz_h(target_ulong r1)
1676 uint32_t ret_hw0 = extract32(r1, 0, 16);
1677 uint32_t ret_hw1 = extract32(r1, 16, 16);
1679 ret_hw0 = clz32(ret_hw0 << 16);
1680 ret_hw1 = clz32(ret_hw1 << 16);
1682 if (ret_hw0 > 16) {
1683 ret_hw0 = 16;
1685 if (ret_hw1 > 16) {
1686 ret_hw1 = 16;
1689 return ret_hw0 | (ret_hw1 << 16);
1692 uint32_t helper_cls(target_ulong r1)
1694 return clrsb32(r1);
1697 uint32_t helper_cls_h(target_ulong r1)
1699 uint32_t ret_hw0 = extract32(r1, 0, 16);
1700 uint32_t ret_hw1 = extract32(r1, 16, 16);
1702 ret_hw0 = clrsb32(ret_hw0 << 16);
1703 ret_hw1 = clrsb32(ret_hw1 << 16);
1705 if (ret_hw0 > 15) {
1706 ret_hw0 = 15;
1708 if (ret_hw1 > 15) {
1709 ret_hw1 = 15;
1712 return ret_hw0 | (ret_hw1 << 16);
1715 uint32_t helper_sh(target_ulong r1, target_ulong r2)
1717 int32_t shift_count = sextract32(r2, 0, 6);
1719 if (shift_count == -32) {
1720 return 0;
1721 } else if (shift_count < 0) {
1722 return r1 >> -shift_count;
1723 } else {
1724 return r1 << shift_count;
1728 uint32_t helper_sh_h(target_ulong r1, target_ulong r2)
1730 int32_t ret_hw0, ret_hw1;
1731 int32_t shift_count;
1733 shift_count = sextract32(r2, 0, 5);
1735 if (shift_count == -16) {
1736 return 0;
1737 } else if (shift_count < 0) {
1738 ret_hw0 = extract32(r1, 0, 16) >> -shift_count;
1739 ret_hw1 = extract32(r1, 16, 16) >> -shift_count;
1740 return (ret_hw0 & 0xffff) | (ret_hw1 << 16);
1741 } else {
1742 ret_hw0 = extract32(r1, 0, 16) << shift_count;
1743 ret_hw1 = extract32(r1, 16, 16) << shift_count;
1744 return (ret_hw0 & 0xffff) | (ret_hw1 << 16);
1748 uint32_t helper_sha(CPUTriCoreState *env, target_ulong r1, target_ulong r2)
1750 int32_t shift_count;
1751 int64_t result, t1;
1752 uint32_t ret;
1754 shift_count = sextract32(r2, 0, 6);
1755 t1 = sextract32(r1, 0, 32);
1757 if (shift_count == 0) {
1758 env->PSW_USB_C = env->PSW_USB_V = 0;
1759 ret = r1;
1760 } else if (shift_count == -32) {
1761 env->PSW_USB_C = r1;
1762 env->PSW_USB_V = 0;
1763 ret = t1 >> 31;
1764 } else if (shift_count > 0) {
1765 result = t1 << shift_count;
1766 /* calc carry */
1767 env->PSW_USB_C = ((result & 0xffffffff00000000ULL) != 0);
1768 /* calc v */
1769 env->PSW_USB_V = (((result > 0x7fffffffLL) ||
1770 (result < -0x80000000LL)) << 31);
1771 /* calc sv */
1772 env->PSW_USB_SV |= env->PSW_USB_V;
1773 ret = (uint32_t)result;
1774 } else {
1775 env->PSW_USB_V = 0;
1776 env->PSW_USB_C = (r1 & ((1 << -shift_count) - 1));
1777 ret = t1 >> -shift_count;
1780 env->PSW_USB_AV = ret ^ ret * 2u;
1781 env->PSW_USB_SAV |= env->PSW_USB_AV;
1783 return ret;
1786 uint32_t helper_sha_h(target_ulong r1, target_ulong r2)
1788 int32_t shift_count;
1789 int32_t ret_hw0, ret_hw1;
1791 shift_count = sextract32(r2, 0, 5);
1793 if (shift_count == 0) {
1794 return r1;
1795 } else if (shift_count < 0) {
1796 ret_hw0 = sextract32(r1, 0, 16) >> -shift_count;
1797 ret_hw1 = sextract32(r1, 16, 16) >> -shift_count;
1798 return (ret_hw0 & 0xffff) | (ret_hw1 << 16);
1799 } else {
1800 ret_hw0 = sextract32(r1, 0, 16) << shift_count;
1801 ret_hw1 = sextract32(r1, 16, 16) << shift_count;
1802 return (ret_hw0 & 0xffff) | (ret_hw1 << 16);
1806 uint32_t helper_bmerge(target_ulong r1, target_ulong r2)
1808 uint32_t i, ret;
1810 ret = 0;
1811 for (i = 0; i < 16; i++) {
1812 ret |= (r1 & 1) << (2 * i + 1);
1813 ret |= (r2 & 1) << (2 * i);
1814 r1 = r1 >> 1;
1815 r2 = r2 >> 1;
1817 return ret;
1820 uint64_t helper_bsplit(uint32_t r1)
1822 int32_t i;
1823 uint64_t ret;
1825 ret = 0;
1826 for (i = 0; i < 32; i = i + 2) {
1827 /* even */
1828 ret |= (r1 & 1) << (i/2);
1829 r1 = r1 >> 1;
1830 /* odd */
1831 ret |= (uint64_t)(r1 & 1) << (i/2 + 32);
1832 r1 = r1 >> 1;
1834 return ret;
1837 uint32_t helper_parity(target_ulong r1)
1839 uint32_t ret;
1840 uint32_t nOnes, i;
1842 ret = 0;
1843 nOnes = 0;
1844 for (i = 0; i < 8; i++) {
1845 ret ^= (r1 & 1);
1846 r1 = r1 >> 1;
1848 /* second byte */
1849 nOnes = 0;
1850 for (i = 0; i < 8; i++) {
1851 nOnes ^= (r1 & 1);
1852 r1 = r1 >> 1;
1854 ret |= nOnes << 8;
1855 /* third byte */
1856 nOnes = 0;
1857 for (i = 0; i < 8; i++) {
1858 nOnes ^= (r1 & 1);
1859 r1 = r1 >> 1;
1861 ret |= nOnes << 16;
1862 /* fourth byte */
1863 nOnes = 0;
1864 for (i = 0; i < 8; i++) {
1865 nOnes ^= (r1 & 1);
1866 r1 = r1 >> 1;
1868 ret |= nOnes << 24;
1870 return ret;
1873 uint32_t helper_pack(uint32_t carry, uint32_t r1_low, uint32_t r1_high,
1874 target_ulong r2)
1876 uint32_t ret;
1877 int32_t fp_exp, fp_frac, temp_exp, fp_exp_frac;
1878 int32_t int_exp = r1_high;
1879 int32_t int_mant = r1_low;
1880 uint32_t flag_rnd = (int_mant & (1 << 7)) && (
1881 (int_mant & (1 << 8)) ||
1882 (int_mant & 0x7f) ||
1883 (carry != 0));
1884 if (((int_mant & (1<<31)) == 0) && (int_exp == 255)) {
1885 fp_exp = 255;
1886 fp_frac = extract32(int_mant, 8, 23);
1887 } else if ((int_mant & (1<<31)) && (int_exp >= 127)) {
1888 fp_exp = 255;
1889 fp_frac = 0;
1890 } else if ((int_mant & (1<<31)) && (int_exp <= -128)) {
1891 fp_exp = 0;
1892 fp_frac = 0;
1893 } else if (int_mant == 0) {
1894 fp_exp = 0;
1895 fp_frac = 0;
1896 } else {
1897 if (((int_mant & (1 << 31)) == 0)) {
1898 temp_exp = 0;
1899 } else {
1900 temp_exp = int_exp + 128;
1902 fp_exp_frac = (((temp_exp & 0xff) << 23) |
1903 extract32(int_mant, 8, 23))
1904 + flag_rnd;
1905 fp_exp = extract32(fp_exp_frac, 23, 8);
1906 fp_frac = extract32(fp_exp_frac, 0, 23);
1908 ret = r2 & (1 << 31);
1909 ret = ret + (fp_exp << 23);
1910 ret = ret + (fp_frac & 0x7fffff);
1912 return ret;
1915 uint64_t helper_unpack(target_ulong arg1)
1917 int32_t fp_exp = extract32(arg1, 23, 8);
1918 int32_t fp_frac = extract32(arg1, 0, 23);
1919 uint64_t ret;
1920 int32_t int_exp, int_mant;
1922 if (fp_exp == 255) {
1923 int_exp = 255;
1924 int_mant = (fp_frac << 7);
1925 } else if ((fp_exp == 0) && (fp_frac == 0)) {
1926 int_exp = -127;
1927 int_mant = 0;
1928 } else if ((fp_exp == 0) && (fp_frac != 0)) {
1929 int_exp = -126;
1930 int_mant = (fp_frac << 7);
1931 } else {
1932 int_exp = fp_exp - 127;
1933 int_mant = (fp_frac << 7);
1934 int_mant |= (1 << 30);
1936 ret = int_exp;
1937 ret = ret << 32;
1938 ret |= int_mant;
1940 return ret;
1943 uint64_t helper_dvinit_b_13(CPUTriCoreState *env, uint32_t r1, uint32_t r2)
1945 uint64_t ret;
1946 int32_t abs_sig_dividend, abs_divisor;
1948 ret = sextract32(r1, 0, 32);
1949 ret = ret << 24;
1950 if (!((r1 & 0x80000000) == (r2 & 0x80000000))) {
1951 ret |= 0xffffff;
1954 abs_sig_dividend = abs((int32_t)r1) >> 8;
1955 abs_divisor = abs((int32_t)r2);
1956 /* calc overflow
1957 ofv if (a/b >= 255) <=> (a/255 >= b) */
1958 env->PSW_USB_V = (abs_sig_dividend >= abs_divisor) << 31;
1959 env->PSW_USB_V = env->PSW_USB_V << 31;
1960 env->PSW_USB_SV |= env->PSW_USB_V;
1961 env->PSW_USB_AV = 0;
1963 return ret;
1966 uint64_t helper_dvinit_b_131(CPUTriCoreState *env, uint32_t r1, uint32_t r2)
1968 uint64_t ret = sextract32(r1, 0, 32);
1970 ret = ret << 24;
1971 if (!((r1 & 0x80000000) == (r2 & 0x80000000))) {
1972 ret |= 0xffffff;
1974 /* calc overflow */
1975 env->PSW_USB_V = ((r2 == 0) || ((r2 == 0xffffffff) && (r1 == 0xffffff80)));
1976 env->PSW_USB_V = env->PSW_USB_V << 31;
1977 env->PSW_USB_SV |= env->PSW_USB_V;
1978 env->PSW_USB_AV = 0;
1980 return ret;
1983 uint64_t helper_dvinit_h_13(CPUTriCoreState *env, uint32_t r1, uint32_t r2)
1985 uint64_t ret;
1986 int32_t abs_sig_dividend, abs_divisor;
1988 ret = sextract32(r1, 0, 32);
1989 ret = ret << 16;
1990 if (!((r1 & 0x80000000) == (r2 & 0x80000000))) {
1991 ret |= 0xffff;
1994 abs_sig_dividend = abs((int32_t)r1) >> 16;
1995 abs_divisor = abs((int32_t)r2);
1996 /* calc overflow
1997 ofv if (a/b >= 0xffff) <=> (a/0xffff >= b) */
1998 env->PSW_USB_V = (abs_sig_dividend >= abs_divisor) << 31;
1999 env->PSW_USB_V = env->PSW_USB_V << 31;
2000 env->PSW_USB_SV |= env->PSW_USB_V;
2001 env->PSW_USB_AV = 0;
2003 return ret;
2006 uint64_t helper_dvinit_h_131(CPUTriCoreState *env, uint32_t r1, uint32_t r2)
2008 uint64_t ret = sextract32(r1, 0, 32);
2010 ret = ret << 16;
2011 if (!((r1 & 0x80000000) == (r2 & 0x80000000))) {
2012 ret |= 0xffff;
2014 /* calc overflow */
2015 env->PSW_USB_V = ((r2 == 0) || ((r2 == 0xffffffff) && (r1 == 0xffff8000)));
2016 env->PSW_USB_V = env->PSW_USB_V << 31;
2017 env->PSW_USB_SV |= env->PSW_USB_V;
2018 env->PSW_USB_AV = 0;
2020 return ret;
2023 uint64_t helper_dvadj(uint64_t r1, uint32_t r2)
2025 int32_t x_sign = (r1 >> 63);
2026 int32_t q_sign = x_sign ^ (r2 >> 31);
2027 int32_t eq_pos = x_sign & ((r1 >> 32) == r2);
2028 int32_t eq_neg = x_sign & ((r1 >> 32) == -r2);
2029 uint32_t quotient;
2030 uint64_t ret, remainder;
2032 if ((q_sign & ~eq_neg) | eq_pos) {
2033 quotient = (r1 + 1) & 0xffffffff;
2034 } else {
2035 quotient = r1 & 0xffffffff;
2038 if (eq_pos | eq_neg) {
2039 remainder = 0;
2040 } else {
2041 remainder = (r1 & 0xffffffff00000000ull);
2043 ret = remainder|quotient;
2044 return ret;
2047 uint64_t helper_dvstep(uint64_t r1, uint32_t r2)
2049 int32_t dividend_sign = extract64(r1, 63, 1);
2050 int32_t divisor_sign = extract32(r2, 31, 1);
2051 int32_t quotient_sign = (dividend_sign != divisor_sign);
2052 int32_t addend, dividend_quotient, remainder;
2053 int32_t i, temp;
2055 if (quotient_sign) {
2056 addend = r2;
2057 } else {
2058 addend = -r2;
2060 dividend_quotient = (int32_t)r1;
2061 remainder = (int32_t)(r1 >> 32);
2063 for (i = 0; i < 8; i++) {
2064 remainder = (remainder << 1) | extract32(dividend_quotient, 31, 1);
2065 dividend_quotient <<= 1;
2066 temp = remainder + addend;
2067 if ((temp < 0) == dividend_sign) {
2068 remainder = temp;
2070 if (((temp < 0) == dividend_sign)) {
2071 dividend_quotient = dividend_quotient | !quotient_sign;
2072 } else {
2073 dividend_quotient = dividend_quotient | quotient_sign;
2076 return ((uint64_t)remainder << 32) | (uint32_t)dividend_quotient;
2079 uint64_t helper_dvstep_u(uint64_t r1, uint32_t r2)
2081 int32_t dividend_quotient = extract64(r1, 0, 32);
2082 int64_t remainder = extract64(r1, 32, 32);
2083 int32_t i;
2084 int64_t temp;
2085 for (i = 0; i < 8; i++) {
2086 remainder = (remainder << 1) | extract32(dividend_quotient, 31, 1);
2087 dividend_quotient <<= 1;
2088 temp = (remainder & 0xffffffff) - r2;
2089 if (temp >= 0) {
2090 remainder = temp;
2092 dividend_quotient = dividend_quotient | !(temp < 0);
2094 return ((uint64_t)remainder << 32) | (uint32_t)dividend_quotient;
2097 uint64_t helper_divide(CPUTriCoreState *env, uint32_t r1, uint32_t r2)
2099 int32_t quotient, remainder;
2100 int32_t dividend = (int32_t)r1;
2101 int32_t divisor = (int32_t)r2;
2103 if (divisor == 0) {
2104 if (dividend >= 0) {
2105 quotient = 0x7fffffff;
2106 remainder = 0;
2107 } else {
2108 quotient = 0x80000000;
2109 remainder = 0;
2111 env->PSW_USB_V = (1 << 31);
2112 } else if ((divisor == 0xffffffff) && (dividend == 0x80000000)) {
2113 quotient = 0x7fffffff;
2114 remainder = 0;
2115 env->PSW_USB_V = (1 << 31);
2116 } else {
2117 remainder = dividend % divisor;
2118 quotient = (dividend - remainder)/divisor;
2119 env->PSW_USB_V = 0;
2121 env->PSW_USB_SV |= env->PSW_USB_V;
2122 env->PSW_USB_AV = 0;
2123 return ((uint64_t)remainder << 32) | (uint32_t)quotient;
2126 uint64_t helper_divide_u(CPUTriCoreState *env, uint32_t r1, uint32_t r2)
2128 uint32_t quotient, remainder;
2129 uint32_t dividend = r1;
2130 uint32_t divisor = r2;
2132 if (divisor == 0) {
2133 quotient = 0xffffffff;
2134 remainder = 0;
2135 env->PSW_USB_V = (1 << 31);
2136 } else {
2137 remainder = dividend % divisor;
2138 quotient = (dividend - remainder)/divisor;
2139 env->PSW_USB_V = 0;
2141 env->PSW_USB_SV |= env->PSW_USB_V;
2142 env->PSW_USB_AV = 0;
2143 return ((uint64_t)remainder << 32) | quotient;
2146 uint64_t helper_mul_h(uint32_t arg00, uint32_t arg01,
2147 uint32_t arg10, uint32_t arg11, uint32_t n)
2149 uint64_t ret;
2150 uint32_t result0, result1;
2152 int32_t sc1 = ((arg00 & 0xffff) == 0x8000) &&
2153 ((arg10 & 0xffff) == 0x8000) && (n == 1);
2154 int32_t sc0 = ((arg01 & 0xffff) == 0x8000) &&
2155 ((arg11 & 0xffff) == 0x8000) && (n == 1);
2156 if (sc1) {
2157 result1 = 0x7fffffff;
2158 } else {
2159 result1 = (((uint32_t)(arg00 * arg10)) << n);
2161 if (sc0) {
2162 result0 = 0x7fffffff;
2163 } else {
2164 result0 = (((uint32_t)(arg01 * arg11)) << n);
2166 ret = (((uint64_t)result1 << 32)) | result0;
2167 return ret;
2170 uint64_t helper_mulm_h(uint32_t arg00, uint32_t arg01,
2171 uint32_t arg10, uint32_t arg11, uint32_t n)
2173 uint64_t ret;
2174 int64_t result0, result1;
2176 int32_t sc1 = ((arg00 & 0xffff) == 0x8000) &&
2177 ((arg10 & 0xffff) == 0x8000) && (n == 1);
2178 int32_t sc0 = ((arg01 & 0xffff) == 0x8000) &&
2179 ((arg11 & 0xffff) == 0x8000) && (n == 1);
2181 if (sc1) {
2182 result1 = 0x7fffffff;
2183 } else {
2184 result1 = (((int32_t)arg00 * (int32_t)arg10) << n);
2186 if (sc0) {
2187 result0 = 0x7fffffff;
2188 } else {
2189 result0 = (((int32_t)arg01 * (int32_t)arg11) << n);
2191 ret = (result1 + result0);
2192 ret = ret << 16;
2193 return ret;
2195 uint32_t helper_mulr_h(uint32_t arg00, uint32_t arg01,
2196 uint32_t arg10, uint32_t arg11, uint32_t n)
2198 uint32_t result0, result1;
2200 int32_t sc1 = ((arg00 & 0xffff) == 0x8000) &&
2201 ((arg10 & 0xffff) == 0x8000) && (n == 1);
2202 int32_t sc0 = ((arg01 & 0xffff) == 0x8000) &&
2203 ((arg11 & 0xffff) == 0x8000) && (n == 1);
2205 if (sc1) {
2206 result1 = 0x7fffffff;
2207 } else {
2208 result1 = ((arg00 * arg10) << n) + 0x8000;
2210 if (sc0) {
2211 result0 = 0x7fffffff;
2212 } else {
2213 result0 = ((arg01 * arg11) << n) + 0x8000;
2215 return (result1 & 0xffff0000) | (result0 >> 16);
2218 uint32_t helper_crc32(uint32_t arg0, uint32_t arg1)
2220 uint8_t buf[4];
2221 uint32_t ret;
2222 stl_be_p(buf, arg0);
2224 ret = crc32(arg1, buf, 4);
2225 return ret;
2228 /* context save area (CSA) related helpers */
2230 static int cdc_increment(target_ulong *psw)
2232 if ((*psw & MASK_PSW_CDC) == 0x7f) {
2233 return 0;
2236 (*psw)++;
2237 /* check for overflow */
2238 int lo = clo32((*psw & MASK_PSW_CDC) << (32 - 7));
2239 int mask = (1u << (7 - lo)) - 1;
2240 int count = *psw & mask;
2241 if (count == 0) {
2242 (*psw)--;
2243 return 1;
2245 return 0;
2248 static int cdc_decrement(target_ulong *psw)
2250 if ((*psw & MASK_PSW_CDC) == 0x7f) {
2251 return 0;
2253 /* check for underflow */
2254 int lo = clo32((*psw & MASK_PSW_CDC) << (32 - 7));
2255 int mask = (1u << (7 - lo)) - 1;
2256 int count = *psw & mask;
2257 if (count == 0) {
2258 return 1;
2260 (*psw)--;
2261 return 0;
2264 static bool cdc_zero(target_ulong *psw)
2266 int cdc = *psw & MASK_PSW_CDC;
2267 /* Returns TRUE if PSW.CDC.COUNT == 0 or if PSW.CDC ==
2268 7'b1111111, otherwise returns FALSE. */
2269 if (cdc == 0x7f) {
2270 return true;
2272 /* find CDC.COUNT */
2273 int lo = clo32((*psw & MASK_PSW_CDC) << (32 - 7));
2274 int mask = (1u << (7 - lo)) - 1;
2275 int count = *psw & mask;
2276 return count == 0;
2279 static void save_context_upper(CPUTriCoreState *env, int ea)
2281 cpu_stl_data(env, ea, env->PCXI);
2282 cpu_stl_data(env, ea+4, env->PSW);
2283 cpu_stl_data(env, ea+8, env->gpr_a[10]);
2284 cpu_stl_data(env, ea+12, env->gpr_a[11]);
2285 cpu_stl_data(env, ea+16, env->gpr_d[8]);
2286 cpu_stl_data(env, ea+20, env->gpr_d[9]);
2287 cpu_stl_data(env, ea+24, env->gpr_d[10]);
2288 cpu_stl_data(env, ea+28, env->gpr_d[11]);
2289 cpu_stl_data(env, ea+32, env->gpr_a[12]);
2290 cpu_stl_data(env, ea+36, env->gpr_a[13]);
2291 cpu_stl_data(env, ea+40, env->gpr_a[14]);
2292 cpu_stl_data(env, ea+44, env->gpr_a[15]);
2293 cpu_stl_data(env, ea+48, env->gpr_d[12]);
2294 cpu_stl_data(env, ea+52, env->gpr_d[13]);
2295 cpu_stl_data(env, ea+56, env->gpr_d[14]);
2296 cpu_stl_data(env, ea+60, env->gpr_d[15]);
2299 static void save_context_lower(CPUTriCoreState *env, int ea)
2301 cpu_stl_data(env, ea, env->PCXI);
2302 cpu_stl_data(env, ea+4, env->gpr_a[11]);
2303 cpu_stl_data(env, ea+8, env->gpr_a[2]);
2304 cpu_stl_data(env, ea+12, env->gpr_a[3]);
2305 cpu_stl_data(env, ea+16, env->gpr_d[0]);
2306 cpu_stl_data(env, ea+20, env->gpr_d[1]);
2307 cpu_stl_data(env, ea+24, env->gpr_d[2]);
2308 cpu_stl_data(env, ea+28, env->gpr_d[3]);
2309 cpu_stl_data(env, ea+32, env->gpr_a[4]);
2310 cpu_stl_data(env, ea+36, env->gpr_a[5]);
2311 cpu_stl_data(env, ea+40, env->gpr_a[6]);
2312 cpu_stl_data(env, ea+44, env->gpr_a[7]);
2313 cpu_stl_data(env, ea+48, env->gpr_d[4]);
2314 cpu_stl_data(env, ea+52, env->gpr_d[5]);
2315 cpu_stl_data(env, ea+56, env->gpr_d[6]);
2316 cpu_stl_data(env, ea+60, env->gpr_d[7]);
2319 static void restore_context_upper(CPUTriCoreState *env, int ea,
2320 target_ulong *new_PCXI, target_ulong *new_PSW)
2322 *new_PCXI = cpu_ldl_data(env, ea);
2323 *new_PSW = cpu_ldl_data(env, ea+4);
2324 env->gpr_a[10] = cpu_ldl_data(env, ea+8);
2325 env->gpr_a[11] = cpu_ldl_data(env, ea+12);
2326 env->gpr_d[8] = cpu_ldl_data(env, ea+16);
2327 env->gpr_d[9] = cpu_ldl_data(env, ea+20);
2328 env->gpr_d[10] = cpu_ldl_data(env, ea+24);
2329 env->gpr_d[11] = cpu_ldl_data(env, ea+28);
2330 env->gpr_a[12] = cpu_ldl_data(env, ea+32);
2331 env->gpr_a[13] = cpu_ldl_data(env, ea+36);
2332 env->gpr_a[14] = cpu_ldl_data(env, ea+40);
2333 env->gpr_a[15] = cpu_ldl_data(env, ea+44);
2334 env->gpr_d[12] = cpu_ldl_data(env, ea+48);
2335 env->gpr_d[13] = cpu_ldl_data(env, ea+52);
2336 env->gpr_d[14] = cpu_ldl_data(env, ea+56);
2337 env->gpr_d[15] = cpu_ldl_data(env, ea+60);
2340 static void restore_context_lower(CPUTriCoreState *env, int ea,
2341 target_ulong *ra, target_ulong *pcxi)
2343 *pcxi = cpu_ldl_data(env, ea);
2344 *ra = cpu_ldl_data(env, ea+4);
2345 env->gpr_a[2] = cpu_ldl_data(env, ea+8);
2346 env->gpr_a[3] = cpu_ldl_data(env, ea+12);
2347 env->gpr_d[0] = cpu_ldl_data(env, ea+16);
2348 env->gpr_d[1] = cpu_ldl_data(env, ea+20);
2349 env->gpr_d[2] = cpu_ldl_data(env, ea+24);
2350 env->gpr_d[3] = cpu_ldl_data(env, ea+28);
2351 env->gpr_a[4] = cpu_ldl_data(env, ea+32);
2352 env->gpr_a[5] = cpu_ldl_data(env, ea+36);
2353 env->gpr_a[6] = cpu_ldl_data(env, ea+40);
2354 env->gpr_a[7] = cpu_ldl_data(env, ea+44);
2355 env->gpr_d[4] = cpu_ldl_data(env, ea+48);
2356 env->gpr_d[5] = cpu_ldl_data(env, ea+52);
2357 env->gpr_d[6] = cpu_ldl_data(env, ea+56);
2358 env->gpr_d[7] = cpu_ldl_data(env, ea+60);
2361 void helper_call(CPUTriCoreState *env, uint32_t next_pc)
2363 target_ulong tmp_FCX;
2364 target_ulong ea;
2365 target_ulong new_FCX;
2366 target_ulong psw;
2368 psw = psw_read(env);
2369 /* if (FCX == 0) trap(FCU); */
2370 if (env->FCX == 0) {
2371 /* FCU trap */
2373 /* if (PSW.CDE) then if (cdc_increment()) then trap(CDO); */
2374 if (psw & MASK_PSW_CDE) {
2375 if (cdc_increment(&psw)) {
2376 /* CDO trap */
2379 /* PSW.CDE = 1;*/
2380 psw |= MASK_PSW_CDE;
2381 /* tmp_FCX = FCX; */
2382 tmp_FCX = env->FCX;
2383 /* EA = {FCX.FCXS, 6'b0, FCX.FCXO, 6'b0}; */
2384 ea = ((env->FCX & MASK_FCX_FCXS) << 12) +
2385 ((env->FCX & MASK_FCX_FCXO) << 6);
2386 /* new_FCX = M(EA, word); */
2387 new_FCX = cpu_ldl_data(env, ea);
2388 /* M(EA, 16 * word) = {PCXI, PSW, A[10], A[11], D[8], D[9], D[10], D[11],
2389 A[12], A[13], A[14], A[15], D[12], D[13], D[14],
2390 D[15]}; */
2391 save_context_upper(env, ea);
2393 /* PCXI.PCPN = ICR.CCPN; */
2394 env->PCXI = (env->PCXI & 0xffffff) +
2395 ((env->ICR & MASK_ICR_CCPN) << 24);
2396 /* PCXI.PIE = ICR.IE; */
2397 env->PCXI = ((env->PCXI & ~MASK_PCXI_PIE) +
2398 ((env->ICR & MASK_ICR_IE) << 15));
2399 /* PCXI.UL = 1; */
2400 env->PCXI |= MASK_PCXI_UL;
2402 /* PCXI[19: 0] = FCX[19: 0]; */
2403 env->PCXI = (env->PCXI & 0xfff00000) + (env->FCX & 0xfffff);
2404 /* FCX[19: 0] = new_FCX[19: 0]; */
2405 env->FCX = (env->FCX & 0xfff00000) + (new_FCX & 0xfffff);
2406 /* A[11] = next_pc[31: 0]; */
2407 env->gpr_a[11] = next_pc;
2409 /* if (tmp_FCX == LCX) trap(FCD);*/
2410 if (tmp_FCX == env->LCX) {
2411 /* FCD trap */
2413 psw_write(env, psw);
2416 void helper_ret(CPUTriCoreState *env)
2418 target_ulong ea;
2419 target_ulong new_PCXI;
2420 target_ulong new_PSW, psw;
2422 psw = psw_read(env);
2423 /* if (PSW.CDE) then if (cdc_decrement()) then trap(CDU);*/
2424 if (env->PSW & MASK_PSW_CDE) {
2425 if (cdc_decrement(&(env->PSW))) {
2426 /* CDU trap */
2429 /* if (PCXI[19: 0] == 0) then trap(CSU); */
2430 if ((env->PCXI & 0xfffff) == 0) {
2431 /* CSU trap */
2433 /* if (PCXI.UL == 0) then trap(CTYP); */
2434 if ((env->PCXI & MASK_PCXI_UL) == 0) {
2435 /* CTYP trap */
2437 /* PC = {A11 [31: 1], 1’b0}; */
2438 env->PC = env->gpr_a[11] & 0xfffffffe;
2440 /* EA = {PCXI.PCXS, 6'b0, PCXI.PCXO, 6'b0}; */
2441 ea = ((env->PCXI & MASK_PCXI_PCXS) << 12) +
2442 ((env->PCXI & MASK_PCXI_PCXO) << 6);
2443 /* {new_PCXI, new_PSW, A[10], A[11], D[8], D[9], D[10], D[11], A[12],
2444 A[13], A[14], A[15], D[12], D[13], D[14], D[15]} = M(EA, 16 * word); */
2445 restore_context_upper(env, ea, &new_PCXI, &new_PSW);
2446 /* M(EA, word) = FCX; */
2447 cpu_stl_data(env, ea, env->FCX);
2448 /* FCX[19: 0] = PCXI[19: 0]; */
2449 env->FCX = (env->FCX & 0xfff00000) + (env->PCXI & 0x000fffff);
2450 /* PCXI = new_PCXI; */
2451 env->PCXI = new_PCXI;
2453 if (tricore_feature(env, TRICORE_FEATURE_13)) {
2454 /* PSW = new_PSW */
2455 psw_write(env, new_PSW);
2456 } else {
2457 /* PSW = {new_PSW[31:26], PSW[25:24], new_PSW[23:0]}; */
2458 psw_write(env, (new_PSW & ~(0x3000000)) + (psw & (0x3000000)));
2462 void helper_bisr(CPUTriCoreState *env, uint32_t const9)
2464 target_ulong tmp_FCX;
2465 target_ulong ea;
2466 target_ulong new_FCX;
2468 if (env->FCX == 0) {
2469 /* FCU trap */
2472 tmp_FCX = env->FCX;
2473 ea = ((env->FCX & 0xf0000) << 12) + ((env->FCX & 0xffff) << 6);
2475 /* new_FCX = M(EA, word); */
2476 new_FCX = cpu_ldl_data(env, ea);
2477 /* M(EA, 16 * word) = {PCXI, A[11], A[2], A[3], D[0], D[1], D[2], D[3], A[4]
2478 , A[5], A[6], A[7], D[4], D[5], D[6], D[7]}; */
2479 save_context_lower(env, ea);
2482 /* PCXI.PCPN = ICR.CCPN */
2483 env->PCXI = (env->PCXI & 0xffffff) +
2484 ((env->ICR & MASK_ICR_CCPN) << 24);
2485 /* PCXI.PIE = ICR.IE */
2486 env->PCXI = ((env->PCXI & ~MASK_PCXI_PIE) +
2487 ((env->ICR & MASK_ICR_IE) << 15));
2488 /* PCXI.UL = 0 */
2489 env->PCXI &= ~(MASK_PCXI_UL);
2490 /* PCXI[19: 0] = FCX[19: 0] */
2491 env->PCXI = (env->PCXI & 0xfff00000) + (env->FCX & 0xfffff);
2492 /* FXC[19: 0] = new_FCX[19: 0] */
2493 env->FCX = (env->FCX & 0xfff00000) + (new_FCX & 0xfffff);
2494 /* ICR.IE = 1 */
2495 env->ICR |= MASK_ICR_IE;
2497 env->ICR |= const9; /* ICR.CCPN = const9[7: 0];*/
2499 if (tmp_FCX == env->LCX) {
2500 /* FCD trap */
2504 void helper_rfe(CPUTriCoreState *env)
2506 target_ulong ea;
2507 target_ulong new_PCXI;
2508 target_ulong new_PSW;
2509 /* if (PCXI[19: 0] == 0) then trap(CSU); */
2510 if ((env->PCXI & 0xfffff) == 0) {
2511 /* raise csu trap */
2513 /* if (PCXI.UL == 0) then trap(CTYP); */
2514 if ((env->PCXI & MASK_PCXI_UL) == 0) {
2515 /* raise CTYP trap */
2517 /* if (!cdc_zero() AND PSW.CDE) then trap(NEST); */
2518 if (!cdc_zero(&(env->PSW)) && (env->PSW & MASK_PSW_CDE)) {
2519 /* raise MNG trap */
2521 env->PC = env->gpr_a[11] & ~0x1;
2522 /* ICR.IE = PCXI.PIE; */
2523 env->ICR = (env->ICR & ~MASK_ICR_IE) + ((env->PCXI & MASK_PCXI_PIE) >> 15);
2524 /* ICR.CCPN = PCXI.PCPN; */
2525 env->ICR = (env->ICR & ~MASK_ICR_CCPN) +
2526 ((env->PCXI & MASK_PCXI_PCPN) >> 24);
2527 /*EA = {PCXI.PCXS, 6'b0, PCXI.PCXO, 6'b0};*/
2528 ea = ((env->PCXI & MASK_PCXI_PCXS) << 12) +
2529 ((env->PCXI & MASK_PCXI_PCXO) << 6);
2530 /*{new_PCXI, PSW, A[10], A[11], D[8], D[9], D[10], D[11], A[12],
2531 A[13], A[14], A[15], D[12], D[13], D[14], D[15]} = M(EA, 16 * word); */
2532 restore_context_upper(env, ea, &new_PCXI, &new_PSW);
2533 /* M(EA, word) = FCX;*/
2534 cpu_stl_data(env, ea, env->FCX);
2535 /* FCX[19: 0] = PCXI[19: 0]; */
2536 env->FCX = (env->FCX & 0xfff00000) + (env->PCXI & 0x000fffff);
2537 /* PCXI = new_PCXI; */
2538 env->PCXI = new_PCXI;
2539 /* write psw */
2540 psw_write(env, new_PSW);
2543 void helper_rfm(CPUTriCoreState *env)
2545 env->PC = (env->gpr_a[11] & ~0x1);
2546 /* ICR.IE = PCXI.PIE; */
2547 env->ICR = (env->ICR & ~MASK_ICR_IE) |
2548 ((env->PCXI & ~MASK_PCXI_PIE) >> 15);
2549 /* ICR.CCPN = PCXI.PCPN; */
2550 env->ICR = (env->ICR & ~MASK_ICR_CCPN) |
2551 ((env->PCXI & ~MASK_PCXI_PCPN) >> 24);
2552 /* {PCXI, PSW, A[10], A[11]} = M(DCX, 4 * word); */
2553 env->PCXI = cpu_ldl_data(env, env->DCX);
2554 psw_write(env, cpu_ldl_data(env, env->DCX+4));
2555 env->gpr_a[10] = cpu_ldl_data(env, env->DCX+8);
2556 env->gpr_a[11] = cpu_ldl_data(env, env->DCX+12);
2558 if (tricore_feature(env, TRICORE_FEATURE_131)) {
2559 env->DBGTCR = 0;
2563 void helper_ldlcx(CPUTriCoreState *env, uint32_t ea)
2565 uint32_t dummy;
2566 /* insn doesn't load PCXI and RA */
2567 restore_context_lower(env, ea, &dummy, &dummy);
2570 void helper_lducx(CPUTriCoreState *env, uint32_t ea)
2572 uint32_t dummy;
2573 /* insn doesn't load PCXI and PSW */
2574 restore_context_upper(env, ea, &dummy, &dummy);
2577 void helper_stlcx(CPUTriCoreState *env, uint32_t ea)
2579 save_context_lower(env, ea);
2582 void helper_stucx(CPUTriCoreState *env, uint32_t ea)
2584 save_context_upper(env, ea);
2587 void helper_svlcx(CPUTriCoreState *env)
2589 target_ulong tmp_FCX;
2590 target_ulong ea;
2591 target_ulong new_FCX;
2593 if (env->FCX == 0) {
2594 /* FCU trap */
2596 /* tmp_FCX = FCX; */
2597 tmp_FCX = env->FCX;
2598 /* EA = {FCX.FCXS, 6'b0, FCX.FCXO, 6'b0}; */
2599 ea = ((env->FCX & MASK_FCX_FCXS) << 12) +
2600 ((env->FCX & MASK_FCX_FCXO) << 6);
2601 /* new_FCX = M(EA, word); */
2602 new_FCX = cpu_ldl_data(env, ea);
2603 /* M(EA, 16 * word) = {PCXI, PSW, A[10], A[11], D[8], D[9], D[10], D[11],
2604 A[12], A[13], A[14], A[15], D[12], D[13], D[14],
2605 D[15]}; */
2606 save_context_lower(env, ea);
2608 /* PCXI.PCPN = ICR.CCPN; */
2609 env->PCXI = (env->PCXI & 0xffffff) +
2610 ((env->ICR & MASK_ICR_CCPN) << 24);
2611 /* PCXI.PIE = ICR.IE; */
2612 env->PCXI = ((env->PCXI & ~MASK_PCXI_PIE) +
2613 ((env->ICR & MASK_ICR_IE) << 15));
2614 /* PCXI.UL = 0; */
2615 env->PCXI &= ~MASK_PCXI_UL;
2617 /* PCXI[19: 0] = FCX[19: 0]; */
2618 env->PCXI = (env->PCXI & 0xfff00000) + (env->FCX & 0xfffff);
2619 /* FCX[19: 0] = new_FCX[19: 0]; */
2620 env->FCX = (env->FCX & 0xfff00000) + (new_FCX & 0xfffff);
2622 /* if (tmp_FCX == LCX) trap(FCD);*/
2623 if (tmp_FCX == env->LCX) {
2624 /* FCD trap */
2628 void helper_rslcx(CPUTriCoreState *env)
2630 target_ulong ea;
2631 target_ulong new_PCXI;
2632 /* if (PCXI[19: 0] == 0) then trap(CSU); */
2633 if ((env->PCXI & 0xfffff) == 0) {
2634 /* CSU trap */
2636 /* if (PCXI.UL == 1) then trap(CTYP); */
2637 if ((env->PCXI & MASK_PCXI_UL) != 0) {
2638 /* CTYP trap */
2640 /* EA = {PCXI.PCXS, 6'b0, PCXI.PCXO, 6'b0}; */
2641 ea = ((env->PCXI & MASK_PCXI_PCXS) << 12) +
2642 ((env->PCXI & MASK_PCXI_PCXO) << 6);
2643 /* {new_PCXI, A[11], A[10], A[11], D[8], D[9], D[10], D[11], A[12],
2644 A[13], A[14], A[15], D[12], D[13], D[14], D[15]} = M(EA, 16 * word); */
2645 restore_context_lower(env, ea, &env->gpr_a[11], &new_PCXI);
2646 /* M(EA, word) = FCX; */
2647 cpu_stl_data(env, ea, env->FCX);
2648 /* M(EA, word) = FCX; */
2649 cpu_stl_data(env, ea, env->FCX);
2650 /* FCX[19: 0] = PCXI[19: 0]; */
2651 env->FCX = (env->FCX & 0xfff00000) + (env->PCXI & 0x000fffff);
2652 /* PCXI = new_PCXI; */
2653 env->PCXI = new_PCXI;
2656 void helper_psw_write(CPUTriCoreState *env, uint32_t arg)
2658 psw_write(env, arg);
2661 uint32_t helper_psw_read(CPUTriCoreState *env)
2663 return psw_read(env);
2667 static inline void QEMU_NORETURN do_raise_exception_err(CPUTriCoreState *env,
2668 uint32_t exception,
2669 int error_code,
2670 uintptr_t pc)
2672 CPUState *cs = CPU(tricore_env_get_cpu(env));
2673 cs->exception_index = exception;
2674 env->error_code = error_code;
2676 if (pc) {
2677 /* now we have a real cpu fault */
2678 cpu_restore_state(cs, pc);
2681 cpu_loop_exit(cs);
2684 void tlb_fill(CPUState *cs, target_ulong addr, int is_write, int mmu_idx,
2685 uintptr_t retaddr)
2687 int ret;
2688 ret = cpu_tricore_handle_mmu_fault(cs, addr, is_write, mmu_idx);
2689 if (ret) {
2690 TriCoreCPU *cpu = TRICORE_CPU(cs);
2691 CPUTriCoreState *env = &cpu->env;
2692 do_raise_exception_err(env, cs->exception_index,
2693 env->error_code, retaddr);