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

Unified Diff: src/objects-inl.h

Issue 1302513004: [simd.js] Macro-ize more SIMD code (2). (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: 2 more #undefs 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 | src/objects-printer.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/objects-inl.h
diff --git a/src/objects-inl.h b/src/objects-inl.h
index 2afd802f534629dc7b4335c677ec59388bf5c6ed..051c4ba3b7d16e54aef797fc6f8fd1a079786200 100644
--- a/src/objects-inl.h
+++ b/src/objects-inl.h
@@ -1258,6 +1258,18 @@ MaybeHandle<Object> Object::GetProperty(Isolate* isolate, Handle<Object> object,
#define WRITE_INTPTR_FIELD(p, offset, value) \
(*reinterpret_cast<intptr_t*>(FIELD_ADDR(p, offset)) = value)
+#define READ_UINT8_FIELD(p, offset) \
+ (*reinterpret_cast<const uint8_t*>(FIELD_ADDR_CONST(p, offset)))
+
+#define WRITE_UINT8_FIELD(p, offset, value) \
+ (*reinterpret_cast<uint8_t*>(FIELD_ADDR(p, offset)) = value)
+
+#define READ_INT8_FIELD(p, offset) \
+ (*reinterpret_cast<const int8_t*>(FIELD_ADDR_CONST(p, offset)))
+
+#define WRITE_INT8_FIELD(p, offset, value) \
+ (*reinterpret_cast<int8_t*>(FIELD_ADDR(p, offset)) = value)
+
#define READ_UINT16_FIELD(p, offset) \
(*reinterpret_cast<const uint16_t*>(FIELD_ADDR_CONST(p, offset)))
@@ -1544,184 +1556,71 @@ SIMD128_TYPES(SIMD128_VALUE_EQUALS)
#undef SIMD128_VALUE_EQUALS
-float Float32x4::get_lane(int lane) const {
- DCHECK(lane < 4 && lane >= 0);
-#if defined(V8_TARGET_LITTLE_ENDIAN)
- return READ_FLOAT_FIELD(this, kValueOffset + lane * kFloatSize);
-#elif defined(V8_TARGET_BIG_ENDIAN)
- return READ_FLOAT_FIELD(this, kValueOffset + (3 - lane) * kFloatSize);
-#else
-#error Unknown byte ordering
-#endif
-}
-
-
-void Float32x4::set_lane(int lane, float value) {
- DCHECK(lane < 4 && lane >= 0);
-#if defined(V8_TARGET_LITTLE_ENDIAN)
- WRITE_FLOAT_FIELD(this, kValueOffset + lane * kFloatSize, value);
-#elif defined(V8_TARGET_BIG_ENDIAN)
- WRITE_FLOAT_FIELD(this, kValueOffset + (3 - lane) * kFloatSize, value);
-#else
-#error Unknown byte ordering
-#endif
-}
-
-
-int32_t Int32x4::get_lane(int lane) const {
- DCHECK(lane < 4 && lane >= 0);
-#if defined(V8_TARGET_LITTLE_ENDIAN)
- return READ_INT32_FIELD(this, kValueOffset + lane * kInt32Size);
-#elif defined(V8_TARGET_BIG_ENDIAN)
- return READ_INT32_FIELD(this, kValueOffset + (3 - lane) * kInt32Size);
-#else
-#error Unknown byte ordering
-#endif
-}
-
-
-void Int32x4::set_lane(int lane, int32_t value) {
- DCHECK(lane < 4 && lane >= 0);
-#if defined(V8_TARGET_LITTLE_ENDIAN)
- WRITE_INT32_FIELD(this, kValueOffset + lane * kInt32Size, value);
-#elif defined(V8_TARGET_BIG_ENDIAN)
- WRITE_INT32_FIELD(this, kValueOffset + (3 - lane) * kInt32Size, value);
-#else
-#error Unknown byte ordering
-#endif
-}
-
-
-bool Bool32x4::get_lane(int lane) const {
- DCHECK(lane < 4 && lane >= 0);
- int32_t value;
-#if defined(V8_TARGET_LITTLE_ENDIAN)
- value = READ_INT32_FIELD(this, kValueOffset + lane * kInt32Size);
-#elif defined(V8_TARGET_BIG_ENDIAN)
- value = READ_INT32_FIELD(this, kValueOffset + (3 - lane) * kInt32Size);
-#else
-#error Unknown byte ordering
-#endif
- DCHECK(value == 0 || value == -1);
- return value != 0;
-}
-
-
-void Bool32x4::set_lane(int lane, bool value) {
- DCHECK(lane < 4 && lane >= 0);
- int32_t int_val = value ? -1 : 0;
-#if defined(V8_TARGET_LITTLE_ENDIAN)
- WRITE_INT32_FIELD(this, kValueOffset + lane * kInt32Size, int_val);
-#elif defined(V8_TARGET_BIG_ENDIAN)
- WRITE_INT32_FIELD(this, kValueOffset + (3 - lane) * kInt32Size, int_val);
-#else
-#error Unknown byte ordering
-#endif
-}
-
-
-int16_t Int16x8::get_lane(int lane) const {
- DCHECK(lane < 8 && lane >= 0);
-#if defined(V8_TARGET_LITTLE_ENDIAN)
- return READ_INT16_FIELD(this, kValueOffset + lane * kShortSize);
-#elif defined(V8_TARGET_BIG_ENDIAN)
- return READ_INT16_FIELD(this, kValueOffset + (7 - lane) * kShortSize);
-#else
-#error Unknown byte ordering
-#endif
-}
-
-
-void Int16x8::set_lane(int lane, int16_t value) {
- DCHECK(lane < 8 && lane >= 0);
-#if defined(V8_TARGET_LITTLE_ENDIAN)
- WRITE_INT16_FIELD(this, kValueOffset + lane * kShortSize, value);
-#elif defined(V8_TARGET_BIG_ENDIAN)
- WRITE_INT16_FIELD(this, kValueOffset + (7 - lane) * kShortSize, value);
-#else
-#error Unknown byte ordering
-#endif
-}
-
-
-bool Bool16x8::get_lane(int lane) const {
- DCHECK(lane < 8 && lane >= 0);
- int16_t value;
#if defined(V8_TARGET_LITTLE_ENDIAN)
- return READ_INT16_FIELD(this, kValueOffset + lane * kShortSize);
+#define SIMD128_READ_LANE(lane_type, lane_count, field_type, field_size) \
+ lane_type value = \
+ READ_##field_type##_FIELD(this, kValueOffset + lane * field_size);
#elif defined(V8_TARGET_BIG_ENDIAN)
- return READ_INT16_FIELD(this, kValueOffset + (7 - lane) * kShortSize);
+#define SIMD128_READ_LANE(lane_type, lane_count, field_type, field_size) \
+ lane_type value = READ_##field_type##_FIELD( \
+ this, kValueOffset + (lane_count - lane - 1) * field_size);
#else
#error Unknown byte ordering
#endif
- DCHECK(value == 0 || value == -1);
- return value != 0;
-}
-
-void Bool16x8::set_lane(int lane, bool value) {
- DCHECK(lane < 8 && lane >= 0);
- int16_t int_val = value ? -1 : 0;
#if defined(V8_TARGET_LITTLE_ENDIAN)
- WRITE_INT16_FIELD(this, kValueOffset + lane * kShortSize, int_val);
+#define SIMD128_WRITE_LANE(lane_count, field_type, field_size, value) \
+ WRITE_##field_type##_FIELD(this, kValueOffset + lane * field_size, value);
#elif defined(V8_TARGET_BIG_ENDIAN)
- WRITE_INT16_FIELD(this, kValueOffset + (7 - lane) * kShortSize, int_val);
+#define SIMD128_WRITE_LANE(lane_count, field_type, field_size, value) \
+ WRITE_##field_type##_FIELD( \
+ this, kValueOffset + (lane_count - lane - 1) * field_size, value);
#else
#error Unknown byte ordering
#endif
-}
-
-int8_t Int8x16::get_lane(int lane) const {
- DCHECK(lane < 16 && lane >= 0);
-#if defined(V8_TARGET_LITTLE_ENDIAN)
- return READ_BYTE_FIELD(this, kValueOffset + lane * kCharSize);
-#elif defined(V8_TARGET_BIG_ENDIAN)
- return READ_BYTE_FIELD(this, kValueOffset + (15 - lane) * kCharSize);
-#else
-#error Unknown byte ordering
-#endif
-}
-
-
-void Int8x16::set_lane(int lane, int8_t value) {
- DCHECK(lane < 16 && lane >= 0);
-#if defined(V8_TARGET_LITTLE_ENDIAN)
- WRITE_BYTE_FIELD(this, kValueOffset + lane * kCharSize, value);
-#elif defined(V8_TARGET_BIG_ENDIAN)
- WRITE_BYTE_FIELD(this, kValueOffset + (15 - lane) * kCharSize, value);
-#else
-#error Unknown byte ordering
-#endif
-}
-
-
-bool Bool8x16::get_lane(int lane) const {
- DCHECK(lane < 16 && lane >= 0);
- int8_t value;
-#if defined(V8_TARGET_LITTLE_ENDIAN)
- value = READ_BYTE_FIELD(this, kValueOffset + lane * kCharSize);
-#elif defined(V8_TARGET_BIG_ENDIAN)
- value = READ_BYTE_FIELD(this, kValueOffset + (15 - lane) * kCharSize);
-#else
-#error Unknown byte ordering
-#endif
- DCHECK(value == 0 || value == -1);
- return value != 0;
-}
-
-
-void Bool8x16::set_lane(int lane, bool value) {
- DCHECK(lane < 16 && lane >= 0);
- int8_t int_val = value ? -1 : 0;
-#if defined(V8_TARGET_LITTLE_ENDIAN)
- WRITE_BYTE_FIELD(this, kValueOffset + lane * kCharSize, int_val);
-#elif defined(V8_TARGET_BIG_ENDIAN)
- WRITE_BYTE_FIELD(this, kValueOffset + (15 - lane) * kCharSize, int_val);
-#else
-#error Unknown byte ordering
-#endif
-}
+#define SIMD128_NUMERIC_LANE_FNS(type, lane_type, lane_count, field_type, \
+ field_size) \
+ lane_type type::get_lane(int lane) const { \
+ DCHECK(lane < lane_count && lane >= 0); \
+ SIMD128_READ_LANE(lane_type, lane_count, field_type, field_size) \
+ return value; \
+ } \
+ \
+ void type::set_lane(int lane, lane_type value) { \
+ DCHECK(lane < lane_count && lane >= 0); \
+ SIMD128_WRITE_LANE(lane_count, field_type, field_size, value) \
+ }
+
+SIMD128_NUMERIC_LANE_FNS(Float32x4, float, 4, FLOAT, kFloatSize)
+SIMD128_NUMERIC_LANE_FNS(Int32x4, int32_t, 4, INT32, kInt32Size)
+SIMD128_NUMERIC_LANE_FNS(Int16x8, int16_t, 8, INT16, kShortSize)
+SIMD128_NUMERIC_LANE_FNS(Int8x16, int8_t, 16, INT8, kCharSize)
+#undef SIMD128_NUMERIC_LANE_FNS
+
+
+#define SIMD128_BOOLEAN_LANE_FNS(type, lane_type, lane_count, field_type, \
+ field_size) \
+ bool type::get_lane(int lane) const { \
+ DCHECK(lane < lane_count && lane >= 0); \
+ SIMD128_READ_LANE(lane_type, lane_count, field_type, field_size) \
+ DCHECK(value == 0 || value == -1); \
+ return value != 0; \
+ } \
+ \
+ void type::set_lane(int lane, bool value) { \
+ DCHECK(lane < lane_count && lane >= 0); \
+ int32_t int_val = value ? -1 : 0; \
+ SIMD128_WRITE_LANE(lane_count, field_type, field_size, int_val) \
+ }
+
+SIMD128_BOOLEAN_LANE_FNS(Bool32x4, int32_t, 4, INT32, kInt32Size)
+SIMD128_BOOLEAN_LANE_FNS(Bool16x8, int16_t, 8, INT16, kShortSize)
+SIMD128_BOOLEAN_LANE_FNS(Bool8x16, int8_t, 16, INT8, kCharSize)
+#undef SIMD128_BOOLEAN_LANE_FNS
+
+#undef SIMD128_READ_LANE
+#undef SIMD128_WRITE_LANE
ACCESSORS(JSObject, properties, FixedArray, kPropertiesOffset)
@@ -7900,6 +7799,10 @@ String::SubStringRange::iterator String::SubStringRange::end() {
#undef WRITE_INT_FIELD
#undef READ_INTPTR_FIELD
#undef WRITE_INTPTR_FIELD
+#undef READ_UINT8_FIELD
+#undef WRITE_UINT8_FIELD
+#undef READ_INT8_FIELD
+#undef WRITE_INT8_FIELD
#undef READ_UINT16_FIELD
#undef WRITE_UINT16_FIELD
#undef READ_INT16_FIELD
« no previous file with comments | « no previous file | src/objects-printer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698