Commit 5d8c1054 authored by bbudge's avatar bbudge Committed by Commit bot

SIMD.js: Update Float32x4 and tests to current spec.

LOG=N
BUG=v8:4124

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

Cr-Commit-Position: refs/heads/master@{#29781}
parent 0c53c669
...@@ -44,7 +44,20 @@ function Float32x4ToString() { ...@@ -44,7 +44,20 @@ function Float32x4ToString() {
x = GlobalFloat32x4.extractLane(value, 1), x = GlobalFloat32x4.extractLane(value, 1),
y = GlobalFloat32x4.extractLane(value, 2), y = GlobalFloat32x4.extractLane(value, 2),
z = GlobalFloat32x4.extractLane(value, 3); z = GlobalFloat32x4.extractLane(value, 3);
return "Float32x4(" + w + ", " + x + ", " + y + ", " + z + ")"; return "SIMD.Float32x4(" + w + ", " + x + ", " + y + ", " + z + ")";
}
function Float32x4ToLocaleString() {
if (!(IS_FLOAT32X4(this) || IS_FLOAT32X4_WRAPPER(this))) {
throw MakeTypeError(kIncompatibleMethodReceiver,
"Float32x4.prototype.toLocaleString", this);
}
var value = %_ValueOf(this);
var w = GlobalFloat32x4.extractLane(value, 0).toLocaleString(),
x = GlobalFloat32x4.extractLane(value, 1).toLocaleString(),
y = GlobalFloat32x4.extractLane(value, 2).toLocaleString(),
z = GlobalFloat32x4.extractLane(value, 3).toLocaleString();
return "SIMD.Float32x4(" + w + ", " + x + ", " + y + ", " + z + ")";
} }
function Float32x4ValueOf() { function Float32x4ValueOf() {
...@@ -64,18 +77,19 @@ function Float32x4ExtractLaneJS(value, lane) { ...@@ -64,18 +77,19 @@ function Float32x4ExtractLaneJS(value, lane) {
// ------------------------------------------------------------------- // -------------------------------------------------------------------
%AddNamedProperty(GlobalSIMD, symbolToStringTag, 'SIMD', READ_ONLY | DONT_ENUM); %AddNamedProperty(GlobalSIMD, symbolToStringTag, 'SIMD', READ_ONLY | DONT_ENUM);
%AddNamedProperty(GlobalSIMD, 'float32x4', GlobalFloat32x4, DONT_ENUM);
%SetCode(GlobalFloat32x4, Float32x4Constructor); %SetCode(GlobalFloat32x4, Float32x4Constructor);
%FunctionSetPrototype(GlobalFloat32x4, {}); %FunctionSetPrototype(GlobalFloat32x4, {});
%AddNamedProperty( %AddNamedProperty(
GlobalFloat32x4.prototype, 'constructor', GlobalFloat32x4, DONT_ENUM); GlobalFloat32x4.prototype, 'constructor', GlobalFloat32x4, DONT_ENUM);
%AddNamedProperty( %AddNamedProperty(
GlobalFloat32x4, symbolToStringTag, 'Float32x4', DONT_ENUM | READ_ONLY); GlobalFloat32x4.prototype, symbolToStringTag, 'Float32x4',
DONT_ENUM | READ_ONLY);
utils.InstallFunctions(GlobalFloat32x4.prototype, DONT_ENUM, [ utils.InstallFunctions(GlobalFloat32x4.prototype, DONT_ENUM, [
'valueOf', Float32x4ValueOf, 'toLocaleString', Float32x4ToLocaleString,
'toString', Float32x4ToString, 'toString', Float32x4ToString,
'valueOf', Float32x4ValueOf,
]); ]);
utils.InstallFunctions(GlobalFloat32x4, DONT_ENUM, [ utils.InstallFunctions(GlobalFloat32x4, DONT_ENUM, [
......
...@@ -488,7 +488,7 @@ TEST(HeapSnapshotFloat32x4) { ...@@ -488,7 +488,7 @@ TEST(HeapSnapshotFloat32x4) {
v8::HandleScope scope(env->GetIsolate()); v8::HandleScope scope(env->GetIsolate());
v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
CompileRun("a = SIMD.float32x4(1, 2, 3, 4);\n"); CompileRun("a = SIMD.Float32x4(1, 2, 3, 4);\n");
const v8::HeapSnapshot* snapshot = heap_profiler->TakeHeapSnapshot(); const v8::HeapSnapshot* snapshot = heap_profiler->TakeHeapSnapshot();
CHECK(ValidateSnapshot(snapshot)); CHECK(ValidateSnapshot(snapshot));
const v8::HeapGraphNode* global = GetGlobalObject(snapshot); const v8::HeapGraphNode* global = GetGlobalObject(snapshot);
......
...@@ -15,12 +15,12 @@ function lanesForType(typeName) { ...@@ -15,12 +15,12 @@ function lanesForType(typeName) {
function isValidSimdString(string, value, type, lanes) { function isValidSimdString(string, value, type, lanes) {
var simdFn = SIMD[type], var simdFn = SIMD[type],
parseFn = parseFn =
type.indexOf('float') === 0 ? Number.parseFloat : Number.parseInt, type.indexOf('Float') === 0 ? Number.parseFloat : Number.parseInt,
indexOfOpenParen = string.indexOf('('); indexOfOpenParen = string.indexOf('(');
// Check prefix for correct type name. // Check prefix (e.g. SIMD.Float32x4.)
if (string.substr(0, indexOfOpenParen).toUpperCase() !== type.toUpperCase()) if (string.substr(0, indexOfOpenParen) !== 'SIMD.' + type)
return false; return false;
// Remove type name and open parenthesis. // Remove type name (e.g. SIMD.Float32x4) and open parenthesis.
string = string.substr(indexOfOpenParen + 1); string = string.substr(indexOfOpenParen + 1);
var laneStrings = string.split(','); var laneStrings = string.split(',');
if (laneStrings.length !== lanes) if (laneStrings.length !== lanes)
...@@ -90,7 +90,7 @@ function TestConstructor(type, lanes) { ...@@ -90,7 +90,7 @@ function TestConstructor(type, lanes) {
// The constructor expects values for all lanes. // The constructor expects values for all lanes.
switch (type) { switch (type) {
case 'float32x4': case 'Float32x4':
// The constructor expects values for all lanes. // The constructor expects values for all lanes.
assertThrows(function () { simdFn() }, TypeError) assertThrows(function () { simdFn() }, TypeError)
assertThrows(function () { simdFn(0) }, TypeError) assertThrows(function () { simdFn(0) }, TypeError)
...@@ -115,12 +115,13 @@ function TestConstructor(type, lanes) { ...@@ -115,12 +115,13 @@ function TestConstructor(type, lanes) {
function TestType(type, lanes) { function TestType(type, lanes) {
var typeofString = type.charAt(0).toLowerCase() + type.slice(1);
for (var i in values) { for (var i in values) {
assertEquals(type, typeof values[i]) assertEquals(typeofString, typeof values[i])
assertTrue(typeof values[i] === type) assertTrue(typeof values[i] === typeofString)
assertTrue(typeof Object(values[i]) === 'object') assertTrue(typeof Object(values[i]) === 'object')
assertEquals(null, %_ClassOf(values[i])) assertEquals(null, %_ClassOf(values[i]))
assertEquals("Float32x4", %_ClassOf(Object(values[i]))) assertEquals(type, %_ClassOf(Object(values[i])))
} }
} }
...@@ -245,28 +246,28 @@ function TestSameValue(type, lanes) { ...@@ -245,28 +246,28 @@ function TestSameValue(type, lanes) {
// SIMD value types. // SIMD value types.
// All lanes checked. // All lanes checked.
// TODO(bbudge): use loops to test lanes when replaceLane is defined. // TODO(bbudge): use loops to test lanes when replaceLane is defined.
assertTrue(sameValueBoth(SIMD.float32x4(1, 2, 3, 4), assertTrue(sameValueBoth(SIMD.Float32x4(1, 2, 3, 4),
SIMD.float32x4(1, 2, 3, 4))); SIMD.Float32x4(1, 2, 3, 4)));
assertFalse(sameValueBoth(SIMD.float32x4(1, 2, 3, 4), assertFalse(sameValueBoth(SIMD.Float32x4(1, 2, 3, 4),
SIMD.float32x4(NaN, 2, 3, 4))); SIMD.Float32x4(NaN, 2, 3, 4)));
assertFalse(sameValueBoth(SIMD.float32x4(1, 2, 3, 4), assertFalse(sameValueBoth(SIMD.Float32x4(1, 2, 3, 4),
SIMD.float32x4(1, NaN, 3, 4))); SIMD.Float32x4(1, NaN, 3, 4)));
assertFalse(sameValueBoth(SIMD.float32x4(1, 2, 3, 4), assertFalse(sameValueBoth(SIMD.Float32x4(1, 2, 3, 4),
SIMD.float32x4(1, 2, NaN, 4))); SIMD.Float32x4(1, 2, NaN, 4)));
assertFalse(sameValueBoth(SIMD.float32x4(1, 2, 3, 4), assertFalse(sameValueBoth(SIMD.Float32x4(1, 2, 3, 4),
SIMD.float32x4(1, 2, 3, NaN))); SIMD.Float32x4(1, 2, 3, NaN)));
// Special values. // Special values.
// TODO(bbudge): use loops to test lanes when replaceLane is defined. // TODO(bbudge): use loops to test lanes when replaceLane is defined.
assertTrue(sameValueBoth(SIMD.float32x4(NaN, 2, 3, 4), assertTrue(sameValueBoth(SIMD.Float32x4(NaN, 2, 3, 4),
SIMD.float32x4(NaN, 2, 3, 4))); SIMD.Float32x4(NaN, 2, 3, 4)));
assertTrue(sameValueBoth(SIMD.float32x4(+0, 2, 3, 4), assertTrue(sameValueBoth(SIMD.Float32x4(+0, 2, 3, 4),
SIMD.float32x4(+0, 2, 3, 4))); SIMD.Float32x4(+0, 2, 3, 4)));
assertTrue(sameValueBoth(SIMD.float32x4(-0, 2, 3, 4), assertTrue(sameValueBoth(SIMD.Float32x4(-0, 2, 3, 4),
SIMD.float32x4(-0, 2, 3, 4))); SIMD.Float32x4(-0, 2, 3, 4)));
assertTrue(sameValueZeroOnly(SIMD.float32x4(+0, 2, 3, 4), assertTrue(sameValueZeroOnly(SIMD.Float32x4(+0, 2, 3, 4),
SIMD.float32x4(-0, 2, 3, 4))); SIMD.Float32x4(-0, 2, 3, 4)));
assertTrue(sameValueZeroOnly(SIMD.float32x4(-0, 2, 3, 4), assertTrue(sameValueZeroOnly(SIMD.Float32x4(-0, 2, 3, 4),
SIMD.float32x4(+0, 2, 3, 4))); SIMD.Float32x4(+0, 2, 3, 4)));
} }
...@@ -382,7 +383,7 @@ function TestReflectApply(type) { ...@@ -382,7 +383,7 @@ function TestReflectApply(type) {
function TestSIMDTypes() { function TestSIMDTypes() {
var types = [ 'float32x4' ]; var types = [ 'Float32x4' ];
for (var i = 0; i < types.length; ++i) { for (var i = 0; i < types.length; ++i) {
var type = types[i], var type = types[i],
lanes = lanesForType(type); lanes = lanesForType(type);
......
...@@ -325,7 +325,7 @@ test(function() { ...@@ -325,7 +325,7 @@ test(function() {
// kSimdToNumber // kSimdToNumber
test(function() { test(function() {
1 + SIMD.float32x4(1, 2, 3, 4); 1 + SIMD.Float32x4(1, 2, 3, 4);
}, "Cannot convert a SIMD value to a number", TypeError); }, "Cannot convert a SIMD value to a number", TypeError);
// kUndefinedOrNullToObject // kUndefinedOrNullToObject
......
...@@ -32,3 +32,7 @@ load('base.js'); ...@@ -32,3 +32,7 @@ load('base.js');
var console = { var console = {
log: function(x) { print(x); }, log: function(x) { print(x); },
}; };
// Disable value type tests for now, since the polyfill can't pass them.
// TODO(bbudge): Drop when polyfill is not needed.
var skipValueTests = true;
...@@ -10,8 +10,12 @@ ...@@ -10,8 +10,12 @@
[ [
[ALWAYS, { [ALWAYS, {
# TODO(bradnelson): Drop when test is fixed upstream. # TODO(bbudge): Drop when test is fixed upstream.
'benchmarks/aobench': SKIP, 'benchmarks/aobench': SKIP,
'benchmarks/averageFloat64x2': SKIP,
'benchmarks/averageFloat64x2Load': SKIP,
'benchmarks/mandelbrot': SKIP,
'benchmarks/sinx4': SKIP,
# TODO(bbudge): Drop this when simd implementation is faster. # TODO(bbudge): Drop this when simd implementation is faster.
'benchmarks/memcpy': SKIP, 'benchmarks/memcpy': SKIP,
......
...@@ -14,10 +14,9 @@ from testrunner.local import testsuite ...@@ -14,10 +14,9 @@ from testrunner.local import testsuite
from testrunner.local import utils from testrunner.local import utils
from testrunner.objects import testcase from testrunner.objects import testcase
SIMDJS_ARCHIVE_REVISION = "07e2713e0c9ea19feb0732d5bd84770c87310d79" SIMDJS_ARCHIVE_REVISION = "99ef44bd4f22acd203c01e524131bc7f2a7eab68"
SIMDJS_ARCHIVE_MD5 = "cf6bddf99f18800b68e782054268ee3c" SIMDJS_ARCHIVE_MD5 = "1428773887924fa5a784bf0843615740"
SIMDJS_URL = ( SIMDJS_URL = ("https://github.com/tc39/ecmascript_simd/archive/%s.tar.gz")
"https://github.com/johnmccutchan/ecmascript_simd/archive/%s.tar.gz")
SIMDJS_SUITE_PATH = ["data", "src"] SIMDJS_SUITE_PATH = ["data", "src"]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment