From 7cc001e63990ae5e8cf2f75b5148093e31fbdc85 Mon Sep 17 00:00:00 2001 From: David Monniaux Date: Wed, 10 Apr 2019 22:50:06 +0200 Subject: get / set k1 --- mppa_k1c/Asm.v | 3 +++ mppa_k1c/Asmexpand.ml | 5 +++++ mppa_k1c/CBuiltins.ml | 5 ++++- mppa_k1c/Machregs.v | 5 ++++- mppa_k1c/TargetPrinter.ml | 8 +++++++- 5 files changed, 23 insertions(+), 3 deletions(-) diff --git a/mppa_k1c/Asm.v b/mppa_k1c/Asm.v index 303a624c..7c6bd013 100644 --- a/mppa_k1c/Asm.v +++ b/mppa_k1c/Asm.v @@ -72,7 +72,10 @@ Inductive instruction : Type := | Pcb (bt: btest) (r: ireg) (l: label) (**r branch based on btest *) | Pcbu (bt: btest) (r: ireg) (l: label) (**r branch based on btest with unsigned semantics *) | Pjumptable (r: ireg) (labels: list label) + | Ploopdo (count: ireg) (loopend: label) + | Pgetn (n: int) (dst: ireg) + | Psetn (n: int) (src: ireg) (** Loads **) | Plb (rd: ireg) (ra: ireg) (ofs: addressing) (**r load byte *) diff --git a/mppa_k1c/Asmexpand.ml b/mppa_k1c/Asmexpand.ml index d12b9785..d4792541 100644 --- a/mppa_k1c/Asmexpand.ml +++ b/mppa_k1c/Asmexpand.ml @@ -357,6 +357,11 @@ let expand_builtin_inline name args res = let open Asmvliw in emit (Pclzll(res, a)) | "__builtin_k1_stsud", [BA(IR a1); BA(IR a2)], BR(IR res) -> emit (Pstsud(res, a1, a2)) + | "__builtin_k1_get", [BA_int(n)], BR(IR res) -> + emit (Pgetn(n, res)) + | "__builtin_k1_set", [BA_int(n); BA(IR src)], _ -> + emit (Psetn(n, src)) + (* Byte swaps *) (*| "__builtin_bswap16", [BA(IR a1)], BR(IR res) -> expand_bswap16 res a1 diff --git a/mppa_k1c/CBuiltins.ml b/mppa_k1c/CBuiltins.ml index 147bbb55..9d0c607d 100644 --- a/mppa_k1c/CBuiltins.ml +++ b/mppa_k1c/CBuiltins.ml @@ -38,7 +38,10 @@ let builtins = { "__builtin_k1_stop", (TVoid [], [], false); "__builtin_k1_syncgroup", (TVoid [], [TInt(IUInt, [])], false); "__builtin_k1_tlbwrite", (TVoid [], [], false); - + + "__builtin_k1_get", (TInt(IULong, []), [TInt(IUInt, [])], false); + "__builtin_k1_set", (TVoid [], [TInt(IUInt, []); TInt(IULong, [])], false); + (* LSU Instructions *) (* No ACWS - __int128 *) "__builtin_k1_afda", (TInt(IULongLong, []), [TPtr(TVoid [], []); TInt(ILongLong, [])], false); diff --git a/mppa_k1c/Machregs.v b/mppa_k1c/Machregs.v index 823b13e9..f9712428 100644 --- a/mppa_k1c/Machregs.v +++ b/mppa_k1c/Machregs.v @@ -218,7 +218,10 @@ Definition two_address_op (op: operation) : bool := Definition builtin_constraints (ef: external_function) : list builtin_arg_constraint := match ef with - | EF_builtin id sg => nil + | EF_builtin id sg => + if string_dec id "__builtin_k1_get" then OK_const :: nil + else if string_dec id "__builtin_k1_set" then OK_const :: OK_default :: nil + else nil | EF_vload _ => OK_addressing :: nil | EF_vstore _ => OK_addressing :: OK_default :: nil | EF_memcpy _ _ => OK_addrstack :: OK_addrstack :: nil diff --git a/mppa_k1c/TargetPrinter.ml b/mppa_k1c/TargetPrinter.ml index 3aa6b319..beac8cfe 100644 --- a/mppa_k1c/TargetPrinter.ml +++ b/mppa_k1c/TargetPrinter.ml @@ -274,8 +274,14 @@ module Target (*: TARGET*) = fprintf oc " goto %a\n" print_label s | Pcb (bt, r, lbl) | Pcbu (bt, r, lbl) -> fprintf oc " cb.%a %a? %a\n" bcond bt ireg r print_label lbl + | Ploopdo (r, lbl) -> - fprintf oc " loopdo %a, %a\n" ireg r print_label lbl + fprintf oc " loopdo %a, %a\n" ireg r print_label lbl + | Pgetn(n, dst) -> + fprintf oc " get %a = $s%ld\n" ireg dst (camlint_of_coqint n) + | Psetn(n, dst) -> + fprintf oc " set $s%ld = %a\n" (camlint_of_coqint n) ireg dst + | Pjumptable (idx_reg, tbl) -> let lbl = new_label() in (* jumptables := (lbl, tbl) :: !jumptables; *) -- cgit