From a168d6a141e77a5fa98017b23ab2aadc5748fe94 Mon Sep 17 00:00:00 2001 From: Bernhard Schommer Date: Mon, 7 Sep 2015 09:40:24 +0200 Subject: Simplified generation of builtins for cache instructions. The cache instructions need no special constraint on the address argument. Therefore also the generation of the address is no longer needed. --- powerpc/Asmexpand.ml | 75 +++++++++++++--------------------------------------- 1 file changed, 18 insertions(+), 57 deletions(-) (limited to 'powerpc/Asmexpand.ml') diff --git a/powerpc/Asmexpand.ml b/powerpc/Asmexpand.ml index 3e57cdbf..a2c07baf 100644 --- a/powerpc/Asmexpand.ml +++ b/powerpc/Asmexpand.ml @@ -324,56 +324,6 @@ let expand_builtin_va_start r = let expand_int64_arith conflict rl fn = if conflict then (fn GPR0; emit (Pmr(rl, GPR0))) else fn rl -(* Handling of cache instructions *) - -(* Auxiliary function to generate address for the cache function *) -let expand_builtin_cache_common addr f = - let add = match addr with - | BA (IR a1) -> a1 - | BA_addrstack ofs -> - emit_addimm GPR11 GPR1 ofs; - GPR11 - | BA_addrglobal(id, ofs) -> - if symbol_is_small_data id ofs then begin - emit (Paddi (GPR11, GPR0, Csymbol_sda(id, ofs))); - GPR11 - end else if symbol_is_rel_data id ofs then begin - emit (Paddis(GPR11, GPR0, Csymbol_rel_high(id, ofs))); - emit (Paddi(GPR11, GPR11, Csymbol_rel_low(id, ofs))); - GPR11 - end else begin - emit (Paddis(GPR11, GPR0, Csymbol_high(id, ofs))); - emit (Paddi (GPR11, GPR11, Csymbol_low(id, ofs))); - GPR11 - end - | _ -> raise (Error "Argument is not an address") in - f add - -let expand_builtin_prefetch addr rw loc = - if not ((loc >= _0) && (loc <= _2)) then - raise (Error "the last argument of __builtin_prefetch must be a constant between 0 and 2"); - let emit_prefetch_instr addr = - if Int.eq rw _0 then begin - emit (Pdcbt (loc,GPR0,addr)); - end else if Int.eq rw _1 then begin - emit (Pdcbtst (loc,GPR0,addr)); - end else - raise (Error "the second argument of __builtin_prefetch must be either 0 or 1") - in - expand_builtin_cache_common addr emit_prefetch_instr - -let expand_builtin_dcbtls addr loc = - if not ((loc == _0) || (loc = _2)) then - raise (Error "the second argument of __builtin_dcbtls must be a constant between 0 and 2"); - let emit_inst addr = emit (Pdcbtls (loc,GPR0,addr)) in - expand_builtin_cache_common addr emit_inst - -let expand_builtin_icbtls addr loc = - if not ((loc == _0) || (loc = _2)) then - raise (Error "the second argument of __builtin_icbtls must be a constant between 0 and 2"); - let emit_inst addr = emit (Picbtls (loc,GPR0,addr)) in - expand_builtin_cache_common addr emit_inst - (* Handling of compiler-inlined builtins *) let expand_builtin_inline name args res = @@ -468,7 +418,7 @@ let expand_builtin_inline name args res = emit (Plwsync) | "__builtin_mbar", [BA_int mo], _ -> if not (mo = _0 || mo = _1) then - raise (Error "the argument of __builtin_mbar must be either 0 or 1"); + raise (Error "the argument of __builtin_mbar must be 0 or 1"); emit (Pmbar mo) | "__builin_mbar",_, _ -> raise (Error "the argument of __builtin_mbar must be a constant"); @@ -484,16 +434,27 @@ let expand_builtin_inline name args res = emit (Pdcbi (GPR0,a1)) | "__builtin_icbi", [BA(IR a1)],_ -> emit (Picbi(GPR0,a1)) - | "__builtin_dcbtls", [a; BA_int loc],_ -> - expand_builtin_dcbtls a loc + | "__builtin_dcbtls", [BA (IR a1); BA_int loc],_ -> + if not ((Int.eq loc _0) || (Int.eq loc _2)) then + raise (Error "the second argument of __builtin_dcbtls must be a constant between 0 and 2"); + emit (Pdcbtls (loc,GPR0,a1)) | "__builtin_dcbtls",_,_ -> raise (Error "the second argument of __builtin_dcbtls must be a constant") - | "__builtin_icbtls", [a; BA_int loc],_ -> - expand_builtin_icbtls a loc + | "__builtin_icbtls", [BA (IR a1); BA_int loc],_ -> + if not ((Int.eq loc _0) || (Int.eq loc _2)) then + raise (Error "the second argument of __builtin_icbtls must be 0 or 2"); + emit (Picbtls (loc,GPR0,a1)) | "__builtin_icbtls",_,_ -> raise (Error "the second argument of __builtin_icbtls must be a constant") - | "__builtin_prefetch" , [a1 ;BA_int rw; BA_int loc],_ -> - expand_builtin_prefetch a1 rw loc + | "__builtin_prefetch" , [BA (IR a1) ;BA_int rw; BA_int loc],_ -> + if not (Int.ltu loc _4) then + raise (Error "the last argument of __builtin_prefetch must be 0, 1 or 2"); + if Int.eq rw _0 then begin + emit (Pdcbt (loc,GPR0,a1)); + end else if Int.eq rw _1 then begin + emit (Pdcbtst (loc,GPR0,a1)); + end else + raise (Error "the second argument of __builtin_prefetch must be 0 or 1") | "__builtin_prefetch" ,_,_ -> raise (Error "the second and third argument of __builtin_prefetch must be a constant") | "__builtin_dcbz",[BA (IR a1)],_ -> -- cgit From 76d82e41797ef79531e6bf3d530f380dddd3310e Mon Sep 17 00:00:00 2001 From: Bernhard Schommer Date: Mon, 7 Sep 2015 15:51:45 +0200 Subject: Added builtin for the cmpb instruction. --- powerpc/Asmexpand.ml | 2 ++ 1 file changed, 2 insertions(+) (limited to 'powerpc/Asmexpand.ml') diff --git a/powerpc/Asmexpand.ml b/powerpc/Asmexpand.ml index a2c07baf..b3d357ef 100644 --- a/powerpc/Asmexpand.ml +++ b/powerpc/Asmexpand.ml @@ -336,6 +336,8 @@ let expand_builtin_inline name args res = emit (Pmulhwu(res, a1, a2)) | "__builtin_clz", [BA(IR a1)], BR(IR res) -> emit (Pcntlzw(res, a1)) + | "__builtin_cmpb", [BA(IR a1); BA(IR a2)], BR(IR res) -> + emit (Pcmpb (res,a1,a2)) | ("__builtin_bswap" | "__builtin_bswap32"), [BA(IR a1)], BR(IR res) -> emit (Pstwu(a1, Cint _m8, GPR1)); emit (Pcfi_adjust _8); -- cgit From 73e20bd6e0586e38fbc7d87d8c306fad7b578418 Mon Sep 17 00:00:00 2001 From: Bernhard Schommer Date: Mon, 7 Sep 2015 19:35:02 +0200 Subject: Added builtins for call frame and return address. This builtins can be used to get the call frame address and the return address. To correctly compute the load address of the return address the allocframe is extended to contain the offset of the return address. --- powerpc/Asmexpand.ml | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'powerpc/Asmexpand.ml') diff --git a/powerpc/Asmexpand.ml b/powerpc/Asmexpand.ml index b3d357ef..929e6325 100644 --- a/powerpc/Asmexpand.ml +++ b/powerpc/Asmexpand.ml @@ -276,6 +276,9 @@ let expand_builtin_vstore chunk args = assert false (* Handling of varargs *) +let linkregister_offset = ref Int.zero + +let retaddr_offset = ref Int.zero let current_function_stacksize = ref 0l @@ -470,6 +473,16 @@ let expand_builtin_inline name args res = emit (Pmtspr(n, a1)) | "__builtin_set_spr", _, _ -> raise (Error "the first argument of __builtin_set_spr must be a constant") + (* Frame and return address *) + | "__builtin_call_frame", _,BR (IR res) -> + let sz = !current_function_stacksize + and ofs = !linkregister_offset in + if sz < 0x8000l then + emit (Paddi(res, GPR1, Cint(coqint_of_camlint sz))) + else + emit (Plwz(res, Cint ofs, GPR1)) + | "__builtin_return_address",_,BR (IR res) -> + emit (Plwz (res, Cint! retaddr_offset,GPR1)) (* Catch-all *) | _ -> raise (Error ("unrecognized builtin " ^ name)) @@ -497,7 +510,7 @@ let num_crbit = function let expand_instruction instr = match instr with - | Pallocframe(sz, ofs) -> + | Pallocframe(sz, ofs,retofs) -> let variadic = (!current_function).fn_sig.sig_cc.cc_vararg in let sz = camlint_of_coqint sz in assert (ofs = Int.zero); @@ -516,7 +529,9 @@ let expand_instruction instr = {sig_args = []; sig_res = None; sig_cc = cc_default})); emit (Pmtlr GPR0) end; - current_function_stacksize := sz + current_function_stacksize := sz; + linkregister_offset := ofs; + retaddr_offset := retofs | Pbctr sg | Pbctrl sg | Pbl(_, sg) | Pbs(_, sg) -> set_cr6 sg; emit instr -- cgit From 2246044e99569fcf1c2172f0e710134123be8b49 Mon Sep 17 00:00:00 2001 From: Bernhard Schommer Date: Tue, 8 Sep 2015 10:44:34 +0200 Subject: Added builtin for isel. The builtin_isel function takes a _Bool as first argument and returns either the second or the third depending on the value of the _Bool. --- powerpc/Asmexpand.ml | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'powerpc/Asmexpand.ml') diff --git a/powerpc/Asmexpand.ml b/powerpc/Asmexpand.ml index 929e6325..3fffc037 100644 --- a/powerpc/Asmexpand.ml +++ b/powerpc/Asmexpand.ml @@ -483,6 +483,10 @@ let expand_builtin_inline name args res = emit (Plwz(res, Cint ofs, GPR1)) | "__builtin_return_address",_,BR (IR res) -> emit (Plwz (res, Cint! retaddr_offset,GPR1)) + (* isel *) + | "__builtin_isel", [BA (IR a1); BA (IR a2); BA (IR a3)],BR (IR res) -> + emit (Pcmpwi (a1,Cint (Int.zero))); + emit (Pisel (res,a3,a2,CRbit_2)) (* Catch-all *) | _ -> raise (Error ("unrecognized builtin " ^ name)) -- cgit From 469badb1eb88b187ff39c9847b3b2316225fd421 Mon Sep 17 00:00:00 2001 From: Michael Schmidt Date: Fri, 18 Sep 2015 12:39:05 +0200 Subject: correct error message for __builtin_dcbtls --- powerpc/Asmexpand.ml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'powerpc/Asmexpand.ml') diff --git a/powerpc/Asmexpand.ml b/powerpc/Asmexpand.ml index 3fffc037..b9fe1d7f 100644 --- a/powerpc/Asmexpand.ml +++ b/powerpc/Asmexpand.ml @@ -441,7 +441,7 @@ let expand_builtin_inline name args res = emit (Picbi(GPR0,a1)) | "__builtin_dcbtls", [BA (IR a1); BA_int loc],_ -> if not ((Int.eq loc _0) || (Int.eq loc _2)) then - raise (Error "the second argument of __builtin_dcbtls must be a constant between 0 and 2"); + raise (Error "the second argument of __builtin_dcbtls must be 0 or 2"); emit (Pdcbtls (loc,GPR0,a1)) | "__builtin_dcbtls",_,_ -> raise (Error "the second argument of __builtin_dcbtls must be a constant") -- cgit