Added doubleToUint32 builtin and make tracker a template.
authorAndreas Gal <gal@mozilla.com>
Sun, 06 Jul 2008 10:59:55 -0700
changeset 17462 a53c3daea0e8bce5abd06e13a810b60177cf5ba5
parent 17460 ba845ab9dff1c7f57f002bd5de9a3a247b43b15e
child 17463 fcd3450f9272bba03d987ed0fe90040c2253a801
push id1452
push usershaver@mozilla.com
push dateFri, 22 Aug 2008 00:08:22 +0000
treeherderautoland@d13bb0868596 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
milestone1.9.1a1pre
Added doubleToUint32 builtin and make tracker a template.
js/src/builtins.tbl
js/src/jsbuiltins.cpp
js/src/jstracer.cpp
js/src/jstracer.h
--- a/js/src/builtins.tbl
+++ b/js/src/builtins.tbl
@@ -36,8 +36,9 @@
  *
  * ***** END LICENSE BLOCK ***** */
 
 BUILTIN2(BoxDouble,             LO, F,  LO,     jsval,     JSContext*, jsdouble,               1, 1)
 BUILTIN2(BoxInt32,              LO, LO, LO,     jsval,     JSContext*, jsint,                  1, 1)
 BUILTIN1(UnboxInt32,            LO,     LO,     int32,     jsval,                              1, 1)
 BUILTIN2(dmod,                  F,  F,  F,      jsdouble,  jsdouble, jsdouble,                 1, 1)
 BUILTIN1(doubleToInt32,         F,      LO,     int32,     jsdouble,                           1, 1)
+BUILTIN1(doubleToUint32,        F,      LO,     int32,     jsdouble,                           1, 1)
\ No newline at end of file
--- a/js/src/jsbuiltins.cpp
+++ b/js/src/jsbuiltins.cpp
@@ -96,8 +96,13 @@ FASTCALL jsint builtin_UnboxInt32(JSCont
         return i;
     return INT32_ERROR_COOKIE;
 }
 
 FASTCALL int32 builtin_doubleToInt32(jsdouble d)
 {
     return js_DoubleToECMAInt32(d);
 }
+
+FASTCALL int32 builtin_doubleToUint32(jsdouble d)
+{
+    return js_DoubleToECMAUint32(d);
+}
--- a/js/src/jstracer.cpp
+++ b/js/src/jstracer.cpp
@@ -51,81 +51,83 @@
 #include "jsscope.h"
 
 using namespace avmplus;
 using namespace nanojit;
 
 static GC gc = GC();
 static avmplus::AvmCore* core = new (&gc) avmplus::AvmCore();
 
-Tracker::Tracker()
+template<class T>
+Tracker<T>::Tracker()
 {
     pagelist = 0;
 }
 
-Tracker::~Tracker()
+template<class T>
+Tracker<T>::~Tracker()
 {
     clear();
 }
 
-jsuword
-Tracker::getPageBase(const void* v) const
+template<class T> jsuword
+Tracker<T>::getPageBase(const void* v) const
 {
     return jsuword(v) & ~jsuword(NJ_PAGE_SIZE-1);
 }
 
-struct Tracker::Page*
-Tracker::findPage(const void* v) const
+template<class T> struct Tracker<T>::Page*
+Tracker<T>::findPage(const void* v) const
 {
     jsuword base = getPageBase(v);
-    struct Tracker::Page* p = pagelist;
+    struct Tracker<T>::Page* p = pagelist;
     while (p) {
         if (p->base == base) {
             return p;
         }
         p = p->next;
     }
     return 0;
 }
 
-struct Tracker::Page*
-Tracker::addPage(const void* v) {
+template <class T> struct Tracker<T>::Page*
+Tracker<T>::addPage(const void* v) {
     jsuword base = getPageBase(v);
     struct Tracker::Page* p = (struct Tracker::Page*)
         GC::Alloc(sizeof(struct Tracker::Page) + (NJ_PAGE_SIZE >> 2) * sizeof(LInsp));
     p->base = base;
     p->next = pagelist;
     pagelist = p;
     return p;
 }
 
-void
-Tracker::clear()
+template <class T> void
+Tracker<T>::clear()
 {
     while (pagelist) {
         Page* p = pagelist;
         pagelist = pagelist->next;
         GC::Free(p);
     }
 }
 
-LIns*
-Tracker::get(const void* v) const
+template <class T> T
+Tracker<T>::get(const void* v) const
 {
-    struct Tracker::Page* p = findPage(v);
+    struct Tracker<T>::Page* p = findPage(v);
     JS_ASSERT(p != 0); /* we must have a page for the slot we are looking for */
-    LIns* i = p->map[(jsuword(v) & 0xfff) >> 2];
+    T i = p->map[(jsuword(v) & 0xfff) >> 2];
     JS_ASSERT(i != 0);
     return i;
 }
 
-void
-Tracker::set(const void* v, LIns* ins)
+template <class T> void
+Tracker<T>::set(const void* v, T ins)
 {
-    struct Tracker::Page* p = findPage(v);
+    struct Tracker<T>::Page* p = findPage(v);
     if (!p)
         p = addPage(v);
     p->map[(jsuword(v) & 0xfff) >> 2] = ins;
 }
 
 #define LO ARGSIZE_LO
 #define F  ARGSIZE_F
 #define Q  ARGSIZE_Q
--- a/js/src/jstracer.h
+++ b/js/src/jstracer.h
@@ -61,50 +61,51 @@
  * not a runtime error.
  */
 #define INT32_ERROR_COOKIE 0xffffabcd
 
 /*
  * Tracker is used to keep track of values being manipulated by the 
  * interpreter during trace recording.
  */
+template <class T>
 class Tracker 
 {
     struct Page {
         struct Page*    next;
         jsuword         base;
-        nanojit::LIns*  map[0];
+        T               map[0];
     };
     struct Page* pagelist;
     
     jsuword         getPageBase(const void* v) const;
     struct Page*    findPage(const void* v) const;
     struct Page*    addPage(const void* v);
 public:    
     Tracker();
     ~Tracker();
     
-    nanojit::LIns*  get(const void* v) const;
-    void            set(const void* v, nanojit::LIns* ins);
+    T               get(const void* v) const;
+    void            set(const void* v, T ins);
     void            clear();
 };
 
 struct VMFragmentInfo {
     unsigned                maxNativeFrameSlots;
     size_t                  nativeStackBase;
     char                    typeMap[0];
 };
 
 struct VMSideExitInfo {
     char                    typeMap[0];
 };
 
 class TraceRecorder {
     JSContext*              cx;
-    Tracker                 tracker;
+    Tracker<nanojit::LIns*> tracker;
     char*                   entryTypeMap;
     unsigned                entryNativeFrameSlots;
     unsigned                maxNativeFrameSlots;
     struct JSStackFrame*    entryFrame;
     struct JSFrameRegs      entryRegs;
     nanojit::Fragment*      fragment;
     VMFragmentInfo*         fragmentInfo;
     nanojit::LirBuffer*     lirbuf;
@@ -430,16 +431,17 @@ public:
     bool JSOP_HOLE();
 };
 
 FASTCALL jsdouble builtin_dmod(jsdouble a, jsdouble b);
 FASTCALL jsval builtin_BoxDouble(JSContext* cx, jsdouble d);
 FASTCALL jsval builtin_BoxInt32(JSContext* cx, jsint i);
 FASTCALL jsint builtin_UnboxInt32(JSContext* cx, jsval v);
 FASTCALL int32 builtin_doubleToInt32(jsdouble d);
+FASTCALL int32 builtin_doubleToUint32(jsdouble d);
 
 /*
  * Trace monitor. Every runtime is associated with a trace monitor that keeps
  * track of loop frequencies for all JavaScript code loaded into that runtime.
  * For this we use a loop table. Adjacent slots in the loop table, one for each
  * loop header in a given script, are requested using lock-free synchronization
  * from the runtime-wide loop table slot space, when the script is compiled.
  *