forked from asmjit/asmjit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathx86operand.h
1662 lines (1350 loc) · 63.6 KB
/
x86operand.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// [AsmJit]
// Complete x86/x64 JIT and Remote Assembler for C++.
//
// [License]
// Zlib - See LICENSE.md file in the package.
// [Guard]
#ifndef _ASMJIT_X86_X86OPERAND_H
#define _ASMJIT_X86_X86OPERAND_H
// [Dependencies - AsmJit]
#include "../base/assembler.h"
#include "../base/compiler.h"
#include "../base/globals.h"
#include "../base/intutil.h"
#include "../base/operand.h"
#include "../base/vectypes.h"
#include "../x86/x86regs.h"
// [Api-Begin]
#include "../apibegin.h"
namespace asmjit {
namespace x86x64 {
// ============================================================================
// [Forward Declarations]
// ============================================================================
struct VarInfo;
struct X86Reg;
struct X86Var;
struct GpReg;
struct GpVar;
struct MmReg;
struct MmVar;
struct XmmReg;
struct XmmVar;
struct YmmReg;
struct YmmVar;
#define _OP_ID(_Op_) reinterpret_cast<const Operand&>(_Op_).getId()
// ============================================================================
// [asmjit::x86x64::Typedefs]
// ============================================================================
//! \addtogroup asmjit_x86x64_general
//! \{
typedef Vec64Data MmData;
typedef Vec128Data XmmData;
typedef Vec256Data YmmData;
// ============================================================================
// [asmjit::x86x64::Variables]
// ============================================================================
//! \internal
ASMJIT_VAR const VarInfo _varInfo[];
// ============================================================================
// [asmjit::x86x64::kMemVSib]
// ============================================================================
//! X86/X64 index register legacy and AVX2 (VSIB) support.
ASMJIT_ENUM(kMemVSib) {
//! Memory operand uses Gp or no index register.
kMemVSibGpz = 0,
//! Memory operand uses Xmm or no index register.
kMemVSibXmm = 1,
//! Memory operand uses Ymm or no index register.
kMemVSibYmm = 2
};
// ============================================================================
// [asmjit::x86x64::kMemFlags]
// ============================================================================
//! \internal
//!
//! X86/X64 specific memory flags.
ASMJIT_ENUM(kMemFlags) {
kMemSegBits = 0x7,
kMemSegIndex = 0,
kMemSegMask = kMemSegBits << kMemSegIndex,
kMemGpdBits = 0x1,
kMemGpdIndex = 3,
kMemGpdMask = kMemGpdBits << kMemGpdIndex,
kMemVSibBits = 0x3,
kMemVSibIndex = 4,
kMemVSibMask = kMemVSibBits << kMemVSibIndex,
kMemShiftBits = 0x3,
kMemShiftIndex = 6,
kMemShiftMask = kMemShiftBits << kMemShiftIndex
};
// ============================================================================
// [asmjit::x86x64::kVarType]
// ============================================================================
//! X86/X64 variable type.
ASMJIT_ENUM(kVarType) {
//! Variable is Mm (MMX).
kVarTypeMm = 12,
//! Variable is Xmm (SSE+).
kVarTypeXmm,
//! Variable is scalar Xmm SP-FP number.
kVarTypeXmmSs,
//! Variable is packed Xmm SP-FP number (4 floats).
kVarTypeXmmPs,
//! Variable is scalar Xmm DP-FP number.
kVarTypeXmmSd,
//! Variable is packed Xmm DP-FP number (2 doubles).
kVarTypeXmmPd,
//! Variable is Ymm (AVX+).
kVarTypeYmm,
//! Variable is packed Ymm SP-FP number (8 floats).
kVarTypeYmmPs,
//! Variable is packed Ymm DP-FP number (4 doubles).
kVarTypeYmmPd,
//! Count of variable types.
kVarTypeCount,
//! \internal
//! \{
_kVarTypeMmStart = kVarTypeMm,
_kVarTypeMmEnd = kVarTypeMm,
_kVarTypeXmmStart = kVarTypeXmm,
_kVarTypeXmmEnd = kVarTypeXmmPd,
_kVarTypeYmmStart = kVarTypeYmm,
_kVarTypeYmmEnd = kVarTypeYmmPd
//! \}
};
// ============================================================================
// [asmjit::x86x64::kVarDesc]
// ============================================================================
//! \internal
//!
//! X86/X64 variable description.
ASMJIT_ENUM(kVarDesc) {
//! Variable contains single-precision floating-point(s).
kVarDescSp = 0x10,
//! Variable contains double-precision floating-point(s).
kVarDescDp = 0x20,
//! Variable is packed (for example float4x, double2x, ...).
kVarDescPacked = 0x40
};
//! \}
// ============================================================================
// [asmjit::x86x64::VarInfo]
// ============================================================================
//! \addtogroup asmjit_x86x64_util
//! \{
//! \internal
//!
//! X86 variable information.
struct VarInfo {
// --------------------------------------------------------------------------
// [Accessors]
// --------------------------------------------------------------------------
//! Get register type, see `kRegType`.
ASMJIT_INLINE uint32_t getReg() const { return _reg; }
//! Get register size in bytes.
ASMJIT_INLINE uint32_t getSize() const { return _size; }
//! Get variable class, see `kRegClass`.
ASMJIT_INLINE uint32_t getClass() const { return _class; }
//! Get variable description, see `kVarDesc`.
ASMJIT_INLINE uint32_t getDesc() const { return _desc; }
//! Get variable type name.
ASMJIT_INLINE const char* getName() const { return _name; }
// --------------------------------------------------------------------------
// [Members]
// --------------------------------------------------------------------------
//! Register type, see `kRegType`.
uint8_t _reg;
//! Register size in bytes.
uint8_t _size;
//! Register class, see `kRegClass`.
uint8_t _class;
//! Variable flags, see `kVarDesc`.
uint8_t _desc;
//! Variable type name.
char _name[4];
};
// ============================================================================
// [asmjit::x86x64::X86Reg]
// ============================================================================
//! X86/X64 register.
struct X86Reg : public BaseReg {
// --------------------------------------------------------------------------
// [Construction / Destruction]
// --------------------------------------------------------------------------
//! Create a dummy X86 register.
ASMJIT_INLINE X86Reg() : BaseReg() {}
//! Create a custom X86 register.
ASMJIT_INLINE X86Reg(uint32_t type, uint32_t index, uint32_t size) : BaseReg(type, index, size) {}
//! Create a reference to `other` X86 register.
ASMJIT_INLINE X86Reg(const X86Reg& other) : BaseReg(other) {}
//! Create non-initialized X86 register.
explicit ASMJIT_INLINE X86Reg(const _NoInit&) : BaseReg(NoInit) {}
// --------------------------------------------------------------------------
// [X86Reg Specific]
// --------------------------------------------------------------------------
ASMJIT_REG_OP(X86Reg)
//! Get whether the register is Gp register.
ASMJIT_INLINE bool isGp() const { return _vreg.type <= kRegTypeGpq; }
//! Get whether the register is Gp byte (8-bit) register.
ASMJIT_INLINE bool isGpb() const { return _vreg.type <= kRegTypeGpbHi; }
//! Get whether the register is Gp lo-byte (8-bit) register.
ASMJIT_INLINE bool isGpbLo() const { return _vreg.type == kRegTypeGpbLo; }
//! Get whether the register is Gp hi-byte (8-bit) register.
ASMJIT_INLINE bool isGpbHi() const { return _vreg.type == kRegTypeGpbHi; }
//! Get whether the register is Gp word (16-bit) register.
ASMJIT_INLINE bool isGpw() const { return _vreg.type == kRegTypeGpw; }
//! Get whether the register is Gp dword (32-bit) register.
ASMJIT_INLINE bool isGpd() const { return _vreg.type == kRegTypeGpd; }
//! Get whether the register is Gp qword (64-bit) register.
ASMJIT_INLINE bool isGpq() const { return _vreg.type == kRegTypeGpq; }
//! Get whether the register is Fp register.
ASMJIT_INLINE bool isFp() const { return _vreg.type == kRegTypeFp; }
//! Get whether the register is Mm (64-bit) register.
ASMJIT_INLINE bool isMm() const { return _vreg.type == kRegTypeMm; }
//! Get whether the register is Xmm (128-bit) register.
ASMJIT_INLINE bool isXmm() const { return _vreg.type == kRegTypeXmm; }
//! Get whether the register is Ymm (256-bit) register.
ASMJIT_INLINE bool isYmm() const { return _vreg.type == kRegTypeYmm; }
//! Get whether the register is a segment.
ASMJIT_INLINE bool isSeg() const { return _vreg.type == kRegTypeSeg; }
};
// ============================================================================
// [asmjit::x86x64::GpReg]
// ============================================================================
//! X86/X64 Gpb/Gpw/Gpd/Gpq register.
struct GpReg : public X86Reg {
// --------------------------------------------------------------------------
// [Construction / Destruction]
// --------------------------------------------------------------------------
//! Create a dummy Gp register.
ASMJIT_INLINE GpReg() : X86Reg() {}
//! Create a reference to `other` Gp register.
ASMJIT_INLINE GpReg(const GpReg& other) : X86Reg(other) {}
//! Create a custom Gp register.
ASMJIT_INLINE GpReg(uint32_t type, uint32_t index, uint32_t size) : X86Reg(type, index, size) {}
//! Create non-initialized Gp register.
explicit ASMJIT_INLINE GpReg(const _NoInit&) : X86Reg(NoInit) {}
// --------------------------------------------------------------------------
// [GpReg Specific]
// --------------------------------------------------------------------------
ASMJIT_REG_OP(GpReg)
};
// ============================================================================
// [asmjit::x86x64::FpReg]
// ============================================================================
//! X86/X64 80-bit Fp register.
struct FpReg : public X86Reg {
// --------------------------------------------------------------------------
// [Construction / Destruction]
// --------------------------------------------------------------------------
//! Create a dummy Fp register.
ASMJIT_INLINE FpReg() : X86Reg() {}
//! Create a reference to `other` FPU register.
ASMJIT_INLINE FpReg(const FpReg& other) : X86Reg(other) {}
//! Create a custom Fp register.
ASMJIT_INLINE FpReg(uint32_t type, uint32_t index, uint32_t size) : X86Reg(type, index, size) {}
//! Create non-initialized Fp register.
explicit ASMJIT_INLINE FpReg(const _NoInit&) : X86Reg(NoInit) {}
// --------------------------------------------------------------------------
// [FpReg Specific]
// --------------------------------------------------------------------------
ASMJIT_REG_OP(FpReg)
};
// ============================================================================
// [asmjit::x86x64::MmReg]
// ============================================================================
//! X86/X64 64-bit Mm register.
struct MmReg : public X86Reg {
// --------------------------------------------------------------------------
// [Construction / Destruction]
// --------------------------------------------------------------------------
//! Create a dummy Mm register.
ASMJIT_INLINE MmReg() : X86Reg() {}
//! Create a reference to `other` Mm register.
ASMJIT_INLINE MmReg(const MmReg& other) : X86Reg(other) {}
//! Create a custom Mm register.
ASMJIT_INLINE MmReg(uint32_t type, uint32_t index, uint32_t size) : X86Reg(type, index, size) {}
//! Create non-initialized Mm register.
explicit ASMJIT_INLINE MmReg(const _NoInit&) : X86Reg(NoInit) {}
// --------------------------------------------------------------------------
// [MmReg Specific]
// --------------------------------------------------------------------------
ASMJIT_REG_OP(MmReg)
};
// ============================================================================
// [asmjit::x86x64::XmmReg]
// ============================================================================
//! X86/X64 128-bit Xmm register.
struct XmmReg : public X86Reg {
// --------------------------------------------------------------------------
// [Construction / Destruction]
// --------------------------------------------------------------------------
//! Create a dummy Xmm register.
ASMJIT_INLINE XmmReg() : X86Reg() {}
//! Create a reference to `other` Xmm register.
ASMJIT_INLINE XmmReg(const XmmReg& other) : X86Reg(other) {}
//! Create a custom Xmm register.
ASMJIT_INLINE XmmReg(uint32_t type, uint32_t index, uint32_t size) : X86Reg(type, index, size) {}
//! Create non-initialized Xmm register.
explicit ASMJIT_INLINE XmmReg(const _NoInit&) : X86Reg(NoInit) {}
// --------------------------------------------------------------------------
// [XmmReg Specific]
// --------------------------------------------------------------------------
ASMJIT_REG_OP(XmmReg)
};
// ============================================================================
// [asmjit::x86x64::YmmReg]
// ============================================================================
//! X86/X64 256-bit Ymm register.
struct YmmReg : public X86Reg {
// --------------------------------------------------------------------------
// [Construction / Destruction]
// --------------------------------------------------------------------------
//! Create a dummy Ymm register.
ASMJIT_INLINE YmmReg() : X86Reg() {}
//! Create a reference to `other` Xmm register.
ASMJIT_INLINE YmmReg(const YmmReg& other) : X86Reg(other) {}
//! Create a custom Ymm register.
ASMJIT_INLINE YmmReg(uint32_t type, uint32_t index, uint32_t size) : X86Reg(type, index, size) {}
//! Create non-initialized Ymm register.
explicit ASMJIT_INLINE YmmReg(const _NoInit&) : X86Reg(NoInit) {}
// --------------------------------------------------------------------------
// [YmmReg Specific]
// --------------------------------------------------------------------------
ASMJIT_REG_OP(YmmReg)
};
// ============================================================================
// [asmjit::x86x64::SegReg]
// ============================================================================
//! X86/X64 segment register.
struct SegReg : public X86Reg {
// --------------------------------------------------------------------------
// [Construction / Destruction]
// --------------------------------------------------------------------------
//! Create a dummy segment register.
ASMJIT_INLINE SegReg() : X86Reg() {}
//! Create a reference to `other` segment register.
ASMJIT_INLINE SegReg(const SegReg& other) : X86Reg(other) {}
//! Create a custom segment register.
ASMJIT_INLINE SegReg(uint32_t type, uint32_t index, uint32_t size) : X86Reg(type, index, size) {}
//! Create non-initialized segment register.
explicit ASMJIT_INLINE SegReg(const _NoInit&) : X86Reg(NoInit) {}
// --------------------------------------------------------------------------
// [SegReg Specific]
// --------------------------------------------------------------------------
ASMJIT_REG_OP(SegReg)
};
// ============================================================================
// [asmjit::x86x64::Mem]
// ============================================================================
//! X86 memory operand.
struct Mem : public BaseMem {
// --------------------------------------------------------------------------
// [Construction / Destruction]
// --------------------------------------------------------------------------
ASMJIT_INLINE Mem() : BaseMem(NoInit) {
reset();
}
ASMJIT_INLINE Mem(const Label& label, int32_t disp, uint32_t size = 0) : BaseMem(NoInit) {
_init_packed_op_sz_b0_b1_id(kOperandTypeMem, size, kMemTypeLabel, 0, label._base.id);
_init_packed_d2_d3(kInvalidValue, disp);
}
ASMJIT_INLINE Mem(const Label& label, const GpReg& index, uint32_t shift, int32_t disp, uint32_t size = 0) : BaseMem(NoInit) {
ASMJIT_ASSERT(shift <= 3);
_init_packed_op_sz_b0_b1_id(kOperandTypeMem, size, kMemTypeLabel,
(kMemVSibGpz << kMemVSibIndex)
+ (shift << kMemShiftIndex),
label.getId());
_vmem.index = index.getRegIndex();
_vmem.displacement = disp;
}
ASMJIT_INLINE Mem(const Label& label, const GpVar& index, uint32_t shift, int32_t disp, uint32_t size = 0) : BaseMem(NoInit) {
ASMJIT_ASSERT(shift <= 3);
_init_packed_op_sz_b0_b1_id(kOperandTypeMem, size, kMemTypeLabel,
(kMemVSibGpz << kMemVSibIndex)
+ (shift << kMemShiftIndex),
label.getId());
_vmem.index = _OP_ID(index);
_vmem.displacement = disp;
}
ASMJIT_INLINE Mem(const GpReg& base, int32_t disp, uint32_t size = 0) : BaseMem(NoInit) {
_init_packed_op_sz_b0_b1_id(kOperandTypeMem, size, kMemTypeBaseIndex,
_getGpdFlags(base)
+ (kMemVSibGpz << kMemVSibIndex),
base.getRegIndex());
_init_packed_d2_d3(kInvalidValue, disp);
}
ASMJIT_INLINE Mem(const GpReg& base, const GpReg& index, uint32_t shift, int32_t disp, uint32_t size = 0) : BaseMem(NoInit) {
ASMJIT_ASSERT(shift <= 3);
_init_packed_op_sz_b0_b1_id(kOperandTypeMem, size, kMemTypeBaseIndex,
_getGpdFlags(base) + (shift << kMemShiftIndex),
base.getRegIndex());
_vmem.index = index.getRegIndex();
_vmem.displacement = disp;
}
ASMJIT_INLINE Mem(const GpReg& base, const XmmReg& index, uint32_t shift, int32_t disp, uint32_t size = 0) : BaseMem(NoInit) {
ASMJIT_ASSERT(shift <= 3);
_init_packed_op_sz_b0_b1_id(kOperandTypeMem, size, kMemTypeBaseIndex,
_getGpdFlags(base)
+ (kMemVSibXmm << kMemVSibIndex)
+ (shift << kMemShiftIndex),
base.getRegIndex());
_vmem.index = index.getRegIndex();
_vmem.displacement = disp;
}
ASMJIT_INLINE Mem(const GpReg& base, const YmmReg& index, uint32_t shift, int32_t disp, uint32_t size = 0) : BaseMem(NoInit) {
ASMJIT_ASSERT(shift <= 3);
_init_packed_op_sz_b0_b1_id(kOperandTypeMem, size, kMemTypeBaseIndex,
_getGpdFlags(base)
+ (kMemVSibYmm << kMemVSibIndex)
+ (shift << kMemShiftIndex),
base.getRegIndex());
_vmem.index = index.getRegIndex();
_vmem.displacement = disp;
}
ASMJIT_INLINE Mem(const GpVar& base, int32_t disp, uint32_t size = 0) : BaseMem(NoInit) {
_init_packed_op_sz_b0_b1_id(kOperandTypeMem, size, kMemTypeBaseIndex,
_getGpdFlags(reinterpret_cast<const BaseVar&>(base))
+ (kMemVSibGpz << kMemVSibIndex),
_OP_ID(base));
_init_packed_d2_d3(kInvalidValue, disp);
}
ASMJIT_INLINE Mem(const GpVar& base, const GpVar& index, uint32_t shift, int32_t disp, uint32_t size = 0) : BaseMem(NoInit) {
ASMJIT_ASSERT(shift <= 3);
_init_packed_op_sz_b0_b1_id(kOperandTypeMem, size, kMemTypeBaseIndex,
_getGpdFlags(reinterpret_cast<const BaseVar&>(base))
+ (shift << kMemShiftIndex),
_OP_ID(base));
_vmem.index = _OP_ID(index);
_vmem.displacement = disp;
}
ASMJIT_INLINE Mem(const GpVar& base, const XmmVar& index, uint32_t shift, int32_t disp, uint32_t size = 0) : BaseMem(NoInit) {
ASMJIT_ASSERT(shift <= 3);
_init_packed_op_sz_b0_b1_id(kOperandTypeMem, size, kMemTypeBaseIndex,
_getGpdFlags(reinterpret_cast<const BaseVar&>(base))
+ (kMemVSibXmm << kMemVSibIndex)
+ (shift << kMemShiftIndex),
_OP_ID(base));
_vmem.index = _OP_ID(index);
_vmem.displacement = disp;
}
ASMJIT_INLINE Mem(const GpVar& base, const YmmVar& index, uint32_t shift, int32_t disp, uint32_t size = 0) : BaseMem(NoInit) {
ASMJIT_ASSERT(shift <= 3);
_init_packed_op_sz_b0_b1_id(kOperandTypeMem, size, kMemTypeBaseIndex,
_getGpdFlags(reinterpret_cast<const BaseVar&>(base))
+ (kMemVSibYmm << kMemVSibIndex)
+ (shift << kMemShiftIndex),
_OP_ID(base));
_vmem.index = _OP_ID(index);
_vmem.displacement = disp;
}
ASMJIT_INLINE Mem(const _Init&, uint32_t memType, const X86Var& base, int32_t disp, uint32_t size) : BaseMem(NoInit) {
_init_packed_op_sz_b0_b1_id(kOperandTypeMem, size, memType, 0, _OP_ID(base));
_vmem.index = kInvalidValue;
_vmem.displacement = disp;
}
ASMJIT_INLINE Mem(const _Init&, uint32_t memType, const X86Var& base, const GpVar& index, uint32_t shift, int32_t disp, uint32_t size) : BaseMem(NoInit) {
ASMJIT_ASSERT(shift <= 3);
_init_packed_op_sz_b0_b1_id(kOperandTypeMem, size, memType, shift << kMemShiftIndex, _OP_ID(base));
_vmem.index = _OP_ID(index);
_vmem.displacement = disp;
}
ASMJIT_INLINE Mem(const Mem& other) : BaseMem(other) {}
explicit ASMJIT_INLINE Mem(const _NoInit&) : BaseMem(NoInit) {}
// --------------------------------------------------------------------------
// [Mem Specific]
// --------------------------------------------------------------------------
//! Clone Mem operand.
ASMJIT_INLINE Mem clone() const {
return Mem(*this);
}
//! Reset Mem operand.
ASMJIT_INLINE void reset() {
_init_packed_op_sz_b0_b1_id(kOperandTypeMem, 0, kMemTypeBaseIndex, 0, kInvalidValue);
_init_packed_d2_d3(kInvalidValue, 0);
}
//! \internal
ASMJIT_INLINE void _init(uint32_t memType, uint32_t base, int32_t disp, uint32_t size) {
_init_packed_op_sz_b0_b1_id(kOperandTypeMem, size, memType, 0, base);
_vmem.index = kInvalidValue;
_vmem.displacement = disp;
}
// --------------------------------------------------------------------------
// [Segment]
// --------------------------------------------------------------------------
//! Get whether the memory operand has segment override prefix.
ASMJIT_INLINE bool hasSegment() const {
return (_vmem.flags & kMemSegMask) != (kSegDefault << kMemSegIndex);
}
//! Get memory operand segment, see `kSeg`.
ASMJIT_INLINE uint32_t getSegment() const {
return (static_cast<uint32_t>(_vmem.flags) >> kMemSegIndex) & kMemSegBits;
}
//! Set memory operand segment, see `kSeg`.
ASMJIT_INLINE Mem& setSegment(uint32_t segIndex) {
_vmem.flags = static_cast<uint8_t>(
(static_cast<uint32_t>(_vmem.flags) & kMemSegMask) + (segIndex << kMemSegIndex));
return *this;
}
//! Set memory operand segment, see `kSeg`.
ASMJIT_INLINE Mem& setSegment(const SegReg& seg) {
return setSegment(seg.getRegIndex());
}
// --------------------------------------------------------------------------
// [Gpd]
// --------------------------------------------------------------------------
//! Get whether the memory operand has 32-bit GP base.
ASMJIT_INLINE bool hasGpdBase() const {
return (_packed[0].u32[0] & IntUtil::pack32_4x8(0x00, 0x00, 0x00, kMemGpdMask)) != 0;
}
//! Set whether the memory operand has 32-bit GP base.
ASMJIT_INLINE Mem& setGpdBase() {
_packed[0].u32[0] |= IntUtil::pack32_4x8(0x00, 0x00, 0x00, kMemGpdMask);
return *this;
}
//! Set whether the memory operand has 32-bit GP base to `b`.
ASMJIT_INLINE Mem& setGpdBase(uint32_t b) {
_packed[0].u32[0] &=~IntUtil::pack32_4x8(0x00, 0x00, 0x00, kMemGpdMask);
_packed[0].u32[0] |= IntUtil::pack32_4x8(0x00, 0x00, 0x00, b << kMemGpdIndex);
return *this;
}
// --------------------------------------------------------------------------
// [VSib]
// --------------------------------------------------------------------------
//! Get SIB type.
ASMJIT_INLINE uint32_t getVSib() const {
return (static_cast<uint32_t>(_vmem.flags) >> kMemVSibIndex) & kMemVSibBits;
}
//! Set SIB type.
ASMJIT_INLINE Mem& _setVSib(uint32_t vsib) {
_packed[0].u32[0] &=~IntUtil::pack32_4x8(0x00, 0x00, 0x00, kMemVSibMask);
_packed[0].u32[0] |= IntUtil::pack32_4x8(0x00, 0x00, 0x00, vsib << kMemVSibIndex);
return *this;
}
// --------------------------------------------------------------------------
// [Size]
// --------------------------------------------------------------------------
//! Set memory operand size.
ASMJIT_INLINE Mem& setSize(uint32_t size) {
_vmem.size = static_cast<uint8_t>(size);
return *this;
}
// --------------------------------------------------------------------------
// [Base]
// --------------------------------------------------------------------------
//! Get whether the memory operand has base register.
ASMJIT_INLINE bool hasBase() const {
return _vmem.base != kInvalidValue;
}
//! Get memory operand base register code, variable id, or `kInvalidValue`.
ASMJIT_INLINE uint32_t getBase() const {
return _vmem.base;
}
//! Set memory operand base register code, variable id, or `kInvalidValue`.
ASMJIT_INLINE Mem& setBase(uint32_t base) {
_vmem.base = base;
return *this;
}
// --------------------------------------------------------------------------
// [Index]
// --------------------------------------------------------------------------
//! Get whether the memory operand has index.
ASMJIT_INLINE bool hasIndex() const {
return _vmem.index != kInvalidValue;
}
//! Get memory operand index register code, variable id, or `kInvalidValue`.
ASMJIT_INLINE uint32_t getIndex() const {
return _vmem.index;
}
//! Set memory operand index register code, variable id, or `kInvalidValue`.
ASMJIT_INLINE Mem& setIndex(uint32_t index) {
_vmem.index = index;
return *this;
}
//! Set memory index.
ASMJIT_INLINE Mem& setIndex(const GpReg& index) {
_vmem.index = index.getRegIndex();
return _setVSib(kMemVSibGpz);
}
//! Set memory index.
ASMJIT_INLINE Mem& setIndex(const GpReg& index, uint32_t shift) {
_vmem.index = index.getRegIndex();
return _setVSib(kMemVSibGpz).setShift(shift);
}
//! Set memory index.
ASMJIT_INLINE Mem& setIndex(const GpVar& index) {
_vmem.index = reinterpret_cast<const BaseVar&>(index).getId();
return _setVSib(kMemVSibGpz);
}
//! Set memory index.
ASMJIT_INLINE Mem& setIndex(const GpVar& index, uint32_t shift) {
_vmem.index = reinterpret_cast<const BaseVar&>(index).getId();
return _setVSib(kMemVSibGpz).setShift(shift);
}
//! Set memory index.
ASMJIT_INLINE Mem& setIndex(const XmmReg& index) {
_vmem.index = index.getRegIndex();
return _setVSib(kMemVSibXmm);
}
//! Set memory index.
ASMJIT_INLINE Mem& setIndex(const XmmReg& index, uint32_t shift) {
_vmem.index = index.getRegIndex();
return _setVSib(kMemVSibXmm).setShift(shift);
}
//! Set memory index.
ASMJIT_INLINE Mem& setIndex(const XmmVar& index) {
_vmem.index = reinterpret_cast<const BaseVar&>(index).getId();
return _setVSib(kMemVSibXmm);
}
//! Set memory index.
ASMJIT_INLINE Mem& setIndex(const XmmVar& index, uint32_t shift) {
_vmem.index = reinterpret_cast<const BaseVar&>(index).getId();
return _setVSib(kMemVSibXmm).setShift(shift);
}
//! Set memory index.
ASMJIT_INLINE Mem& setIndex(const YmmReg& index) {
_vmem.index = index.getRegIndex();
return _setVSib(kMemVSibYmm);
}
//! Set memory index.
ASMJIT_INLINE Mem& setIndex(const YmmReg& index, uint32_t shift) {
_vmem.index = index.getRegIndex();
return _setVSib(kMemVSibYmm).setShift(shift);
}
//! Set memory index.
ASMJIT_INLINE Mem& setIndex(const YmmVar& index) {
_vmem.index = reinterpret_cast<const BaseVar&>(index).getId();
return _setVSib(kMemVSibYmm);
}
//! Set memory index.
ASMJIT_INLINE Mem& setIndex(const YmmVar& index, uint32_t shift) {
_vmem.index = reinterpret_cast<const BaseVar&>(index).getId();
return _setVSib(kMemVSibYmm).setShift(shift);
}
//! Reset memory index.
ASMJIT_INLINE Mem& resetIndex() {
_vmem.index = kInvalidValue;
return _setVSib(kMemVSibGpz);
}
// --------------------------------------------------------------------------
// [Misc]
// --------------------------------------------------------------------------
//! Get whether the memory operand has base and index register.
ASMJIT_INLINE bool hasBaseOrIndex() const {
return _vmem.base != kInvalidValue || _vmem.index != kInvalidValue;
}
//! Get whether the memory operand has base and index register.
ASMJIT_INLINE bool hasBaseAndIndex() const {
return _vmem.base != kInvalidValue && _vmem.index != kInvalidValue;
}
// --------------------------------------------------------------------------
// [Shift]
// --------------------------------------------------------------------------
//! Get whether the memory operand has shift used.
ASMJIT_INLINE bool hasShift() const {
return (_vmem.flags & kMemShiftMask) != 0;
}
//! Get memory operand index scale (0, 1, 2 or 3).
ASMJIT_INLINE uint32_t getShift() const {
return _vmem.flags >> kMemShiftIndex;
}
//! Set memory operand index scale (0, 1, 2 or 3).
ASMJIT_INLINE Mem& setShift(uint32_t shift) {
_packed[0].u32[0] &=~IntUtil::pack32_4x8(0x00, 0x00, 0x00, kMemShiftMask);
_packed[0].u32[0] |= IntUtil::pack32_4x8(0x00, 0x00, 0x00, shift << kMemShiftIndex);
return *this;
}
// --------------------------------------------------------------------------
// [Displacement]
// --------------------------------------------------------------------------
//! Get memory operand relative displacement.
ASMJIT_INLINE int32_t getDisplacement() const {
return _vmem.displacement;
}
//! Set memory operand relative displacement.
ASMJIT_INLINE Mem& setDisplacement(int32_t disp) {
_vmem.displacement = disp;
return *this;
}
//! Reset memory operand relative displacement.
ASMJIT_INLINE Mem& resetDisplacement(int32_t disp) {
_vmem.displacement = 0;
return *this;
}
//! Adjust memory operand relative displacement by `disp`.
ASMJIT_INLINE Mem& adjust(int32_t disp) {
_vmem.displacement += disp;
return *this;
}
//! Get new memory operand adjusted by `disp`.
ASMJIT_INLINE Mem adjusted(int32_t disp) const {
Mem result(*this);
result.adjust(disp);
return result;
}
// --------------------------------------------------------------------------
// [Operator Overload]
// --------------------------------------------------------------------------
ASMJIT_INLINE Mem& operator=(const Mem& other) {
_copy(other);
return *this;
}
ASMJIT_INLINE bool operator==(const Mem& other) const {
return (_packed[0] == other._packed[0]) & (_packed[1] == other._packed[1]) ;
}
ASMJIT_INLINE bool operator!=(const Mem& other) const {
return !(*this == other);
}
// --------------------------------------------------------------------------
// [Static]
// --------------------------------------------------------------------------
static ASMJIT_INLINE uint32_t _getGpdFlags(const Operand& base) {
return (base._vreg.size & 0x4) << (kMemGpdIndex - 2);
}
};
// ============================================================================
// [asmjit::x86x64::X86Var]
// ============================================================================
//! Base class for all variables.
struct X86Var : public BaseVar {
// --------------------------------------------------------------------------
// [Construction / Destruction]
// --------------------------------------------------------------------------
ASMJIT_INLINE X86Var() : BaseVar(NoInit) {
reset();
}
ASMJIT_INLINE X86Var(const X86Var& other) : BaseVar(other) {}
explicit ASMJIT_INLINE X86Var(const _NoInit&) : BaseVar(NoInit) {}
// --------------------------------------------------------------------------
// [X86Var Specific]
// --------------------------------------------------------------------------
//! Clone X86Var operand.
ASMJIT_INLINE X86Var clone() const {
return X86Var(*this);
}
//! Reset X86Var operand.
ASMJIT_INLINE void reset() {
_init_packed_op_sz_b0_b1_id(kOperandTypeVar, 0, kInvalidReg, kInvalidReg, kInvalidValue);
_init_packed_d2_d3(kInvalidValue, kInvalidValue);
}
// --------------------------------------------------------------------------
// [Type]
// --------------------------------------------------------------------------
//! Get register type.
ASMJIT_INLINE uint32_t getRegType() const { return _vreg.type; }
//! Get variable type.
ASMJIT_INLINE uint32_t getVarType() const { return _vreg.vType; }
//! Get whether the variable is Gpb register.
ASMJIT_INLINE bool isGp() const { return _vreg.type <= kRegTypeGpq; }
//! Get whether the variable is Gpb register.
ASMJIT_INLINE bool isGpb() const { return _vreg.type <= kRegTypeGpbHi; }
//! Get whether the variable is Gpb-lo register.
ASMJIT_INLINE bool isGpbLo() const { return _vreg.type == kRegTypeGpbLo; }
//! Get whether the variable is Gpb-hi register.
ASMJIT_INLINE bool isGpbHi() const { return _vreg.type == kRegTypeGpbHi; }
//! Get whether the variable is Gpw register.
ASMJIT_INLINE bool isGpw() const { return _vreg.type == kRegTypeGpw; }
//! Get whether the variable is Gpd register.
ASMJIT_INLINE bool isGpd() const { return _vreg.type == kRegTypeGpd; }
//! Get whether the variable is Gpq register.
ASMJIT_INLINE bool isGpq() const { return _vreg.type == kRegTypeGpq; }
//! Get whether the variable is Fp register.
ASMJIT_INLINE bool isFp() const { return _vreg.type == kRegTypeFp; }
//! Get whether the variable is Mm type.
ASMJIT_INLINE bool isMm() const { return _vreg.type == kRegTypeMm; }
//! Get whether the variable is Xmm type.
ASMJIT_INLINE bool isXmm() const { return _vreg.type == kRegTypeXmm; }
//! Get whether the variable is Ymm type.
ASMJIT_INLINE bool isYmm() const { return _vreg.type == kRegTypeYmm; }
// --------------------------------------------------------------------------
// [Memory Cast]
// --------------------------------------------------------------------------
//! Cast this variable to memory operand.
//!
//! \note Size of operand depends on native variable type, you can use other
//! variants if you want specific one.
ASMJIT_INLINE Mem m(int32_t disp = 0) const {
return Mem(Init, kMemTypeStackIndex, *this, disp, getSize());
}
//! \overload
ASMJIT_INLINE Mem m(const GpVar& index, uint32_t shift = 0, int32_t disp = 0) const {
return Mem(Init, kMemTypeStackIndex, *this, index, shift, disp, getSize());
}
//! Cast this variable to 8-bit memory operand.
ASMJIT_INLINE Mem m8(int32_t disp = 0) const {
return Mem(Init, kMemTypeStackIndex, *this, disp, 1);
}
//! \overload
ASMJIT_INLINE Mem m8(const GpVar& index, uint32_t shift = 0, int32_t disp = 0) const {
return Mem(Init, kMemTypeStackIndex, *this, index, shift, disp, 1);
}
//! Cast this variable to 16-bit memory operand.
ASMJIT_INLINE Mem m16(int32_t disp = 0) const {
return Mem(Init, kMemTypeStackIndex, *this, disp, 2);
}
//! \overload
ASMJIT_INLINE Mem m16(const GpVar& index, uint32_t shift = 0, int32_t disp = 0) const {
return Mem(Init, kMemTypeStackIndex, *this, index, shift, disp, 2);
}
//! Cast this variable to 32-bit memory operand.
ASMJIT_INLINE Mem m32(int32_t disp = 0) const {
return Mem(Init, kMemTypeStackIndex, *this, disp, 4);
}
//! \overload
ASMJIT_INLINE Mem m32(const GpVar& index, uint32_t shift = 0, int32_t disp = 0) const {
return Mem(Init, kMemTypeStackIndex, *this, index, shift, disp, 4);
}
//! Cast this variable to 64-bit memory operand.
ASMJIT_INLINE Mem m64(int32_t disp = 0) const {
return Mem(Init, kMemTypeStackIndex, *this, disp, 8);
}
//! \overload
ASMJIT_INLINE Mem m64(const GpVar& index, uint32_t shift = 0, int32_t disp = 0) const {
return Mem(Init, kMemTypeStackIndex, *this, index, shift, disp, 8);
}
//! Cast this variable to 80-bit memory operand (long double).
ASMJIT_INLINE Mem m80(int32_t disp = 0) const {
return Mem(Init, kMemTypeStackIndex, *this, disp, 10);
}
//! \overload
ASMJIT_INLINE Mem m80(const GpVar& index, uint32_t shift = 0, int32_t disp = 0) const {