1 // Copyright (c) 2010 ARM Limited
4 // The license below extends only to copyright in the software and shall
5 // not be construed as granting a license to any other intellectual
6 // property including but not limited to intellectual property relating
7 // to a hardware implementation of the functionality of the software
8 // licensed hereunder. You may use the software subject to the license
9 // terms below provided that you ensure that this notice is replicated
10 // unmodified and in its entirety in all distributions of the software,
11 // modified or unmodified, in source code or in binary form.
13 // Redistribution and use in source and binary forms, with or without
14 // modification, are permitted provided that the following conditions are
15 // met: redistributions of source code must retain the above copyright
16 // notice, this list of conditions and the following disclaimer;
17 // redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution;
20 // neither the name of the copyright holders nor the names of its
21 // contributors may be used to endorse or promote products derived from
22 // this software without specific prior written permission.
24 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
27 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
28 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
29 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
30 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
31 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
32 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
34 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 // Authors: Gabe Black
38 def format ArmMultAndMultAcc() {{
41 // The manual defines this field as 23-20, but bit 20 is usually
43 const uint32_t op = bits(machInst, 23, 21);
44 const bool s = bits(machInst, 20);
45 const IntRegIndex rd = (IntRegIndex)(uint32_t)bits(machInst, 19, 16);
46 const IntRegIndex ra = (IntRegIndex)(uint32_t)bits(machInst, 15, 12);
47 const IntRegIndex rm = (IntRegIndex)(uint32_t)bits(machInst, 11, 8);
48 const IntRegIndex rn = (IntRegIndex)(uint32_t)bits(machInst, 3, 0);
52 return new MulCc(machInst, rd, rm, rn);
54 return new Mul(machInst, rd, rm, rn);
58 return new MlaCc(machInst, rd, rn, rm, ra);
60 return new Mla(machInst, rd, rn, rm, ra);
63 return new Umaal(machInst, ra, rd, rn, rm);
65 return new Mls(machInst, rd, rn, rm, ra);
68 return new UmullCc(machInst, ra, rd, rn, rm);
70 return new Umull(machInst, ra, rd, rn, rm);
74 return new UmlalCc(machInst, ra, rd, rn, rm);
76 return new Umlal(machInst, ra, rd, rn, rm);
80 return new SmullCc(machInst, ra, rd, rn, rm);
82 return new Smull(machInst, ra, rd, rn, rm);
86 return new SmlalCc(machInst, ra, rd, rn, rm);
88 return new Smlal(machInst, ra, rd, rn, rm);
97 def format ArmHalfWordMultAndMultAcc() {{
100 const uint32_t op1 = bits(machInst, 22, 21);
101 const bool op = bits(machInst, 5);
102 const IntRegIndex rd = (IntRegIndex)(uint32_t)bits(machInst, 19, 16);
103 const IntRegIndex ra = (IntRegIndex)(uint32_t)bits(machInst, 15, 12);
104 const IntRegIndex rm = (IntRegIndex)(uint32_t)bits(machInst, 11, 8);
105 const IntRegIndex rn = (IntRegIndex)(uint32_t)bits(machInst, 3, 0);
108 switch (bits(machInst, 6, 5)) {
110 return new SmlabbCc(machInst, rd, rn, rm, ra);
112 return new SmlatbCc(machInst, rd, rn, rm, ra);
114 return new SmlabtCc(machInst, rd, rn, rm, ra);
116 return new SmlattCc(machInst, rd, rn, rm, ra);
122 if (bits(machInst, 6)) {
123 return new Smulwt(machInst, rd, rn, rm);
125 return new Smulwb(machInst, rd, rn, rm);
128 if (bits(machInst, 6)) {
129 return new SmlawtCc(machInst, rd, rn, rm, ra);
131 return new SmlawbCc(machInst, rd, rn, rm, ra);
135 switch (bits(machInst, 6, 5)) {
137 return new Smlalbb(machInst, ra, rd, rn, rm);
139 return new Smlaltb(machInst, ra, rd, rn, rm);
141 return new Smlalbt(machInst, ra, rd, rn, rm);
143 return new Smlaltt(machInst, ra, rd, rn, rm);
148 switch (bits(machInst, 6, 5)) {
150 return new Smulbb(machInst, rd, rn, rm);
152 return new Smultb(machInst, rd, rn, rm);
154 return new Smulbt(machInst, rd, rn, rm);
156 return new Smultt(machInst, rd, rn, rm);
167 def format Thumb32MulMulAccAndAbsDiff() {{
170 const uint32_t op1 = bits(machInst, 22, 20);
171 const uint32_t op2 = bits(machInst, 5, 4);
172 const IntRegIndex ra = (IntRegIndex)(uint32_t)bits(machInst, 15, 12);
173 const IntRegIndex rn = (IntRegIndex)(uint32_t)bits(machInst, 19, 16);
174 const IntRegIndex rd = (IntRegIndex)(uint32_t)bits(machInst, 11, 8);
175 const IntRegIndex rm = (IntRegIndex)(uint32_t)bits(machInst, 3, 0);
176 if (op1 != 0x1 && bits(op2, 1) != 0) {
177 return new Unknown(machInst);
183 return new Mul(machInst, rd, rn, rm);
185 return new Mla(machInst, rd, rn, rm, ra);
188 return new Mls(machInst, rd, rn, rm, ra);
192 switch (bits(machInst, 5, 4)) {
194 return new Smulbb(machInst, rd, rn, rm);
196 return new Smulbt(machInst, rd, rn, rm);
198 return new Smultb(machInst, rd, rn, rm);
200 return new Smultt(machInst, rd, rn, rm);
203 switch (bits(machInst, 5, 4)) {
205 return new SmlabbCc(machInst, rd, rn, rm, ra);
207 return new SmlabtCc(machInst, rd, rn, rm, ra);
209 return new SmlatbCc(machInst, rd, rn, rm, ra);
211 return new SmlattCc(machInst, rd, rn, rm, ra);
217 if (bits(machInst, 4)) {
218 return new SmuadxCc(machInst, rd, rn, rm);
220 return new SmuadCc(machInst, rd, rn, rm);
223 if (bits(machInst, 4)) {
224 return new SmladxCc(machInst, rd, rn, rm, ra);
226 return new SmladCc(machInst, rd, rn, rm, ra);
231 if (bits(machInst, 4)) {
232 return new Smulwt(machInst, rd, rn, rm);
234 return new Smulwb(machInst, rd, rn, rm);
237 if (bits(machInst, 4)) {
238 return new SmlawtCc(machInst, rd, rn, rm, ra);
240 return new SmlawbCc(machInst, rd, rn, rm, ra);
245 if (bits(machInst, 4)) {
246 return new Smusdx(machInst, rd, rn, rm);
248 return new Smusd(machInst, rd, rn, rm);
251 if (bits(machInst, 4)) {
252 return new SmlsdxCc(machInst, rd, rn, rm, ra);
254 return new SmlsdCc(machInst, rd, rn, rm, ra);
259 if (bits(machInst, 4)) {
260 return new Smmulr(machInst, rd, rn, rm);
262 return new Smmul(machInst, rd, rn, rm);
265 if (bits(machInst, 4)) {
266 return new Smmlar(machInst, rd, rn, rm, ra);
268 return new Smmla(machInst, rd, rn, rm, ra);
272 if (bits(machInst, 4)) {
273 return new Smmlsr(machInst, rd, rn, rm, ra);
275 return new Smmls(machInst, rd, rn, rm, ra);
279 return new Unknown(machInst);
280 } else if (ra == 0xf) {
281 return new Usad8(machInst, rd, rn, rm);
283 return new Usada8(machInst, rd, rn, rm, ra);
292 def format Thumb32LongMulMulAccAndDiv() {{
295 const uint32_t op1 = bits(machInst, 22, 20);
296 const uint32_t op2 = bits(machInst, 7, 4);
297 const IntRegIndex rn = (IntRegIndex)(uint32_t)bits(machInst, 19, 16);
298 const IntRegIndex rdlo = (IntRegIndex)(uint32_t)bits(machInst, 15, 12);
299 const IntRegIndex rdhi = (IntRegIndex)(uint32_t)bits(machInst, 11, 8);
300 const IntRegIndex rm = (IntRegIndex)(uint32_t)bits(machInst, 3, 0);
304 return new Smull(machInst, rdlo, rdhi, rn, rm);
309 return new Sdiv(machInst, rdhi, rn, rm);
314 return new Umull(machInst, rdlo, rdhi, rn, rm);
319 return new Udiv(machInst, rdhi, rn, rm);
324 return new Smlal(machInst, rdlo, rdhi, rn, rm);
325 } else if (bits(op2, 3, 2) == 0x2) {
326 switch (bits(machInst, 5, 4)) {
328 return new Smlalbb(machInst, rdlo, rdhi, rn, rm);
330 return new Smlalbt(machInst, rdlo, rdhi, rn, rm);
332 return new Smlaltb(machInst, rdlo, rdhi, rn, rm);
334 return new Smlaltt(machInst, rdlo, rdhi, rn, rm);
336 } else if (bits(op2, 3, 1) == 0x6) {
337 if (bits(machInst, 4)) {
338 return new Smlaldx(machInst, rdlo, rdhi, rn, rm);
340 return new Smlald(machInst, rdlo, rdhi, rn, rm);
345 if (bits(op2, 3, 1) == 0x6) {
346 if (bits(machInst, 4)) {
347 return new Smlsldx(machInst, rdlo, rdhi, rn, rm);
349 return new Smlsld(machInst, rdlo, rdhi, rn, rm);
355 return new Umlal(machInst, rdlo, rdhi, rn, rm);
356 } else if (op2 == 0x6) {
357 return new Umaal(machInst, rdlo, rdhi, rn, rm);
361 return new Unknown(machInst);
366 def format ArmSignedMultiplies() {{
369 const uint32_t op1 = bits(machInst, 22, 20);
370 // This is 7-5 in the manual, but bit 5 is always ignored.
371 const uint32_t op2 = bits(machInst, 7, 6);
372 const bool aIsF = (bits(machInst, 15, 12) == 0xf);
373 const IntRegIndex rd = (IntRegIndex)(uint32_t)bits(machInst, 19, 16);
374 const IntRegIndex rn = (IntRegIndex)(uint32_t)bits(machInst, 3, 0);
375 const IntRegIndex rm = (IntRegIndex)(uint32_t)bits(machInst, 11, 8);
376 const IntRegIndex ra = (IntRegIndex)(uint32_t)bits(machInst, 15, 12);
377 const bool m = bits(machInst, 5);
383 return new SmuadxCc(machInst, rd, rn, rm);
385 return new SmuadCc(machInst, rd, rn, rm);
389 return new SmladxCc(machInst, rd, rn, rm, ra);
391 return new SmladCc(machInst, rd, rn, rm, ra);
394 } else if (op2 == 1) {
397 return new Smusdx(machInst, rd, rn, rm);
399 return new Smusd(machInst, rd, rn, rm);
403 return new SmlsdxCc(machInst, rd, rn, rm, ra);
405 return new SmlsdCc(machInst, rd, rn, rm, ra);
411 if (op2 == 0 && m == 0 && ra == 0xf) {
412 return new Sdiv(machInst, rd, rn, rm);
416 if (op2 == 0 && m == 0 && ra == 0xf) {
417 return new Udiv(machInst, rd, rn, rm);
423 return new Smlaldx(machInst, ra, rd, rn, rm);
425 return new Smlald(machInst, ra, rd, rn, rm);
427 } else if (op2 == 1) {
429 return new Smlsldx(machInst, ra, rd, rn, rm);
431 return new Smlsld(machInst, ra, rd, rn, rm);
439 return new Smmulr(machInst, rd, rn, rm);
441 return new Smmul(machInst, rd, rn, rm);
445 return new Smmlar(machInst, rd, rn, rm, ra);
447 return new Smmla(machInst, rd, rn, rm, ra);
450 } else if (op2 == 0x3) {
452 return new Smmlsr(machInst, rd, rn, rm, ra);
454 return new Smmls(machInst, rd, rn, rm, ra);
461 return new Unknown(machInst);