From db67dfcafe811831167b3997f8676a36955e103d Mon Sep 17 00:00:00 2001 From: Vladimir Vukicevic Date: Thu, 4 Feb 2010 15:31:40 -0800 Subject: [PATCH] b=542402; add FLOAT64 to typed arrays; r=jorendorff --- js/src/jsapi.cpp | 1 + js/src/jsproto.tbl | 1 + js/src/jstracer.cpp | 13 ++++++++- js/src/jstypedarray.cpp | 28 +++++++++++++++++-- js/src/jstypedarray.h | 1 + js/src/tests/js1_8_5/extensions/typedarray.js | 7 +++-- 6 files changed, 46 insertions(+), 5 deletions(-) diff --git a/js/src/jsapi.cpp b/js/src/jsapi.cpp index b4ef1929a0ed..925199f49ca3 100644 --- a/js/src/jsapi.cpp +++ b/js/src/jsapi.cpp @@ -1508,6 +1508,7 @@ static JSStdName standard_class_names[] = { {js_InitTypedArrayClasses, EAGER_CLASS_ATOM(Int32Array), NULL}, {js_InitTypedArrayClasses, EAGER_CLASS_ATOM(Uint32Array), NULL}, {js_InitTypedArrayClasses, EAGER_CLASS_ATOM(Float32Array), NULL}, + {js_InitTypedArrayClasses, EAGER_CLASS_ATOM(Float64Array), NULL}, {NULL, 0, NULL, NULL} }; diff --git a/js/src/jsproto.tbl b/js/src/jsproto.tbl index 8459929ab7d7..5bcb4b648ddb 100644 --- a/js/src/jsproto.tbl +++ b/js/src/jsproto.tbl @@ -115,6 +115,7 @@ JS_PROTO(Uint16Array, 33, js_InitTypedArrayClasses) JS_PROTO(Int32Array, 34, js_InitTypedArrayClasses) JS_PROTO(Uint32Array, 35, js_InitTypedArrayClasses) JS_PROTO(Float32Array, 36, js_InitTypedArrayClasses) +JS_PROTO(Float64Array, 37, js_InitTypedArrayClasses) #undef SCRIPT_INIT #undef XML_INIT diff --git a/js/src/jstracer.cpp b/js/src/jstracer.cpp index b1ee9c3960be..c283a9bb2bbb 100644 --- a/js/src/jstracer.cpp +++ b/js/src/jstracer.cpp @@ -12282,7 +12282,8 @@ TraceRecorder::setElem(int lval_spindex, int idx_spindex, int v_spindex) if (isNumber(v)) { if (isPromoteInt(v_ins) && - tarray->type != js::TypedArray::TYPE_FLOAT32) { + tarray->type != js::TypedArray::TYPE_FLOAT32 && + tarray->type != js::TypedArray::TYPE_FLOAT64) { LIns *v_ins_int = demote(lir, v_ins); switch (tarray->type) { case js::TypedArray::TYPE_INT8: @@ -12300,6 +12301,8 @@ TraceRecorder::setElem(int lval_spindex, int idx_spindex, int v_spindex) addr_ins = lir->ins2(LIR_piadd, data_ins, lir->ins2i(LIR_pilsh, pidx_ins, 2)); lir->insStore(LIR_sti, v_ins_int, addr_ins, 0); break; + case js::TypedArray::TYPE_FLOAT32: + case js::TypedArray::TYPE_FLOAT64: default: JS_NOT_REACHED("Unknown typed array in tracer"); } @@ -12324,6 +12327,10 @@ TraceRecorder::setElem(int lval_spindex, int idx_spindex, int v_spindex) addr_ins = lir->ins2(LIR_piadd, data_ins, lir->ins2i(LIR_pilsh, pidx_ins, 2)); lir->insStore(LIR_st32f, v_ins, addr_ins, 0); break; + case js::TypedArray::TYPE_FLOAT64: + addr_ins = lir->ins2(LIR_piadd, data_ins, lir->ins2i(LIR_pilsh, pidx_ins, 3)); + lir->insStore(LIR_stfi, v_ins, addr_ins, 0); + break; default: JS_NOT_REACHED("Unknown typed array type in tracer"); } @@ -13313,6 +13320,10 @@ TraceRecorder::typedArrayElement(jsval& oval, jsval& ival, jsval*& vp, LIns*& v_ addr_ins = lir->ins2(LIR_piadd, data_ins, lir->ins2i(LIR_pilsh, pidx_ins, 2)); v_ins = lir->insLoad(LIR_ld32f, addr_ins, 0); break; + case js::TypedArray::TYPE_FLOAT64: + addr_ins = lir->ins2(LIR_piadd, data_ins, lir->ins2i(LIR_pilsh, pidx_ins, 3)); + v_ins = lir->insLoad(LIR_ldf, addr_ins, 0); + break; default: JS_NOT_REACHED("Unknown typed array type in tracer"); } diff --git a/js/src/jstypedarray.cpp b/js/src/jstypedarray.cpp index 543dfd3bca19..aa28ac0d935c 100644 --- a/js/src/jstypedarray.cpp +++ b/js/src/jstypedarray.cpp @@ -312,6 +312,7 @@ template<> inline const int TypeIDOfType() { return TypedArray::TYPE_UIN template<> inline const int TypeIDOfType() { return TypedArray::TYPE_INT32; } template<> inline const int TypeIDOfType() { return TypedArray::TYPE_UINT32; } template<> inline const int TypeIDOfType() { return TypedArray::TYPE_FLOAT32; } +template<> inline const int TypeIDOfType() { return TypedArray::TYPE_FLOAT64; } template class TypedArrayTemplate; @@ -322,6 +323,7 @@ typedef TypedArrayTemplate Uint16Array; typedef TypedArrayTemplate Int32Array; typedef TypedArrayTemplate Uint32Array; typedef TypedArrayTemplate Float32Array; +typedef TypedArrayTemplate Float64Array; template class TypedArrayTemplate @@ -896,6 +898,12 @@ class TypedArrayTemplate *dest++ = NativeType(*src++); break; } + case TypedArray::TYPE_FLOAT64: { + double *src = static_cast(tarray->data); + for (uintN i = 0; i < length; ++i) + *dest++ = NativeType(*src++); + break; + } default: JS_NOT_REACHED("copyFrom with a TypedArray of unknown type"); break; @@ -994,6 +1002,15 @@ TypedArrayTemplate::copyIndexToValue(JSContext *cx, uint32 index, jsval * *vp = JSVAL_VOID; } +template<> +void +TypedArrayTemplate::copyIndexToValue(JSContext *cx, uint32 index, jsval *vp) +{ + double val = getIndex(index); + if (!js_NewWeaklyRootedNumber(cx, jsdouble(val), vp)) + *vp = JSVAL_VOID; +} + /*** *** JS impl ***/ @@ -1108,6 +1125,7 @@ IMPL_TYPED_ARRAY_STATICS(Uint16Array); IMPL_TYPED_ARRAY_STATICS(Int32Array); IMPL_TYPED_ARRAY_STATICS(Uint32Array); IMPL_TYPED_ARRAY_STATICS(Float32Array); +IMPL_TYPED_ARRAY_STATICS(Float64Array); JSClass TypedArray::fastClasses[TYPE_MAX] = { IMPL_TYPED_ARRAY_FAST_CLASS(Int8Array), @@ -1116,7 +1134,8 @@ JSClass TypedArray::fastClasses[TYPE_MAX] = { IMPL_TYPED_ARRAY_FAST_CLASS(Uint16Array), IMPL_TYPED_ARRAY_FAST_CLASS(Int32Array), IMPL_TYPED_ARRAY_FAST_CLASS(Uint32Array), - IMPL_TYPED_ARRAY_FAST_CLASS(Float32Array) + IMPL_TYPED_ARRAY_FAST_CLASS(Float32Array), + IMPL_TYPED_ARRAY_FAST_CLASS(Float64Array) }; JSClass TypedArray::slowClasses[TYPE_MAX] = { @@ -1126,7 +1145,8 @@ JSClass TypedArray::slowClasses[TYPE_MAX] = { IMPL_TYPED_ARRAY_SLOW_CLASS(Uint16Array), IMPL_TYPED_ARRAY_SLOW_CLASS(Int32Array), IMPL_TYPED_ARRAY_SLOW_CLASS(Uint32Array), - IMPL_TYPED_ARRAY_SLOW_CLASS(Float32Array) + IMPL_TYPED_ARRAY_SLOW_CLASS(Float32Array), + IMPL_TYPED_ARRAY_SLOW_CLASS(Float64Array) }; JS_FRIEND_API(JSObject *) @@ -1148,6 +1168,7 @@ js_InitTypedArrayClasses(JSContext *cx, JSObject *obj) INIT_TYPED_ARRAY_CLASS(Int32Array,TYPE_INT32); INIT_TYPED_ARRAY_CLASS(Uint32Array,TYPE_UINT32); INIT_TYPED_ARRAY_CLASS(Float32Array,TYPE_FLOAT32); + INIT_TYPED_ARRAY_CLASS(Float64Array,TYPE_FLOAT64); proto = js_InitClass(cx, obj, NULL, &ArrayBuffer::jsclass, ArrayBuffer::class_constructor, 1, @@ -1213,6 +1234,9 @@ TypedArrayConstruct(JSContext *cx, jsint atype, uintN argc, jsval *argv, jsval * case TypedArray::TYPE_FLOAT32: return Float32Array::class_constructor(cx, cx->globalObject, argc, argv, rv); + case TypedArray::TYPE_FLOAT64: + return Float64Array::class_constructor(cx, cx->globalObject, argc, argv, rv); + default: JS_NOT_REACHED("shouldn't have gotten here"); return false; diff --git a/js/src/jstypedarray.h b/js/src/jstypedarray.h index fd46e279230f..3d54f4ac9ed0 100644 --- a/js/src/jstypedarray.h +++ b/js/src/jstypedarray.h @@ -101,6 +101,7 @@ struct JS_FRIEND_API(TypedArray) { TYPE_INT32, TYPE_UINT32, TYPE_FLOAT32, + TYPE_FLOAT64, TYPE_MAX }; diff --git a/js/src/tests/js1_8_5/extensions/typedarray.js b/js/src/tests/js1_8_5/extensions/typedarray.js index ca15a23ac70b..8099d3ae6b9a 100644 --- a/js/src/tests/js1_8_5/extensions/typedarray.js +++ b/js/src/tests/js1_8_5/extensions/typedarray.js @@ -81,7 +81,7 @@ function test() check(function() thrown, todo); } - var buf; + var buf, buf2; buf = new ArrayBuffer(100); check(function() buf); @@ -132,6 +132,9 @@ function test() check(function() (new Int32Array(buf)).length == 1); check(function() (new Uint32Array(buf)).length == 1); check(function() (new Float32Array(buf)).length == 1); + checkThrows(function() (new Float64Array(buf))); + buf2 = new ArrayBuffer(8); + check(function() (new Float64Array(buf2)).length == 1); buf = new ArrayBuffer(5); check(function() buf); @@ -180,7 +183,7 @@ function test() print ("done"); - reportCompare(0, TestFailCount, "typed array test failures"); + reportCompare(0, TestFailCount, "typed array tests"); exitFunc ('test'); }