3 // Copyright (c) 2010 ARM Limited
6 // The license below extends only to copyright in the software and shall
7 // not be construed as granting a license to any other intellectual
8 // property including but not limited to intellectual property relating
9 // to a hardware implementation of the functionality of the software
10 // licensed hereunder. You may use the software subject to the license
11 // terms below provided that you ensure that this notice is replicated
12 // unmodified and in its entirety in all distributions of the software,
13 // modified or unmodified, in source code or in binary form.
15 // Copyright (c) 2007-2008 The Florida State University
16 // All rights reserved.
18 // Redistribution and use in source and binary forms, with or without
19 // modification, are permitted provided that the following conditions are
20 // met: redistributions of source code must retain the above copyright
21 // notice, this list of conditions and the following disclaimer;
22 // redistributions in binary form must reproduce the above copyright
23 // notice, this list of conditions and the following disclaimer in the
24 // documentation and/or other materials provided with the distribution;
25 // neither the name of the copyright holders nor the names of its
26 // contributors may be used to endorse or promote products derived from
27 // this software without specific prior written permission.
29 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
30 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
31 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
32 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
33 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
34 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
35 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
36 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
37 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
38 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
39 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
41 // Authors: Stephen Hines
43 ////////////////////////////////////////////////////////////////////
45 // Floating Point operate instructions
48 def template FPAExecute {{
49 Fault %(class_name)s::execute(%(CPU_exec_context)s *xc, Trace::InstRecord *traceData) const
51 Fault fault = NoFault;
58 if (%(predicate_test)s) {
60 if (fault == NoFault) {
69 def template FloatDoubleDecode {{
71 ArmStaticInst *i = NULL;
72 switch (OPCODE_19 << 1 | OPCODE_7)
75 i = (ArmStaticInst *)new %(class_name)sS(machInst);
78 i = (ArmStaticInst *)new %(class_name)sD(machInst);
83 panic("Cannot decode float/double nature of the instruction");
89 // Primary format for float point operate instructions:
90 def format FloatOp(code, *flags) {{
94 iop = InstObjParams(name, Name, 'PredOp',
96 "predicate_test": predicateTest},
98 header_output = BasicDeclare.subst(iop)
99 decoder_output = BasicConstructor.subst(iop)
100 exec_output = FPAExecute.subst(iop)
103 sng_iop = InstObjParams(name, Name+'S', 'PredOp',
105 "predicate_test": predicateTest},
107 header_output += BasicDeclare.subst(sng_iop)
108 decoder_output += BasicConstructor.subst(sng_iop)
109 exec_output += FPAExecute.subst(sng_iop)
111 dbl_code = re.sub(r'\.sf', '.df', orig_code)
114 dbl_iop = InstObjParams(name, Name+'D', 'PredOp',
116 "predicate_test": predicateTest},
118 header_output += BasicDeclare.subst(dbl_iop)
119 decoder_output += BasicConstructor.subst(dbl_iop)
120 exec_output += FPAExecute.subst(dbl_iop)
122 decode_block = FloatDoubleDecode.subst(iop)
127 uint16_t _in, _iz, _ic, _iv;
129 _in = %(fReg1)s < %(fReg2)s;
130 _iz = %(fReg1)s == %(fReg2)s;
131 _ic = %(fReg1)s >= %(fReg2)s;
132 _iv = (isnan(%(fReg1)s) || isnan(%(fReg2)s)) & 1;
134 CondCodes = _in << 31 | _iz << 30 | _ic << 29 | _iv << 28 |
135 (CondCodes & 0x0FFFFFFF);
139 def format FloatCmp(fReg1, fReg2, *flags) {{
140 code = calcFPCcCode % vars()
141 iop = InstObjParams(name, Name, 'PredOp',
143 "predicate_test": predicateTest},
145 header_output = BasicDeclare.subst(iop)
146 decoder_output = BasicConstructor.subst(iop)
147 decode_block = BasicDecode.subst(iop)
148 exec_output = FPAExecute.subst(iop)
154 decodeExtensionRegLoadStore(ExtMachInst machInst);
158 decodeExtensionRegLoadStore(ExtMachInst machInst)
160 const uint32_t opcode = bits(machInst, 24, 20);
161 const uint32_t offset = bits(machInst, 7, 0);
162 const bool single = (bits(machInst, 8) == 0);
163 const IntRegIndex rn = (IntRegIndex)(uint32_t)bits(machInst, 19, 16);
166 vd = (RegIndex)(uint32_t)((bits(machInst, 15, 12) << 1) |
169 vd = (RegIndex)(uint32_t)((bits(machInst, 15, 12) << 1) |
170 (bits(machInst, 22) << 5));
172 switch (bits(opcode, 4, 3)) {
174 if (bits(opcode, 4, 1) == 0x2 &&
175 !(machInst.thumb == 1 && bits(machInst, 28) == 1) &&
176 !(machInst.thumb == 0 && machInst.condCode == 0xf)) {
177 if ((bits(machInst, 7, 4) & 0xd) != 1) {
180 const IntRegIndex rt =
181 (IntRegIndex)(uint32_t)bits(machInst, 15, 12);
182 const IntRegIndex rt2 =
183 (IntRegIndex)(uint32_t)bits(machInst, 19, 16);
184 const bool op = bits(machInst, 20);
187 vm = (bits(machInst, 3, 0) << 1) | bits(machInst, 5);
189 vm = (bits(machInst, 3, 0) << 1) |
190 (bits(machInst, 5) << 5);
193 return new Vmov2Core2Reg(machInst, rt, rt2,
196 return new Vmov2Reg2Core(machInst, (IntRegIndex)vm,
202 switch (bits(opcode, 1, 0)) {
204 return new VLdmStm(machInst, rn, vd, single,
205 true, false, false, offset);
207 return new VLdmStm(machInst, rn, vd, single,
208 true, false, true, offset);
210 return new VLdmStm(machInst, rn, vd, single,
211 true, true, false, offset);
213 // If rn == sp, then this is called vpop.
214 return new VLdmStm(machInst, rn, vd, single,
215 true, true, true, offset);
218 if (bits(opcode, 1, 0) == 0x2) {
219 // If rn == sp, then this is called vpush.
220 return new VLdmStm(machInst, rn, vd, single,
221 false, true, false, offset);
222 } else if (bits(opcode, 1, 0) == 0x3) {
223 return new VLdmStm(machInst, rn, vd, single,
224 false, true, true, offset);
226 // Fall through on purpose
228 const bool up = (bits(machInst, 23) == 1);
229 const uint32_t imm = bits(machInst, 7, 0) << 2;
232 vd = (RegIndex)(uint32_t)((bits(machInst, 15, 12) << 1) |
233 (bits(machInst, 22)));
235 vd = (RegIndex)(uint32_t)((bits(machInst, 15, 12) << 1) |
236 (bits(machInst, 22) << 5));
238 if (bits(opcode, 1, 0) == 0x0) {
241 return new %(vstr_us)s(machInst, vd, rn, up, imm);
243 return new %(vstr_s)s(machInst, vd, rn, up, imm);
247 return new %(vstr_ud)s(machInst, vd, vd + 1,
250 return new %(vstr_d)s(machInst, vd, vd + 1,
254 } else if (bits(opcode, 1, 0) == 0x1) {
257 return new %(vldr_us)s(machInst, vd, rn, up, imm);
259 return new %(vldr_s)s(machInst, vd, rn, up, imm);
263 return new %(vldr_ud)s(machInst, vd, vd + 1,
266 return new %(vldr_d)s(machInst, vd, vd + 1,
272 return new Unknown(machInst);
275 "vldr_us" : "VLDR_" + loadImmClassName(False, True, False),
276 "vldr_s" : "VLDR_" + loadImmClassName(False, False, False),
277 "vldr_ud" : "VLDR_" + loadDoubleImmClassName(False, True, False),
278 "vldr_d" : "VLDR_" + loadDoubleImmClassName(False, False, False),
279 "vstr_us" : "VSTR_" + storeImmClassName(False, True, False),
280 "vstr_s" : "VSTR_" + storeImmClassName(False, False, False),
281 "vstr_ud" : "VSTR_" + storeDoubleImmClassName(False, True, False),
282 "vstr_d" : "VSTR_" + storeDoubleImmClassName(False, False, False)
286 def format ExtensionRegLoadStore() {{
288 return decodeExtensionRegLoadStore(machInst);
295 decodeShortFpTransfer(ExtMachInst machInst);
299 decodeShortFpTransfer(ExtMachInst machInst)
301 const uint32_t l = bits(machInst, 20);
302 const uint32_t c = bits(machInst, 8);
303 const uint32_t a = bits(machInst, 23, 21);
304 const uint32_t b = bits(machInst, 6, 5);
305 if ((machInst.thumb == 1 && bits(machInst, 28) == 1) ||
306 (machInst.thumb == 0 && machInst.condCode == 0xf)) {
307 return new Unknown(machInst);
309 if (l == 0 && c == 0) {
311 const uint32_t vn = (bits(machInst, 19, 16) << 1) |
313 const IntRegIndex rt =
314 (IntRegIndex)(uint32_t)bits(machInst, 15, 12);
315 if (bits(machInst, 20) == 1) {
316 return new VmovRegCoreW(machInst, rt, (IntRegIndex)vn);
318 return new VmovCoreRegW(machInst, (IntRegIndex)vn, rt);
320 } else if (a == 0x7) {
321 const IntRegIndex rt =
322 (IntRegIndex)(uint32_t)bits(machInst, 15, 12);
323 uint32_t specReg = bits(machInst, 19, 16);
326 specReg = MISCREG_FPSID;
329 specReg = MISCREG_FPSCR;
332 specReg = MISCREG_MVFR1;
335 specReg = MISCREG_MVFR0;
338 specReg = MISCREG_FPEXC;
341 return new Unknown(machInst);
343 return new Vmsr(machInst, (IntRegIndex)specReg, rt);
345 } else if (l == 0 && c == 1) {
346 if (bits(a, 2) == 0) {
347 uint32_t vd = (bits(machInst, 7) << 5) |
348 (bits(machInst, 19, 16) << 1);
349 uint32_t index, size;
350 const IntRegIndex rt =
351 (IntRegIndex)(uint32_t)bits(machInst, 15, 12);
352 if (bits(machInst, 22) == 1) {
354 index = (bits(machInst, 21) << 2) |
355 bits(machInst, 6, 5);
356 } else if (bits(machInst, 5) == 1) {
358 index = (bits(machInst, 21) << 1) |
360 } else if (bits(machInst, 6) == 0) {
362 index = bits(machInst, 21);
364 return new Unknown(machInst);
366 if (index >= (32 / size)) {
367 index -= (32 / size);
372 return new VmovCoreRegB(machInst, (IntRegIndex)vd,
375 return new VmovCoreRegH(machInst, (IntRegIndex)vd,
378 return new VmovCoreRegW(machInst, (IntRegIndex)vd, rt);
380 } else if (bits(b, 1) == 0) {
382 return new WarnUnimplemented("vdup", machInst);
384 } else if (l == 1 && c == 0) {
386 const uint32_t vn = (bits(machInst, 19, 16) << 1) |
388 const IntRegIndex rt =
389 (IntRegIndex)(uint32_t)bits(machInst, 15, 12);
390 if (bits(machInst, 20) == 1) {
391 return new VmovRegCoreW(machInst, rt, (IntRegIndex)vn);
393 return new VmovCoreRegW(machInst, (IntRegIndex)vn, rt);
396 const IntRegIndex rt =
397 (IntRegIndex)(uint32_t)bits(machInst, 15, 12);
398 uint32_t specReg = bits(machInst, 19, 16);
401 specReg = MISCREG_FPSID;
404 specReg = MISCREG_FPSCR;
407 specReg = MISCREG_MVFR1;
410 specReg = MISCREG_MVFR0;
413 specReg = MISCREG_FPEXC;
416 return new Unknown(machInst);
424 return new VmrsApsr(machInst, INTREG_CONDCODES,
425 (IntRegIndex)specReg, (uint32_t)cpsrMask);
427 return new Vmrs(machInst, rt, (IntRegIndex)specReg);
431 uint32_t vd = (bits(machInst, 7) << 5) |
432 (bits(machInst, 19, 16) << 1);
433 uint32_t index, size;
434 const IntRegIndex rt =
435 (IntRegIndex)(uint32_t)bits(machInst, 15, 12);
436 const bool u = (bits(machInst, 23) == 1);
437 if (bits(machInst, 22) == 1) {
439 index = (bits(machInst, 21) << 2) |
440 bits(machInst, 6, 5);
441 } else if (bits(machInst, 5) == 1) {
443 index = (bits(machInst, 21) << 1) |
445 } else if (bits(machInst, 6) == 0 && !u) {
447 index = bits(machInst, 21);
449 return new Unknown(machInst);
451 if (index >= (32 / size)) {
452 index -= (32 / size);
458 return new VmovRegCoreUB(machInst, rt,
459 (IntRegIndex)vd, index);
461 return new VmovRegCoreSB(machInst, rt,
462 (IntRegIndex)vd, index);
466 return new VmovRegCoreUH(machInst, rt,
467 (IntRegIndex)vd, index);
469 return new VmovRegCoreSH(machInst, rt,
470 (IntRegIndex)vd, index);
473 return new VmovRegCoreW(machInst, rt, (IntRegIndex)vd);
476 return new Unknown(machInst);
481 def format ShortFpTransfer() {{
483 return decodeShortFpTransfer(machInst);
490 decodeVfpData(ExtMachInst machInst);
494 decodeVfpData(ExtMachInst machInst)
496 const uint32_t opc1 = bits(machInst, 23, 20);
497 const uint32_t opc2 = bits(machInst, 19, 16);
498 const uint32_t opc3 = bits(machInst, 7, 6);
499 //const uint32_t opc4 = bits(machInst, 3, 0);
500 const bool single = (bits(machInst, 8) == 0);
501 // Used to select between vcmp and vcmpe.
502 const bool e = (bits(machInst, 7) == 1);
507 vd = (IntRegIndex)(bits(machInst, 22) |
508 (bits(machInst, 15, 12) << 1));
509 vm = (IntRegIndex)(bits(machInst, 5) |
510 (bits(machInst, 3, 0) << 1));
511 vn = (IntRegIndex)(bits(machInst, 7) |
512 (bits(machInst, 19, 16) << 1));
514 vd = (IntRegIndex)((bits(machInst, 22) << 5) |
515 (bits(machInst, 15, 12) << 1));
516 vm = (IntRegIndex)((bits(machInst, 5) << 5) |
517 (bits(machInst, 3, 0) << 1));
518 vn = (IntRegIndex)((bits(machInst, 7) << 5) |
519 (bits(machInst, 19, 16) << 1));
521 switch (opc1 & 0xb /* 1011 */) {
523 if (bits(machInst, 6) == 0) {
525 return decodeVfpRegRegRegOp<VmlaS>(
526 machInst, vd, vn, vm, false);
528 return decodeVfpRegRegRegOp<VmlaD>(
529 machInst, vd, vn, vm, true);
533 return decodeVfpRegRegRegOp<VmlsS>(
534 machInst, vd, vn, vm, false);
536 return decodeVfpRegRegRegOp<VmlsD>(
537 machInst, vd, vn, vm, true);
541 if (bits(machInst, 6) == 1) {
543 return decodeVfpRegRegRegOp<VnmlaS>(
544 machInst, vd, vn, vm, false);
546 return decodeVfpRegRegRegOp<VnmlaD>(
547 machInst, vd, vn, vm, true);
551 return decodeVfpRegRegRegOp<VnmlsS>(
552 machInst, vd, vn, vm, false);
554 return decodeVfpRegRegRegOp<VnmlsD>(
555 machInst, vd, vn, vm, true);
559 if ((opc3 & 0x1) == 0) {
561 return decodeVfpRegRegRegOp<VmulS>(
562 machInst, vd, vn, vm, false);
564 return decodeVfpRegRegRegOp<VmulD>(
565 machInst, vd, vn, vm, true);
569 return decodeVfpRegRegRegOp<VnmulS>(
570 machInst, vd, vn, vm, false);
572 return decodeVfpRegRegRegOp<VnmulD>(
573 machInst, vd, vn, vm, true);
577 if ((opc3 & 0x1) == 0) {
579 return decodeVfpRegRegRegOp<VaddS>(
580 machInst, vd, vn, vm, false);
582 return decodeVfpRegRegRegOp<VaddD>(
583 machInst, vd, vn, vm, true);
587 return decodeVfpRegRegRegOp<VsubS>(
588 machInst, vd, vn, vm, false);
590 return decodeVfpRegRegRegOp<VsubD>(
591 machInst, vd, vn, vm, true);
595 if ((opc3 & 0x1) == 0) {
597 return decodeVfpRegRegRegOp<VdivS>(
598 machInst, vd, vn, vm, false);
600 return decodeVfpRegRegRegOp<VdivD>(
601 machInst, vd, vn, vm, true);
606 if ((opc3 & 0x1) == 0) {
607 const uint32_t baseImm =
608 bits(machInst, 3, 0) | (bits(machInst, 19, 16) << 4);
610 uint32_t imm = vfp_modified_imm(baseImm, false);
611 return decodeVfpRegImmOp<VmovImmS>(
612 machInst, vd, imm, false);
614 uint64_t imm = vfp_modified_imm(baseImm, true);
615 return decodeVfpRegImmOp<VmovImmD>(
616 machInst, vd, imm, true);
623 return decodeVfpRegRegOp<VmovRegS>(
624 machInst, vd, vm, false);
626 return decodeVfpRegRegOp<VmovRegD>(
627 machInst, vd, vm, true);
631 return decodeVfpRegRegOp<VabsS>(
632 machInst, vd, vm, false);
634 return decodeVfpRegRegOp<VabsD>(
635 machInst, vd, vm, true);
641 return decodeVfpRegRegOp<VnegS>(
642 machInst, vd, vm, false);
644 return decodeVfpRegRegOp<VnegD>(
645 machInst, vd, vm, true);
649 return decodeVfpRegRegOp<VsqrtS>(
650 machInst, vd, vm, false);
652 return decodeVfpRegRegOp<VsqrtD>(
653 machInst, vd, vm, true);
658 // Between half and single precision.
659 return new WarnUnimplemented("vcvtb, vcvtt", machInst);
663 return new VcmpeS(machInst, vd, vm);
665 return new VcmpS(machInst, vd, vm);
669 return new VcmpeD(machInst, vd, vm);
671 return new VcmpD(machInst, vd, vm);
677 return new VcmpeZeroS(machInst, vd, 0);
679 return new VcmpZeroS(machInst, vd, 0);
683 return new VcmpeZeroD(machInst, vd, 0);
685 return new VcmpZeroD(machInst, vd, 0);
691 vm = (IntRegIndex)(bits(machInst, 5) |
692 (bits(machInst, 3, 0) << 1));
693 return new VcvtFpSFpD(machInst, vd, vm);
695 vd = (IntRegIndex)(bits(machInst, 22) |
696 (bits(machInst, 15, 12) << 1));
697 return new VcvtFpDFpS(machInst, vd, vm);
702 if (bits(machInst, 7) == 0) {
704 return new VcvtUIntFpS(machInst, vd, vm);
706 vm = (IntRegIndex)(bits(machInst, 5) |
707 (bits(machInst, 3, 0) << 1));
708 return new VcvtUIntFpD(machInst, vd, vm);
712 return new VcvtSIntFpS(machInst, vd, vm);
714 vm = (IntRegIndex)(bits(machInst, 5) |
715 (bits(machInst, 3, 0) << 1));
716 return new VcvtSIntFpD(machInst, vd, vm);
721 const bool half = (bits(machInst, 7) == 0);
722 const uint32_t imm = bits(machInst, 5) |
723 (bits(machInst, 3, 0) << 1);
724 const uint32_t size =
725 (bits(machInst, 7) == 0 ? 16 : 32) - imm;
728 return new VcvtSHFixedFpS(machInst, vd, vd, size);
730 return new VcvtSFixedFpS(machInst, vd, vd, size);
734 return new VcvtSHFixedFpD(machInst, vd, vd, size);
736 return new VcvtSFixedFpD(machInst, vd, vd, size);
742 const bool half = (bits(machInst, 7) == 0);
743 const uint32_t imm = bits(machInst, 5) |
744 (bits(machInst, 3, 0) << 1);
745 const uint32_t size =
746 (bits(machInst, 7) == 0 ? 16 : 32) - imm;
749 return new VcvtUHFixedFpS(machInst, vd, vd, size);
751 return new VcvtUFixedFpS(machInst, vd, vd, size);
755 return new VcvtUHFixedFpD(machInst, vd, vd, size);
757 return new VcvtUFixedFpD(machInst, vd, vd, size);
762 if (bits(machInst, 7) == 0) {
764 return new VcvtFpUIntSR(machInst, vd, vm);
766 vd = (IntRegIndex)(bits(machInst, 22) |
767 (bits(machInst, 15, 12) << 1));
768 return new VcvtFpUIntDR(machInst, vd, vm);
772 return new VcvtFpUIntS(machInst, vd, vm);
774 vd = (IntRegIndex)(bits(machInst, 22) |
775 (bits(machInst, 15, 12) << 1));
776 return new VcvtFpUIntD(machInst, vd, vm);
780 if (bits(machInst, 7) == 0) {
782 return new VcvtFpSIntSR(machInst, vd, vm);
784 vd = (IntRegIndex)(bits(machInst, 22) |
785 (bits(machInst, 15, 12) << 1));
786 return new VcvtFpSIntDR(machInst, vd, vm);
790 return new VcvtFpSIntS(machInst, vd, vm);
792 vd = (IntRegIndex)(bits(machInst, 22) |
793 (bits(machInst, 15, 12) << 1));
794 return new VcvtFpSIntD(machInst, vd, vm);
799 const bool half = (bits(machInst, 7) == 0);
800 const uint32_t imm = bits(machInst, 5) |
801 (bits(machInst, 3, 0) << 1);
802 const uint32_t size =
803 (bits(machInst, 7) == 0 ? 16 : 32) - imm;
806 return new VcvtFpSHFixedS(machInst, vd, vd, size);
808 return new VcvtFpSFixedS(machInst, vd, vd, size);
812 return new VcvtFpSHFixedD(machInst, vd, vd, size);
814 return new VcvtFpSFixedD(machInst, vd, vd, size);
820 const bool half = (bits(machInst, 7) == 0);
821 const uint32_t imm = bits(machInst, 5) |
822 (bits(machInst, 3, 0) << 1);
823 const uint32_t size =
824 (bits(machInst, 7) == 0 ? 16 : 32) - imm;
827 return new VcvtFpUHFixedS(machInst, vd, vd, size);
829 return new VcvtFpUFixedS(machInst, vd, vd, size);
833 return new VcvtFpUHFixedD(machInst, vd, vd, size);
835 return new VcvtFpUFixedD(machInst, vd, vd, size);
842 return new Unknown(machInst);
847 def format VfpData() {{
849 return decodeVfpData(machInst);