diff options
author | Michael Schmidt <github@mschmidt.me> | 2015-12-11 15:53:47 +0100 |
---|---|---|
committer | Michael Schmidt <github@mschmidt.me> | 2015-12-11 15:53:47 +0100 |
commit | 75a55495bdde3eb2366dd164a4c44f416fc592a0 (patch) | |
tree | b1f7daad95f5ce260b62658e272209df502ad28b | |
parent | fd2d8d86daf9d63d5695c93f412a7cf549d312c6 (diff) | |
download | compcert-75a55495bdde3eb2366dd164a4c44f416fc592a0.tar.gz compcert-75a55495bdde3eb2366dd164a4c44f416fc592a0.zip |
bug 17752, add builtin_clzl and builtin_clzll for PowerPC
-rw-r--r-- | powerpc/Asmexpand.ml | 13 | ||||
-rw-r--r-- | powerpc/CBuiltins.ml | 4 |
2 files changed, 16 insertions, 1 deletions
diff --git a/powerpc/Asmexpand.ml b/powerpc/Asmexpand.ml index 93a0b17f..b8d8205b 100644 --- a/powerpc/Asmexpand.ml +++ b/powerpc/Asmexpand.ml @@ -38,6 +38,7 @@ let _2 = coqint_of_camlint 2l let _4 = coqint_of_camlint 4l let _6 = coqint_of_camlint 6l let _8 = coqint_of_camlint 8l +let _32 = coqint_of_camlint 32l let _m4 = coqint_of_camlint (-4l) let _m8 = coqint_of_camlint (-8l) @@ -344,8 +345,18 @@ let expand_builtin_inline name args res = emit (Pmulhw(res, a1, a2)) | "__builtin_mulhwu", [BA(IR a1); BA(IR a2)], BR(IR res) -> emit (Pmulhwu(res, a1, a2)) - | "__builtin_clz", [BA(IR a1)], BR(IR res) -> + | ("__builtin_clz" | "__builtin_clzl"), [BA(IR a1)], BR(IR res) -> emit (Pcntlzw(res, a1)) + | "__builtin_clzll", [BA_splitlong(BA(IR ah), BA(IR al))], BR(IR res) -> + let lbl = new_label () in + emit (Pcntlzw(res, ah)); + (* less than 32 bits zero? *) + emit (Pcmpwi (res, Cint _32)); + emit (Pbf (CRbit_2, lbl)); + (* high bits all zero, count bits in low word and increment by 32*) + emit (Pcntlzw(res, al)); + emit (Paddi(res, res, Cint _32)); + emit (Plabel lbl) | "__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) -> diff --git a/powerpc/CBuiltins.ml b/powerpc/CBuiltins.ml index a611aabe..169647b6 100644 --- a/powerpc/CBuiltins.ml +++ b/powerpc/CBuiltins.ml @@ -30,6 +30,10 @@ let builtins = { (TInt(IUInt, []), [TInt(IUInt, []); TInt(IUInt, [])], false); "__builtin_clz", (TInt(IUInt, []), [TInt(IUInt, [])], false); + "__builtin_clzl", + (TInt(IUInt, []), [TInt(IULong, [])], false); + "__builtin_clzll", + (TInt(IUInt, []), [TInt(IULongLong, [])], false); "__builtin_bswap", (TInt(IUInt, []), [TInt(IUInt, [])], false); "__builtin_bswap32", |