19
19
[Flambda_backend_flags] and shared variables.
20
20
For details, see [asmgen.mli]. *)
21
21
22
+ open ! Int_replace_polymorphic_compare
23
+
22
24
open Cmm
23
25
open Arch
24
26
open Proc
@@ -28,6 +30,7 @@ open Linear
28
30
open Emitaux
29
31
30
32
open X86_ast
33
+ open X86_ast_utils
31
34
open X86_proc
32
35
open X86_dsl
33
36
module String = Misc.Stdlib. String
@@ -42,6 +45,18 @@ open! Branch_relaxation
42
45
43
46
let _label s = D. label ~typ: QWORD s
44
47
48
+ let is_linux = function
49
+ | S_linux -> true
50
+ | _ -> false
51
+
52
+ let is_macosx = function
53
+ | S_macosx -> true
54
+ | _ -> false
55
+
56
+ let is_win64 = function
57
+ | S_win64 -> true
58
+ | _ -> false
59
+
45
60
(* Override proc.ml *)
46
61
47
62
let int_reg_name =
@@ -143,7 +158,7 @@ let pop r =
143
158
144
159
(* Symbols *)
145
160
146
- let symbol_prefix = if system = S_macosx then " _" else " "
161
+ let symbol_prefix = match system with S_macosx -> " _" | _ -> " "
147
162
148
163
let emit_symbol s = string_of_symbol symbol_prefix s
149
164
@@ -652,7 +667,7 @@ let emit_float_test (width : Cmm.float_width)
652
667
| Float32 -> I. ucomiss, I. comiss
653
668
in
654
669
match cmp with
655
- | CFeq when arg i 1 = arg i 0 ->
670
+ | CFeq when equal_arg ( arg i 1 ) ( arg i 0 ) ->
656
671
ucomi (arg i 1 ) (arg i 0 );
657
672
taken NP
658
673
| CFeq ->
@@ -661,7 +676,7 @@ let emit_float_test (width : Cmm.float_width)
661
676
I. jp (label next); (* skip if unordered *)
662
677
taken E ; (* branch taken if x=y *)
663
678
def_label next
664
- | CFneq when arg i 1 = arg i 0 ->
679
+ | CFneq when equal_arg ( arg i 1 ) ( arg i 0 ) ->
665
680
ucomi (arg i 1 ) (arg i 0 );
666
681
taken P
667
682
| CFneq ->
@@ -826,8 +841,8 @@ let move (src : Reg.t) (dst : Reg.t) =
826
841
end
827
842
828
843
let stack_to_stack_move (src : Reg.t ) (dst : Reg.t ) =
829
- assert (src.typ = dst.typ);
830
- if ( src.loc <> dst.loc) then begin
844
+ assert (Cmm. equal_machtype_component src.typ dst.typ);
845
+ if not ( Reg. equal_location src.loc dst.loc) then begin
831
846
match src.typ with
832
847
| Int | Val ->
833
848
(* Not calling move because r15 is not in int_reg_name. *)
@@ -1071,11 +1086,11 @@ end = struct
1071
1086
abstraction barrier of [X86_ast]. *)
1072
1087
let [@ inline always] uses_register register = function
1073
1088
| Reg8L register' | Reg16 register' | Reg32 register' | Reg64 register' ->
1074
- register = register'
1089
+ equal_reg64 register register'
1075
1090
| Mem { idx = register' ; base = None ; scale; _ } ->
1076
- scale <> 0 && register = register'
1091
+ scale <> 0 && equal_reg64 register register'
1077
1092
| Mem { idx = register' ; base = Some register'' ; _ } ->
1078
- register = register' || register = register''
1093
+ equal_reg64 register register' || equal_reg64 register register''
1079
1094
| _ -> false
1080
1095
;;
1081
1096
@@ -1339,7 +1354,7 @@ let emit_simd_instr op i =
1339
1354
| BMI2 Deposit_64 -> I. pdep (arg i 1 ) (arg i 0 ) (res i 0 )
1340
1355
| SSE Round_current_f32_i64 -> I. cvtss2si (arg i 0 ) (res i 0 )
1341
1356
| SSE Sqrt_scalar_f32 ->
1342
- if arg i 0 <> res i 0 then
1357
+ if not (equal_arg ( arg i 0 ) ( res i 0 )) then
1343
1358
I. xorpd (res i 0 ) (res i 0 ); (* avoid partial register stall *)
1344
1359
I. sqrtss (arg i 0 ) (res i 0 )
1345
1360
| SSE Max_scalar_f32 -> I. maxss (arg i 1 ) (res i 0 )
@@ -1364,7 +1379,7 @@ let emit_simd_instr op i =
1364
1379
| SSE2 Max_scalar_f64 -> I. maxsd (arg i 1 ) (res i 0 )
1365
1380
| SSE2 Min_scalar_f64 -> I. minsd (arg i 1 ) (res i 0 )
1366
1381
| SSE2 Sqrt_scalar_f64 ->
1367
- if arg i 0 <> res i 0 then
1382
+ if not (equal_arg ( arg i 0 ) ( res i 0 )) then
1368
1383
I. xorpd (res i 0 ) (res i 0 ); (* avoid partial register stall *)
1369
1384
I. sqrtsd (arg i 0 ) (res i 0 )
1370
1385
| SSE2 Sqrt_f64 -> I. sqrtpd (arg i 0 ) (res i 0 )
@@ -1522,11 +1537,11 @@ let emit_simd_instr op i =
1522
1537
| SSE41 Min_unsigned_i16 -> I. pminuw (arg i 1 ) (res i 0 )
1523
1538
| SSE41 Min_unsigned_i32 -> I. pminud (arg i 1 ) (res i 0 )
1524
1539
| SSE41 (Round_scalar_f64 n ) ->
1525
- if arg i 0 <> res i 0 then
1540
+ if not (equal_arg ( arg i 0 ) ( res i 0 )) then
1526
1541
I. xorpd (res i 0 ) (res i 0 ); (* avoid partial register stall *)
1527
1542
I. roundsd n (arg i 0 ) (res i 0 )
1528
1543
| SSE41 (Round_scalar_f32 n ) ->
1529
- if arg i 0 <> res i 0 then
1544
+ if not (equal_arg ( arg i 0 ) ( res i 0 )) then
1530
1545
I. xorpd (res i 0 ) (res i 0 ); (* avoid partial register stall *)
1531
1546
I. roundss n (arg i 0 ) (res i 0 )
1532
1547
| SSE41 (Round_f64 n ) -> I. roundpd n (arg i 0 ) (res i 0 )
@@ -1584,7 +1599,7 @@ let emit_instr ~first ~fallthrough i =
1584
1599
| Lop (Move | Spill | Reload ) ->
1585
1600
move i.arg.(0 ) i.res.(0 )
1586
1601
| Lop (Const_int n ) ->
1587
- if n = 0n then begin
1602
+ if Nativeint. equal n 0n then begin
1588
1603
match i.res.(0 ).loc with
1589
1604
| Reg _ ->
1590
1605
(* Clearing the bottom half also clears the top half (except for
@@ -1593,7 +1608,7 @@ let emit_instr ~first ~fallthrough i =
1593
1608
I. xor (res32 i 0 ) (res32 i 0 )
1594
1609
| _ ->
1595
1610
I. mov (int 0 ) (res i 0 )
1596
- end else if n > 0n && n < = 0xFFFF_FFFFn then begin
1611
+ end else if Nativeint. compare n 0n > 0 && Nativeint. compare n 0xFFFF_FFFFn < = 0 then begin
1597
1612
match i.res.(0 ).loc with
1598
1613
| Reg _ ->
1599
1614
(* Similarly, setting only the bottom half clears the top half. *)
@@ -1641,7 +1656,7 @@ let emit_instr ~first ~fallthrough i =
1641
1656
output_epilogue (fun () -> I. jmp (arg i 0 ))
1642
1657
| Lcall_op (Ltailcall_imm { func; } ) ->
1643
1658
begin
1644
- if func.sym_name = ! function_name then
1659
+ if String. equal func.sym_name ! function_name then
1645
1660
match ! tailrec_entry_point with
1646
1661
| None -> Misc. fatal_error " jump to missing tailrec entry point"
1647
1662
| Some tailrec_entry_point -> I. jmp (label tailrec_entry_point)
@@ -1664,7 +1679,7 @@ let emit_instr ~first ~fallthrough i =
1664
1679
load_symbol_addr (Cmm. global_symbol func) rax;
1665
1680
emit_call (Cmm. global_symbol " caml_c_call" );
1666
1681
record_frame i.live (Dbg_other i.dbg);
1667
- if not Config. runtime5 && system <> S_win64 then begin
1682
+ if not Config. runtime5 && not (is_win64 system) then begin
1668
1683
1669
1684
(* In amd64.S, "caml_c_call" tail-calls the C function (in order to
1670
1685
produce nicer backtraces), so we need to restore r15 manually after
@@ -1819,7 +1834,7 @@ let emit_instr ~first ~fallthrough i =
1819
1834
I. movzx al (res i 0 )
1820
1835
| Lop (Intop_imm (Iand, n )) when n > = 0 && n < = 0xFFFF_FFFF && Reg. is_reg i.res.(0 ) ->
1821
1836
I. and_ (int n) (res32 i 0 )
1822
- | Lop (Intop Ixor) when i.arg.(1 ).loc = i.res.(0 ).loc && Reg. is_reg i.res.(0 ) ->
1837
+ | Lop (Intop Ixor) when Reg. equal_location i.arg.(1 ).loc i.res.(0 ).loc && Reg. is_reg i.res.(0 ) ->
1823
1838
I. xor (res32 i 0 ) (res32 i 0 )
1824
1839
| Lop (Intop (Idiv | Imod )) ->
1825
1840
I. cqo () ;
@@ -1834,7 +1849,7 @@ let emit_instr ~first ~fallthrough i =
1834
1849
| Lop (Intop ((Iadd |Isub |Imul |Iand |Ior |Ixor ) as op )) ->
1835
1850
(* We have i.arg.(0) = i.res.(0) *)
1836
1851
instr_for_intop op (arg i 1 ) (res i 0 )
1837
- | Lop (Intop_imm(Iadd, n )) when i.arg.(0 ).loc <> i.res.(0 ).loc ->
1852
+ | Lop (Intop_imm(Iadd, n )) when not ( Reg. equal_location i.arg.(0 ).loc i.res.(0 ).loc) ->
1838
1853
I. lea (mem64 NONE n (arg64 i 0 )) (res i 0 )
1839
1854
| Lop (Intop_imm (Iadd , 1 ) | Intop_imm (Isub, -1 )) ->
1840
1855
I. inc (res i 0 )
@@ -1871,7 +1886,7 @@ let emit_instr ~first ~fallthrough i =
1871
1886
| Lop (Floatop (width , (Iaddf | Isubf | Imulf | Idivf as floatop ))) ->
1872
1887
instr_for_floatop width floatop (arg i 1 ) (res i 0 )
1873
1888
| Lop (Opaque) ->
1874
- assert (i.arg.(0 ).loc = i.res.(0 ).loc)
1889
+ assert (Reg. equal_location i.arg.(0 ).loc i.res.(0 ).loc)
1875
1890
| Lop (Specific(Ilea addr )) ->
1876
1891
I. lea (addressing addr NONE i 0 ) (res i 0 )
1877
1892
| Lop (Specific(Ioffset_loc(n , addr ))) ->
@@ -1964,7 +1979,7 @@ let emit_instr ~first ~fallthrough i =
1964
1979
I. mov rax (res i 0 );
1965
1980
I. or_ rdx (res i 0 ))
1966
1981
| Lop (Specific Irdpmc) ->
1967
- assert (arg64 i 0 = RCX );
1982
+ assert (equal_reg64 ( arg64 i 0 ) RCX );
1968
1983
I. rdpmc () ;
1969
1984
let rdx = Reg64 RDX in
1970
1985
(* The instruction fills in the low 32 bits of the result registers. *)
@@ -2096,7 +2111,7 @@ let emit_instr ~first ~fallthrough i =
2096
2111
can still be assigned to one of these two registers, so
2097
2112
we must be careful not to clobber it before use. *)
2098
2113
let (tmp1, tmp2) =
2099
- if i.arg.(0 ).loc = Reg 0 (* rax *)
2114
+ if Reg. equal_location i.arg.(0 ).loc ( Reg 0 ) (* rax *)
2100
2115
then (phys_rdx, phys_rax)
2101
2116
else (phys_rax, phys_rdx) in
2102
2117
@@ -2220,7 +2235,7 @@ let fundecl fundecl =
2220
2235
emit_function_or_basic_block_section_name () ;
2221
2236
D. align ~data: false 16 ;
2222
2237
add_def_symbol fundecl.fun_name;
2223
- if system = S_macosx
2238
+ if is_macosx system
2224
2239
&& not ! Clflags. output_c_object
2225
2240
&& is_generic_function fundecl.fun_name
2226
2241
then (* PR#4690 *)
@@ -2234,7 +2249,7 @@ let fundecl fundecl =
2234
2249
D. label (label_name (emit_symbol fundecl.fun_name));
2235
2250
emit_debug_info fundecl.fun_dbg;
2236
2251
cfi_startproc () ;
2237
- if Config. runtime5 && (not Config. no_stack_checks) && ! Clflags. runtime_variant = " d" then begin
2252
+ if Config. runtime5 && (not Config. no_stack_checks) && String. equal ! Clflags. runtime_variant " d" then begin
2238
2253
emit_call (Cmm. global_symbol " caml_assert_stack_invariants" );
2239
2254
end ;
2240
2255
emit_all ~first: true ~fallthrough: true fundecl.fun_body;
@@ -2314,7 +2329,7 @@ let begin_assembly unix =
2314
2329
Emitaux.Dwarf_helpers. begin_dwarf ~build_asm_directives ~code_begin ~code_end
2315
2330
~file_emitter: D. file;
2316
2331
2317
- if system = S_win64 then begin
2332
+ if is_win64 system then begin
2318
2333
D. extrn " caml_call_gc" NEAR ;
2319
2334
D. extrn " caml_c_call" NEAR ;
2320
2335
D. extrn " caml_allocN" NEAR ;
@@ -2355,7 +2370,7 @@ let begin_assembly unix =
2355
2370
2356
2371
emit_named_text_section code_begin;
2357
2372
emit_global_label_for_symbol code_begin;
2358
- if system = S_macosx then I. nop () ; (* PR#4690 *)
2373
+ if is_macosx system then I. nop () ; (* PR#4690 *)
2359
2374
2360
2375
D. label (emit_cmm_symbol call_gc_local_sym);
2361
2376
cfi_startproc () ;
@@ -2694,7 +2709,7 @@ let emit_trap_notes () =
2694
2709
end
2695
2710
2696
2711
let end_assembly () =
2697
- if ! float_constants <> [] then begin
2712
+ if not ( Misc.Stdlib.List. is_empty ! float_constants) then begin
2698
2713
begin match system with
2699
2714
| S_macosx -> D. section [" __TEXT" ;" __literal8" ] None [" 8byte_literals" ]
2700
2715
| S_mingw64 | S_cygwin -> D. section [" .rdata" ] (Some " dr" ) []
@@ -2704,7 +2719,7 @@ let end_assembly () =
2704
2719
D. align ~data: true 8 ;
2705
2720
List. iter (fun (cst ,lbl ) -> emit_float_constant cst lbl) ! float_constants;
2706
2721
end ;
2707
- if ! vec128_constants <> [] then begin
2722
+ if not ( Misc.Stdlib.List. is_empty ! vec128_constants) then begin
2708
2723
begin match system with
2709
2724
| S_macosx -> D. section [" __TEXT" ;" __literal16" ] None [" 16byte_literals" ]
2710
2725
| S_mingw64 | S_cygwin -> D. section [" .rdata" ] (Some " dr" ) []
@@ -2723,7 +2738,7 @@ let end_assembly () =
2723
2738
2724
2739
let code_end = Cmm_helpers. make_symbol " code_end" in
2725
2740
emit_named_text_section code_end;
2726
- if system = S_macosx then I. nop () ;
2741
+ if is_macosx system then I. nop () ;
2727
2742
(* suppress "ld warning: atom sorting error" *)
2728
2743
2729
2744
emit_global_label_for_symbol code_end;
@@ -2755,7 +2770,7 @@ let end_assembly () =
2755
2770
ConstSub (ConstLabel (emit_label lbl), ConstThis ),
2756
2771
const_32 ofs
2757
2772
) in
2758
- if system = S_macosx then begin
2773
+ if is_macosx system then begin
2759
2774
incr setcnt;
2760
2775
let s = Printf. sprintf " L$set$%d" ! setcnt in
2761
2776
D. setvar (s, c);
@@ -2767,20 +2782,22 @@ let end_assembly () =
2767
2782
efa_string = (fun s -> D. bytes (s ^ " \000 " ))
2768
2783
};
2769
2784
2770
- if system = S_linux || system = S_freebsd || system = S_netbsd || system = S_openbsd then begin
2785
+ begin match system with
2786
+ | S_linux | S_freebsd | S_netbsd | S_openbsd ->
2771
2787
let frametable = emit_symbol (Cmm_helpers. make_symbol " frametable" ) in
2772
2788
D. size frametable (ConstSub (ConstThis , ConstLabel frametable))
2789
+ | _ -> ()
2773
2790
end ;
2774
2791
2775
2792
D. data () ;
2776
2793
emit_probe_notes () ;
2777
2794
emit_trap_notes () ;
2778
2795
2779
- if system = S_linux then
2796
+ if is_linux system then
2780
2797
(* Mark stack as non-executable, PR#4564 *)
2781
2798
D. section [" .note.GNU-stack" ] (Some " " ) [ " %progbits" ];
2782
2799
2783
- if system = S_win64 then begin
2800
+ if is_win64 system then begin
2784
2801
D. comment " External functions" ;
2785
2802
String.Set. iter
2786
2803
(fun s ->
0 commit comments