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

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

Issue 1309513005: Revert of [simd.js] Update to spec version 0.8.2. (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 | « src/runtime/runtime.h ('k') | test/cctest/test-heap.cc » ('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 a202b64306deb47dc6178d82c8b336a9b63a6164..ce9512e8da4b14c73469a879861efc2ca650ce46 100644
--- a/src/runtime/runtime-simd.cc
+++ b/src/runtime/runtime-simd.cc
@@ -21,29 +21,6 @@
// 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;
-}
-
-
-template <>
-bool CanCast<float>(uint32_t from) {
- return true;
-}
-
-
template <typename T>
static T ConvertNumber(double number);
@@ -61,32 +38,14 @@
template <>
-uint32_t ConvertNumber<uint32_t>(double number) {
- return DoubleToUint32(number);
-}
-
-
-template <>
int16_t ConvertNumber<int16_t>(double number) {
return static_cast<int16_t>(DoubleToInt32(number));
-}
-
-
-template <>
-uint16_t ConvertNumber<uint16_t>(double number) {
- return static_cast<uint16_t>(DoubleToUint32(number));
}
template <>
int8_t ConvertNumber<int8_t>(double number) {
return static_cast<int8_t>(DoubleToInt32(number));
-}
-
-
-template <>
-uint8_t ConvertNumber<uint8_t>(double number) {
- return static_cast<uint8_t>(DoubleToUint32(number));
}
@@ -110,14 +69,6 @@
}
-// Widening absolute difference for uint16_t and uint8_t.
-template <typename T>
-inline uint32_t AbsoluteDifference(T a, T b) {
- uint32_t result = std::abs(a - b);
- return result;
-}
-
-
// Saturating subtraction for int16_t and int8_t.
template <typename T>
inline T SubSaturate(T a, T b) {
@@ -157,6 +108,15 @@
if (std::isnan(a)) return b;
if (std::isnan(b)) return a;
return Max(a, 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
@@ -280,16 +240,13 @@
#define GET_BOOLEAN_ARG(lane_type, name, index) \
name = args[index]->BooleanValue();
-#define SIMD_ALL_TYPES(FUNCTION) \
- FUNCTION(Float32x4, float, 4, NewNumber, GET_NUMERIC_ARG) \
- FUNCTION(Int32x4, int32_t, 4, NewNumber, GET_NUMERIC_ARG) \
- FUNCTION(Uint32x4, uint32_t, 4, NewNumber, GET_NUMERIC_ARG) \
- FUNCTION(Bool32x4, bool, 4, ToBoolean, GET_BOOLEAN_ARG) \
- FUNCTION(Int16x8, int16_t, 8, NewNumber, GET_NUMERIC_ARG) \
- FUNCTION(Uint16x8, uint16_t, 8, NewNumber, GET_NUMERIC_ARG) \
- FUNCTION(Bool16x8, bool, 8, ToBoolean, GET_BOOLEAN_ARG) \
- FUNCTION(Int8x16, int8_t, 16, NewNumber, GET_NUMERIC_ARG) \
- FUNCTION(Uint8x16, uint8_t, 16, NewNumber, GET_NUMERIC_ARG) \
+#define SIMD_ALL_TYPES(FUNCTION) \
+ FUNCTION(Float32x4, float, 4, NewNumber, GET_NUMERIC_ARG) \
+ FUNCTION(Int32x4, int32_t, 4, NewNumber, GET_NUMERIC_ARG) \
+ FUNCTION(Bool32x4, bool, 4, ToBoolean, GET_BOOLEAN_ARG) \
+ FUNCTION(Int16x8, int16_t, 8, NewNumber, GET_NUMERIC_ARG) \
+ FUNCTION(Bool16x8, bool, 8, ToBoolean, GET_BOOLEAN_ARG) \
+ FUNCTION(Int8x16, int8_t, 16, NewNumber, GET_NUMERIC_ARG) \
FUNCTION(Bool8x16, bool, 16, ToBoolean, GET_BOOLEAN_ARG)
#define SIMD_CREATE_FUNCTION(type, lane_type, lane_count, extract, replace) \
@@ -446,11 +403,6 @@
FUNCTION(Int16x8, int16_t, 16, 8) \
FUNCTION(Int8x16, int8_t, 8, 16)
-#define SIMD_UINT_TYPES(FUNCTION) \
- FUNCTION(Uint32x4, uint32_t, 32, 4) \
- FUNCTION(Uint16x8, uint16_t, 16, 8) \
- FUNCTION(Uint8x16, uint8_t, 8, 16)
-
#define CONVERT_SHIFT_ARG_CHECKED(name, index) \
RUNTIME_ASSERT(args[index]->IsNumber()); \
int32_t signed_shift = 0; \
@@ -485,7 +437,7 @@
if (shift < lane_bits) { \
for (int i = 0; i < kLaneCount; i++) { \
lanes[i] = static_cast<lane_type>( \
- bit_cast<lane_type>(a->get_lane(i)) >> shift); \
+ bit_cast<u##lane_type>(a->get_lane(i)) >> shift); \
} \
} \
Handle<type> result = isolate->factory()->New##type(lanes); \
@@ -509,23 +461,9 @@
return *result; \
}
-#define SIMD_HORIZONTAL_SUM_FUNCTION(type, lane_type, lane_bits, lane_count) \
- RUNTIME_FUNCTION(Runtime_##type##HorizontalSum) { \
- HandleScope scope(isolate); \
- DCHECK(args.length() == 1); \
- CONVERT_ARG_HANDLE_CHECKED(type, a, 0); \
- double sum = 0; \
- for (int i = 0; i < lane_count; i++) { \
- sum += a->get_lane(i); \
- } \
- return *isolate->factory()->NewNumber(sum); \
- }
-
SIMD_INT_TYPES(SIMD_LSL_FUNCTION)
-SIMD_UINT_TYPES(SIMD_LSL_FUNCTION)
+SIMD_INT_TYPES(SIMD_LSR_FUNCTION)
SIMD_INT_TYPES(SIMD_ASR_FUNCTION)
-SIMD_UINT_TYPES(SIMD_LSR_FUNCTION)
-SIMD_UINT_TYPES(SIMD_HORIZONTAL_SUM_FUNCTION)
//-------------------------------------------------------------------
@@ -575,9 +513,7 @@
#define SIMD_SMALL_INT_TYPES(FUNCTION) \
FUNCTION(Int16x8, int16_t, 8) \
- FUNCTION(Uint16x8, uint16_t, 8) \
- FUNCTION(Int8x16, int8_t, 16) \
- FUNCTION(Uint8x16, uint8_t, 16)
+ FUNCTION(Int8x16, int8_t, 16)
#define SIMD_ADD_SATURATE_FUNCTION(type, lane_type, lane_count) \
RUNTIME_FUNCTION(Runtime_##type##AddSaturate) { \
@@ -599,51 +535,20 @@
//-------------------------------------------------------------------
-// Small Unsigned int-only functions.
-
-#define SIMD_SMALL_UINT_TYPES(FUNCTION) \
- FUNCTION(Uint16x8, uint16_t, 8, Uint32x4, uint32_t) \
- FUNCTION(Uint8x16, uint8_t, 16, Uint16x8, uint16_t)
-
-#define SIMD_ABS_DIFF_FUNCTION(type, lane_type, lane_count, wide_type, \
- wide_ctype) \
- RUNTIME_FUNCTION(Runtime_##type##AbsoluteDifference) { \
- HandleScope scope(isolate); \
- SIMD_BINARY_OP(type, lane_type, lane_count, AbsoluteDifference, result); \
- return *result; \
- }
-
-#define SIMD_WIDE_ABS_DIFF_FUNCTION(type, lane_type, lane_count, wide_type, \
- wide_ctype) \
- RUNTIME_FUNCTION(Runtime_##type##WidenedAbsoluteDifference) { \
- HandleScope scope(isolate); \
- static const int kLaneCount = lane_count / 2; \
- DCHECK(args.length() == 2); \
- CONVERT_ARG_HANDLE_CHECKED(type, a, 0); \
- CONVERT_ARG_HANDLE_CHECKED(type, b, 1); \
- wide_ctype lanes[kLaneCount]; \
- for (int i = 0; i < kLaneCount; i++) { \
- lanes[i] = AbsoluteDifference(a->get_lane(i), b->get_lane(i)); \
- } \
- Handle<wide_type> result = isolate->factory()->New##wide_type(lanes); \
- return *result; \
- }
-
-SIMD_SMALL_UINT_TYPES(SIMD_ABS_DIFF_FUNCTION)
-SIMD_SMALL_UINT_TYPES(SIMD_WIDE_ABS_DIFF_FUNCTION)
-
-//-------------------------------------------------------------------
-
// Numeric functions.
#define SIMD_NUMERIC_TYPES(FUNCTION) \
FUNCTION(Float32x4, float, 4) \
FUNCTION(Int32x4, int32_t, 4) \
- FUNCTION(Uint32x4, uint32_t, 4) \
FUNCTION(Int16x8, int16_t, 8) \
- FUNCTION(Uint16x8, uint16_t, 8) \
- FUNCTION(Int8x16, int8_t, 16) \
- FUNCTION(Uint8x16, uint8_t, 16)
+ FUNCTION(Int8x16, int8_t, 16)
+
+#define SIMD_NEG_FUNCTION(type, lane_type, lane_count) \
+ RUNTIME_FUNCTION(Runtime_##type##Neg) { \
+ HandleScope scope(isolate); \
+ SIMD_UNARY_OP(type, lane_type, lane_count, -, result); \
+ return *result; \
+ }
#define BINARY_ADD(a, b) (a) + (b)
#define SIMD_ADD_FUNCTION(type, lane_type, lane_count) \
@@ -683,6 +588,7 @@
return *result; \
}
+SIMD_NUMERIC_TYPES(SIMD_NEG_FUNCTION)
SIMD_NUMERIC_TYPES(SIMD_ADD_FUNCTION)
SIMD_NUMERIC_TYPES(SIMD_SUB_FUNCTION)
SIMD_NUMERIC_TYPES(SIMD_MUL_FUNCTION)
@@ -696,11 +602,8 @@
#define SIMD_RELATIONAL_TYPES(FUNCTION) \
FUNCTION(Float32x4, Bool32x4, 4) \
FUNCTION(Int32x4, Bool32x4, 4) \
- FUNCTION(Uint32x4, Bool32x4, 4) \
FUNCTION(Int16x8, Bool16x8, 8) \
- FUNCTION(Uint16x8, Bool16x8, 8) \
- FUNCTION(Int8x16, Bool8x16, 16) \
- FUNCTION(Uint8x16, Bool8x16, 16)
+ FUNCTION(Int8x16, Bool8x16, 16)
#define SIMD_EQUALITY_TYPES(FUNCTION) \
SIMD_RELATIONAL_TYPES(FUNCTION) \
@@ -762,15 +665,12 @@
// Logical functions.
-#define SIMD_LOGICAL_TYPES(FUNCTION) \
- FUNCTION(Int32x4, int32_t, 4, _INT) \
- FUNCTION(Uint32x4, uint32_t, 4, _INT) \
- FUNCTION(Int16x8, int16_t, 8, _INT) \
- FUNCTION(Uint16x8, uint16_t, 8, _INT) \
- FUNCTION(Int8x16, int8_t, 16, _INT) \
- FUNCTION(Uint8x16, uint8_t, 16, _INT) \
- FUNCTION(Bool32x4, bool, 4, _BOOL) \
- FUNCTION(Bool16x8, bool, 8, _BOOL) \
+#define SIMD_LOGICAL_TYPES(FUNCTION) \
+ FUNCTION(Int32x4, int32_t, 4, _INT) \
+ FUNCTION(Int16x8, int16_t, 8, _INT) \
+ FUNCTION(Int8x16, int8_t, 16, _INT) \
+ FUNCTION(Bool32x4, bool, 4, _BOOL) \
+ FUNCTION(Bool16x8, bool, 8, _BOOL) \
FUNCTION(Bool8x16, bool, 16, _BOOL)
#define BINARY_AND_INT(a, b) (a) & (b)
@@ -818,14 +718,11 @@
// Select functions.
-#define SIMD_SELECT_TYPES(FUNCTION) \
- FUNCTION(Float32x4, float, Bool32x4, 4) \
- FUNCTION(Int32x4, int32_t, Bool32x4, 4) \
- FUNCTION(Uint32x4, uint32_t, Bool32x4, 4) \
- FUNCTION(Int16x8, int16_t, Bool16x8, 8) \
- FUNCTION(Uint16x8, uint16_t, Bool16x8, 8) \
- FUNCTION(Int8x16, int8_t, Bool8x16, 16) \
- FUNCTION(Uint8x16, uint8_t, Bool8x16, 16)
+#define SIMD_SELECT_TYPES(FUNCTION) \
+ FUNCTION(Float32x4, float, Bool32x4, 4) \
+ FUNCTION(Int32x4, int32_t, Bool32x4, 4) \
+ FUNCTION(Int16x8, int16_t, Bool16x8, 8) \
+ FUNCTION(Int8x16, int8_t, Bool8x16, 16)
#define SIMD_SELECT_FUNCTION(type, lane_type, bool_type, lane_count) \
RUNTIME_FUNCTION(Runtime_##type##Select) { \
@@ -847,38 +744,11 @@
//-------------------------------------------------------------------
-// Signed / unsigned functions.
-
-#define SIMD_SIGNED_TYPES(FUNCTION) \
- FUNCTION(Float32x4, float, 4) \
- FUNCTION(Int32x4, int32_t, 4) \
- FUNCTION(Int16x8, int16_t, 8) \
- FUNCTION(Int8x16, int8_t, 16)
-
-#define SIMD_NEG_FUNCTION(type, lane_type, lane_count) \
- RUNTIME_FUNCTION(Runtime_##type##Neg) { \
- HandleScope scope(isolate); \
- SIMD_UNARY_OP(type, lane_type, lane_count, -, result); \
- return *result; \
- }
-
-SIMD_SIGNED_TYPES(SIMD_NEG_FUNCTION)
-
-//-------------------------------------------------------------------
-
// Casting functions.
-#define SIMD_FROM_TYPES(FUNCTION) \
- FUNCTION(Float32x4, float, 4, Int32x4, int32_t) \
- FUNCTION(Float32x4, float, 4, Uint32x4, uint32_t) \
- FUNCTION(Int32x4, int32_t, 4, Float32x4, float) \
- FUNCTION(Int32x4, int32_t, 4, Uint32x4, uint32_t) \
- FUNCTION(Uint32x4, uint32_t, 4, Float32x4, float) \
- FUNCTION(Uint32x4, uint32_t, 4, Int32x4, int32_t) \
- FUNCTION(Int16x8, int16_t, 8, Uint16x8, uint16_t) \
- FUNCTION(Uint16x8, uint16_t, 8, Int16x8, int16_t) \
- FUNCTION(Int8x16, int8_t, 16, Uint8x16, uint8_t) \
- FUNCTION(Uint8x16, uint8_t, 16, Int8x16, int8_t)
+#define SIMD_FROM_TYPES(FUNCTION) \
+ FUNCTION(Float32x4, float, 4, Int32x4, int32_t) \
+ FUNCTION(Int32x4, int32_t, 4, Float32x4, float)
#define SIMD_FROM_FUNCTION(type, lane_type, lane_count, from_type, from_ctype) \
RUNTIME_FUNCTION(Runtime_##type##From##from_type) { \
@@ -889,8 +759,7 @@
lane_type lanes[kLaneCount]; \
for (int i = 0; i < kLaneCount; i++) { \
from_ctype a_value = a->get_lane(i); \
- if (a_value != a_value) a_value = 0; \
- RUNTIME_ASSERT(CanCast<lane_type>(a_value)); \
+ RUNTIME_ASSERT(CanCast(a_value)); \
lanes[i] = static_cast<lane_type>(a_value); \
} \
Handle<type> result = isolate->factory()->New##type(lanes); \
@@ -899,49 +768,19 @@
SIMD_FROM_TYPES(SIMD_FROM_FUNCTION)
-#define SIMD_FROM_BITS_TYPES(FUNCTION) \
- FUNCTION(Float32x4, float, 4, Int32x4) \
- FUNCTION(Float32x4, float, 4, Uint32x4) \
- FUNCTION(Float32x4, float, 4, Int16x8) \
- FUNCTION(Float32x4, float, 4, Uint16x8) \
- FUNCTION(Float32x4, float, 4, Int8x16) \
- FUNCTION(Float32x4, float, 4, Uint8x16) \
- FUNCTION(Int32x4, int32_t, 4, Float32x4) \
- FUNCTION(Int32x4, int32_t, 4, Uint32x4) \
- FUNCTION(Int32x4, int32_t, 4, Int16x8) \
- FUNCTION(Int32x4, int32_t, 4, Uint16x8) \
- FUNCTION(Int32x4, int32_t, 4, Int8x16) \
- FUNCTION(Int32x4, int32_t, 4, Uint8x16) \
- FUNCTION(Uint32x4, uint32_t, 4, Float32x4) \
- FUNCTION(Uint32x4, uint32_t, 4, Int32x4) \
- FUNCTION(Uint32x4, uint32_t, 4, Int16x8) \
- FUNCTION(Uint32x4, uint32_t, 4, Uint16x8) \
- FUNCTION(Uint32x4, uint32_t, 4, Int8x16) \
- FUNCTION(Uint32x4, uint32_t, 4, Uint8x16) \
- FUNCTION(Int16x8, int16_t, 8, Float32x4) \
- FUNCTION(Int16x8, int16_t, 8, Int32x4) \
- FUNCTION(Int16x8, int16_t, 8, Uint32x4) \
- FUNCTION(Int16x8, int16_t, 8, Uint16x8) \
- FUNCTION(Int16x8, int16_t, 8, Int8x16) \
- FUNCTION(Int16x8, int16_t, 8, Uint8x16) \
- FUNCTION(Uint16x8, uint16_t, 8, Float32x4) \
- FUNCTION(Uint16x8, uint16_t, 8, Int32x4) \
- FUNCTION(Uint16x8, uint16_t, 8, Uint32x4) \
- FUNCTION(Uint16x8, uint16_t, 8, Int16x8) \
- FUNCTION(Uint16x8, uint16_t, 8, Int8x16) \
- FUNCTION(Uint16x8, uint16_t, 8, Uint8x16) \
- FUNCTION(Int8x16, int8_t, 16, Float32x4) \
- FUNCTION(Int8x16, int8_t, 16, Int32x4) \
- FUNCTION(Int8x16, int8_t, 16, Uint32x4) \
- FUNCTION(Int8x16, int8_t, 16, Int16x8) \
- FUNCTION(Int8x16, int8_t, 16, Uint16x8) \
- FUNCTION(Int8x16, int8_t, 16, Uint8x16) \
- FUNCTION(Uint8x16, uint8_t, 16, Float32x4) \
- FUNCTION(Uint8x16, uint8_t, 16, Int32x4) \
- FUNCTION(Uint8x16, uint8_t, 16, Uint32x4) \
- FUNCTION(Uint8x16, uint8_t, 16, Int16x8) \
- FUNCTION(Uint8x16, uint8_t, 16, Uint16x8) \
- FUNCTION(Uint8x16, uint8_t, 16, Int8x16)
+#define SIMD_FROM_BITS_TYPES(FUNCTION) \
+ FUNCTION(Float32x4, float, 4, Int32x4) \
+ FUNCTION(Float32x4, float, 4, Int16x8) \
+ FUNCTION(Float32x4, float, 4, Int8x16) \
+ FUNCTION(Int32x4, int32_t, 4, Float32x4) \
+ FUNCTION(Int32x4, int32_t, 4, Int16x8) \
+ FUNCTION(Int32x4, int32_t, 4, Int8x16) \
+ FUNCTION(Int16x8, int16_t, 8, Float32x4) \
+ FUNCTION(Int16x8, int16_t, 8, Int32x4) \
+ FUNCTION(Int16x8, int16_t, 8, Int8x16) \
+ FUNCTION(Int8x16, int8_t, 16, Float32x4) \
+ FUNCTION(Int8x16, int8_t, 16, Int32x4) \
+ FUNCTION(Int8x16, int8_t, 16, Int16x8)
#define SIMD_FROM_BITS_FUNCTION(type, lane_type, lane_count, from_type) \
RUNTIME_FUNCTION(Runtime_##type##From##from_type##Bits) { \
@@ -957,5 +796,26 @@
SIMD_FROM_BITS_TYPES(SIMD_FROM_BITS_FUNCTION)
+//-------------------------------------------------------------------
+
+// Unsigned extract functions.
+// TODO(bbudge): remove when spec changes to include unsigned int types.
+
+RUNTIME_FUNCTION(Runtime_Int16x8UnsignedExtractLane) {
+ HandleScope scope(isolate);
+ DCHECK(args.length() == 2);
+ CONVERT_ARG_HANDLE_CHECKED(Int16x8, a, 0);
+ CONVERT_SIMD_LANE_ARG_CHECKED(lane, 1, 8);
+ return *isolate->factory()->NewNumber(bit_cast<uint16_t>(a->get_lane(lane)));
+}
+
+
+RUNTIME_FUNCTION(Runtime_Int8x16UnsignedExtractLane) {
+ HandleScope scope(isolate);
+ DCHECK(args.length() == 2);
+ CONVERT_ARG_HANDLE_CHECKED(Int8x16, a, 0);
+ CONVERT_SIMD_LANE_ARG_CHECKED(lane, 1, 16);
+ return *isolate->factory()->NewNumber(bit_cast<uint8_t>(a->get_lane(lane)));
+}
} // namespace internal
} // namespace v8
« no previous file with comments | « src/runtime/runtime.h ('k') | test/cctest/test-heap.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698