Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1127)

Unified Diff: src/runtime/runtime-simd.cc

Issue 1312703003: [simd.js] Set --harmony-simd flag in test config. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | test/simdjs/testcfg.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/runtime/runtime-simd.cc
diff --git a/src/runtime/runtime-simd.cc b/src/runtime/runtime-simd.cc
index ce9512e8da4b14c73469a879861efc2ca650ce46..e1d39798d09d3047bdeff820da43de91967a651c 100644
--- a/src/runtime/runtime-simd.cc
+++ b/src/runtime/runtime-simd.cc
@@ -21,6 +21,24 @@ namespace {
// Functions to convert Numbers to SIMD component types.
+template <typename T, typename F>
+static bool CanCast(F from) {
+ // A float can't represent 2^31 - 1 or 2^32 - 1 exactly, so promote the limits
+ // to double. Otherwise, the limit is truncated and numbers like 2^31 or 2^32
+ // get through, causing any static_cast to be undefined.
+ return from >= static_cast<double>(std::numeric_limits<T>::min()) &&
+ from <= static_cast<double>(std::numeric_limits<T>::max());
+}
+
+
+// Explicitly specialize for conversions to float, which always succeed.
+template <>
+bool CanCast<float>(int32_t from) {
+ return true;
+}
+
+} // namespace
+
template <typename T>
static T ConvertNumber(double number);
@@ -111,16 +129,6 @@ inline float MaxNumber(float a, float b) {
}
-inline bool CanCast(int32_t a) { return true; }
-
-
-inline bool CanCast(float a) {
- return a > std::numeric_limits<int32_t>::min() &&
- a < std::numeric_limits<int32_t>::max();
-}
-
-} // namespace
-
//-------------------------------------------------------------------
// SIMD helper functions.
@@ -759,7 +767,7 @@ SIMD_SELECT_TYPES(SIMD_SELECT_FUNCTION)
lane_type lanes[kLaneCount]; \
for (int i = 0; i < kLaneCount; i++) { \
from_ctype a_value = a->get_lane(i); \
- RUNTIME_ASSERT(CanCast(a_value)); \
+ RUNTIME_ASSERT(CanCast<lane_type>(a_value)); \
lanes[i] = static_cast<lane_type>(a_value); \
} \
Handle<type> result = isolate->factory()->New##type(lanes); \
« no previous file with comments | « no previous file | test/simdjs/testcfg.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698