/
asm6.go
5444 lines (4871 loc) · 144 KB
/
asm6.go
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
// Inferno utils/6l/span.c
// https://bitbucket.org/inferno-os/inferno-os/src/default/utils/6l/span.c
//
// Copyright © 1994-1999 Lucent Technologies Inc. All rights reserved.
// Portions Copyright © 1995-1997 C H Forsyth (forsyth@terzarima.net)
// Portions Copyright © 1997-1999 Vita Nuova Limited
// Portions Copyright © 2000-2007 Vita Nuova Holdings Limited (www.vitanuova.com)
// Portions Copyright © 2004,2006 Bruce Ellis
// Portions Copyright © 2005-2007 C H Forsyth (forsyth@terzarima.net)
// Revisions Copyright © 2000-2007 Lucent Technologies Inc. and others
// Portions Copyright © 2009 The Go Authors. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
package x86
import (
"cmd/internal/obj"
"cmd/internal/objabi"
"cmd/internal/sys"
"encoding/binary"
"fmt"
"log"
"strings"
)
var (
plan9privates *obj.LSym
deferreturn *obj.LSym
)
// Instruction layout.
// Loop alignment constants:
// want to align loop entry to loopAlign-byte boundary,
// and willing to insert at most maxLoopPad bytes of NOP to do so.
// We define a loop entry as the target of a backward jump.
//
// gcc uses maxLoopPad = 10 for its 'generic x86-64' config,
// and it aligns all jump targets, not just backward jump targets.
//
// As of 6/1/2012, the effect of setting maxLoopPad = 10 here
// is very slight but negative, so the alignment is disabled by
// setting MaxLoopPad = 0. The code is here for reference and
// for future experiments.
//
const (
loopAlign = 16
maxLoopPad = 0
)
// Bit flags that are used to express jump target properties.
const (
// branchBackwards marks targets that are located behind.
// Used to express jumps to loop headers.
branchBackwards = (1 << iota)
// branchShort marks branches those target is close,
// with offset is in -128..127 range.
branchShort
// branchLoopHead marks loop entry.
// Used to insert padding for misaligned loops.
branchLoopHead
)
// opBytes holds optab encoding bytes.
// Each ytab reserves fixed amount of bytes in this array.
//
// The size should be the minimal number of bytes that
// are enough to hold biggest optab op lines.
type opBytes [31]uint8
type Optab struct {
as obj.As
ytab []ytab
prefix uint8
op opBytes
}
type Movtab struct {
as obj.As
ft uint8
f3t uint8
tt uint8
code uint8
op [4]uint8
}
const (
Yxxx = iota
Ynone
Yi0 // $0
Yi1 // $1
Yu2 // $x, x fits in uint2
Yi8 // $x, x fits in int8
Yu8 // $x, x fits in uint8
Yu7 // $x, x in 0..127 (fits in both int8 and uint8)
Ys32
Yi32
Yi64
Yiauto
Yal
Ycl
Yax
Ycx
Yrb
Yrl
Yrl32 // Yrl on 32-bit system
Yrf
Yf0
Yrx
Ymb
Yml
Ym
Ybr
Ycs
Yss
Yds
Yes
Yfs
Ygs
Ygdtr
Yidtr
Yldtr
Ymsw
Ytask
Ycr0
Ycr1
Ycr2
Ycr3
Ycr4
Ycr5
Ycr6
Ycr7
Ycr8
Ydr0
Ydr1
Ydr2
Ydr3
Ydr4
Ydr5
Ydr6
Ydr7
Ytr0
Ytr1
Ytr2
Ytr3
Ytr4
Ytr5
Ytr6
Ytr7
Ymr
Ymm
Yxr0 // X0 only. "<XMM0>" notation in Intel manual.
YxrEvexMulti4 // [ X<n> - X<n+3> ]; multisource YxrEvex
Yxr // X0..X15
YxrEvex // X0..X31
Yxm
YxmEvex // YxrEvex+Ym
Yxvm // VSIB vector array; vm32x/vm64x
YxvmEvex // Yxvm which permits High-16 X register as index.
YyrEvexMulti4 // [ Y<n> - Y<n+3> ]; multisource YyrEvex
Yyr // Y0..Y15
YyrEvex // Y0..Y31
Yym
YymEvex // YyrEvex+Ym
Yyvm // VSIB vector array; vm32y/vm64y
YyvmEvex // Yyvm which permits High-16 Y register as index.
YzrMulti4 // [ Z<n> - Z<n+3> ]; multisource YzrEvex
Yzr // Z0..Z31
Yzm // Yzr+Ym
Yzvm // VSIB vector array; vm32z/vm64z
Yk0 // K0
Yknot0 // K1..K7; write mask
Yk // K0..K7; used for KOP
Ykm // Yk+Ym; used for KOP
Ytls
Ytextsize
Yindir
Ymax
)
const (
Zxxx = iota
Zlit
Zlitm_r
Zlitr_m
Zlit_m_r
Z_rp
Zbr
Zcall
Zcallcon
Zcallduff
Zcallind
Zcallindreg
Zib_
Zib_rp
Zibo_m
Zibo_m_xm
Zil_
Zil_rp
Ziq_rp
Zilo_m
Zjmp
Zjmpcon
Zloop
Zo_iw
Zm_o
Zm_r
Z_m_r
Zm2_r
Zm_r_xm
Zm_r_i_xm
Zm_r_xm_nr
Zr_m_xm_nr
Zibm_r // mmx1,mmx2/mem64,imm8
Zibr_m
Zmb_r
Zaut_r
Zo_m
Zo_m64
Zpseudo
Zr_m
Zr_m_xm
Zrp_
Z_ib
Z_il
Zm_ibo
Zm_ilo
Zib_rr
Zil_rr
Zbyte
Zvex_rm_v_r
Zvex_rm_v_ro
Zvex_r_v_rm
Zvex_i_rm_vo
Zvex_v_rm_r
Zvex_i_rm_r
Zvex_i_r_v
Zvex_i_rm_v_r
Zvex
Zvex_rm_r_vo
Zvex_i_r_rm
Zvex_hr_rm_v_r
Zevex_first
Zevex_i_r_k_rm
Zevex_i_r_rm
Zevex_i_rm_k_r
Zevex_i_rm_k_vo
Zevex_i_rm_r
Zevex_i_rm_v_k_r
Zevex_i_rm_v_r
Zevex_i_rm_vo
Zevex_k_rmo
Zevex_r_k_rm
Zevex_r_v_k_rm
Zevex_r_v_rm
Zevex_rm_k_r
Zevex_rm_v_k_r
Zevex_rm_v_r
Zevex_last
Zmax
)
const (
Px = 0
Px1 = 1 // symbolic; exact value doesn't matter
P32 = 0x32 // 32-bit only
Pe = 0x66 // operand escape
Pm = 0x0f // 2byte opcode escape
Pq = 0xff // both escapes: 66 0f
Pb = 0xfe // byte operands
Pf2 = 0xf2 // xmm escape 1: f2 0f
Pf3 = 0xf3 // xmm escape 2: f3 0f
Pef3 = 0xf5 // xmm escape 2 with 16-bit prefix: 66 f3 0f
Pq3 = 0x67 // xmm escape 3: 66 48 0f
Pq4 = 0x68 // xmm escape 4: 66 0F 38
Pq4w = 0x69 // Pq4 with Rex.w 66 0F 38
Pq5 = 0x6a // xmm escape 5: F3 0F 38
Pq5w = 0x6b // Pq5 with Rex.w F3 0F 38
Pfw = 0xf4 // Pf3 with Rex.w: f3 48 0f
Pw = 0x48 // Rex.w
Pw8 = 0x90 // symbolic; exact value doesn't matter
Py = 0x80 // defaults to 64-bit mode
Py1 = 0x81 // symbolic; exact value doesn't matter
Py3 = 0x83 // symbolic; exact value doesn't matter
Pavx = 0x84 // symbolic: exact value doesn't matter
RxrEvex = 1 << 4 // AVX512 extension to REX.R/VEX.R
Rxw = 1 << 3 // =1, 64-bit operand size
Rxr = 1 << 2 // extend modrm reg
Rxx = 1 << 1 // extend sib index
Rxb = 1 << 0 // extend modrm r/m, sib base, or opcode reg
)
const (
// Encoding for VEX prefix in tables.
// The P, L, and W fields are chosen to match
// their eventual locations in the VEX prefix bytes.
// Encoding for VEX prefix in tables.
// The P, L, and W fields are chosen to match
// their eventual locations in the VEX prefix bytes.
// Using spare bit to make leading [E]VEX encoding byte different from
// 0x0f even if all other VEX fields are 0.
avxEscape = 1 << 6
// P field - 2 bits
vex66 = 1 << 0
vexF3 = 2 << 0
vexF2 = 3 << 0
// L field - 1 bit
vexLZ = 0 << 2
vexLIG = 0 << 2
vex128 = 0 << 2
vex256 = 1 << 2
// W field - 1 bit
vexWIG = 0 << 7
vexW0 = 0 << 7
vexW1 = 1 << 7
// M field - 5 bits, but mostly reserved; we can store up to 3
vex0F = 1 << 3
vex0F38 = 2 << 3
vex0F3A = 3 << 3
)
var ycover [Ymax * Ymax]uint8
var reg [MAXREG]int
var regrex [MAXREG + 1]int
var ynone = []ytab{
{Zlit, 1, argList{}},
}
var ytext = []ytab{
{Zpseudo, 0, argList{Ymb, Ytextsize}},
{Zpseudo, 1, argList{Ymb, Yi32, Ytextsize}},
}
var ynop = []ytab{
{Zpseudo, 0, argList{}},
{Zpseudo, 0, argList{Yiauto}},
{Zpseudo, 0, argList{Yml}},
{Zpseudo, 0, argList{Yrf}},
{Zpseudo, 0, argList{Yxr}},
{Zpseudo, 0, argList{Yiauto}},
{Zpseudo, 0, argList{Yml}},
{Zpseudo, 0, argList{Yrf}},
{Zpseudo, 1, argList{Yxr}},
}
var yfuncdata = []ytab{
{Zpseudo, 0, argList{Yi32, Ym}},
}
var ypcdata = []ytab{
{Zpseudo, 0, argList{Yi32, Yi32}},
}
var yxorb = []ytab{
{Zib_, 1, argList{Yi32, Yal}},
{Zibo_m, 2, argList{Yi32, Ymb}},
{Zr_m, 1, argList{Yrb, Ymb}},
{Zm_r, 1, argList{Ymb, Yrb}},
}
var yaddl = []ytab{
{Zibo_m, 2, argList{Yi8, Yml}},
{Zil_, 1, argList{Yi32, Yax}},
{Zilo_m, 2, argList{Yi32, Yml}},
{Zr_m, 1, argList{Yrl, Yml}},
{Zm_r, 1, argList{Yml, Yrl}},
}
var yincl = []ytab{
{Z_rp, 1, argList{Yrl}},
{Zo_m, 2, argList{Yml}},
}
var yincq = []ytab{
{Zo_m, 2, argList{Yml}},
}
var ycmpb = []ytab{
{Z_ib, 1, argList{Yal, Yi32}},
{Zm_ibo, 2, argList{Ymb, Yi32}},
{Zm_r, 1, argList{Ymb, Yrb}},
{Zr_m, 1, argList{Yrb, Ymb}},
}
var ycmpl = []ytab{
{Zm_ibo, 2, argList{Yml, Yi8}},
{Z_il, 1, argList{Yax, Yi32}},
{Zm_ilo, 2, argList{Yml, Yi32}},
{Zm_r, 1, argList{Yml, Yrl}},
{Zr_m, 1, argList{Yrl, Yml}},
}
var yshb = []ytab{
{Zo_m, 2, argList{Yi1, Ymb}},
{Zibo_m, 2, argList{Yu8, Ymb}},
{Zo_m, 2, argList{Ycx, Ymb}},
}
var yshl = []ytab{
{Zo_m, 2, argList{Yi1, Yml}},
{Zibo_m, 2, argList{Yu8, Yml}},
{Zo_m, 2, argList{Ycl, Yml}},
{Zo_m, 2, argList{Ycx, Yml}},
}
var ytestl = []ytab{
{Zil_, 1, argList{Yi32, Yax}},
{Zilo_m, 2, argList{Yi32, Yml}},
{Zr_m, 1, argList{Yrl, Yml}},
{Zm_r, 1, argList{Yml, Yrl}},
}
var ymovb = []ytab{
{Zr_m, 1, argList{Yrb, Ymb}},
{Zm_r, 1, argList{Ymb, Yrb}},
{Zib_rp, 1, argList{Yi32, Yrb}},
{Zibo_m, 2, argList{Yi32, Ymb}},
}
var ybtl = []ytab{
{Zibo_m, 2, argList{Yi8, Yml}},
{Zr_m, 1, argList{Yrl, Yml}},
}
var ymovw = []ytab{
{Zr_m, 1, argList{Yrl, Yml}},
{Zm_r, 1, argList{Yml, Yrl}},
{Zil_rp, 1, argList{Yi32, Yrl}},
{Zilo_m, 2, argList{Yi32, Yml}},
{Zaut_r, 2, argList{Yiauto, Yrl}},
}
var ymovl = []ytab{
{Zr_m, 1, argList{Yrl, Yml}},
{Zm_r, 1, argList{Yml, Yrl}},
{Zil_rp, 1, argList{Yi32, Yrl}},
{Zilo_m, 2, argList{Yi32, Yml}},
{Zm_r_xm, 1, argList{Yml, Ymr}}, // MMX MOVD
{Zr_m_xm, 1, argList{Ymr, Yml}}, // MMX MOVD
{Zm_r_xm, 2, argList{Yml, Yxr}}, // XMM MOVD (32 bit)
{Zr_m_xm, 2, argList{Yxr, Yml}}, // XMM MOVD (32 bit)
{Zaut_r, 2, argList{Yiauto, Yrl}},
}
var yret = []ytab{
{Zo_iw, 1, argList{}},
{Zo_iw, 1, argList{Yi32}},
}
var ymovq = []ytab{
// valid in 32-bit mode
{Zm_r_xm_nr, 1, argList{Ym, Ymr}}, // 0x6f MMX MOVQ (shorter encoding)
{Zr_m_xm_nr, 1, argList{Ymr, Ym}}, // 0x7f MMX MOVQ
{Zm_r_xm_nr, 2, argList{Yxr, Ymr}}, // Pf2, 0xd6 MOVDQ2Q
{Zm_r_xm_nr, 2, argList{Yxm, Yxr}}, // Pf3, 0x7e MOVQ xmm1/m64 -> xmm2
{Zr_m_xm_nr, 2, argList{Yxr, Yxm}}, // Pe, 0xd6 MOVQ xmm1 -> xmm2/m64
// valid only in 64-bit mode, usually with 64-bit prefix
{Zr_m, 1, argList{Yrl, Yml}}, // 0x89
{Zm_r, 1, argList{Yml, Yrl}}, // 0x8b
{Zilo_m, 2, argList{Ys32, Yrl}}, // 32 bit signed 0xc7,(0)
{Ziq_rp, 1, argList{Yi64, Yrl}}, // 0xb8 -- 32/64 bit immediate
{Zilo_m, 2, argList{Yi32, Yml}}, // 0xc7,(0)
{Zm_r_xm, 1, argList{Ymm, Ymr}}, // 0x6e MMX MOVD
{Zr_m_xm, 1, argList{Ymr, Ymm}}, // 0x7e MMX MOVD
{Zm_r_xm, 2, argList{Yml, Yxr}}, // Pe, 0x6e MOVD xmm load
{Zr_m_xm, 2, argList{Yxr, Yml}}, // Pe, 0x7e MOVD xmm store
{Zaut_r, 1, argList{Yiauto, Yrl}}, // 0 built-in LEAQ
}
var ymovbe = []ytab{
{Zlitm_r, 3, argList{Ym, Yrl}},
{Zlitr_m, 3, argList{Yrl, Ym}},
}
var ym_rl = []ytab{
{Zm_r, 1, argList{Ym, Yrl}},
}
var yrl_m = []ytab{
{Zr_m, 1, argList{Yrl, Ym}},
}
var ymb_rl = []ytab{
{Zmb_r, 1, argList{Ymb, Yrl}},
}
var yml_rl = []ytab{
{Zm_r, 1, argList{Yml, Yrl}},
}
var yrl_ml = []ytab{
{Zr_m, 1, argList{Yrl, Yml}},
}
var yml_mb = []ytab{
{Zr_m, 1, argList{Yrb, Ymb}},
{Zm_r, 1, argList{Ymb, Yrb}},
}
var yrb_mb = []ytab{
{Zr_m, 1, argList{Yrb, Ymb}},
}
var yxchg = []ytab{
{Z_rp, 1, argList{Yax, Yrl}},
{Zrp_, 1, argList{Yrl, Yax}},
{Zr_m, 1, argList{Yrl, Yml}},
{Zm_r, 1, argList{Yml, Yrl}},
}
var ydivl = []ytab{
{Zm_o, 2, argList{Yml}},
}
var ydivb = []ytab{
{Zm_o, 2, argList{Ymb}},
}
var yimul = []ytab{
{Zm_o, 2, argList{Yml}},
{Zib_rr, 1, argList{Yi8, Yrl}},
{Zil_rr, 1, argList{Yi32, Yrl}},
{Zm_r, 2, argList{Yml, Yrl}},
}
var yimul3 = []ytab{
{Zibm_r, 2, argList{Yi8, Yml, Yrl}},
{Zibm_r, 2, argList{Yi32, Yml, Yrl}},
}
var ybyte = []ytab{
{Zbyte, 1, argList{Yi64}},
}
var yin = []ytab{
{Zib_, 1, argList{Yi32}},
{Zlit, 1, argList{}},
}
var yint = []ytab{
{Zib_, 1, argList{Yi32}},
}
var ypushl = []ytab{
{Zrp_, 1, argList{Yrl}},
{Zm_o, 2, argList{Ym}},
{Zib_, 1, argList{Yi8}},
{Zil_, 1, argList{Yi32}},
}
var ypopl = []ytab{
{Z_rp, 1, argList{Yrl}},
{Zo_m, 2, argList{Ym}},
}
var ywrfsbase = []ytab{
{Zm_o, 2, argList{Yrl}},
}
var yrdrand = []ytab{
{Zo_m, 2, argList{Yrl}},
}
var yclflush = []ytab{
{Zo_m, 2, argList{Ym}},
}
var ybswap = []ytab{
{Z_rp, 2, argList{Yrl}},
}
var yscond = []ytab{
{Zo_m, 2, argList{Ymb}},
}
var yjcond = []ytab{
{Zbr, 0, argList{Ybr}},
{Zbr, 0, argList{Yi0, Ybr}},
{Zbr, 1, argList{Yi1, Ybr}},
}
var yloop = []ytab{
{Zloop, 1, argList{Ybr}},
}
var ycall = []ytab{
{Zcallindreg, 0, argList{Yml}},
{Zcallindreg, 2, argList{Yrx, Yrx}},
{Zcallind, 2, argList{Yindir}},
{Zcall, 0, argList{Ybr}},
{Zcallcon, 1, argList{Yi32}},
}
var yduff = []ytab{
{Zcallduff, 1, argList{Yi32}},
}
var yjmp = []ytab{
{Zo_m64, 2, argList{Yml}},
{Zjmp, 0, argList{Ybr}},
{Zjmpcon, 1, argList{Yi32}},
}
var yfmvd = []ytab{
{Zm_o, 2, argList{Ym, Yf0}},
{Zo_m, 2, argList{Yf0, Ym}},
{Zm_o, 2, argList{Yrf, Yf0}},
{Zo_m, 2, argList{Yf0, Yrf}},
}
var yfmvdp = []ytab{
{Zo_m, 2, argList{Yf0, Ym}},
{Zo_m, 2, argList{Yf0, Yrf}},
}
var yfmvf = []ytab{
{Zm_o, 2, argList{Ym, Yf0}},
{Zo_m, 2, argList{Yf0, Ym}},
}
var yfmvx = []ytab{
{Zm_o, 2, argList{Ym, Yf0}},
}
var yfmvp = []ytab{
{Zo_m, 2, argList{Yf0, Ym}},
}
var yfcmv = []ytab{
{Zm_o, 2, argList{Yrf, Yf0}},
}
var yfadd = []ytab{
{Zm_o, 2, argList{Ym, Yf0}},
{Zm_o, 2, argList{Yrf, Yf0}},
{Zo_m, 2, argList{Yf0, Yrf}},
}
var yfxch = []ytab{
{Zo_m, 2, argList{Yf0, Yrf}},
{Zm_o, 2, argList{Yrf, Yf0}},
}
var ycompp = []ytab{
{Zo_m, 2, argList{Yf0, Yrf}}, // botch is really f0,f1
}
var ystsw = []ytab{
{Zo_m, 2, argList{Ym}},
{Zlit, 1, argList{Yax}},
}
var ysvrs_mo = []ytab{
{Zm_o, 2, argList{Ym}},
}
// unaryDst version of "ysvrs_mo".
var ysvrs_om = []ytab{
{Zo_m, 2, argList{Ym}},
}
var ymm = []ytab{
{Zm_r_xm, 1, argList{Ymm, Ymr}},
{Zm_r_xm, 2, argList{Yxm, Yxr}},
}
var yxm = []ytab{
{Zm_r_xm, 1, argList{Yxm, Yxr}},
}
var yxm_q4 = []ytab{
{Zm_r, 1, argList{Yxm, Yxr}},
}
var yxcvm1 = []ytab{
{Zm_r_xm, 2, argList{Yxm, Yxr}},
{Zm_r_xm, 2, argList{Yxm, Ymr}},
}
var yxcvm2 = []ytab{
{Zm_r_xm, 2, argList{Yxm, Yxr}},
{Zm_r_xm, 2, argList{Ymm, Yxr}},
}
var yxr = []ytab{
{Zm_r_xm, 1, argList{Yxr, Yxr}},
}
var yxr_ml = []ytab{
{Zr_m_xm, 1, argList{Yxr, Yml}},
}
var ymr = []ytab{
{Zm_r, 1, argList{Ymr, Ymr}},
}
var ymr_ml = []ytab{
{Zr_m_xm, 1, argList{Ymr, Yml}},
}
var yxcmpi = []ytab{
{Zm_r_i_xm, 2, argList{Yxm, Yxr, Yi8}},
}
var yxmov = []ytab{
{Zm_r_xm, 1, argList{Yxm, Yxr}},
{Zr_m_xm, 1, argList{Yxr, Yxm}},
}
var yxcvfl = []ytab{
{Zm_r_xm, 1, argList{Yxm, Yrl}},
}
var yxcvlf = []ytab{
{Zm_r_xm, 1, argList{Yml, Yxr}},
}
var yxcvfq = []ytab{
{Zm_r_xm, 2, argList{Yxm, Yrl}},
}
var yxcvqf = []ytab{
{Zm_r_xm, 2, argList{Yml, Yxr}},
}
var yps = []ytab{
{Zm_r_xm, 1, argList{Ymm, Ymr}},
{Zibo_m_xm, 2, argList{Yi8, Ymr}},
{Zm_r_xm, 2, argList{Yxm, Yxr}},
{Zibo_m_xm, 3, argList{Yi8, Yxr}},
}
var yxrrl = []ytab{
{Zm_r, 1, argList{Yxr, Yrl}},
}
var ymrxr = []ytab{
{Zm_r, 1, argList{Ymr, Yxr}},
{Zm_r_xm, 1, argList{Yxm, Yxr}},
}
var ymshuf = []ytab{
{Zibm_r, 2, argList{Yi8, Ymm, Ymr}},
}
var ymshufb = []ytab{
{Zm2_r, 2, argList{Yxm, Yxr}},
}
// It should never have more than 1 entry,
// because some optab entries you opcode secuences that
// are longer than 2 bytes (zoffset=2 here),
// ROUNDPD and ROUNDPS and recently added BLENDPD,
// to name a few.
var yxshuf = []ytab{
{Zibm_r, 2, argList{Yu8, Yxm, Yxr}},
}
var yextrw = []ytab{
{Zibm_r, 2, argList{Yu8, Yxr, Yrl}},
{Zibr_m, 2, argList{Yu8, Yxr, Yml}},
}
var yextr = []ytab{
{Zibr_m, 3, argList{Yu8, Yxr, Ymm}},
}
var yinsrw = []ytab{
{Zibm_r, 2, argList{Yu8, Yml, Yxr}},
}
var yinsr = []ytab{
{Zibm_r, 3, argList{Yu8, Ymm, Yxr}},
}
var ypsdq = []ytab{
{Zibo_m, 2, argList{Yi8, Yxr}},
}
var ymskb = []ytab{
{Zm_r_xm, 2, argList{Yxr, Yrl}},
{Zm_r_xm, 1, argList{Ymr, Yrl}},
}
var ycrc32l = []ytab{
{Zlitm_r, 0, argList{Yml, Yrl}},
}
var ycrc32b = []ytab{
{Zlitm_r, 0, argList{Ymb, Yrl}},
}
var yprefetch = []ytab{
{Zm_o, 2, argList{Ym}},
}
var yaes = []ytab{
{Zlitm_r, 2, argList{Yxm, Yxr}},
}
var yxbegin = []ytab{
{Zjmp, 1, argList{Ybr}},
}
var yxabort = []ytab{
{Zib_, 1, argList{Yu8}},
}
var ylddqu = []ytab{
{Zm_r, 1, argList{Ym, Yxr}},
}
var ypalignr = []ytab{
{Zibm_r, 2, argList{Yu8, Yxm, Yxr}},
}
var ysha256rnds2 = []ytab{
{Zlit_m_r, 0, argList{Yxr0, Yxm, Yxr}},
}
var yblendvpd = []ytab{
{Z_m_r, 1, argList{Yxr0, Yxm, Yxr}},
}
var ymmxmm0f38 = []ytab{
{Zlitm_r, 3, argList{Ymm, Ymr}},
{Zlitm_r, 5, argList{Yxm, Yxr}},
}
var yextractps = []ytab{
{Zibr_m, 2, argList{Yu2, Yxr, Yml}},
}
var ysha1rnds4 = []ytab{
{Zibm_r, 2, argList{Yu2, Yxm, Yxr}},
}
// You are doasm, holding in your hand a *obj.Prog with p.As set to, say,
// ACRC32, and p.From and p.To as operands (obj.Addr). The linker scans optab
// to find the entry with the given p.As and then looks through the ytable for
// that instruction (the second field in the optab struct) for a line whose
// first two values match the Ytypes of the p.From and p.To operands. The
// function oclass computes the specific Ytype of an operand and then the set
// of more general Ytypes that it satisfies is implied by the ycover table, set
// up in instinit. For example, oclass distinguishes the constants 0 and 1
// from the more general 8-bit constants, but instinit says
//
// ycover[Yi0*Ymax+Ys32] = 1
// ycover[Yi1*Ymax+Ys32] = 1
// ycover[Yi8*Ymax+Ys32] = 1
//
// which means that Yi0, Yi1, and Yi8 all count as Ys32 (signed 32)
// if that's what an instruction can handle.
//
// In parallel with the scan through the ytable for the appropriate line, there
// is a z pointer that starts out pointing at the strange magic byte list in
// the Optab struct. With each step past a non-matching ytable line, z
// advances by the 4th entry in the line. When a matching line is found, that
// z pointer has the extra data to use in laying down the instruction bytes.
// The actual bytes laid down are a function of the 3rd entry in the line (that
// is, the Ztype) and the z bytes.
//
// For example, let's look at AADDL. The optab line says:
// {AADDL, yaddl, Px, opBytes{0x83, 00, 0x05, 0x81, 00, 0x01, 0x03}},
//
// and yaddl says
// var yaddl = []ytab{
// {Yi8, Ynone, Yml, Zibo_m, 2},
// {Yi32, Ynone, Yax, Zil_, 1},
// {Yi32, Ynone, Yml, Zilo_m, 2},
// {Yrl, Ynone, Yml, Zr_m, 1},
// {Yml, Ynone, Yrl, Zm_r, 1},
// }
//
// so there are 5 possible types of ADDL instruction that can be laid down, and
// possible states used to lay them down (Ztype and z pointer, assuming z
// points at opBytes{0x83, 00, 0x05,0x81, 00, 0x01, 0x03}) are:
//
// Yi8, Yml -> Zibo_m, z (0x83, 00)
// Yi32, Yax -> Zil_, z+2 (0x05)
// Yi32, Yml -> Zilo_m, z+2+1 (0x81, 0x00)
// Yrl, Yml -> Zr_m, z+2+1+2 (0x01)
// Yml, Yrl -> Zm_r, z+2+1+2+1 (0x03)
//
// The Pconstant in the optab line controls the prefix bytes to emit. That's
// relatively straightforward as this program goes.
//
// The switch on yt.zcase in doasm implements the various Z cases. Zibo_m, for
// example, is an opcode byte (z[0]) then an asmando (which is some kind of
// encoded addressing mode for the Yml arg), and then a single immediate byte.
// Zilo_m is the same but a long (32-bit) immediate.
var optab =
// as, ytab, andproto, opcode
[...]Optab{
{obj.AXXX, nil, 0, opBytes{}},
{AAAA, ynone, P32, opBytes{0x37}},
{AAAD, ynone, P32, opBytes{0xd5, 0x0a}},
{AAAM, ynone, P32, opBytes{0xd4, 0x0a}},
{AAAS, ynone, P32, opBytes{0x3f}},
{AADCB, yxorb, Pb, opBytes{0x14, 0x80, 02, 0x10, 0x12}},
{AADCL, yaddl, Px, opBytes{0x83, 02, 0x15, 0x81, 02, 0x11, 0x13}},
{AADCQ, yaddl, Pw, opBytes{0x83, 02, 0x15, 0x81, 02, 0x11, 0x13}},
{AADCW, yaddl, Pe, opBytes{0x83, 02, 0x15, 0x81, 02, 0x11, 0x13}},
{AADCXL, yml_rl, Pq4, opBytes{0xf6}},
{AADCXQ, yml_rl, Pq4w, opBytes{0xf6}},
{AADDB, yxorb, Pb, opBytes{0x04, 0x80, 00, 0x00, 0x02}},
{AADDL, yaddl, Px, opBytes{0x83, 00, 0x05, 0x81, 00, 0x01, 0x03}},
{AADDPD, yxm, Pq, opBytes{0x58}},
{AADDPS, yxm, Pm, opBytes{0x58}},
{AADDQ, yaddl, Pw, opBytes{0x83, 00, 0x05, 0x81, 00, 0x01, 0x03}},
{AADDSD, yxm, Pf2, opBytes{0x58}},
{AADDSS, yxm, Pf3, opBytes{0x58}},
{AADDSUBPD, yxm, Pq, opBytes{0xd0}},
{AADDSUBPS, yxm, Pf2, opBytes{0xd0}},
{AADDW, yaddl, Pe, opBytes{0x83, 00, 0x05, 0x81, 00, 0x01, 0x03}},
{AADOXL, yml_rl, Pq5, opBytes{0xf6}},
{AADOXQ, yml_rl, Pq5w, opBytes{0xf6}},
{AADJSP, nil, 0, opBytes{}},
{AANDB, yxorb, Pb, opBytes{0x24, 0x80, 04, 0x20, 0x22}},
{AANDL, yaddl, Px, opBytes{0x83, 04, 0x25, 0x81, 04, 0x21, 0x23}},
{AANDNPD, yxm, Pq, opBytes{0x55}},
{AANDNPS, yxm, Pm, opBytes{0x55}},
{AANDPD, yxm, Pq, opBytes{0x54}},
{AANDPS, yxm, Pm, opBytes{0x54}},
{AANDQ, yaddl, Pw, opBytes{0x83, 04, 0x25, 0x81, 04, 0x21, 0x23}},
{AANDW, yaddl, Pe, opBytes{0x83, 04, 0x25, 0x81, 04, 0x21, 0x23}},
{AARPL, yrl_ml, P32, opBytes{0x63}},
{ABOUNDL, yrl_m, P32, opBytes{0x62}},
{ABOUNDW, yrl_m, Pe, opBytes{0x62}},
{ABSFL, yml_rl, Pm, opBytes{0xbc}},
{ABSFQ, yml_rl, Pw, opBytes{0x0f, 0xbc}},
{ABSFW, yml_rl, Pq, opBytes{0xbc}},
{ABSRL, yml_rl, Pm, opBytes{0xbd}},
{ABSRQ, yml_rl, Pw, opBytes{0x0f, 0xbd}},
{ABSRW, yml_rl, Pq, opBytes{0xbd}},
{ABSWAPW, ybswap, Pe, opBytes{0x0f, 0xc8}},
{ABSWAPL, ybswap, Px, opBytes{0x0f, 0xc8}},
{ABSWAPQ, ybswap, Pw, opBytes{0x0f, 0xc8}},
{ABTCL, ybtl, Pm, opBytes{0xba, 07, 0xbb}},
{ABTCQ, ybtl, Pw, opBytes{0x0f, 0xba, 07, 0x0f, 0xbb}},
{ABTCW, ybtl, Pq, opBytes{0xba, 07, 0xbb}},
{ABTL, ybtl, Pm, opBytes{0xba, 04, 0xa3}},
{ABTQ, ybtl, Pw, opBytes{0x0f, 0xba, 04, 0x0f, 0xa3}},
{ABTRL, ybtl, Pm, opBytes{0xba, 06, 0xb3}},
{ABTRQ, ybtl, Pw, opBytes{0x0f, 0xba, 06, 0x0f, 0xb3}},
{ABTRW, ybtl, Pq, opBytes{0xba, 06, 0xb3}},
{ABTSL, ybtl, Pm, opBytes{0xba, 05, 0xab}},
{ABTSQ, ybtl, Pw, opBytes{0x0f, 0xba, 05, 0x0f, 0xab}},
{ABTSW, ybtl, Pq, opBytes{0xba, 05, 0xab}},
{ABTW, ybtl, Pq, opBytes{0xba, 04, 0xa3}},
{ABYTE, ybyte, Px, opBytes{1}},
{obj.ACALL, ycall, Px, opBytes{0xff, 02, 0xff, 0x15, 0xe8}},
{ACBW, ynone, Pe, opBytes{0x98}},
{ACDQ, ynone, Px, opBytes{0x99}},
{ACDQE, ynone, Pw, opBytes{0x98}},
{ACLAC, ynone, Pm, opBytes{01, 0xca}},
{ACLC, ynone, Px, opBytes{0xf8}},
{ACLD, ynone, Px, opBytes{0xfc}},
{ACLFLUSH, yclflush, Pm, opBytes{0xae, 07}},
{ACLFLUSHOPT, yclflush, Pq, opBytes{0xae, 07}},
{ACLI, ynone, Px, opBytes{0xfa}},
{ACLTS, ynone, Pm, opBytes{0x06}},
{ACMC, ynone, Px, opBytes{0xf5}},
{ACMOVLCC, yml_rl, Pm, opBytes{0x43}},
{ACMOVLCS, yml_rl, Pm, opBytes{0x42}},
{ACMOVLEQ, yml_rl, Pm, opBytes{0x44}},
{ACMOVLGE, yml_rl, Pm, opBytes{0x4d}},
{ACMOVLGT, yml_rl, Pm, opBytes{0x4f}},
{ACMOVLHI, yml_rl, Pm, opBytes{0x47}},
{ACMOVLLE, yml_rl, Pm, opBytes{0x4e}},
{ACMOVLLS, yml_rl, Pm, opBytes{0x46}},
{ACMOVLLT, yml_rl, Pm, opBytes{0x4c}},