Skip to content

Commit 04bb034

Browse files
pcwaltongraydon
authored andcommitted
---
yaml --- r: 302 b: refs/heads/master c: 1c1dc65 h: refs/heads/master v: v3
1 parent 637ba81 commit 04bb034

File tree

3 files changed

+100
-25
lines changed

3 files changed

+100
-25
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: 22eca31d98ce3e1bc5690799e669911e4d06a5aa
2+
refs/heads/master: 1c1dc651a70a1c8a1ee2ca896f4cc29ec88b363c

trunk/src/boot/be/abi.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ let tydesc_field_free_glue = 5;;
7777
let tydesc_field_sever_glue = 6;;
7878
let tydesc_field_mark_glue = 7;;
7979
let tydesc_field_obj_drop_glue = 8;;
80+
let tydesc_field_cmp_glue = 9;;
81+
let tydesc_field_hash_glue = 10;;
8082

8183
let vec_elt_rc = 0;;
8284
let vec_elt_alloc = 1;;

trunk/src/boot/me/trans.ml

Lines changed: 97 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -964,7 +964,7 @@ let trans_visitor
964964
lea base (fst (need_mem_cell data));
965965
add elt (Il.Cell base) mul_idx;
966966
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
968968
trans_cond_fail "bounds check" jmp;
969969
based elt_reg
970970

@@ -1714,6 +1714,8 @@ let trans_visitor
17141714
in
17151715
get_typed_mem_glue g fty inner
17161716

1717+
and get_cmp_glue _ = failwith "TODO"
1718+
17171719

17181720
(* Glue functions use mostly the same calling convention as ordinary
17191721
* functions.
@@ -1821,18 +1823,88 @@ let trans_visitor
18211823
(Array.append [| ty_params_ptr |] args)
18221824
clo
18231825

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
18271884
(cjmp:Il.jmpop)
18281885
(lhs:Il.operand)
18291886
(rhs:Il.operand)
18301887
: quad_idx list =
1831-
(* FIXME: this is an x86-ism; abstract via ABI. *)
18321888
emit (Il.cmp (Il.Cell (Il.Reg (force_to_reg lhs))) rhs);
18331889
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
18361908

18371909
and trans_cond (invert:bool) (expr:Ast.expr) : quad_idx list =
18381910

@@ -1864,12 +1936,12 @@ let trans_visitor
18641936
cjmp
18651937
in
18661938
anno ();
1867-
trans_compare cjmp' lhs rhs
1939+
trans_compare_simple cjmp' lhs rhs
18681940

18691941
| _ ->
18701942
let bool_operand = trans_expr expr in
18711943
anno ();
1872-
trans_compare Il.JNE bool_operand
1944+
trans_compare_simple Il.JNE bool_operand
18731945
(if invert then imm_true else imm_false)
18741946

18751947
and trans_binop (binop:Ast.binop) : Il.binop =
@@ -1915,7 +1987,7 @@ let trans_visitor
19151987

19161988
| _ -> let dst = Il.Reg (Il.next_vreg (emitter()), Il.ValTy Il.Bits8) in
19171989
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
19191991
mov dst imm_false;
19201992
List.iter patch jmps;
19211993
Il.Cell dst
@@ -2330,7 +2402,7 @@ let trans_visitor
23302402
annotate (Printf.sprintf "tag case #%i == %a" i
23312403
Ast.sprintf_name key)));
23322404
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))
23342406
in
23352407
let ttup = Hashtbl.find ttag key in
23362408
iter_tup_parts
@@ -2383,7 +2455,9 @@ let trans_visitor
23832455
mov ptr (Il.Cell lim);
23842456
add_to lim (Il.Cell len);
23852457
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
23872461
let unit_cell =
23882462
deref (ptr_cast ptr (referent_type abi unit_ty))
23892463
in
@@ -2737,9 +2811,7 @@ let trans_visitor
27372811
MEM_gc ->
27382812
let tmp = next_vreg_cell Il.voidptr_t in
27392813
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
27432815
(* Iterate over box parts marking outgoing links. *)
27442816
let (body_mem, _) =
27452817
need_mem_cell
@@ -3455,7 +3527,7 @@ let trans_visitor
34553527
in
34563528
call_code (code_of_operand fn_ptr);
34573529
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
34593531
let errstr = Printf.sprintf "predicate check: %a"
34603532
Ast.sprintf_constr constr
34613533
in
@@ -3956,7 +4028,7 @@ let trans_visitor
39564028
let rec trans_pat pat src_cell src_ty =
39574029
match pat with
39584030
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)
39604032

39614033
| Ast.PAT_tag (lval, pats) ->
39624034
let tag_name = tag_ctor_name_to_tag_name (lval_to_name lval) in
@@ -3980,7 +4052,7 @@ let trans_visitor
39804052
in
39814053

39824054
let next_jumps =
3983-
trans_compare Il.JNE
4055+
trans_compare_simple Il.JNE
39844056
(Il.Cell tag_cell) (imm (Int64.of_int tag_number))
39854057
in
39864058

@@ -4233,12 +4305,13 @@ let trans_visitor
42334305
patch fwd_jmp;
42344306
check_interrupt_flag ();
42354307
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);
42424315
| t ->
42434316
begin
42444317
bug () "unsupported vector-append type %a" Ast.sprintf_ty t

0 commit comments

Comments
 (0)