mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1031203 - Implemented float64x2. r=bbouvier
This commit is contained in:
parent
6ab7673b0a
commit
b4208b9620
@ -462,7 +462,7 @@ struct JSClass {
|
||||
// the beginning of every global object's slots for use by the
|
||||
// application.
|
||||
#define JSCLASS_GLOBAL_APPLICATION_SLOTS 4
|
||||
#define JSCLASS_GLOBAL_SLOT_COUNT (JSCLASS_GLOBAL_APPLICATION_SLOTS + JSProto_LIMIT * 3 + 30)
|
||||
#define JSCLASS_GLOBAL_SLOT_COUNT (JSCLASS_GLOBAL_APPLICATION_SLOTS + JSProto_LIMIT * 3 + 31)
|
||||
#define JSCLASS_GLOBAL_FLAGS_WITH_SLOTS(n) \
|
||||
(JSCLASS_IS_GLOBAL | JSCLASS_HAS_RESERVED_SLOTS(JSCLASS_GLOBAL_SLOT_COUNT + (n)))
|
||||
#define JSCLASS_GLOBAL_FLAGS \
|
||||
|
@ -31,6 +31,7 @@ using mozilla::FloorLog2;
|
||||
|
||||
namespace js {
|
||||
extern const JSFunctionSpec Float32x4Methods[];
|
||||
extern const JSFunctionSpec Float64x2Methods[];
|
||||
extern const JSFunctionSpec Int32x4Methods[];
|
||||
}
|
||||
|
||||
@ -65,6 +66,7 @@ js::IsVectorObject(HandleValue v)
|
||||
|
||||
template bool js::IsVectorObject<Int32x4>(HandleValue v);
|
||||
template bool js::IsVectorObject<Float32x4>(HandleValue v);
|
||||
template bool js::IsVectorObject<Float64x2>(HandleValue v);
|
||||
|
||||
template<typename V>
|
||||
bool
|
||||
@ -124,6 +126,9 @@ static bool type##Lane##lane(JSContext *cx, unsigned argc, Value *vp) { \
|
||||
FOUR_LANES_ACCESSOR(Int32x4);
|
||||
FOUR_LANES_ACCESSOR(Float32x4);
|
||||
#undef FOUR_LANES_ACCESSOR
|
||||
|
||||
LANE_ACCESSOR(Float64x2, 0);
|
||||
LANE_ACCESSOR(Float64x2, 1);
|
||||
#undef LANE_ACCESSOR
|
||||
|
||||
template<typename SimdType>
|
||||
@ -168,6 +173,7 @@ static bool type##SignMask(JSContext *cx, unsigned argc, Value *vp) { \
|
||||
return SignMask<type>(cx, argc, vp); \
|
||||
}
|
||||
SIGN_MASK(Float32x4);
|
||||
SIGN_MASK(Float64x2);
|
||||
SIGN_MASK(Int32x4);
|
||||
#undef SIGN_MASK
|
||||
|
||||
@ -201,6 +207,13 @@ class Float32x4Defn {
|
||||
static const JSPropertySpec TypedObjectProperties[];
|
||||
static const JSFunctionSpec TypedObjectMethods[];
|
||||
};
|
||||
class Float64x2Defn {
|
||||
public:
|
||||
static const SimdTypeDescr::Type type = SimdTypeDescr::TYPE_FLOAT64;
|
||||
static const JSFunctionSpec TypeDescriptorMethods[];
|
||||
static const JSPropertySpec TypedObjectProperties[];
|
||||
static const JSFunctionSpec TypedObjectMethods[];
|
||||
};
|
||||
} // namespace js
|
||||
|
||||
const JSFunctionSpec js::Float32x4Defn::TypeDescriptorMethods[] = {
|
||||
@ -224,6 +237,25 @@ const JSFunctionSpec js::Float32x4Defn::TypedObjectMethods[] = {
|
||||
JS_FS_END
|
||||
};
|
||||
|
||||
const JSFunctionSpec js::Float64x2Defn::TypeDescriptorMethods[] = {
|
||||
JS_SELF_HOSTED_FN("toSource", "DescrToSource", 0, 0),
|
||||
JS_SELF_HOSTED_FN("array", "ArrayShorthand", 1, 0),
|
||||
JS_SELF_HOSTED_FN("equivalent", "TypeDescrEquivalent", 1, 0),
|
||||
JS_FS_END
|
||||
};
|
||||
|
||||
const JSPropertySpec js::Float64x2Defn::TypedObjectProperties[] = {
|
||||
JS_PSG("x", Float64x2Lane0, JSPROP_PERMANENT),
|
||||
JS_PSG("y", Float64x2Lane1, JSPROP_PERMANENT),
|
||||
JS_PSG("signMask", Float64x2SignMask, JSPROP_PERMANENT),
|
||||
JS_PS_END
|
||||
};
|
||||
|
||||
const JSFunctionSpec js::Float64x2Defn::TypedObjectMethods[] = {
|
||||
JS_SELF_HOSTED_FN("toSource", "SimdToSource", 0, 0),
|
||||
JS_FS_END
|
||||
};
|
||||
|
||||
const JSFunctionSpec js::Int32x4Defn::TypeDescriptorMethods[] = {
|
||||
JS_SELF_HOSTED_FN("toSource", "DescrToSource", 0, 0),
|
||||
JS_SELF_HOSTED_FN("array", "ArrayShorthand", 1, 0),
|
||||
@ -268,6 +300,7 @@ CreateSimdClass(JSContext *cx, Handle<GlobalObject*> global, HandlePropertyName
|
||||
typeDescr->initReservedSlot(JS_DESCR_SLOT_SIZE, Int32Value(SimdTypeDescr::size(type)));
|
||||
typeDescr->initReservedSlot(JS_DESCR_SLOT_OPAQUE, BooleanValue(false));
|
||||
typeDescr->initReservedSlot(JS_DESCR_SLOT_TYPE, Int32Value(T::type));
|
||||
typeDescr->initReservedSlot(JS_DESCR_SLOT_LANES, Int32Value(SimdTypeDescr::lanes(type)));
|
||||
|
||||
if (!CreateUserSizeAndAlignmentProperties(cx, typeDescr))
|
||||
return nullptr;
|
||||
@ -298,6 +331,18 @@ CreateSimdClass(JSContext *cx, Handle<GlobalObject*> global, HandlePropertyName
|
||||
return typeDescr;
|
||||
}
|
||||
|
||||
const char*
|
||||
SimdTypeToMinimumLanesNumber(SimdTypeDescr &descr) {
|
||||
switch (descr.type()) {
|
||||
case SimdTypeDescr::TYPE_INT32:
|
||||
case SimdTypeDescr::TYPE_FLOAT32:
|
||||
return "3";
|
||||
case SimdTypeDescr::TYPE_FLOAT64:
|
||||
return "1";
|
||||
}
|
||||
MOZ_CRASH("Unexpected SIMD type description.");
|
||||
}
|
||||
|
||||
bool
|
||||
SimdTypeDescr::call(JSContext *cx, unsigned argc, Value *vp)
|
||||
{
|
||||
@ -336,6 +381,13 @@ SimdTypeDescr::call(JSContext *cx, unsigned argc, Value *vp)
|
||||
}
|
||||
break;
|
||||
}
|
||||
case SimdTypeDescr::TYPE_FLOAT64: {
|
||||
double *mem = reinterpret_cast<double*>(result->typedMem());
|
||||
for (unsigned i = 0; i < 2; i++) {
|
||||
if (!ToNumber(cx, args[i], &mem[i]))
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
args.rval().setObject(*result);
|
||||
return true;
|
||||
@ -386,6 +438,23 @@ SIMDObject::initClass(JSContext *cx, Handle<GlobalObject *> global)
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// float64x2
|
||||
RootedObject float64x2Object(cx);
|
||||
float64x2Object = CreateSimdClass<Float64x2Defn>(cx, global,
|
||||
cx->names().float64x2);
|
||||
if (!float64x2Object)
|
||||
return nullptr;
|
||||
|
||||
// Define float64x2 functions and install as a property of the SIMD object.
|
||||
RootedValue float64x2Value(cx, ObjectValue(*float64x2Object));
|
||||
if (!JS_DefineFunctions(cx, float64x2Object, Float64x2Methods) ||
|
||||
!JSObject::defineProperty(cx, SIMD, cx->names().float64x2,
|
||||
float64x2Value, nullptr, nullptr,
|
||||
JSPROP_READONLY | JSPROP_PERMANENT))
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// int32x4
|
||||
RootedObject int32x4Object(cx);
|
||||
int32x4Object = CreateSimdClass<Int32x4Defn>(cx, global,
|
||||
@ -411,6 +480,7 @@ SIMDObject::initClass(JSContext *cx, Handle<GlobalObject *> global)
|
||||
|
||||
global->setConstructor(JSProto_SIMD, SIMDValue);
|
||||
global->setFloat32x4TypeDescr(*float32x4Object);
|
||||
global->setFloat64x2TypeDescr(*float64x2Object);
|
||||
global->setInt32x4TypeDescr(*int32x4Object);
|
||||
return SIMD;
|
||||
}
|
||||
@ -441,6 +511,7 @@ js::CreateSimd(JSContext *cx, typename V::Elem *data)
|
||||
}
|
||||
|
||||
template JSObject *js::CreateSimd<Float32x4>(JSContext *cx, Float32x4::Elem *data);
|
||||
template JSObject *js::CreateSimd<Float64x2>(JSContext *cx, Float64x2::Elem *data);
|
||||
template JSObject *js::CreateSimd<Int32x4>(JSContext *cx, Int32x4::Elem *data);
|
||||
|
||||
namespace js {
|
||||
@ -767,8 +838,10 @@ CompareFunc(JSContext *cx, unsigned argc, Value *vp)
|
||||
int32_t result[Int32x4::lanes];
|
||||
InElem *left = TypedObjectMemory<InElem *>(args[0]);
|
||||
InElem *right = TypedObjectMemory<InElem *>(args[1]);
|
||||
for (unsigned i = 0; i < Int32x4::lanes; i++)
|
||||
result[i] = Op<InElem>::apply(left[i], right[i]);
|
||||
for (unsigned i = 0; i < Int32x4::lanes; i++) {
|
||||
unsigned j = (i * In::lanes) / Int32x4::lanes;
|
||||
result[i] = Op<InElem>::apply(left[j], right[j]);
|
||||
}
|
||||
|
||||
return StoreResult<Int32x4>(cx, args, result);
|
||||
}
|
||||
@ -787,7 +860,8 @@ FuncConvert(JSContext *cx, unsigned argc, Value *vp)
|
||||
Elem *val = TypedObjectMemory<Elem *>(args[0]);
|
||||
RetElem result[Vret::lanes];
|
||||
for (unsigned i = 0; i < Vret::lanes; i++)
|
||||
result[i] = ConvertScalar<RetElem>(val[i]);
|
||||
result[i] = i < V::lanes ? ConvertScalar<RetElem>(val[i]) : 0;
|
||||
|
||||
return StoreResult<Vret>(cx, args, result);
|
||||
}
|
||||
|
||||
@ -858,27 +932,29 @@ Int32x4Bool(JSContext *cx, unsigned argc, Value *vp)
|
||||
return StoreResult<Int32x4>(cx, args, result);
|
||||
}
|
||||
|
||||
template<typename In>
|
||||
static bool
|
||||
Float32x4Clamp(JSContext *cx, unsigned argc, Value *vp)
|
||||
Clamp(JSContext *cx, unsigned argc, Value *vp)
|
||||
{
|
||||
typedef typename In::Elem InElem;
|
||||
CallArgs args = CallArgsFromVp(argc, vp);
|
||||
if (args.length() != 3 || !IsVectorObject<Float32x4>(args[0]) ||
|
||||
!IsVectorObject<Float32x4>(args[1]) || !IsVectorObject<Float32x4>(args[2]))
|
||||
if (args.length() != 3 || !IsVectorObject<In>(args[0]) ||
|
||||
!IsVectorObject<In>(args[1]) || !IsVectorObject<In>(args[2]))
|
||||
{
|
||||
return ErrorBadArgs(cx);
|
||||
}
|
||||
|
||||
float *val = TypedObjectMemory<float *>(args[0]);
|
||||
float *lowerLimit = TypedObjectMemory<float *>(args[1]);
|
||||
float *upperLimit = TypedObjectMemory<float *>(args[2]);
|
||||
InElem *val = TypedObjectMemory<InElem *>(args[0]);
|
||||
InElem *lowerLimit = TypedObjectMemory<InElem *>(args[1]);
|
||||
InElem *upperLimit = TypedObjectMemory<InElem *>(args[2]);
|
||||
|
||||
float result[Float32x4::lanes];
|
||||
for (unsigned i = 0; i < Float32x4::lanes; i++) {
|
||||
InElem result[In::lanes];
|
||||
for (unsigned i = 0; i < In::lanes; i++) {
|
||||
result[i] = val[i] < lowerLimit[i] ? lowerLimit[i] : val[i];
|
||||
result[i] = result[i] > upperLimit[i] ? upperLimit[i] : result[i];
|
||||
}
|
||||
|
||||
return StoreResult<Float32x4>(cx, args, result);
|
||||
return StoreResult<In>(cx, args, result);
|
||||
}
|
||||
|
||||
template<typename V>
|
||||
@ -987,8 +1063,7 @@ Load(JSContext *cx, unsigned argc, Value *vp)
|
||||
return false;
|
||||
|
||||
Elem *dest = reinterpret_cast<Elem*>(result->typedMem());
|
||||
for (unsigned i = 0; i < NumElem; i++)
|
||||
dest[i] = typedArrayData[i];
|
||||
memcpy(dest, typedArrayData, sizeof(Elem) * NumElem);
|
||||
|
||||
args.rval().setObject(*result);
|
||||
return true;
|
||||
@ -1012,8 +1087,7 @@ Store(JSContext *cx, unsigned argc, Value *vp)
|
||||
return ErrorBadArgs(cx);
|
||||
|
||||
Elem *src = TypedObjectMemory<Elem*>(args[2]);
|
||||
for (unsigned i = 0; i < NumElem; i++)
|
||||
typedArrayData[i] = src[i];
|
||||
memcpy(typedArrayData, src, sizeof(Elem) * NumElem);
|
||||
|
||||
args.rval().setObject(args[2].toObject());
|
||||
return true;
|
||||
@ -1026,7 +1100,16 @@ js::simd_float32x4_##Name(JSContext *cx, unsigned argc, Value *vp) \
|
||||
return Func(cx, argc, vp); \
|
||||
}
|
||||
FLOAT32X4_FUNCTION_LIST(DEFINE_SIMD_FLOAT32X4_FUNCTION)
|
||||
#undef DEFINE_SIMD_FLOAT32x4_FUNCTION
|
||||
#undef DEFINE_SIMD_FLOAT32X4_FUNCTION
|
||||
|
||||
#define DEFINE_SIMD_FLOAT64X2_FUNCTION(Name, Func, Operands, Flags) \
|
||||
bool \
|
||||
js::simd_float64x2_##Name(JSContext *cx, unsigned argc, Value *vp) \
|
||||
{ \
|
||||
return Func(cx, argc, vp); \
|
||||
}
|
||||
FLOAT64X2_FUNCTION_LIST(DEFINE_SIMD_FLOAT64X2_FUNCTION)
|
||||
#undef DEFINE_SIMD_FLOAT64X2_FUNCTION
|
||||
|
||||
#define DEFINE_SIMD_INT32X4_FUNCTION(Name, Func, Operands, Flags) \
|
||||
bool \
|
||||
@ -1045,6 +1128,14 @@ const JSFunctionSpec js::Float32x4Methods[] = {
|
||||
JS_FS_END
|
||||
};
|
||||
|
||||
const JSFunctionSpec js::Float64x2Methods[] = {
|
||||
#define SIMD_FLOAT64X2_FUNCTION_ITEM(Name, Func, Operands, Flags) \
|
||||
JS_FN(#Name, js::simd_float64x2_##Name, Operands, Flags),
|
||||
FLOAT64X2_FUNCTION_LIST(SIMD_FLOAT64X2_FUNCTION_ITEM)
|
||||
#undef SIMD_FLOAT64X2_FUNCTION_ITEM
|
||||
JS_FS_END
|
||||
};
|
||||
|
||||
const JSFunctionSpec js::Int32x4Methods[] = {
|
||||
#define SIMD_INT32X4_FUNCTION_ITEM(Name, Func, Operands, Flags) \
|
||||
JS_FN(#Name, js::simd_int32x4_##Name, Operands, Flags),
|
||||
|
@ -22,6 +22,8 @@
|
||||
|
||||
#define FLOAT32X4_UNARY_FUNCTION_LIST(V) \
|
||||
V(abs, (UnaryFunc<Float32x4, Abs, Float32x4>), 1, 0) \
|
||||
V(fromFloat64x2, (FuncConvert<Float64x2, Float32x4> ), 1, 0) \
|
||||
V(fromFloat64x2Bits, (FuncConvertBits<Float64x2, Float32x4>), 1, 0) \
|
||||
V(fromInt32x4, (FuncConvert<Int32x4, Float32x4> ), 1, 0) \
|
||||
V(fromInt32x4Bits, (FuncConvertBits<Int32x4, Float32x4>), 1, 0) \
|
||||
V(neg, (UnaryFunc<Float32x4, Neg, Float32x4>), 1, 0) \
|
||||
@ -64,7 +66,7 @@
|
||||
|
||||
#define FLOAT32X4_TERNARY_FUNCTION_LIST(V) \
|
||||
V(bitselect, BitSelect<Float32x4>, 3, 0) \
|
||||
V(clamp, Float32x4Clamp, 3, 0) \
|
||||
V(clamp, Clamp<Float32x4>, 3, 0) \
|
||||
V(select, Select<Float32x4>, 3, 0)
|
||||
|
||||
#define FLOAT32X4_SHUFFLE_FUNCTION_LIST(V) \
|
||||
@ -77,9 +79,60 @@
|
||||
FLOAT32X4_TERNARY_FUNCTION_LIST(V) \
|
||||
FLOAT32X4_SHUFFLE_FUNCTION_LIST(V)
|
||||
|
||||
#define FLOAT64X2_UNARY_FUNCTION_LIST(V) \
|
||||
V(abs, (UnaryFunc<Float64x2, Abs, Float64x2>), 1, 0) \
|
||||
V(fromFloat32x4, (FuncConvert<Float32x4, Float64x2> ), 1, 0) \
|
||||
V(fromFloat32x4Bits, (FuncConvertBits<Float32x4, Float64x2>), 1, 0) \
|
||||
V(fromInt32x4, (FuncConvert<Int32x4, Float64x2> ), 1, 0) \
|
||||
V(fromInt32x4Bits, (FuncConvertBits<Int32x4, Float64x2>), 1, 0) \
|
||||
V(neg, (UnaryFunc<Float64x2, Neg, Float64x2>), 1, 0) \
|
||||
V(reciprocal, (UnaryFunc<Float64x2, Rec, Float64x2>), 1, 0) \
|
||||
V(reciprocalSqrt, (UnaryFunc<Float64x2, RecSqrt, Float64x2>), 1, 0) \
|
||||
V(splat, (FuncSplat<Float64x2>), 1, 0) \
|
||||
V(sqrt, (UnaryFunc<Float64x2, Sqrt, Float64x2>), 1, 0)
|
||||
|
||||
#define FLOAT64X2_BINARY_FUNCTION_LIST(V) \
|
||||
V(add, (BinaryFunc<Float64x2, Add, Float64x2>), 2, 0) \
|
||||
V(div, (BinaryFunc<Float64x2, Div, Float64x2>), 2, 0) \
|
||||
V(equal, (CompareFunc<Float64x2, Equal>), 2, 0) \
|
||||
V(greaterThan, (CompareFunc<Float64x2, GreaterThan>), 2, 0) \
|
||||
V(greaterThanOrEqual, (CompareFunc<Float64x2, GreaterThanOrEqual>), 2, 0) \
|
||||
V(lessThan, (CompareFunc<Float64x2, LessThan>), 2, 0) \
|
||||
V(lessThanOrEqual, (CompareFunc<Float64x2, LessThanOrEqual>), 2, 0) \
|
||||
V(load, (Load<Float64x2, 2>), 2, 0) \
|
||||
V(loadX, (Load<Float64x2, 1>), 2, 0) \
|
||||
V(max, (BinaryFunc<Float64x2, Maximum, Float64x2>), 2, 0) \
|
||||
V(maxNum, (BinaryFunc<Float64x2, MaxNum, Float64x2>), 2, 0) \
|
||||
V(min, (BinaryFunc<Float64x2, Minimum, Float64x2>), 2, 0) \
|
||||
V(minNum, (BinaryFunc<Float64x2, MinNum, Float64x2>), 2, 0) \
|
||||
V(mul, (BinaryFunc<Float64x2, Mul, Float64x2>), 2, 0) \
|
||||
V(notEqual, (CompareFunc<Float64x2, NotEqual>), 2, 0) \
|
||||
V(store, (Store<Float64x2, 2>), 3, 0) \
|
||||
V(storeX, (Store<Float64x2, 1>), 3, 0) \
|
||||
V(sub, (BinaryFunc<Float64x2, Sub, Float64x2>), 2, 0) \
|
||||
V(withX, (FuncWith<Float64x2, WithX>), 2, 0) \
|
||||
V(withY, (FuncWith<Float64x2, WithY>), 2, 0)
|
||||
|
||||
#define FLOAT64X2_TERNARY_FUNCTION_LIST(V) \
|
||||
V(bitselect, BitSelect<Float64x2>, 3, 0) \
|
||||
V(clamp, Clamp<Float64x2>, 3, 0) \
|
||||
V(select, Select<Float64x2>, 3, 0)
|
||||
|
||||
#define FLOAT64X2_SHUFFLE_FUNCTION_LIST(V) \
|
||||
V(swizzle, Swizzle<Float64x2>, 2, 0) \
|
||||
V(shuffle, Shuffle<Float64x2>, 3, 0)
|
||||
|
||||
#define FLOAT64X2_FUNCTION_LIST(V) \
|
||||
FLOAT64X2_UNARY_FUNCTION_LIST(V) \
|
||||
FLOAT64X2_BINARY_FUNCTION_LIST(V) \
|
||||
FLOAT64X2_TERNARY_FUNCTION_LIST(V) \
|
||||
FLOAT64X2_SHUFFLE_FUNCTION_LIST(V)
|
||||
|
||||
#define INT32X4_UNARY_FUNCTION_LIST(V) \
|
||||
V(fromFloat32x4, (FuncConvert<Float32x4, Int32x4>), 1, 0) \
|
||||
V(fromFloat32x4Bits, (FuncConvertBits<Float32x4, Int32x4>), 1, 0) \
|
||||
V(fromFloat64x2, (FuncConvert<Float64x2, Int32x4>), 1, 0) \
|
||||
V(fromFloat64x2Bits, (FuncConvertBits<Float64x2, Int32x4>), 1, 0) \
|
||||
V(neg, (UnaryFunc<Int32x4, Neg, Int32x4>), 1, 0) \
|
||||
V(not, (UnaryFunc<Int32x4, Not, Int32x4>), 1, 0) \
|
||||
V(splat, (FuncSplat<Int32x4>), 0, 0)
|
||||
@ -212,6 +265,26 @@ struct Float32x4 {
|
||||
}
|
||||
};
|
||||
|
||||
struct Float64x2 {
|
||||
typedef double Elem;
|
||||
static const unsigned lanes = 2;
|
||||
static const SimdTypeDescr::Type type = SimdTypeDescr::TYPE_FLOAT64;
|
||||
|
||||
static TypeDescr &GetTypeDescr(GlobalObject &global) {
|
||||
return global.float64x2TypeDescr().as<TypeDescr>();
|
||||
}
|
||||
static Elem toType(Elem a) {
|
||||
return a;
|
||||
}
|
||||
static bool toType(JSContext *cx, JS::HandleValue v, Elem *out) {
|
||||
*out = v.toNumber();
|
||||
return true;
|
||||
}
|
||||
static void setReturn(CallArgs &args, Elem value) {
|
||||
args.rval().setDouble(JS::CanonicalizeNaN(value));
|
||||
}
|
||||
};
|
||||
|
||||
struct Int32x4 {
|
||||
typedef int32_t Elem;
|
||||
static const unsigned lanes = 4;
|
||||
@ -246,6 +319,12 @@ simd_float32x4_##Name(JSContext *cx, unsigned argc, Value *vp);
|
||||
FLOAT32X4_FUNCTION_LIST(DECLARE_SIMD_FLOAT32X4_FUNCTION)
|
||||
#undef DECLARE_SIMD_FLOAT32X4_FUNCTION
|
||||
|
||||
#define DECLARE_SIMD_FLOAT64X2_FUNCTION(Name, Func, Operands, Flags) \
|
||||
extern bool \
|
||||
simd_float64x2_##Name(JSContext *cx, unsigned argc, Value *vp);
|
||||
FLOAT64X2_FUNCTION_LIST(DECLARE_SIMD_FLOAT64X2_FUNCTION)
|
||||
#undef DECLARE_SIMD_FLOAT64X2_FUNCTION
|
||||
|
||||
#define DECLARE_SIMD_INT32x4_FUNCTION(Name, Func, Operands, Flags) \
|
||||
extern bool \
|
||||
simd_int32x4_##Name(JSContext *cx, unsigned argc, Value *vp);
|
||||
|
@ -406,18 +406,25 @@ js::ReferenceTypeDescr::call(JSContext *cx, unsigned argc, Value *vp)
|
||||
}
|
||||
|
||||
/***************************************************************************
|
||||
* X4 type objects
|
||||
* SIMD type objects
|
||||
*
|
||||
* Note: these are partially defined in SIMD.cpp
|
||||
*/
|
||||
|
||||
static const int32_t SimdSizes[] = {
|
||||
#define SIMD_SIZE(_kind, _type, _name) \
|
||||
sizeof(_type) * 4,
|
||||
#define SIMD_SIZE(_kind, _type, _name, _lanes) \
|
||||
sizeof(_type) * _lanes,
|
||||
JS_FOR_EACH_SIMD_TYPE_REPR(SIMD_SIZE) 0
|
||||
#undef SIMD_SIZE
|
||||
};
|
||||
|
||||
static int32_t SimdLanes[] = {
|
||||
#define SIMD_LANE(_kind, _type, _name, _lanes) \
|
||||
_lanes,
|
||||
JS_FOR_EACH_SIMD_TYPE_REPR(SIMD_LANE) 0
|
||||
#undef SIMD_LANE
|
||||
};
|
||||
|
||||
int32_t
|
||||
SimdTypeDescr::size(Type t)
|
||||
{
|
||||
@ -430,6 +437,12 @@ SimdTypeDescr::alignment(Type t)
|
||||
return SimdSizes[t];
|
||||
}
|
||||
|
||||
int32_t
|
||||
SimdTypeDescr::lanes(Type t)
|
||||
{
|
||||
return SimdLanes[t];
|
||||
}
|
||||
|
||||
/***************************************************************************
|
||||
* ArrayMetaTypeDescr class
|
||||
*/
|
||||
@ -2694,6 +2707,16 @@ js::GetFloat32x4TypeDescr(JSContext *cx, unsigned argc, Value *vp)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
js::GetFloat64x2TypeDescr(JSContext *cx, unsigned argc, Value *vp)
|
||||
{
|
||||
CallArgs args = CallArgsFromVp(argc, vp);
|
||||
Rooted<GlobalObject*> global(cx, cx->global());
|
||||
MOZ_ASSERT(global);
|
||||
args.rval().setObject(global->float64x2TypeDescr());
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
js::GetInt32x4TypeDescr(JSContext *cx, unsigned argc, Value *vp)
|
||||
{
|
||||
|
@ -325,7 +325,7 @@ class ComplexTypeDescr : public TypeDescr
|
||||
};
|
||||
|
||||
/*
|
||||
* Type descriptors `float32x4` and `int32x4`
|
||||
* Type descriptors `float32x4`, `int32x4` and `float64x2`
|
||||
*/
|
||||
class SimdTypeDescr : public ComplexTypeDescr
|
||||
{
|
||||
@ -333,6 +333,7 @@ class SimdTypeDescr : public ComplexTypeDescr
|
||||
enum Type {
|
||||
TYPE_INT32 = JS_SIMDTYPEREPR_INT32,
|
||||
TYPE_FLOAT32 = JS_SIMDTYPEREPR_FLOAT32,
|
||||
TYPE_FLOAT64 = JS_SIMDTYPEREPR_FLOAT64
|
||||
};
|
||||
|
||||
static const type::Kind Kind = type::Simd;
|
||||
@ -340,6 +341,7 @@ class SimdTypeDescr : public ComplexTypeDescr
|
||||
static const Class class_;
|
||||
static int32_t size(Type t);
|
||||
static int32_t alignment(Type t);
|
||||
static int32_t lanes(Type t);
|
||||
|
||||
SimdTypeDescr::Type type() const {
|
||||
return (SimdTypeDescr::Type) getReservedSlot(JS_DESCR_SLOT_TYPE).toInt32();
|
||||
@ -350,8 +352,9 @@ class SimdTypeDescr : public ComplexTypeDescr
|
||||
};
|
||||
|
||||
#define JS_FOR_EACH_SIMD_TYPE_REPR(macro_) \
|
||||
macro_(SimdTypeDescr::TYPE_INT32, int32_t, int32) \
|
||||
macro_(SimdTypeDescr::TYPE_FLOAT32, float, float32)
|
||||
macro_(SimdTypeDescr::TYPE_INT32, int32_t, int32, 4) \
|
||||
macro_(SimdTypeDescr::TYPE_FLOAT32, float, float32, 4) \
|
||||
macro_(SimdTypeDescr::TYPE_FLOAT64, double, float64, 2)
|
||||
|
||||
bool IsTypedObjectClass(const Class *clasp); // Defined below
|
||||
bool IsTypedObjectArray(JSObject& obj);
|
||||
@ -880,6 +883,14 @@ bool GetTypedObjectModule(JSContext *cx, unsigned argc, Value *vp);
|
||||
*/
|
||||
bool GetFloat32x4TypeDescr(JSContext *cx, unsigned argc, Value *vp);
|
||||
|
||||
/*
|
||||
* Usage: GetFloat64x2TypeDescr()
|
||||
*
|
||||
* Returns the float64x2 type object. SIMD pseudo-module must have
|
||||
* been initialized for this to be safe.
|
||||
*/
|
||||
bool GetFloat64x2TypeDescr(JSContext *cx, unsigned argc, Value *vp);
|
||||
|
||||
/*
|
||||
* Usage: GetInt32x4TypeDescr()
|
||||
*
|
||||
|
@ -152,6 +152,11 @@ function TypedObjectGetSimd(descr, typedObj, offset) {
|
||||
var w = Load_float32(typedObj, offset + 12);
|
||||
return GetFloat32x4TypeDescr()(x, y, z, w);
|
||||
|
||||
case JS_SIMDTYPEREPR_FLOAT64:
|
||||
var x = Load_float64(typedObj, offset + 0);
|
||||
var y = Load_float64(typedObj, offset + 8);
|
||||
return GetFloat64x2TypeDescr()(x, y);
|
||||
|
||||
case JS_SIMDTYPEREPR_INT32:
|
||||
var x = Load_int32(typedObj, offset + 0);
|
||||
var y = Load_int32(typedObj, offset + 4);
|
||||
@ -322,6 +327,10 @@ function TypedObjectSetSimd(descr, typedObj, offset, fromValue) {
|
||||
Store_float32(typedObj, offset + 8, Load_float32(fromValue, 8));
|
||||
Store_float32(typedObj, offset + 12, Load_float32(fromValue, 12));
|
||||
break;
|
||||
case JS_SIMDTYPEREPR_FLOAT64:
|
||||
Store_float64(typedObj, offset + 0, Load_float64(fromValue, 0));
|
||||
Store_float64(typedObj, offset + 8, Load_float64(fromValue, 8));
|
||||
break;
|
||||
case JS_SIMDTYPEREPR_INT32:
|
||||
Store_int32(typedObj, offset + 0, Load_int32(fromValue, 0));
|
||||
Store_int32(typedObj, offset + 4, Load_int32(fromValue, 4));
|
||||
@ -457,6 +466,21 @@ function SimdProtoString(type) {
|
||||
return "int32x4";
|
||||
case JS_SIMDTYPEREPR_FLOAT32:
|
||||
return "float32x4";
|
||||
case JS_SIMDTYPEREPR_FLOAT64:
|
||||
return "float64x2";
|
||||
}
|
||||
|
||||
assert(false, "Unhandled type constant");
|
||||
return undefined;
|
||||
}
|
||||
|
||||
function SimdTypeToLength(type) {
|
||||
switch (type) {
|
||||
case JS_SIMDTYPEREPR_INT32:
|
||||
case JS_SIMDTYPEREPR_FLOAT32:
|
||||
return 4;
|
||||
case JS_SIMDTYPEREPR_FLOAT64:
|
||||
return 2;
|
||||
}
|
||||
|
||||
assert(false, "Unhandled type constant");
|
||||
@ -473,7 +497,12 @@ function SimdToSource() {
|
||||
ThrowError(JSMSG_INCOMPATIBLE_PROTO, "SIMD", "toSource", typeof this);
|
||||
|
||||
var type = DESCR_TYPE(descr);
|
||||
return SimdProtoString(type)+"("+this.x+", "+this.y+", "+this.z+", "+this.w+")";
|
||||
var protoString = SimdProtoString(type);
|
||||
var length = SimdTypeToLength(type);
|
||||
if (length == 4)
|
||||
return protoString+"("+this.x+", "+this.y+", "+this.z+", "+this.w+")";
|
||||
else if (length == 2)
|
||||
return protoString+"("+this.x+", "+this.y+")";
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
@ -32,8 +32,9 @@
|
||||
#define JS_DESCR_SLOT_ARRAYPROTO 6 // Lazily created prototype for arrays
|
||||
#define JS_DESCR_SLOT_TRACE_LIST 7 // List of references for use in tracing
|
||||
|
||||
// Slots on scalars, references, and x4s
|
||||
// Slots on scalars, references, and SIMD objects
|
||||
#define JS_DESCR_SLOT_TYPE 8 // Type code
|
||||
#define JS_DESCR_SLOT_LANES 9
|
||||
|
||||
// Slots on array descriptors
|
||||
#define JS_DESCR_SLOT_ARRAY_ELEM_TYPE 8
|
||||
@ -85,5 +86,6 @@
|
||||
// case.
|
||||
#define JS_SIMDTYPEREPR_INT32 0
|
||||
#define JS_SIMDTYPEREPR_FLOAT32 1
|
||||
#define JS_SIMDTYPEREPR_FLOAT64 2
|
||||
|
||||
#endif
|
||||
|
@ -79,6 +79,7 @@
|
||||
macro(float32, float32, "float32") \
|
||||
macro(float32x4, float32x4, "float32x4") \
|
||||
macro(float64, float64, "float64") \
|
||||
macro(float64x2, float64x2, "float64x2") \
|
||||
macro(forceInterpreter, forceInterpreter, "forceInterpreter") \
|
||||
macro(format, format, "format") \
|
||||
macro(frame, frame, "frame") \
|
||||
|
@ -104,8 +104,9 @@ class GlobalObject : public NativeObject
|
||||
static const unsigned RUNTIME_CODEGEN_ENABLED = WARNED_PROTO_SETTING_SLOW + 1;
|
||||
static const unsigned DEBUGGERS = RUNTIME_CODEGEN_ENABLED + 1;
|
||||
static const unsigned INTRINSICS = DEBUGGERS + 1;
|
||||
static const unsigned FLOAT32X4_TYPE_DESCR = INTRINSICS + 1;
|
||||
static const unsigned INT32X4_TYPE_DESCR = FLOAT32X4_TYPE_DESCR + 1;
|
||||
static const unsigned FLOAT32X4_TYPE_DESCR = INTRINSICS + 1;
|
||||
static const unsigned FLOAT64X2_TYPE_DESCR = FLOAT32X4_TYPE_DESCR + 1;
|
||||
static const unsigned INT32X4_TYPE_DESCR = FLOAT64X2_TYPE_DESCR + 1;
|
||||
static const unsigned FOR_OF_PIC_CHAIN = INT32X4_TYPE_DESCR + 1;
|
||||
|
||||
/* Total reserved-slot count for global objects. */
|
||||
@ -408,6 +409,16 @@ class GlobalObject : public NativeObject
|
||||
return getSlotRef(FLOAT32X4_TYPE_DESCR).toObject();
|
||||
}
|
||||
|
||||
void setFloat64x2TypeDescr(JSObject &obj) {
|
||||
MOZ_ASSERT(getSlotRef(FLOAT64X2_TYPE_DESCR).isUndefined());
|
||||
setSlot(FLOAT64X2_TYPE_DESCR, ObjectValue(obj));
|
||||
}
|
||||
|
||||
JSObject &float64x2TypeDescr() {
|
||||
MOZ_ASSERT(getSlotRef(FLOAT64X2_TYPE_DESCR).isObject());
|
||||
return getSlotRef(FLOAT64X2_TYPE_DESCR).toObject();
|
||||
}
|
||||
|
||||
void setInt32x4TypeDescr(JSObject &obj) {
|
||||
MOZ_ASSERT(getSlotRef(INT32X4_TYPE_DESCR).isUndefined());
|
||||
setSlot(INT32X4_TYPE_DESCR, ObjectValue(obj));
|
||||
|
@ -969,6 +969,7 @@ static const JSFunctionSpec intrinsic_functions[] = {
|
||||
JS_FN("ClampToUint8", js::ClampToUint8, 1, 0),
|
||||
JS_FN("GetTypedObjectModule", js::GetTypedObjectModule, 0, 0),
|
||||
JS_FN("GetFloat32x4TypeDescr", js::GetFloat32x4TypeDescr, 0, 0),
|
||||
JS_FN("GetFloat64x2TypeDescr", js::GetFloat64x2TypeDescr, 0, 0),
|
||||
JS_FN("GetInt32x4TypeDescr", js::GetInt32x4TypeDescr, 0, 0),
|
||||
|
||||
#define LOAD_AND_STORE_SCALAR_FN_DECLS(_constant, _type, _name) \
|
||||
|
Loading…
Reference in New Issue
Block a user