зеркало из https://github.com/mozilla/gecko-dev.git
Bug 996076: Preparatory clean-ups, factor out error code; r=nmatsakis
This commit is contained in:
Родитель
5c947c8bd5
Коммит
3850b48521
|
@ -42,7 +42,7 @@ static bool GetX4Lane(JSContext *cx, unsigned argc, Value *vp) {
|
|||
typedef typename Type32x4::Elem Elem;
|
||||
|
||||
CallArgs args = CallArgsFromVp(argc, vp);
|
||||
if(!args.thisv().isObject() || !args.thisv().toObject().is<TypedObject>()) {
|
||||
if (!args.thisv().isObject() || !args.thisv().toObject().is<TypedObject>()) {
|
||||
JS_ReportErrorNumber(cx, js_GetErrorMessage, nullptr, JSMSG_INCOMPATIBLE_PROTO,
|
||||
X4TypeDescr::class_.name, laneNames[lane],
|
||||
InformalValueTypeName(args.thisv()));
|
||||
|
@ -84,7 +84,7 @@ static bool SignMask(JSContext *cx, unsigned argc, Value *vp) {
|
|||
typedef typename Type32x4::Elem Elem;
|
||||
|
||||
CallArgs args = CallArgsFromVp(argc, vp);
|
||||
if(!args.thisv().isObject() || !args.thisv().toObject().is<TypedObject>()) {
|
||||
if (!args.thisv().isObject() || !args.thisv().toObject().is<TypedObject>()) {
|
||||
JS_ReportErrorNumber(cx, js_GetErrorMessage, nullptr, JSMSG_INCOMPATIBLE_PROTO,
|
||||
X4TypeDescr::class_.name, "signMask",
|
||||
InformalValueTypeName(args.thisv()));
|
||||
|
@ -255,7 +255,7 @@ bool
|
|||
X4TypeDescr::call(JSContext *cx, unsigned argc, Value *vp)
|
||||
{
|
||||
CallArgs args = CallArgsFromVp(argc, vp);
|
||||
const uint32_t LANES = 4;
|
||||
const unsigned LANES = 4;
|
||||
|
||||
if (args.length() < LANES) {
|
||||
JS_ReportErrorNumber(cx, js_GetErrorMessage, nullptr, JSMSG_MORE_ARGS_NEEDED,
|
||||
|
@ -264,7 +264,7 @@ X4TypeDescr::call(JSContext *cx, unsigned argc, Value *vp)
|
|||
}
|
||||
|
||||
double values[LANES];
|
||||
for (uint32_t i = 0; i < LANES; i++) {
|
||||
for (unsigned i = 0; i < LANES; i++) {
|
||||
if (!ToNumber(cx, args[i], &values[i]))
|
||||
return false;
|
||||
}
|
||||
|
@ -279,9 +279,8 @@ X4TypeDescr::call(JSContext *cx, unsigned argc, Value *vp)
|
|||
case _constant: \
|
||||
{ \
|
||||
_type *mem = reinterpret_cast<_type*>(result->typedMem()); \
|
||||
for (uint32_t i = 0; i < LANES; i++) { \
|
||||
for (unsigned i = 0; i < LANES; i++) \
|
||||
mem[i] = ConvertScalar<_type>(values[i]); \
|
||||
} \
|
||||
break; \
|
||||
}
|
||||
JS_FOR_EACH_X4_TYPE_REPR(STORE_LANES)
|
||||
|
@ -324,7 +323,7 @@ SIMDObject::initClass(JSContext *cx, Handle<GlobalObject *> global)
|
|||
|
||||
// Create SIMD Object.
|
||||
RootedObject objProto(cx, global->getOrCreateObjectPrototype(cx));
|
||||
if(!objProto)
|
||||
if (!objProto)
|
||||
return nullptr;
|
||||
RootedObject SIMD(cx, NewObjectWithGivenProto(cx, &SIMDObject::class_, objProto,
|
||||
global, SingletonObject));
|
||||
|
@ -332,13 +331,13 @@ SIMDObject::initClass(JSContext *cx, Handle<GlobalObject *> global)
|
|||
return nullptr;
|
||||
|
||||
// float32x4
|
||||
|
||||
RootedObject float32x4Object(cx);
|
||||
float32x4Object = CreateX4Class<Float32x4Defn>(cx, global,
|
||||
cx->names().float32x4);
|
||||
if (!float32x4Object)
|
||||
return nullptr;
|
||||
|
||||
// Define float32x4 functions and install as a property of the SIMD object.
|
||||
RootedValue float32x4Value(cx, ObjectValue(*float32x4Object));
|
||||
if (!JS_DefineFunctions(cx, float32x4Object, Float32x4Methods) ||
|
||||
!JSObject::defineProperty(cx, SIMD, cx->names().float32x4,
|
||||
|
@ -349,13 +348,13 @@ SIMDObject::initClass(JSContext *cx, Handle<GlobalObject *> global)
|
|||
}
|
||||
|
||||
// int32x4
|
||||
|
||||
RootedObject int32x4Object(cx);
|
||||
int32x4Object = CreateX4Class<Int32x4Defn>(cx, global,
|
||||
cx->names().int32x4);
|
||||
if (!int32x4Object)
|
||||
return nullptr;
|
||||
|
||||
// Define int32x4 functions and install as a property of the SIMD object.
|
||||
RootedValue int32x4Value(cx, ObjectValue(*int32x4Object));
|
||||
if (!JS_DefineFunctions(cx, int32x4Object, Int32x4Methods) ||
|
||||
!JSObject::defineProperty(cx, SIMD, cx->names().int32x4,
|
||||
|
@ -372,13 +371,8 @@ SIMDObject::initClass(JSContext *cx, Handle<GlobalObject *> global)
|
|||
return nullptr;
|
||||
|
||||
global->setConstructor(JSProto_SIMD, SIMDValue);
|
||||
|
||||
// Define float32x4 functions and install as a property of the SIMD object.
|
||||
global->setFloat32x4TypeDescr(*float32x4Object);
|
||||
|
||||
// Define int32x4 functions and install as a property of the SIMD object.
|
||||
global->setInt32x4TypeDescr(*int32x4Object);
|
||||
|
||||
return SIMD;
|
||||
}
|
||||
|
||||
|
@ -562,6 +556,13 @@ struct Shuffle {
|
|||
};
|
||||
}
|
||||
|
||||
static inline bool
|
||||
ErrorBadArgs(JSContext *cx)
|
||||
{
|
||||
JS_ReportErrorNumber(cx, js_GetErrorMessage, nullptr, JSMSG_TYPED_ARRAY_BAD_ARGS);
|
||||
return false;
|
||||
}
|
||||
|
||||
template<typename V, typename Op, typename Vret>
|
||||
static bool
|
||||
Func(JSContext *cx, unsigned argc, Value *vp)
|
||||
|
@ -570,32 +571,25 @@ Func(JSContext *cx, unsigned argc, Value *vp)
|
|||
typedef typename Vret::Elem RetElem;
|
||||
|
||||
CallArgs args = CallArgsFromVp(argc, vp);
|
||||
if (args.length() != 1 && args.length() != 2) {
|
||||
JS_ReportErrorNumber(cx, js_GetErrorMessage, nullptr, JSMSG_TYPED_ARRAY_BAD_ARGS);
|
||||
return false;
|
||||
}
|
||||
if (args.length() != 1 && args.length() != 2)
|
||||
return ErrorBadArgs(cx);
|
||||
|
||||
RetElem result[Vret::lanes];
|
||||
if (args.length() == 1) {
|
||||
if (!IsVectorObject<V>(args[0])) {
|
||||
JS_ReportErrorNumber(cx, js_GetErrorMessage, nullptr, JSMSG_TYPED_ARRAY_BAD_ARGS);
|
||||
return false;
|
||||
}
|
||||
if (!IsVectorObject<V>(args[0]))
|
||||
return ErrorBadArgs(cx);
|
||||
|
||||
Elem *val = TypedObjectMemory<Elem *>(args[0]);
|
||||
for (int32_t i = 0; i < Vret::lanes; i++)
|
||||
for (unsigned i = 0; i < Vret::lanes; i++)
|
||||
result[i] = Op::apply(val[i], 0);
|
||||
} else {
|
||||
JS_ASSERT(args.length() == 2);
|
||||
if(!IsVectorObject<V>(args[0]) || !IsVectorObject<V>(args[1]))
|
||||
{
|
||||
JS_ReportErrorNumber(cx, js_GetErrorMessage, nullptr, JSMSG_TYPED_ARRAY_BAD_ARGS);
|
||||
return false;
|
||||
}
|
||||
if (!IsVectorObject<V>(args[0]) || !IsVectorObject<V>(args[1]))
|
||||
return ErrorBadArgs(cx);
|
||||
|
||||
Elem *left = TypedObjectMemory<Elem *>(args[0]);
|
||||
Elem *right = TypedObjectMemory<Elem *>(args[1]);
|
||||
for (int32_t i = 0; i < Vret::lanes; i++)
|
||||
for (unsigned i = 0; i < Vret::lanes; i++)
|
||||
result[i] = Op::apply(left[i], right[i]);
|
||||
}
|
||||
|
||||
|
@ -618,8 +612,7 @@ FuncWith(JSContext *cx, unsigned argc, Value *vp)
|
|||
if (args.length() != 2 || !IsVectorObject<V>(args[0]) ||
|
||||
(!args[1].isNumber() && !args[1].isBoolean()))
|
||||
{
|
||||
JS_ReportErrorNumber(cx, js_GetErrorMessage, nullptr, JSMSG_TYPED_ARRAY_BAD_ARGS);
|
||||
return false;
|
||||
return ErrorBadArgs(cx);
|
||||
}
|
||||
|
||||
Elem *val = TypedObjectMemory<Elem *>(args[0]);
|
||||
|
@ -629,11 +622,12 @@ FuncWith(JSContext *cx, unsigned argc, Value *vp)
|
|||
Elem withAsNumber;
|
||||
if (!Vret::toType(cx, args[1], &withAsNumber))
|
||||
return false;
|
||||
for (int32_t i = 0; i < Vret::lanes; i++)
|
||||
for (unsigned i = 0; i < Vret::lanes; i++)
|
||||
result[i] = OpWith::apply(i, withAsNumber, val[i]);
|
||||
} else if (args[1].isBoolean()) {
|
||||
} else {
|
||||
JS_ASSERT(args[1].isBoolean());
|
||||
bool withAsBool = args[1].toBoolean();
|
||||
for (int32_t i = 0; i < Vret::lanes; i++)
|
||||
for (unsigned i = 0; i < Vret::lanes; i++)
|
||||
result[i] = OpWith::apply(i, withAsBool, val[i]);
|
||||
}
|
||||
|
||||
|
@ -653,33 +647,25 @@ FuncShuffle(JSContext *cx, unsigned argc, Value *vp)
|
|||
typedef typename Vret::Elem RetElem;
|
||||
|
||||
CallArgs args = CallArgsFromVp(argc, vp);
|
||||
if (args.length() != 2 && args.length() != 3) {
|
||||
JS_ReportErrorNumber(cx, js_GetErrorMessage, nullptr, JSMSG_TYPED_ARRAY_BAD_ARGS);
|
||||
return false;
|
||||
}
|
||||
if (args.length() != 2 && args.length() != 3)
|
||||
return ErrorBadArgs(cx);
|
||||
|
||||
RetElem result[Vret::lanes];
|
||||
if (args.length() == 2) {
|
||||
if (!IsVectorObject<V>(args[0]) || !args[1].isNumber())
|
||||
{
|
||||
JS_ReportErrorNumber(cx, js_GetErrorMessage, nullptr, JSMSG_TYPED_ARRAY_BAD_ARGS);
|
||||
return false;
|
||||
}
|
||||
return ErrorBadArgs(cx);
|
||||
|
||||
Elem *val = TypedObjectMemory<Elem *>(args[0]);;
|
||||
Elem arg1;
|
||||
if (!Vret::toType(cx, args[1], &arg1))
|
||||
return false;
|
||||
|
||||
for (int32_t i = 0; i < Vret::lanes; i++)
|
||||
for (unsigned i = 0; i < Vret::lanes; i++)
|
||||
result[i] = val[OpShuffle::apply(i * 2, arg1)];
|
||||
} else {
|
||||
JS_ASSERT(args.length() == 3);
|
||||
if (!IsVectorObject<V>(args[0]) || !IsVectorObject<V>(args[1]) || !args[2].isNumber())
|
||||
{
|
||||
JS_ReportErrorNumber(cx, js_GetErrorMessage, nullptr, JSMSG_TYPED_ARRAY_BAD_ARGS);
|
||||
return false;
|
||||
}
|
||||
return ErrorBadArgs(cx);
|
||||
|
||||
Elem *val1 = TypedObjectMemory<Elem *>(args[0]);
|
||||
Elem *val2 = TypedObjectMemory<Elem *>(args[1]);
|
||||
|
@ -687,12 +673,11 @@ FuncShuffle(JSContext *cx, unsigned argc, Value *vp)
|
|||
if (!Vret::toType(cx, args[2], &arg2))
|
||||
return false;
|
||||
|
||||
for (int32_t i = 0; i < Vret::lanes; i++) {
|
||||
if (i < Vret::lanes / 2)
|
||||
result[i] = val1[OpShuffle::apply(i * 2, arg2)];
|
||||
else
|
||||
result[i] = val2[OpShuffle::apply(i * 2, arg2)];
|
||||
}
|
||||
unsigned i = 0;
|
||||
for (; i < Vret::lanes / 2; i++)
|
||||
result[i] = val1[OpShuffle::apply(i * 2, arg2)];
|
||||
for (; i < Vret::lanes; i++)
|
||||
result[i] = val2[OpShuffle::apply(i * 2, arg2)];
|
||||
}
|
||||
|
||||
RootedObject obj(cx, Create<Vret>(cx, result));
|
||||
|
@ -712,14 +697,11 @@ FuncConvert(JSContext *cx, unsigned argc, Value *vp)
|
|||
|
||||
CallArgs args = CallArgsFromVp(argc, vp);
|
||||
if (args.length() != 1 || !IsVectorObject<V>(args[0]))
|
||||
{
|
||||
JS_ReportErrorNumber(cx, js_GetErrorMessage, nullptr, JSMSG_TYPED_ARRAY_BAD_ARGS);
|
||||
return false;
|
||||
}
|
||||
return ErrorBadArgs(cx);
|
||||
|
||||
Elem *val = TypedObjectMemory<Elem *>(args[0]);
|
||||
RetElem result[Vret::lanes];
|
||||
for (int32_t i = 0; i < Vret::lanes; i++)
|
||||
for (unsigned i = 0; i < Vret::lanes; i++)
|
||||
result[i] = RetElem(val[i]);
|
||||
|
||||
RootedObject obj(cx, Create<Vret>(cx, result));
|
||||
|
@ -738,10 +720,7 @@ FuncConvertBits(JSContext *cx, unsigned argc, Value *vp)
|
|||
|
||||
CallArgs args = CallArgsFromVp(argc, vp);
|
||||
if (args.length() != 1 || !IsVectorObject<V>(args[0]))
|
||||
{
|
||||
JS_ReportErrorNumber(cx, js_GetErrorMessage, nullptr, JSMSG_TYPED_ARRAY_BAD_ARGS);
|
||||
return false;
|
||||
}
|
||||
return ErrorBadArgs(cx);
|
||||
|
||||
RetElem *val = TypedObjectMemory<RetElem *>(args[0]);
|
||||
RootedObject obj(cx, Create<Vret>(cx, val));
|
||||
|
@ -759,13 +738,11 @@ FuncZero(JSContext *cx, unsigned argc, Value *vp)
|
|||
typedef typename Vret::Elem RetElem;
|
||||
|
||||
CallArgs args = CallArgsFromVp(argc, vp);
|
||||
if (args.length() != 0) {
|
||||
JS_ReportErrorNumber(cx, js_GetErrorMessage, nullptr, JSMSG_TYPED_ARRAY_BAD_ARGS);
|
||||
return false;
|
||||
}
|
||||
if (args.length() != 0)
|
||||
return ErrorBadArgs(cx);
|
||||
|
||||
RetElem result[Vret::lanes];
|
||||
for (int32_t i = 0; i < Vret::lanes; i++)
|
||||
for (unsigned i = 0; i < Vret::lanes; i++)
|
||||
result[i] = RetElem(0);
|
||||
|
||||
RootedObject obj(cx, Create<Vret>(cx, result));
|
||||
|
@ -783,17 +760,15 @@ FuncSplat(JSContext *cx, unsigned argc, Value *vp)
|
|||
typedef typename Vret::Elem RetElem;
|
||||
|
||||
CallArgs args = CallArgsFromVp(argc, vp);
|
||||
if (args.length() != 1 || !args[0].isNumber()) {
|
||||
JS_ReportErrorNumber(cx, js_GetErrorMessage, nullptr, JSMSG_TYPED_ARRAY_BAD_ARGS);
|
||||
return false;
|
||||
}
|
||||
if (args.length() != 1 || !args[0].isNumber())
|
||||
return ErrorBadArgs(cx);
|
||||
|
||||
RetElem arg;
|
||||
if (!Vret::toType(cx, args[0], &arg))
|
||||
return false;
|
||||
|
||||
RetElem result[Vret::lanes];
|
||||
for (int32_t i = 0; i < Vret::lanes; i++)
|
||||
for (unsigned i = 0; i < Vret::lanes; i++)
|
||||
result[i] = arg;
|
||||
|
||||
RootedObject obj(cx, Create<Vret>(cx, result));
|
||||
|
@ -812,12 +787,11 @@ Int32x4Bool(JSContext *cx, unsigned argc, Value *vp)
|
|||
!args[0].isBoolean() || !args[1].isBoolean() ||
|
||||
!args[2].isBoolean() || !args[3].isBoolean())
|
||||
{
|
||||
JS_ReportErrorNumber(cx, js_GetErrorMessage, nullptr, JSMSG_TYPED_ARRAY_BAD_ARGS);
|
||||
return false;
|
||||
return ErrorBadArgs(cx);
|
||||
}
|
||||
|
||||
int32_t result[Int32x4::lanes];
|
||||
for (int32_t i = 0; i < Int32x4::lanes; i++)
|
||||
for (unsigned i = 0; i < Int32x4::lanes; i++)
|
||||
result[i] = args[i].toBoolean() ? 0xFFFFFFFF : 0x0;
|
||||
|
||||
RootedObject obj(cx, Create<Int32x4>(cx, result));
|
||||
|
@ -835,8 +809,7 @@ Float32x4Clamp(JSContext *cx, unsigned argc, Value *vp)
|
|||
if (args.length() != 3 || !IsVectorObject<Float32x4>(args[0]) ||
|
||||
!IsVectorObject<Float32x4>(args[1]) || !IsVectorObject<Float32x4>(args[2]))
|
||||
{
|
||||
JS_ReportErrorNumber(cx, js_GetErrorMessage, nullptr, JSMSG_TYPED_ARRAY_BAD_ARGS);
|
||||
return false;
|
||||
return ErrorBadArgs(cx);
|
||||
}
|
||||
|
||||
float *val = TypedObjectMemory<float *>(args[0]);
|
||||
|
@ -844,7 +817,7 @@ Float32x4Clamp(JSContext *cx, unsigned argc, Value *vp)
|
|||
float *upperLimit = TypedObjectMemory<float *>(args[2]);
|
||||
|
||||
float result[Float32x4::lanes];
|
||||
for (int32_t i = 0; i < Float32x4::lanes; i++) {
|
||||
for (unsigned i = 0; i < Float32x4::lanes; i++) {
|
||||
result[i] = val[i] < lowerLimit[i] ? lowerLimit[i] : val[i];
|
||||
result[i] = result[i] > upperLimit[i] ? upperLimit[i] : result[i];
|
||||
}
|
||||
|
@ -864,8 +837,7 @@ Int32x4Select(JSContext *cx, unsigned argc, Value *vp)
|
|||
if (args.length() != 3 || !IsVectorObject<Int32x4>(args[0]) ||
|
||||
!IsVectorObject<Float32x4>(args[1]) || !IsVectorObject<Float32x4>(args[2]))
|
||||
{
|
||||
JS_ReportErrorNumber(cx, js_GetErrorMessage, nullptr, JSMSG_TYPED_ARRAY_BAD_ARGS);
|
||||
return false;
|
||||
return ErrorBadArgs(cx);
|
||||
}
|
||||
|
||||
int32_t *val = TypedObjectMemory<int32_t *>(args[0]);
|
||||
|
@ -873,15 +845,15 @@ Int32x4Select(JSContext *cx, unsigned argc, Value *vp)
|
|||
int32_t *fv = TypedObjectMemory<int32_t *>(args[2]);
|
||||
|
||||
int32_t tr[Int32x4::lanes];
|
||||
for (int32_t i = 0; i < Int32x4::lanes; i++)
|
||||
for (unsigned i = 0; i < Int32x4::lanes; i++)
|
||||
tr[i] = And<int32_t, Int32x4>::apply(val[i], tv[i]);
|
||||
|
||||
int32_t fr[Int32x4::lanes];
|
||||
for (int32_t i = 0; i < Int32x4::lanes; i++)
|
||||
for (unsigned i = 0; i < Int32x4::lanes; i++)
|
||||
fr[i] = And<int32_t, Int32x4>::apply(Not<int32_t, Int32x4>::apply(val[i], 0), fv[i]);
|
||||
|
||||
int32_t orInt[Int32x4::lanes];
|
||||
for (int32_t i = 0; i < Int32x4::lanes; i++)
|
||||
for (unsigned i = 0; i < Int32x4::lanes; i++)
|
||||
orInt[i] = Or<int32_t, Int32x4>::apply(tr[i], fr[i]);
|
||||
|
||||
float *result = reinterpret_cast<float *>(orInt);
|
||||
|
|
|
@ -116,7 +116,7 @@ class SIMDObject : public JSObject
|
|||
|
||||
struct Float32x4 {
|
||||
typedef float Elem;
|
||||
static const int32_t lanes = 4;
|
||||
static const unsigned lanes = 4;
|
||||
static const X4TypeDescr::Type type = X4TypeDescr::TYPE_FLOAT32;
|
||||
|
||||
static TypeDescr &GetTypeDescr(GlobalObject &global) {
|
||||
|
@ -136,7 +136,7 @@ struct Float32x4 {
|
|||
|
||||
struct Int32x4 {
|
||||
typedef int32_t Elem;
|
||||
static const int32_t lanes = 4;
|
||||
static const unsigned lanes = 4;
|
||||
static const X4TypeDescr::Type type = X4TypeDescr::TYPE_INT32;
|
||||
|
||||
static TypeDescr &GetTypeDescr(GlobalObject &global) {
|
||||
|
|
Загрузка…
Ссылка в новой задаче