From 468f0c4407895557ca8089430f894a85f06afe97 Mon Sep 17 00:00:00 2001 From: xleroy Date: Sat, 20 Apr 2013 17:46:58 +0000 Subject: Add __builtin_bswap16 and __builtin_bswap32 to all ports. Remove __builtin_{read,write}_reversed from IA32 and ARM ports. Machregs: tighten destroyed_by_builtin Packedstructs: use bswap if read/write-reversed not available. git-svn-id: https://yquem.inria.fr/compcert/svn/compcert/trunk@2208 fca1b0fc-160b-0410-b1d3-a4f43f01ea2e --- ia32/CBuiltins.ml | 15 +++++---------- ia32/Machregs.v | 10 +++++----- ia32/PrintAsm.ml | 28 +++++----------------------- 3 files changed, 15 insertions(+), 38 deletions(-) (limited to 'ia32') diff --git a/ia32/CBuiltins.ml b/ia32/CBuiltins.ml index 596d291e..4a3dde52 100644 --- a/ia32/CBuiltins.ml +++ b/ia32/CBuiltins.ml @@ -23,21 +23,16 @@ let builtins = { (* Integer arithmetic *) "__builtin_bswap", (TInt(IUInt, []), [TInt(IUInt, [])], false); + "__builtin_bswap32", + (TInt(IUInt, []), [TInt(IUInt, [])], false); + "__builtin_bswap16", + (TInt(IUShort, []), [TInt(IUShort, [])], false); (* Float arithmetic *) "__builtin_fsqrt", (TFloat(FDouble, []), [TFloat(FDouble, [])], false); "__builtin_fmax", (TFloat(FDouble, []), [TFloat(FDouble, []); TFloat(FDouble, [])], false); "__builtin_fmin", - (TFloat(FDouble, []), [TFloat(FDouble, []); TFloat(FDouble, [])], false); - (* Memory accesses *) - "__builtin_read16_reversed", - (TInt(IUShort, []), [TPtr(TInt(IUShort, [AConst]), [])], false); - "__builtin_read32_reversed", - (TInt(IUInt, []), [TPtr(TInt(IUInt, [AConst]), [])], false); - "__builtin_write16_reversed", - (TVoid [], [TPtr(TInt(IUShort, []), []); TInt(IUShort, [])], false); - "__builtin_write32_reversed", - (TVoid [], [TPtr(TInt(IUInt, []), []); TInt(IUInt, [])], false); + (TFloat(FDouble, []), [TFloat(FDouble, []); TFloat(FDouble, [])], false) ] } diff --git a/ia32/Machregs.v b/ia32/Machregs.v index 3b84aa5f..a2f3c3ea 100644 --- a/ia32/Machregs.v +++ b/ia32/Machregs.v @@ -105,11 +105,11 @@ Definition destroyed_by_builtin (ef: external_function): list mreg := match ef with | EF_memcpy sz al => if zle sz 32 then CX :: X7 :: nil else CX :: SI :: DI :: nil - | EF_vload _ => nil - | EF_vload_global _ _ _ => nil - | EF_vstore _ => AX :: CX :: X7 :: nil - | EF_vstore_global _ _ _ => AX :: X7 :: nil - | _ => AX :: CX :: X7 :: FP0 :: nil + | EF_vstore (Mint8unsigned|Mint8signed) => AX :: CX :: nil + | EF_vstore Mfloat32 => X7 :: nil + | EF_vstore_global (Mint8unsigned|Mint8signed) _ _ => AX :: nil + | EF_vstore_global Mfloat32 _ _ => X7 :: nil + | _ => nil end. Definition destroyed_at_function_entry: list mreg := diff --git a/ia32/PrintAsm.ml b/ia32/PrintAsm.ml index c2ea98f2..08783711 100644 --- a/ia32/PrintAsm.ml +++ b/ia32/PrintAsm.ml @@ -390,33 +390,15 @@ let print_builtin_vstore_global oc chunk id ofs args = let print_builtin_inline oc name args res = fprintf oc "%s begin builtin %s\n" comment name; begin match name, args, res with - (* Memory accesses *) - | "__builtin_read16_reversed", [IR a1], [IR res] -> - let tmp = if Asmgen.low_ireg res then res else ECX in - fprintf oc " movzwl 0(%a), %a\n" ireg a1 ireg tmp; - fprintf oc " xchg %a, %a\n" ireg8 tmp high_ireg8 tmp; - if tmp <> res then - fprintf oc " movl %a, %a\n" ireg tmp ireg res - | "__builtin_read32_reversed", [IR a1], [IR res] -> - fprintf oc " movl 0(%a), %a\n" ireg a1 ireg res; - fprintf oc " bswap %a\n" ireg res - | "__builtin_write16_reversed", [IR a1; IR a2], _ -> - let tmp = if a1 = ECX then EDX else ECX in - if a2 <> tmp then - fprintf oc " movl %a, %a\n" ireg a2 ireg tmp; - fprintf oc " xchg %a, %a\n" ireg8 tmp high_ireg8 tmp; - fprintf oc " movw %a, 0(%a)\n" ireg16 tmp ireg a1 - | "__builtin_write32_reversed", [IR a1; IR a2], _ -> - let tmp = if a1 = ECX then EDX else ECX in - if a2 <> tmp then - fprintf oc " movl %a, %a\n" ireg a2 ireg tmp; - fprintf oc " bswap %a\n" ireg tmp; - fprintf oc " movl %a, 0(%a)\n" ireg tmp ireg a1 (* Integer arithmetic *) - | "__builtin_bswap", [IR a1], [IR res] -> + | ("__builtin_bswap"| "__builtin_bswap32"), [IR a1], [IR res] -> if a1 <> res then fprintf oc " movl %a, %a\n" ireg a1 ireg res; fprintf oc " bswap %a\n" ireg res + | "__builtin_bswap16", [IR a1], [IR res] -> + if a1 <> res then + fprintf oc " movl %a, %a\n" ireg a1 ireg res; + fprintf oc " rolw $8, %a\n" ireg16 res (* Float arithmetic *) | "__builtin_fabs", [FR a1], [FR res] -> need_masks := true; -- cgit