Backed out changeset 5b3dd105258e for Windows build failures

--HG--
extra : rebase_source : 83cadf05aaff31283f52bca8e0c9b90b2d8c6cc0
This commit is contained in:
Benjamin Bouvier 2014-02-04 16:33:21 +01:00
parent 8fded3a557
commit 0e8978f8ec
5 changed files with 50 additions and 138 deletions

View File

@ -98,4 +98,3 @@ assertEq(asmLink(asmCompileCached("g","ffis", USE_ASM + "var x=ffis.x|0; functio
var i32 = new Int32Array(4096);
i32[4] = 42;
assertEq(asmLink(asmCompileCached("g","ffis","buf", USE_ASM + "var i32=new g.Int32Array(buf); function f(i) { i=i|0; return i32[i>>2]|0 } return f"), this, null, i32.buffer)(4*4), 42);
assertEq(asmLink(asmCompileCached('glob', USE_ASM + 'var x=glob.Math.PI; function f() { return +x } return f'), this)(), Math.PI);

View File

@ -86,17 +86,3 @@ assertAsmTypeFail('glob', USE_ASM + 'var im=glob.Math.imul; function f(i) { i=i|
assertAsmTypeFail('glob', USE_ASM + 'var im=glob.Math.imul; function f(i) { i=i|0; i = im(i,i); } return f');
assertAsmTypeFail('glob', USE_ASM + 'var abs=glob.Math.abs; function f(i) { i=i|0; +abs(i|0); } return f');
assertAsmTypeFail('glob', USE_ASM + 'var abs=glob.Math.abs; function f(d) { d=+d; abs(d)|0; } return f');
assertAsmTypeFail('glob', USE_ASM + 'var tau=glob.Math.TAU; function f() {} return f');
assertAsmTypeFail('glob', USE_ASM + 'var pi=glob.Math.PI; function f() { return pi | 0 } return f');
assertAsmTypeFail('glob', USE_ASM + 'var pi=glob.Math.PI; function f() { return +pi() } return f');
assertAsmTypeFail('glob', USE_ASM + 'var pi=glob.Math.PI; function f() { pi = +3; } return f');
assertAsmLinkAlwaysFail(asmCompile('glob', USE_ASM + 'var pi=glob.Math.PI; function f() {} return f'), {});
assertAsmLinkFail(asmCompile('glob', USE_ASM + 'var pi=glob.Math.PI; function f() {} return f'), {Math: {}});
assertAsmLinkFail(asmCompile('glob', USE_ASM + 'var pi=glob.Math.PI; function f() {} return f'), {Math: {PI: Math.cos}});
assertAsmLinkFail(asmCompile('glob', USE_ASM + 'var pi=glob.Math.PI; function f() {} return f'), {Math: {PI: Math.SQRT2}});
for (var c of ['E', 'LN10', 'LN2', 'LOG2E', 'LOG10E', 'PI', 'SQRT1_2', 'SQRT2']) {
var f = asmLink(asmCompile('glob', USE_ASM + 'var x=glob.Math.' + c +'; function f() { return +x } return f'), this);
assertEq(f(), eval('Math.' + c));
}

View File

@ -936,7 +936,7 @@ class MOZ_STACK_CLASS ModuleCompiler
FuncPtrTable,
FFI,
ArrayView,
MathBuiltinFunction
MathBuiltin
};
private:
@ -951,7 +951,7 @@ class MOZ_STACK_CLASS ModuleCompiler
uint32_t funcPtrTableIndex_;
uint32_t ffiIndex_;
ArrayBufferView::ViewType viewType_;
AsmJSMathBuiltinFunction mathBuiltinFunc_;
AsmJSMathBuiltin mathBuiltin_;
} u;
friend class ModuleCompiler;
@ -994,9 +994,9 @@ class MOZ_STACK_CLASS ModuleCompiler
JS_ASSERT(which_ == ArrayView);
return u.viewType_;
}
AsmJSMathBuiltinFunction mathBuiltinFunction() const {
JS_ASSERT(which_ == MathBuiltinFunction);
return u.mathBuiltinFunc_;
AsmJSMathBuiltin mathBuiltin() const {
JS_ASSERT(which_ == MathBuiltin);
return u.mathBuiltin_;
}
};
@ -1063,25 +1063,6 @@ class MOZ_STACK_CLASS ModuleCompiler
typedef HashMap<ExitDescriptor, unsigned, ExitDescriptor> ExitMap;
struct MathBuiltin
{
enum Kind { Function, Constant };
Kind kind;
union {
double cst;
AsmJSMathBuiltinFunction func;
} u;
MathBuiltin() : kind(Kind(-1)) {}
MathBuiltin(double cst) : kind(Constant) {
u.cst = cst;
}
MathBuiltin(AsmJSMathBuiltinFunction func) : kind(Function) {
u.func = func;
}
};
private:
struct SlowFunction
{
@ -1091,7 +1072,7 @@ class MOZ_STACK_CLASS ModuleCompiler
unsigned column;
};
typedef HashMap<PropertyName*, MathBuiltin> MathNameMap;
typedef HashMap<PropertyName*, AsmJSMathBuiltin> MathNameMap;
typedef HashMap<PropertyName*, Global*> GlobalMap;
typedef js::Vector<Func*> FuncVector;
typedef js::Vector<AsmJSGlobalAccess> GlobalAccessVector;
@ -1125,18 +1106,10 @@ class MOZ_STACK_CLASS ModuleCompiler
DebugOnly<bool> finishedFunctionBodies_;
bool addStandardLibraryMathName(const char *name, AsmJSMathBuiltinFunction func) {
bool addStandardLibraryMathName(const char *name, AsmJSMathBuiltin builtin) {
JSAtom *atom = Atomize(cx_, name, strlen(name));
if (!atom)
return false;
MathBuiltin builtin(func);
return standardLibraryMathNames_.putNew(atom->asPropertyName(), builtin);
}
bool addStandardLibraryMathName(const char *name, double cst) {
JSAtom *atom = Atomize(cx_, name, strlen(name));
if (!atom)
return false;
MathBuiltin builtin(cst);
return standardLibraryMathNames_.putNew(atom->asPropertyName(), builtin);
}
@ -1202,15 +1175,7 @@ class MOZ_STACK_CLASS ModuleCompiler
!addStandardLibraryMathName("abs", AsmJSMathBuiltin_abs) ||
!addStandardLibraryMathName("atan2", AsmJSMathBuiltin_atan2) ||
!addStandardLibraryMathName("imul", AsmJSMathBuiltin_imul) ||
!addStandardLibraryMathName("fround", AsmJSMathBuiltin_fround) ||
!addStandardLibraryMathName("E", M_E) ||
!addStandardLibraryMathName("LN10", M_LN10) ||
!addStandardLibraryMathName("LN2", M_LN2) ||
!addStandardLibraryMathName("LOG2E", M_LOG2E) ||
!addStandardLibraryMathName("LOG10E", M_LOG10E) ||
!addStandardLibraryMathName("PI", M_PI) ||
!addStandardLibraryMathName("SQRT1_2", M_SQRT1_2) ||
!addStandardLibraryMathName("SQRT2", M_SQRT2))
!addStandardLibraryMathName("fround", AsmJSMathBuiltin_fround))
{
return false;
}
@ -1324,7 +1289,7 @@ class MOZ_STACK_CLASS ModuleCompiler
FuncPtrTable &funcPtrTable(unsigned i) {
return funcPtrTables_[i];
}
bool lookupStandardLibraryMathName(PropertyName *name, MathBuiltin *mathBuiltin) const {
bool lookupStandardLibraryMathName(PropertyName *name, AsmJSMathBuiltin *mathBuiltin) const {
if (MathNameMap::Ptr p = standardLibraryMathNames_.lookup(name)) {
*mathBuiltin = p->value();
return true;
@ -1425,17 +1390,18 @@ class MOZ_STACK_CLASS ModuleCompiler
global->u.viewType_ = vt;
return globals_.putNew(varName, global);
}
bool addMathBuiltinFunction(PropertyName *varName, AsmJSMathBuiltinFunction func, PropertyName *fieldName) {
if (!module_->addMathBuiltinFunction(func, fieldName))
bool addMathBuiltin(PropertyName *varName, AsmJSMathBuiltin mathBuiltin, PropertyName *fieldName) {
if (!module_->addMathBuiltin(mathBuiltin, fieldName))
return false;
Global *global = moduleLifo_.new_<Global>(Global::MathBuiltinFunction);
Global *global = moduleLifo_.new_<Global>(Global::MathBuiltin);
if (!global)
return false;
global->u.mathBuiltinFunc_ = func;
global->u.mathBuiltin_ = mathBuiltin;
return globals_.putNew(varName, global);
}
private:
bool addGlobalDoubleConstant(PropertyName *varName, double constant) {
bool addGlobalConstant(PropertyName *varName, double constant, PropertyName *fieldName) {
if (!module_->addGlobalConstant(constant, fieldName))
return false;
Global *global = moduleLifo_.new_<Global>(Global::ConstantLiteral);
if (!global)
return false;
@ -1443,17 +1409,6 @@ class MOZ_STACK_CLASS ModuleCompiler
global->u.varOrConst.type_ = VarType::Double;
return globals_.putNew(varName, global);
}
public:
bool addMathBuiltinConstant(PropertyName *varName, double constant, PropertyName *fieldName) {
if (!module_->addMathBuiltinConstant(constant, fieldName))
return false;
return addGlobalDoubleConstant(varName, constant);
}
bool addGlobalConstant(PropertyName *varName, double constant, PropertyName *fieldName) {
if (!module_->addGlobalConstant(constant, fieldName))
return false;
return addGlobalDoubleConstant(varName, constant);
}
bool addExportedFunction(const Func *func, PropertyName *maybeFieldName) {
AsmJSModule::ArgCoercionVector argCoercions;
const VarTypeVector &args = func->sig().args();
@ -1819,8 +1774,8 @@ IsFloatCoercion(ModuleCompiler &m, ParseNode *pn, ParseNode **coercedExpr)
const ModuleCompiler::Global *global = m.lookupGlobal(callee->name());
if (!global ||
global->which() != ModuleCompiler::Global::MathBuiltinFunction ||
global->mathBuiltinFunction() != AsmJSMathBuiltin_fround)
global->which() != ModuleCompiler::Global::MathBuiltin ||
global->mathBuiltin() != AsmJSMathBuiltin_fround)
{
return false;
}
@ -3149,19 +3104,11 @@ CheckGlobalDotImport(ModuleCompiler &m, PropertyName *varName, ParseNode *initNo
if (!IsUseOfName(global, m.module().globalArgumentName()) || math != m.cx()->names().Math)
return m.fail(base, "expecting global.Math");
ModuleCompiler::MathBuiltin mathBuiltin;
AsmJSMathBuiltin mathBuiltin;
if (!m.lookupStandardLibraryMathName(field, &mathBuiltin))
return m.failName(initNode, "'%s' is not a standard Math builtin", field);
switch (mathBuiltin.kind) {
case ModuleCompiler::MathBuiltin::Function:
return m.addMathBuiltinFunction(varName, mathBuiltin.u.func, field);
case ModuleCompiler::MathBuiltin::Constant:
return m.addMathBuiltinConstant(varName, mathBuiltin.u.cst, field);
default:
break;
}
MOZ_ASSUME_UNREACHABLE("unexpected or uninitialized math builtin type");
return m.addMathBuiltin(varName, mathBuiltin, field);
}
if (IsUseOfName(base, m.module().globalArgumentName())) {
@ -3419,7 +3366,7 @@ CheckVarRef(FunctionCompiler &f, ParseNode *varRef, MDefinition **def, Type *typ
break;
case ModuleCompiler::Global::Function:
case ModuleCompiler::Global::FFI:
case ModuleCompiler::Global::MathBuiltinFunction:
case ModuleCompiler::Global::MathBuiltin:
case ModuleCompiler::Global::FuncPtrTable:
case ModuleCompiler::Global::ArrayView:
return f.failName(varRef, "'%s' may not be accessed by ordinary expressions", name);
@ -4074,12 +4021,12 @@ CheckIsMaybeFloat(FunctionCompiler &f, ParseNode *argNode, Type type)
}
static bool
CheckMathBuiltinCall(FunctionCompiler &f, ParseNode *callNode, AsmJSMathBuiltinFunction func,
CheckMathBuiltinCall(FunctionCompiler &f, ParseNode *callNode, AsmJSMathBuiltin mathBuiltin,
RetType retType, MDefinition **def, Type *type)
{
unsigned arity = 0;
AsmJSImmKind doubleCallee, floatCallee;
switch (func) {
switch (mathBuiltin) {
case AsmJSMathBuiltin_imul: return CheckMathIMul(f, callNode, retType, def, type);
case AsmJSMathBuiltin_abs: return CheckMathAbs(f, callNode, retType, def, type);
case AsmJSMathBuiltin_sqrt: return CheckMathSqrt(f, callNode, retType, def, type);
@ -4096,7 +4043,7 @@ CheckMathBuiltinCall(FunctionCompiler &f, ParseNode *callNode, AsmJSMathBuiltinF
case AsmJSMathBuiltin_log: arity = 1; doubleCallee = AsmJSImm_LogD; floatCallee = AsmJSImm_LogF; break;
case AsmJSMathBuiltin_pow: arity = 2; doubleCallee = AsmJSImm_PowD; floatCallee = AsmJSImm_Invalid; break;
case AsmJSMathBuiltin_atan2: arity = 2; doubleCallee = AsmJSImm_ATan2D; floatCallee = AsmJSImm_Invalid; break;
default: MOZ_ASSUME_UNREACHABLE("unexpected mathBuiltin function");
default: MOZ_ASSUME_UNREACHABLE("unexpected mathBuiltin");
}
if (retType == RetType::Float && floatCallee == AsmJSImm_Invalid)
@ -4141,8 +4088,8 @@ CheckCall(FunctionCompiler &f, ParseNode *call, RetType retType, MDefinition **d
switch (global->which()) {
case ModuleCompiler::Global::FFI:
return CheckFFICall(f, call, global->ffiIndex(), retType, def, type);
case ModuleCompiler::Global::MathBuiltinFunction:
return CheckMathBuiltinCall(f, call, global->mathBuiltinFunction(), retType, def, type);
case ModuleCompiler::Global::MathBuiltin:
return CheckMathBuiltinCall(f, call, global->mathBuiltin(), retType, def, type);
case ModuleCompiler::Global::ConstantLiteral:
case ModuleCompiler::Global::ConstantImport:
case ModuleCompiler::Global::Variable:

View File

@ -143,7 +143,7 @@ ValidateArrayView(JSContext *cx, AsmJSModule::Global &global, HandleValue global
}
static bool
ValidateMathBuiltinFunction(JSContext *cx, AsmJSModule::Global &global, HandleValue globalVal)
ValidateMathBuiltin(JSContext *cx, AsmJSModule::Global &global, HandleValue globalVal)
{
RootedValue v(cx);
if (!GetDataProperty(cx, globalVal, cx->names().Math, &v))
@ -153,7 +153,7 @@ ValidateMathBuiltinFunction(JSContext *cx, AsmJSModule::Global &global, HandleVa
return false;
Native native = nullptr;
switch (global.mathBuiltinFunction()) {
switch (global.mathBuiltin()) {
case AsmJSMathBuiltin_sin: native = math_sin; break;
case AsmJSMathBuiltin_cos: native = math_cos; break;
case AsmJSMathBuiltin_tan: native = math_tan; break;
@ -173,26 +173,21 @@ ValidateMathBuiltinFunction(JSContext *cx, AsmJSModule::Global &global, HandleVa
}
if (!IsNativeFunction(v, native))
return LinkFail(cx, "bad Math.* builtin function");
return LinkFail(cx, "bad Math.* builtin");
return true;
}
static bool
ValidateConstant(JSContext *cx, AsmJSModule::Global &global, HandleValue globalVal)
ValidateGlobalConstant(JSContext *cx, AsmJSModule::Global &global, HandleValue globalVal)
{
RootedPropertyName field(cx, global.constantName());
RootedValue v(cx, globalVal);
if (global.constantKind() == AsmJSModule::Global::MathConstant) {
if (!GetDataProperty(cx, v, cx->names().Math, &v))
return false;
}
if (!GetDataProperty(cx, v, field, &v))
RootedValue v(cx);
if (!GetDataProperty(cx, globalVal, field, &v))
return false;
if (!v.isNumber())
return LinkFail(cx, "math / global constant value needs to be a number");
return LinkFail(cx, "global constant value needs to be a number");
// NaN != NaN
if (IsNaN(global.constantValue())) {
@ -274,12 +269,12 @@ DynamicallyLinkModule(JSContext *cx, CallArgs args, AsmJSModule &module)
if (!ValidateArrayView(cx, global, globalVal, bufferVal))
return false;
break;
case AsmJSModule::Global::MathBuiltinFunction:
if (!ValidateMathBuiltinFunction(cx, global, globalVal))
case AsmJSModule::Global::MathBuiltin:
if (!ValidateMathBuiltin(cx, global, globalVal))
return false;
break;
case AsmJSModule::Global::Constant:
if (!ValidateConstant(cx, global, globalVal))
if (!ValidateGlobalConstant(cx, global, globalVal))
return false;
break;
}

View File

@ -34,7 +34,7 @@ enum AsmJSCoercion
};
// The asm.js spec recognizes this set of builtin Math functions.
enum AsmJSMathBuiltinFunction
enum AsmJSMathBuiltin
{
AsmJSMathBuiltin_sin, AsmJSMathBuiltin_cos, AsmJSMathBuiltin_tan,
AsmJSMathBuiltin_asin, AsmJSMathBuiltin_acos, AsmJSMathBuiltin_atan,
@ -97,9 +97,8 @@ class AsmJSModule
class Global
{
public:
enum Which { Variable, FFI, ArrayView, MathBuiltinFunction, Constant };
enum Which { Variable, FFI, ArrayView, MathBuiltin, Constant };
enum VarInitKind { InitConstant, InitImport };
enum ConstantKind { GlobalConstant, MathConstant };
private:
struct Pod {
@ -115,11 +114,8 @@ class AsmJSModule
} var;
uint32_t ffiIndex_;
ArrayBufferView::ViewType viewType_;
AsmJSMathBuiltinFunction mathBuiltinFunc_;
struct {
ConstantKind kind_;
double value_;
} constant;
AsmJSMathBuiltin mathBuiltin_;
double constantValue_;
} u;
} pod;
PropertyName *name_;
@ -183,24 +179,20 @@ class AsmJSModule
return pod.u.viewType_;
}
PropertyName *mathName() const {
JS_ASSERT(pod.which_ == MathBuiltinFunction);
JS_ASSERT(pod.which_ == MathBuiltin);
return name_;
}
AsmJSMathBuiltinFunction mathBuiltinFunction() const {
JS_ASSERT(pod.which_ == MathBuiltinFunction);
return pod.u.mathBuiltinFunc_;
AsmJSMathBuiltin mathBuiltin() const {
JS_ASSERT(pod.which_ == MathBuiltin);
return pod.u.mathBuiltin_;
}
PropertyName *constantName() const {
JS_ASSERT(pod.which_ == Constant);
return name_;
}
ConstantKind constantKind() const {
JS_ASSERT(pod.which_ == Constant);
return pod.u.constant.kind_;
}
double constantValue() const {
JS_ASSERT(pod.which_ == Constant);
return pod.u.constant.value_;
return pod.u.constantValue_;
}
size_t serializedSize() const;
@ -496,21 +488,14 @@ class AsmJSModule
g.pod.u.viewType_ = vt;
return globals_.append(g);
}
bool addMathBuiltinFunction(AsmJSMathBuiltinFunction func, PropertyName *field) {
Global g(Global::MathBuiltinFunction, field);
g.pod.u.mathBuiltinFunc_ = func;
return globals_.append(g);
}
bool addMathBuiltinConstant(double value, PropertyName *field) {
Global g(Global::Constant, field);
g.pod.u.constant.value_ = value;
g.pod.u.constant.kind_ = Global::MathConstant;
bool addMathBuiltin(AsmJSMathBuiltin mathBuiltin, PropertyName *field) {
Global g(Global::MathBuiltin, field);
g.pod.u.mathBuiltin_ = mathBuiltin;
return globals_.append(g);
}
bool addGlobalConstant(double value, PropertyName *name) {
Global g(Global::Constant, name);
g.pod.u.constant.value_ = value;
g.pod.u.constant.kind_ = Global::GlobalConstant;
g.pod.u.constantValue_ = value;
return globals_.append(g);
}
bool addFuncPtrTable(unsigned numElems, uint32_t *globalDataOffset) {