This repository has been archived by the owner on Nov 20, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathfjitdef.h
7451 lines (6872 loc) · 301 KB
/
fjitdef.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// ==++==
//
//
// Copyright (c) 2006 Microsoft Corporation. All rights reserved.
//
// The use and distribution terms for this software are contained in the file
// named license.txt, which can be found in the root of this distribution.
// By using this software in any fashion, you are agreeing to be bound by the
// terms of this license.
//
// You must not remove this notice, or any other, from this software.
//
//
// ==--==
/***************************************************************************/
/* fjitdef.h */
/***************************************************************************/
/* Defines the code generators and helpers for the fast jit in a platform
and chip neutral way. It is also 32 and 64 bit neutral. */
/* This file implements all of the opcodes via helper calls with the exception'
of the call/return/jmps and direct stack manipulations */
/* a chip specific file can redefine any macros directly. For an example of
this see the file x86fit.h */
/* The top of stack may or may not be enregistered. The macros
enregisterTOS and deregisterTOS dynamically move and track the
TOS. */
/*
*/
/***************************************************************************/
#ifndef FJITDEF_H
#define FJITDEF_H
#include <float.h> // for _isnan
/***************************************************************************
The following macros are used in the JIT but either no high level
implementation is provided or they are redefined in terms of another macro
***************************************************************************/
/* push/load result */
#define emit_pushresult_U4() emit_pushresult_I4()
#define emit_pushresult_U8() emit_pushresult_I8()
#define emit_loadresult_U4() emit_loadresult_I4()
#define emit_loadresult_U8() emit_loadresult_I8()
/* call/return */
#define emit_ret(argsSize, restoreAddr) ret(argsSize, restoreAddr)
#define emit_call_abs_address(absAddress, adj) call_abs_address(absAddress, adj)
/* stack operations */
#define emit_POP_R4() emit_POP_I4()
#define emit_POP_R8() emit_POP_I8()
#define emit_DUP_R4() emit_DUP_I8() // since R4 is always promoted to R8 on the stack
#define emit_DUP_R8() emit_DUP_I8()
/* relative jumps and misc*/
#define emit_jmp_abs_address(cond, absAddress, adj) jmp_abs_address(cond, absAddress, adj)
#define emit_read_address(iStart,address, errorCode) read_address(iStart, address, errorCode)
#define emit_patch_address(iStart, absAddress, sIP, errorCode) patch_address(iStart, absAddress, sIP, errorCode)
/***************************************************************************
The following macros must be defined for each chip.
These consist of call/return and direct stack manipulations
***************************************************************************/
#if defined(_X86_) // Defines for the X86 platform
/**************************************************************************
define the calling convention for calling internal helpers
**************************************************************************/
/* macros used to implement helper calls */
#define NUMBER_ARGUMENT_REGISTERS 2
#define INTERNAL_CALL false
#define EXTERNAL_CALL true
#define HELPER_CALL __stdcall
#define CALLER_CLEANS_STACK false
/**************************************************************************
define abstract condition codes in terms of native machine condition codes
**************************************************************************/
#define CEE_CondBelow x86CondBelow
#define CEE_CondAboveEq x86CondAboveEq
#define CEE_CondEq x86CondEq
#define CEE_CondNotEq x86CondNotEq
#define CEE_CondBelowEq x86CondBelowEq
#define CEE_CondAbove x86CondAbove
#define CEE_CondLt x86CondLt
#define CEE_CondGtEq x86CondGtEq
#define CEE_CondLtEq x86CondLtEq
#define CEE_CondGt x86CondGt
#define CEE_CondAlways x86CondAlways
#define CondNonZero x86CondNotEq
#define CondZero x86CondEq
/**************************************************************************
define abstract registers in terms of native machine registers
**************************************************************************/
#define SIZE_ARGUMENT_REGISTER 4
#define SP X86_ESP // Stack pointer used to access the evaluation stack
#define FP X86_EBP // Frame pointer used to access the local variables and arguments
// Argument registers used to pass arguments
#define ARG_1 X86_ECX
#define ARG_2 X86_EDX
#define ARG_3 X86_EDI // Never used but needs to be defined for macro expension
#define ARG_4 X86_EDI // Never used but needs to be defined for macro expension
#define ARG_5 X86_EDI // Never used but needs to be defined for macro expension
// Callee saved registers that can be used to store values across calls
#define CALLEE_SAVED_1 X86_ESI
#define CALLEE_SAVED_2 X86_EDI
#define TOS_REG_1 X86_EAX
// Result registers in which the value of the function is returned
#define RESULT_1 X86_EAX // this should be the same as TOS_REG_1 on X86
#define RESULT_2 X86_EDX // this cannot be the same as ARG_1
#define RESULT_1_OUT RESULT_1 // The values are returned and recieved in the same registeres on x86
#define RESULT_2_OUT RESULT_2
// Indirect call register
#define CALLREG X86_EAX // register via which indirect calls should be made
#define ZEROREG X86_EAX // register that always reads 'zero' ( not used on x86 )
/**************************************************************************
define macros used by high level macros to their native implementation
**************************************************************************/
#define push_register(r, slot) x86_push(r)
#define pop_register(r, slot) x86_pop(r)
#define mov_register(r1,r2) x86_mov_reg(x86DirTo,x86Big,x86_mod_reg(r1,r2))
#define mov_register_indirect_to(r1,r2) load_indirect_dword_signextend(r1,r2,true)
#define mov_register_indirect_from(r1,r2) store_indirect_32bits(r1,r2,true)
#define mov_constant(r,c) x86_mov_reg_imm(x86Big,r,(unsigned int)c)
#define load_indirect_byte_signextend(r1,r2) x86_movsx(x86Byte,x86_mod_ind(r1,r2))
#define load_indirect_byte_zeroextend(r1,r2) x86_movzx(x86Byte,x86_mod_ind(r1,r2))
#define load_indirect_word_signextend(r1,r2,align) x86_movsx(x86Big,x86_mod_ind(r1,r2))
#define load_indirect_word_zeroextend(r1,r2,align) x86_movzx(x86Big,x86_mod_ind(r1,r2))
#define load_indirect_dword_signextend(r1,r2,align) x86_mov_reg(x86DirTo,x86Big,x86_mod_ind(r1,r2))
#define load_indirect_dword_zeroextend(r1,r2,align) x86_mov_reg(x86DirTo,x86Big,x86_mod_ind(r1,r2))
#define load_single( reg, offset ) { _ASSERTE(false); }
#define load_double( reg, offset ) { _ASSERTE(false); }
#define store_indirect_8bits(r1,r2) x86_mov_reg(x86DirFrom,x86Byte,x86_mod_ind(r1,r2))
#define store_indirect_16bits(r1,r2,align) x86_16bit(x86_mov_reg(x86DirFrom,x86Big,x86_mod_ind(r1,r2)))
#define store_indirect_32bits(r1,r2,align) x86_mov_reg(x86DirFrom,x86Big,x86_mod_ind(r1,r2))
#define store_gp_arg(a_size, num, s_size) x86_store_gp_arg(a_size, num, s_size)
#define store_float_arg(a_size, num, g_num, s_size) { _ASSERTE(false); num++; }
#define restore_gp_arg(a_size, num, s_size) x86_restore_gp_arg(a_size, num, s_size)
#define restore_float_arg(a_size, num, g_num, s_size) { _ASSERTE(false); num++; }
#define move_unaligned_arg(src, dst) { _ASSERTE(false); }
#define add_constant(r,c) if ((unsigned)c < 128) {x86_barith_imm(x86OpAdd,x86Big,x86Extend,r,c); } \
else {x86_barith_imm(x86OpAdd,x86Big,x86NoExtend,r,c); }
#define and_constant(r,c) if (c < 128) {x86_barith_imm(x86OpAnd,x86Big,x86Extend,r,c); } \
else {x86_barith_imm(x86OpAnd,x86Big,x86NoExtend,r,c); }
#define sub_register(r1,r2) x86_barith(x86OpSub, x86Big, x86_mod_reg(r1,r2))
#define compare_register(r1,r2,cond) x86_barith(x86OpCmp,x86Big,x86_mod_reg(r1,r2))
#define and_register(r1,r2,cr) x86_test(x86Big, x86_mod_reg(r1, r2))
#define mult_power_of_2(r,c) x86_shift_imm(x86ShiftLeft,r,c)
#define div_power_of_2(r,c) x86_shift_imm(x86ShiftRight,r,c)
#define setup_frame() x86_setup_frame()
#define restore_frame(hasRetBuff,resetupFrame) x86_restore_frame()
#define emit_call_frame(n) grow(n, false)
#define call_frame_size(args, enreg) (args - enreg)
#define ret(x, restoreAddr) x86_ret(x)
#define emit_restore_state() {x86_mov_reg(x86DirTo, x86Big, x86_mod_ind_disp(X86_ESI, X86_EBP, \
0-sizeof(void*)));}
#define save_return_address() {} // call instruction always saves ret. address on stack
#define restore_return_address() {} // ret instruction reads ret. address from the stack
#define call_register(r) x86_call_reg(r)
#define call_abs_address(absAddress, adj) x86_call_abs_address(absAddress, adj)
#define mark_retbuff_callsite(size) { _ASSERTE(false); }
#define jmp_register(r,preserveRetAddr) x86_jmp_reg(r)
#define jmp_abs_address(cond, absAddress, adj) x86_jmp_abs_address(cond, absAddress, adj)
#define read_address(iStart,address,errorCode) x86_read_address(iStart, address)
#define patch_address(iStart, absAddress, sIP, errorCode) x86_patch_address(iStart, absAddress)
#define emit_istream_arg(arg_size,arg_ptr,reg) x86_emit_istream_arg( arg_size, arg_ptr, reg )
#define emit_break() x86_break()
#define nop() x86_nop()
#define emit_il_nop() x86_cld() // we use cld for a nop since the native nop is used for seq. points
#define emit_SWITCH(limit) x86_SWITCH(limit)
#define emit_call_memory_indirect(c, retBuff) x86_call_memory_indirect(c)
#define emit_conv_R4toR8 x86_emit_conv_R4toR8
#define emit_conv_R8toR4 x86_emit_conv_R8toR4
#define emit_narrow_R8toR4 x86_narrow_R8toR4
#define emit_pushresult_R4() x86_pushresult_R4
#define emit_pushresult_R8() x86_pushresult_R8
#define emit_loadresult_R4() x86_emit_loadresult_R4()
#define emit_loadresult_R8() x86_emit_loadresult_R8()
#define emit_relocate_retval_filter()
#define emit_store_toc_reg(helper)
#define emit_restore_toc_reg(helper)
#include "i386/x86fjit.h"
#elif defined(_PPC_) // defined for the PowerPC platform
/**************************************************************************
define the calling convention for calling internal helpers
**************************************************************************/
#define NUMBER_ARGUMENT_REGISTERS 8
#define INTERNAL_CALL true
#define EXTERNAL_CALL true
#define HELPER_CALL
//#define CALLER_CLEANS_STACK false
/**************************************************************************
define abstract condition codes in terms of native machine condition codes
**************************************************************************/
#define CEE_CondBelow ppcCondBelow
#define CEE_CondAboveEq ppcCondAboveEq
#define CEE_CondEq ppcCondEq
#define CEE_CondNotEq ppcCondNotEq
#define CEE_CondBelowEq ppcCondBelowEq
#define CEE_CondAbove ppcCondAbove
#define CEE_CondLt ppcCondLt
#define CEE_CondGtEq ppcCondGtEq
#define CEE_CondLtEq ppcCondLtEq
#define CEE_CondGt ppcCondGt
#define CEE_CondAlways ppcCondAlways
#define CondNonZero ppcCondNotEq
#define CondZero ppcCondEq
/**************************************************************************
define abstract registers in terms of native machine registers
**************************************************************************/
#define SIZE_ARGUMENT_REGISTER 4
#define SP R1 // Stack pointer used to access the evaluation stack
#define FP R30 // Frame pointer used to access the local variables and arguments
// Argument registers used to pass arguments
#define ARG_1 R3
#define ARG_2 R4
#define ARG_3 R5
#define ARG_4 R6
#define ARG_5 R7
// Callee saved registers that can be used to store values across calls
#define CALLEE_SAVED_1 R29
#define CALLEE_SAVED_2 R31
#define TOS_REG_1 R11
// Result registers in which the value of the function is returned
#define RESULT_1 R3
#define RESULT_2 R4 // this cannot be the same as ARG_1
#define RESULT_1_OUT RESULT_1 // The values are returned and recieved in the same registeres on PPC
#define RESULT_2_OUT RESULT_2
// Indirect call register
#define CALLREG R12 // register via which indirect calls should be made
#define ZEROREG R0 // register that always reads 'zero' ( not used on PPC )
/**************************************************************************
define macros used by high level macros to their native implementation
**************************************************************************/
#define push_register(r, slot) ppc_stwu(r, R1, -4) /* stwu reg, -4(r1) */
#define pop_register(r, slot) { ppc_lwz(r, R1, 0); ppc_addi( R1, R1, 4 ) } /* ldw reg, 0(r1), addi r1, 4 */
#define mov_register(r1,r2) ppc_or( r1, r2, r2, 0 ) /* or reg1, reg2, reg2 */
#define mov_register_indirect_to(r1,r2) load_indirect_dword_signextend(r1,r2,true)
#define mov_register_indirect_from(r1,r2) store_indirect_32bits(r1,r2,true)
#define mov_constant(r,c) ppc_move_constant(r,c)
#define load_indirect_byte_signextend(r1,r2) { ppc_lbz(r1, r2, 0); ppc_extsb(r1, r1, 0) }/* lbz reg1,0(reg2);extsb r1,r1*/
#define load_indirect_byte_zeroextend(r1,r2) ppc_lbz(r1, r2, 0) /* lbz reg1,0(reg2) */
#define load_indirect_word_signextend(r1,r2,align) ppc_lha(r1, r2, 0) /* lha reg1,0(reg2) */
#define load_indirect_word_zeroextend(r1,r2,align) ppc_lhz(r1, r2, 0) /* lhz reg1,0(reg2) */
#define load_indirect_dword_signextend(r1,r2,align) ppc_lwz(r1, r2, 0) /* ldw reg1,0(reg2) */
#define load_indirect_dword_zeroextend(r1,r2,align) ppc_lwz(r1, r2, 0) /* ldw reg1,0(reg2) */
#define load_single( reg, offset ) { ppc_lfs( argFloatRegistersMap[reg], R1, offset ) }
#define load_double( reg, offset ) { ppc_lfd( argFloatRegistersMap[reg], R1, offset ) }
#define store_indirect_8bits(r1,r2) ppc_stb(r1, r2, 0) /* stb reg1,0(reg2) */
#define store_indirect_16bits(r1,r2,align) ppc_sth(r1, r2, 0) /* sth reg1,0(reg2) */
#define store_indirect_32bits(r1,r2,align) ppc_stw(r1, r2, 0) /* stw reg1, 0(reg2) */
#define store_gp_arg(a_size, num, s_size) ppc_store_gp_arg(a_size, num, s_size)
#define store_float_arg(a_size, num, g_num, s_size) ppc_store_float_arg(a_size, num, g_num, s_size)
#define restore_gp_arg(a_size, num, s_size) ppc_restore_gp_arg(a_size, num, s_size)
#define restore_float_arg(a_size, num, g_num, s_size) ppc_restore_float_arg(a_size, num, g_num, s_size)
#define move_unaligned_arg(src, dst) { _ASSERTE(false); }
#define sub_register(r1,r2) ppc_subf(r1, r2, r1, 0, 0)
#define compare_register(r1,r2,cond) ppc_compare_register(r1,r2,cond)
#define and_register(r1,r2,c) {if (!c) ppc_and(r1, r1, r2, 0) else ppc_and(r1, r1, r2, 1)}
#define mult_power_of_2(r,c) _ASSERTE(c < 0x1F && r != R0); ppc_addi( R0, R0, c & 0x1F); \
ppc_slw(r, r, R0, 0)
#define div_power_of_2(r,c) _ASSERTE(c < 0x1F && r != R0); ppc_addi( R0, R0, c & 0x1F); \
ppc_srw(r, r, R0, 0)
#define add_constant(r,c) ppc_add_constant(r, c)
#define and_constant(r,c) ppc_and_constant(r, c)
#define setup_frame() ppc_setup_frame()
#define restore_frame(hasRetBuff,resetupFrame) ppc_restore_frame(resetupFrame)
#define emit_call_frame(n) ppc_stwu(R30, R1, (((unsigned)(-(int)(n))) & 0xFFFF))
#define call_frame_size(args, enreg) (args + sizeof(prolog_frame))
#define mark_retbuff_callsite(size) ppc_oris(R0,R0,0)
#define ret(x, restoreAddr) ppc_ret(x, restoreAddr)
#define emit_restore_state() { if (mapInfo.savedIP) ppc_lwz(R29, R30, 0x4) }
#define save_return_address() { ppc_mfspr(R0, PPC_MOVE_LR); ppc_stwu(R0, R1, -4) }
#define restore_return_address() { ppc_lwz(R12, R1, 0); ppc_addi( R1, R1, 4 ); }
#define call_register(r) ppc_call_register(r)
#define jmp_register(r,preserveRetAddr) ppc_jmp_reg(r,preserveRetAddr)
#define call_abs_address(absAddress, adj) ppc_call_abs_address(absAddress, adj)
#define jmp_abs_address(cond, absAddress, adj) ppc_jmp_abs_address(cond, absAddress, adj)
#define read_address(iStart,address, errorCode) ppc_read_address(iStart, address, errorCode)
#define patch_address(iStart, absAddress, sIP, errorCode) ppc_patch_address(iStart, absAddress, sIP, errorCode)
#define emit_istream_arg(arg_size,arg_ptr,reg) ppc_emit_istream_arg( arg_size, arg_ptr, reg )
#define nop() ppc_nop()
#define emit_break() ppc_break()
#define emit_il_nop() ppc_cld()
#define emit_SWITCH(limit) ppc_SWITCH(limit)
#define emit_call_memory_indirect(c, retBuff) ppc_call_memory_indirect((unsigned)c)
#define emit_conv_R4toR8 ppc_emit_conv_R4toR8
#define emit_conv_R8toR4 ppc_emit_conv_R8toR4
#define emit_narrow_R8toR4(nativeOff,ilOff) ppc_narrow_R8toR4(nativeOff,ilOff)
#define emit_pushresult_R4() ppc_pushresult_R4()
#define emit_pushresult_R8() ppc_pushresult_R8()
#define emit_loadresult_R4() ppc_emit_loadresult_R4()
#define emit_loadresult_R8() ppc_emit_loadresult_R8()
#define emit_relocate_retval_filter()
#define emit_store_toc_reg(helper) ppc_emit_store_toc_reg(helper)
#define emit_restore_toc_reg(helper) ppc_emit_restore_toc_reg(helper)
#include "ppc/ppcfjit.h"
#else // could not recognize the platform
#error "Platform not supported"
#endif
#ifndef SCHAR_MAX
#define SCHAR_MAX 127.0 // Maximum signed char value
#define SCHAR_MIN -128.0 // Minimum signed char value
#define UCHAR_MAX 255.0 //Maximum unsigned char value
#define USHRT_MAX 65535.0 //Maximum unsigned short value
#define SHRT_MAX 32767.0 //Maximum (signed) short value
#define SHRT_MIN -32768 //Minimum (signed) short value
#define UINT_MAX 4294967295.0 //Maximum unsigned int value
#define INT_MAX 2147483647.0 // Maximum (signed) int value
#define INT_MIN -2147483648.0 // Minimum (unsigned) int value
#endif
/*******************************************************************************/
#ifndef emit_conv_R4toR
#define emit_conv_R4toR() { emit_conv_R4toR8() }
#endif
#ifndef emit_conv_R8toR
#define emit_conv_R8toR() { } /* nop */
#endif
#ifndef emit_conv_RtoR4
#define emit_conv_RtoR4() { emit_conv_R8toR4() }
#endif
#ifndef emit_conv_RtoR8
#define emit_conv_RtoR8() { } /* nop */
#endif
/************************************************************************************
Macros for manipulating top of stack (TOS). TOS is normally stored in a register
defined as TOS_REG_1.
*************************************************************************************/
#ifndef deregisterTOS
#define deregisterTOS \
{ \
if (inRegTOS) \
push_register(TOS_REG_1, true); \
inRegTOS = false; \
}
#endif // deregisterTOS
#ifndef enregisterTOS
#define enregisterTOS \
if (!inRegTOS) \
{ pop_register(TOS_REG_1, true); } \
inRegTOS = true;
#endif // enregisterTOS
#ifndef emit_mov_TOS_reg
#define emit_mov_TOS_reg(reg) \
{ \
if (inRegTOS) { \
mov_register(reg,TOS_REG_1); \
inRegTOS = false; \
} \
else { \
pop_register(reg, true); \
} \
}
#endif // !emit_mov_TOS_reg
#ifndef emit_mov_reg_TOS
#define emit_mov_reg_TOS(reg) \
{ \
if (inRegTOS) { \
push_register(TOS_REG_1, true); \
} \
mov_register(TOS_REG_1, reg); \
inRegTOS = true; \
}
#endif // !emit_reg_TOS
/*
emit_save_TOS copies the TOS to a save area in the frame or register but leaves
the current value on the TOS. emit_restore_TOS pushes the saved value onto the TOS.
Used for new obj, since constructors doesn't return the constructed object. Also used for
calli since the target address needs to come off the stack while building the call frame
*/
#define emit_save_TOS() \
{ \
if (inRegTOS) \
{ mov_register(CALLEE_SAVED_1,TOS_REG_1); } \
else \
{ pop_register(CALLEE_SAVED_1, true); \
push_register(CALLEE_SAVED_1, true); }; \
}
#define emit_restore_TOS() \
{ \
deregisterTOS; \
mov_register(TOS_REG_1,CALLEE_SAVED_1); \
inRegTOS = true; \
mov_constant(CALLEE_SAVED_1,0); \
}
#ifndef emit_pushconstant_4
#define emit_pushconstant_4(val) \
{ \
deregisterTOS; \
mov_constant(TOS_REG_1,val); \
inRegTOS = true; \
}
#endif // !emit_pushconstant_4
#ifndef emit_pushconstant_8
#define emit_pushconstant_8(val) \
{ \
int v1 = (int) ((val >> 32) & 0xffffffff); \
int v2 = (int) (val & 0xffffffff); \
deregisterTOS; \
if ( SIZE_STACK_SLOT < 8 ) \
{ \
emit_pushconstant_4((BIGENDIAN_MACHINE ? v2: v1)); \
deregisterTOS; \
emit_pushconstant_4((BIGENDIAN_MACHINE ? v1: v2)); \
inRegTOS = true; \
} \
else \
{ \
grow( SIZE_STACK_SLOT, false ); \
mov_register(TOS_REG_1,SP); \
if (STACK_BUFFER) add_constant(TOS_REG_1, (int)STACK_BUFFER); \
mov_constant(RESULT_1,(BIGENDIAN_MACHINE ? v1: v2)); \
mov_register_indirect_from(RESULT_1, TOS_REG_1); \
add_constant(TOS_REG_1, (sizeof(void *))); \
mov_constant(RESULT_1,(BIGENDIAN_MACHINE ? v2: v1)); \
mov_register_indirect_from(RESULT_1, TOS_REG_1); \
} \
}
#endif // !emit_pushconstant_8
#ifndef emit_pushconstant_Ptr
#define emit_pushconstant_Ptr(val)\
{ \
deregisterTOS; \
mov_constant(TOS_REG_1,val); \
inRegTOS = true; \
}
#endif // !emit_pushconstant_Ptr
/*************************************************************************************
call/return macros
*************************************************************************************/
#ifndef grow
#define grow(n,zeroInitialized) \
{ \
if (zeroInitialized) \
{ \
_ASSERTE(((n) % (SIZE_STACK_SLOT/sizeof(void *))) == 0); \
unsigned l_slots = (n) / (SIZE_STACK_SLOT/sizeof(void *));\
mov_constant(CALLEE_SAVED_1, (l_slots)); \
deregisterTOS; \
mov_constant(TOS_REG_1,0); \
unsigned char* label = outPtr; \
push_register(TOS_REG_1, false); \
add_constant(CALLEE_SAVED_1,(unsigned)(-1)); \
and_register(CALLEE_SAVED_1, CALLEE_SAVED_1, 1); \
jmp_abs_address(CondNonZero,label, true); \
} \
else \
{ \
_ASSERTE( ((n) % SIZE_STACK_SLOT == 0) ); \
unsigned temp_n = n; \
int temp_p = (int)(PAGE_SIZE-SIZE_STACK_SLOT); \
while ( temp_n >= PAGE_SIZE) \
{ \
add_constant(SP,-temp_p); \
/* touch allocated page */ \
push_register(TOS_REG_1, true); \
temp_n -= PAGE_SIZE; \
} \
if (temp_n) \
add_constant(SP,-(int)(temp_n)); \
} \
}
#endif // !grow
#ifndef emit_grow
#define emit_grow(n) grow(n,false)
#endif // !emit_grow
#ifndef emit_drop
#define emit_drop(n) \
{ \
if (n) \
{ \
_ASSERTE((n) % SIZE_STACK_SLOT == 0); \
add_constant(SP,n); \
} \
}
#endif // !emit_drop
#ifndef emit_prolog
#define emit_prolog(locals) \
{ \
setup_frame(); \
storeEnregisteredArguments(); \
ON_X86_ONLY(if (locals)) \
grow(locals ON_PPC_ONLY(+1) ON_SPARC_ONLY(+1),true); /*zero initialized */ \
if ( ALIGN_ARGS ) \
alignArguments(); \
}
#endif // !emit_prolog
// check to see that the stack is not corrupted only in debug code
#ifdef _DEBUG
#define emit_stack_check(localWords) \
{ \
_ASSERTE( !inRegTOS ); \
callInfo.reset(); \
emit_reg_arg( SP, 3, INTERNAL_CALL); /*push_register(SP); */ \
emit_reg_arg( FP, 2, INTERNAL_CALL); /*push_register(FP); */ \
emit_arg( sizeof(prolog_data) + (localWords)*sizeof(void*) + STACK_BUFFER, 1, INTERNAL_CALL ); \
emit_callhelper_I4I4I4(check_stack); \
}
#ifdef DECLARE_HELPERS
void HELPER_CALL check_stack(int frameSize, BYTE* fp, BYTE* sp) {
if (sp + frameSize != fp)
_ASSERTE(!"ESP not correct on method exit. Did you forget a leave?");
}
#endif // DECLARE_HELPERS
#else // !_DEBUG
#define emit_stack_check(zeroCnt)
#endif // _DEBUG
#ifndef emit_return
#define emit_return(argsSize, hasRetBuff) \
{ \
restore_frame(hasRetBuff,false); \
ret(argsSize, false); \
}
#endif // !emit_return
#ifndef emit_jmp_absolute
#define emit_jmp_absolute(address) \
{ \
mov_constant(CALLREG,address); \
jmp_register(CALLREG, true); \
}
#endif // !emit_jmp_absolute
#ifndef emit_compute_virtaddress
#define emit_compute_virtaddress(vt_offset, sizeRetBuff) \
{ deregisterTOS; \
mov_register_indirect_to(TOS_REG_1, \
(ReturnBufferFirst && sizeRetBuff) ? ARG_2 : ARG_1); \
add_constant(TOS_REG_1,vt_offset); \
mov_register_indirect_to(TOS_REG_1,TOS_REG_1); \
push_register(TOS_REG_1, true); \
_ASSERTE(inRegTOS == false); \
}
#endif // !emit_compute_virtaddress
#ifndef emit_callvirt
#define emit_callvirt(vt_offset, sizeRetBuff) \
{ \
_ASSERTE( CALLREG != TOS_REG_1 || !inRegTOS ); \
mov_register_indirect_to(CALLREG, \
(ReturnBufferFirst && sizeRetBuff) ? ARG_2 : ARG_1); \
add_constant(CALLREG,vt_offset); \
mov_register_indirect_to(CALLREG,CALLREG); \
call_register(CALLREG); \
if (M_RETBUFF_CALLSITE && sizeRetBuff ) \
mark_retbuff_callsite(sizeRetBuff) \
}
#endif // !emit_callvirt
#ifndef emit_check_null_reference
#define emit_check_null_reference(testTOS) \
{ \
if (testTOS) \
{ \
enregisterTOS; \
load_indirect_byte_signextend(ARG_1,TOS_REG_1); \
} \
else \
load_indirect_byte_signextend(TOS_REG_1,ARG_1); \
}
#endif // !emit_check_this_null_reference
// The EE can demand that some calls use a helper function to find the method to call.
// The first argument to the helper function is the run-time type.
// We get this by dereferencing the object pointer.
// The second argument is the handle of the parent of the method.
// (i.e. the class of the method.) This is the argument to the macro.
// The third argument is the method descriptor for the static type
// (i.e.possibly a superclass).
#ifndef emit_ldvirtftn_helper
#define emit_ldvirtftn_helper(memberRef, parentToken) \
{\
CORINFO_CLASS_HANDLE tokenType;\
TokenToHandle(memberRef, tokenType); /* Push MethodHandle. */ \
TokenToHandle(parentToken, tokenType); /* Push ClassHandle. */ \
callInfo.reset();\
emit_tos_arg( 1, INTERNAL_CALL ); /* ClassHandle */ \
emit_tos_arg( 2, INTERNAL_CALL ); /* MethodHandle */ \
emit_tos_arg( 3, INTERNAL_CALL ); /* obj * */ \
emit_callhelper_I4I4I4_I4(ldvirtftn_helper);\
emit_pushresult_I4();\
}
#ifdef DECLARE_HELPERS
void* HELPER_CALL ldvirtftn_helper(void* classHandle, void* methodHandle, void* obj)
{
// reverse order of arguments and call the actual helper
return HCALL3(void*, FJit_pHlpGenericVirtual, void*, obj, void*, classHandle, void*, methodHandle);
}
#endif // DECLARE_HELPERS
#endif // !emit_ldvirtftn_helper
#ifndef emit_calli
#define emit_calli(sizeRetBuff) \
{ \
if ( CALLREG == TOS_REG_1 ) \
{enregisterTOS; } \
else \
emit_mov_TOS_reg( CALLREG ) \
call_register(CALLREG); \
if (M_RETBUFF_CALLSITE && sizeRetBuff ) \
mark_retbuff_callsite(sizeRetBuff) \
inRegTOS = false; \
}
#endif // !emit_calli
#ifndef emit_ldvtable_address
#define emit_ldvtable_address(hint, offset)\
{ \
_ASSERTE(inRegTOS); \
mov_register(ARG_1,TOS_REG_1); \
mov_constant(TOS_REG_1,hint); \
push_register(TOS_REG_1, true); \
mov_register_indirect_to(TOS_REG_1,TOS_REG_1); \
call_register(TOS_REG_1); \
add_constant(RESULT_1,offset); \
mov_register_indirect_to(TOS_REG_1,RESULT_1); \
inRegTOS = true; \
}
#endif // !emit_ldvtable_address
#ifndef emit_ldvtable_address_new
#define emit_ldvtable_address_new(interface_offset, vt_offset) \
{ \
_ASSERTE(inRegTOS); \
mov_register_indirect_to(TOS_REG_1,TOS_REG_1); \
add_constant(TOS_REG_1,offsetOfEEClass); \
mov_register_indirect_to(TOS_REG_1,TOS_REG_1); \
add_constant(TOS_REG_1,offsetOfInterfaceTable); \
mov_register_indirect_to(TOS_REG_1,TOS_REG_1); \
add_constant(TOS_REG_1,interface_offset); \
mov_register_indirect_to(TOS_REG_1,TOS_REG_1); \
add_constant(TOS_REG_1,vt_offset); \
mov_register_indirect_to(TOS_REG_1,TOS_REG_1); \
}
#endif // !emit_ldvtable_address_new
#ifndef emit_callinterface
#define emit_callinterface(vt_offset,hint, sizeRetBuff)\
{ \
mov_constant(TOS_REG_1,hint); \
push_register(TOS_REG_1, true); \
inRegTOS = false; \
mov_register_indirect_to(CALLREG, CALLREG); \
call_register(CALLREG); \
add_constant(RESULT_1,vt_offset); \
mov_register_indirect_to(CALLREG,RESULT_1); \
call_register(CALLREG); \
if (M_RETBUFF_CALLSITE && sizeRetBuff ) \
mark_retbuff_callsite(sizeRetBuff) \
}
#endif // !emit_callinterface
#ifndef emit_compute_interface_new
#define emit_compute_interface_new(interface_offset, vt_offset, sizeRetBuff) \
{ \
mov_register_indirect_to(TOS_REG_1, \
(ReturnBufferFirst && sizeRetBuff) ? ARG_2 : ARG_1); \
add_constant(TOS_REG_1,offsetOfEEClass); \
mov_register_indirect_to(TOS_REG_1,TOS_REG_1); \
add_constant(TOS_REG_1,offsetOfInterfaceTable); \
mov_register_indirect_to(TOS_REG_1,TOS_REG_1); \
add_constant(TOS_REG_1,interface_offset); \
mov_register_indirect_to(TOS_REG_1,TOS_REG_1); \
add_constant(TOS_REG_1,vt_offset); \
mov_register_indirect_to(TOS_REG_1,TOS_REG_1); \
push_register(TOS_REG_1, true); \
}
#endif // !emit_computed_interface_new
#ifndef emit_callinterface_new
#define emit_callinterface_new(interface_offset, vt_offset, sizeRetBuff) \
{ \
_ASSERTE( CALLREG != TOS_REG_1 || !inRegTOS ); \
mov_register_indirect_to(CALLREG, \
(ReturnBufferFirst && sizeRetBuff) ? ARG_2 : ARG_1); \
add_constant(CALLREG,offsetOfEEClass); \
mov_register_indirect_to(CALLREG,CALLREG); \
add_constant(CALLREG,offsetOfInterfaceTable); \
mov_register_indirect_to(CALLREG,CALLREG); \
add_constant(CALLREG,interface_offset); \
mov_register_indirect_to(CALLREG,CALLREG); \
add_constant(CALLREG,vt_offset); \
mov_register_indirect_to(CALLREG,CALLREG); \
call_register(CALLREG); \
if (M_RETBUFF_CALLSITE && sizeRetBuff ) \
mark_retbuff_callsite(sizeRetBuff) \
}
#endif // !emit_callinterface_new
#ifndef emit_callnonvirt
#define emit_callnonvirt(ftnptr, sizeRetBuff, indirect) \
{ \
_ASSERTE( CALLREG != TOS_REG_1 || !inRegTOS );\
mov_constant(CALLREG,ftnptr); \
if (indirect) \
{ mov_register_indirect_to(CALLREG,CALLREG); } \
call_register(CALLREG); \
if (M_RETBUFF_CALLSITE && sizeRetBuff ) \
mark_retbuff_callsite(sizeRetBuff) \
}
#endif // !emit_callnonvirt
#ifndef emit_tail_call
#define emit_tail_call(sizeCaller, sizeTarget, Flags ) { \
emit_LDC_I(sizeCaller); \
emit_LDC_I(sizeTarget); \
emit_LDC_I(Flags); \
}
#endif // !emit_tail_call
#ifndef emit_call_stub
#define emit_call_stub( stubAddress ) \
{ \
_ASSERTE(!inRegTOS); /* TOS_REG is used for custom call conv */ \
if ( !NUMBER_ARGUMENT_REGISTERS ) \
{ mov_register_indirect_to(ARG_1, SP); } \
mov_register_indirect_to(TOS_REG_1, ARG_1); \
mov_constant(CALLREG, stubAddress); \
call_register(CALLREG); \
}
#endif // !emit_call_stub
#ifndef emit_set_zero
#define emit_set_zero(offset) \
{ \
_ASSERTE(!inRegTOS); /* I trash EAX */ \
mov_register(TOS_REG_1,SP); \
add_constant(TOS_REG_1,offset); \
if (!HASZEROREG) \
{ \
/* since this is going to be trashed*/ \
push_register(ARG_1, true); \
mov_constant(ARG_1,0); \
mov_register_indirect_from(ARG_1,TOS_REG_1); \
pop_register(ARG_1, true); /* restore */ \
} \
else \
{ \
mov_register_indirect_from(ZEROREG,TOS_REG_1); \
} \
}
#endif // !emit_set_zero
#ifndef emit_getSP
#define emit_getSP(n)\
{ \
deregisterTOS; \
mov_register(TOS_REG_1,SP); \
add_constant(TOS_REG_1,n); \
inRegTOS = true; \
}
#endif // !emit_getSP
#ifndef emit_storeTOS_in_JitGenerated_local
#define emit_storeTOS_in_JitGenerated_local(nestingLevel,isFilter) \
save_return_address(); \
mov_register(ARG_1,FP); \
add_constant(ARG_1,((int)prolog_bias+(int)sizeof(void*)*(JIT_GENERATED_LOCAL_NESTING_COUNTER-1))) ; \
mov_constant(ARG_2, nestingLevel); \
mov_register_indirect_from(ARG_2,ARG_1); \
mult_power_of_2(ARG_2, emit_WIN32(2) emit_WIN64(3) ); \
sub_register(ARG_1,ARG_2); \
if (isFilter) { \
mov_register(ARG_2,SP); \
add_constant(ARG_2, ((int)STACK_BUFFER +1)); \
mov_register_indirect_from(ARG_2,ARG_1); \
} \
else { \
if (STACK_BUFFER) \
{ \
mov_register(ARG_2,SP); \
add_constant(ARG_2, (int)STACK_BUFFER); \
mov_register_indirect_from(ARG_2,ARG_1); \
} else { \
mov_register_indirect_from(SP,ARG_1); \
} \
}
#endif
#ifndef emit_reset_storedTOS_in_JitGenerated_local
#define emit_reset_storedTOS_in_JitGenerated_local(ret_val) \
if (ret_val && ARG_1 == RESULT_1_OUT) \
push_register(ARG_1, true); \
mov_register(ARG_1,FP); \
add_constant(ARG_1,((int)prolog_bias+(int)sizeof(void*)*(JIT_GENERATED_LOCAL_NESTING_COUNTER-1))) ; \
mov_register_indirect_to(ARG_2,ARG_1); \
add_constant(ARG_2,-1); \
mov_register_indirect_from(ARG_2,ARG_1); \
mult_power_of_2(ARG_2, emit_WIN32(2) emit_WIN64(3) ); \
sub_register(ARG_1,ARG_2); \
mov_constant(ARG_2,0) ; \
add_constant(ARG_1,-(int)sizeof(void*)); \
mov_register_indirect_from(ARG_2,ARG_1); \
if (ret_val && ARG_1 == RESULT_1_OUT) \
pop_register(ARG_1, true); \
restore_return_address();
#endif
#ifndef emit_LOCALLOC
#define emit_LOCALLOC(initialized,EHcount) \
{ \
/* Get the size of the localloc into TOS_REG_1 */ \
enregisterTOS; \
and_register(TOS_REG_1,TOS_REG_1, 1); \
/* If the size is zero jump over the following loop */ \
BYTE* label_1 = outPtr; \
jmp_abs_address(CondZero, 0, false); \
/* Calculate the size in stack slots */ \
add_constant(TOS_REG_1, (SIZE_STACK_SLOT - 1) ); \
mov_register(ARG_1,TOS_REG_1); \
div_power_of_2(ARG_1, ( SIZE_STACK_SLOT == 4 ? 2 : 3 ) ); \
/* Loop for sizeInStackSlots pushing '0' */ \
mov_constant(TOS_REG_1,0); \
unsigned char* label = outPtr; \
push_register(TOS_REG_1, false); \
add_constant(ARG_1,-1); \
and_register(ARG_1, ARG_1, 1); \
jmp_abs_address(CondNonZero,label, true); \
/* Patch the jump address, since the loop size is now known */ \
FJitResult PatchResult = FJIT_OK; \
patch_address( label_1, outPtr, storedStartIP, PatchResult ); \
_ASSERTE( PatchResult == FJIT_OK ); \
/* also store the esp in the appropriate JitGenerated local slot, to support GC reporting */ \
mov_register(TOS_REG_1,FP); \
add_constant(TOS_REG_1,((int)prolog_bias+(int)sizeof(void*)*(JIT_GENERATED_LOCAL_LOCALLOC_OFFSET-1))) ; \
if (STACK_BUFFER) \
{ \
mov_register(ARG_2,SP); \
add_constant(ARG_2, (int)STACK_BUFFER); \
mov_register_indirect_from(ARG_2,TOS_REG_1); \
mov_register(TOS_REG_1, ARG_2); \
} else { \
mov_register_indirect_from(SP,TOS_REG_1); \
/* Put the pointer to the allocated register into TOS */ \
mov_register(TOS_REG_1,SP) ; \
} \
_ASSERTE( inRegTOS ); \
}
#endif
#ifndef emit_init_bytes
#define emit_init_bytes(num_of_bytes) \
{ \
callInfo.reset(); \
emit_arg(num_of_bytes, 1, INTERNAL_CALL); \
emit_tos_arg(2, INTERNAL_CALL); \
emit_callhelper_I4I4(InitBytes_helper); \
}
#ifdef DECLARE_HELPERS
void HELPER_CALL InitBytes_helper(const unsigned __int32 size, __int8 * dest)
{
if(dest == NULL) {
THROW_FROM_HELPER(CORINFO_NullReferenceException);
}
memset(dest,0,size);
}
#endif // DECLARE_HELPERS
#endif // !emit_init_bytes
#ifndef emit_copy_bytes
#define emit_copy_bytes(num_of_bytes,gcLayoutSize,gcLayout,unaligned) \
{ \
callInfo.reset(); \
emit_tos_arg(4, INTERNAL_CALL); \
emit_tos_arg(5, INTERNAL_CALL); \
emit_arg(((int)unaligned), 3, INTERNAL_CALL); \
emit_arg(num_of_bytes, 2, INTERNAL_CALL); \
deregisterTOS; \
emit_istream_arg(gcLayoutSize, gcLayout, ARG_1); \
emit_reg_to_arg(1, ARG_1, INTERNAL_CALL); \
emit_callhelper_I4I4I4I4I4(CopyBytes_helper); \
}
#endif // !emit_copy_bytes
// Helper macro to allow the interpter to unwind the stack
#ifndef INTEPRETER_ESCAPE
#define INTEPRETER_ESCAPE() \
volatile int x = 0; \
if(x != 0) return;
#endif
#ifdef DECLARE_HELPERS
void HELPER_CALL CopyBytes_helper(const unsigned char* gcLayout, unsigned __int32 size, __int32 unaligned, __int32 * src, __int32 * dest)
{
unsigned char mask = 1;
if((unsigned) dest <= sizeof(void*)) {
THROW_FROM_HELPER(CORINFO_NullReferenceException);
}
unsigned i;
for (i = 0; i < size/sizeof(void*); i++) {
if (gcLayout[i/8] & mask) {
__int32 val = unaligned == 0 ? *src : GET_UNALIGNED_32(src);
HCALL2(void, FJit_pHlpAssign_Ref, CORINFO_Object**, (CORINFO_Object**)dest, CORINFO_Object*, (CORINFO_Object*)val);
INTEPRETER_ESCAPE();
src++;
dest++;
}
else {
if ( unaligned == 0 )
*dest++ = *src++;
else
{
SET_UNALIGNED_32(dest, GET_UNALIGNED_32(src));
src++;
dest++;
}
}
if (mask == 0x80)
mask = 1;
else
mask <<= 1;
}
// all of the bits left in the byte should be zero (this insures we aren't pointing at trash).
_ASSERTE(mask == 1 || ((-mask) & gcLayout[i/8]) == 0);
// now copy any leftover bytes
{
unsigned char* _dest = (unsigned char*)dest;
unsigned char* _src = (unsigned char*)src;
unsigned int numBytes = size & 3;
for (i=0; i<numBytes;i++)
*_dest++ = *_src++;
}
}
#endif // DECLARE_HELPERS
#ifndef emit_DUP_PTR
#define emit_DUP_PTR()\
{ \
emit_WIN32(emit_DUP_I4()); \
emit_WIN64(emit_DUP_I8()); \
}
#endif // !emit_DUP_PTR
#ifndef emit_CPBLK
#define emit_CPBLK() \
{ \
callInfo.reset(); \
emit_tos_arg( 1, INTERNAL_CALL ); \
emit_tos_arg( 2, INTERNAL_CALL ); \
emit_tos_arg( 3, INTERNAL_CALL ); \