summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Dunbar <daniel@zuster.org>2008-07-21 18:44:41 +0000
committerDaniel Dunbar <daniel@zuster.org>2008-07-21 18:44:41 +0000
commitc2f67966f4807d7f80849838dbb672631c4f8a50 (patch)
treea21b57c5caf0e8bdae843587c516964de112fb5e
parent5b288788b3eb72380311e477ec72bb0b7508a46d (diff)
downloadbcm5719-llvm-c2f67966f4807d7f80849838dbb672631c4f8a50.tar.gz
bcm5719-llvm-c2f67966f4807d7f80849838dbb672631c4f8a50.zip
Add __builtin_powi[fl] support
llvm-svn: 53866
-rw-r--r--clang/include/clang/AST/Builtins.def3
-rw-r--r--clang/lib/CodeGen/CGBuiltin.cpp14
-rw-r--r--clang/test/CodeGen/builtins-powi.c29
3 files changed, 46 insertions, 0 deletions
diff --git a/clang/include/clang/AST/Builtins.def b/clang/include/clang/AST/Builtins.def
index c3113a9148b..7443583c4a5 100644
--- a/clang/include/clang/AST/Builtins.def
+++ b/clang/include/clang/AST/Builtins.def
@@ -70,6 +70,9 @@ BUILTIN(__builtin_fabsl, "LdLd", "ncF")
BUILTIN(__builtin_copysign, "ddd", "ncF")
BUILTIN(__builtin_copysignf, "fff", "ncF")
BUILTIN(__builtin_copysignl, "LdLdLd", "ncF")
+BUILTIN(__builtin_powi , "ddi" , "nc")
+BUILTIN(__builtin_powif, "ffi" , "nc")
+BUILTIN(__builtin_powil, "LdLdi", "nc")
// FP Comparisons.
BUILTIN(__builtin_isgreater , "i.", "nc")
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index d186a716197..a85f139a0d5 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -192,6 +192,7 @@ RValue CodeGenFunction::EmitBuiltinExpr(unsigned BuiltinID, const CallExpr *E) {
}
case Builtin::BI__builtin_expect:
+ // FIXME: pass expect through to LLVM
return RValue::get(EmitScalarExpr(E->getArg(0)));
case Builtin::BI__builtin_bswap32:
case Builtin::BI__builtin_bswap64: {
@@ -226,6 +227,19 @@ RValue CodeGenFunction::EmitBuiltinExpr(unsigned BuiltinID, const CallExpr *E) {
// Otherwise, call libm 'nan'.
break;
}
+ case Builtin::BI__builtin_powi:
+ case Builtin::BI__builtin_powif:
+ case Builtin::BI__builtin_powil: {
+ Value *Base = EmitScalarExpr(E->getArg(0));
+ Value *Exponent = EmitScalarExpr(E->getArg(1));
+
+ const llvm::Type *ArgType = Base->getType();
+ Value *F = CGM.getIntrinsic(Intrinsic::powi, &ArgType, 1);
+
+ const llvm::Type *ResultType = ConvertType(E->getType());
+ return RValue::get(Builder.CreateCall2(F, Base, Exponent, "tmp"));
+ }
+
case Builtin::BI__builtin_isgreater:
case Builtin::BI__builtin_isgreaterequal:
case Builtin::BI__builtin_isless:
diff --git a/clang/test/CodeGen/builtins-powi.c b/clang/test/CodeGen/builtins-powi.c
new file mode 100644
index 00000000000..6d82f8af51f
--- /dev/null
+++ b/clang/test/CodeGen/builtins-powi.c
@@ -0,0 +1,29 @@
+// RUN: clang -emit-llvm -o - %s > %t
+// RUN: ! grep "__builtin" %t
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <math.h>
+
+void test(long double a, int b) {
+ printf("%Lf**%d: %08x %08x %016Lx\n",
+ a, b,
+ __builtin_powi(a, b),
+ __builtin_powif(a, b),
+ __builtin_powil(a, b)
+ );
+}
+
+int main() {
+ int i;
+
+ test(-1,-1LL);
+ test(0,0);
+ test(1,1);
+
+ for (i=0; i<3; i++) {
+ test(random(), i);
+ }
+
+ return 0;
+}
OpenPOWER on IntegriCloud