forked from openjdk/jdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathassembler_x86.hpp
More file actions
3241 lines (2682 loc) · 148 KB
/
Copy pathassembler_x86.hpp
File metadata and controls
3241 lines (2682 loc) · 148 KB
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
/*
* Copyright (c) 1997, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
*/
#ifndef CPU_X86_ASSEMBLER_X86_HPP
#define CPU_X86_ASSEMBLER_X86_HPP
#include "asm/register.hpp"
#include "utilities/checkedCast.hpp"
#include "utilities/powerOfTwo.hpp"
// Contains all the definitions needed for x86 assembly code generation.
// Calling convention
class Argument {
public:
enum {
#ifdef _WIN64
n_int_register_parameters_c = 4, // rcx, rdx, r8, r9 (c_rarg0, c_rarg1, ...)
n_float_register_parameters_c = 4, // xmm0 - xmm3 (c_farg0, c_farg1, ... )
n_int_register_returns_c = 1, // rax
n_float_register_returns_c = 1, // xmm0
#else
n_int_register_parameters_c = 6, // rdi, rsi, rdx, rcx, r8, r9 (c_rarg0, c_rarg1, ...)
n_float_register_parameters_c = 8, // xmm0 - xmm7 (c_farg0, c_farg1, ... )
n_int_register_returns_c = 2, // rax, rdx
n_float_register_returns_c = 2, // xmm0, xmm1
#endif // _WIN64
n_int_register_parameters_j = 6, // j_rarg0, j_rarg1, ...
n_float_register_parameters_j = 8 // j_farg0, j_farg1, ...
};
};
// Symbolically name the register arguments used by the c calling convention.
// Windows is different from linux/solaris. So much for standards...
#ifdef _WIN64
constexpr Register c_rarg0 = rcx;
constexpr Register c_rarg1 = rdx;
constexpr Register c_rarg2 = r8;
constexpr Register c_rarg3 = r9;
constexpr XMMRegister c_farg0 = xmm0;
constexpr XMMRegister c_farg1 = xmm1;
constexpr XMMRegister c_farg2 = xmm2;
constexpr XMMRegister c_farg3 = xmm3;
#else
constexpr Register c_rarg0 = rdi;
constexpr Register c_rarg1 = rsi;
constexpr Register c_rarg2 = rdx;
constexpr Register c_rarg3 = rcx;
constexpr Register c_rarg4 = r8;
constexpr Register c_rarg5 = r9;
constexpr XMMRegister c_farg0 = xmm0;
constexpr XMMRegister c_farg1 = xmm1;
constexpr XMMRegister c_farg2 = xmm2;
constexpr XMMRegister c_farg3 = xmm3;
constexpr XMMRegister c_farg4 = xmm4;
constexpr XMMRegister c_farg5 = xmm5;
constexpr XMMRegister c_farg6 = xmm6;
constexpr XMMRegister c_farg7 = xmm7;
#endif // _WIN64
// Symbolically name the register arguments used by the Java calling convention.
// We have control over the convention for java so we can do what we please.
// What pleases us is to offset the java calling convention so that when
// we call a suitable jni method the arguments are lined up and we don't
// have to do little shuffling. A suitable jni method is non-static and a
// small number of arguments (two fewer args on windows)
//
// |-------------------------------------------------------|
// | c_rarg0 c_rarg1 c_rarg2 c_rarg3 c_rarg4 c_rarg5 |
// |-------------------------------------------------------|
// | rcx rdx r8 r9 rdi* rsi* | windows (* not a c_rarg)
// | rdi rsi rdx rcx r8 r9 | solaris/linux
// |-------------------------------------------------------|
// | j_rarg5 j_rarg0 j_rarg1 j_rarg2 j_rarg3 j_rarg4 |
// |-------------------------------------------------------|
constexpr Register j_rarg0 = c_rarg1;
constexpr Register j_rarg1 = c_rarg2;
constexpr Register j_rarg2 = c_rarg3;
// Windows runs out of register args here
#ifdef _WIN64
constexpr Register j_rarg3 = rdi;
constexpr Register j_rarg4 = rsi;
#else
constexpr Register j_rarg3 = c_rarg4;
constexpr Register j_rarg4 = c_rarg5;
#endif /* _WIN64 */
constexpr Register j_rarg5 = c_rarg0;
constexpr XMMRegister j_farg0 = xmm0;
constexpr XMMRegister j_farg1 = xmm1;
constexpr XMMRegister j_farg2 = xmm2;
constexpr XMMRegister j_farg3 = xmm3;
constexpr XMMRegister j_farg4 = xmm4;
constexpr XMMRegister j_farg5 = xmm5;
constexpr XMMRegister j_farg6 = xmm6;
constexpr XMMRegister j_farg7 = xmm7;
constexpr Register rscratch1 = r10; // volatile
constexpr Register rscratch2 = r11; // volatile
constexpr Register r12_heapbase = r12; // callee-saved
constexpr Register r15_thread = r15; // callee-saved
// JSR 292
// On x86, the SP does not have to be saved when invoking method handle intrinsics
// or compiled lambda forms. We indicate that by setting rbp_mh_SP_save to noreg.
constexpr Register rbp_mh_SP_save = noreg;
// Address is an abstraction used to represent a memory location
// using any of the amd64 addressing modes with one object.
//
// Note: A register location is represented via a Register, not
// via an address for efficiency & simplicity reasons.
class ArrayAddress;
class Address {
public:
enum ScaleFactor {
no_scale = -1,
times_1 = 0,
times_2 = 1,
times_4 = 2,
times_8 = 3,
times_ptr = times_8
};
static ScaleFactor times(int size) {
assert(size >= 1 && size <= 8 && is_power_of_2(size), "bad scale size");
if (size == 8) return times_8;
if (size == 4) return times_4;
if (size == 2) return times_2;
return times_1;
}
static int scale_size(ScaleFactor scale) {
assert(scale != no_scale, "");
assert(((1 << (int)times_1) == 1 &&
(1 << (int)times_2) == 2 &&
(1 << (int)times_4) == 4 &&
(1 << (int)times_8) == 8), "");
return (1 << (int)scale);
}
private:
Register _base;
Register _index;
XMMRegister _xmmindex;
ScaleFactor _scale;
int _disp;
bool _isxmmindex;
RelocationHolder _rspec;
// Easily misused constructors make them private
// %%% can we make these go away?
Address(int disp, address loc, relocInfo::relocType rtype);
Address(int disp, address loc, RelocationHolder spec);
public:
int disp() { return _disp; }
// creation
Address()
: _base(noreg),
_index(noreg),
_xmmindex(xnoreg),
_scale(no_scale),
_disp(0),
_isxmmindex(false){
}
explicit Address(Register base, int disp = 0)
: _base(base),
_index(noreg),
_xmmindex(xnoreg),
_scale(no_scale),
_disp(disp),
_isxmmindex(false){
}
Address(Register base, Register index, ScaleFactor scale, int disp = 0)
: _base (base),
_index(index),
_xmmindex(xnoreg),
_scale(scale),
_disp (disp),
_isxmmindex(false) {
assert(!index->is_valid() == (scale == Address::no_scale),
"inconsistent address");
}
Address(Register base, RegisterOrConstant index, ScaleFactor scale = times_1, int disp = 0)
: _base (base),
_index(index.register_or_noreg()),
_xmmindex(xnoreg),
_scale(scale),
_disp (disp + checked_cast<int>(index.constant_or_zero() * scale_size(scale))),
_isxmmindex(false){
if (!index.is_register()) scale = Address::no_scale;
assert(!_index->is_valid() == (scale == Address::no_scale),
"inconsistent address");
}
Address(Register base, XMMRegister index, ScaleFactor scale, int disp = 0)
: _base (base),
_index(noreg),
_xmmindex(index),
_scale(scale),
_disp(disp),
_isxmmindex(true) {
assert(!index->is_valid() == (scale == Address::no_scale),
"inconsistent address");
}
// The following overloads are used in connection with the
// ByteSize type (see sizes.hpp). They simplify the use of
// ByteSize'd arguments in assembly code.
Address(Register base, ByteSize disp)
: Address(base, in_bytes(disp)) {}
Address(Register base, Register index, ScaleFactor scale, ByteSize disp)
: Address(base, index, scale, in_bytes(disp)) {}
Address(Register base, RegisterOrConstant index, ScaleFactor scale, ByteSize disp)
: Address(base, index, scale, in_bytes(disp)) {}
Address plus_disp(int disp) const {
Address a = (*this);
a._disp += disp;
return a;
}
Address plus_disp(RegisterOrConstant disp, ScaleFactor scale = times_1) const {
Address a = (*this);
a._disp += checked_cast<int>(disp.constant_or_zero() * scale_size(scale));
if (disp.is_register()) {
assert(!a.index()->is_valid(), "competing indexes");
a._index = disp.as_register();
a._scale = scale;
}
return a;
}
bool is_same_address(Address a) const {
// disregard _rspec
return _base == a._base && _disp == a._disp && _index == a._index && _scale == a._scale;
}
// accessors
bool uses(Register reg) const { return _base == reg || _index == reg; }
Register base() const { return _base; }
Register index() const { return _index; }
XMMRegister xmmindex() const { return _xmmindex; }
ScaleFactor scale() const { return _scale; }
int disp() const { return _disp; }
bool isxmmindex() const { return _isxmmindex; }
// Convert the raw encoding form into the form expected by the constructor for
// Address. An index of 4 (rsp) corresponds to having no index, so convert
// that to noreg for the Address constructor.
static Address make_raw(int base, int index, int scale, int disp, relocInfo::relocType disp_reloc);
static Address make_array(ArrayAddress);
private:
bool base_needs_rex() const {
return _base->is_valid() && ((_base->encoding() & 8) == 8);
}
bool base_needs_rex2() const {
return _base->is_valid() && _base->encoding() >= 16;
}
bool index_needs_rex() const {
return _index->is_valid() && ((_index->encoding() & 8) == 8);
}
bool index_needs_rex2() const {
return _index->is_valid() &&_index->encoding() >= 16;
}
bool xmmindex_needs_rex() const {
return _xmmindex->is_valid() && ((_xmmindex->encoding() & 8) == 8);
}
bool xmmindex_needs_rex2() const {
return _xmmindex->is_valid() && _xmmindex->encoding() >= 16;
}
relocInfo::relocType reloc() const { return _rspec.type(); }
friend class Assembler;
friend class MacroAssembler;
friend class LIR_Assembler; // base/index/scale/disp
};
//
// AddressLiteral has been split out from Address because operands of this type
// need to be treated specially on 32bit vs. 64bit platforms. By splitting it out
// the few instructions that need to deal with address literals are unique and the
// MacroAssembler does not have to implement every instruction in the Assembler
// in order to search for address literals that may need special handling depending
// on the instruction and the platform. As small step on the way to merging i486/amd64
// directories.
//
class AddressLiteral {
friend class ArrayAddress;
RelocationHolder _rspec;
// Typically we use AddressLiterals we want to use their rval
// However in some situations we want the lval (effect address) of the item.
// We provide a special factory for making those lvals.
bool _is_lval;
// If the target is far we'll need to load the ea of this to
// a register to reach it. Otherwise if near we can do rip
// relative addressing.
address _target;
protected:
// creation
AddressLiteral()
: _is_lval(false),
_target(nullptr)
{}
public:
AddressLiteral(address target, relocInfo::relocType rtype);
AddressLiteral(address target, RelocationHolder const& rspec)
: _rspec(rspec),
_is_lval(false),
_target(target)
{}
AddressLiteral addr() {
AddressLiteral ret = *this;
ret._is_lval = true;
return ret;
}
private:
address target() { return _target; }
bool is_lval() const { return _is_lval; }
relocInfo::relocType reloc() const { return _rspec.type(); }
const RelocationHolder& rspec() const { return _rspec; }
friend class Assembler;
friend class MacroAssembler;
friend class Address;
friend class LIR_Assembler;
};
// Convenience classes
class RuntimeAddress: public AddressLiteral {
public:
RuntimeAddress(address target) : AddressLiteral(target, relocInfo::runtime_call_type) {}
};
class ExternalAddress: public AddressLiteral {
private:
static relocInfo::relocType reloc_for_target(address target) {
// Sometimes ExternalAddress is used for values which aren't
// exactly addresses, like the card table base.
// external_word_type can't be used for values in the first page
// so just skip the reloc in that case.
return external_word_Relocation::can_be_relocated(target) ? relocInfo::external_word_type : relocInfo::none;
}
public:
ExternalAddress(address target) : AddressLiteral(target, reloc_for_target(target)) {}
};
class InternalAddress: public AddressLiteral {
public:
InternalAddress(address target) : AddressLiteral(target, relocInfo::internal_word_type) {}
};
// x86 can do array addressing as a single operation since disp can be an absolute
// address amd64 can't. We create a class that expresses the concept but does extra
// magic on amd64 to get the final result
class ArrayAddress {
private:
AddressLiteral _base;
Address _index;
public:
ArrayAddress() {};
ArrayAddress(AddressLiteral base, Address index): _base(base), _index(index) {};
AddressLiteral base() { return _base; }
Address index() { return _index; }
};
class InstructionAttr;
// 64-bit reflect the fxsave size which is 512 bytes and the new xsave area on EVEX which is another 2176 bytes
// See fxsave and xsave(EVEX enabled) documentation for layout
const int FPUStateSizeInWords = 2688 / wordSize;
// AVX10 new minmax instruction control mask encoding.
//
// imm8[4] = 0 (please refer to Table 11.1 of section 11.2 of AVX10 manual[1] for details)
// imm8[3:2] (sign control) = 01 (select sign, please refer to Table 11.5 of section 11.2 of AVX10 manual[1] for details)
// imm8[1:0] = 00 (min) / 01 (max)
//
// [1] https://www.intel.com/content/www/us/en/content-details/856721/intel-advanced-vector-extensions-10-2-intel-avx10-2-architecture-specification.html?wapkw=AVX10
const int AVX10_2_MINMAX_MAX_COMPARE_SIGN = 0x5;
const int AVX10_2_MINMAX_MIN_COMPARE_SIGN = 0x4;
// The Intel x86/Amd64 Assembler: Pure assembler doing NO optimizations on the instruction
// level (e.g. mov rax, 0 is not translated into xor rax, rax!); i.e., what you write
// is what you get. The Assembler is generating code into a CodeBuffer.
class Assembler : public AbstractAssembler {
friend class AbstractAssembler; // for the non-virtual hack
friend class LIR_Assembler; // as_Address()
friend class StubGenerator;
public:
enum Condition { // The x86 condition codes used for conditional jumps/moves.
zero = 0x4,
notZero = 0x5,
equal = 0x4,
notEqual = 0x5,
less = 0xc,
lessEqual = 0xe,
greater = 0xf,
greaterEqual = 0xd,
below = 0x2,
belowEqual = 0x6,
above = 0x7,
aboveEqual = 0x3,
overflow = 0x0,
noOverflow = 0x1,
carrySet = 0x2,
carryClear = 0x3,
negative = 0x8,
positive = 0x9,
parity = 0xa,
noParity = 0xb
};
enum Prefix {
// segment overrides
CS_segment = 0x2e,
SS_segment = 0x36,
DS_segment = 0x3e,
ES_segment = 0x26,
FS_segment = 0x64,
GS_segment = 0x65,
REX = 0x40,
REX_B = 0x41,
REX_X = 0x42,
REX_XB = 0x43,
REX_R = 0x44,
REX_RB = 0x45,
REX_RX = 0x46,
REX_RXB = 0x47,
REX_W = 0x48,
REX_WB = 0x49,
REX_WX = 0x4A,
REX_WXB = 0x4B,
REX_WR = 0x4C,
REX_WRB = 0x4D,
REX_WRX = 0x4E,
REX_WRXB = 0x4F,
REX2 = 0xd5,
WREX2 = REX2 << 8,
VEX_3bytes = 0xC4,
VEX_2bytes = 0xC5,
EVEX_4bytes = 0x62,
Prefix_EMPTY = 0x0
};
enum PrefixBits {
REX2BIT_B = 0x01,
REX2BIT_X = 0x02,
REX2BIT_R = 0x04,
REX2BIT_W = 0x08,
REX2BIT_B4 = 0x10,
REX2BIT_X4 = 0x20,
REX2BIT_R4 = 0x40,
REX2BIT_M0 = 0x80,
REX2BIT_WB = 0x09,
REX2BIT_WB4 = 0x18,
};
enum VexPrefix {
VEX_B = 0x20,
VEX_X = 0x40,
VEX_R = 0x80,
VEX_W = 0x80
};
enum ExexPrefix {
EVEX_F = 0x04,
EVEX_V = 0x08,
EVEX_Rb = 0x10,
EVEX_B = 0x20,
EVEX_X = 0x40,
EVEX_Z = 0x80
};
enum ExtEvexPrefix {
EEVEX_R = 0x10,
EEVEX_B = 0x08,
EEVEX_X = 0x04,
EEVEX_V = 0x08
};
enum EvexRoundPrefix {
EVEX_RNE = 0x0,
EVEX_RD = 0x1,
EVEX_RU = 0x2,
EVEX_RZ = 0x3
};
enum VexSimdPrefix {
VEX_SIMD_NONE = 0x0,
VEX_SIMD_66 = 0x1,
VEX_SIMD_F3 = 0x2,
VEX_SIMD_F2 = 0x3,
};
enum VexOpcode {
VEX_OPCODE_NONE = 0x0,
VEX_OPCODE_0F = 0x1,
VEX_OPCODE_0F_38 = 0x2,
VEX_OPCODE_0F_3A = 0x3,
VEX_OPCODE_0F_3C = 0x4,
VEX_OPCODE_MAP5 = 0x5,
VEX_OPCODE_MAP6 = 0x6,
VEX_OPCODE_MASK = 0x1F
};
enum AvxVectorLen {
AVX_128bit = 0x0,
AVX_256bit = 0x1,
AVX_512bit = 0x2,
AVX_NoVec = 0x4
};
enum EvexTupleType {
EVEX_FV = 0,
EVEX_HV = 4,
EVEX_FVM = 6,
EVEX_T1S = 7,
EVEX_T1F = 11,
EVEX_T2 = 13,
EVEX_T4 = 15,
EVEX_T8 = 17,
EVEX_HVM = 18,
EVEX_QVM = 19,
EVEX_OVM = 20,
EVEX_M128 = 21,
EVEX_DUP = 22,
EVEX_NOSCALE = 23,
EVEX_ETUP = 24
};
enum EvexInputSizeInBits {
EVEX_8bit = 0,
EVEX_16bit = 1,
EVEX_32bit = 2,
EVEX_64bit = 3,
EVEX_NObit = 4
};
enum WhichOperand {
// input to locate_operand, and format code for relocations
imm_operand = 0, // embedded 32-bit|64-bit immediate operand
disp32_operand = 1, // embedded 32-bit displacement or address
call32_operand = 2, // embedded 32-bit self-relative displacement
narrow_oop_operand = 3, // embedded 32-bit immediate narrow oop
_WhichOperand_limit = 4
};
// Comparison predicates for integral types & FP types when using SSE
enum ComparisonPredicate {
eq = 0,
lt = 1,
le = 2,
_false = 3,
neq = 4,
nlt = 5,
nle = 6,
_true = 7
};
// Comparison predicates for FP types when using AVX
// O means ordered. U is unordered. When using ordered, any NaN comparison is false. Otherwise, it is true.
// S means signaling. Q means non-signaling. When signaling is true, instruction signals #IA on NaN.
enum ComparisonPredicateFP {
EQ_OQ = 0,
LT_OS = 1,
LE_OS = 2,
UNORD_Q = 3,
NEQ_UQ = 4,
NLT_US = 5,
NLE_US = 6,
ORD_Q = 7,
EQ_UQ = 8,
NGE_US = 9,
NGT_US = 0xA,
FALSE_OQ = 0XB,
NEQ_OQ = 0xC,
GE_OS = 0xD,
GT_OS = 0xE,
TRUE_UQ = 0xF,
EQ_OS = 0x10,
LT_OQ = 0x11,
LE_OQ = 0x12,
UNORD_S = 0x13,
NEQ_US = 0x14,
NLT_UQ = 0x15,
NLE_UQ = 0x16,
ORD_S = 0x17,
EQ_US = 0x18,
NGE_UQ = 0x19,
NGT_UQ = 0x1A,
FALSE_OS = 0x1B,
NEQ_OS = 0x1C,
GE_OQ = 0x1D,
GT_OQ = 0x1E,
TRUE_US =0x1F
};
enum Width {
B = 0,
W = 1,
D = 2,
Q = 3
};
//---< calculate length of instruction >---
// As instruction size can't be found out easily on x86/x64,
// we just use '4' for len and maxlen.
// instruction must start at passed address
static unsigned int instr_len(unsigned char *instr) { return 4; }
//---< longest instructions >---
// Max instruction length is not specified in architecture documentation.
// We could use a "safe enough" estimate (15), but just default to
// instruction length guess from above.
static unsigned int instr_maxlen() { return 4; }
// NOTE: The general philopsophy of the declarations here is that 64bit versions
// of instructions are freely declared without the need for wrapping them an ifdef.
// (Some dangerous instructions are ifdef's out of inappropriate jvm's.)
// In the .cpp file the implementations are wrapped so that they are dropped out
// of the resulting jvm. This is done mostly to keep the footprint of MINIMAL
// to the size it was prior to merging up the 32bit and 64bit assemblers.
//
// This does mean you'll get a linker/runtime error if you use a 64bit only instruction
// in a 32bit vm. This is somewhat unfortunate but keeps the ifdef noise down.
private:
bool _legacy_mode_bw;
bool _legacy_mode_dq;
bool _legacy_mode_vl;
bool _legacy_mode_vlbw;
InstructionAttr *_attributes;
void set_attributes(InstructionAttr* attributes);
int get_base_prefix_bits(int enc);
int get_index_prefix_bits(int enc);
int get_base_prefix_bits(Register base);
int get_index_prefix_bits(Register index);
int get_reg_prefix_bits(int enc);
// 64bit prefixes
void prefix(Register reg);
void prefix(Register dst, Register src, Prefix p);
void prefix_rex2(Register dst, Register src);
void prefix(Register dst, Address adr, Prefix p);
void prefix_rex2(Register dst, Address adr);
// The is_map1 bool indicates an x86 map1 instruction which, when
// legacy encoded, uses a 0x0F opcode prefix. By specification, the
// opcode prefix is omitted when using rex2 encoding in support
// of APX extended GPRs.
void prefix(Address adr, bool is_map1 = false);
void prefix_rex2(Address adr, bool is_map1 = false);
void prefix(Address adr, Register reg, bool byteinst = false, bool is_map1 = false);
void prefix_rex2(Address adr, Register reg, bool byteinst = false, bool is_map1 = false);
void prefix(Address adr, XMMRegister reg);
void prefix_rex2(Address adr, XMMRegister reg);
int prefix_and_encode(int reg_enc, bool byteinst = false, bool is_map1 = false);
int prefix_and_encode_rex2(int reg_enc, bool is_map1 = false);
int prefix_and_encode(int dst_enc, int src_enc, bool is_map1 = false) {
return prefix_and_encode(dst_enc, false, src_enc, false, is_map1);
}
int prefix_and_encode(int dst_enc, bool dst_is_byte, int src_enc, bool src_is_byte, bool is_map1 = false);
int prefix_and_encode_rex2(int dst_enc, int src_enc, int init_bits = 0);
// Some prefixq variants always emit exactly one prefix byte, so besides a
// prefix-emitting method we provide a method to get the prefix byte to emit,
// which can then be folded into a byte stream.
int get_prefixq(Address adr, bool is_map1 = false);
int get_prefixq_rex2(Address adr, bool is_map1 = false);
int get_prefixq(Address adr, Register reg, bool is_map1 = false);
int get_prefixq_rex2(Address adr, Register reg, bool ismap1 = false);
void prefixq(Address adr);
void prefixq(Address adr, Register reg, bool is_map1 = false);
void prefixq(Address adr, XMMRegister reg);
void prefixq_rex2(Address adr, XMMRegister src);
bool prefix_is_rex2(int prefix);
int prefixq_and_encode(int reg_enc, bool is_map1 = false);
int prefixq_and_encode_rex2(int reg_enc, bool is_map1 = false);
int prefixq_and_encode(int dst_enc, int src_enc, bool is_map1 = false);
int prefixq_and_encode_rex2(int dst_enc, int src_enc, bool is_map1 = false);
bool needs_rex2(Register reg1, Register reg2 = noreg, Register reg3 = noreg);
bool needs_eevex(Register reg1, Register reg2 = noreg, Register reg3 = noreg);
bool needs_eevex(int enc1, int enc2 = -1, int enc3 = -1);
NOT_PRODUCT(bool needs_evex(XMMRegister reg1, XMMRegister reg2 = xnoreg, XMMRegister reg3 = xnoreg);)
void rex_prefix(Address adr, XMMRegister xreg,
VexSimdPrefix pre, VexOpcode opc, bool rex_w);
int rex_prefix_and_encode(int dst_enc, int src_enc,
VexSimdPrefix pre, VexOpcode opc, bool rex_w);
void vex_prefix(bool vex_r, bool vex_b, bool vex_x, int nds_enc, VexSimdPrefix pre, VexOpcode opc);
void evex_prefix(bool vex_r, bool vex_b, bool vex_x, bool evex_v, bool evex_r, bool evex_b,
bool eevex_x, int nds_enc, VexSimdPrefix pre, VexOpcode opc, bool no_flags = false);
void eevex_prefix_ndd(Address adr, int ndd_enc, int xreg_enc, VexSimdPrefix pre, VexOpcode opc,
InstructionAttr *attributes, bool no_flags = false);
void eevex_prefix_nf(Address adr, int ndd_enc, int xreg_enc, VexSimdPrefix pre, VexOpcode opc,
InstructionAttr *attributes, bool no_flags = false);
void vex_prefix(Address adr, int nds_enc, int xreg_enc, VexSimdPrefix pre, VexOpcode opc,
InstructionAttr *attributes, bool nds_is_ndd = false, bool no_flags = false);
int vex_prefix_and_encode(int dst_enc, int nds_enc, int src_enc,
VexSimdPrefix pre, VexOpcode opc,
InstructionAttr *attributes, bool src_is_gpr = false, bool nds_is_ndd = false, bool no_flags = false);
int eevex_prefix_and_encode_nf(int dst_enc, int nds_enc, int src_enc, VexSimdPrefix pre, VexOpcode opc,
InstructionAttr *attributes, bool no_flags = false);
int emit_eevex_prefix_ndd(int dst_enc, VexSimdPrefix pre, VexOpcode opc, InstructionAttr *attributes, bool no_flags = false);
int emit_eevex_prefix_or_demote_ndd(int dst_enc, int nds_enc, int src_enc, VexSimdPrefix pre, VexOpcode opc,
InstructionAttr *attributes, bool no_flags = false, bool use_prefixq = false);
int emit_eevex_prefix_or_demote_ndd(int dst_enc, int nds_enc, VexSimdPrefix pre, VexOpcode opc,
InstructionAttr *attributes, bool no_flags = false, bool use_prefixq = false);
void emit_eevex_prefix_or_demote_arith_ndd(Register dst, Register src1, Register src2, VexSimdPrefix pre, VexOpcode opc,
int size, int op1, int op2, bool no_flags = false, bool is_commutative = false);
void emit_eevex_prefix_or_demote_arith_ndd(Register dst, Register nds, int32_t imm32, VexSimdPrefix pre, VexOpcode opc,
int size, int op1, int op2, bool no_flags);
void emit_eevex_or_demote(Register dst, Register src1, Address src2, VexSimdPrefix pre, VexOpcode opc,
int size, int opcode_byte, bool no_flags = false, bool is_map1 = false);
void emit_eevex_or_demote(Register dst, Address src1, Register src2, VexSimdPrefix pre, VexOpcode opc,
int size, int opcode_byte, bool no_flags = false, bool is_map1 = false, bool is_commutative = false);
void emit_eevex_or_demote(int dst_enc, int nds_enc, int src_enc, VexSimdPrefix pre, VexOpcode opc,
int size, int opcode_byte, bool no_flags, bool is_map1 = false, bool swap = false, bool is_commutative = false);
void emit_eevex_or_demote(int dst_enc, int nds_enc, int src_enc, int8_t imm8, VexSimdPrefix pre, VexOpcode opc,
int size, int opcode_byte, bool no_flags, bool is_map1 = false);
void simd_prefix(XMMRegister xreg, XMMRegister nds, Address adr, VexSimdPrefix pre,
VexOpcode opc, InstructionAttr *attributes);
int simd_prefix_and_encode(XMMRegister dst, XMMRegister nds, XMMRegister src, VexSimdPrefix pre,
VexOpcode opc, InstructionAttr *attributes, bool src_is_gpr = false);
// Helper functions for groups of instructions
bool is_demotable(bool no_flags, int dst_enc, int nds_enc);
void emit_arith_b(int op1, int op2, Register dst, int imm8);
void emit_arith(int op1, int op2, Register dst, int32_t imm32, bool optimize_rax_dst = true);
// Force generation of a 4 byte immediate value even if it fits into 8bit
void emit_arith_imm32(int op1, int op2, Register dst, int32_t imm32);
void emit_arith(int op1, int op2, Register dst, Register src);
bool emit_compressed_disp_byte(int &disp);
void emit_modrm(int mod, int dst_enc, int src_enc);
void emit_modrm_disp8(int mod, int dst_enc, int src_enc,
int disp);
void emit_modrm_sib(int mod, int dst_enc, int src_enc,
Address::ScaleFactor scale, int index_enc, int base_enc);
void emit_modrm_sib_disp8(int mod, int dst_enc, int src_enc,
Address::ScaleFactor scale, int index_enc, int base_enc,
int disp);
void emit_operand_helper(int reg_enc,
int base_enc, int index_enc, Address::ScaleFactor scale,
int disp,
RelocationHolder const& rspec,
int post_addr_length);
void emit_operand(Register reg,
Register base, Register index, Address::ScaleFactor scale,
int disp,
RelocationHolder const& rspec,
int post_addr_length);
void emit_operand(Register reg,
Register base, XMMRegister index, Address::ScaleFactor scale,
int disp,
RelocationHolder const& rspec,
int post_addr_length);
void emit_operand(XMMRegister xreg,
Register base, XMMRegister xindex, Address::ScaleFactor scale,
int disp,
RelocationHolder const& rspec,
int post_addr_length);
void emit_operand(Register reg, Address adr,
int post_addr_length);
void emit_operand(XMMRegister reg,
Register base, Register index, Address::ScaleFactor scale,
int disp,
RelocationHolder const& rspec,
int post_addr_length);
void emit_operand_helper(KRegister kreg,
int base_enc, int index_enc, Address::ScaleFactor scale,
int disp,
RelocationHolder const& rspec,
int post_addr_length);
void emit_operand(KRegister kreg, Address adr,
int post_addr_length);
void emit_operand(KRegister kreg,
Register base, Register index, Address::ScaleFactor scale,
int disp,
RelocationHolder const& rspec,
int post_addr_length);
void emit_operand(XMMRegister reg, Address adr, int post_addr_length);
// Immediate-to-memory forms
void emit_arith_operand(int op1, Register rm, Address adr, int32_t imm32);
void emit_arith_operand_imm32(int op1, Register rm, Address adr, int32_t imm32);
protected:
#ifdef ASSERT
void check_relocation(RelocationHolder const& rspec, int format);
#endif
void emit_data(jint data, relocInfo::relocType rtype, int format = 0);
void emit_data(jint data, RelocationHolder const& rspec, int format = 0);
void emit_data64(jlong data, relocInfo::relocType rtype, int format = 0);
void emit_data64(jlong data, RelocationHolder const& rspec, int format = 0);
void emit_prefix_and_int8(int prefix, int b1);
void emit_opcode_prefix_and_encoding(int byte1, int ocp_and_encoding);
void emit_opcode_prefix_and_encoding(int byte1, int byte2, int ocp_and_encoding);
void emit_opcode_prefix_and_encoding(int byte1, int byte2, int ocp_and_encoding, int byte3);
bool always_reachable(AddressLiteral adr);
bool reachable(AddressLiteral adr);
// These are all easily abused and hence protected
public:
void mov_literal64(Register dst, intptr_t imm64, RelocationHolder const& rspec); // 64BIT ONLY
void cmp_narrow_oop(Register src1, int32_t imm32, RelocationHolder const& rspec);
void cmp_narrow_oop(Address src1, int32_t imm32, RelocationHolder const& rspec);
void mov_narrow_oop(Register dst, int32_t imm32, RelocationHolder const& rspec);
void mov_narrow_oop(Address dst, int32_t imm32, RelocationHolder const& rspec);
protected:
// These are unique in that we are ensured by the caller that the 32bit
// relative in these instructions will always be able to reach the potentially
// 64bit address described by entry. Since they can take a 64bit address they
// don't have the 32 suffix like the other instructions in this class.
void call_literal(address entry, RelocationHolder const& rspec);
void jmp_literal(address entry, RelocationHolder const& rspec);
// Avoid using directly section
// Instructions in this section are actually usable by anyone without danger
// of failure but have performance issues that are addressed my enhanced
// instructions which will do the proper thing base on the particular cpu.
// We protect them because we don't trust you...
// Don't use next inc() and dec() methods directly. INC & DEC instructions
// could cause a partial flag stall since they don't set CF flag.
// Use MacroAssembler::decrement() & MacroAssembler::increment() methods
// which call inc() & dec() or add() & sub() in accordance with
// the product flag UseIncDec value.
void decl(Register dst);
void decl(Address dst);
void decq(Address dst);
void incl(Register dst);
void incl(Address dst);
void incq(Register dst);
void incq(Address dst);
// New cpus require use of movsd and movss to avoid partial register stall
// when loading from memory. But for old Opteron use movlpd instead of movsd.
// The selection is done in MacroAssembler::movdbl() and movflt().
// Move Scalar Single-Precision Floating-Point Values
void movss(XMMRegister dst, Address src);
void movss(XMMRegister dst, XMMRegister src);
void movss(Address dst, XMMRegister src);
// Move Scalar Double-Precision Floating-Point Values
void movsd(XMMRegister dst, Address src);
void movsd(XMMRegister dst, XMMRegister src);
void movsd(Address dst, XMMRegister src);
void movlpd(XMMRegister dst, Address src);
void vmovsd(XMMRegister dst, XMMRegister src, XMMRegister src2);
// New cpus require use of movaps and movapd to avoid partial register stall
// when moving between registers.
void movaps(XMMRegister dst, XMMRegister src);
void movapd(XMMRegister dst, Address src);
void movapd(XMMRegister dst, XMMRegister src);
// End avoid using directly
// Instruction prefixes
void prefix(Prefix p);
void prefix16(int p);
public:
// Creation