Bug 1052514: Use AsmJSNumLit in AsmJSModule.h; r=luke
authorBenjamin Bouvier <benj@benj.me>
Wed, 27 Aug 2014 12:21:42 +0200
changeset 223595 badda824a0b70630b225612a5983c3ea03d978fe
parent 223594 ae45bd114347b1c7990dc5dba65047957fafbae7
child 223596 0783f33c02707b9a6636a515384b6c57562c9fb5
push id3979
push userraliiev@mozilla.com
push dateMon, 13 Oct 2014 16:35:44 +0000
treeherdermozilla-beta@30f2cc610691 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersluke
bugs1052514
milestone34.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1052514: Use AsmJSNumLit in AsmJSModule.h; r=luke
js/src/asmjs/AsmJSLink.cpp
js/src/asmjs/AsmJSModule.h
js/src/asmjs/AsmJSValidate.cpp
--- a/js/src/asmjs/AsmJSLink.cpp
+++ b/js/src/asmjs/AsmJSLink.cpp
@@ -101,27 +101,32 @@ ValidateGlobalVariable(JSContext *cx, co
                        HandleValue importVal)
 {
     JS_ASSERT(global.which() == AsmJSModule::Global::Variable);
 
     void *datum = module.globalVarIndexToGlobalDatum(global.varIndex());
 
     switch (global.varInitKind()) {
       case AsmJSModule::Global::InitConstant: {
-        const Value &v = global.varInitConstant();
-        switch (global.varInitCoercion()) {
-          case AsmJS_ToInt32:
+        const AsmJSNumLit &lit = global.varInitNumLit();
+        const Value &v = lit.value();
+        switch (lit.which()) {
+          case AsmJSNumLit::Fixnum:
+          case AsmJSNumLit::NegativeInt:
+          case AsmJSNumLit::BigUnsigned:
             *(int32_t *)datum = v.toInt32();
             break;
-          case AsmJS_ToNumber:
+          case AsmJSNumLit::Double:
             *(double *)datum = v.toDouble();
             break;
-          case AsmJS_FRound:
+          case AsmJSNumLit::Float:
             *(float *)datum = static_cast<float>(v.toDouble());
             break;
+          case AsmJSNumLit::OutOfRangeInt:
+            MOZ_MAKE_COMPILER_ASSUME_IS_UNREACHABLE("OutOfRangeInt isn't valid in the first place");
         }
         break;
       }
       case AsmJSModule::Global::InitImport: {
         RootedPropertyName field(cx, global.varImportField());
         RootedValue v(cx);
         if (!GetDataProperty(cx, importVal, field, &v))
             return false;
--- a/js/src/asmjs/AsmJSModule.h
+++ b/js/src/asmjs/AsmJSModule.h
@@ -163,20 +163,20 @@ class AsmJSModule
 
       private:
         struct Pod {
             Which which_;
             union {
                 struct {
                     uint32_t index_;
                     VarInitKind initKind_;
-                    AsmJSCoercion coercion_;
                     union {
-                        Value constant_; // will only contain int32/double
-                    } init;
+                        AsmJSCoercion coercion_;
+                        AsmJSNumLit numLit_;
+                    } u;
                 } var;
                 uint32_t ffiIndex_;
                 Scalar::Type viewType_;
                 AsmJSMathBuiltinFunction mathBuiltinFunc_;
                 struct {
                     ConstantKind kind_;
                     double value_;
                 } constant;
@@ -191,40 +191,41 @@ class AsmJSModule
             name_ = name;
             JS_ASSERT_IF(name_, name_->isTenured());
         }
 
         void trace(JSTracer *trc) {
             if (name_)
                 MarkStringUnbarriered(trc, &name_, "asm.js global name");
             JS_ASSERT_IF(pod.which_ == Variable && pod.u.var.initKind_ == InitConstant,
-                         !pod.u.var.init.constant_.isMarkable());
+                         !pod.u.var.u.numLit_.value().isMarkable());
         }
 
       public:
         Global() {}
         Which which() const {
             return pod.which_;
         }
         uint32_t varIndex() const {
             JS_ASSERT(pod.which_ == Variable);
             return pod.u.var.index_;
         }
         VarInitKind varInitKind() const {
             JS_ASSERT(pod.which_ == Variable);
             return pod.u.var.initKind_;
         }
-        const Value &varInitConstant() const {
+        const AsmJSNumLit &varInitNumLit() const {
             JS_ASSERT(pod.which_ == Variable);
             JS_ASSERT(pod.u.var.initKind_ == InitConstant);
-            return pod.u.var.init.constant_;
+            return pod.u.var.u.numLit_;
         }
         AsmJSCoercion varInitCoercion() const {
             JS_ASSERT(pod.which_ == Variable);
-            return pod.u.var.coercion_;
+            JS_ASSERT(pod.u.var.initKind_ == InitImport);
+            return pod.u.var.u.coercion_;
         }
         PropertyName *varImportField() const {
             JS_ASSERT(pod.which_ == Variable);
             JS_ASSERT(pod.u.var.initKind_ == InitImport);
             return name_;
         }
         PropertyName *ffiField() const {
             JS_ASSERT(pod.which_ == FFI);
@@ -811,32 +812,31 @@ class AsmJSModule
         return globalArgumentName_;
     }
     PropertyName *importArgumentName() const {
         return importArgumentName_;
     }
     PropertyName *bufferArgumentName() const {
         return bufferArgumentName_;
     }
-    bool addGlobalVarInit(const Value &v, AsmJSCoercion coercion, uint32_t *globalIndex) {
+    bool addGlobalVarInit(const AsmJSNumLit &lit, uint32_t *globalIndex) {
         JS_ASSERT(!isFinishedWithModulePrologue());
         if (pod.numGlobalVars_ == UINT32_MAX)
             return false;
         Global g(Global::Variable, nullptr);
         g.pod.u.var.initKind_ = Global::InitConstant;
-        g.pod.u.var.init.constant_ = v;
-        g.pod.u.var.coercion_ = coercion;
+        g.pod.u.var.u.numLit_ = lit;
         g.pod.u.var.index_ = *globalIndex = pod.numGlobalVars_++;
         return globals_.append(g);
     }
     bool addGlobalVarImport(PropertyName *name, AsmJSCoercion coercion, uint32_t *globalIndex) {
         JS_ASSERT(!isFinishedWithModulePrologue());
         Global g(Global::Variable, name);
         g.pod.u.var.initKind_ = Global::InitImport;
-        g.pod.u.var.coercion_ = coercion;
+        g.pod.u.var.u.coercion_ = coercion;
         g.pod.u.var.index_ = *globalIndex = pod.numGlobalVars_++;
         return globals_.append(g);
     }
     bool addFFI(PropertyName *field, uint32_t *ffiIndex) {
         JS_ASSERT(!isFinishedWithModulePrologue());
         if (pod.numFFIs_ == UINT32_MAX)
             return false;
         Global g(Global::FFI, field);
--- a/js/src/asmjs/AsmJSValidate.cpp
+++ b/js/src/asmjs/AsmJSValidate.cpp
@@ -1345,17 +1345,17 @@ class MOZ_STACK_CLASS ModuleCompiler
 
     void initGlobalArgumentName(PropertyName *n) { module_->initGlobalArgumentName(n); }
     void initImportArgumentName(PropertyName *n) { module_->initImportArgumentName(n); }
     void initBufferArgumentName(PropertyName *n) { module_->initBufferArgumentName(n); }
 
     bool addGlobalVarInit(PropertyName *varName, const AsmJSNumLit &lit, bool isConst) {
         uint32_t index;
         VarType type = VarType::Of(lit);
-        if (!module_->addGlobalVarInit(lit.value(), type.toCoercion(), &index))
+        if (!module_->addGlobalVarInit(lit, &index))
             return false;
 
         Global::Which which = isConst ? Global::ConstantLiteral : Global::Variable;
         Global *global = moduleLifo_.new_<Global>(which);
         if (!global)
             return false;
         global->u.varOrConst.index_ = index;
         global->u.varOrConst.type_ = type.which();