3 // Copyright (c) 2009 The University of Edinburgh
4 // All rights reserved.
6 // Redistribution and use in source and binary forms, with or without
7 // modification, are permitted provided that the following conditions are
8 // met: redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer;
10 // redistributions in binary form must reproduce the above copyright
11 // notice, this list of conditions and the following disclaimer in the
12 // documentation and/or other materials provided with the distribution;
13 // neither the name of the copyright holders nor the names of its
14 // contributors may be used to endorse or promote products derived from
15 // this software without specific prior written permission.
17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 ////////////////////////////////////////////////////////////////////
31 // The actual Power ISA decoder
32 // ------------------------------
34 // I've used the Power ISA Book I v2.06 for instruction formats,
35 // opcode numbers, register names, etc.
37 decode PO default Unknown::unknown() {
39 // Unconditionally branch to a PC-relative or absoulute address.
41 18: b({{ NIA = CIA + disp; }},
45 // Conditionally branch to a PC-relative or absoulute address based
47 format BranchDispCondOp {
48 16: bc({{ NIA = CIA + disp; }},
54 // Conditionally branch to an address in a register based on
55 // either CR only or both CR and CTR.
56 format BranchRegCondOp {
57 16: bclr({{ NIA = LR & -4ULL; }}, true, [ IsReturn ]);
58 528: bcctr({{ NIA = CTR & -4ULL; }});
59 560: bctar({{ NIA = TAR & -4ULL; }}, true);
62 // Condition register manipulation instructions.
65 uint32_t crBa = bits(CR, 31 - ba);
66 uint32_t crBb = bits(CR, 31 - bb);
67 CR = insertBits(CR, 31 - bt, crBa & crBb);
71 uint32_t crBa = bits(CR, 31 - ba);
72 uint32_t crBb = bits(CR, 31 - bb);
73 CR = insertBits(CR, 31 - bt, crBa | crBb);
77 uint32_t crBa = bits(CR, 31 - ba);
78 uint32_t crBb = bits(CR, 31 - bb);
79 CR = insertBits(CR, 31 - bt, !(crBa & crBb));
83 uint32_t crBa = bits(CR, 31 - ba);
84 uint32_t crBb = bits(CR, 31 - bb);
85 CR = insertBits(CR, 31 - bt, crBa ^ crBb);
89 uint32_t crBa = bits(CR, 31 - ba);
90 uint32_t crBb = bits(CR, 31 - bb);
91 CR = insertBits(CR, 31 - bt, !(crBa | crBb));
95 uint32_t crBa = bits(CR, 31 - ba);
96 uint32_t crBb = bits(CR, 31 - bb);
97 CR = insertBits(CR, 31 - bt, crBa == crBb);
101 uint32_t crBa = bits(CR, 31 - ba);
102 uint32_t crBb = bits(CR, 31 - bb);
103 CR = insertBits(CR, 31 - bt, crBa & !crBb);
107 uint32_t crBa = bits(CR, 31 - ba);
108 uint32_t crBb = bits(CR, 31 - bb);
109 CR = insertBits(CR, 31 - bt, crBa | !crBb);
115 uint32_t crBfa = bits(CR, 31 - bfa*4, 28 - bfa*4);
116 CR = insertBits(CR, 31 - bf*4, 28 - bf*4, crBfa);
121 150: isync({{ }}, [ IsSerializeAfter ]);
124 uint32_t msr12=(bits(MSR,60)&bits(SRR1,12))
125 |((bits(MSR,60)^0x01)&bits(MSR,12));
126 MSR = insertBits(MSR,12,msr12);
127 uint32_t msr60=bits(MSR,60)&bits(SRR1,60);
128 MSR = insertBits(MSR,60,msr60);
129 if((bits(MSR,34,32)!=0x02)|(bits(SRR1,34,32)!=0x00))
130 MSR = insertBits(MSR,34,32,bits(SRR1,34,32));
131 MSR = insertBits(MSR,15,(bits(SRR1,15)|bits(SRR1,14)));
132 MSR = insertBits(MSR,5,(bits(SRR1,5)|bits(SRR1,14)));
133 MSR = insertBits(MSR,4,(bits(SRR1,4)|bits(SRR1,14)));
134 MSR = insertBits(MSR,63,61,bits(SRR1,63,61));
135 MSR = insertBits(MSR,59,35,bits(SRR1,59,35));
136 MSR = insertBits(MSR,31,bits(SRR1,31));
137 MSR = insertBits(MSR,26,22,bits(SRR1,26,22));
138 MSR = insertBits(MSR,14,13,bits(SRR1,14,13));
139 MSR = insertBits(MSR,11,6,bits(SRR1,11,6));
140 MSR = insertBits(MSR,3,0,bits(SRR1,3,0));
142 }}, [ IsPrivileged ]);
144 if((bits(MSR,34,32)!=0x02)|(bits(HSRR1,34,32)!=0x00))
145 MSR = insertBits(MSR,34,32,bits(HSRR1,34,32));
146 MSR = insertBits(MSR,15,(bits(HSRR1,15)|bits(HSRR1,14)));
147 MSR = insertBits(MSR,5,(bits(HSRR1,5)|bits(HSRR1,14)));
148 MSR = insertBits(MSR,4,(bits(HSRR1,4)|bits(HSRR1,14)));
149 MSR = insertBits(MSR,63,35,bits(HSRR1,63,35));
150 MSR = insertBits(MSR,31,bits(HSRR1,31));
151 MSR = insertBits(MSR,26,22,bits(HSRR1,26,22));
152 MSR = insertBits(MSR,14,6,bits(HSRR1,14,6));
153 MSR = insertBits(MSR,3,0,bits(HSRR1,3,0));
158 default: decode DX_XO {
159 format IntDispArithOp {
160 2: addpcis({{ Rt = NIA + (disp << 16); }});
165 //TODO:Right now sc instruction not handles LEV=1 case
170 fault= std::make_shared<SystemCallInterrupt>();
172 xc->syscall(R0, &fault);
175 [ IsSyscall, IsNonSpeculative, IsSerializeAfter ]);
180 34: lbz({{ Rt = Mem_ub; }});
181 40: lhz({{ Rt = Mem_uh; }});
182 42: lha({{ Rt = Mem_sh; }});
183 32: lwz({{ Rt = Mem_uw; }});
187 format LoadDispShiftOp {
188 2: lwa({{ Rt = Mem_sw; }});
189 0: ld({{ Rt = Mem; }});
192 format LoadDispShiftUpdateOp {
193 1: ldu({{ Rt = Mem; }});
198 format StoreDispShiftOp {
199 0: std({{ Mem = Rs; }});
202 format StoreDispShiftUpdateOp {
203 1: stdu({{ Mem = Rs; }});
207 format LoadDispUpdateOp {
208 35: lbzu({{ Rt = Mem_ub; }});
209 41: lhzu({{ Rt = Mem_uh; }});
210 43: lhau({{ Rt = Mem_sh; }});
211 33: lwzu({{ Rt = Mem_uw; }});
215 38: stb({{ Mem_ub = Rs_ub; }});
216 44: sth({{ Mem_uh = Rs_uh; }});
217 36: stw({{ Mem = Rs_uw; }});
220 format StoreDispUpdateOp {
221 39: stbu({{ Mem_ub = Rs_ub; }});
222 45: sthu({{ Mem_uh = Rs_uh; }});
223 37: stwu({{ Mem = Rs_uw; }});
226 format IntImmArithCheckRaOp {
227 14: addi({{ Rt = Ra + simm; }},
229 15: addis({{ Rt = Ra + (simm << 16); }},
230 {{ Rt = simm << 16; }});
233 format IntImmArithOp {
253 int64_t res = Ra_sd * simm;
260 // Arithmetic instructions that use source registers Ra, Rb and Rc,
261 // with destination register Rt.
265 std::tie(std::ignore, res) = multiplyAdd(Ra_sd, Rb_sd, Rc_sd);
271 std::tie(std::ignore, res) = multiplyAdd(Ra, Rb, Rc);
277 std::tie(res, std::ignore) = multiplyAdd(Ra_sd, Rb_sd, Rc_sd);
283 format IntImmCompOp {
286 cr = makeCRField(Ra_sd, simm, xer.so);
288 cr = makeCRField((int32_t)Ra_sd, simm, xer.so);
293 format IntImmCompLogicOp {
296 cr = makeCRField(Ra, uimm, xer.so);
298 cr = makeCRField((uint32_t)Ra, uimm, xer.so);
303 format IntImmLogicOp {
304 24: ori({{ Ra = Rs | uimm; }});
305 25: oris({{ Ra = Rs | (uimm << 16); }});
306 26: xori({{ Ra = Rs ^ uimm; }});
307 27: xoris({{ Ra = Rs ^ (uimm << 16); }});
308 28: andi_({{ Ra = Rs & uimm; }},
310 29: andis_({{ Ra = Rs & (uimm << 16); }},
317 res = rotate(Rs, shift);
318 res = res & bitmask(maskBeg, maskEnd);
324 res = rotate(Rs, Rb);
325 res = res & bitmask(maskBeg, maskEnd);
331 mask = bitmask(maskBeg, maskEnd);
332 res = rotate(Rs, shift);
333 res = (res & mask) | (Ra & ~mask);
338 // There are a large number of instructions that have the same primary
339 // opcode (PO) of 31. In this case, the instructions are of different
340 // forms. For every form, the XO fields may vary in position and width.
341 // The X, XFL, XFX and XL form instructions use bits 21 - 30 and the
342 // XO form instructions use bits 22 - 30 as extended opcode (XO). To
343 // avoid conflicts, instructions of each form have to be defined under
344 // separate decode blocks. However, only a single decode block can be
345 // associated with a particular PO and it will recognize only one type
346 // of XO field. A solution for associating decode blocks for the other
347 // types of XO fields with the same PO is to have the other blocks as
348 // nested default cases.
351 // All loads with an index register. The non-update versions
352 // all use the value 0 if Ra == R0, not the value contained in
353 // R0. Others update Ra with the effective address. In all cases,
354 // Ra and Rb are source registers, Rt is the destintation.
356 87: lbzx({{ Rt = Mem_ub; }});
357 52: lbarx({{ Rt = Mem_ub; Rsv = 1; RsvLen = 1; RsvAddr = EA; }});
358 279: lhzx({{ Rt = Mem_uh; }});
359 343: lhax({{ Rt = Mem_sh; }});
360 116: lharx({{ Rt = Mem_uh; Rsv = 1; RsvLen = 2; RsvAddr = EA; }});
361 790: lhbrx({{ Rt = swap_byte(Mem_uh); }});
362 23: lwzx({{ Rt = Mem_uw; }});
363 341: lwax({{ Rt = Mem_sw; }});
364 20: lwarx({{ Rt = Mem_uw; Rsv = 1; RsvLen = 4; RsvAddr = EA; }});
365 534: lwbrx({{ Rt = swap_byte(Mem_uw); }});
366 21: ldx({{ Rt = Mem; }});
367 84: ldarx({{ Rt = Mem_ud; Rsv = 1; RsvLen = 8; RsvAddr = EA; }});
368 532: ldbrx({{ Rt = swap_byte(Mem); }});
369 535: lfsx({{ Ft_sf = Mem_sf; }});
370 599: lfdx({{ Ft = Mem_df; }});
371 855: lfiwax({{ Ft_uw = Mem; }});
374 format LoadIndexUpdateOp {
375 119: lbzux({{ Rt = Mem_ub; }});
376 311: lhzux({{ Rt = Mem_uh; }});
377 375: lhaux({{ Rt = Mem_sh; }});
378 55: lwzux({{ Rt = Mem_uw; }});
379 373: lwaux({{ Rt = Mem_sw; }});
380 53: ldux({{ Rt = Mem; }});
381 567: lfsux({{ Ft_sf = Mem_sf; }});
382 631: lfdux({{ Ft = Mem_df; }});
385 format StoreIndexOp {
386 215: stbx({{ Mem_ub = Rs_ub; }});
388 bool store_performed = false;
393 store_performed = true;
399 cr.cr0 = ((store_performed ? 0x2 : 0x0) | xer.so);
403 407: sthx({{ Mem_uh = Rs_uh; }});
405 bool store_performed = false;
410 store_performed = true;
416 cr.cr0 = ((store_performed ? 0x2 : 0x0) | xer.so);
420 918: sthbrx({{ Mem_uh = swap_byte(Rs_uh); }});
421 151: stwx({{ Mem_uw = Rs_uw; }});
423 bool store_performed = false;
428 store_performed = true;
434 cr.cr0 = ((store_performed ? 0x2 : 0x0) | xer.so);
438 662: stwbrx({{ Mem_uw = swap_byte(Rs_uw); }});
439 149: stdx({{ Mem = Rs }});
441 bool store_performed = false;
446 store_performed = true;
452 cr.cr0 = ((store_performed ? 0x2 : 0x0) | xer.so);
456 660: stdbrx({{ Mem = swap_byte(Rs); }});
459 format StoreIndexUpdateOp {
460 247: stbux({{ Mem_ub = Rs_ub; }});
461 439: sthux({{ Mem_uh = Rs_uh; }});
462 183: stwux({{ Mem_uw = Rs_uw; }});
463 181: stdux({{ Mem = Rs; }});
468 int64_t src1 = Ra_sw;
469 int64_t src2 = Rb_sw;
470 if ((src1 != INT32_MIN || src2 != -1) && src2 != 0) {
478 uint64_t src1 = Ra_uw;
479 uint64_t src2 = Rb_uw;
488 int64_t src1 = Ra_sd;
489 int64_t src2 = Rb_sd;
490 if ((src1 != INT64_MIN || src2 != -1) && src2 != 0) {
511 cr = makeCRField(Ra_sd, Rb_sd, xer.so);
513 cr = makeCRField((int32_t)Ra_sd, (int32_t)Rb_sd, xer.so);
519 cr = makeCRField(Ra, Rb, xer.so);
521 cr = makeCRField((uint32_t)Ra, (uint32_t)Rb, xer.so);
526 uint32_t src1 = Ra_ub;
527 uint32_t src2 = Rb_uw;
528 uint8_t src2lo = src2 & 0xff;
529 uint8_t src2hi = (src2 >>= 8) & 0xff;
530 uint32_t res = (src2lo <= src1) & (src1 <= src2hi);
532 src2lo = (src2 >>= 8) & 0xff;
533 src2hi = (src2 >>= 8) & 0xff;
534 res = ((src2lo <= src1) & (src1 <= src2hi)) | res;
540 const uint64_t m1 = 0x0101010101010101;
541 const uint64_t m2 = 0x8080808080808080;
542 uint64_t res = Rb ^ (Ra_ub * m1);
543 res = (res - m1) & ~res & m2;
544 cr = (res != 0) << 2;
548 // Generic integer format instructions.
551 0x004: mftfhar({{ Rt = TFHAR; }});
552 0x008: mfvrsave({{ Rt = VRSAVE; }});
553 0x018: mfsier({{Rt = SIER;}});
554 0x019: mfbescrs({{Rt = BESCRS;}});
555 0x01C: mfppr({{ Rt = PPR; }});
556 0x020: mfxer({{ Rt = XER; }});
557 0x024: mftfiar({{ Rt = TFIAR; }});
558 0x039: mfbescrsu({{Rt = BESCRSU;}});
559 0x044: mftexasr({{ Rt = TEXASR; }});
560 0x05C: mfppr2({{ Rt =PPR32; }});
561 0x078: mfupmc1({{Rt = PMC1;}});
562 0x098: mfupmc2({{Rt = PMC2;}});
563 0x099: mfebbhr({{Rt = EBBHR;}});
564 0x0b8: mfupmc3({{Rt = PMC3;}});
565 0x0b9: mfebbrr({{Rt = EBBRR;}});
566 0x0d8: mfupmc4({{Rt = PMC4;}});
567 0x0d9: mfbescr({{Rt = BESCR;}});
568 0x0f8: mfupmc5({{Rt = PMC5;}});
569 0x100: mflr({{ Rt = LR; }});
570 0x104: mfctrl({{ Rt = CTRL; }});
571 0x118: mfupmc6r({{Rt = PMC6;}});
572 0x120: mfctr({{ Rt = CTR; }});
573 0x188: mftb({{ Rt = TB; }});
574 0x1A8: mftbu({{ Rt = TBU; }});
575 0x1b8: mfsdar({{Rt = SDAR;}});
576 0x1f9: mftar({{Rt = TAR;}});
577 0x204: mftidr({{ Rt = TIDR; }}, [ IsPrivileged ]);
578 0x205: mfdpdes({{ Rt = DPDES; }}, [ IsPrivileged ]);
579 0x208: mfsprg0({{Rt = SPRG0;}});
580 0x209: mfhsprg0({{Rt = HSPRG0;}});
581 0x20a: mfhmer({{Rt = HMER;}});
582 0x20E: mfptcr({{ Rt = PTCR; }});
583 0x219: mfasdr({{Rt = ASDR;}});
584 0x21a: mfic({{Rt = IC;}}, [ IsPrivileged ]);
585 0x21f: mfhir0({{Rt = HIR0;}});
586 0x220: mfdscr({{ Rt = DSCR; }});
587 0x228: mfsprg1({{Rt = SPRG1;}});
588 0x229: mfhsprg1({{Rt = HSPRG1;}});
589 0x22a: mfhmeer({{Rt = HMEER;}});
590 0x23a: mfvtb({{Rt = VTB;}}, [ IsPrivileged ]);
591 0x240: mfdsisr({{ Rt = DSISR; }});
592 0x248: mfsprg2({{Rt = SPRG2;}});
593 0x249: mfhdisr({{Rt = HDSISR;}});
594 0x24a: mfpcr({{Rt = PCR;}});
595 0x260: mfdar({{ Rt = DAR; }});
596 0x268: mfsprg3({{Rt = SPRG3;}});
597 0x269: mfhdar({{Rt = HDAR;}});
598 0x285: mfdawr0({{ Rt = DAWR0; }});
599 0x289: mfspurr({{Rt = SPURR;}}, [ IsPrivileged ]);
600 0x2a9: mfpurr({{Rt = PURR;}}, [ IsPrivileged ]);
601 0x2C0: mfdec({{ Rt = DEC; }});
602 0x2c9: mfhdec({{Rt = HDEC;}});
603 0x2fa: mfpsscr({{Rt = PSSCR;}});
604 0x324: mffscr({{Rt = FSCR;}});
605 0x329: mfhrmor({{Rt = HRMOR;}});
606 0x340: mfsrr0({{ Rt = SRR0; }});
607 0x345: mfrpr({{ Rt = RPR; }});
608 0x349: mfhssr0({{Rt = HSRR0;}});
609 0x360: mfsrr1({{ Rt = SRR1; }});
610 0x365: mfciabr({{ Rt = CIABR; }});
611 0x368: mfcir({{Rt = CIR;}}, [ IsPrivileged ]);
612 0x369: mfhssr1({{Rt = HSRR1;}});
613 0x380: mfcfar({{ Rt = CFAR; }});
614 0x3a0: mfamr({{ Rt = AMR; }}, [ IsPrivileged ]);
615 0x3a1: mfiamr({{Rt = IAMR;}});
616 0x3a4: mfuamor({{ Rt = UAMOR; }}, [ IsPrivileged ]);
617 0x3aa: mfamor({{Rt = AMOR;}});
618 0x3c5: mfhfscr({{Rt = HFSCR;}});
619 0x3c9: mflpcr({{Rt = LPCR;}});
620 0x3E8: mfpvr({{ Rt = PVR; }});
621 0x3e9: mflpidr({{Rt = LPIDR;}});
625 0x004: mttfhar({{TFHAR = Rs;}});
626 0x008: mtvrsave({{ VRSAVE = Rs; }});
627 0x019: mtbescrs({{BESCRS = Rs;}});
628 0x01C: mtppr({{ PPR = Rs; }});
629 0x020: mtxer({{ XER = Rs; }});
630 0x024: mttfiar({{TFIAR = Rs;}});
631 0x039: mtbescrsu({{BESCRSU = Rs;}});
632 0x044: mttexasr({{TEXASR = Rs;}});
633 0x05C: mtppr32({{ PPR32 = Rs; }});
634 0x078: mtupmc1({{PMC1 = Rs;}});
635 0x098: mtupmc2({{PMC2 = Rs;}});
636 0x099: mtebbhr({{EBBHR = Rs;}});
637 0x0b8: mtupmc3({{PMC3 = Rs;}});
638 0x0b9: mtebbrr({{EBBRR = Rs;}});
639 0x0d8: mtupmc4({{PMC4 = Rs;}});
640 0x0d9: mtbescr({{BESCR = Rs;}});
641 0x0f8: mtupmc5({{PMC5 = Rs;}});
642 0x100: mtlr({{ LR = Rs; }});
643 0x118: mtupmc6({{PMC6 = Rs;}});
644 0x120: mtctr({{ CTR = Rs; }});
645 0x1A8: mttbu({{ TBU = Rs; }});
646 0x1f9: mttar({{TAR = Rs;}});
647 0x201: mtpidr({{PIDR = Rs;}});
648 0x204: mttidr({{TIDR = Rs;}}, [ IsPrivileged ]);
649 0x205: mtdpdes({{DPDES = Rs;}});
650 0x208: mtsprg0({{SPRG0 = Rs;}});
651 0x209: mthsprg0({{HSPRG0 = Rs;}});
652 0x20a: mthmer({{HMER = Rs;}});
653 0x20E: mtptcr({{ PTCR = Rs; }});
654 0x219: mtasdr({{ASDR = Rs;}});
655 0x21a: mtic({{IC = Rs;}});
656 0x21f: mthir0({{HIR0 = Rs;}});
657 0x220: mtdscr({{ DSCR = Rs; }});
658 0x228: mtsprg1({{SPRG1 = Rs;}});
659 0x229: mthsprg1({{HSPRG1 = Rs;}});
660 0x22a: mthmeer({{HMEER = Rs;}});
661 0x238: mtmmcr2({{MMCR2 = Rs;}});
662 0x23a: mtvtb({{VTB = Rs;}});
663 0x240: mtdsisr({{ DSISR = Rs; }});
664 0x248: mtsprg2({{SPRG2 = Rs;}});
665 0x249: mthdisr({{HDSISR = Rs;}});
666 0x24a: mtpcr({{PCR = Rs;}});
667 0x258: mtmmcra({{MMCRA = Rs;}});
668 0x260: mtdar({{ DAR = Rs; }});
669 0x268: mtsprg3({{SPRG3 = Rs;}});
670 0x269: mthdar({{HDAR = Rs;}});
671 0x27a: mtmmcrc({{MMCRC = Rs;}});
672 0x285: mtdawr0({{DAWR0 = Rs;}});
673 0x289: mtspurr({{SPURR = Rs;}});
674 0x2a9: mtpurr({{PURR = Rs;}});
675 0x2C0: mtdec({{ DEC = Rs; }});
676 0x2c9: mthdec({{HDEC = Rs;}});
677 0x2fa: mtpsscr({{PSSCR = Rs;}});
678 0x304: mtctrl({{ CTRL = Rs; }});
679 0x324: mtfscr({{FSCR = Rs;}});
680 0x329: mthrmor({{HRMOR = Rs;}});
681 0x340: mtsrr0({{ SRR0 = Rs; }});
682 0x345: mtrpr({{RPR = Rs;}});
683 0x349: mthssr0({{HSRR0 = Rs;}});
684 0x360: mtsrr1({{ SRR1 = Rs; }});
685 0x365: mtciabr({{CIABR = Rs;}});
686 0x369: mthssr1({{HSRR1 = Rs;}});
687 0x378: mtmmcr0({{MMCR0 = Rs;}});
688 0x380: mtcfar({{ CFAR = Rs; }});
689 0x390: mttbl({{ TBL = Rs; }});
690 0x3a0: mtamr({{AMR = Rs;}}, [ IsPrivileged ]);
691 0x3a1: mtiamr({{IAMR = Rs;}});
692 0x3a4: mtuamor({{UAMOR = Rs;}}, [ IsPrivileged ]);
693 0x3aa: mtamor({{AMOR = Rs;}});
694 0x3c5: mthfscr({{HFSCR = Rs;}});
695 0x3c8: mttbu40({{TBU40 = Rs;}});
696 0x3c9: mtlpcr({{LPCR = Rs;}});
697 0x3d8: mtmmcr1({{MMCR1 = Rs;}});
698 0x3e9: mtlpidr({{LPIDR = Rs;}});
701 83: mfmsr({{ Rt = MSR; }}, [ IsPrivileged ]);
705 uint64_t val = bits(Rs, 34, 32);
707 if(bits(MSR, 34, 32) != 0x2 || val != 0x0) {
708 MSR = insertBits(MSR, 34, 32, val);
713 MSR = insertBits(MSR, 5, bits(Rs, 5) | val);
714 MSR = insertBits(MSR, 4, bits(Rs, 4) | val);
716 MSR = insertBits(MSR, 63, 61, bits(Rs, 63, 61));
717 MSR = insertBits(MSR, 59, 35, bits(Rs, 59, 35));
718 MSR = insertBits(MSR, 31, 16, bits(Rs, 31, 16));
719 MSR = insertBits(MSR, 14, 13, bits(Rs, 14, 13));
720 MSR = insertBits(MSR, 11, 6, bits(Rs, 11, 6));
721 MSR = insertBits(MSR, 3, 1, bits(Rs, 3, 1));
723 MSR = insertBits(MSR, 15, bits(Rs, 15));
724 MSR = insertBits(MSR, 1, bits(Rs, 1));
726 }}, [ IsPrivileged ]);
730 MSR = insertBits(MSR,15,bits(Rs,15)|bits(Rs,14));
731 MSR = insertBits(MSR,5,bits(Rs,5)|bits(Rs,14));
732 MSR = insertBits(MSR,4,bits(Rs,4)|bits(Rs,14));
733 MSR = insertBits(MSR,31,16,bits(Rs,31,16));
734 MSR = insertBits(MSR,14,13,bits(Rs,14,13));
735 MSR = insertBits(MSR,11,6,bits(Rs,11,6));
736 MSR = insertBits(MSR,3,1,bits(Rs,3,1));
739 MSR = insertBits(MSR,15,bits(Rs,15));
740 MSR = insertBits(MSR,1,bits(Rs,1));
742 }}, [ IsPrivileged ]);
745 // Integer logic instructions use source registers Rs and Rb,
746 // with destination register Ra.
748 28: and({{ Ra = Rs & Rb; }}, true);
749 316: xor({{ Ra = Rs ^ Rb; }}, true);
750 476: nand({{ Ra = ~(Rs & Rb); }}, true);
751 444: or({{ Ra = Rs | Rb; }}, true);
752 124: nor({{ Ra = ~(Rs | Rb); }}, true);
753 60: andc({{ Ra = Rs & ~Rb; }}, true);
754 284: eqv({{ Ra = ~(Rs ^ Rb); }}, true);
755 412: orc({{ Ra = Rs | ~Rb; }}, true);
756 954: extsb({{ Ra = Rs_sb; }}, true);
757 922: extsh({{ Ra = Rs_sh; }}, true);
758 986: extsw({{ Ra = Rs_sw; }}, true);
759 26: cntlzw({{ Ra = findLeadingZeros(Rs_uw); }}, true);
760 58: cntlzd({{ Ra = findLeadingZeros(Rs); }}, true);
761 538: cnttzw({{ Ra = findTrailingZeros(Rs_uw); }}, true);
762 570: cnttzd({{ Ra = findTrailingZeros(Rs); }}, true);
765 uint64_t mask = 0xff;
767 for (int i = 0; i < 8; ++i) {
768 if ((Rs & mask) == (Rb & mask)) {
777 const uint64_t m1 = 0x5555555555555555ULL;
778 const uint64_t m2 = 0x3333333333333333ULL;
779 const uint64_t m4 = 0x0f0f0f0f0f0f0f0fULL;
781 res = (res & m1) + ((res >> 1) & m1);
782 res = (res & m2) + ((res >> 2) & m2);
783 res = (res & m4) + ((res >> 4) & m4);
788 const uint64_t m1 = 0x5555555555555555ULL;
789 const uint64_t m2 = 0x3333333333333333ULL;
790 const uint64_t m4 = 0x0f0f0f0f0f0f0f0fULL;
791 const uint64_t m8 = 0x00ff00ff00ff00ffULL;
792 const uint64_t m16 = 0x0000ffff0000ffffULL;
794 res = (res & m1) + ((res >> 1) & m1);
795 res = (res & m2) + ((res >> 2) & m2);
796 res = (res & m4) + ((res >> 4) & m4);
797 res = (res & m8) + ((res >> 8) & m8);
798 res = (res & m16) + ((res >> 16) & m16);
802 506: popcntd({{ Ra = popCount(Rs); }});
806 res = res ^ (res >> 16);
807 res = res ^ (res >> 8);
808 res = res & 0x100000001;
814 res = res ^ (res >> 32);
815 res = res ^ (res >> 16);
816 res = res ^ (res >> 8);
823 for (int i = 0; i < 8; ++i) {
824 int index = (Rs >> (i * 8)) & 0xff;
826 if (Rb & (1ULL << (63 - index))) {
835 // Integer instructions with a shift value.
838 int32_t shift = Rb_sw;
839 uint32_t res = Rs_uw & ~((shift << 26) >> 31);
841 shift = shift & 0x1f;
848 int32_t shift = Rb_sw;
849 uint32_t res = Rs_uw & ~((shift << 26) >> 31);
851 shift = shift & 0x1f;
859 uint32_t shift = Rb_uw;
861 if ((shift & 0x20) != 0) {
868 shift = shift & 0x1f;
870 if (src < 0 && (src & mask(shift)) != 0) {
886 if (src < 0 && (src & mask(shift)) != 0) {
897 format IntConcatShiftOp {
899 int64_t shift = Rb_sd;
900 uint64_t res = Rs & ~((shift << 57) >> 63);
902 shift = shift & 0x3f;
909 int64_t shift = Rb_sd;
910 uint64_t res = Rs & ~((shift << 57) >> 63);
912 shift = shift & 0x3f;
922 if ((shift & 0x40) != 0) {
929 shift = shift & 0x3f;
931 if (src < 0 && (src & mask(shift)) != 0) {
943 format StoreIndexOp {
944 663: stfsx({{ Mem_sf = Fs_sf; }});
945 727: stfdx({{ Mem_df = Fs; }});
946 983: stfiwx({{ Mem = Fs_uw; }});
949 format StoreIndexUpdateOp {
950 695: stfsux({{ Mem_sf = Fs_sf; }});
951 759: stfdux({{ Mem_df = Fs; }});
954 // These instructions all provide data cache hints
958 598: sync({{ }}, [ IsMemBarrier ]);
959 854: eieio({{ }}, [ IsMemBarrier ]);
963 274: tlbiel({{ }}, [ IsPrivileged ]);
965 498: slbia({{ }}, [ IsPrivileged ]);
968 // These instructions are of XO form with bit 21 as the OE bit.
969 default: decode XO_XO {
971 // These instructions can all be reduced to the form
972 // Rt = src1 + src2 [+ CA], therefore we just give src1 and src2
973 // (and, if necessary, CA) definitions and let the python script
974 // deal with setting things up correctly. We also give flags to
975 // say which control registers to set.
977 266: add({{ Ra }}, {{ Rb }});
978 40: subf({{ ~Ra }}, {{ Rb }}, {{ 1 }});
979 10: addc({{ Ra }}, {{ Rb }},
981 8: subfc({{ ~Ra }}, {{ Rb }}, {{ 1 }},
983 104: neg({{ ~Ra }}, {{ 1 }});
984 138: adde({{ Ra }}, {{ Rb }}, {{ xer.ca }},
986 234: addme({{ Ra }}, {{ -1ULL }}, {{ xer.ca }},
988 136: subfe({{ ~Ra }}, {{ Rb }}, {{ xer.ca }},
990 232: subfme({{ ~Ra }}, {{ -1ULL }}, {{ xer.ca }},
992 202: addze({{ Ra }}, {{ xer.ca }},
994 200: subfze({{ ~Ra }}, {{ xer.ca }},
998 // Arithmetic instructions all use source registers Ra and Rb,
999 // with destination register Rt.
1000 format IntArithCheckRcOp {
1002 uint64_t res = (int64_t)Ra_sw * Rb_sw;
1008 uint64_t res = (uint64_t)Ra_uw * Rb_uw;
1014 int64_t res = (int64_t)Ra_sw * Rb_sw;
1015 if (res != (int32_t)res) {
1024 std::tie(std::ignore, res) = multiply(Ra_sd, Rb_sd);
1030 std::tie(std::ignore, res) = multiply(Ra, Rb);
1035 int64_t src1 = Ra_sd;
1036 int64_t src2 = Rb_sd;
1037 uint64_t res = src1 * src2;
1038 std::tie(res, std::ignore) = multiply(src1, src2);
1039 if (src1 != 0 && (int64_t)res / src1 != src2) {
1047 int32_t src1 = Ra_sw;
1048 int32_t src2 = Rb_sw;
1049 if ((src1 != INT32_MIN || src2 != -1) && src2 != 0) {
1050 Rt = (uint32_t)(src1 / src2);
1059 uint32_t src1 = Ra_uw;
1060 uint32_t src2 = Rb_uw;
1071 int32_t src1 = Ra_sw;
1072 int32_t src2 = Rb_sw;
1074 if ((src1 != INT32_MIN || src2 != -1) && src2 != 0) {
1075 res = ((int64_t)src1 << 32) / src2;
1076 if (res == (int32_t)res) {
1090 uint32_t src1 = Ra_ud;
1091 uint32_t src2 = Rb_ud;
1094 res = ((uint64_t)src1 << 32) / src2;
1095 if (res <= UINT32_MAX) {
1109 int64_t src1 = Ra_sd;
1110 int64_t src2 = Rb_sd;
1111 if ((src1 != INT64_MIN || src2 != -1) && src2 != 0) {
1133 int64_t src1 = Ra_sd;
1134 int64_t src2 = Rb_sd;
1136 std::tie(setOV, res, std::ignore) = divide(0, src1, src2);
1149 std::tie(setOV, res, std::ignore) = divide(0, src1, src2);
1159 // These instructions are of XS form and use bits 21 - 29 as XO.
1160 default: decode XS_XO {
1161 format IntConcatShiftOp {
1163 int64_t src = Rs_sd;
1166 if (src < 0 && (src & mask(shift))) {
1176 int64_t src = Rs_sw;
1185 default: decode XFX_XO {
1189 for (int i = 0; i < 8; ++i) {
1190 if (((FXM >> i) & 0x1) == 0x1) {
1191 mask |= 0xf << (4 * i);
1194 CR = (Rs & mask) | (CR & ~mask);
1197 19: mfcr({{ Rt = CR; }});
1204 // These instructions are of MD form and use bits 27 - 29 as XO.
1206 format IntConcatRotateOp {
1210 res = rotate(Rs, shift);
1214 res = res & bitmask(maskBeg, 63);
1221 res = rotate(Rs, shift);
1225 res = res & bitmask(0, maskEnd);
1232 res = rotate(Rs, shift);
1236 res = res & bitmask(maskBeg, ~shift);
1242 mask = bitmask(maskBeg, ~shift);
1244 res = rotate(Rs, shift);
1249 res = res | (Ra & ~mask);
1253 // These instructions are of MDS form and use bits 27 - 30 as XO.
1254 default: decode MDS_XO {
1257 uint32_t shift = Rb & 0x3f;
1259 res = rotate(Rs, shift);
1263 res = res & bitmask(maskBeg, 63);
1269 uint32_t shift = Rb & 0x3f;
1271 res = rotate(Rs, shift);
1275 res = res & bitmask(0, maskEnd);
1283 48: lfs({{ Ft_sf = Mem_sf; }});
1284 50: lfd({{ Ft = Mem_df; }});
1287 format LoadDispUpdateOp {
1288 49: lfsu({{ Ft_sf = Mem_sf; }});
1289 51: lfdu({{ Ft = Mem_df; }});
1292 format StoreDispOp {
1293 52: stfs({{ Mem_sf = Fs_sf; }});
1294 54: stfd({{ Mem_df = Fs; }});
1297 format StoreDispUpdateOp {
1298 53: stfsu({{ Mem_sf = Fs_sf; }});
1299 55: stfdu({{ Mem_df = Fs; }});
1302 format FloatArithOp {
1304 21: fadds({{ Ft = Fa + Fb; }});
1305 20: fsubs({{ Ft = Fa - Fb; }});
1306 25: fmuls({{ Ft = Fa * Fc; }});
1307 18: fdivs({{ Ft = Fa / Fb; }});
1308 29: fmadds({{ Ft = (Fa * Fc) + Fb; }});
1309 28: fmsubs({{ Ft = (Fa * Fc) - Fb; }});
1310 31: fnmadds({{ Ft = -((Fa * Fc) + Fb); }});
1311 30: fnmsubs({{ Ft = -((Fa * Fc) - Fb); }});
1316 format FloatArithOp {
1317 21: fadd({{ Ft = Fa + Fb; }});
1318 20: fsub({{ Ft = Fa - Fb; }});
1319 25: fmul({{ Ft = Fa * Fc; }});
1320 18: fdiv({{ Ft = Fa / Fb; }});
1321 29: fmadd({{ Ft = (Fa * Fc) + Fb; }});
1322 28: fmsub({{ Ft = (Fa * Fc) - Fb; }});
1323 31: fnmadd({{ Ft = -((Fa * Fc) + Fb); }});
1324 30: fnmsub({{ Ft = -((Fa * Fc) - Fb); }});
1327 default: decode X_XO {
1328 format FloatRCCheckOp {
1329 72: fmr({{ Ft = Fb; }});
1332 Ft_ud = insertBits(Ft_ud, 63, 0); }});
1335 Ft_ud = insertBits(Ft_ud, 63, 1); }});
1336 40: fneg({{ Ft = -Fb; }});
1339 Ft_ud = insertBits(Ft_ud, 63, Fa_ud<63:63>);
1343 format FloatConvertOp {
1344 12: frsp({{ Ft_sf = Fb; }});
1345 15: fctiwz({{ Ft_sw = (int32_t)trunc(Fb); }});
1350 uint32_t c = makeCRField(Fa, Fb);
1351 Fpscr fpscr = FPSCR;
1352 fpscr.fprf.fpcc = c;
1354 CR = insertCRField(CR, BF, c);
1358 format FloatRCCheckOp {
1359 583: mffs({{ Ft_ud = FPSCR; }});
1361 FPSCR = insertCRField(FPSCR, BF + (8 * (1 - W_FIELD)),
1364 70: mtfsb0({{ FPSCR = insertBits(FPSCR, 31 - BT, 0); }});
1365 38: mtfsb1({{ FPSCR = insertBits(FPSCR, 31 - BT, 1); }});
1367 default: decode XFL_XO {
1369 if (L_FIELD == 1) { FPSCR = Fb_ud; }
1371 for (int i = 0; i < 8; ++i) {
1372 if (bits(FLM, i) == 1) {
1373 int k = 4 * (i + (8 * (1 - W_FIELD)));
1374 FPSCR = insertBits(FPSCR, k + 3, k,
1375 bits(Fb_ud, k + 3, k));