blob: 43f551724c772260d685b9e972050175a4dc03c8 [file] [log] [blame]
Tim Northover3b0846e2014-05-24 12:50:23 +00001//===- AArch64AddressingModes.h - AArch64 Addressing Modes ------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file contains the AArch64 addressing mode implementation stuff.
11//
12//===----------------------------------------------------------------------===//
13
Benjamin Kramera7c40ef2014-08-13 16:26:38 +000014#ifndef LLVM_LIB_TARGET_AARCH64_MCTARGETDESC_AARCH64ADDRESSINGMODES_H
15#define LLVM_LIB_TARGET_AARCH64_MCTARGETDESC_AARCH64ADDRESSINGMODES_H
Tim Northover3b0846e2014-05-24 12:50:23 +000016
17#include "llvm/ADT/APFloat.h"
18#include "llvm/ADT/APInt.h"
19#include "llvm/Support/ErrorHandling.h"
20#include "llvm/Support/MathExtras.h"
21#include <cassert>
22
23namespace llvm {
24
25/// AArch64_AM - AArch64 Addressing Mode Stuff
26namespace AArch64_AM {
27
28//===----------------------------------------------------------------------===//
29// Shifts
30//
31
32enum ShiftExtendType {
33 InvalidShiftExtend = -1,
34 LSL = 0,
35 LSR,
36 ASR,
37 ROR,
38 MSL,
39
40 UXTB,
41 UXTH,
42 UXTW,
43 UXTX,
44
45 SXTB,
46 SXTH,
47 SXTW,
48 SXTX,
49};
50
51/// getShiftName - Get the string encoding for the shift type.
52static inline const char *getShiftExtendName(AArch64_AM::ShiftExtendType ST) {
53 switch (ST) {
54 default: assert(false && "unhandled shift type!");
55 case AArch64_AM::LSL: return "lsl";
56 case AArch64_AM::LSR: return "lsr";
57 case AArch64_AM::ASR: return "asr";
58 case AArch64_AM::ROR: return "ror";
59 case AArch64_AM::MSL: return "msl";
60 case AArch64_AM::UXTB: return "uxtb";
61 case AArch64_AM::UXTH: return "uxth";
62 case AArch64_AM::UXTW: return "uxtw";
63 case AArch64_AM::UXTX: return "uxtx";
64 case AArch64_AM::SXTB: return "sxtb";
65 case AArch64_AM::SXTH: return "sxth";
66 case AArch64_AM::SXTW: return "sxtw";
67 case AArch64_AM::SXTX: return "sxtx";
68 }
69 return nullptr;
70}
71
72/// getShiftType - Extract the shift type.
73static inline AArch64_AM::ShiftExtendType getShiftType(unsigned Imm) {
74 switch ((Imm >> 6) & 0x7) {
75 default: return AArch64_AM::InvalidShiftExtend;
76 case 0: return AArch64_AM::LSL;
77 case 1: return AArch64_AM::LSR;
78 case 2: return AArch64_AM::ASR;
79 case 3: return AArch64_AM::ROR;
80 case 4: return AArch64_AM::MSL;
81 }
82}
83
84/// getShiftValue - Extract the shift value.
85static inline unsigned getShiftValue(unsigned Imm) {
86 return Imm & 0x3f;
87}
88
89/// getShifterImm - Encode the shift type and amount:
90/// imm: 6-bit shift amount
91/// shifter: 000 ==> lsl
92/// 001 ==> lsr
93/// 010 ==> asr
94/// 011 ==> ror
95/// 100 ==> msl
96/// {8-6} = shifter
97/// {5-0} = imm
98static inline unsigned getShifterImm(AArch64_AM::ShiftExtendType ST,
99 unsigned Imm) {
100 assert((Imm & 0x3f) == Imm && "Illegal shifted immedate value!");
101 unsigned STEnc = 0;
102 switch (ST) {
103 default: llvm_unreachable("Invalid shift requested");
104 case AArch64_AM::LSL: STEnc = 0; break;
105 case AArch64_AM::LSR: STEnc = 1; break;
106 case AArch64_AM::ASR: STEnc = 2; break;
107 case AArch64_AM::ROR: STEnc = 3; break;
108 case AArch64_AM::MSL: STEnc = 4; break;
109 }
110 return (STEnc << 6) | (Imm & 0x3f);
111}
112
113//===----------------------------------------------------------------------===//
114// Extends
115//
116
117/// getArithShiftValue - get the arithmetic shift value.
118static inline unsigned getArithShiftValue(unsigned Imm) {
119 return Imm & 0x7;
120}
121
122/// getExtendType - Extract the extend type for operands of arithmetic ops.
123static inline AArch64_AM::ShiftExtendType getExtendType(unsigned Imm) {
124 assert((Imm & 0x7) == Imm && "invalid immediate!");
125 switch (Imm) {
126 default: llvm_unreachable("Compiler bug!");
127 case 0: return AArch64_AM::UXTB;
128 case 1: return AArch64_AM::UXTH;
129 case 2: return AArch64_AM::UXTW;
130 case 3: return AArch64_AM::UXTX;
131 case 4: return AArch64_AM::SXTB;
132 case 5: return AArch64_AM::SXTH;
133 case 6: return AArch64_AM::SXTW;
134 case 7: return AArch64_AM::SXTX;
135 }
136}
137
138static inline AArch64_AM::ShiftExtendType getArithExtendType(unsigned Imm) {
139 return getExtendType((Imm >> 3) & 0x7);
140}
141
142/// Mapping from extend bits to required operation:
143/// shifter: 000 ==> uxtb
144/// 001 ==> uxth
145/// 010 ==> uxtw
146/// 011 ==> uxtx
147/// 100 ==> sxtb
148/// 101 ==> sxth
149/// 110 ==> sxtw
150/// 111 ==> sxtx
151inline unsigned getExtendEncoding(AArch64_AM::ShiftExtendType ET) {
152 switch (ET) {
153 default: llvm_unreachable("Invalid extend type requested");
154 case AArch64_AM::UXTB: return 0; break;
155 case AArch64_AM::UXTH: return 1; break;
156 case AArch64_AM::UXTW: return 2; break;
157 case AArch64_AM::UXTX: return 3; break;
158 case AArch64_AM::SXTB: return 4; break;
159 case AArch64_AM::SXTH: return 5; break;
160 case AArch64_AM::SXTW: return 6; break;
161 case AArch64_AM::SXTX: return 7; break;
162 }
163}
164
165/// getArithExtendImm - Encode the extend type and shift amount for an
166/// arithmetic instruction:
167/// imm: 3-bit extend amount
168/// {5-3} = shifter
169/// {2-0} = imm3
170static inline unsigned getArithExtendImm(AArch64_AM::ShiftExtendType ET,
171 unsigned Imm) {
172 assert((Imm & 0x7) == Imm && "Illegal shifted immedate value!");
173 return (getExtendEncoding(ET) << 3) | (Imm & 0x7);
174}
175
176/// getMemDoShift - Extract the "do shift" flag value for load/store
177/// instructions.
178static inline bool getMemDoShift(unsigned Imm) {
179 return (Imm & 0x1) != 0;
180}
181
182/// getExtendType - Extract the extend type for the offset operand of
183/// loads/stores.
184static inline AArch64_AM::ShiftExtendType getMemExtendType(unsigned Imm) {
185 return getExtendType((Imm >> 1) & 0x7);
186}
187
188/// getExtendImm - Encode the extend type and amount for a load/store inst:
189/// doshift: should the offset be scaled by the access size
190/// shifter: 000 ==> uxtb
191/// 001 ==> uxth
192/// 010 ==> uxtw
193/// 011 ==> uxtx
194/// 100 ==> sxtb
195/// 101 ==> sxth
196/// 110 ==> sxtw
197/// 111 ==> sxtx
198/// {3-1} = shifter
199/// {0} = doshift
200static inline unsigned getMemExtendImm(AArch64_AM::ShiftExtendType ET,
201 bool DoShift) {
202 return (getExtendEncoding(ET) << 1) | unsigned(DoShift);
203}
204
205static inline uint64_t ror(uint64_t elt, unsigned size) {
206 return ((elt & 1) << (size-1)) | (elt >> 1);
207}
208
209/// processLogicalImmediate - Determine if an immediate value can be encoded
210/// as the immediate operand of a logical instruction for the given register
211/// size. If so, return true with "encoding" set to the encoded value in
212/// the form N:immr:imms.
213static inline bool processLogicalImmediate(uint64_t imm, unsigned regSize,
214 uint64_t &encoding) {
215 if (imm == 0ULL || imm == ~0ULL ||
216 (regSize != 64 && (imm >> regSize != 0 || imm == ~0U)))
217 return false;
218
Tim Northover3b0846e2014-05-24 12:50:23 +0000219 // First, determine the element size.
Akira Hatanaka9ee2c262014-11-03 23:06:31 +0000220 unsigned size = regSize;
Tim Northover3b0846e2014-05-24 12:50:23 +0000221
Akira Hatanaka9ee2c262014-11-03 23:06:31 +0000222 do {
223 size /= 2;
224 uint64_t mask = (1ULL << size) - 1;
Tim Northover3b0846e2014-05-24 12:50:23 +0000225
Akira Hatanaka9ee2c262014-11-03 23:06:31 +0000226 if ((imm & mask) != ((imm >> size) & mask)) {
227 size *= 2;
Tim Northover3b0846e2014-05-24 12:50:23 +0000228 break;
229 }
Akira Hatanaka9ee2c262014-11-03 23:06:31 +0000230 } while (size > 2);
Tim Northover3b0846e2014-05-24 12:50:23 +0000231
232 // Second, determine the rotation to make the element be: 0^m 1^n.
Akira Hatanaka9ee2c262014-11-03 23:06:31 +0000233 uint32_t cto, i;
234 uint64_t mask = ((uint64_t)-1LL) >> (64 - size);
235 imm &= mask;
Tim Northover3b0846e2014-05-24 12:50:23 +0000236
Akira Hatanaka9ee2c262014-11-03 23:06:31 +0000237 if (isShiftedMask_64(imm)) {
238 i = countTrailingZeros(imm);
239 cto = CountTrailingOnes_64(imm >> i);
240 } else {
241 imm |= ~mask;
242 if (!isShiftedMask_64(~imm))
243 return false;
Tim Northover3b0846e2014-05-24 12:50:23 +0000244
Akira Hatanaka9ee2c262014-11-03 23:06:31 +0000245 unsigned clo = CountLeadingOnes_64(imm);
246 i = 64 - clo;
247 cto = clo + CountTrailingOnes_64(imm) - (64 - size);
Tim Northover3b0846e2014-05-24 12:50:23 +0000248 }
249
Akira Hatanaka9ee2c262014-11-03 23:06:31 +0000250 // Encode in immr the number of RORs it would take to get *from* 0^m 1^n
251 // to our target value, where i is the number of RORs to go the opposite
252 // direction.
253 assert(size > i && "i should be smaller than element size");
254 unsigned immr = (size - i) & (size - 1);
255
256 // If size has a 1 in the n'th bit, create a value that has zeroes in
257 // bits [0, n] and ones above that.
258 uint64_t nimms = ~(size-1) << 1;
259
260 // Or the CTO value into the low bits, which must be below the Nth bit
261 // bit mentioned above.
262 nimms |= (cto-1);
263
264 // Extract the seventh bit and toggle it to create the N field.
265 unsigned N = ((nimms >> 6) & 1) ^ 1;
266
267 encoding = (N << 12) | (immr << 6) | (nimms & 0x3f);
268 return true;
Tim Northover3b0846e2014-05-24 12:50:23 +0000269}
270
271/// isLogicalImmediate - Return true if the immediate is valid for a logical
272/// immediate instruction of the given register size. Return false otherwise.
273static inline bool isLogicalImmediate(uint64_t imm, unsigned regSize) {
274 uint64_t encoding;
275 return processLogicalImmediate(imm, regSize, encoding);
276}
277
278/// encodeLogicalImmediate - Return the encoded immediate value for a logical
279/// immediate instruction of the given register size.
280static inline uint64_t encodeLogicalImmediate(uint64_t imm, unsigned regSize) {
281 uint64_t encoding = 0;
282 bool res = processLogicalImmediate(imm, regSize, encoding);
283 assert(res && "invalid logical immediate");
284 (void)res;
285 return encoding;
286}
287
288/// decodeLogicalImmediate - Decode a logical immediate value in the form
289/// "N:immr:imms" (where the immr and imms fields are each 6 bits) into the
290/// integer value it represents with regSize bits.
291static inline uint64_t decodeLogicalImmediate(uint64_t val, unsigned regSize) {
292 // Extract the N, imms, and immr fields.
293 unsigned N = (val >> 12) & 1;
294 unsigned immr = (val >> 6) & 0x3f;
295 unsigned imms = val & 0x3f;
296
297 assert((regSize == 64 || N == 0) && "undefined logical immediate encoding");
298 int len = 31 - countLeadingZeros((N << 6) | (~imms & 0x3f));
299 assert(len >= 0 && "undefined logical immediate encoding");
300 unsigned size = (1 << len);
301 unsigned R = immr & (size - 1);
302 unsigned S = imms & (size - 1);
303 assert(S != size - 1 && "undefined logical immediate encoding");
304 uint64_t pattern = (1ULL << (S + 1)) - 1;
305 for (unsigned i = 0; i < R; ++i)
306 pattern = ror(pattern, size);
307
308 // Replicate the pattern to fill the regSize.
309 while (size != regSize) {
310 pattern |= (pattern << size);
311 size *= 2;
312 }
313 return pattern;
314}
315
316/// isValidDecodeLogicalImmediate - Check to see if the logical immediate value
317/// in the form "N:immr:imms" (where the immr and imms fields are each 6 bits)
318/// is a valid encoding for an integer value with regSize bits.
319static inline bool isValidDecodeLogicalImmediate(uint64_t val,
320 unsigned regSize) {
321 // Extract the N and imms fields needed for checking.
322 unsigned N = (val >> 12) & 1;
323 unsigned imms = val & 0x3f;
324
325 if (regSize == 32 && N != 0) // undefined logical immediate encoding
326 return false;
327 int len = 31 - countLeadingZeros((N << 6) | (~imms & 0x3f));
328 if (len < 0) // undefined logical immediate encoding
329 return false;
330 unsigned size = (1 << len);
331 unsigned S = imms & (size - 1);
332 if (S == size - 1) // undefined logical immediate encoding
333 return false;
334
335 return true;
336}
337
338//===----------------------------------------------------------------------===//
339// Floating-point Immediates
340//
341static inline float getFPImmFloat(unsigned Imm) {
342 // We expect an 8-bit binary encoding of a floating-point number here.
343 union {
344 uint32_t I;
345 float F;
346 } FPUnion;
347
348 uint8_t Sign = (Imm >> 7) & 0x1;
349 uint8_t Exp = (Imm >> 4) & 0x7;
350 uint8_t Mantissa = Imm & 0xf;
351
352 // 8-bit FP iEEEE Float Encoding
353 // abcd efgh aBbbbbbc defgh000 00000000 00000000
354 //
355 // where B = NOT(b);
356
357 FPUnion.I = 0;
358 FPUnion.I |= Sign << 31;
359 FPUnion.I |= ((Exp & 0x4) != 0 ? 0 : 1) << 30;
360 FPUnion.I |= ((Exp & 0x4) != 0 ? 0x1f : 0) << 25;
361 FPUnion.I |= (Exp & 0x3) << 23;
362 FPUnion.I |= Mantissa << 19;
363 return FPUnion.F;
364}
365
366/// getFP32Imm - Return an 8-bit floating-point version of the 32-bit
367/// floating-point value. If the value cannot be represented as an 8-bit
368/// floating-point value, then return -1.
369static inline int getFP32Imm(const APInt &Imm) {
370 uint32_t Sign = Imm.lshr(31).getZExtValue() & 1;
371 int32_t Exp = (Imm.lshr(23).getSExtValue() & 0xff) - 127; // -126 to 127
372 int64_t Mantissa = Imm.getZExtValue() & 0x7fffff; // 23 bits
373
374 // We can handle 4 bits of mantissa.
375 // mantissa = (16+UInt(e:f:g:h))/16.
376 if (Mantissa & 0x7ffff)
377 return -1;
378 Mantissa >>= 19;
379 if ((Mantissa & 0xf) != Mantissa)
380 return -1;
381
382 // We can handle 3 bits of exponent: exp == UInt(NOT(b):c:d)-3
383 if (Exp < -3 || Exp > 4)
384 return -1;
385 Exp = ((Exp+3) & 0x7) ^ 4;
386
387 return ((int)Sign << 7) | (Exp << 4) | Mantissa;
388}
389
390static inline int getFP32Imm(const APFloat &FPImm) {
391 return getFP32Imm(FPImm.bitcastToAPInt());
392}
393
394/// getFP64Imm - Return an 8-bit floating-point version of the 64-bit
395/// floating-point value. If the value cannot be represented as an 8-bit
396/// floating-point value, then return -1.
397static inline int getFP64Imm(const APInt &Imm) {
398 uint64_t Sign = Imm.lshr(63).getZExtValue() & 1;
399 int64_t Exp = (Imm.lshr(52).getSExtValue() & 0x7ff) - 1023; // -1022 to 1023
400 uint64_t Mantissa = Imm.getZExtValue() & 0xfffffffffffffULL;
401
402 // We can handle 4 bits of mantissa.
403 // mantissa = (16+UInt(e:f:g:h))/16.
404 if (Mantissa & 0xffffffffffffULL)
405 return -1;
406 Mantissa >>= 48;
407 if ((Mantissa & 0xf) != Mantissa)
408 return -1;
409
410 // We can handle 3 bits of exponent: exp == UInt(NOT(b):c:d)-3
411 if (Exp < -3 || Exp > 4)
412 return -1;
413 Exp = ((Exp+3) & 0x7) ^ 4;
414
415 return ((int)Sign << 7) | (Exp << 4) | Mantissa;
416}
417
418static inline int getFP64Imm(const APFloat &FPImm) {
419 return getFP64Imm(FPImm.bitcastToAPInt());
420}
421
422//===--------------------------------------------------------------------===//
423// AdvSIMD Modified Immediates
424//===--------------------------------------------------------------------===//
425
426// 0x00 0x00 0x00 abcdefgh 0x00 0x00 0x00 abcdefgh
427static inline bool isAdvSIMDModImmType1(uint64_t Imm) {
428 return ((Imm >> 32) == (Imm & 0xffffffffULL)) &&
429 ((Imm & 0xffffff00ffffff00ULL) == 0);
430}
431
432static inline uint8_t encodeAdvSIMDModImmType1(uint64_t Imm) {
433 return (Imm & 0xffULL);
434}
435
436static inline uint64_t decodeAdvSIMDModImmType1(uint8_t Imm) {
437 uint64_t EncVal = Imm;
438 return (EncVal << 32) | EncVal;
439}
440
441// 0x00 0x00 abcdefgh 0x00 0x00 0x00 abcdefgh 0x00
442static inline bool isAdvSIMDModImmType2(uint64_t Imm) {
443 return ((Imm >> 32) == (Imm & 0xffffffffULL)) &&
444 ((Imm & 0xffff00ffffff00ffULL) == 0);
445}
446
447static inline uint8_t encodeAdvSIMDModImmType2(uint64_t Imm) {
448 return (Imm & 0xff00ULL) >> 8;
449}
450
451static inline uint64_t decodeAdvSIMDModImmType2(uint8_t Imm) {
452 uint64_t EncVal = Imm;
453 return (EncVal << 40) | (EncVal << 8);
454}
455
456// 0x00 abcdefgh 0x00 0x00 0x00 abcdefgh 0x00 0x00
457static inline bool isAdvSIMDModImmType3(uint64_t Imm) {
458 return ((Imm >> 32) == (Imm & 0xffffffffULL)) &&
459 ((Imm & 0xff00ffffff00ffffULL) == 0);
460}
461
462static inline uint8_t encodeAdvSIMDModImmType3(uint64_t Imm) {
463 return (Imm & 0xff0000ULL) >> 16;
464}
465
466static inline uint64_t decodeAdvSIMDModImmType3(uint8_t Imm) {
467 uint64_t EncVal = Imm;
468 return (EncVal << 48) | (EncVal << 16);
469}
470
471// abcdefgh 0x00 0x00 0x00 abcdefgh 0x00 0x00 0x00
472static inline bool isAdvSIMDModImmType4(uint64_t Imm) {
473 return ((Imm >> 32) == (Imm & 0xffffffffULL)) &&
474 ((Imm & 0x00ffffff00ffffffULL) == 0);
475}
476
477static inline uint8_t encodeAdvSIMDModImmType4(uint64_t Imm) {
478 return (Imm & 0xff000000ULL) >> 24;
479}
480
481static inline uint64_t decodeAdvSIMDModImmType4(uint8_t Imm) {
482 uint64_t EncVal = Imm;
483 return (EncVal << 56) | (EncVal << 24);
484}
485
486// 0x00 abcdefgh 0x00 abcdefgh 0x00 abcdefgh 0x00 abcdefgh
487static inline bool isAdvSIMDModImmType5(uint64_t Imm) {
488 return ((Imm >> 32) == (Imm & 0xffffffffULL)) &&
489 (((Imm & 0x00ff0000ULL) >> 16) == (Imm & 0x000000ffULL)) &&
490 ((Imm & 0xff00ff00ff00ff00ULL) == 0);
491}
492
493static inline uint8_t encodeAdvSIMDModImmType5(uint64_t Imm) {
494 return (Imm & 0xffULL);
495}
496
497static inline uint64_t decodeAdvSIMDModImmType5(uint8_t Imm) {
498 uint64_t EncVal = Imm;
499 return (EncVal << 48) | (EncVal << 32) | (EncVal << 16) | EncVal;
500}
501
502// abcdefgh 0x00 abcdefgh 0x00 abcdefgh 0x00 abcdefgh 0x00
503static inline bool isAdvSIMDModImmType6(uint64_t Imm) {
504 return ((Imm >> 32) == (Imm & 0xffffffffULL)) &&
505 (((Imm & 0xff000000ULL) >> 16) == (Imm & 0x0000ff00ULL)) &&
506 ((Imm & 0x00ff00ff00ff00ffULL) == 0);
507}
508
509static inline uint8_t encodeAdvSIMDModImmType6(uint64_t Imm) {
510 return (Imm & 0xff00ULL) >> 8;
511}
512
513static inline uint64_t decodeAdvSIMDModImmType6(uint8_t Imm) {
514 uint64_t EncVal = Imm;
515 return (EncVal << 56) | (EncVal << 40) | (EncVal << 24) | (EncVal << 8);
516}
517
518// 0x00 0x00 abcdefgh 0xFF 0x00 0x00 abcdefgh 0xFF
519static inline bool isAdvSIMDModImmType7(uint64_t Imm) {
520 return ((Imm >> 32) == (Imm & 0xffffffffULL)) &&
521 ((Imm & 0xffff00ffffff00ffULL) == 0x000000ff000000ffULL);
522}
523
524static inline uint8_t encodeAdvSIMDModImmType7(uint64_t Imm) {
525 return (Imm & 0xff00ULL) >> 8;
526}
527
528static inline uint64_t decodeAdvSIMDModImmType7(uint8_t Imm) {
529 uint64_t EncVal = Imm;
530 return (EncVal << 40) | (EncVal << 8) | 0x000000ff000000ffULL;
531}
532
533// 0x00 abcdefgh 0xFF 0xFF 0x00 abcdefgh 0xFF 0xFF
534static inline bool isAdvSIMDModImmType8(uint64_t Imm) {
535 return ((Imm >> 32) == (Imm & 0xffffffffULL)) &&
536 ((Imm & 0xff00ffffff00ffffULL) == 0x0000ffff0000ffffULL);
537}
538
539static inline uint64_t decodeAdvSIMDModImmType8(uint8_t Imm) {
540 uint64_t EncVal = Imm;
541 return (EncVal << 48) | (EncVal << 16) | 0x0000ffff0000ffffULL;
542}
543
544static inline uint8_t encodeAdvSIMDModImmType8(uint64_t Imm) {
545 return (Imm & 0x00ff0000ULL) >> 16;
546}
547
548// abcdefgh abcdefgh abcdefgh abcdefgh abcdefgh abcdefgh abcdefgh abcdefgh
549static inline bool isAdvSIMDModImmType9(uint64_t Imm) {
550 return ((Imm >> 32) == (Imm & 0xffffffffULL)) &&
551 ((Imm >> 48) == (Imm & 0x0000ffffULL)) &&
552 ((Imm >> 56) == (Imm & 0x000000ffULL));
553}
554
555static inline uint8_t encodeAdvSIMDModImmType9(uint64_t Imm) {
556 return (Imm & 0xffULL);
557}
558
559static inline uint64_t decodeAdvSIMDModImmType9(uint8_t Imm) {
560 uint64_t EncVal = Imm;
561 EncVal |= (EncVal << 8);
562 EncVal |= (EncVal << 16);
563 EncVal |= (EncVal << 32);
564 return EncVal;
565}
566
567// aaaaaaaa bbbbbbbb cccccccc dddddddd eeeeeeee ffffffff gggggggg hhhhhhhh
568// cmode: 1110, op: 1
569static inline bool isAdvSIMDModImmType10(uint64_t Imm) {
570 uint64_t ByteA = Imm & 0xff00000000000000ULL;
571 uint64_t ByteB = Imm & 0x00ff000000000000ULL;
572 uint64_t ByteC = Imm & 0x0000ff0000000000ULL;
573 uint64_t ByteD = Imm & 0x000000ff00000000ULL;
574 uint64_t ByteE = Imm & 0x00000000ff000000ULL;
575 uint64_t ByteF = Imm & 0x0000000000ff0000ULL;
576 uint64_t ByteG = Imm & 0x000000000000ff00ULL;
577 uint64_t ByteH = Imm & 0x00000000000000ffULL;
578
579 return (ByteA == 0ULL || ByteA == 0xff00000000000000ULL) &&
580 (ByteB == 0ULL || ByteB == 0x00ff000000000000ULL) &&
581 (ByteC == 0ULL || ByteC == 0x0000ff0000000000ULL) &&
582 (ByteD == 0ULL || ByteD == 0x000000ff00000000ULL) &&
583 (ByteE == 0ULL || ByteE == 0x00000000ff000000ULL) &&
584 (ByteF == 0ULL || ByteF == 0x0000000000ff0000ULL) &&
585 (ByteG == 0ULL || ByteG == 0x000000000000ff00ULL) &&
586 (ByteH == 0ULL || ByteH == 0x00000000000000ffULL);
587}
588
589static inline uint8_t encodeAdvSIMDModImmType10(uint64_t Imm) {
590 uint8_t BitA = (Imm & 0xff00000000000000ULL) != 0;
591 uint8_t BitB = (Imm & 0x00ff000000000000ULL) != 0;
592 uint8_t BitC = (Imm & 0x0000ff0000000000ULL) != 0;
593 uint8_t BitD = (Imm & 0x000000ff00000000ULL) != 0;
594 uint8_t BitE = (Imm & 0x00000000ff000000ULL) != 0;
595 uint8_t BitF = (Imm & 0x0000000000ff0000ULL) != 0;
596 uint8_t BitG = (Imm & 0x000000000000ff00ULL) != 0;
597 uint8_t BitH = (Imm & 0x00000000000000ffULL) != 0;
598
599 uint8_t EncVal = BitA;
600 EncVal <<= 1;
601 EncVal |= BitB;
602 EncVal <<= 1;
603 EncVal |= BitC;
604 EncVal <<= 1;
605 EncVal |= BitD;
606 EncVal <<= 1;
607 EncVal |= BitE;
608 EncVal <<= 1;
609 EncVal |= BitF;
610 EncVal <<= 1;
611 EncVal |= BitG;
612 EncVal <<= 1;
613 EncVal |= BitH;
614 return EncVal;
615}
616
617static inline uint64_t decodeAdvSIMDModImmType10(uint8_t Imm) {
618 uint64_t EncVal = 0;
619 if (Imm & 0x80) EncVal |= 0xff00000000000000ULL;
620 if (Imm & 0x40) EncVal |= 0x00ff000000000000ULL;
621 if (Imm & 0x20) EncVal |= 0x0000ff0000000000ULL;
622 if (Imm & 0x10) EncVal |= 0x000000ff00000000ULL;
623 if (Imm & 0x08) EncVal |= 0x00000000ff000000ULL;
624 if (Imm & 0x04) EncVal |= 0x0000000000ff0000ULL;
625 if (Imm & 0x02) EncVal |= 0x000000000000ff00ULL;
626 if (Imm & 0x01) EncVal |= 0x00000000000000ffULL;
627 return EncVal;
628}
629
630// aBbbbbbc defgh000 0x00 0x00 aBbbbbbc defgh000 0x00 0x00
631static inline bool isAdvSIMDModImmType11(uint64_t Imm) {
632 uint64_t BString = (Imm & 0x7E000000ULL) >> 25;
633 return ((Imm >> 32) == (Imm & 0xffffffffULL)) &&
634 (BString == 0x1f || BString == 0x20) &&
635 ((Imm & 0x0007ffff0007ffffULL) == 0);
636}
637
638static inline uint8_t encodeAdvSIMDModImmType11(uint64_t Imm) {
639 uint8_t BitA = (Imm & 0x80000000ULL) != 0;
640 uint8_t BitB = (Imm & 0x20000000ULL) != 0;
641 uint8_t BitC = (Imm & 0x01000000ULL) != 0;
642 uint8_t BitD = (Imm & 0x00800000ULL) != 0;
643 uint8_t BitE = (Imm & 0x00400000ULL) != 0;
644 uint8_t BitF = (Imm & 0x00200000ULL) != 0;
645 uint8_t BitG = (Imm & 0x00100000ULL) != 0;
646 uint8_t BitH = (Imm & 0x00080000ULL) != 0;
647
648 uint8_t EncVal = BitA;
649 EncVal <<= 1;
650 EncVal |= BitB;
651 EncVal <<= 1;
652 EncVal |= BitC;
653 EncVal <<= 1;
654 EncVal |= BitD;
655 EncVal <<= 1;
656 EncVal |= BitE;
657 EncVal <<= 1;
658 EncVal |= BitF;
659 EncVal <<= 1;
660 EncVal |= BitG;
661 EncVal <<= 1;
662 EncVal |= BitH;
663 return EncVal;
664}
665
666static inline uint64_t decodeAdvSIMDModImmType11(uint8_t Imm) {
667 uint64_t EncVal = 0;
668 if (Imm & 0x80) EncVal |= 0x80000000ULL;
669 if (Imm & 0x40) EncVal |= 0x3e000000ULL;
670 else EncVal |= 0x40000000ULL;
671 if (Imm & 0x20) EncVal |= 0x01000000ULL;
672 if (Imm & 0x10) EncVal |= 0x00800000ULL;
673 if (Imm & 0x08) EncVal |= 0x00400000ULL;
674 if (Imm & 0x04) EncVal |= 0x00200000ULL;
675 if (Imm & 0x02) EncVal |= 0x00100000ULL;
676 if (Imm & 0x01) EncVal |= 0x00080000ULL;
677 return (EncVal << 32) | EncVal;
678}
679
680// aBbbbbbb bbcdefgh 0x00 0x00 0x00 0x00 0x00 0x00
681static inline bool isAdvSIMDModImmType12(uint64_t Imm) {
682 uint64_t BString = (Imm & 0x7fc0000000000000ULL) >> 54;
683 return ((BString == 0xff || BString == 0x100) &&
684 ((Imm & 0x0000ffffffffffffULL) == 0));
685}
686
687static inline uint8_t encodeAdvSIMDModImmType12(uint64_t Imm) {
688 uint8_t BitA = (Imm & 0x8000000000000000ULL) != 0;
689 uint8_t BitB = (Imm & 0x0040000000000000ULL) != 0;
690 uint8_t BitC = (Imm & 0x0020000000000000ULL) != 0;
691 uint8_t BitD = (Imm & 0x0010000000000000ULL) != 0;
692 uint8_t BitE = (Imm & 0x0008000000000000ULL) != 0;
693 uint8_t BitF = (Imm & 0x0004000000000000ULL) != 0;
694 uint8_t BitG = (Imm & 0x0002000000000000ULL) != 0;
695 uint8_t BitH = (Imm & 0x0001000000000000ULL) != 0;
696
697 uint8_t EncVal = BitA;
698 EncVal <<= 1;
699 EncVal |= BitB;
700 EncVal <<= 1;
701 EncVal |= BitC;
702 EncVal <<= 1;
703 EncVal |= BitD;
704 EncVal <<= 1;
705 EncVal |= BitE;
706 EncVal <<= 1;
707 EncVal |= BitF;
708 EncVal <<= 1;
709 EncVal |= BitG;
710 EncVal <<= 1;
711 EncVal |= BitH;
712 return EncVal;
713}
714
715static inline uint64_t decodeAdvSIMDModImmType12(uint8_t Imm) {
716 uint64_t EncVal = 0;
717 if (Imm & 0x80) EncVal |= 0x8000000000000000ULL;
718 if (Imm & 0x40) EncVal |= 0x3fc0000000000000ULL;
719 else EncVal |= 0x4000000000000000ULL;
720 if (Imm & 0x20) EncVal |= 0x0020000000000000ULL;
721 if (Imm & 0x10) EncVal |= 0x0010000000000000ULL;
722 if (Imm & 0x08) EncVal |= 0x0008000000000000ULL;
723 if (Imm & 0x04) EncVal |= 0x0004000000000000ULL;
724 if (Imm & 0x02) EncVal |= 0x0002000000000000ULL;
725 if (Imm & 0x01) EncVal |= 0x0001000000000000ULL;
726 return (EncVal << 32) | EncVal;
727}
728
729} // end namespace AArch64_AM
730
731} // end namespace llvm
732
733#endif