From 9ee09b9b2cb498219bd8012bed69ecf63fce63a4 Mon Sep 17 00:00:00 2001 From: xleroy Date: Wed, 27 Aug 2014 09:51:01 +0000 Subject: Rename __builtin_cntlz to __builtin_clz. IA32: add __builtin_clz, __builtin_ctz. git-svn-id: https://yquem.inria.fr/compcert/svn/compcert/trunk@2619 fca1b0fc-160b-0410-b1d3-a4f43f01ea2e --- Changelog | 6 ++++++ arm/CBuiltins.ml | 2 +- arm/PrintAsm.ml | 2 +- ia32/CBuiltins.ml | 4 ++++ ia32/PrintAsm.ml | 5 +++++ powerpc/Asmexpand.ml | 2 +- powerpc/CBuiltins.ml | 2 +- test/regression/Results/builtins-ia32 | 2 ++ test/regression/builtins-arm.c | 2 +- test/regression/builtins-ia32.c | 2 ++ test/regression/builtins-powerpc.c | 2 +- 11 files changed, 25 insertions(+), 6 deletions(-) diff --git a/Changelog b/Changelog index 18545bd..55a67fa 100644 --- a/Changelog +++ b/Changelog @@ -34,6 +34,12 @@ - Language features: support C99 compound literals. +- Built-in function '__builtin_cntlz' (count leading zeros) + renamed '__builtin_clz' for GCC / Clang compatibility. + +- IA32: added built-in functions __builtin_clz and __builtin_ctz + (count leading / trailing zeros). + Release 2.3pl2, 2014-05-15 ========================== diff --git a/arm/CBuiltins.ml b/arm/CBuiltins.ml index 401bde8..6f62bed 100644 --- a/arm/CBuiltins.ml +++ b/arm/CBuiltins.ml @@ -29,7 +29,7 @@ let builtins = { (TInt(IUInt, []), [TInt(IUInt, [])], false); "__builtin_bswap16", (TInt(IUShort, []), [TInt(IUShort, [])], false); - "__builtin_cntlz", + "__builtin_clz", (TInt(IUInt, []), [TInt(IUInt, [])], false); (* Float arithmetic *) "__builtin_fsqrt", diff --git a/arm/PrintAsm.ml b/arm/PrintAsm.ml index dfe6bfc..01ec716 100644 --- a/arm/PrintAsm.ml +++ b/arm/PrintAsm.ml @@ -551,7 +551,7 @@ let print_builtin_inline oc name args res = fprintf oc " rev %a, %a\n" ireg res ireg a1; 1 | "__builtin_bswap16", [IR a1], [IR res] -> fprintf oc " rev16 %a, %a\n" ireg res ireg a1; 1 - | "__builtin_cntlz", [IR a1], [IR res] -> + | "__builtin_clz", [IR a1], [IR res] -> fprintf oc " clz %a, %a\n" ireg res ireg a1; 1 (* Float arithmetic *) | "__builtin_fabs", [FR a1], [FR res] -> diff --git a/ia32/CBuiltins.ml b/ia32/CBuiltins.ml index 6046126..765f5b1 100644 --- a/ia32/CBuiltins.ml +++ b/ia32/CBuiltins.ml @@ -29,6 +29,10 @@ let builtins = { (TInt(IUInt, []), [TInt(IUInt, [])], false); "__builtin_bswap16", (TInt(IUShort, []), [TInt(IUShort, [])], false); + "__builtin_clz", + (TInt(IUInt, []), [TInt(IUInt, [])], false); + "__builtin_ctz", + (TInt(IUInt, []), [TInt(IUInt, [])], false); (* Float arithmetic *) "__builtin_fsqrt", (TFloat(FDouble, []), [TFloat(FDouble, [])], false); diff --git a/ia32/PrintAsm.ml b/ia32/PrintAsm.ml index 56e837d..8828faa 100644 --- a/ia32/PrintAsm.ml +++ b/ia32/PrintAsm.ml @@ -448,6 +448,11 @@ let print_builtin_inline oc name args res = if a1 <> res then fprintf oc " movl %a, %a\n" ireg a1 ireg res; fprintf oc " rolw $8, %a\n" ireg16 res + | "__builtin_clz", [IR a1], [IR res] -> + fprintf oc " bsrl %a, %a\n" ireg a1 ireg res; + fprintf oc " xorl $31, %a\n" ireg res + | "__builtin_ctz", [IR a1], [IR res] -> + fprintf oc " bsfl %a, %a\n" ireg a1 ireg res (* Float arithmetic *) | "__builtin_fabs", [FR a1], [FR res] -> need_masks := true; diff --git a/powerpc/Asmexpand.ml b/powerpc/Asmexpand.ml index 3554de8..7a45452 100644 --- a/powerpc/Asmexpand.ml +++ b/powerpc/Asmexpand.ml @@ -342,7 +342,7 @@ let expand_builtin_inline name args res = emit (Pmulhw(res, a1, a2)) | "__builtin_mulhwu", [IR a1; IR a2], [IR res] -> emit (Pmulhwu(res, a1, a2)) - | "__builtin_cntlz", [IR a1], [IR res] -> + | "__builtin_clz", [IR a1], [IR res] -> emit (Pcntlz(res, a1)) | ("__builtin_bswap" | "__builtin_bswap32"), [IR a1], [IR res] -> emit (Pstwu(a1, Cint _m8, GPR1)); diff --git a/powerpc/CBuiltins.ml b/powerpc/CBuiltins.ml index f28ff8b..53d84f7 100644 --- a/powerpc/CBuiltins.ml +++ b/powerpc/CBuiltins.ml @@ -28,7 +28,7 @@ let builtins = { (TInt(IInt, []), [TInt(IInt, []); TInt(IInt, [])], false); "__builtin_mulhwu", (TInt(IUInt, []), [TInt(IUInt, []); TInt(IUInt, [])], false); - "__builtin_cntlz", + "__builtin_clz", (TInt(IUInt, []), [TInt(IUInt, [])], false); "__builtin_bswap", (TInt(IUInt, []), [TInt(IUInt, [])], false); diff --git a/test/regression/Results/builtins-ia32 b/test/regression/Results/builtins-ia32 index 5d14a88..3f9a917 100644 --- a/test/regression/Results/builtins-ia32 +++ b/test/regression/Results/builtins-ia32 @@ -1,5 +1,7 @@ bswap(12345678) = 78563412 bswap16(1234) = 3412 +clz(12345678) = 3 +ctz(1234) = 2 fsqrt(3.141590) = 1.772453 fmin(3.141590, 2.718000) = 2.718000 fmax(3.141590, 2.718000) = 3.141590 diff --git a/test/regression/builtins-arm.c b/test/regression/builtins-arm.c index 5a9cdd0..91a8e89 100644 --- a/test/regression/builtins-arm.c +++ b/test/regression/builtins-arm.c @@ -11,7 +11,7 @@ int main(int argc, char ** argv) printf("bswap(%x) = %x\n", x, __builtin_bswap(x)); printf("bswap16(%x) = %x\n", s, __builtin_bswap16(s)); - printf("cntlz(%x) = %d\n", x, __builtin_cntlz(x)); + printf("cntlz(%x) = %d\n", x, __builtin_clz(x)); printf("fsqrt(%f) = %f\n", a, __builtin_fsqrt(a)); printf ("read_16_rev = %x\n", __builtin_read16_reversed(&s)); diff --git a/test/regression/builtins-ia32.c b/test/regression/builtins-ia32.c index 9145518..1042620 100644 --- a/test/regression/builtins-ia32.c +++ b/test/regression/builtins-ia32.c @@ -13,6 +13,8 @@ int main(int argc, char ** argv) printf("bswap(%x) = %x\n", x, __builtin_bswap(x)); printf("bswap16(%x) = %x\n", s, __builtin_bswap16(s)); + printf("clz(%x) = %d\n", x, __builtin_clz(x)); + printf("ctz(%x) = %d\n", s, __builtin_ctz(s)); printf("fsqrt(%f) = %f\n", a, __builtin_fsqrt(a)); printf("fmin(%f, %f) = %f\n", a, b, __builtin_fmin(a, b)); diff --git a/test/regression/builtins-powerpc.c b/test/regression/builtins-powerpc.c index d8a28ed..17d4d3c 100644 --- a/test/regression/builtins-powerpc.c +++ b/test/regression/builtins-powerpc.c @@ -13,7 +13,7 @@ int main(int argc, char ** argv) printf("mulhw(%x, %x) = %x\n", x, y, __builtin_mulhw(x, y)); printf("mulhwu(%x, %x) = %x\n", x, y, __builtin_mulhwu(x, y)); - printf("cntlz(%x) = %d\n", x, __builtin_cntlz(x)); + printf("cntlz(%x) = %d\n", x, __builtin_clz(x)); printf("bswap(%x) = %x\n", x, __builtin_bswap(x)); printf("bswap16(%x) = %x\n", s, __builtin_bswap16(s)); -- cgit v1.2.3