Skip to content

Commit

Permalink
[hl] added $prefetch support
Browse files Browse the repository at this point in the history
  • Loading branch information
ncannasse authored Aug 26, 2023
1 parent acce4e0 commit d033a09
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 1 deletion.
15 changes: 15 additions & 0 deletions src/generators/genhl.ml
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,12 @@ let unsigned_op e1 e2 =
in
is_unsigned e1 && is_unsigned e2

let rec get_const e =
match e.eexpr with
| TConst c -> c
| TParenthesis e | TCast (e,_) -> get_const e
| _ -> abort "Should be a constant" e.epos

let set_curpos ctx p =
ctx.m.mcurpos <- p

Expand Down Expand Up @@ -2067,6 +2073,15 @@ and eval_expr ctx e =
free ctx rfile;
free ctx min;
r
| "$prefetch", [value; mode] ->
let mode = (match get_const mode with
| TInt m -> Int32.to_int m
| _ -> abort "Constant mode required" e.epos
) in
(match get_access ctx value with
| AInstanceField (f, index) -> op ctx (OPrefetch (eval_expr ctx f, index + 1, mode))
| _ -> op ctx (OPrefetch (eval_expr ctx value, 0, mode)));
alloc_tmp ctx HVoid
| _ ->
abort ("Unknown native call " ^ s) e.epos)
| TEnumIndex v ->
Expand Down
9 changes: 9 additions & 0 deletions src/generators/hl2c.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1087,6 +1087,15 @@ let generate_function ctx f =
sexpr "%s = %s + %s" (reg r) (reg r2) (reg off)
| ONop _ ->
()
| OPrefetch (r,fid,mode) ->
let expr = (if fid = 0 then reg r else (match rtype r with
| HObj o | HStruct o ->
let name, t = resolve_field o (fid - 1) in
Printf.sprintf "%s->%s" (reg r) name
| _ ->
Globals.die "" __LOC__
)) in
sexpr "__hl_prefetch_m%d(%s)" mode expr
) f.code;
flush_options (Array.length f.code);
unblock();
Expand Down
3 changes: 3 additions & 0 deletions src/generators/hlcode.ml
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ type opcode =
| ORefData of reg * reg
| ORefOffset of reg * reg * reg
| ONop of string
| OPrefetch of reg * field index * int

type fundecl = {
fpath : string * string;
Expand Down Expand Up @@ -572,6 +573,8 @@ let ostr fstr o =
| ORefData (r,d) -> Printf.sprintf "refdata %d, %d" r d
| ORefOffset (r,r2,off) -> Printf.sprintf "refoffset %d, %d, %d" r r2 off
| ONop s -> if s = "" then "nop" else "nop " ^ s
| OPrefetch (r,f,mode) -> Printf.sprintf "prefetch %d[%d] %d" r f mode

let fundecl_name f = if snd f.fpath = "" then "fun$" ^ (string_of_int f.findex) else (fst f.fpath) ^ "." ^ (snd f.fpath)

let dump pr code =
Expand Down
4 changes: 3 additions & 1 deletion src/generators/hlinterp.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1154,7 +1154,7 @@ let interp ctx f args =
(match get r2, get off with
| VRef (RArray (a,pos),t), VInt i -> set r (VRef (RArray (a,pos + Int32.to_int i),t))
| _ -> Globals.die "" __LOC__)
| ONop _ ->
| ONop _ | OPrefetch _ ->
()
);
loop()
Expand Down Expand Up @@ -2547,6 +2547,8 @@ let check code macros =
reg off HI32;
| ONop _ ->
();
| OPrefetch (r,f,_) ->
if f = 0 then ignore(rtype r) else ignore(tfield r (f - 1) false)
) f.code
(* TODO : check that all path correctly initialize NULL values and reach a return *)
in
Expand Down
5 changes: 5 additions & 0 deletions src/generators/hlopt.ml
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,8 @@ let opcode_fx frw op =
write r;
| ONop _ ->
()
| OPrefetch (r,_,_) ->
read r

let opcode_eq a b =
match a, b with
Expand Down Expand Up @@ -432,6 +434,9 @@ let opcode_map read write op =
ORefOffset (write r,r2,off);
| ONop _ ->
op
| OPrefetch (r, fid, mode) ->
let r2 = read r in
OPrefetch (r2, fid, mode)

(* build code graph *)

Expand Down

0 comments on commit d033a09

Please sign in to comment.