summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Steckelmacher <steckdenis@yahoo.fr>2011-10-24 19:13:10 +0200
committerDenis Steckelmacher <steckdenis@yahoo.fr>2011-10-24 19:13:10 +0200
commit750754c5e57953b0231cad56a392461b6e92c7ff (patch)
treecda895307fa957d068ddfe83be32fca0ff6edc99
parent8a6e965c8a6d3a7bbef277191e7ca698a5b247f8 (diff)
New exp() function
exp2() is currently broken.
-rw-r--r--src/runtime/builtins.def23
-rw-r--r--src/runtime/stdlib.h2
-rw-r--r--tests/test_builtins.cpp4
3 files changed, 28 insertions, 1 deletions
diff --git a/src/runtime/builtins.def b/src/runtime/builtins.def
index b01279b..4f50ed4 100644
--- a/src/runtime/builtins.def
+++ b/src/runtime/builtins.def
@@ -140,6 +140,7 @@ func float copysign float : x:float y:float
if ((x < 0.0f && y > 0.0f) ||
(x > 0.0f && y < 0.0f))
return -x;
+ return x;
end
native $type copysign $vecf : x:$type y:$type
@@ -175,12 +176,32 @@ end
// gentype cospi (gentype x)
func $type cospi $gentype : x:$type
- return cos(x * M_PI);
+ return cos(x * (float)M_PI);
end
// TODO: gentype erfc (gentype)
// TODO: gentype erf (gentype)
+// gentype exp(gentype x)
+native float exp float : x:float
+ return std::exp(x);
+end
+
+native $type exp $vecf : x:$type
+ REPL($vecdim)
+ result[i] = std::exp(x[i]);
+end
+
+// gentype exp2(gentype x)
+native float exp2 float : x:float
+ //return std::ldexp(x, 2);
+end
+
+native $type exp2 $vecf : x:$type
+ //REPL($vecdim)
+ // result[i] = std::ldexp(x[i], 2);
+end
+
func $type fmin $gentype : x:$type y:$type
return (x < y ? x : y);
end
diff --git a/src/runtime/stdlib.h b/src/runtime/stdlib.h
index 2cfe88e..cfa5e30 100644
--- a/src/runtime/stdlib.h
+++ b/src/runtime/stdlib.h
@@ -25,6 +25,8 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+#pragma OPENCL EXTENSION cl_khr_fp64 : enable
+
/* Types */
/* Standard types from Clang's stddef and stdint, Copyright (C) 2008 Eli Friedman */
diff --git a/tests/test_builtins.cpp b/tests/test_builtins.cpp
index 80852a9..1394a27 100644
--- a/tests/test_builtins.cpp
+++ b/tests/test_builtins.cpp
@@ -109,6 +109,7 @@ const char builtins_source[] =
" if (cos(0.0f) != 1.0f) { *rs = 2; return; }\n"
" if (copysign(1.0f, -0.5f) != -1.0f) { *rs = 3; return; }\n"
" if (copysign(f2, f2b).x != -1.0f) { *rs = 4; return; }\n"
+ " if (exp2(3.0f) != 8.0f) { *rs = 5; return; }\n"
"}\n";
enum TestCaseKind
@@ -392,6 +393,9 @@ START_TEST (test_builtins)
case 4:
errstr = "float2 copysign(float2) doesn't behave correctly";
break;
+ case 5:
+ errstr = "exp2() doesn't behave correctly";
+ break;
default:
errstr = default_error(rs);
}