Bug 1273462 - Part 1: Simplify and refactor AssemblerBuffer a bit to make it easier to replace mozilla::Vector. r=jandem
authorEmanuel Hoogeveen <emanuel.hoogeveen@gmail.com>
Fri, 27 May 2016 13:58:00 +0200
changeset 338559 dbd9ceba3964f756765cbd96d3beea7b3de0a933
parent 338558 f5804d79ba15e4e16aaa004cd37331a4b2233a9f
child 338560 9a76ad279eaa7387317d2dbdfde222f7cabcc7b1
push id6249
push userjlund@mozilla.com
push dateMon, 01 Aug 2016 13:59:36 +0000
treeherdermozilla-beta@bad9d4f5bf7e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjandem
bugs1273462
milestone49.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 1273462 - Part 1: Simplify and refactor AssemblerBuffer a bit to make it easier to replace mozilla::Vector. r=jandem
js/src/jit/x86-shared/AssemblerBuffer-x86-shared.h
js/src/jit/x86-shared/BaseAssembler-x86-shared.h
--- a/js/src/jit/x86-shared/AssemblerBuffer-x86-shared.h
+++ b/js/src/jit/x86-shared/AssemblerBuffer-x86-shared.h
@@ -62,88 +62,65 @@
 #define ADDR_o32r(offset)                      (offset)
 
 namespace js {
 
     class Sprinter;
 
 namespace jit {
 
-    class AssemblerBuffer {
+    class AssemblerBuffer
+    {
+        template<size_t size, typename T>
+        MOZ_ALWAYS_INLINE void sizedAppendUnchecked(T value)
+        {
+            m_buffer.infallibleAppend(reinterpret_cast<unsigned char*>(&value), size);
+        }
+
+        template<size_t size, typename T>
+        MOZ_ALWAYS_INLINE void sizedAppend(T value)
+        {
+            if (MOZ_UNLIKELY(!m_buffer.append(reinterpret_cast<unsigned char*>(&value), size)))
+                oomDetected();
+        }
+
     public:
         AssemblerBuffer()
             : m_oom(false)
         {
         }
 
         void ensureSpace(size_t space)
         {
             if (MOZ_UNLIKELY(!m_buffer.reserve(m_buffer.length() + space)))
                 oomDetected();
         }
 
-        bool growByUninitialized(size_t space)
-        {
-            if (MOZ_UNLIKELY(!m_buffer.growByUninitialized(space))) {
-                oomDetected();
-                return false;
-            }
-            return true;
-        }
-
         bool isAligned(size_t alignment) const
         {
             return !(m_buffer.length() & (alignment - 1));
         }
 
-        void putByteUnchecked(int value)
-        {
-            m_buffer.infallibleAppend(char(value));
-        }
-
-        void putByte(int value)
-        {
-            if (MOZ_UNLIKELY(!m_buffer.append(char(value))))
-                oomDetected();
-        }
+        MOZ_ALWAYS_INLINE void putByteUnchecked(int value) { sizedAppendUnchecked<1>(value); }
+        MOZ_ALWAYS_INLINE void putShortUnchecked(int value) { sizedAppendUnchecked<2>(value); }
+        MOZ_ALWAYS_INLINE void putIntUnchecked(int value) { sizedAppendUnchecked<4>(value); }
+        MOZ_ALWAYS_INLINE void putInt64Unchecked(int64_t value) { sizedAppendUnchecked<8>(value); }
 
-        void putShortUnchecked(int value)
-        {
-            m_buffer.infallibleGrowByUninitialized(2);
-            memcpy(m_buffer.end() - 2, &value, 2);
-        }
+        MOZ_ALWAYS_INLINE void putByte(int value) { sizedAppend<1>(value); }
+        MOZ_ALWAYS_INLINE void putShort(int value) { sizedAppend<2>(value); }
+        MOZ_ALWAYS_INLINE void putInt(int value) { sizedAppend<4>(value); }
+        MOZ_ALWAYS_INLINE void putInt64(int64_t value) { sizedAppend<8>(value); }
 
-        void putShort(int value)
+        MOZ_MUST_USE bool append(const unsigned char* values, size_t size)
         {
-            if (MOZ_UNLIKELY(!m_buffer.growByUninitialized(2))) {
+            if (MOZ_UNLIKELY(!m_buffer.append(values, size))) {
                 oomDetected();
-                return;
+                return false;
             }
-            memcpy(m_buffer.end() - 2, &value, 2);
-        }
-
-        void putIntUnchecked(int value)
-        {
-            m_buffer.infallibleGrowByUninitialized(4);
-            memcpy(m_buffer.end() - 4, &value, 4);
-        }
-
-        void putInt64Unchecked(int64_t value)
-        {
-            m_buffer.infallibleGrowByUninitialized(8);
-            memcpy(m_buffer.end() - 8, &value, 8);
-        }
-
-        void putInt(int value)
-        {
-            if (MOZ_UNLIKELY(!m_buffer.growByUninitialized(4))) {
-                oomDetected();
-                return;
-            }
-            memcpy(m_buffer.end() - 4, &value, 4);
+            return true;
         }
 
         unsigned char* data()
         {
             return m_buffer.begin();
         }
 
         size_t size() const
--- a/js/src/jit/x86-shared/BaseAssembler-x86-shared.h
+++ b/js/src/jit/x86-shared/BaseAssembler-x86-shared.h
@@ -3492,24 +3492,19 @@ threeByteOpImmSimd("vblendps", VEX_PD, O
         unsigned char* code = m_formatter.data();
         SetRel32(code + from.offset(), code + to.offset());
     }
 
     void executableCopy(void* buffer)
     {
         memcpy(buffer, m_formatter.buffer(), size());
     }
-    bool appendBuffer(const BaseAssembler& other)
-    {
-        size_t otherSize = other.size();
-        size_t formerSize = size();
-        if (!m_formatter.growByUninitialized(otherSize))
-            return false;
-        memcpy((char*)m_formatter.buffer() + formerSize, other.m_formatter.buffer(), otherSize);
-        return true;
+    MOZ_MUST_USE bool appendBuffer(const BaseAssembler& other)
+    {
+        return m_formatter.append(other.m_formatter.buffer(), other.size());
     }
 
   protected:
     static bool CAN_SIGN_EXTEND_8_32(int32_t value) { return value == (int32_t)(int8_t)value; }
     static bool CAN_SIGN_EXTEND_16_32(int32_t value) { return value == (int32_t)(int16_t)value; }
     static bool CAN_ZERO_EXTEND_8_32(int32_t value) { return value == (int32_t)(uint8_t)value; }
     static bool CAN_ZERO_EXTEND_8H_32(int32_t value) { return value == (value & 0xff00); }
     static bool CAN_ZERO_EXTEND_16_32(int32_t value) { return value == (int32_t)(uint16_t)value; }
@@ -4747,22 +4742,26 @@ threeByteOpImmSimd("vblendps", VEX_PD, O
         {
             m_buffer.ensureSpace(sizeof(int32_t));
             m_buffer.putIntUnchecked(i);
         }
 
         // Administrative methods:
 
         size_t size() const { return m_buffer.size(); }
-        bool growByUninitialized(size_t size) { return m_buffer.growByUninitialized(size); }
         const unsigned char* buffer() const { return m_buffer.buffer(); }
         bool oom() const { return m_buffer.oom(); }
         bool isAligned(int alignment) const { return m_buffer.isAligned(alignment); }
         unsigned char* data() { return m_buffer.data(); }
 
+        MOZ_MUST_USE bool append(const unsigned char* values, size_t size)
+        {
+            return m_buffer.append(values, size);
+        }
+
     private:
 
         // Internals; ModRm and REX formatters.
 
         // Byte operand register spl & above requir a REX prefix, which precludes
         // use of the h registers in the same instruction.
         static bool byteRegRequiresRex(RegisterID reg)
         {