@@ -964,7 +964,7 @@ let trans_visitor
964
964
lea base (fst (need_mem_cell data));
965
965
add elt (Il. Cell base) mul_idx;
966
966
emit (Il. binary Il. SUB diff (Il. Cell elt) (Il. Cell base));
967
- let jmp = trans_compare Il. JB (Il. Cell diff) (Il. Cell len) in
967
+ let jmp = trans_compare_simple Il. JB (Il. Cell diff) (Il. Cell len) in
968
968
trans_cond_fail " bounds check" jmp;
969
969
based elt_reg
970
970
@@ -1714,6 +1714,8 @@ let trans_visitor
1714
1714
in
1715
1715
get_typed_mem_glue g fty inner
1716
1716
1717
+ and get_cmp_glue _ = failwith " TODO"
1718
+
1717
1719
1718
1720
(* Glue functions use mostly the same calling convention as ordinary
1719
1721
* functions.
@@ -1821,18 +1823,88 @@ let trans_visitor
1821
1823
(Array. append [| ty_params_ptr |] args)
1822
1824
clo
1823
1825
1824
- (* trans_compare returns a quad number of the cjmp, which the caller
1825
- patches to the cjmp destination. *)
1826
- and trans_compare
1826
+ (* [trans_compare_full] returns the quad number of the cjmp, which the
1827
+ * caller patches to the cjmp destination.
1828
+ *
1829
+ * We assume that the LHS and RHS of the comparison have the same type, an
1830
+ * invariant that the typechecker enforces. *)
1831
+ and trans_compare_full
1832
+ ~cjmp :(cjmp :Il.jmpop )
1833
+ ~ty_params :(ty_params :Il.cell )
1834
+ ~ty :(ty :Ast.ty )
1835
+ ~curr_iso :(curr_iso :Ast.ty_iso option )
1836
+ (lhs :Il.cell )
1837
+ (rhs :Il.cell )
1838
+ : quad_idx list =
1839
+ let ty = strip_mutable_or_constrained_ty (maybe_iso curr_iso ty) in
1840
+ let (result:Il.cell ) = next_vreg_cell (Il. ValTy Il. Bits32 ) in
1841
+ begin
1842
+ match ty with
1843
+ Ast. TY_obj _ ->
1844
+ let lhs_binding = get_element_ptr lhs Abi. obj_field_body_box in
1845
+ let rhs_binding = get_element_ptr rhs Abi. obj_field_body_box in
1846
+ let lhs_box, rhs_box = deref lhs_binding, deref rhs_binding in
1847
+ let lhs_obj = get_element_ptr lhs_box Abi. box_rc_field_body in
1848
+ let rhs_obj = get_element_ptr rhs_box Abi. box_rc_field_body in
1849
+ let tydesc = get_element_ptr lhs_obj Abi. obj_body_elt_tydesc in
1850
+ let lhs_body = get_element_ptr lhs_obj Abi. obj_body_elt_fields in
1851
+ let rhs_body = get_element_ptr rhs_obj Abi. obj_body_elt_fields in
1852
+ trans_call_dynamic_glue
1853
+ tydesc
1854
+ Abi. tydesc_field_cmp_glue
1855
+ (Some result)
1856
+ [| alias lhs_body; alias rhs_body |]
1857
+ None
1858
+
1859
+ | Ast. TY_param (i , _ ) ->
1860
+ trans_call_simple_dynamic_glue
1861
+ i
1862
+ Abi. tydesc_field_cmp_glue
1863
+ ty_params
1864
+ [| alias lhs; alias rhs |]
1865
+ None
1866
+
1867
+ | _ ->
1868
+ trans_call_static_glue
1869
+ (code_fixup_to_ptr_operand (get_cmp_glue ty curr_iso))
1870
+ (Some result)
1871
+ [| lhs; rhs |]
1872
+ None
1873
+ end ;
1874
+ emit (Il. cmp (Il. Cell result) zero);
1875
+ let jmp = mark() in
1876
+ emit (Il. jmp cjmp Il. CodeNone );
1877
+ [ jmp ]
1878
+
1879
+ (* Like [trans_compare_full], returns the address of the jump, which the
1880
+ * caller patches to the destination. Only use this function if you are sure
1881
+ * that the LHS and RHS have the same type and that both will fit in a
1882
+ * machine register; otherwise, use [trans_compare] instead. *)
1883
+ and trans_compare_simple
1827
1884
(cjmp :Il.jmpop )
1828
1885
(lhs :Il.operand )
1829
1886
(rhs :Il.operand )
1830
1887
: quad_idx list =
1831
- (* FIXME: this is an x86-ism; abstract via ABI. *)
1832
1888
emit (Il. cmp (Il. Cell (Il. Reg (force_to_reg lhs))) rhs);
1833
1889
let jmp = mark() in
1834
- emit (Il. jmp cjmp Il. CodeNone );
1835
- [jmp]
1890
+ emit (Il. jmp cjmp Il. CodeNone );
1891
+ [ jmp ]
1892
+
1893
+ and trans_compare
1894
+ ?ty_params :(ty_params = get_ty_params_of_current_frame() )
1895
+ ~cjmp: (cjmp:Il.jmpop )
1896
+ ~ty: (ty:Ast.ty )
1897
+ ~curr_iso: (curr_iso:Ast.ty_iso option )
1898
+ (lhs:Il.operand )
1899
+ (rhs:Il.operand )
1900
+ : quad_idx list =
1901
+ ignore (trans_compare ~cjmp: cjmp ~ty: ty ~curr_iso: curr_iso lhs rhs);
1902
+ (* TODO *)
1903
+ match lhs, rhs with
1904
+ Il. Cell lhs , Il. Cell rhs ->
1905
+ trans_compare_full
1906
+ ~cjmp: cjmp ~ty_params: ty_params ~ty: ty ~curr_iso: curr_iso lhs rhs
1907
+ | _ -> trans_compare_simple cjmp lhs rhs
1836
1908
1837
1909
and trans_cond (invert :bool ) (expr :Ast.expr ) : quad_idx list =
1838
1910
@@ -1864,12 +1936,12 @@ let trans_visitor
1864
1936
cjmp
1865
1937
in
1866
1938
anno () ;
1867
- trans_compare cjmp' lhs rhs
1939
+ trans_compare_simple cjmp' lhs rhs
1868
1940
1869
1941
| _ ->
1870
1942
let bool_operand = trans_expr expr in
1871
1943
anno () ;
1872
- trans_compare Il. JNE bool_operand
1944
+ trans_compare_simple Il. JNE bool_operand
1873
1945
(if invert then imm_true else imm_false)
1874
1946
1875
1947
and trans_binop (binop :Ast.binop ) : Il.binop =
@@ -1915,7 +1987,7 @@ let trans_visitor
1915
1987
1916
1988
| _ -> let dst = Il. Reg (Il. next_vreg (emitter() ), Il. ValTy Il. Bits8 ) in
1917
1989
mov dst imm_true;
1918
- let jmps = trans_compare (binop_to_jmpop binop) lhs rhs in
1990
+ let jmps = trans_compare_simple (binop_to_jmpop binop) lhs rhs in
1919
1991
mov dst imm_false;
1920
1992
List. iter patch jmps;
1921
1993
Il. Cell dst
@@ -2330,7 +2402,7 @@ let trans_visitor
2330
2402
annotate (Printf. sprintf " tag case #%i == %a" i
2331
2403
Ast. sprintf_name key)));
2332
2404
let jmps =
2333
- trans_compare Il. JNE (Il. Cell tmp) (imm (Int64. of_int i))
2405
+ trans_compare_simple Il. JNE (Il. Cell tmp) (imm (Int64. of_int i))
2334
2406
in
2335
2407
let ttup = Hashtbl. find ttag key in
2336
2408
iter_tup_parts
@@ -2383,7 +2455,9 @@ let trans_visitor
2383
2455
mov ptr (Il. Cell lim);
2384
2456
add_to lim (Il. Cell len);
2385
2457
let back_jmp_target = mark () in
2386
- let fwd_jmps = trans_compare Il. JAE (Il. Cell ptr) (Il. Cell lim) in
2458
+ let fwd_jmps =
2459
+ trans_compare_simple Il. JAE (Il. Cell ptr) (Il. Cell lim)
2460
+ in
2387
2461
let unit_cell =
2388
2462
deref (ptr_cast ptr (referent_type abi unit_ty))
2389
2463
in
@@ -2737,9 +2811,7 @@ let trans_visitor
2737
2811
MEM_gc ->
2738
2812
let tmp = next_vreg_cell Il. voidptr_t in
2739
2813
trans_upcall " upcall_mark" tmp [| Il. Cell cell |];
2740
- let marked_jump =
2741
- trans_compare Il. JE (Il. Cell tmp) zero;
2742
- in
2814
+ let marked_jump = trans_compare_simple Il. JE (Il. Cell tmp) zero in
2743
2815
(* Iterate over box parts marking outgoing links. *)
2744
2816
let (body_mem, _) =
2745
2817
need_mem_cell
@@ -3455,7 +3527,7 @@ let trans_visitor
3455
3527
in
3456
3528
call_code (code_of_operand fn_ptr);
3457
3529
iflog (fun _ -> annotate " predicate check/fail" );
3458
- let jmp = trans_compare Il. JE (Il. Cell dst_cell) imm_true in
3530
+ let jmp = trans_compare_simple Il. JE (Il. Cell dst_cell) imm_true in
3459
3531
let errstr = Printf. sprintf " predicate check: %a"
3460
3532
Ast. sprintf_constr constr
3461
3533
in
@@ -3956,7 +4028,7 @@ let trans_visitor
3956
4028
let rec trans_pat pat src_cell src_ty =
3957
4029
match pat with
3958
4030
Ast. PAT_lit lit ->
3959
- trans_compare Il. JNE (trans_lit lit) (Il. Cell src_cell)
4031
+ trans_compare_simple Il. JNE (trans_lit lit) (Il. Cell src_cell)
3960
4032
3961
4033
| Ast. PAT_tag (lval , pats ) ->
3962
4034
let tag_name = tag_ctor_name_to_tag_name (lval_to_name lval) in
@@ -3980,7 +4052,7 @@ let trans_visitor
3980
4052
in
3981
4053
3982
4054
let next_jumps =
3983
- trans_compare Il. JNE
4055
+ trans_compare_simple Il. JNE
3984
4056
(Il. Cell tag_cell) (imm (Int64. of_int tag_number))
3985
4057
in
3986
4058
@@ -4233,12 +4305,13 @@ let trans_visitor
4233
4305
patch fwd_jmp;
4234
4306
check_interrupt_flag () ;
4235
4307
let back_jmp =
4236
- trans_compare Il. JB (Il. Cell dptr) (Il. Cell dlim) in
4237
- List. iter
4238
- (fun j -> patch_existing j back_jmp_targ) back_jmp;
4239
- let v = next_vreg_cell word_sty in
4240
- mov v (Il. Cell src_fill);
4241
- add_to dst_fill (Il. Cell v);
4308
+ trans_compare_simple Il. JB (Il. Cell dptr) (Il. Cell dlim)
4309
+ in
4310
+ List. iter
4311
+ (fun j -> patch_existing j back_jmp_targ) back_jmp;
4312
+ let v = next_vreg_cell word_sty in
4313
+ mov v (Il. Cell src_fill);
4314
+ add_to dst_fill (Il. Cell v);
4242
4315
| t ->
4243
4316
begin
4244
4317
bug () " unsupported vector-append type %a" Ast. sprintf_ty t
0 commit comments