-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathassembler-s390.cc
3034 lines (2590 loc) · 104 KB
/
assembler-s390.cc
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) 1994-2006 Sun Microsystems Inc.
// All Rights Reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// - Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// - Redistribution in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the
// distribution.
//
// - Neither the name of Sun Microsystems or the names of contributors may
// be used to endorse or promote products derived from this software without
// specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
// OF THE POSSIBILITY OF SUCH DAMAGE.
// The original source code covered by the above license above has been
// modified significantly by Google Inc.
// Copyright 2014 the V8 project authors. All rights reserved.
#include "src/s390/assembler-s390.h"
#if V8_TARGET_ARCH_S390
#if V8_HOST_ARCH_S390
#include <elf.h> // Required for auxv checks for STFLE support
#endif
#include "src/base/bits.h"
#include "src/base/cpu.h"
#include "src/s390/assembler-s390-inl.h"
#include "src/macro-assembler.h"
namespace v8 {
namespace internal {
// Get the CPU features enabled by the build.
static unsigned CpuFeaturesImpliedByCompiler() {
unsigned answer = 0;
return answer;
}
// Check whether Store Facility STFLE instruction is available on the platform.
// Instruction returns a bit vector of the enabled hardware facilities.
static bool supportsSTFLE() {
#if V8_HOST_ARCH_S390
static bool read_tried = false;
static uint32_t auxv_hwcap = 0;
if (!read_tried) {
// Open the AUXV (auxilliary vector) psuedo-file
int fd = open("/proc/self/auxv", O_RDONLY);
read_tried = true;
if (fd != -1) {
#if V8_TARGET_ARCH_S390X
static Elf64_auxv_t buffer[16];
Elf64_auxv_t* auxv_element;
#else
static Elf32_auxv_t buffer[16];
Elf32_auxv_t* auxv_element;
#endif
int bytes_read = 0;
while (bytes_read >= 0) {
// Read a chunk of the AUXV
bytes_read = read(fd, buffer, sizeof(buffer));
// Locate and read the platform field of AUXV if it is in the chunk
for (auxv_element = buffer;
auxv_element + sizeof(auxv_element) <= buffer + bytes_read &&
auxv_element->a_type != AT_NULL;
auxv_element++) {
// We are looking for HWCAP entry in AUXV to search for STFLE support
if (auxv_element->a_type == AT_HWCAP) {
/* Note: Both auxv_hwcap and buffer are static */
auxv_hwcap = auxv_element->a_un.a_val;
goto done_reading;
}
}
}
done_reading:
close(fd);
}
}
// Did not find result
if (0 == auxv_hwcap) {
return false;
}
// HWCAP_S390_STFLE is defined to be 4 in include/asm/elf.h. Currently
// hardcoded in case that include file does not exist.
const uint32_t HWCAP_S390_STFLE = 4;
return (auxv_hwcap & HWCAP_S390_STFLE);
#else
// STFLE is not available on non-s390 hosts
return false;
#endif
}
void CpuFeatures::ProbeImpl(bool cross_compile) {
supported_ |= CpuFeaturesImpliedByCompiler();
icache_line_size_ = 256;
// Only use statically determined features for cross compile (snapshot).
if (cross_compile) return;
#ifdef DEBUG
initialized_ = true;
#endif
static bool performSTFLE = supportsSTFLE();
// Need to define host, as we are generating inlined S390 assembly to test
// for facilities.
#if V8_HOST_ARCH_S390
if (performSTFLE) {
// STFLE D(B) requires:
// GPR0 to specify # of double words to update minus 1.
// i.e. GPR0 = 0 for 1 doubleword
// D(B) to specify to memory location to store the facilities bits
// The facilities we are checking for are:
// Bit 45 - Distinct Operands for instructions like ARK, SRK, etc.
// As such, we require only 1 double word
int64_t facilities[1];
facilities[0] = 0;
// LHI sets up GPR0
// STFLE is specified as .insn, as opcode is not recognized.
// We register the instructions kill r0 (LHI) and the CC (STFLE).
asm volatile(
"lhi 0,0\n"
".insn s,0xb2b00000,%0\n"
: "=Q"(facilities)
:
: "cc", "r0");
// Test for Distinct Operands Facility - Bit 45
if (facilities[0] & (1lu << (63 - 45))) {
supported_ |= (1u << DISTINCT_OPS);
}
// Test for General Instruction Extension Facility - Bit 34
if (facilities[0] & (1lu << (63 - 34))) {
supported_ |= (1u << GENERAL_INSTR_EXT);
}
// Test for Floating Point Extension Facility - Bit 37
if (facilities[0] & (1lu << (63 - 37))) {
supported_ |= (1u << FLOATING_POINT_EXT);
}
}
#else
// All distinct ops instructions can be simulated
supported_ |= (1u << DISTINCT_OPS);
// RISBG can be simulated
supported_ |= (1u << GENERAL_INSTR_EXT);
supported_ |= (1u << FLOATING_POINT_EXT);
USE(performSTFLE); // To avoid assert
#endif
supported_ |= (1u << FPU);
}
void CpuFeatures::PrintTarget() {
const char* s390_arch = NULL;
#if V8_TARGET_ARCH_S390X
s390_arch = "s390x";
#else
s390_arch = "s390";
#endif
printf("target %s\n", s390_arch);
}
void CpuFeatures::PrintFeatures() {
printf("FPU=%d\n", CpuFeatures::IsSupported(FPU));
printf("FPU_EXT=%d\n", CpuFeatures::IsSupported(FLOATING_POINT_EXT));
printf("GENERAL_INSTR=%d\n", CpuFeatures::IsSupported(GENERAL_INSTR_EXT));
printf("DISTINCT_OPS=%d\n", CpuFeatures::IsSupported(DISTINCT_OPS));
}
Register ToRegister(int num) {
DCHECK(num >= 0 && num < kNumRegisters);
const Register kRegisters[] = {r0, r1, r2, r3, r4, r5, r6, r7,
r8, r9, r10, fp, ip, r13, r14, sp};
return kRegisters[num];
}
// -----------------------------------------------------------------------------
// Implementation of RelocInfo
const int RelocInfo::kApplyMask =
RelocInfo::kCodeTargetMask | 1 << RelocInfo::INTERNAL_REFERENCE;
bool RelocInfo::IsCodedSpecially() {
// The deserializer needs to know whether a pointer is specially
// coded. Being specially coded on S390 means that it is an iihf/iilf
// instruction sequence, and that is always the case inside code
// objects.
return true;
}
bool RelocInfo::IsInConstantPool() { return false; }
// -----------------------------------------------------------------------------
// Implementation of Operand and MemOperand
// See assembler-s390-inl.h for inlined constructors
Operand::Operand(Handle<Object> handle) {
AllowDeferredHandleDereference using_raw_address;
rm_ = no_reg;
// Verify all Objects referred by code are NOT in new space.
Object* obj = *handle;
if (obj->IsHeapObject()) {
DCHECK(!HeapObject::cast(obj)->GetHeap()->InNewSpace(obj));
imm_ = reinterpret_cast<intptr_t>(handle.location());
rmode_ = RelocInfo::EMBEDDED_OBJECT;
} else {
// no relocation needed
imm_ = reinterpret_cast<intptr_t>(obj);
rmode_ = kRelocInfo_NONEPTR;
}
}
MemOperand::MemOperand(Register rn, int32_t offset) {
baseRegister = rn;
indexRegister = r0;
offset_ = offset;
}
MemOperand::MemOperand(Register rx, Register rb, int32_t offset) {
baseRegister = rb;
indexRegister = rx;
offset_ = offset;
}
// -----------------------------------------------------------------------------
// Specific instructions, constants, and masks.
Assembler::Assembler(Isolate* isolate, void* buffer, int buffer_size)
: AssemblerBase(isolate, buffer, buffer_size),
recorded_ast_id_(TypeFeedbackId::None()),
code_targets_(100),
positions_recorder_(this) {
reloc_info_writer.Reposition(buffer_ + buffer_size_, pc_);
last_bound_pos_ = 0;
ClearRecordedAstId();
relocations_.reserve(128);
}
void Assembler::GetCode(CodeDesc* desc) {
EmitRelocations();
// Set up code descriptor.
desc->buffer = buffer_;
desc->buffer_size = buffer_size_;
desc->instr_size = pc_offset();
desc->reloc_size = (buffer_ + buffer_size_) - reloc_info_writer.pos();
desc->origin = this;
}
void Assembler::Align(int m) {
DCHECK(m >= 4 && base::bits::IsPowerOfTwo32(m));
while ((pc_offset() & (m - 1)) != 0) {
nop(0);
}
}
void Assembler::CodeTargetAlign() { Align(8); }
Condition Assembler::GetCondition(Instr instr) {
switch (instr & kCondMask) {
case BT:
return eq;
case BF:
return ne;
default:
UNIMPLEMENTED();
}
return al;
}
#if V8_TARGET_ARCH_S390X
// This code assumes a FIXED_SEQUENCE for 64bit loads (iihf/iilf)
bool Assembler::Is64BitLoadIntoIP(SixByteInstr instr1, SixByteInstr instr2) {
// Check the instructions are the iihf/iilf load into ip
return (((instr1 >> 32) == 0xC0C8) && ((instr2 >> 32) == 0xC0C9));
}
#else
// This code assumes a FIXED_SEQUENCE for 32bit loads (iilf)
bool Assembler::Is32BitLoadIntoIP(SixByteInstr instr) {
// Check the instruction is an iilf load into ip/r12.
return ((instr >> 32) == 0xC0C9);
}
#endif
// Labels refer to positions in the (to be) generated code.
// There are bound, linked, and unused labels.
//
// Bound labels refer to known positions in the already
// generated code. pos() is the position the label refers to.
//
// Linked labels refer to unknown positions in the code
// to be generated; pos() is the position of the last
// instruction using the label.
// The link chain is terminated by a negative code position (must be aligned)
const int kEndOfChain = -4;
// Returns the target address of the relative instructions, typically
// of the form: pos + imm (where immediate is in # of halfwords for
// BR* and LARL).
int Assembler::target_at(int pos) {
SixByteInstr instr = instr_at(pos);
// check which type of branch this is 16 or 26 bit offset
Opcode opcode = Instruction::S390OpcodeValue(buffer_ + pos);
if (BRC == opcode || BRCT == opcode || BRCTG == opcode) {
int16_t imm16 = SIGN_EXT_IMM16((instr & kImm16Mask));
imm16 <<= 1; // BRC immediate is in # of halfwords
if (imm16 == 0) return kEndOfChain;
return pos + imm16;
} else if (LLILF == opcode || BRCL == opcode || LARL == opcode ||
BRASL == opcode) {
int32_t imm32 =
static_cast<int32_t>(instr & (static_cast<uint64_t>(0xffffffff)));
if (LLILF != opcode)
imm32 <<= 1; // BR* + LARL treat immediate in # of halfwords
if (imm32 == 0) return kEndOfChain;
return pos + imm32;
}
// Unknown condition
DCHECK(false);
return -1;
}
// Update the target address of the current relative instruction.
void Assembler::target_at_put(int pos, int target_pos, bool* is_branch) {
SixByteInstr instr = instr_at(pos);
Opcode opcode = Instruction::S390OpcodeValue(buffer_ + pos);
if (is_branch != nullptr) {
*is_branch = (opcode == BRC || opcode == BRCT || opcode == BRCTG ||
opcode == BRCL || opcode == BRASL);
}
if (BRC == opcode || BRCT == opcode || BRCTG == opcode) {
int16_t imm16 = target_pos - pos;
instr &= (~0xffff);
CHECK(is_int16(imm16));
instr_at_put<FourByteInstr>(pos, instr | (imm16 >> 1));
return;
} else if (BRCL == opcode || LARL == opcode || BRASL == opcode) {
// Immediate is in # of halfwords
int32_t imm32 = target_pos - pos;
instr &= (~static_cast<uint64_t>(0xffffffff));
instr_at_put<SixByteInstr>(pos, instr | (imm32 >> 1));
return;
} else if (LLILF == opcode) {
CHECK(target_pos == kEndOfChain || target_pos >= 0);
// Emitted label constant, not part of a branch.
// Make label relative to Code* of generated Code object.
int32_t imm32 = target_pos + (Code::kHeaderSize - kHeapObjectTag);
instr &= (~static_cast<uint64_t>(0xffffffff));
instr_at_put<SixByteInstr>(pos, instr | imm32);
return;
}
DCHECK(false);
}
// Returns the maximum number of bits given instruction can address.
int Assembler::max_reach_from(int pos) {
Opcode opcode = Instruction::S390OpcodeValue(buffer_ + pos);
// Check which type of instr. In theory, we can return
// the values below + 1, given offset is # of halfwords
if (BRC == opcode || BRCT == opcode || BRCTG == opcode) {
return 16;
} else if (LLILF == opcode || BRCL == opcode || LARL == opcode ||
BRASL == opcode) {
return 31; // Using 31 as workaround instead of 32 as
// is_intn(x,32) doesn't work on 32-bit platforms.
// llilf: Emitted label constant, not part of
// a branch (regexp PushBacktrack).
}
DCHECK(false);
return 16;
}
void Assembler::bind_to(Label* L, int pos) {
DCHECK(0 <= pos && pos <= pc_offset()); // must have a valid binding position
bool is_branch = false;
while (L->is_linked()) {
int fixup_pos = L->pos();
#ifdef DEBUG
int32_t offset = pos - fixup_pos;
int maxReach = max_reach_from(fixup_pos);
#endif
next(L); // call next before overwriting link with target at fixup_pos
DCHECK(is_intn(offset, maxReach));
target_at_put(fixup_pos, pos, &is_branch);
}
L->bind_to(pos);
// Keep track of the last bound label so we don't eliminate any instructions
// before a bound label.
if (pos > last_bound_pos_) last_bound_pos_ = pos;
}
void Assembler::bind(Label* L) {
DCHECK(!L->is_bound()); // label can only be bound once
bind_to(L, pc_offset());
}
void Assembler::next(Label* L) {
DCHECK(L->is_linked());
int link = target_at(L->pos());
if (link == kEndOfChain) {
L->Unuse();
} else {
DCHECK(link >= 0);
L->link_to(link);
}
}
bool Assembler::is_near(Label* L, Condition cond) {
DCHECK(L->is_bound());
if (L->is_bound() == false) return false;
int maxReach = ((cond == al) ? 26 : 16);
int offset = L->pos() - pc_offset();
return is_intn(offset, maxReach);
}
int Assembler::link(Label* L) {
int position;
if (L->is_bound()) {
position = L->pos();
} else {
if (L->is_linked()) {
position = L->pos(); // L's link
} else {
// was: target_pos = kEndOfChain;
// However, using self to mark the first reference
// should avoid most instances of branch offset overflow. See
// target_at() for where this is converted back to kEndOfChain.
position = pc_offset();
}
L->link_to(pc_offset());
}
return position;
}
void Assembler::load_label_offset(Register r1, Label* L) {
int target_pos;
int constant;
if (L->is_bound()) {
target_pos = L->pos();
constant = target_pos + (Code::kHeaderSize - kHeapObjectTag);
} else {
if (L->is_linked()) {
target_pos = L->pos(); // L's link
} else {
// was: target_pos = kEndOfChain;
// However, using branch to self to mark the first reference
// should avoid most instances of branch offset overflow. See
// target_at() for where this is converted back to kEndOfChain.
target_pos = pc_offset();
}
L->link_to(pc_offset());
constant = target_pos - pc_offset();
}
llilf(r1, Operand(constant));
}
// Pseudo op - branch on condition
void Assembler::branchOnCond(Condition c, int branch_offset, bool is_bound) {
int offset = branch_offset;
if (is_bound && is_int16(offset)) {
brc(c, Operand(offset & 0xFFFF)); // short jump
} else {
brcl(c, Operand(offset)); // long jump
}
}
// 32-bit Store Multiple - short displacement (12-bits unsigned)
void Assembler::stm(Register r1, Register r2, const MemOperand& src) {
rs_form(STM, r1, r2, src.rb(), src.offset());
}
// 32-bit Store Multiple - long displacement (20-bits signed)
void Assembler::stmy(Register r1, Register r2, const MemOperand& src) {
rsy_form(STMY, r1, r2, src.rb(), src.offset());
}
// 64-bit Store Multiple - long displacement (20-bits signed)
void Assembler::stmg(Register r1, Register r2, const MemOperand& src) {
rsy_form(STMG, r1, r2, src.rb(), src.offset());
}
// Exception-generating instructions and debugging support.
// Stops with a non-negative code less than kNumOfWatchedStops support
// enabling/disabling and a counter feature. See simulator-s390.h .
void Assembler::stop(const char* msg, Condition cond, int32_t code,
CRegister cr) {
if (cond != al) {
Label skip;
b(NegateCondition(cond), &skip, Label::kNear);
bkpt(0);
bind(&skip);
} else {
bkpt(0);
}
}
void Assembler::bkpt(uint32_t imm16) {
// GDB software breakpoint instruction
emit2bytes(0x0001);
}
// Pseudo instructions.
void Assembler::nop(int type) {
switch (type) {
case 0:
lr(r0, r0);
break;
case DEBUG_BREAK_NOP:
// TODO(john.yan): Use a better NOP break
oill(r3, Operand::Zero());
break;
default:
UNIMPLEMENTED();
}
}
// RR format: <insn> R1,R2
// +--------+----+----+
// | OpCode | R1 | R2 |
// +--------+----+----+
// 0 8 12 15
#define RR_FORM_EMIT(name, op) \
void Assembler::name(Register r1, Register r2) { rr_form(op, r1, r2); }
void Assembler::rr_form(Opcode op, Register r1, Register r2) {
DCHECK(is_uint8(op));
emit2bytes(op * B8 | r1.code() * B4 | r2.code());
}
void Assembler::rr_form(Opcode op, DoubleRegister r1, DoubleRegister r2) {
DCHECK(is_uint8(op));
emit2bytes(op * B8 | r1.code() * B4 | r2.code());
}
// RR2 format: <insn> M1,R2
// +--------+----+----+
// | OpCode | M1 | R2 |
// +--------+----+----+
// 0 8 12 15
#define RR2_FORM_EMIT(name, op) \
void Assembler::name(Condition m1, Register r2) { rr_form(op, m1, r2); }
void Assembler::rr_form(Opcode op, Condition m1, Register r2) {
DCHECK(is_uint8(op));
DCHECK(is_uint4(m1));
emit2bytes(op * B8 | m1 * B4 | r2.code());
}
// RX format: <insn> R1,D2(X2,B2)
// +--------+----+----+----+-------------+
// | OpCode | R1 | X2 | B2 | D2 |
// +--------+----+----+----+-------------+
// 0 8 12 16 20 31
#define RX_FORM_EMIT(name, op) \
void Assembler::name(Register r, const MemOperand& opnd) { \
name(r, opnd.getIndexRegister(), opnd.getBaseRegister(), \
opnd.getDisplacement()); \
} \
void Assembler::name(Register r1, Register x2, Register b2, Disp d2) { \
rx_form(op, r1, x2, b2, d2); \
}
void Assembler::rx_form(Opcode op, Register r1, Register x2, Register b2,
Disp d2) {
DCHECK(is_uint8(op));
DCHECK(is_uint12(d2));
emit4bytes(op * B24 | r1.code() * B20 | x2.code() * B16 | b2.code() * B12 |
d2);
}
void Assembler::rx_form(Opcode op, DoubleRegister r1, Register x2, Register b2,
Disp d2) {
DCHECK(is_uint8(op));
DCHECK(is_uint12(d2));
emit4bytes(op * B24 | r1.code() * B20 | x2.code() * B16 | b2.code() * B12 |
d2);
}
// RI1 format: <insn> R1,I2
// +--------+----+----+------------------+
// | OpCode | R1 |OpCd| I2 |
// +--------+----+----+------------------+
// 0 8 12 16 31
#define RI1_FORM_EMIT(name, op) \
void Assembler::name(Register r, const Operand& i2) { ri_form(op, r, i2); }
void Assembler::ri_form(Opcode op, Register r1, const Operand& i2) {
DCHECK(is_uint12(op));
DCHECK(is_uint16(i2.imm_) || is_int16(i2.imm_));
emit4bytes((op & 0xFF0) * B20 | r1.code() * B20 | (op & 0xF) * B16 |
(i2.imm_ & 0xFFFF));
}
// RI2 format: <insn> M1,I2
// +--------+----+----+------------------+
// | OpCode | M1 |OpCd| I2 |
// +--------+----+----+------------------+
// 0 8 12 16 31
#define RI2_FORM_EMIT(name, op) \
void Assembler::name(Condition m, const Operand& i2) { ri_form(op, m, i2); }
void Assembler::ri_form(Opcode op, Condition m1, const Operand& i2) {
DCHECK(is_uint12(op));
DCHECK(is_uint4(m1));
DCHECK(is_uint16(i2.imm_));
emit4bytes((op & 0xFF0) * B20 | m1 * B20 | (op & 0xF) * B16 |
(i2.imm_ & 0xFFFF));
}
// RIE-f format: <insn> R1,R2,I3,I4,I5
// +--------+----+----+------------------+--------+--------+
// | OpCode | R1 | R2 | I3 | I4 | I5 | OpCode |
// +--------+----+----+------------------+--------+--------+
// 0 8 12 16 24 32 40 47
void Assembler::rie_f_form(Opcode op, Register r1, Register r2,
const Operand& i3, const Operand& i4,
const Operand& i5) {
DCHECK(is_uint16(op));
DCHECK(is_uint8(i3.imm_));
DCHECK(is_uint8(i4.imm_));
DCHECK(is_uint8(i5.imm_));
uint64_t code = (static_cast<uint64_t>(op & 0xFF00)) * B32 |
(static_cast<uint64_t>(r1.code())) * B36 |
(static_cast<uint64_t>(r2.code())) * B32 |
(static_cast<uint64_t>(i3.imm_)) * B24 |
(static_cast<uint64_t>(i4.imm_)) * B16 |
(static_cast<uint64_t>(i5.imm_)) * B8 |
(static_cast<uint64_t>(op & 0x00FF));
emit6bytes(code);
}
// RIE format: <insn> R1,R3,I2
// +--------+----+----+------------------+--------+--------+
// | OpCode | R1 | R3 | I2 |////////| OpCode |
// +--------+----+----+------------------+--------+--------+
// 0 8 12 16 32 40 47
#define RIE_FORM_EMIT(name, op) \
void Assembler::name(Register r1, Register r3, const Operand& i2) { \
rie_form(op, r1, r3, i2); \
}
void Assembler::rie_form(Opcode op, Register r1, Register r3,
const Operand& i2) {
DCHECK(is_uint16(op));
DCHECK(is_int16(i2.imm_));
uint64_t code = (static_cast<uint64_t>(op & 0xFF00)) * B32 |
(static_cast<uint64_t>(r1.code())) * B36 |
(static_cast<uint64_t>(r3.code())) * B32 |
(static_cast<uint64_t>(i2.imm_ & 0xFFFF)) * B16 |
(static_cast<uint64_t>(op & 0x00FF));
emit6bytes(code);
}
// RIL1 format: <insn> R1,I2
// +--------+----+----+------------------------------------+
// | OpCode | R1 |OpCd| I2 |
// +--------+----+----+------------------------------------+
// 0 8 12 16 47
#define RIL1_FORM_EMIT(name, op) \
void Assembler::name(Register r, const Operand& i2) { ril_form(op, r, i2); }
void Assembler::ril_form(Opcode op, Register r1, const Operand& i2) {
DCHECK(is_uint12(op));
uint64_t code = (static_cast<uint64_t>(op & 0xFF0)) * B36 |
(static_cast<uint64_t>(r1.code())) * B36 |
(static_cast<uint64_t>(op & 0x00F)) * B32 |
(static_cast<uint64_t>(i2.imm_) & 0xFFFFFFFF);
emit6bytes(code);
}
// RIL2 format: <insn> M1,I2
// +--------+----+----+------------------------------------+
// | OpCode | M1 |OpCd| I2 |
// +--------+----+----+------------------------------------+
// 0 8 12 16 47
#define RIL2_FORM_EMIT(name, op) \
void Assembler::name(Condition m1, const Operand& i2) { \
ril_form(op, m1, i2); \
}
void Assembler::ril_form(Opcode op, Condition m1, const Operand& i2) {
DCHECK(is_uint12(op));
DCHECK(is_uint4(m1));
uint64_t code = (static_cast<uint64_t>(op & 0xFF0)) * B36 |
(static_cast<uint64_t>(m1)) * B36 |
(static_cast<uint64_t>(op & 0x00F)) * B32 |
(static_cast<uint64_t>(i2.imm_ & 0xFFFFFFFF));
emit6bytes(code);
}
// RRE format: <insn> R1,R2
// +------------------+--------+----+----+
// | OpCode |////////| R1 | R2 |
// +------------------+--------+----+----+
// 0 16 24 28 31
#define RRE_FORM_EMIT(name, op) \
void Assembler::name(Register r1, Register r2) { rre_form(op, r1, r2); }
void Assembler::rre_form(Opcode op, Register r1, Register r2) {
DCHECK(is_uint16(op));
emit4bytes(op << 16 | r1.code() * B4 | r2.code());
}
void Assembler::rre_form(Opcode op, DoubleRegister r1, DoubleRegister r2) {
DCHECK(is_uint16(op));
emit4bytes(op << 16 | r1.code() * B4 | r2.code());
}
// RRD format: <insn> R1,R3, R2
// +------------------+----+----+----+----+
// | OpCode | R1 |////| R3 | R2 |
// +------------------+----+----+----+----+
// 0 16 20 24 28 31
#define RRD_FORM_EMIT(name, op) \
void Assembler::name(Register r1, Register r3, Register r2) { \
rrd_form(op, r1, r3, r2); \
}
void Assembler::rrd_form(Opcode op, Register r1, Register r3, Register r2) {
emit4bytes(op << 16 | r1.code() * B12 | r3.code() * B4 | r2.code());
}
// RS1 format: <insn> R1,R3,D2(B2)
// +--------+----+----+----+-------------+
// | OpCode | R1 | R3 | B2 | D2 |
// +--------+----+----+----+-------------+
// 0 8 12 16 20 31
#define RS1_FORM_EMIT(name, op) \
void Assembler::name(Register r1, Register r3, Register b2, Disp d2) { \
rs_form(op, r1, r3, b2, d2); \
} \
void Assembler::name(Register r1, Register r3, const MemOperand& opnd) { \
name(r1, r3, opnd.getBaseRegister(), opnd.getDisplacement()); \
}
void Assembler::rs_form(Opcode op, Register r1, Register r3, Register b2,
const Disp d2) {
DCHECK(is_uint12(d2));
emit4bytes(op * B24 | r1.code() * B20 | r3.code() * B16 | b2.code() * B12 |
d2);
}
// RS2 format: <insn> R1,M3,D2(B2)
// +--------+----+----+----+-------------+
// | OpCode | R1 | M3 | B2 | D2 |
// +--------+----+----+----+-------------+
// 0 8 12 16 20 31
#define RS2_FORM_EMIT(name, op) \
void Assembler::name(Register r1, Condition m3, Register b2, Disp d2) { \
rs_form(op, r1, m3, b2, d2); \
} \
void Assembler::name(Register r1, Condition m3, const MemOperand& opnd) { \
name(r1, m3, opnd.getBaseRegister(), opnd.getDisplacement()); \
}
void Assembler::rs_form(Opcode op, Register r1, Condition m3, Register b2,
const Disp d2) {
DCHECK(is_uint12(d2));
emit4bytes(op * B24 | r1.code() * B20 | m3 * B16 | b2.code() * B12 | d2);
}
// RSI format: <insn> R1,R3,I2
// +--------+----+----+------------------+
// | OpCode | R1 | R3 | RI2 |
// +--------+----+----+------------------+
// 0 8 12 16 31
#define RSI_FORM_EMIT(name, op) \
void Assembler::name(Register r1, Register r3, const Operand& i2) { \
rsi_form(op, r1, r3, i2); \
}
void Assembler::rsi_form(Opcode op, Register r1, Register r3,
const Operand& i2) {
DCHECK(is_uint8(op));
DCHECK(is_uint16(i2.imm_));
emit4bytes(op * B24 | r1.code() * B20 | r3.code() * B16 | (i2.imm_ & 0xFFFF));
}
// RSL format: <insn> R1,R3,D2(B2)
// +--------+----+----+----+-------------+--------+--------+
// | OpCode | L1 | | B2 | D2 | | OpCode |
// +--------+----+----+----+-------------+--------+--------+
// 0 8 12 16 20 32 40 47
#define RSL_FORM_EMIT(name, op) \
void Assembler::name(Length l1, Register b2, Disp d2) { \
rsl_form(op, l1, b2, d2); \
}
void Assembler::rsl_form(Opcode op, Length l1, Register b2, Disp d2) {
DCHECK(is_uint16(op));
uint64_t code = (static_cast<uint64_t>(op & 0xFF00)) * B32 |
(static_cast<uint64_t>(l1)) * B36 |
(static_cast<uint64_t>(b2.code())) * B28 |
(static_cast<uint64_t>(d2)) * B16 |
(static_cast<uint64_t>(op & 0x00FF));
emit6bytes(code);
}
// RSY1 format: <insn> R1,R3,D2(B2)
// +--------+----+----+----+-------------+--------+--------+
// | OpCode | R1 | R3 | B2 | DL2 | DH2 | OpCode |
// +--------+----+----+----+-------------+--------+--------+
// 0 8 12 16 20 32 40 47
#define RSY1_FORM_EMIT(name, op) \
void Assembler::name(Register r1, Register r3, Register b2, Disp d2) { \
rsy_form(op, r1, r3, b2, d2); \
} \
void Assembler::name(Register r1, Register r3, const MemOperand& opnd) { \
name(r1, r3, opnd.getBaseRegister(), opnd.getDisplacement()); \
}
void Assembler::rsy_form(Opcode op, Register r1, Register r3, Register b2,
const Disp d2) {
DCHECK(is_int20(d2));
DCHECK(is_uint16(op));
uint64_t code = (static_cast<uint64_t>(op & 0xFF00)) * B32 |
(static_cast<uint64_t>(r1.code())) * B36 |
(static_cast<uint64_t>(r3.code())) * B32 |
(static_cast<uint64_t>(b2.code())) * B28 |
(static_cast<uint64_t>(d2 & 0x0FFF)) * B16 |
(static_cast<uint64_t>(d2 & 0x0FF000)) >> 4 |
(static_cast<uint64_t>(op & 0x00FF));
emit6bytes(code);
}
// RSY2 format: <insn> R1,M3,D2(B2)
// +--------+----+----+----+-------------+--------+--------+
// | OpCode | R1 | M3 | B2 | DL2 | DH2 | OpCode |
// +--------+----+----+----+-------------+--------+--------+
// 0 8 12 16 20 32 40 47
#define RSY2_FORM_EMIT(name, op) \
void Assembler::name(Register r1, Condition m3, Register b2, Disp d2) { \
rsy_form(op, r1, m3, b2, d2); \
} \
void Assembler::name(Register r1, Condition m3, const MemOperand& opnd) { \
name(r1, m3, opnd.getBaseRegister(), opnd.getDisplacement()); \
}
void Assembler::rsy_form(Opcode op, Register r1, Condition m3, Register b2,
const Disp d2) {
DCHECK(is_int20(d2));
DCHECK(is_uint16(op));
uint64_t code = (static_cast<uint64_t>(op & 0xFF00)) * B32 |
(static_cast<uint64_t>(r1.code())) * B36 |
(static_cast<uint64_t>(m3)) * B32 |
(static_cast<uint64_t>(b2.code())) * B28 |
(static_cast<uint64_t>(d2 & 0x0FFF)) * B16 |
(static_cast<uint64_t>(d2 & 0x0FF000)) >> 4 |
(static_cast<uint64_t>(op & 0x00FF));
emit6bytes(code);
}
// RXE format: <insn> R1,D2(X2,B2)
// +--------+----+----+----+-------------+--------+--------+
// | OpCode | R1 | X2 | B2 | D2 |////////| OpCode |
// +--------+----+----+----+-------------+--------+--------+
// 0 8 12 16 20 32 40 47
#define RXE_FORM_EMIT(name, op) \
void Assembler::name(Register r1, Register x2, Register b2, Disp d2) { \
rxe_form(op, r1, x2, b2, d2); \
} \
void Assembler::name(Register r1, const MemOperand& opnd) { \
name(r1, opnd.getIndexRegister(), opnd.getBaseRegister(), \
opnd.getDisplacement()); \
}
void Assembler::rxe_form(Opcode op, Register r1, Register x2, Register b2,
Disp d2) {
DCHECK(is_uint12(d2));
DCHECK(is_uint16(op));
uint64_t code = (static_cast<uint64_t>(op & 0xFF00)) * B32 |
(static_cast<uint64_t>(r1.code())) * B36 |
(static_cast<uint64_t>(x2.code())) * B32 |
(static_cast<uint64_t>(b2.code())) * B28 |
(static_cast<uint64_t>(d2 & 0x0FFF)) * B16 |
(static_cast<uint64_t>(op & 0x00FF));
emit6bytes(code);
}
// RXY format: <insn> R1,D2(X2,B2)
// +--------+----+----+----+-------------+--------+--------+
// | OpCode | R1 | X2 | B2 | DL2 | DH2 | OpCode |
// +--------+----+----+----+-------------+--------+--------+
// 0 8 12 16 20 32 36 40 47
#define RXY_FORM_EMIT(name, op) \
void Assembler::name(Register r1, Register x2, Register b2, Disp d2) { \
rxy_form(op, r1, x2, b2, d2); \
} \
void Assembler::name(Register r1, const MemOperand& opnd) { \
name(r1, opnd.getIndexRegister(), opnd.getBaseRegister(), \
opnd.getDisplacement()); \
}
void Assembler::rxy_form(Opcode op, Register r1, Register x2, Register b2,
Disp d2) {
DCHECK(is_int20(d2));
DCHECK(is_uint16(op));
uint64_t code = (static_cast<uint64_t>(op & 0xFF00)) * B32 |
(static_cast<uint64_t>(r1.code())) * B36 |
(static_cast<uint64_t>(x2.code())) * B32 |
(static_cast<uint64_t>(b2.code())) * B28 |
(static_cast<uint64_t>(d2 & 0x0FFF)) * B16 |
(static_cast<uint64_t>(d2 & 0x0FF000)) >> 4 |
(static_cast<uint64_t>(op & 0x00FF));
emit6bytes(code);
}
void Assembler::rxy_form(Opcode op, DoubleRegister r1, Register x2, Register b2,
Disp d2) {
DCHECK(is_int20(d2));
DCHECK(is_uint16(op));
uint64_t code = (static_cast<uint64_t>(op & 0xFF00)) * B32 |
(static_cast<uint64_t>(r1.code())) * B36 |
(static_cast<uint64_t>(x2.code())) * B32 |
(static_cast<uint64_t>(b2.code())) * B28 |
(static_cast<uint64_t>(d2 & 0x0FFF)) * B16 |
(static_cast<uint64_t>(d2 & 0x0FF000)) >> 4 |
(static_cast<uint64_t>(op & 0x00FF));
emit6bytes(code);
}
// RRS format: <insn> R1,R2,M3,D4(B4)
// +--------+----+----+----+-------------+----+---+--------+
// | OpCode | R1 | R2 | B4 | D4 | M3 |///| OpCode |
// +--------+----+----+----+-------------+----+---+--------+
// 0 8 12 16 20 32 36 40 47
#define RRS_FORM_EMIT(name, op) \
void Assembler::name(Register r1, Register r2, Register b4, Disp d4, \
Condition m3) { \
rrs_form(op, r1, r2, b4, d4, m3); \
} \
void Assembler::name(Register r1, Register r2, Condition m3, \
const MemOperand& opnd) { \
name(r1, r2, opnd.getBaseRegister(), opnd.getDisplacement(), m3); \
}
void Assembler::rrs_form(Opcode op, Register r1, Register r2, Register b4,
Disp d4, Condition m3) {
DCHECK(is_uint12(d4));
DCHECK(is_uint16(op));
uint64_t code = (static_cast<uint64_t>(op & 0xFF00)) * B32 |
(static_cast<uint64_t>(r1.code())) * B36 |
(static_cast<uint64_t>(r2.code())) * B32 |
(static_cast<uint64_t>(b4.code())) * B28 |
(static_cast<uint64_t>(d4)) * B16 |
(static_cast<uint64_t>(m3)) << 12 |
(static_cast<uint64_t>(op & 0x00FF));
emit6bytes(code);
}
// RIS format: <insn> R1,I2,M3,D4(B4)
// +--------+----+----+----+-------------+--------+--------+
// | OpCode | R1 | M3 | B4 | D4 | I2 | OpCode |
// +--------+----+----+----+-------------+--------+--------+
// 0 8 12 16 20 32 40 47
#define RIS_FORM_EMIT(name, op) \
void Assembler::name(Register r1, Condition m3, Register b4, Disp d4, \
const Operand& i2) { \
ris_form(op, r1, m3, b4, d4, i2); \
} \
void Assembler::name(Register r1, const Operand& i2, Condition m3, \
const MemOperand& opnd) { \