Skip to content

Hints phys equal #1745

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: hints
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions compiler/lib/generate.ml
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,8 @@ let plus_int x y =

let bool e = J.ECond (e, one, zero)

let bool_not e = J.ECond (e, zero, one)

(****)

let source_location loc =
Expand Down Expand Up @@ -1547,6 +1549,24 @@ let rec translate_expr ctx loc x e level : (_ * J.statement_list) Expr_builder.t
| _ -> J.EBin (J.Plus, ca, cb)
in
return (add ca cb)
| Extern "%phys_equal", [ x; y ] ->
let* cx = access' ~ctx x in
let* cy = access' ~ctx y in
return
(bool
(J.call
(J.dot (s_var "Object") (Utf8_string.of_string_exn "is"))
[ cx; cy ]
loc))
| Extern "%not_phys_equal", [ x; y ] ->
let* cx = access' ~ctx x in
let* cy = access' ~ctx y in
return
(bool_not
(J.call
(J.dot (s_var "Object") (Utf8_string.of_string_exn "is"))
[ cx; cy ]
loc))
| Extern name_orig, l -> (
let name = Primitive.resolve name_orig in
match internal_prim name with
Expand Down
17 changes: 15 additions & 2 deletions compiler/lib/parse_bytecode.ml
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,7 @@ module Hints = struct
; layout : Lambda.bigarray_layout
}
| Hint_primitive of Primitive.description
| Hint_phys_equal

type t = { hints : optimization_hint Int.Hashtbl.t }

Expand Down Expand Up @@ -2320,23 +2321,35 @@ and compile infos pc state (instrs : instr list) =

if debug_parser ()
then Format.printf "%a = mk_bool(%a == %a)@." Var.print x Var.print y Var.print z;
let hints = Hints.find infos.hints pc in
let prim =
if List.mem ~eq:Hints.equal Hints.Hint_phys_equal hints
then Extern "%phys_equal"
else Eq
in
compile
infos
(pc + 1)
(State.pop 1 state)
(Let (x, Prim (Eq, [ Pv y; Pv z ])) :: instrs)
(Let (x, Prim (prim, [ Pv y; Pv z ])) :: instrs)
| NEQ ->
let y = State.accu state in
let z = State.peek 0 state in
let x, state = State.fresh_var state in

if debug_parser ()
then Format.printf "%a = mk_bool(%a != %a)@." Var.print x Var.print y Var.print z;
let hints = Hints.find infos.hints pc in
let prim =
if List.mem ~eq:Hints.equal Hints.Hint_phys_equal hints
then Extern "%not_phys_equal"
else Neq
in
compile
infos
(pc + 1)
(State.pop 1 state)
(Let (x, Prim (Neq, [ Pv y; Pv z ])) :: instrs)
(Let (x, Prim (prim, [ Pv y; Pv z ])) :: instrs)
| LTINT ->
let y = State.accu state in
let z = State.peek 0 state in
Expand Down
Loading
Loading