[simd.js] Add SIMD load functions for Phase 1.

Float32x4, Int32x4, Uint32x4:
  load, load1, load2, load3

Int16x8, Int8x16, Uint16x8, Uint8x16:
  load

BUG=v8:4124
LOG=N

Review URL: https://codereview.chromium.org/1302133002

Cr-Commit-Position: refs/heads/master@{#30422}
This commit is contained in:
gdeepti 2015-08-27 09:35:37 -07:00 committed by Commit bot
parent ab5146925e
commit a6754d8c3c
3 changed files with 125 additions and 0 deletions

View File

@ -243,6 +243,10 @@ function NAMEGreaterThanJS(a, b) {
function NAMEGreaterThanOrEqualJS(a, b) {
return %NAMEGreaterThanOrEqual(a, b);
}
function NAMELoadJS(tarray, index) {
return %NAMELoad(tarray, index);
}
endmacro
SIMD_NUMERIC_TYPES(DECLARE_NUMERIC_FUNCTIONS)
@ -347,6 +351,27 @@ endmacro
SIMD_FROM_BITS_TYPES(DECLARE_FROM_BITS_FUNCTIONS)
macro SIMD_LOADN_STOREN_TYPES(FUNCTION)
FUNCTION(Float32x4, 1)
FUNCTION(Float32x4, 2)
FUNCTION(Float32x4, 3)
FUNCTION(Int32x4, 1)
FUNCTION(Int32x4, 2)
FUNCTION(Int32x4, 3)
FUNCTION(Uint32x4, 1)
FUNCTION(Uint32x4, 2)
FUNCTION(Uint32x4, 3)
endmacro
macro DECLARE_LOADN_STOREN_FUNCTIONS(NAME, COUNT)
function NAMELoadCOUNTJS(tarray, index) {
return %NAMELoadCOUNT(tarray, index);
}
endmacro
SIMD_LOADN_STOREN_TYPES(DECLARE_LOADN_STOREN_FUNCTIONS)
//-------------------------------------------------------------------
macro SIMD_X4_TYPES(FUNCTION)
@ -599,6 +624,10 @@ utils.InstallFunctions(GlobalFloat32x4, DONT_ENUM, [
'fromUint16x8Bits', Float32x4FromUint16x8BitsJS,
'fromInt8x16Bits', Float32x4FromInt8x16BitsJS,
'fromUint8x16Bits', Float32x4FromUint8x16BitsJS,
'load', Float32x4LoadJS,
'load1', Float32x4Load1JS,
'load2', Float32x4Load2JS,
'load3', Float32x4Load3JS,
]);
utils.InstallFunctions(GlobalInt32x4, DONT_ENUM, [
@ -635,6 +664,10 @@ utils.InstallFunctions(GlobalInt32x4, DONT_ENUM, [
'fromUint16x8Bits', Int32x4FromUint16x8BitsJS,
'fromInt8x16Bits', Int32x4FromInt8x16BitsJS,
'fromUint8x16Bits', Int32x4FromUint8x16BitsJS,
'load', Int32x4LoadJS,
'load1', Int32x4Load1JS,
'load2', Int32x4Load2JS,
'load3', Int32x4Load3JS,
]);
utils.InstallFunctions(GlobalUint32x4, DONT_ENUM, [
@ -671,6 +704,10 @@ utils.InstallFunctions(GlobalUint32x4, DONT_ENUM, [
'fromUint16x8Bits', Uint32x4FromUint16x8BitsJS,
'fromInt8x16Bits', Uint32x4FromInt8x16BitsJS,
'fromUint8x16Bits', Uint32x4FromUint8x16BitsJS,
'load', Uint32x4LoadJS,
'load1', Uint32x4Load1JS,
'load2', Uint32x4Load2JS,
'load3', Uint32x4Load3JS,
]);
utils.InstallFunctions(GlobalBool32x4, DONT_ENUM, [
@ -723,6 +760,7 @@ utils.InstallFunctions(GlobalInt16x8, DONT_ENUM, [
'fromUint16x8Bits', Int16x8FromUint16x8BitsJS,
'fromInt8x16Bits', Int16x8FromInt8x16BitsJS,
'fromUint8x16Bits', Int16x8FromUint8x16BitsJS,
'load', Int16x8LoadJS,
]);
utils.InstallFunctions(GlobalUint16x8, DONT_ENUM, [
@ -762,6 +800,7 @@ utils.InstallFunctions(GlobalUint16x8, DONT_ENUM, [
'fromInt16x8Bits', Uint16x8FromInt16x8BitsJS,
'fromInt8x16Bits', Uint16x8FromInt8x16BitsJS,
'fromUint8x16Bits', Uint16x8FromUint8x16BitsJS,
'load', Uint16x8LoadJS,
]);
utils.InstallFunctions(GlobalBool16x8, DONT_ENUM, [
@ -814,6 +853,7 @@ utils.InstallFunctions(GlobalInt8x16, DONT_ENUM, [
'fromInt16x8Bits', Int8x16FromInt16x8BitsJS,
'fromUint16x8Bits', Int8x16FromUint16x8BitsJS,
'fromUint8x16Bits', Int8x16FromUint8x16BitsJS,
'load', Int8x16LoadJS,
]);
utils.InstallFunctions(GlobalUint8x16, DONT_ENUM, [
@ -853,6 +893,7 @@ utils.InstallFunctions(GlobalUint8x16, DONT_ENUM, [
'fromInt16x8Bits', Uint8x16FromInt16x8BitsJS,
'fromUint16x8Bits', Uint8x16FromUint16x8BitsJS,
'fromInt8x16Bits', Uint8x16FromInt8x16BitsJS,
'load', Uint8x16LoadJS,
]);
utils.InstallFunctions(GlobalBool8x16, DONT_ENUM, [

View File

@ -957,5 +957,73 @@ SIMD_FROM_TYPES(SIMD_FROM_FUNCTION)
SIMD_FROM_BITS_TYPES(SIMD_FROM_BITS_FUNCTION)
//-------------------------------------------------------------------
// Load functions.
#define SIMD_LOADN_STOREN_TYPES(FUNCTION) \
FUNCTION(Float32x4, float, 4) \
FUNCTION(Int32x4, int32_t, 4) \
FUNCTION(Uint32x4, uint32_t, 4)
// Common Load Functions
#define SIMD_LOAD(type, lane_type, lane_count, count, result) \
static const int kLaneCount = lane_count; \
DCHECK(args.length() == 2); \
CONVERT_ARG_HANDLE_CHECKED(JSTypedArray, tarray, 0); \
CONVERT_INT32_ARG_CHECKED(index, 1) \
size_t bpe = tarray->element_size(); \
uint32_t bytes = count * sizeof(lane_type); \
size_t byte_length = NumberToSize(isolate, tarray->byte_length()); \
RUNTIME_ASSERT(index >= 0 && index * bpe + bytes <= byte_length); \
size_t tarray_offset = NumberToSize(isolate, tarray->byte_offset()); \
uint8_t* tarray_base = \
static_cast<uint8_t*>(tarray->GetBuffer()->backing_store()) + \
tarray_offset; \
lane_type lanes[kLaneCount] = {0}; \
memcpy(lanes, tarray_base + index * bpe, bytes); \
Handle<type> result = isolate->factory()->New##type(lanes);
#define SIMD_LOAD_FUNCTION(type, lane_type, lane_count) \
RUNTIME_FUNCTION(Runtime_##type##Load) { \
HandleScope scope(isolate); \
SIMD_LOAD(type, lane_type, lane_count, lane_count, result); \
return *result; \
}
#define SIMD_LOAD1_FUNCTION(type, lane_type, lane_count) \
RUNTIME_FUNCTION(Runtime_##type##Load1) { \
HandleScope scope(isolate); \
SIMD_LOAD(type, lane_type, lane_count, 1, result); \
return *result; \
}
#define SIMD_LOAD2_FUNCTION(type, lane_type, lane_count) \
RUNTIME_FUNCTION(Runtime_##type##Load2) { \
HandleScope scope(isolate); \
SIMD_LOAD(type, lane_type, lane_count, 2, result); \
return *result; \
}
#define SIMD_LOAD3_FUNCTION(type, lane_type, lane_count) \
RUNTIME_FUNCTION(Runtime_##type##Load3) { \
HandleScope scope(isolate); \
SIMD_LOAD(type, lane_type, lane_count, 3, result); \
return *result; \
}
SIMD_NUMERIC_TYPES(SIMD_LOAD_FUNCTION)
SIMD_LOADN_STOREN_TYPES(SIMD_LOAD1_FUNCTION)
SIMD_LOADN_STOREN_TYPES(SIMD_LOAD2_FUNCTION)
SIMD_LOADN_STOREN_TYPES(SIMD_LOAD3_FUNCTION)
//-------------------------------------------------------------------
} // namespace internal
} // namespace v8

View File

@ -611,6 +611,10 @@ namespace internal {
F(Float32x4FromUint16x8Bits, 1, 1) \
F(Float32x4FromInt8x16Bits, 1, 1) \
F(Float32x4FromUint8x16Bits, 1, 1) \
F(Float32x4Load, 2, 1) \
F(Float32x4Load1, 2, 1) \
F(Float32x4Load2, 2, 1) \
F(Float32x4Load3, 2, 1) \
F(Int32x4Check, 1, 1) \
F(Int32x4ExtractLane, 2, 1) \
F(Int32x4ReplaceLane, 3, 1) \
@ -643,6 +647,10 @@ namespace internal {
F(Int32x4FromUint16x8Bits, 1, 1) \
F(Int32x4FromInt8x16Bits, 1, 1) \
F(Int32x4FromUint8x16Bits, 1, 1) \
F(Int32x4Load, 2, 1) \
F(Int32x4Load1, 2, 1) \
F(Int32x4Load2, 2, 1) \
F(Int32x4Load3, 2, 1) \
F(Uint32x4Check, 1, 1) \
F(Uint32x4ExtractLane, 2, 1) \
F(Uint32x4ReplaceLane, 3, 1) \
@ -675,6 +683,10 @@ namespace internal {
F(Uint32x4FromUint16x8Bits, 1, 1) \
F(Uint32x4FromInt8x16Bits, 1, 1) \
F(Uint32x4FromUint8x16Bits, 1, 1) \
F(Uint32x4Load, 2, 1) \
F(Uint32x4Load1, 2, 1) \
F(Uint32x4Load2, 2, 1) \
F(Uint32x4Load3, 2, 1) \
F(Bool32x4Check, 1, 1) \
F(Bool32x4ExtractLane, 2, 1) \
F(Bool32x4ReplaceLane, 3, 1) \
@ -719,6 +731,7 @@ namespace internal {
F(Int16x8FromUint16x8Bits, 1, 1) \
F(Int16x8FromInt8x16Bits, 1, 1) \
F(Int16x8FromUint8x16Bits, 1, 1) \
F(Int16x8Load, 2, 1) \
F(Uint16x8Check, 1, 1) \
F(Uint16x8ExtractLane, 2, 1) \
F(Uint16x8ReplaceLane, 3, 1) \
@ -754,6 +767,7 @@ namespace internal {
F(Uint16x8FromInt16x8Bits, 1, 1) \
F(Uint16x8FromInt8x16Bits, 1, 1) \
F(Uint16x8FromUint8x16Bits, 1, 1) \
F(Uint16x8Load, 2, 1) \
F(Bool16x8Check, 1, 1) \
F(Bool16x8ExtractLane, 2, 1) \
F(Bool16x8ReplaceLane, 3, 1) \
@ -798,6 +812,7 @@ namespace internal {
F(Int8x16FromInt16x8Bits, 1, 1) \
F(Int8x16FromUint16x8Bits, 1, 1) \
F(Int8x16FromUint8x16Bits, 1, 1) \
F(Int8x16Load, 2, 1) \
F(Uint8x16Check, 1, 1) \
F(Uint8x16ExtractLane, 2, 1) \
F(Uint8x16ReplaceLane, 3, 1) \
@ -833,6 +848,7 @@ namespace internal {
F(Uint8x16FromInt16x8Bits, 1, 1) \
F(Uint8x16FromUint16x8Bits, 1, 1) \
F(Uint8x16FromInt8x16Bits, 1, 1) \
F(Uint8x16Load, 2, 1) \
F(Bool8x16Check, 1, 1) \
F(Bool8x16ExtractLane, 2, 1) \
F(Bool8x16ReplaceLane, 3, 1) \