summaryrefslogtreecommitdiff
path: root/ia32
diff options
context:
space:
mode:
authorGravatar xleroy <xleroy@fca1b0fc-160b-0410-b1d3-a4f43f01ea2e>2013-04-29 07:51:00 +0000
committerGravatar xleroy <xleroy@fca1b0fc-160b-0410-b1d3-a4f43f01ea2e>2013-04-29 07:51:00 +0000
commitfbdff974fe7d2040c25dee1d35781f7e70d87d6c (patch)
tree14f112a70481f467e581ca59136eed42601ce725 /ia32
parente1fc4beb37252b6248c0e0ca4cf5ec00a45190bf (diff)
Revert suppression of __builtin_{read,write}_reversed for x86 and ARM,
for compatibility with earlier CompCert versions. But don't use them in PackedStructs. git-svn-id: https://yquem.inria.fr/compcert/svn/compcert/trunk@2216 fca1b0fc-160b-0410-b1d3-a4f43f01ea2e
Diffstat (limited to 'ia32')
-rw-r--r--ia32/CBuiltins.ml11
-rw-r--r--ia32/Machregs.v11
-rw-r--r--ia32/PrintAsm.ml19
3 files changed, 38 insertions, 3 deletions
diff --git a/ia32/CBuiltins.ml b/ia32/CBuiltins.ml
index 4a3dde5..cbd5998 100644
--- a/ia32/CBuiltins.ml
+++ b/ia32/CBuiltins.ml
@@ -33,6 +33,15 @@ let builtins = {
"__builtin_fmax",
(TFloat(FDouble, []), [TFloat(FDouble, []); TFloat(FDouble, [])], false);
"__builtin_fmin",
- (TFloat(FDouble, []), [TFloat(FDouble, []); TFloat(FDouble, [])], false)
+ (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);
]
}
diff --git a/ia32/Machregs.v b/ia32/Machregs.v
index a2f3c3e..31ea8ee 100644
--- a/ia32/Machregs.v
+++ b/ia32/Machregs.v
@@ -101,6 +101,11 @@ Definition destroyed_by_cond (cond: condition): list mreg :=
Definition destroyed_by_jumptable: list mreg :=
nil.
+Local Open Scope string_scope.
+
+Definition builtin_write16_reversed := ident_of_string "__builtin_write16_reversed".
+Definition builtin_write32_reversed := ident_of_string "__builtin_write32_reversed".
+
Definition destroyed_by_builtin (ef: external_function): list mreg :=
match ef with
| EF_memcpy sz al =>
@@ -109,6 +114,10 @@ Definition destroyed_by_builtin (ef: external_function): list mreg :=
| EF_vstore Mfloat32 => X7 :: nil
| EF_vstore_global (Mint8unsigned|Mint8signed) _ _ => AX :: nil
| EF_vstore_global Mfloat32 _ _ => X7 :: nil
+ | EF_builtin id sg =>
+ if ident_eq id builtin_write16_reversed
+ || ident_eq id builtin_write32_reversed
+ then CX :: DX :: nil else nil
| _ => nil
end.
@@ -131,8 +140,6 @@ Definition mregs_for_operation (op: operation): list (option mreg) * option mreg
| _ => (nil, None)
end.
-Local Open Scope string_scope.
-
Definition builtin_negl := ident_of_string "__builtin_negl".
Definition builtin_addl := ident_of_string "__builtin_addl".
Definition builtin_subl := ident_of_string "__builtin_subl".
diff --git a/ia32/PrintAsm.ml b/ia32/PrintAsm.ml
index 0878371..2d676d1 100644
--- a/ia32/PrintAsm.ml
+++ b/ia32/PrintAsm.ml
@@ -442,6 +442,25 @@ let print_builtin_inline oc name args res =
| "__builtin_mull", [IR a; IR b], [IR rh; IR rl] ->
assert (a = EAX && b = EDX && rh = EDX && rl = EAX);
fprintf oc " mull %a\n" ireg EDX
+ (* Memory accesses *)
+ | "__builtin_read16_reversed", [IR a1], [IR res] ->
+ fprintf oc " movzwl 0(%a), %a\n" ireg a1 ireg res;
+ fprintf oc " rolw $8, %a\n" ireg16 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
(* Catch-all *)
| _ ->
invalid_arg ("unrecognized builtin " ^ name)