2 # This file is part of the program psim.
4 # Copyright (C) 1994-1995, Andrew Cagney <cagney@highland.com.au>
8 # The pseudo-code that appears below, translated into C, was copied
9 # by Andrew Cagney of Moss Vale, Australia.
11 # This pseudo-code is copied by permission from the publication
12 # "The PowerPC Architecture: A Specification for A New Family of
13 # RISC Processors" (ISBN 1-55860-316-6) copyright 1993, 1994 by
14 # International Business Machines Corporation.
16 # THIS PERMISSION IS PROVIDED WITHOUT WARRANTY OF ANY KIND, EITHER
17 # EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO IMPLIED WARRANTIES
18 # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
22 # This program is free software; you can redistribute it and/or modify
23 # it under the terms of the GNU General Public License as published by
24 # the Free Software Foundation; either version 2 of the License, or
25 # (at your option) any later version.
27 # This program is distributed in the hope that it will be useful,
28 # but WITHOUT ANY WARRANTY; without even the implied warranty of
29 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30 # GNU General Public License for more details.
32 # You should have received a copy of the GNU General Public License
33 # along with this program; if not, write to the Free Software
34 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
41 # 1 Instruction format as a `start-bit,content' pairs.
42 # the content is one of a digit, field name or `/' (aka.0)
46 # 3 Flags: 64 - 64bit only
47 # f - floating point enabled required
54 # For flags marked 'model', the fields are interpreted as follows:
62 # 4 String name for model
64 # 5 Specific CPU model, must be an identifier
66 # 6 Comma separated list of functional units
69 ::model-macro:::#define PPC_LOAD 0x00000001
70 ::model-macro:::#define PPC_STORE 0x00000002
71 ::model-macro:::#define PPC_SERIALIZE 0x00000004
74 ::model:604:PPC604:SCIU=2 single cycle integer,MCIU=1 multiple cycle integer,FPU=1 floating point,LSU=1 memory,BPU=1 branch
75 ::model:603e:PPC603e:IU=1 integer,FPU=1 floating point,LSU=1 memory,SRU=1 system register,BPU=1 branch
76 ::model:603:PPC603:IU=1 integer,FPU=1 floating point,LSU=1 memory,SRU=1 system register,BPU=1 branch
78 void::model-function::model_init:void
79 void::model-function::model_halt:void
80 void::model-function::model_print_info:void
82 # The following (illegal) instruction is `known' by gen and is
83 # called when ever an illegal instruction is encountered
85 program_interrupt(processor, cia,
86 illegal_instruction_program_interrupt);
90 # The following (floating point unavailable) instruction is `known' by gen
91 # and is called when ever an a floating point instruction is to be
92 # executed but floating point is make unavailable by the MSR
93 ::internal::floating_point_unavailable
94 floating_point_unavailable_interrupt(processor, cia);
99 # Floating point support functions
102 # Convert 32bit single to 64bit double
103 unsigned64::function::DOUBLE:unsigned32 WORD
105 if (EXTRACTED32(WORD, 1, 8) > 0
106 && EXTRACTED32(WORD, 1, 8) < 255) {
107 /* normalized operand */
108 int not_word_1_1 = !EXTRACTED32(WORD, 1, 1); /*2.6.3 bug*/
109 FRT = (INSERTED64(EXTRACTED32(WORD, 0, 1), 0, 1)
110 | INSERTED64(not_word_1_1, 2, 2)
111 | INSERTED64(not_word_1_1, 3, 3)
112 | INSERTED64(not_word_1_1, 4, 4)
113 | INSERTED64(EXTRACTED32(WORD, 2, 31), 5, (63 - 29)));
115 else if (EXTRACTED32(WORD, 1, 8) == 0
116 && EXTRACTED32(WORD, 9, 31) != 0) {
117 /* denormalized operand */
118 int sign = EXTRACTED32(WORD, 0, 0);
120 unsigned64 frac = INSERTED64(EXTRACTED32(WORD, 9, 31), 1, (52 - 29));
121 /* normalize the operand */
122 while (MASKED64(frac, 0, 0) == 0) {
126 FRT = (INSERTED64(sign, 0, 0)
127 | INSERTED64(exp + 1023, 1, 11)
128 | INSERTED64(EXTRACTED64(frac, 1, 52), 12, 63));
130 else if (EXTRACTED32(WORD, 1, 8) == 255
131 || EXTRACTED32(WORD, 1, 31) == 0) {
132 FRT = (INSERTED64(EXTRACTED32(WORD, 0, 1), 0, 1)
133 | INSERTED64(EXTRACTED32(WORD, 1, 1), 2, 2)
134 | INSERTED64(EXTRACTED32(WORD, 1, 1), 3, 3)
135 | INSERTED64(EXTRACTED32(WORD, 1, 1), 4, 4)
136 | INSERTED64(EXTRACTED32(WORD, 2, 31), 5, (63 - 29)));
139 error("DOUBLE - unknown case\n");
144 # Convert 64bit single to 32bit double
145 unsigned32::function::SINGLE:unsigned64 FRS
147 if (EXTRACTED64(FRS, 1, 11) > 896
148 || EXTRACTED64(FRS, 1, 63) == 0) {
149 /* no denormalization required (includes Zero/Infinity/NaN) */
150 WORD = (INSERTED32(EXTRACTED64(FRS, 0, 1), 0, 1)
151 | INSERTED32(EXTRACTED64(FRS, 5, 34), 2, 31));
153 else if (874 <= EXTRACTED64(FRS, 1, 11)
154 && EXTRACTED64(FRS, 1, 11) <= 896) {
155 /* denormalization required */
156 int sign = EXTRACTED64(FRS, 0, 0);
157 int exp = EXTRACTED64(FRS, 1, 11) - 1023;
158 unsigned64 frac = (BIT64(0)
159 | INSERTED64(EXTRACTED64(FRS, 12, 63), 1, 52));
160 /* denormalize the operand */
162 frac = INSERTED64(EXTRACTED64(frac, 0, 62), 1, 63);
165 WORD = (INSERTED32(sign, 0, 0)
166 | INSERTED32(0x00, 1, 8)
167 | INSERTED32(EXTRACTED64(frac, 1, 23), 9, 31));
170 WORD = 0x0; /* ??? */
175 # round 64bit double to 64bit but single
176 void::function::Round_Single:cpu *processor, int sign, int *exp, unsigned64 *frac_grx
177 /* comparisons ignore u bits */
180 int lsb = EXTRACTED64(*frac_grx, 23, 23);
181 int gbit = EXTRACTED64(*frac_grx, 24, 24);
182 int rbit = EXTRACTED64(*frac_grx, 25, 25);
183 int xbit = EXTRACTED64(*frac_grx, 26, 55) != 0;
184 if ((FPSCR & fpscr_rn) == fpscr_rn_round_to_nearest) {
185 if (lsb == 1 && gbit == 1) inc = 1;
186 if (lsb == 0 && gbit == 1 && rbit == 1) inc = 1;
187 if (lsb == 0 && gbit == 1 && xbit == 1) inc = 1;
189 if ((FPSCR & fpscr_rn) == fpscr_rn_round_towards_pos_infinity) {
190 if (sign == 0 && gbit == 1) inc = 1;
191 if (sign == 0 && rbit == 1) inc = 1;
192 if (sign == 0 && xbit == 1) inc = 1;
194 if ((FPSCR & fpscr_rn) == fpscr_rn_round_towards_neg_infinity) {
195 if (sign == 1 && gbit == 1) inc = 1;
196 if (sign == 1 && rbit == 1) inc = 1;
197 if (sign == 1 && xbit == 1) inc = 1;
199 /* work out addition in low 25 bits of out */
200 out = EXTRACTED64(*frac_grx, 0, 23) + inc;
201 *frac_grx = INSERTED64(out, 0, 23);
202 if (out & BIT64(64 - 23 - 1 - 1)) {
203 *frac_grx = (BIT64(0) |
204 INSERTED64(EXTRACTED64(*frac_grx, 0, 22), 1, 23));
207 /* frac_grx[24:52] = 0 already */
209 FPSCR_SET_FI(gbit || rbit || xbit);
213 void::function::Round_Integer:cpu *processor, int sign, unsigned64 *frac, int *frac64, int gbit, int rbit, int xbit, fpscreg round_mode
215 if (round_mode == fpscr_rn_round_to_nearest) {
216 if (*frac64 == 1 && gbit == 1) inc = 1;
217 if (*frac64 == 0 && gbit == 1 && rbit == 1) inc = 1;
218 if (*frac64 == 0 && gbit == 1 && xbit == 1) inc = 1;
220 if (round_mode == fpscr_rn_round_towards_pos_infinity) {
221 if (sign == 0 && gbit == 1) inc = 1;
222 if (sign == 0 && rbit == 1) inc = 1;
223 if (sign == 0 && xbit == 1) inc = 1;
225 if (round_mode == fpscr_rn_round_towards_neg_infinity) {
226 if (sign == 1 && gbit == 1) inc = 1;
227 if (sign == 1 && rbit == 1) inc = 1;
228 if (sign == 1 && xbit == 1) inc = 1;
230 /* frac[0:64] = frac[0:64} + inc */
231 *frac += (*frac64 && inc ? 1 : 0);
232 *frac64 = (*frac64 + inc) & 0x1;
234 FPSCR_SET_FI(gbit | rbit | xbit);
237 void::function::Round_Float:cpu *processor, int sign, int *exp, unsigned64 *frac, fpscreg round_mode
240 int lsb = EXTRACTED64(*frac, 52, 52);
241 int gbit = EXTRACTED64(*frac, 53, 53);
242 int rbit = EXTRACTED64(*frac, 54, 54);
243 int xbit = EXTRACTED64(*frac, 55, 55);
244 if (round_mode == fpscr_rn_round_to_nearest) {
245 if (lsb == 1 && gbit == 1) inc = 1;
246 if (lsb == 0 && gbit == 1 && rbit == 1) inc = 1;
247 if (lsb == 0 && gbit == 1 && xbit == 1) inc = 1;
249 if (round_mode == fpscr_rn_round_towards_pos_infinity) {
250 if (sign == 0 && gbit == 1) inc = 1;
251 if (sign == 0 && rbit == 1) inc = 1;
252 if (sign == 0 && xbit == 1) inc = 1;
254 if (round_mode == fpscr_rn_round_towards_neg_infinity) {
255 if (sign == 1 && gbit == 1) inc = 1;
256 if (sign == 1 && rbit == 1) inc = 1;
257 if (sign == 1 && xbit == 1) inc = 1;
259 /* frac//carry_out = frac + inc */
260 *frac = (*frac >> 1) + (INSERTED64(inc, 52, 52) >> 1);
261 carry_out = EXTRACTED64(*frac, 0, 0);
263 if (carry_out == 1) *exp = *exp + 1;
265 FPSCR_SET_FI(gbit | rbit | xbit);
266 FPSCR_SET_XX(FPSCR & fpscr_fi);
269 # conversion of FP to integer
270 void::function::convert_to_integer:cpu *processor, unsigned_word cia, unsigned64 *frt, unsigned64 frb, fpscreg round_mode, int tgt_precision
278 int sign = EXTRACTED64(frb, 0, 0);
279 if (EXTRACTED64(frb, 1, 11) == 2047 && EXTRACTED64(frb, 12, 63) == 0)
280 goto Infinity_Operand;
281 if (EXTRACTED64(frb, 1, 11) == 2047 && EXTRACTED64(frb, 12, 12) == 0)
283 if (EXTRACTED64(frb, 1, 11) == 2047 && EXTRACTED64(frb, 12, 12) == 1)
285 if (EXTRACTED64(frb, 1, 11) > 1086) goto Large_Operand;
286 if (EXTRACTED64(frb, 1, 11) > 0) exp = EXTRACTED64(frb, 1, 11) - 1023;
287 if (EXTRACTED64(frb, 1, 11) == 0) exp = -1022;
288 if (EXTRACTED64(frb, 1, 11) > 0) { /* normal */
289 frac = BIT64(1) | INSERTED64(EXTRACTED64(frb, 12, 63), 2, 53);
292 if (EXTRACTED64(frb, 1, 11) == 0) { /* denorm */
293 frac = INSERTED64(EXTRACTED64(frb, 12, 63), 2, 53);
296 gbit = 0, rbit = 0, xbit = 0;
297 for (i = 1; i <= 63 - exp; i++) {
301 frac64 = EXTRACTED64(frac, 63, 63);
302 frac = INSERTED64(EXTRACTED64(frac, 0, 62), 1, 63);
304 Round_Integer(processor, sign, &frac, &frac64, gbit, rbit, xbit, round_mode);
305 if (sign == 1) { /* frac[0:64] = ~frac[0:64] + 1 */
308 frac += (frac64 ? 1 : 0);
309 frac64 = (frac64 + 1) & 0x1;
311 if (tgt_precision == 32 /* can ignore frac64 in compare */
312 && (signed64)frac > (signed64)MASK64(33+1, 63)/*2^31-1 >>1*/)
314 if (tgt_precision == 64 /* can ignore frac64 in compare */
315 && (signed64)frac > (signed64)MASK64(1+1, 63)/*2^63-1 >>1*/)
317 if (tgt_precision == 32 /* can ignore frac64 in compare */
318 && (signed64)frac < (signed64)MASK64(0, 32+1)/*-2^31 >>1*/)
320 if (tgt_precision == 64 /* can ignore frac64 in compare */
321 && (signed64)frac < (signed64)MASK64(0, 0+1)/*-2^63 >>1*/)
323 FPSCR_SET_XX(FPSCR & fpscr_fi);
324 if (tgt_precision == 32)
325 *frt = MASKED64(*frt, 0, 31) | (EXTRACTED64(frac, 33, 63) << 1) | frac64;
326 if (tgt_precision == 64)
327 *frt = (EXTRACTED64(frac, 1, 63) << 1) | frac64;
328 /*FPSCR[fprf] = undefined */
334 FPSCR_OR_VX(fpscr_vxcvi);
335 if ((FPSCR & fpscr_ve) == 0) {
336 if (tgt_precision == 32) {
337 if (sign == 0) *frt = MASKED64(*frt, 0, 31) | 0x7FFFFFFF;
338 if (sign == 1) *frt = MASKED64(*frt, 0, 31) | 0x80000000;
341 if (sign == 0) *frt = MASK64(1, 63); /*0x7FFF_FFFF_FFFF_FFFF*/
342 if (sign == 1) *frt = BIT64(0); /*0x8000_0000_0000_0000*/
344 /* FPSCR[FPRF] = undefined */
351 FPSCR_OR_VX(fpscr_vxsnan | fpscr_vxcvi);
352 if ((FPSCR & fpscr_ve) == 0) {
353 if (tgt_precision == 32) *frt = MASKED64(*frt, 0, 31) | 0x80000000;
354 if (tgt_precision == 64) *frt = BIT64(0); /*0x8000_0000_0000_0000*/
355 /* FPSCR[fprf] = undefined */
362 FPSCR_OR_VX(fpscr_vxcvi);
363 if ((FPSCR & fpscr_ve) == 0) {
364 if (tgt_precision == 32) *frt = MASKED64(*frt, 0, 31) | 0x80000000;
365 if (tgt_precision == 64) *frt = BIT64(0);/*0x8000_0000_0000_0000*/
366 /* FPSCR[fprf] = undefined */
373 FPSCR_OR_VX(fpscr_vxcvi);
374 if ((FPSCR & fpscr_ve) == 0) {
375 if (tgt_precision == 32) {
376 if (sign == 0) *frt = MASKED64(*frt, 0, 31) | 0x7fffffff;
377 if (sign == 1) *frt = MASKED64(*frt, 0, 31) | 0x80000000;
380 if (sign == 0) *frt = MASK64(1, 63); /*0x7FFF_FFFF_FFFF_FFFF*/
381 if (sign == 1) *frt = BIT64(0); /*0x8000_0000_0000_0000*/
383 /* FPSCR[fprf] = undefined */
389 # extract out raw fields of a FP number
390 int::function::sign:unsigned64 FRS
391 return (MASKED64(FRS, 0, 0)
394 int::function::biased_exp:unsigned64 frs, int single
396 return EXTRACTED64(frs, 1, 8);
398 return EXTRACTED64(frs, 1, 11);
399 unsigned64::function::fraction:unsigned64 frs, int single
401 return EXTRACTED64(frs, 9, 31);
403 return EXTRACTED64(frs, 12, 63);
405 # a number?, each of the below return +1 or -1 (based on sign bit)
407 int::function::is_nor:unsigned64 frs, int single
408 int exp = biased_exp(frs, single);
410 && exp <= (single ? 254 : 2046));
411 int::function::is_zero:unsigned64 FRS
412 return (MASKED64(FRS, 1, 63) == 0
415 int::function::is_den:unsigned64 frs, int single
416 int exp = biased_exp(frs, single);
417 unsigned64 frac = fraction(frs, single);
418 return (exp == 0 && frac != 0
421 int::function::is_inf:unsigned64 frs, int single
422 int exp = biased_exp(frs, single);
423 int frac = fraction(frs, single);
424 return (exp == (single ? 255 : 2047) && frac == 0
427 int::function::is_NaN:unsigned64 frs, int single
428 int exp = biased_exp(frs, single);
429 int frac = fraction(frs, single);
430 return (exp == (single ? 255 : 2047) && frac != 0
433 int::function::is_SNaN:unsigned64 frs, int single
434 return (is_NaN(frs, single)
435 && !(frs & (single ? MASK64(9, 9) : MASK64(12, 12)))
438 int::function::is_QNaN:unsigned64 frs, int single
439 return (is_NaN(frs, single) && !is_SNaN(frs, single));
440 int::function::is_less_than:unsigned64 *fra, unsigned64 *frb
441 return *(double*)fra < *(double*)frb;
442 int::function::is_greater_than:unsigned64 *fra, unsigned64 *frb
443 return *(double*)fra > *(double*)frb;
444 int::function::is_equan_to:unsigned64 *fra, unsigned64 *frb
445 return *(double*)fra == *(double*)frb;
448 # which quiet nan should become the result
449 unsigned64::function::select_qnan:unsigned64 fra, unsigned64 frb, unsigned64 frc, int instruction_is_frsp, int generate_qnan, int single
451 if (is_NaN(fra, single))
453 else if (is_NaN(frb, single))
454 if (instruction_is_frsp)
455 frt = MASKED64(frb, 0, 34);
458 else if (is_NaN(frc, single))
460 else if (generate_qnan)
461 frt = MASK64(1, 12); /* 0x7FF8_0000_0000_0000 */
463 error("select_qnan - default reached\n");
467 # detect invalid operation
468 int::function::is_invalid_operation:cpu *processor, unsigned_word cia, unsigned64 fra, unsigned64 frb, fpscreg check, int single, int negate
470 if ((check & fpscr_vxsnan)
471 && (is_SNaN(fra, single) || is_SNaN(frb, single))) {
472 FPSCR_OR_VX(fpscr_vxsnan);
475 if ((check & fpscr_vxisi)
476 && (is_inf(fra, single) && is_inf(frb, single))
477 && ((negate && sign(fra) != sign(frb))
478 || (!negate && sign(fra) == sign(frb)))) {
479 /*FIXME: don't handle inf-inf VS inf+-inf */
480 FPSCR_OR_VX(fpscr_vxisi);
483 if ((check & fpscr_vxidi)
484 && (is_inf(fra, single) && is_inf(frb, single))) {
485 FPSCR_OR_VX(fpscr_vxidi);
488 if ((check & fpscr_vxzdz)
489 && (is_zero(fra) && is_zero(frb))) {
490 FPSCR_OR_VX(fpscr_vxzdz);
493 if ((check & fpscr_vximz)
494 && (is_zero(fra) && is_inf(frb, single))) {
495 FPSCR_OR_VX(fpscr_vximz);
498 if ((check & fpscr_vxvc)
499 && (is_NaN(fra, single) || is_NaN(frb, single))) {
500 FPSCR_OR_VX(fpscr_vxvc);
503 if ((check & fpscr_vxsoft)) {
504 FPSCR_OR_VX(fpscr_vxsoft);
507 if ((check & fpscr_vxsqrt)
509 FPSCR_OR_VX(fpscr_vxsqrt);
512 /* if ((check && fpscr_vxcvi) {
513 && (is_inf(fra, single) || is_NaN(fra, single) || is_large(fra, single)))
514 FPSCR_OR_VX(fpscr_vxcvi);
524 # handle case of invalid operation
525 void::function::invalid_arithemetic_operation:cpu *processor, unsigned_word cia, unsigned64 *frt, unsigned64 fra, unsigned64 frb, unsigned64 frc, int instruction_is_frsp, int instruction_is_convert_to_64bit, int instruction_is_convert_to_32bit, int single
526 if (FPSCR & fpscr_ve) {
527 /* invalid operation exception enabled */
531 /* fpscr_FPRF unchanged */
534 /* invalid operation exception disabled */
535 if (instruction_is_convert_to_64bit) {
538 else if (instruction_is_convert_to_32bit) {
541 else { /* arrith, frsp */
542 *frt = select_qnan(fra, frb, frc,
543 instruction_is_frsp, 0/*generate*/, single);
546 FPSCR_SET_FPRF(fpscr_rf_quiet_nan);
554 # I.2.4.1 Branch Instructions
556 0.18,6.LI,30.AA,31.LK:I:t::Branch
557 *PPC603:PPC603_BPU:1:1:0
558 *PPC603e:PPC603_BPU:1:1:0
559 *PPC604:PPC603_BPU:1:1:0
560 if (AA) NIA = IEA(EXTS(LI_0b00));
561 else NIA = IEA(CIA + EXTS(LI_0b00));
562 if (LK) LR = (spreg)CIA+4;
563 0.16,6.BO,11.BI,16.BD,30.AA,31.LK:B:t::Branch Conditional
564 *PPC603:PPC603_BPU:1:1:0
565 *PPC603e:PPC603_BPU:1:1:0
566 *PPC604:PPC603_BPU:1:1:0
567 int M, ctr_ok, cond_ok;
568 if (is_64bit_implementation && is_64bit_mode) M = 0;
570 if (!BO{2}) CTR = CTR - 1;
571 ctr_ok = BO{2} || ((MASKED(CTR, M, 63) != 0) != (BO{3}));
572 cond_ok = BO{0} || ((CR{BI}) == (BO{1}));
573 if (ctr_ok && cond_ok)
574 if (AA) NIA = IEA(EXTS(BD_0b00));
575 else NIA = IEA(CIA + EXTS(BD_0b00));
576 if (LK) LR = (spreg)IEA(CIA + 4);
577 0.19,6.BO,11.BI,16./,21.16,31.LK:XL:t::Branch Conditional to Link Register
578 *PPC603:PPC603_BPU:1:1:0
579 *PPC603e:PPC603_BPU:1:1:0
580 *PPC604:PPC603_BPU:1:1:0
581 int M, ctr_ok, cond_ok;
582 if (is_64bit_implementation && is_64bit_mode) M = 0;
584 if (!BO{2}) CTR = CTR - 1;
585 ctr_ok = BO{2} || ((MASKED(CTR, M, 63) != 0) != BO{3});
586 cond_ok = BO{0} || (CR{BI} == BO{1});
587 if (ctr_ok && cond_ok) NIA = IEA(LR_0b00);
588 if (LK) LR = (spreg)IEA(CIA + 4);
589 0.19,6.BO,11.BI,16./,21.528,31.LK:XL:t::Branch Conditional to Count Register
590 *PPC603:PPC603_BPU:1:1:0
591 *PPC603e:PPC603_BPU:1:1:0
592 *PPC604:PPC603_BPU:1:1:0
594 cond_ok = BO{0} || (CR{BI} == BO{1});
595 if (cond_ok) NIA = IEA(CTR_0b00);
596 if (LK) LR = (spreg)IEA(CIA + 4);
599 # I.2.4.2 System Call Instruction
601 0.17,6./,11./,16./,30.1,31./:SC:t::System Call
602 system_call_interrupt(processor, cia);
605 # I.2.4.3 Condition Register Logical Instructions
607 0.19,6.BT,11.BA,16.BB,21.257,31./:XL::crand:Condition Register AND
608 BLIT32(CR, BT, CR{BA} && CR{BB});
609 0.19,6.BT,11.BA,16.BB,21.449,31./:XL::cror:Condition Register OR
610 BLIT32(CR, BT, CR{BA} || CR{BB});
611 0.19,6.BT,11.BA,16.BB,21.193,31./:XL::crxor:Condition Register XOR
612 BLIT32(CR, BT, CR{BA} != CR{BB});
613 0.19,6.BT,11.BA,16.BB,21.225,31./:XL::crnand:Condition Register NAND
614 BLIT32(CR, BT, !(CR{BA} && CR{BB}));
615 0.19,6.BT,11.BA,16.BB,21.33,31./:XL::crnor:Condition Register NOR
616 BLIT32(CR, BT, !(CR{BA} || CR{BB}));
617 0.19,6.BT,11.BA,16.BB,21.289,31./:XL::creqv:Condition Register Equivalent
618 BLIT32(CR, BT, CR{BA} == CR{BB});
619 0.19,6.BT,11.BA,16.BB,21.129,31./:XL::crandc:Condition Register AND with Complement
620 BLIT32(CR, BT, CR{BA} && !CR{BB});
621 0.19,6.BT,11.BA,16.BB,21.417,31./:XL::crorc:Condition Register OR with Complement
622 BLIT32(CR, BT, CR{BA} || !CR{BB});
625 # I.2.4.4 Condition Register Field Instruction
627 0.19,6.BF,9./,11.BFA,14./,16./,21.0,31./:XL:::Move Condition Register Field
628 MBLIT32(CR, 4*BF, 4*BF+3, EXTRACTED32(CR, 4*BFA, 4*BFA+3));
632 # I.3.3.2 Fixed-Point Load Instructions
635 0.34,6.RT,11.RA,16.D:D:::Load Byte and Zero
641 *rT = MEM(unsigned, EA, 1);
642 0.31,6.RT,11.RA,16.RB,21.87,31./:X:::Load Byte and Zero Indexed
648 *rT = MEM(unsigned, EA, 1);
649 0.35,6.RT,11.RA,16.D:D:::Load Byte and Zero with Update
651 if (RA == 0 || RA == RT)
652 program_interrupt(processor, cia,
653 illegal_instruction_program_interrupt);
655 *rT = MEM(unsigned, EA, 1);
657 0.31,6.RT,11.RA,16.RB,21.119,31./:X:::Load Byte and Zero with Update Indexed
659 if (RA == 0 || RA == RT)
660 program_interrupt(processor, cia,
661 illegal_instruction_program_interrupt);
663 *rT = MEM(unsigned, EA, 1);
666 0.40,6.RT,11.RA,16.D:D:::Load Halfword and Zero
672 *rT = MEM(unsigned, EA, 2);
673 0.31,6.RT,11.RA,16.RB,21.279,31./:X:::Load Halfword and Zero Indexed
679 *rT = MEM(unsigned, EA, 2);
680 0.41,6.RT,11.RA,16.D:D:::Load Halfword and Zero with Update
682 if (RA == 0 || RA == RT)
683 program_interrupt(processor, cia,
684 illegal_instruction_program_interrupt);
686 *rT = MEM(unsigned, EA, 2);
688 0.31,6.RT,11.RA,16.RB,21.311,31./:X:::Load Halfword and Zero with Update Indexed
690 if (RA == 0 || RA == RT)
691 program_interrupt(processor, cia,
692 illegal_instruction_program_interrupt);
694 *rT = MEM(unsigned, EA, 2);
697 0.42,6.RT,11.RA,16.D:D:::Load Halfword Algebraic
703 *rT = MEM(signed, EA, 2);
704 0.31,6.RT,11.RA,16.RB,21.343,31./:X:::Load Halfword Algebraic Indexed
710 *rT = MEM(signed, EA, 2);
711 0.43,6.RT,11.RA,16.D:D:::Load Halfword Algebraic with Update
713 if (RA == 0 || RA == RT)
714 program_interrupt(processor, cia,
715 illegal_instruction_program_interrupt);
717 *rT = MEM(signed, EA, 2);
718 0.31,6.RT,11.RA,16.RB,21.375,31./:X:::Load Halfword Algebraic with Update Indexed
720 if (RA == 0 || RA == RT)
721 program_interrupt(processor, cia,
722 illegal_instruction_program_interrupt);
724 *rT = MEM(signed, EA, 2);
727 0.32,6.RT,11.RA,16.D:D:::Load Word and Zero
733 *rT = MEM(unsigned, EA, 4);
734 0.31,6.RT,11.RA,16.RB,21.23,31./:X:::Load Word and Zero Indexed
740 *rT = MEM(unsigned, EA, 4);
741 0.33,6.RT,11.RA,16.D:D:::Load Word and Zero with Update
743 if (RA == 0 || RA == RT)
744 program_interrupt(processor, cia,
745 illegal_instruction_program_interrupt);
747 *rT = MEM(unsigned, EA, 4);
749 0.31,6.RT,11.RA,16.RB,21.55,31./:X:::Load Word and Zero with Update Indexed
751 if (RA == 0 || RA == RT)
752 program_interrupt(processor, cia,
753 illegal_instruction_program_interrupt);
755 *rT = MEM(unsigned, EA, 4);
758 0.58,6.RT,11.RA,16.DS,30.2:DS:64::Load Word Algebraic
761 # if (RA == 0) b = 0;
763 # EA = b + EXTS(DS_0b00);
764 # *rT = MEM(signed, EA, 4);
765 0.31,6.RT,11.RA,16.RB,21.341,31./:X:64::Load Word Algebraic Indexed
768 # if (RA == 0) b = 0;
771 # *rT = MEM(signed, EA, 4);
772 0.31,6.RT,11.RA,16.RB,21.373,31./:X:64::Load Word Algebraic with Update Indexed
774 # if (RA == 0 || RA == RT)
775 # program_interrupt(processor, cia
776 # illegal_instruction_program_interrupt);
778 # *rT = MEM(signed, EA, 4);
781 0.58,6.RT,11.RA,16.DS,30.0:DS:64::Load Doubleword
784 # if (RA == 0) b = 0;
786 # EA = b + EXTS(DS_0b00);
787 # *rT = MEM(unsigned, EA, 8);
788 0.31,6.RT,11.RA,16.RB,21.21,31./:X:64::Load Doubleword Indexed
791 # if (RA == 0) b = 0;
794 # *rT = MEM(unsigned, EA, 8);
795 0.58,6.RT,11.RA,16.DS,30.1:DS:64::Load Doubleword with Update
797 # if (RA == 0 || RA == RT)
798 # program_interrupt(processor, cia
799 # illegal_instruction_program_interrupt);
800 # EA = *rA + EXTS(DS_0b00);
801 # *rT = MEM(unsigned, EA, 8);
803 0.31,6.RT,11.RA,16.RB,21.53,31./:DS:64::Load Doubleword with Update Indexed
805 # if (RA == 0 || RA == RT)
806 # program_interrupt(processor, cia
807 # illegal_instruction_program_interrupt);
809 # *rT = MEM(unsigned, EA, 8);
815 # I.3.3.3 Fixed-Point Store Instructions
818 0.38,6.RS,11.RA,16.D:D:::Store Byte
825 0.31,6.RS,11.RA,16.RB,21.215,31./:X:::Store Byte Indexed
832 0.39,6.RS,11.RA,16.D:D:::Store Byte with Update
835 program_interrupt(processor, cia,
836 illegal_instruction_program_interrupt);
840 0.31,6.RS,11.RA,16.RB,21.247,31./:X:::Store Byte with Update Indexed
843 program_interrupt(processor, cia,
844 illegal_instruction_program_interrupt);
849 0.44,6.RS,11.RA,16.D:D:::Store Half Word
856 0.31,6.RS,11.RA,16.RB,21.407,31./:X:::Store Half Word Indexed
863 0.45,6.RS,11.RA,16.D:D:::Store Half Word with Update
866 program_interrupt(processor, cia,
867 illegal_instruction_program_interrupt);
871 0.31,6.RS,11.RA,16.RB,21.439,31./:X:::Store Half Word with Update Indexed
874 program_interrupt(processor, cia,
875 illegal_instruction_program_interrupt);
880 0.36,6.RS,11.RA,16.D:D:::Store Word
887 0.31,6.RS,11.RA,16.RB,21.151,31./:X:::Store Word Indexed
894 0.37,6.RS,11.RA,16.D:D:::Store Word with Update
897 program_interrupt(processor, cia,
898 illegal_instruction_program_interrupt);
902 0.31,6.RS,11.RA,16.RB,21.183,31./:X:::Store Word with Update Indexed
905 program_interrupt(processor, cia,
906 illegal_instruction_program_interrupt);
911 0.62,6.RS,11.RA,16.DS,30.0:DS:64::Store Doubleword
914 # if (RA == 0) b = 0;
916 # EA = b + EXTS(DS_0b00);
918 0.31,6.RS,11.RA,16.RB,21.149,31./:X:64::Store Doubleword Indexed
921 # if (RA == 0) b = 0;
925 0.62,6.RS,11.RA,16.DS,30.1:DS:64::Store Doubleword with Update
928 # program_interrupt(processor, cia
929 # illegal_instruction_program_interrupt);
930 # EA = *rA + EXTS(DS_0b00);
933 0.31,6.RS,11.RA,16.RB,21.181,31./:X:64::Store Doubleword with Update Indexed
936 # program_interrupt(processor, cia
937 # illegal_instruction_program_interrupt);
944 # I.3.3.4 Fixed-Point Load and Store with Byte Reversal Instructions
947 0.31,6.RT,11.RA,16.RB,21.790,31./:X:::Load Halfword Byte-Reverse Indexed
953 *rT = SWAP_2(MEM(unsigned, EA, 2));
954 0.31,6.RT,11.RA,16.RB,21.534,31./:X:::Load Word Byte-Reverse Indexed
960 *rT = SWAP_4(MEM(unsigned, EA, 4));
962 0.31,6.RS,11.RA,16.RB,21.918,31./:X:::Store Half Word Byte-Reversed Indexed
968 STORE(EA, 2, SWAP_2(*rS));
969 0.31,6.RS,11.RA,16.RB,21.662,31./:X:::Store Word Byte-Reversed Indexed
975 STORE(EA, 4, SWAP_4(*rS));
979 # I.3.3.5 Fixed-Point Load and Store Multiple Instrctions
982 0.46,6.RT,11.RA,16.D:D:be::Load Multiple Word
983 0.47,6.RS,11.RA,16.D:D:be::Store Multiple Word
987 # I.3.3.6 Fixed-Point Move Assist Instructions
990 0.31,6.RT,11.RA,16.NB,21.597,31./:X:be::Load String Word Immediate
991 0.31,6.RT,11.RA,16.RB,21.533,31./:X:be::Load String Word Indexed
993 0.31,6.RS,11.RA,16.NB,21.725,31./:X:be::Store String Word Immedate
994 0.31,6.RS,11.RA,16.RB,21.661,31./:X:be::Store String Word Indexed
998 # I.3.3.7 Storage Synchronization Instructions
1000 # HACK: Rather than monitor addresses looking for a reason
1001 # to cancel a reservation. This code instead keeps
1002 # a copy of the data read from memory. Before performing
1003 # a store, the memory area is checked to see if it has
1005 0.31,6.RT,11.RA,16.RB,21.20,31./:X:::Load Word And Reserve Indexed
1012 RESERVE_ADDR = real_addr(EA, 1/*is-read?*/);
1013 RESERVE_DATA = MEM(unsigned, EA, 4);
1015 0.31,6.RT,11.RA,16.RB,21.84,31./:X:64::Load Doubleword And Reserve Indexed
1022 RESERVE_ADDR = real_addr(EA, 1/*is-read?*/);
1023 RESERVE_DATA = MEM(unsigned, EA, 8);
1026 0.31,6.RS,11.RA,16.RB,21.150,31.1:X:::Store Word Conditional Indexed
1033 if (RESERVE_ADDR == real_addr(EA, 0/*is-read?*/)
1034 && /*HACK*/ RESERVE_DATA == MEM(unsigned, EA, 4)) {
1036 CR_SET_XER_SO(0, cr_i_zero);
1039 /* ment to randomly to store, we never do! */
1040 CR_SET_XER_SO(0, 0);
1045 CR_SET_XER_SO(0, 0);
1047 0.31,6.RS,11.RA,16.RB,21.214,31.1:X:64::Store Doubleword Conditional Indexed
1054 if (RESERVE_ADDR == real_addr(EA, 0/*is-read?*/)
1055 && /*HACK*/ RESERVE_DATA == MEM(unsigned, EA, 8)) {
1057 CR_SET_XER_SO(0, cr_i_zero);
1060 /* ment to randomly to store, we never do */
1061 CR_SET_XER_SO(0, 0);
1066 CR_SET_XER_SO(0, 0);
1069 0.31,6./,11./,16./,21.598,31./:X::sync:Synchronize
1074 # I.3.3.9 Fixed-Point Arithmetic Instructions
1077 0.14,6.RT,11.RA,16.SI:D:T::Add Immediate
1078 *PPC603:PPC603_IU:1:1:0
1079 *PPC603e:PPC603e_IU|PPC603e_SRU:1:1:0
1080 *PPC604:PPC604_SCIU:1:1:0
1081 if (RA_is_0) *rT = EXTS(SI);
1082 else *rT = *rA + EXTS(SI);
1083 0.15,6.RT,11.RA,16.SI:D:::Add Immediate Shifted
1084 if (RA_is_0) *rT = EXTS(SI) << 16;
1085 else *rT = *rA + (EXTS(SI) << 16);
1086 0.31,6.RT,11.RA,16.RB,21.OE,22.266,31.Rc:XO:::Add
1089 ALU_END(*rT, 0/*CA*/, OE, Rc);
1090 0.31,6.RT,11.RA,16.RB,21.OE,22.40,31.Rc:XO:::Subtract From
1095 ALU_END(*rT, 0/*CA*/, OE, Rc);
1096 0.12,6.RT,11.RA,16.SI:D:::Add Immediate Carrying
1099 ALU_END(*rT, 1/*CA*/, 0/*OE*/, 0/*Rc*/);
1100 0.13,6.RT,11.RA,16.SI:D:::Add Immediate Carrying and Record
1103 ALU_END(*rT, 1/*CA*/, 0/*OE*/, 1/*Rc*/);
1104 0.8,6.RT,11.RA,16.SI:D:::Subtract From Immediate Carrying
1109 ALU_END(*rT, 1/*CA*/, 0/*OE*/, 0/*Rc*/);
1110 0.31,6.RT,11.RA,16.RB,21.OE,22.10,31.Rc:XO:::Add Carrying
1113 ALU_END(*rT, 1/*CA*/, OE, Rc);
1114 0.31,6.RT,11.RA,16.RB,21.OE,22.8,31.Rc:XO:::Subtract From Carrying
1115 /* RT <- ~RA + RB + 1 === RT <- RB - RA */
1120 ALU_END(*rT, 1/*CA*/, OE, Rc);
1121 0.31,6.RT,11.RA,16.RB,21.OE,22.138,31.Rc:XO:::Add Extended
1125 ALU_END(*rT, 1/*CA*/, OE, Rc);
1126 0.31,6.RT,11.RA,16.RB,21.OE,22.136,31.Rc:XO:::Subtract From Extended
1131 ALU_END(*rT, 1/*CA*/, OE, Rc);
1132 0.31,6.RT,11.RA,16./,21.OE,22.234,31.Rc:XO:::Add to Minus One Extended
1136 # ALU_END(*rT, 1/*CA*/, OE, Rc);
1137 0.31,6.RT,11.RA,16./,21.OE,22.232,31.Rc:XO:::Subtract From Minus One Extended
1142 # ALU_END(*rT, 1/*CA*/, OE, Rc);
1143 0.31,6.RT,11.RA,16./,21.OE,22.202,31.Rc:XO::addze:Add to Zero Extended
1146 ALU_END(*rT, 1/*CA*/, OE, Rc);
1147 0.31,6.RT,11.RA,16./,21.OE,22.200,31.Rc:XO:::Subtract from Zero Extended
1151 ALU_END(*rT, 1/*CA*/, OE, Rc);
1152 0.31,6.RT,11.RA,16./,21.OE,22.104,31.Rc:XO:::Negate
1156 ALU_END(*rT,0/*CA*/,OE,Rc);
1157 0.7,6.RT,11.RA,16.SI:D::mulli:Multiply Low Immediate
1158 signed_word prod = *rA * EXTS(SI);
1160 0.31,6.RT,11.RA,16.RB,21.OE,22.233,31.Rc:D:64::Multiply Low Doubleword
1161 0.31,6.RT,11.RA,16.RB,21.OE,22.235,31.Rc:XO::mullw:Multiply Low Word
1162 signed64 a = (signed32)(*rA);
1163 signed64 b = (signed32)(*rB);
1164 signed64 prod = a * b;
1165 signed_word t = prod;
1167 if (t != prod && OE)
1168 XER |= (xer_overflow | xer_summary_overflow);
1169 CR0_COMPARE(t, 0, Rc);
1170 0.31,6.RT,11.RA,16.RB,21./,22.73,31.Rc:XO:64::Multiply High Doubleword
1171 0.31,6.RT,11.RA,16.RB,21./,22.75,31.Rc:XO::mulhw:Multiply High Word
1172 signed64 a = (signed32)(*rA);
1173 signed64 b = (signed32)(*rB);
1174 signed64 prod = a * b;
1175 signed_word t = EXTRACTED64(prod, 0, 31);
1177 CR0_COMPARE(t, 0, Rc);
1178 0.31,6.RT,11.RA,16.RB,21./,22.9,31.Rc:XO:64::Multiply High Doubleword Unsigned
1179 0.31,6.RT,11.RA,16.RB,21./,22.11,31.Rc:XO::milhwu:Multiply High Word Unsigned
1180 unsigned64 a = (unsigned32)(*rA);
1181 unsigned64 b = (unsigned32)(*rB);
1182 unsigned64 prod = a * b;
1183 signed_word t = EXTRACTED64(prod, 0, 31);
1185 CR0_COMPARE(t, 0, Rc);
1186 0.31,6.RT,11.RA,16.RB,21.OE,22.489,31.Rc:XO:64::Divide Doubleword
1187 0.31,6.RT,11.RA,16.RB,21.OE,22.491,31.Rc:XO::divw:Divide Word
1188 signed64 dividend = (signed32)(*rA);
1189 signed64 divisor = (signed32)(*rB);
1190 if (divisor == 0 /* nb 0x8000..0 is sign extended */
1191 || (dividend == 0x80000000 && divisor == -1)) {
1193 XER |= (xer_overflow | xer_summary_overflow);
1194 CR0_COMPARE(0, 0, Rc);
1197 signed64 quotent = dividend / divisor;
1199 CR0_COMPARE((signed_word)quotent, 0, Rc);
1201 0.31,6.RT,11.RA,16.RB,21.OE,22.457,31.Rc:XO:64::Divide Doubleword Unsigned
1202 0.31,6.RT,11.RA,16.RB,21.OE,22.459,31.Rc:XO::divwu:Divide Word Unsigned
1203 unsigned64 dividend = (unsigned32)(*rA);
1204 unsigned64 divisor = (unsigned32)(*rB);
1207 XER |= (xer_overflow | xer_summary_overflow);
1208 CR0_COMPARE(0, 0, Rc);
1211 unsigned64 quotent = dividend / divisor;
1213 CR0_COMPARE((signed_word)quotent, 0, Rc);
1218 # I.3.3.10 Fixed-Point Compare Instructions
1221 0.11,6.BF,9./,10.L,11.RA,16.SI:D:::Compare Immediate
1222 if (!is_64bit_mode && L)
1223 program_interrupt(processor, cia,
1224 illegal_instruction_program_interrupt);
1227 signed_word b = EXTS(SI);
1232 CR_COMPARE(BF, a, b);
1234 0.31,6.BF,9./,10.L,11.RA,16.RB,21.0,31./:X:::Compare
1235 if (!is_64bit_mode && L)
1236 program_interrupt(processor, cia,
1237 illegal_instruction_program_interrupt);
1249 CR_COMPARE(BF, a, b);
1251 0.10,6.BF,9./,10.L,11.RA,16.UI:D:::Compare Logical Immediate
1252 if (!is_64bit_mode && L)
1253 program_interrupt(processor, cia,
1254 illegal_instruction_program_interrupt);
1257 unsigned_word b = UI;
1259 a = MASKED(*rA, 32, 63);
1262 CR_COMPARE(BF, a, b);
1264 0.31,6.BF,9./,10.L,11.RA,16.RB,21.32,31./:X:::Compare Logical
1265 if (!is_64bit_mode && L)
1266 program_interrupt(processor, cia,
1267 illegal_instruction_program_interrupt);
1272 a = MASKED(*rA, 32, 63);
1273 b = MASKED(*rB, 32, 63);
1279 CR_COMPARE(BF, a, b);
1284 # I.3.3.11 Fixed-Point Trap Instructions
1287 0.2,6.TO,11.RA,16.SI:D:64::Trap Doubleword Immediate
1289 program_interrupt(processor, cia,
1290 illegal_instruction_program_interrupt);
1292 signed_word a = *rA;
1293 signed_word b = EXTS(SI);
1294 if ((a < b && TO{0})
1296 || (a == b && TO{2})
1297 || ((unsigned_word)a < (unsigned_word)b && TO{3})
1298 || ((unsigned_word)a > (unsigned_word)b && TO{4})
1300 program_interrupt(processor, cia,
1301 trap_program_interrupt);
1303 0.3,6.TO,11.RA,16.SI:D:::Trap Word Immediate
1304 signed_word a = EXTENDED(*rA);
1305 signed_word b = EXTS(SI);
1306 if ((a < b && TO{0})
1308 || (a == b && TO{2})
1309 || ((unsigned_word)a < (unsigned_word)b && TO{3})
1310 || ((unsigned_word)a > (unsigned_word)b && TO{4})
1312 program_interrupt(processor, cia,
1313 trap_program_interrupt);
1314 0.31,6.TO,11.RA,16.RB,21.68,31./:X:64::Trap Doubleword
1316 program_interrupt(processor, cia,
1317 illegal_instruction_program_interrupt);
1319 signed_word a = *rA;
1320 signed_word b = *rB;
1321 if ((a < b && TO{0})
1323 || (a == b && TO{2})
1324 || ((unsigned_word)a < (unsigned_word)b && TO{3})
1325 || ((unsigned_word)a > (unsigned_word)b && TO{4})
1327 program_interrupt(processor, cia,
1328 trap_program_interrupt);
1330 0.31,6.TO,11.RA,16.RB,21.4,31./:X:::Trap Word
1331 signed_word a = EXTENDED(*rA);
1332 signed_word b = EXTENDED(*rB);
1333 if (TO == 12 && rA == rB) {
1334 ITRACE(trace_breakpoint, ("breakpoint\n"));
1335 cpu_halt(processor, cia, was_trap, 0);
1337 else if ((a < b && TO{0})
1339 || (a == b && TO{2})
1340 || ((unsigned_word)a < (unsigned_word)b && TO{3})
1341 || ((unsigned_word)a > (unsigned_word)b && TO{4})
1343 program_interrupt(processor, cia,
1344 trap_program_interrupt);
1347 # I.3.3.12 Fixed-Point Logical Instructions
1350 0.28,6.RS,11.RA,16.UI:D:::AND Immediate
1352 CR0_COMPARE(*rA, 0, 1/*Rc*/);
1353 0.29,6.RS,11.RA,16.UI:D:::AND Immediate Shifted
1354 *rA = *rS & (UI << 16);
1355 CR0_COMPARE(*rA, 0, 1/*Rc*/);
1356 0.24,6.RS,11.RA,16.UI:D:::OR Immediate
1358 0.25,6.RS,11.RA,16.UI:D:::OR Immediate Shifted
1359 *rA = *rS | (UI << 16);
1360 0.26,6.RS,11.RA,16.UI:D:::XOR Immediate
1362 0.27,6.RS,11.RA,16.UI:D:::XOR Immediate Shifted
1363 *rA = *rS ^ (UI << 16);
1364 0.31,6.RS,11.RA,16.RB,21.28,31.Rc:X:::AND
1366 CR0_COMPARE(*rA, 0, Rc);
1367 0.31,6.RS,11.RA,16.RB,21.444,31.Rc:X:::OR
1369 CR0_COMPARE(*rA, 0, Rc);
1370 0.31,6.RS,11.RA,16.RB,21.316,31.Rc:X:::XOR
1372 CR0_COMPARE(*rA, 0, Rc);
1373 0.31,6.RS,11.RA,16.RB,21.476,31.Rc:X:::NAND
1375 CR0_COMPARE(*rA, 0, Rc);
1376 0.31,6.RS,11.RA,16.RB,21.124,31.Rc:X:::NOR
1378 CR0_COMPARE(*rA, 0, Rc);
1379 0.31,6.RS,11.RA,16.RB,21.284,31.Rc:X:::Equivalent
1380 # *rA = ~(*rS ^ *rB); /* A === B */
1381 # CR0_COMPARE(*rA, 0, Rc);
1382 0.31,6.RS,11.RA,16.RB,21.60,31.Rc:X:::AND with Complement
1384 CR0_COMPARE(*rA, 0, Rc);
1385 0.31,6.RS,11.RA,16.RB,21.412,31.Rc:X:::OR with Complement
1387 CR0_COMPARE(*rA, 0, Rc);
1388 0.31,6.RS,11.RA,16./,21.954,31.Rc:X::extsb:Extend Sign Byte
1389 *rA = (signed_word)(signed8)*rS;
1390 CR0_COMPARE(*rA, 0, Rc);
1391 0.31,6.RS,11.RA,16./,21.922,31.Rc:X::extsh:Extend Sign Half Word
1392 *rA = (signed_word)(signed16)*rS;
1393 CR0_COMPARE(*rA, 0, Rc);
1394 0.31,6.RS,11.RA,16./,21.986,31.Rc:X:64::Extend Sign Word
1395 # *rA = (signed_word)(signed32)*rS;
1396 # CR0_COMPARE(*rA, 0, Rc);
1397 0.31,6.RS,11.RA,16./,21.58,31.Rc:X:64::Count Leading Zeros Doubleword
1399 # unsigned64 mask = BIT64(0);
1400 # unsigned64 source = *rS;
1401 # while (!(source & mask) && mask != 0) {
1406 # CR0_COMPARE(count, 0, Rc); /* FIXME - is this correct */
1407 0.31,6.RS,11.RA,16./,21.26,31.Rc:X:::Count Leading Zeros Word
1409 unsigned32 mask = BIT32(0);
1410 unsigned32 source = *rS;
1411 while (!(source & mask) && mask != 0) {
1416 CR0_COMPARE(count, 0, Rc); /* FIXME - is this correct */
1420 # I.3.3.13 Fixed-Point Rotate and Shift Instructions
1423 0.30,6.RS,11.RA,16.sh_0_4,21.mb,27.0,30.sh_5,31.Rc:MD:64::Rotate Left Doubleword Immediate then Clear Left
1424 # long n = (sh_5 << 4) | sh_0_4;
1425 # unsigned_word r = ROTL64(*rS, n);
1426 # long b = (mb_5 << 4) | mb_0_4;
1427 # unsigned_word m = MASK(b, 63);
1428 # signed_word result = r & m;
1430 # CR0_COMPARE(result, 0, Rc); /* FIXME - is this correct */
1431 0.30,6.RS,11.RA,16.sh_0_4,21.me,27.1,30.sh_5,31.Rc:MD:64::Rotate Left Doubleword Immediate then Clear Right
1432 # long n = (sh_5 << 4) | sh_0_4;
1433 # unsigned_word r = ROTL64(*rS, n);
1434 # long e = (me_5 << 4) | me_0_4;
1435 # unsigned_word m = MASK(0, e);
1436 # signed_word result = r & m;
1438 # CR0_COMPARE(result, 0, Rc); /* FIXME - is this correct */
1439 0.30,6.RS,11.RA,16.sh_0_4,21.mb,27.2,30.sh_5,31.Rc:MD:64::Rotate Left Doubleword Immediate then Clear
1440 # long n = (sh_5 << 4) | sh_0_4;
1441 # unsigned_word r = ROTL64(*rS, n);
1442 # long b = (mb_5 << 4) | mb_0_4;
1443 # unsigned_word m = MASK(0, (64-n));
1444 # signed_word result = r & m;
1446 # CR0_COMPARE(result, 0, Rc); /* FIXME - is this correct */
1448 0.21,6.RS,11.RA,16.SH,21.MB,26.ME,31.Rc:M:::Rotate Left Word Immediate then AND with Mask
1451 unsigned32 r = ROTL32(s, n);
1452 unsigned32 m = MASK(MB+32, ME+32);
1453 signed_word result = r & m;
1455 CR0_COMPARE(result, 0, Rc);
1457 ("n=%d, s=0x%x, r=0x%x, m=0x%x, result=0x%x, cr=0x%x\n",
1458 n, s, r, m, result, CR));
1460 0.30,6.RS,11.RA,16.RB,21.mb,27.8,31.Rc:MDS:64::Rotate Left Doubleword then Clear Left
1461 # long n = MASKED(*rB, 58, 63);
1462 # unsigned_word r = ROTL64(*rS, n);
1463 # long b = (mb_5 << 4) | mb_0_4;
1464 # unsigned_word m = MASK(b, 63);
1465 # signed_word result = r & m;
1467 # CR0_COMPARE(result, 0, Rc);
1468 0.30,6.RS,11.RA,16.RB,21.me,27.9,31.Rc:MDS:64::Rotate Left Doubleword then Clear Right
1469 # long n = MASKED(*rB, 58, 63);
1470 # unsigned_word r = ROTL64(*rS, n);
1471 # long e = (me_5 << 4) | me_0_4;
1472 # unsigned_word m = MASK(0, e);
1473 # signed_word result = r & m;
1475 # CR0_COMPARE(result, 0, Rc);
1477 0.23,6.RS,11.RA,16.RB,21.MB,26.ME,31.Rc:M:::Rotate Left Word then AND with Mask
1478 # long n = MASKED(*rB, 59, 63);
1479 # unsigned32 r = ROTL32(*rS, n);
1480 # unsigned32 m = MASK(MB+32, ME+32);
1481 # signed_word result = r & m;
1483 # CR0_COMPARE(result, 0, Rc);
1484 0.30,6.RS,11.RA,16.sh_0_4,21.mb,27.3,30.sh_5,31.Rc:MD:64::Rotate Left Doubleword Immediate then Mask Insert
1485 # long n = (sh_5 << 4) | sh_0_4;
1486 # unsigned_word r = ROTL64(*rS, n);
1487 # long b = (mb_5 << 4) | mb_0_4;
1488 # unsigned_word m = MASK(b, (64-n));
1489 # signed_word result = (r & m) | (*rA & ~m)
1491 # CR0_COMPARE(result, 0, Rc);
1492 0.20,6.RS,11.RA,16.SH,21.MB,26.ME,31.Rc:M::rlwimi:Rotate Left Word Immediate then Mask Insert
1494 unsigned32 r = ROTL32(*rS, n);
1495 unsigned32 m = MASK(MB+32, ME+32);
1496 signed_word result = (r & m) | (*rA & ~m);
1498 ITRACE(trace_alu, (": n=%d *rS=0x%x r=0x%x m=0x%x result=0x%x\n",
1499 n, *rS, r, m, result));
1500 CR0_COMPARE(result, 0, Rc);
1503 0.31,6.RS,11.RA,16.RB,21.27,31.Rc:X:64::Shift Left Doubleword
1504 0.31,6.RS,11.RA,16.RB,21.24,31.Rc:X:::Shift Left Word
1505 int n = MASKED(*rB, 59, 63);
1506 unsigned32 source = *rS;
1507 signed_word shifted;
1509 shifted = (source << n);
1513 CR0_COMPARE(shifted, 0, Rc);
1515 ("n=%d, source=0x%x, shifted=0x%x\n",
1516 n, source, shifted));
1517 0.31,6.RS,11.RA,16.RB,21.539,31.Rc:X:64::Shift Right Doubleword
1518 0.31,6.RS,11.RA,16.RB,21.536,31.Rc:X:::Shift Right Word
1519 int n = MASKED(*rB, 59, 63);
1520 unsigned32 source = *rS;
1521 signed_word shifted;
1523 shifted = (source >> n);
1527 CR0_COMPARE(shifted, 0, Rc);
1529 ("n=%d, source=0x%x, shifted=0x%x\n",
1530 n, source, shifted));
1532 0.31,6.RS,11.RA,16.sh_0_4,21.413,30.sh_5,31.Rc:XS:64::Shift Right Algebraic Doubleword Immediate
1533 0.31,6.RS,11.RA,16.SH,21.824,31.Rc:X:::Shift Right Algebraic Word Immediate
1535 signed_word r = ROTL32(*rS, /*64*/32-n);
1536 signed_word m = MASK(n+32, 63);
1537 int S = MASKED(*rS, 32, 32);
1538 signed_word shifted = (r & m) | (S ? ~m : 0);
1540 if (S && ((r & ~m) & MASK(32, 63)) != 0)
1544 CR0_COMPARE(shifted, 0, Rc);
1545 0.31,6.RS,11.RA,16.RB,21.794,31.Rc:X:64::Shift Right Algebraic Doubleword
1546 0.31,6.RS,11.RA,16.RB,21.792,31.Rc:X:::Shift Right Algebraic Word
1547 int n = MASKED(*rB, 58, 63);
1548 int shift = (n >= 31 ? 31 : n);
1549 signed32 source = (signed32)*rS; /* signed to keep sign bit */
1550 signed32 shifted = source >> shift;
1551 unsigned32 mask = ((unsigned32)-1) >> (31-shift);
1552 *rA = (signed_word)shifted; /* if 64bit will sign extend */
1553 if (source < 0 && (source & mask))
1557 CR0_COMPARE(shifted, 0, Rc);
1561 # I.3.3.14 Move to/from System Register Instructions
1564 0.31,6.RS,11.spr,21.467,31./:XFX:::Move to Special Purpose Register
1565 int n = (spr{5:9} << 5) | spr{0:4};
1566 if (spr{0} && IS_PROBLEM_STATE(processor))
1567 program_interrupt(processor, cia,
1568 privileged_instruction_program_interrupt);
1569 else if (!spr_is_valid(n)
1570 || spr_is_readonly(n))
1571 program_interrupt(processor, cia,
1572 illegal_instruction_program_interrupt);
1574 spreg new_val = (spr_length(n) == 64
1576 : MASKED(*rS, 32, 63));
1577 /* HACK - time base registers need to be updated immediatly */
1578 if (WITH_TIME_BASE) {
1582 cpu_set_time_base(processor,
1583 (MASKED64(cpu_get_time_base(processor),
1585 | ((signed64)new_val << 32)));
1588 cpu_set_time_base(processor,
1589 (MASKED64(cpu_get_time_base(processor),
1591 | ((signed64)new_val << 32)));
1594 cpu_set_decrementer(processor, new_val);
1605 0.31,6.RT,11.spr,21.339,31./:XFX:uea::Move from Special Purpose Register
1606 int n = (spr{5:9} << 5) | spr{0:4};
1607 if (spr{0} && IS_PROBLEM_STATE(processor))
1608 program_interrupt(processor, cia,
1609 privileged_instruction_program_interrupt);
1610 else if (!spr_is_valid(n))
1611 program_interrupt(processor, cia,
1612 illegal_instruction_program_interrupt);
1614 /* HACK - some SPR's need to get their value extracted specially */
1617 0.31,6.RS,11./,12.FXM,20./,21.144,31./:XFX::mtfcr:Move to Condition Register Fields
1622 unsigned_word mask = 0;
1624 for (f = 0; f < 8; f++) {
1625 if (FXM & (0x80 >> f))
1626 mask |= (0xf << 4*(7-f));
1628 CR = (MASKED(*rS, 32, 63) & mask) | (CR & ~mask);
1630 0.31,6.BF,9./,11./,16./,21.512,31./:X:::Move to Condition Register from XER
1631 0.31,6.RT,11./,16./,21.19,31./:X:::Move From Condition Register
1632 *rT = (unsigned32)CR;
1635 # I.4.6.2 Floating-Point Load Instructions
1638 0.48,6.FRT,11.RA,16.D:D:f:lfs:Load Floating-Point Single
1644 *frT = DOUBLE(MEM(unsigned, EA, 4));
1645 0.31,6.FRT,11.RA,16.RB,21.535,31./:X:f::Load Floating-Point Single Indexed
1651 *frT = DOUBLE(MEM(unsigned, EA, 4));
1652 0.49,6.FRT,11.RA,16.D:D:f::Load Floating-Point Single with Update
1655 program_interrupt(processor, cia,
1656 illegal_instruction_program_interrupt);
1658 *frT = DOUBLE(MEM(unsigned, EA, 4));
1660 0.31,6.FRT,11.RA,16.RB,21.576,31./:X:f::Load Floating-Point Single with Update Indexed
1663 program_interrupt(processor, cia,
1664 illegal_instruction_program_interrupt);
1666 *frT = DOUBLE(MEM(unsigned, EA, 4));
1669 0.50,6.FRT,11.RA,16.D:D:f::Load Floating-Point Double
1675 *frT = MEM(unsigned, EA, 8);
1676 0.31,6.FRT,11.RA,16.RB,21.599,31./:X:f::Load Floating-Point Double Indexed
1682 *frT = MEM(unsigned, EA, 8);
1683 0.51,6.FRT,11.RA,16.D:D:f::Load Floating-Point Double with Update
1686 program_interrupt(processor, cia,
1687 illegal_instruction_program_interrupt);
1689 *frT = MEM(unsigned, EA, 8);
1691 0.31,6.FRT,11.RA,16.RB,21.631,31./:X:f::Load Floating-Point Double with Update Indexed
1694 program_interrupt(processor, cia,
1695 illegal_instruction_program_interrupt);
1697 *frT = MEM(unsigned, EA, 8);
1702 # I.4.6.3 Floating-Point Store Instructions
1705 0.52,6.FRS,11.RA,16.D:D:f::Store Floating-Point Single
1711 STORE(EA, 4, SINGLE(*frS));
1712 0.31,6.FRS,11.RA,16.RB,21.663,31./:X:f::Store Floating-Point Single Indexed
1718 STORE(EA, 4, SINGLE(*frS));
1719 0.53,6.FRS,11.RA,16.D:D:f::Store Floating-Point Single with Update
1722 program_interrupt(processor, cia,
1723 illegal_instruction_program_interrupt);
1725 STORE(EA, 4, SINGLE(*frS));
1727 0.31,6.FRS,11.RA,16.RB,21.695,31./:X:f::Store Floating-Point Single with Update Indexed
1730 program_interrupt(processor, cia,
1731 illegal_instruction_program_interrupt);
1733 STORE(EA, 4, SINGLE(*frS));
1736 0.54,6.FRS,11.RA,16.D:D:f::Store Floating-Point Double
1743 0.31,6.FRS,11.RA,16.RB,21.727,31./:X:f::Store Floating-Point Double Indexed
1750 0.55,6.FRS,11.RA,16.D:D:f::Store Floating-Point Double with Update
1753 program_interrupt(processor, cia,
1754 illegal_instruction_program_interrupt);
1758 0.31,6.FRS,11.RA,16.RB,21.759,31./:X:f::Store Floating-Point Double with Update Indexed
1761 program_interrupt(processor, cia,
1762 illegal_instruction_program_interrupt);
1769 # I.4.6.4 Floating-Point Move Instructions
1772 0.63,6.FRT,11./,16.FRB,21.72,31.Rc:X:f::Floating Move Register
1775 0.63,6.FRT,11./,16.FRB,21.40,31.Rc:X:f::Floating Negate
1776 *frT = *frB ^ BIT64(0);
1778 0.63,6.FRT,11./,16.FRB,21.264,31.Rc:X:f::Floating Absolute Value
1779 *frT = *frB & ~BIT64(0);
1781 0.63,6.FRT,11./,16.FRB,21.136,31.Rc:X:f::Floating Negative Absolute Value
1782 *frT = *frB | BIT64(0);
1788 # I.4.6.5 Floating-Point Arithmetic Instructions
1791 0.63,6.FRT,11.FRA,16.FRB,21./,26.21,31.Rc:A:f:fadd:Floating Add
1793 if (is_invalid_operation(processor, cia,
1795 fpscr_vxsnan | fpscr_vxisi,
1798 invalid_arithemetic_operation(processor, cia,
1800 0, /*instruction_is_frsp*/
1801 0, /*instruction_is_convert_to_64bit*/
1802 0, /*instruction_is_convert_to_32bit*/
1803 0); /*single-precision*/
1807 double s = *(double*)frA + *(double*)frB;
1811 0.59,6.FRT,11.FRA,16.FRB,21./,26.21,31.Rc:A:f:fadds:Floating Add Single
1813 if (is_invalid_operation(processor, cia,
1815 fpscr_vxsnan | fpscr_vxisi,
1818 invalid_arithemetic_operation(processor, cia,
1820 0, /*instruction_is_frsp*/
1821 0, /*instruction_is_convert_to_64bit*/
1822 0, /*instruction_is_convert_to_32bit*/
1823 1); /*single-precision*/
1827 float s = *(double*)frA + *(double*)frB;
1832 0.63,6.FRT,11.FRA,16.FRB,21./,26.20,31.Rc:A:f:fsub:Floating Subtract
1834 if (is_invalid_operation(processor, cia,
1836 fpscr_vxsnan | fpscr_vxisi,
1839 invalid_arithemetic_operation(processor, cia,
1841 0, /*instruction_is_frsp*/
1842 0, /*instruction_is_convert_to_64bit*/
1843 0, /*instruction_is_convert_to_32bit*/
1844 0); /*single-precision*/
1848 double s = *(double*)frA - *(double*)frB;
1852 0.59,6.FRT,11.FRA,16.FRB,21./,26.20,31.Rc:A:f:fsubs:Floating Subtract Single
1854 if (is_invalid_operation(processor, cia,
1856 fpscr_vxsnan | fpscr_vxisi,
1859 invalid_arithemetic_operation(processor, cia,
1861 0, /*instruction_is_frsp*/
1862 0, /*instruction_is_convert_to_64bit*/
1863 0, /*instruction_is_convert_to_32bit*/
1864 1); /*single-precision*/
1868 float s = *(double*)frA - *(double*)frB;
1873 0.63,6.FRT,11.FRA,16./,21.FRC,26.25,31.Rc:A:f:fmul:Floating Multiply
1875 if (is_invalid_operation(processor, cia,
1877 fpscr_vxsnan | fpscr_vximz,
1880 invalid_arithemetic_operation(processor, cia,
1882 0, /*instruction_is_frsp*/
1883 0, /*instruction_is_convert_to_64bit*/
1884 0, /*instruction_is_convert_to_32bit*/
1885 0); /*single-precision*/
1889 double s = *(double*)frA * *(double*)frC;
1893 0.59,6.FRT,11.FRA,16./,21.FRC,26.25,31.Rc:A:f:fmuls:Floating Multiply Single
1895 if (is_invalid_operation(processor, cia,
1897 fpscr_vxsnan | fpscr_vximz,
1900 invalid_arithemetic_operation(processor, cia,
1902 0, /*instruction_is_frsp*/
1903 0, /*instruction_is_convert_to_64bit*/
1904 0, /*instruction_is_convert_to_32bit*/
1905 1); /*single-precision*/
1909 float s = *(double*)frA * *(double*)frC;
1914 0.63,6.FRT,11.FRA,16.FRB,21./,26.18,31.Rc:A:f:fdiv:Floating Divide
1916 if (is_invalid_operation(processor, cia,
1918 fpscr_vxsnan | fpscr_vxzdz,
1921 invalid_arithemetic_operation(processor, cia,
1923 0, /*instruction_is_frsp*/
1924 0, /*instruction_is_convert_to_64bit*/
1925 0, /*instruction_is_convert_to_32bit*/
1926 0); /*single-precision*/
1930 double s = *(double*)frA / *(double*)frB;
1934 0.59,6.FRT,11.FRA,16.FRB,21./,26.18,31.Rc:A:f:fdivs:Floating Divide Single
1936 if (is_invalid_operation(processor, cia,
1938 fpscr_vxsnan | fpscr_vxzdz,
1941 invalid_arithemetic_operation(processor, cia,
1943 0, /*instruction_is_frsp*/
1944 0, /*instruction_is_convert_to_64bit*/
1945 0, /*instruction_is_convert_to_32bit*/
1946 1); /*single-precision*/
1950 float s = *(double*)frA / *(double*)frB;
1955 0.63,6.FRT,11.FRA,16.FRB,21.FRC,26.29,31.Rc:A:f:fmadd:Floating Multiply-Add
1957 double product; /*HACK! - incorrectly loosing precision ... */
1958 /* compute the multiply */
1959 if (is_invalid_operation(processor, cia,
1961 fpscr_vxsnan | fpscr_vximz,
1964 invalid_arithemetic_operation(processor, cia,
1965 (unsigned64*)&product, *frA, 0, *frC,
1966 0, /*instruction_is_frsp*/
1967 0, /*instruction_is_convert_to_64bit*/
1968 0, /*instruction_is_convert_to_32bit*/
1969 0); /*single-precision*/
1973 product = *(double*)frA * *(double*)frC;
1975 /* compute the add */
1976 if (is_invalid_operation(processor, cia,
1978 fpscr_vxsnan | fpscr_vxisi,
1981 invalid_arithemetic_operation(processor, cia,
1982 frT, product, *frB, 0,
1983 0, /*instruction_is_frsp*/
1984 0, /*instruction_is_convert_to_64bit*/
1985 0, /*instruction_is_convert_to_32bit*/
1986 0); /*single-precision*/
1990 double s = product + *(double*)frB;
1994 0.59,6.FRT,11.FRA,16.FRB,21.FRC,26.29,31.Rc:A:f::Floating Multiply-Add Single
1996 0.63,6.FRT,11.FRA,16.FRB,21.FRC,26.28,31.Rc:A:f::Floating Multiply-Subtract
1997 0.59,6.FRT,11.FRA,16.FRB,21.FRC,26.28,31.Rc:A:f::Floating Multiply-Subtract Single
1999 0.63,6.FRT,11.FRA,16.FRB,21.FRC,26.31,31.Rc:A:f::Floating Negative Multiply-Add
2000 0.59,6.FRT,11.FRA,16.FRB,21.FRC,26.31,31.Rc:A:f::Floating Negative Multiply-Add Single
2002 0.63,6.FRT,11.FRA,16.FRB,21.FRC,26.30,31.Rc:A:f::Floating Negative Multiply-Subtract
2003 0.59,6.FRT,11.FRA,16.FRB,21.FRC,26.30,31.Rc:A:f::Floating Negative Multiply-Subtract Single
2007 # I.4.6.6 Floating-Point Rounding and Conversion Instructions
2010 0.63,6.FRT,11./,16.FRB,21.12,31.Rc:X:f::Floating Round to Single-Precision
2013 unsigned64 frac_grx;
2014 /* split off cases for what to do */
2015 if (EXTRACTED64(*frB, 1, 11) < 897
2016 && EXTRACTED64(*frB, 1, 63) > 0) {
2017 if ((FPSCR & fpscr_ue) == 0) goto Disabled_Exponent_Underflow;
2018 if ((FPSCR & fpscr_ue) != 0) goto Enabled_Exponent_Underflow;
2020 if (EXTRACTED64(*frB, 1, 11) > 1150
2021 && EXTRACTED64(*frB, 1, 11) < 2047) {
2022 if ((FPSCR & fpscr_oe) == 0) goto Disabled_Exponent_Overflow;
2023 if ((FPSCR & fpscr_oe) != 0) goto Enabled_Exponent_Overflow;
2025 if (EXTRACTED64(*frB, 1, 11) > 896
2026 && EXTRACTED64(*frB, 1, 11) < 1151) goto Normal_Operand;
2027 if (EXTRACTED64(*frB, 1, 63) == 0) goto Zero_Operand;
2028 if (EXTRACTED64(*frB, 1, 11) == 2047) {
2029 if (EXTRACTED64(*frB, 12, 63) == 0) goto Infinity_Operand;
2030 if (EXTRACTED64(*frB, 12, 12) == 1) goto QNaN_Operand;
2031 if (EXTRACTED64(*frB, 12, 12) == 0
2032 && EXTRACTED64(*frB, 13, 63) > 0) goto SNaN_Operand;
2035 Disabled_Exponent_Underflow:
2036 sign = EXTRACTED64(*frB, 0, 0);
2037 if (EXTRACTED64(*frB, 1, 11) == 0) {
2039 frac_grx = INSERTED64(EXTRACTED64(*frB, 12, 63), 1, 52);
2041 if (EXTRACTED64(*frB, 1, 11) > 0) {
2042 exp = EXTRACTED64(*frB, 1, 11) - 1023;
2043 frac_grx = BIT64(0) | INSERTED64(EXTRACTED64(*frB, 12, 63), 1, 52);
2045 Denormalize_Operand:
2046 /* G|R|X == zero from above */
2047 while (exp < -126) {
2049 frac_grx = (INSERTED64(EXTRACTED64(frac_grx, 0, 54), 1, 55)
2050 | MASKED64(frac_grx, 55, 55));
2052 FPSCR_SET_UX(EXTRACTED64(frac_grx, 24, 55) > 0);
2053 Round_Single(processor, sign, &exp, &frac_grx);
2054 FPSCR_SET_XX(FPSCR & fpscr_fi);
2055 if (EXTRACTED64(frac_grx, 0, 52) == 0) {
2056 *frT = INSERTED64(sign, 0, 0);
2057 if (sign == 0) FPSCR_SET_FPRF(fpscr_rf_pos_zero);
2058 if (sign == 1) FPSCR_SET_FPRF(fpscr_rf_neg_zero);
2060 if (EXTRACTED64(frac_grx, 0, 52) > 0) {
2061 if (EXTRACTED64(frac_grx, 0, 0) == 1) {
2062 if (sign == 0) FPSCR_SET_FPRF(fpscr_rf_pos_normal_number);
2063 if (sign == 1) FPSCR_SET_FPRF(fpscr_rf_neg_normal_number);
2065 if (EXTRACTED64(frac_grx, 0, 0) == 0) {
2066 if (sign == 0) FPSCR_SET_FPRF(fpscr_rf_pos_denormalized_number);
2067 if (sign == 1) FPSCR_SET_FPRF(fpscr_rf_neg_denormalized_number);
2069 /*Normalize_Operand:*/
2070 while (EXTRACTED64(frac_grx, 0, 0) == 0) {
2072 frac_grx = INSERTED64(EXTRACTED64(frac_grx, 1, 52), 0, 51);
2074 *frT = (INSERTED64(sign, 0, 0)
2075 | INSERTED64(exp + 1023, 1, 11)
2076 | INSERTED64(EXTRACTED64(frac_grx, 1, 52), 12, 63));
2079 Enabled_Exponent_Underflow:
2081 sign = EXTRACTED64(*frB, 0, 0);
2082 if (EXTRACTED64(*frB, 1, 11) == 0) {
2084 frac_grx = INSERTED64(EXTRACTED64(*frB, 12, 63), 1, 52);
2086 if (EXTRACTED64(*frB, 1, 11) > 0) {
2087 exp = EXTRACTED64(*frB, 1, 11) - 1023;
2088 frac_grx = (BIT64(0) |
2089 INSERTED64(EXTRACTED64(*frB, 12, 63), 1, 52));
2091 /*Normalize_Operand:*/
2092 while (EXTRACTED64(frac_grx, 0, 0) == 0) {
2094 frac_grx = INSERTED64(EXTRACTED64(frac_grx, 1, 52), 0, 51);
2096 Round_Single(processor, sign, &exp, &frac_grx);
2097 FPSCR_SET_XX(FPSCR & fpscr_fi);
2099 *frT = (INSERTED64(sign, 0, 0)
2100 | INSERTED64(exp + 1023, 1, 11)
2101 | INSERTED64(EXTRACTED64(frac_grx, 1, 52), 12, 63));
2102 if (sign == 0) FPSCR_SET_FPRF(fpscr_rf_pos_normal_number);
2103 if (sign == 1) FPSCR_SET_FPRF(fpscr_rf_neg_normal_number);
2105 Disabled_Exponent_Overflow:
2107 if ((FPSCR & fpscr_rn) == fpscr_rn_round_to_nearest) {
2108 if (EXTRACTED64(*frB, 0, 0) == 0) {
2109 *frT = INSERTED64(0x7FF00000, 0, 31) | 0x00000000;
2110 FPSCR_SET_FPRF(fpscr_rf_pos_infinity);
2112 if (EXTRACTED64(*frB, 0, 0) == 1) {
2113 *frT = INSERTED64(0xFFF00000, 0, 31) | 0x00000000;
2114 FPSCR_SET_FPRF(fpscr_rf_neg_infinity);
2117 if ((FPSCR & fpscr_rn) == fpscr_rn_round_towards_zero) {
2118 if (EXTRACTED64(*frB, 0, 0) == 0) {
2119 *frT = INSERTED64(0x47EFFFFF, 0, 31) | 0xE0000000;
2120 FPSCR_SET_FPRF(fpscr_rf_pos_normal_number);
2122 if (EXTRACTED64(*frB, 0, 0) == 1) {
2123 *frT = INSERTED64(0xC7EFFFFF, 0, 31) | 0xE0000000;
2124 FPSCR_SET_FPRF(fpscr_rf_neg_normal_number);
2127 if ((FPSCR & fpscr_rn) == fpscr_rn_round_towards_pos_infinity) {
2128 if (EXTRACTED64(*frB, 0, 0) == 0) {
2129 *frT = INSERTED64(0x7FF00000, 0, 31) | 0x00000000;
2130 FPSCR_SET_FPRF(fpscr_rf_pos_infinity);
2132 if (EXTRACTED64(*frB, 0, 0) == 1) {
2133 *frT = INSERTED64(0xC7EFFFFF, 0, 31) | 0xE0000000;
2134 FPSCR_SET_FPRF(fpscr_rf_neg_normal_number);
2137 if ((FPSCR & fpscr_rn) == fpscr_rn_round_towards_neg_infinity) {
2138 if (EXTRACTED64(*frB, 0, 0) == 0) {
2139 *frT = INSERTED64(0x47EFFFFF, 0, 31) | 0xE0000000;
2140 FPSCR_SET_FPRF(fpscr_rf_pos_normal_number);
2142 if (EXTRACTED64(*frB, 0, 0) == 1) {
2143 *frT = INSERTED64(0xFFF00000, 0, 31) | 0x00000000;
2144 FPSCR_SET_FPRF(fpscr_rf_neg_infinity);
2147 /* FPSCR[FR] <- undefined */
2151 Enabled_Exponent_Overflow:
2152 sign = EXTRACTED64(*frB, 0, 0);
2153 exp = EXTRACTED64(*frB, 1, 11) - 1023;
2154 frac_grx = BIT64(0) | INSERTED64(EXTRACTED64(*frB, 12, 63), 1, 52);
2155 Round_Single(processor, sign, &exp, &frac_grx);
2156 FPSCR_SET_XX(FPSCR & fpscr_fi);
2160 *frT = (INSERTED64(sign, 0, 0)
2161 | INSERTED64(exp + 1023, 1, 11)
2162 | INSERTED64(EXTRACTED64(frac_grx, 1, 52), 12, 63));
2163 if (sign == 0) FPSCR_SET_FPRF(fpscr_rf_pos_normal_number);
2164 if (sign == 1) FPSCR_SET_FPRF(fpscr_rf_neg_normal_number);
2168 if (EXTRACTED64(*frB, 0, 0) == 0) FPSCR_SET_FPRF(fpscr_rf_pos_zero);
2169 if (EXTRACTED64(*frB, 0, 0) == 1) FPSCR_SET_FPRF(fpscr_rf_neg_zero);
2175 if (EXTRACTED64(*frB, 0, 0) == 0) FPSCR_SET_FPRF(fpscr_rf_pos_infinity);
2176 if (EXTRACTED64(*frB, 0, 0) == 1) FPSCR_SET_FPRF(fpscr_rf_neg_infinity);
2181 *frT = INSERTED64(EXTRACTED64(*frB, 0, 34), 0, 34);
2182 FPSCR_SET_FPRF(fpscr_rf_quiet_nan);
2187 FPSCR_OR_VX(fpscr_vxsnan);
2188 if ((FPSCR & fpscr_ve) == 0) {
2189 *frT = (MASKED64(*frB, 0, 11)
2191 | MASKED64(*frB, 13, 34));
2192 FPSCR_SET_FPRF(fpscr_rf_quiet_nan);
2198 sign = EXTRACTED64(*frB, 0, 0);
2199 exp = EXTRACTED64(*frB, 1, 11) - 1023;
2200 frac_grx = BIT64(0) | INSERTED64(EXTRACTED64(*frB, 12, 63), 1, 52);
2201 Round_Single(processor, sign, &exp, &frac_grx);
2202 FPSCR_SET_XX(FPSCR & fpscr_fi);
2203 if (exp > 127 && (FPSCR & fpscr_oe) == 0) goto Disabled_Exponent_Overflow;
2204 if (exp > 127 && (FPSCR & fpscr_oe) != 0) goto Enabled_Overflow;
2205 *frT = (INSERTED64(sign, 0, 0)
2206 | INSERTED64(exp + 1023, 1, 11)
2207 | INSERTED64(EXTRACTED64(frac_grx, 1, 52), 12, 63));
2208 if (sign == 0) FPSCR_SET_FPRF(fpscr_rf_pos_normal_number);
2209 if (sign == 1) FPSCR_SET_FPRF(fpscr_rf_neg_normal_number);
2212 0.63,6.FRT,11./,16.FRB,21.814,31.Rc:X:64,f::Floating Convert To Integer Doubleword
2213 0.63,6.FRT,11./,16.FRB,21.815,31.Rc:X:64,f::Floating Convert To Integer Doubleword with round towards Zero
2214 0.63,6.FRT,11./,16.FRB,21.14,31.Rc:X:f::Floating Convert To Integer Word
2215 0.63,6.FRT,11./,16.FRB,21.15,31.Rc:X:f:fctiwz:Floating Convert To Integer Word with round towards Zero
2217 convert_to_integer(processor, cia,
2219 fpscr_rn_round_towards_zero, 32);
2221 0.63,6.FRT,11./,16.FRB,21.846,31.Rc:X:64,f::Floating Convert from Integer Doubleword
2222 int sign = EXTRACTED64(*frB, 0, 0);
2224 unsigned64 frac = *frB;
2225 if (frac == 0) goto Zero_Operand;
2226 if (sign == 1) frac = ~frac + 1;
2227 while (EXTRACTED64(frac, 0, 0) == 0) {
2228 /*??? do the loop 0 times if (FRB) = max negative integer */
2229 frac = INSERTED64(EXTRACTED64(frac, 1, 63), 0, 62);
2232 Round_Float(processor, sign, &exp, &frac, FPSCR & fpscr_rn);
2233 if (sign == 0) FPSCR_SET_FPRF(fpscr_rf_pos_normal_number);
2234 if (sign == 1) FPSCR_SET_FPRF(fpscr_rf_pos_normal_number);
2235 *frT = (INSERTED64(sign, 0, 0)
2236 | INSERTED64(exp + 1023, 1, 11)
2237 | INSERTED64(EXTRACTED64(frac, 1, 52), 12, 63));
2243 FPSCR_SET_FPRF(fpscr_rf_pos_zero);
2250 # I.4.6.7 Floating-Point Compare Instructions
2253 0.63,6.BF,9./,11.FRA,16.FRB,21.0,31./:X:f:fcmpu:Floating Compare Unordered
2256 if (is_NaN(*frA, 0) || is_NaN(*frB, 0))
2257 c = cr_i_summary_overflow; /* 0b0001 - (FRA) ? (FRB) */
2258 else if (is_less_than(frA, frB))
2259 c = cr_i_negative; /* 0b1000 - (FRA) < (FRB) */
2260 else if (is_greater_than(frA, frB))
2261 c = cr_i_positive; /* 0b0100 - (FRA) > (FRB) */
2263 c = cr_i_zero; /* 0b0010 - (FRA) = (FRB) */
2265 CR_SET(BF, c); /* CR[4*BF..4*BF+3] = c */
2266 if (is_SNaN(*frA, 0) || is_SNaN(*frB, 0))
2267 FPSCR_OR_VX(fpscr_vxsnan);
2269 0.63,6.BF,9./,11.FRA,16.FRB,21.32,31./:X:f:fcmpo:Floating Compare Ordered
2272 if (is_NaN(*frA, 0) || is_NaN(*frB, 0))
2273 c = cr_i_summary_overflow; /* 0b0001 - (FRA) ? (FRB) */
2274 else if (is_less_than(frA, frB))
2275 c = cr_i_negative; /* 0b1000 - (FRA) < (FRB) */
2276 else if (is_greater_than(frA, frB))
2277 c = cr_i_positive; /* 0b0100 - (FRA) > (FRB) */
2279 c = cr_i_zero; /* 0b0010 - (FRA) = (FRB) */
2281 CR_SET(BF, c); /* CR[4*BF..4*BF+3] = c */
2282 if (is_SNaN(*frA, 0) || is_SNaN(*frB, 0)) {
2283 FPSCR_OR_VX(fpscr_vxsnan);
2284 if ((FPSCR & fpscr_ve) == 0)
2285 FPSCR_OR_VX(fpscr_vxvc);
2287 else if (is_QNaN(*frA, 0) || is_QNaN(*frB, 0)) {
2288 FPSCR_OR_VX(fpscr_vxvc);
2294 # I.4.6.8 Floating-Point Status and Control Register Instructions
2297 0.63,6.FRT,11./,16./,21.583,31.Rc:X:f::Move From FPSCR
2298 0.63,6.BF,9./,11.BFA,14./,16./,21.64,31./:X:f::Move to Condition Register from FPSCR
2299 0.64,6.BF,9./,11./,16.U,20./,21.134,31.Rc:X:f::Move To FPSCR Field Immediate
2300 0.63,6./,7.FLM,15./,16.FRB,21.711,31.Rc:XFL:f::Move To FPSCR Fields
2301 0.63,6.BT,11./,16./,21.70,31.Rc:X:f::Move To FPSCR Bit 0
2302 0.63,6.BT,11./,16./,21.38,31.Rc:X:f::Move To FPSCR Bit 1
2306 # I.A.1.1 Floating-Point Store Instruction
2308 0.31,6.FRS,11.RA,16.RB,21.983,31./:X:f::Store Floating-Point as Integer Word Indexed
2311 # I.A.1.2 Floating-Point Arithmetic Instructions
2314 0.63,6.FRT,11./,16.FRB,21./,26.22,31.Rc:A:f::Floating Square Root
2315 0.59,6.FRT,11./,16.FRB,21./,26.22,31.Rc:A:f::Floating Square Root Single
2317 0.59,6.FRT,11./,16.FRB,21./,26.24,31.Rc:A:f::Floating Reciprocal Estimate Single
2318 0.63,6.FRT,11./,16.FRB,21./,26.26,31.Rc:A:f::Floating Reciprocal Square Root Estimate
2321 # I.A.1.3 Floating-Point Select Instruction
2324 0.63,6.FRT,11.FRA,16.FRB,21.FRC,26.23,31.Rc:A:f::Floating Select
2328 # II.3.2 Cache Management Instructions
2331 0.31,6./,11.RA,16.RB,21.982,31./:X::icbi:Instruction Cache Block Invalidate
2334 0.19,6./,11./,16./,21.150,31./:XL::isync:Instruction Synchronize
2335 cpu_synchronize_context(processor);
2339 # II.3.2.2 Data Cache Instructions
2342 0.31,6./,11.RA,16.RB,21.278,31./:X:::Data Cache Block Touch
2345 0.31,6./,11.RA,16.RB,21.246,31./:X:::Data Cache Block Touch for Store
2348 0.31,6./,11.RA,16.RB,21.1014,31./:X:::Data Cache Block set to Zero
2351 0.31,6./,11.RA,16.RB,21.54,31./:X:::Data Cache Block Store
2354 0.31,6./,11.RA,16.RB,21.86,31./:X:::Data Cache Block Flush
2358 # II.3.3 Envorce In-order Execution of I/O Instruction
2361 0.31,6./,11./,16./,21.854,31./:X::eieio:Enforce In-order Execution of I/O
2362 /* Since this model has no instruction overlap
2363 this instruction need do nothing */
2366 # II.4.1 Time Base Instructions
2369 0.31,6.RT,11.tbr,21.371,31./:XFX::mftb:Move From Time Base
2370 int n = (tbr{5:9} << 5) | tbr{0:4};
2372 if (is_64bit_implementation) *rT = TB;
2373 else *rT = EXTRACTED64(TB, 32, 63);
2375 else if (n == 269) {
2376 if (is_64bit_implementation) *rT = EXTRACTED64(TB, 0, 31);
2377 else *rT = EXTRACTED64(TB, 0, 31);
2380 program_interrupt(processor, cia,
2381 illegal_instruction_program_interrupt);
2385 # III.2.3.1 System Linkage Instructions
2388 #0.17,6./,11./,16./,30.1,31./:SC:::System Call
2389 0.19,6./,11./,16./,21.50,31./:XL:::Return From Interrupt
2392 # III.3.4.1 Move to/from System Register Instructions
2395 #0.31,6.RS,11.spr,21.467,31./:XFX:::Move To Special Purpose Register
2396 #0.31,6.RT,11.spr,21.339,31./:XFX:::Move From Special Purpose Register
2397 0.31,6.RS,11./,16./,21.146,31./:X:::Move To Machine State Register
2398 if (IS_PROBLEM_STATE(processor))
2399 program_interrupt(processor, cia,
2400 privileged_instruction_program_interrupt);
2403 0.31,6.RT,11./,16./,21.83,31./:X:::Move From Machine State Register
2404 if (IS_PROBLEM_STATE(processor))
2405 program_interrupt(processor, cia,
2406 privileged_instruction_program_interrupt);
2412 # III.4.11.1 Cache Management Instructions
2415 0.31,6./,11.RA,16.RB,21.470,31./:X::dcbi:Data Cache Block Invalidate
2419 # III.4.11.2 Segment Register Manipulation Instructions
2422 0.31,6.RS,11./,12.SR,16./,21.210,31./:X:32:mtsr %SR,%RS:Move To Segment Register
2423 if (IS_PROBLEM_STATE(processor))
2424 program_interrupt(processor, cia,
2425 privileged_instruction_program_interrupt);
2428 0.31,6.RS,11./,16.RB,21.242,31./:X:32:mtsrin %RS,%RB:Move To Segment Register Indirect
2429 if (IS_PROBLEM_STATE(processor))
2430 program_interrupt(processor, cia,
2431 privileged_instruction_program_interrupt);
2433 SEGREG(EXTRACTED32(*rB, 0, 3)) = *rS;
2434 0.31,6.RT,11./,12.SR,16./,21.595,31./:X:32:mfsr %RT,%RS:Move From Segment Register
2435 if (IS_PROBLEM_STATE(processor))
2436 program_interrupt(processor, cia,
2437 privileged_instruction_program_interrupt);
2440 0.31,6.RT,11./,16.RB,21.659,31./:X:32:mfsrin %RT,%RB:Move From Segment Register Indirect
2441 if (IS_PROBLEM_STATE(processor))
2442 program_interrupt(processor, cia,
2443 privileged_instruction_program_interrupt);
2445 *rT = SEGREG(EXTRACTED32(*rB, 0, 3));
2449 # III.4.11.3 Lookaside Buffer Management Instructions (Optional)
2452 0.31,6./,11./,16.RB,21.434,31./:X:64::SLB Invalidate Entry
2453 0.31,6./,11./,16./,21.498,31./:X:64::SLB Invalidate All
2455 0.31,6./,11./,16.RB,21.306,31./:X:::TLB Invalidate Entry
2456 0.31,6./,11./,16./,21.370,31./:X:::TLB Invalidate All
2458 0.31,6./,11./,16./,21.566,31./:X:::TLB Sychronize
2462 # III.A.1.2 External Access Instructions
2465 0.31,6.RT,11.RA,16.RB,21.310,31./:X:earwax::External Control In Word Indexed
2466 0.31,6.RS,11.RA,16.RB,21.438,31./:X:earwax::External Control Out Word Indexed