Bug 1273462 - Part 1: Simplify and refactor AssemblerBuffer a bit to make it easier to replace mozilla::Vector. r=jandem

This commit is contained in:
Emanuel Hoogeveen 2016-05-27 13:58:00 +02:00
parent 145a8d24cf
commit f09abdde26
2 changed files with 35 additions and 59 deletions

View File

@ -67,7 +67,21 @@ namespace js {
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)
@ -80,65 +94,28 @@ namespace jit {
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));
}
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 putByte(int value)
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); }
MOZ_MUST_USE bool append(const unsigned char* values, size_t size)
{
if (MOZ_UNLIKELY(!m_buffer.append(char(value))))
if (MOZ_UNLIKELY(!m_buffer.append(values, size))) {
oomDetected();
}
void putShortUnchecked(int value)
{
m_buffer.infallibleGrowByUninitialized(2);
memcpy(m_buffer.end() - 2, &value, 2);
}
void putShort(int value)
{
if (MOZ_UNLIKELY(!m_buffer.growByUninitialized(2))) {
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()

View File

@ -3497,14 +3497,9 @@ threeByteOpImmSimd("vblendps", VEX_PD, OP3_BLENDPS_VpsWpsIb, ESCAPE_3A, imm, off
{
memcpy(buffer, m_formatter.buffer(), size());
}
bool appendBuffer(const BaseAssembler& other)
MOZ_MUST_USE 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;
return m_formatter.append(other.m_formatter.buffer(), other.size());
}
protected:
@ -4752,12 +4747,16 @@ threeByteOpImmSimd("vblendps", VEX_PD, OP3_BLENDPS_VpsWpsIb, ESCAPE_3A, imm, off
// 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.