From f531d386db7051761bd31f2740a893ff97ce65aa Mon Sep 17 00:00:00 2001 From: Xavier Leroy Date: Tue, 22 Dec 2015 11:06:35 +0100 Subject: Add CLZ builtins for ARM and IA32 ARM: add __builtin_clzl, __builtin_clzll IA32: add __builtin_clzl, __builtin_clzll, __builtin_ctzl, __builtin_ctzll Add corresponding tests in tests/regression/ --- ia32/Asmexpand.ml | 27 +++++++++++++++++++++++++-- ia32/CBuiltins.ml | 8 ++++++++ 2 files changed, 33 insertions(+), 2 deletions(-) (limited to 'ia32') diff --git a/ia32/Asmexpand.ml b/ia32/Asmexpand.ml index d7b554dc..7ca31902 100644 --- a/ia32/Asmexpand.ml +++ b/ia32/Asmexpand.ml @@ -245,11 +245,34 @@ let expand_builtin_inline name args res = if a1 <> res then emit (Pmov_rr (res,a1)); emit (Pbswap16 res) - | "__builtin_clz", [BA(IR a1)], BR(IR res) -> + | ("__builtin_clz"|"__builtin_clzl"), [BA(IR a1)], BR(IR res) -> emit (Pbsr (res,a1)); emit (Pxor_ri(res,coqint_of_camlint 31l)) - | "__builtin_ctz", [BA(IR a1)], BR(IR res) -> + | "__builtin_clzll", [BA_splitlong(BA (IR ah), BA (IR al))], BR(IR res) -> + let lbl1 = new_label() in + let lbl2 = new_label() in + emit (Ptest_rr(ah, ah)); + emit (Pjcc(Cond_e, lbl1)); + emit (Pbsr(res, ah)); + emit (Pxor_ri(res, coqint_of_camlint 31l)); + emit (Pjmp_l lbl2); + emit (Plabel lbl1); + emit (Pbsr(res, al)); + emit (Pxor_ri(res, coqint_of_camlint 63l)); + emit (Plabel lbl2) + | ("__builtin_ctz" | "__builtin_ctzl"), [BA(IR a1)], BR(IR res) -> emit (Pbsf (res,a1)) + | "__builtin_ctzll", [BA_splitlong(BA (IR ah), BA (IR al))], BR(IR res) -> + let lbl1 = new_label() in + let lbl2 = new_label() in + emit (Ptest_rr(al, al)); + emit (Pjcc(Cond_e, lbl1)); + emit (Pbsf(res, al)); + emit (Pjmp_l lbl2); + emit (Plabel lbl1); + emit (Pbsf(res, ah)); + emit (Padd_ri(res, coqint_of_camlint 32l)); + emit (Plabel lbl2) (* Float arithmetic *) | "__builtin_fabs", [BA(FR a1)], BR(FR res) -> if a1 <> res then diff --git a/ia32/CBuiltins.ml b/ia32/CBuiltins.ml index 802588d4..79a839f3 100644 --- a/ia32/CBuiltins.ml +++ b/ia32/CBuiltins.ml @@ -31,8 +31,16 @@ let builtins = { (TInt(IUShort, []), [TInt(IUShort, [])], false); "__builtin_clz", (TInt(IInt, []), [TInt(IUInt, [])], false); + "__builtin_clzl", + (TInt(IInt, []), [TInt(IULong, [])], false); + "__builtin_clzll", + (TInt(IInt, []), [TInt(IULongLong, [])], false); "__builtin_ctz", (TInt(IInt, []), [TInt(IUInt, [])], false); + "__builtin_ctzl", + (TInt(IInt, []), [TInt(IULong, [])], false); + "__builtin_ctzll", + (TInt(IInt, []), [TInt(IULongLong, [])], false); (* Float arithmetic *) "__builtin_fsqrt", (TFloat(FDouble, []), [TFloat(FDouble, [])], false); -- cgit