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() {
x = GlobalFloat32x4.extractLane(value, 1),
y = GlobalFloat32x4.extractLane(value, 2),
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() {
......@@ -64,18 +77,19 @@ function Float32x4ExtractLaneJS(value, lane) {
// -------------------------------------------------------------------
%AddNamedProperty(GlobalSIMD, symbolToStringTag, 'SIMD', READ_ONLY | DONT_ENUM);
%AddNamedProperty(GlobalSIMD, 'float32x4', GlobalFloat32x4, DONT_ENUM);
%SetCode(GlobalFloat32x4, Float32x4Constructor);
%FunctionSetPrototype(GlobalFloat32x4, {});
%AddNamedProperty(
GlobalFloat32x4.prototype, 'constructor', GlobalFloat32x4, DONT_ENUM);
%AddNamedProperty(
GlobalFloat32x4, symbolToStringTag, 'Float32x4', DONT_ENUM | READ_ONLY);
GlobalFloat32x4.prototype, symbolToStringTag, 'Float32x4',
DONT_ENUM | READ_ONLY);
utils.InstallFunctions(GlobalFloat32x4.prototype, DONT_ENUM, [
'valueOf', Float32x4ValueOf,
'toLocaleString', Float32x4ToLocaleString,
'toString', Float32x4ToString,
'valueOf', Float32x4ValueOf,
]);
utils.InstallFunctions(GlobalFloat32x4, DONT_ENUM, [
......
......@@ -488,7 +488,7 @@ TEST(HeapSnapshotFloat32x4) {
v8::HandleScope scope(env->GetIsolate());
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();
CHECK(ValidateSnapshot(snapshot));
const v8::HeapGraphNode* global = GetGlobalObject(snapshot);
......
......@@ -15,12 +15,12 @@ function lanesForType(typeName) {
function isValidSimdString(string, value, type, lanes) {
var simdFn = SIMD[type],
parseFn =
type.indexOf('float') === 0 ? Number.parseFloat : Number.parseInt,
type.indexOf('Float') === 0 ? Number.parseFloat : Number.parseInt,
indexOfOpenParen = string.indexOf('(');
// Check prefix for correct type name.
if (string.substr(0, indexOfOpenParen).toUpperCase() !== type.toUpperCase())
// Check prefix (e.g. SIMD.Float32x4.)
if (string.substr(0, indexOfOpenParen) !== 'SIMD.' + type)
return false;
// Remove type name and open parenthesis.
// Remove type name (e.g. SIMD.Float32x4) and open parenthesis.
string = string.substr(indexOfOpenParen + 1);
var laneStrings = string.split(',');
if (laneStrings.length !== lanes)
......@@ -90,7 +90,7 @@ function TestConstructor(type, lanes) {
// The constructor expects values for all lanes.
switch (type) {
case 'float32x4':
case 'Float32x4':
// The constructor expects values for all lanes.
assertThrows(function () { simdFn() }, TypeError)
assertThrows(function () { simdFn(0) }, TypeError)
......@@ -115,12 +115,13 @@ function TestConstructor(type, lanes) {
function TestType(type, lanes) {
var typeofString = type.charAt(0).toLowerCase() + type.slice(1);
for (var i in values) {
assertEquals(type, typeof values[i])
assertTrue(typeof values[i] === type)
assertEquals(typeofString, typeof values[i])
assertTrue(typeof values[i] === typeofString)
assertTrue(typeof Object(values[i]) === 'object')
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) {
// SIMD value types.
// All lanes checked.
// TODO(bbudge): use loops to test lanes when replaceLane is defined.
assertTrue(sameValueBoth(SIMD.float32x4(1, 2, 3, 4),
SIMD.float32x4(1, 2, 3, 4)));
assertFalse(sameValueBoth(SIMD.float32x4(1, 2, 3, 4),
SIMD.float32x4(NaN, 2, 3, 4)));
assertFalse(sameValueBoth(SIMD.float32x4(1, 2, 3, 4),
SIMD.float32x4(1, NaN, 3, 4)));
assertFalse(sameValueBoth(SIMD.float32x4(1, 2, 3, 4),
SIMD.float32x4(1, 2, NaN, 4)));
assertFalse(sameValueBoth(SIMD.float32x4(1, 2, 3, 4),
SIMD.float32x4(1, 2, 3, NaN)));
assertTrue(sameValueBoth(SIMD.Float32x4(1, 2, 3, 4),
SIMD.Float32x4(1, 2, 3, 4)));
assertFalse(sameValueBoth(SIMD.Float32x4(1, 2, 3, 4),
SIMD.Float32x4(NaN, 2, 3, 4)));
assertFalse(sameValueBoth(SIMD.Float32x4(1, 2, 3, 4),
SIMD.Float32x4(1, NaN, 3, 4)));
assertFalse(sameValueBoth(SIMD.Float32x4(1, 2, 3, 4),
SIMD.Float32x4(1, 2, NaN, 4)));
assertFalse(sameValueBoth(SIMD.Float32x4(1, 2, 3, 4),
SIMD.Float32x4(1, 2, 3, NaN)));
// Special values.
// TODO(bbudge): use loops to test lanes when replaceLane is defined.
assertTrue(sameValueBoth(SIMD.float32x4(NaN, 2, 3, 4),
SIMD.float32x4(NaN, 2, 3, 4)));
assertTrue(sameValueBoth(SIMD.float32x4(+0, 2, 3, 4),
SIMD.float32x4(+0, 2, 3, 4)));
assertTrue(sameValueBoth(SIMD.float32x4(-0, 2, 3, 4),
SIMD.float32x4(-0, 2, 3, 4)));
assertTrue(sameValueZeroOnly(SIMD.float32x4(+0, 2, 3, 4),
SIMD.float32x4(-0, 2, 3, 4)));
assertTrue(sameValueZeroOnly(SIMD.float32x4(-0, 2, 3, 4),
SIMD.float32x4(+0, 2, 3, 4)));
assertTrue(sameValueBoth(SIMD.Float32x4(NaN, 2, 3, 4),
SIMD.Float32x4(NaN, 2, 3, 4)));
assertTrue(sameValueBoth(SIMD.Float32x4(+0, 2, 3, 4),
SIMD.Float32x4(+0, 2, 3, 4)));
assertTrue(sameValueBoth(SIMD.Float32x4(-0, 2, 3, 4),
SIMD.Float32x4(-0, 2, 3, 4)));
assertTrue(sameValueZeroOnly(SIMD.Float32x4(+0, 2, 3, 4),
SIMD.Float32x4(-0, 2, 3, 4)));
assertTrue(sameValueZeroOnly(SIMD.Float32x4(-0, 2, 3, 4),
SIMD.Float32x4(+0, 2, 3, 4)));
}
......@@ -382,7 +383,7 @@ function TestReflectApply(type) {
function TestSIMDTypes() {
var types = [ 'float32x4' ];
var types = [ 'Float32x4' ];
for (var i = 0; i < types.length; ++i) {
var type = types[i],
lanes = lanesForType(type);
......
......@@ -325,7 +325,7 @@ test(function() {
// kSimdToNumber
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);
// kUndefinedOrNullToObject
......
......@@ -32,3 +32,7 @@ load('base.js');
var console = {
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 @@
[
[ALWAYS, {
# TODO(bradnelson): Drop when test is fixed upstream.
# TODO(bbudge): Drop when test is fixed upstream.
'benchmarks/aobench': SKIP,
'benchmarks/averageFloat64x2': SKIP,
'benchmarks/averageFloat64x2Load': SKIP,
'benchmarks/mandelbrot': SKIP,
'benchmarks/sinx4': SKIP,
# TODO(bbudge): Drop this when simd implementation is faster.
'benchmarks/memcpy': SKIP,
......
......@@ -14,10 +14,9 @@ from testrunner.local import testsuite
from testrunner.local import utils
from testrunner.objects import testcase
SIMDJS_ARCHIVE_REVISION = "07e2713e0c9ea19feb0732d5bd84770c87310d79"
SIMDJS_ARCHIVE_MD5 = "cf6bddf99f18800b68e782054268ee3c"
SIMDJS_URL = (
"https://github.com/johnmccutchan/ecmascript_simd/archive/%s.tar.gz")
SIMDJS_ARCHIVE_REVISION = "99ef44bd4f22acd203c01e524131bc7f2a7eab68"
SIMDJS_ARCHIVE_MD5 = "1428773887924fa5a784bf0843615740"
SIMDJS_URL = ("https://github.com/tc39/ecmascript_simd/archive/%s.tar.gz")
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