ggaren@apple.com | 58f417e | 2008-11-17 06:27:06 +0000 | [diff] [blame] | 1 | /* |
mark.lam@apple.com | d27553f | 2019-09-18 00:36:19 +0000 | [diff] [blame] | 2 | * Copyright (C) 2008-2019 Apple Inc. All rights reserved. |
ggaren@apple.com | 58f417e | 2008-11-17 06:27:06 +0000 | [diff] [blame] | 3 | * |
| 4 | * Redistribution and use in source and binary forms, with or without |
| 5 | * modification, are permitted provided that the following conditions |
| 6 | * are met: |
| 7 | * 1. Redistributions of source code must retain the above copyright |
| 8 | * notice, this list of conditions and the following disclaimer. |
| 9 | * 2. Redistributions in binary form must reproduce the above copyright |
| 10 | * notice, this list of conditions and the following disclaimer in the |
| 11 | * documentation and/or other materials provided with the distribution. |
| 12 | * |
| 13 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY |
| 14 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 15 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR |
| 17 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 18 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 19 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 20 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
| 21 | * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 24 | */ |
| 25 | |
ryanhaddad@apple.com | 22104f5 | 2016-09-28 17:08:17 +0000 | [diff] [blame] | 26 | #pragma once |
ggaren@apple.com | 58f417e | 2008-11-17 06:27:06 +0000 | [diff] [blame] | 27 | |
ggaren@apple.com | 58f417e | 2008-11-17 06:27:06 +0000 | [diff] [blame] | 28 | #if ENABLE(ASSEMBLER) |
| 29 | |
fpizlo@apple.com | b75911b | 2012-06-13 20:53:52 +0000 | [diff] [blame] | 30 | #include "ExecutableAllocator.h" |
fpizlo@apple.com | 0f25ee8 | 2012-03-01 05:46:20 +0000 | [diff] [blame] | 31 | #include "JITCompilationEffort.h" |
barraclough@apple.com | 780b75b | 2008-12-17 01:27:13 +0000 | [diff] [blame] | 32 | #include "stdint.h" |
ggaren@apple.com | 3e9d413 | 2008-11-18 03:25:03 +0000 | [diff] [blame] | 33 | #include <string.h> |
ggaren@apple.com | 58f417e | 2008-11-17 06:27:06 +0000 | [diff] [blame] | 34 | #include <wtf/Assertions.h> |
| 35 | #include <wtf/FastMalloc.h> |
sbarati@apple.com | 80c907f | 2018-09-28 05:34:38 +0000 | [diff] [blame] | 36 | #if CPU(ARM64E) |
| 37 | #include <wtf/PtrTag.h> |
| 38 | #endif |
loki@webkit.org | 7534a3f | 2010-08-13 10:14:36 +0000 | [diff] [blame] | 39 | #include <wtf/StdLibExtras.h> |
yusukesuzuki@slowstart.org | 6836640 | 2018-08-19 22:50:05 +0000 | [diff] [blame] | 40 | #include <wtf/UnalignedAccess.h> |
ggaren@apple.com | 58f417e | 2008-11-17 06:27:06 +0000 | [diff] [blame] | 41 | |
| 42 | namespace JSC { |
| 43 | |
sbarati@apple.com | 80c907f | 2018-09-28 05:34:38 +0000 | [diff] [blame] | 44 | class LinkBuffer; |
| 45 | |
barraclough@apple.com | 4836c7a | 2011-05-01 22:20:59 +0000 | [diff] [blame] | 46 | struct AssemblerLabel { |
barraclough@apple.com | c5390ae | 2011-05-02 18:30:03 +0000 | [diff] [blame] | 47 | AssemblerLabel() |
| 48 | : m_offset(std::numeric_limits<uint32_t>::max()) |
| 49 | { |
| 50 | } |
| 51 | |
| 52 | explicit AssemblerLabel(uint32_t offset) |
barraclough@apple.com | 4836c7a | 2011-05-01 22:20:59 +0000 | [diff] [blame] | 53 | : m_offset(offset) |
| 54 | { |
| 55 | } |
| 56 | |
| 57 | bool isSet() const { return (m_offset != std::numeric_limits<uint32_t>::max()); } |
| 58 | |
barraclough@apple.com | c5390ae | 2011-05-02 18:30:03 +0000 | [diff] [blame] | 59 | AssemblerLabel labelAtOffset(int offset) const |
| 60 | { |
| 61 | return AssemblerLabel(m_offset + offset); |
| 62 | } |
| 63 | |
sbarati@apple.com | d3d0c00 | 2016-01-30 01:11:05 +0000 | [diff] [blame] | 64 | bool operator==(const AssemblerLabel& other) const { return m_offset == other.m_offset; } |
| 65 | |
barraclough@apple.com | 4836c7a | 2011-05-01 22:20:59 +0000 | [diff] [blame] | 66 | uint32_t m_offset; |
| 67 | }; |
| 68 | |
benjamin@webkit.org | f6de077 | 2014-07-15 23:59:14 +0000 | [diff] [blame] | 69 | class AssemblerData { |
sbarati@apple.com | b5bee81 | 2016-06-19 19:42:18 +0000 | [diff] [blame] | 70 | WTF_MAKE_NONCOPYABLE(AssemblerData); |
mark.lam@apple.com | d27553f | 2019-09-18 00:36:19 +0000 | [diff] [blame] | 71 | static constexpr size_t InlineCapacity = 128; |
ggaren@apple.com | 58f417e | 2008-11-17 06:27:06 +0000 | [diff] [blame] | 72 | public: |
benjamin@webkit.org | f6de077 | 2014-07-15 23:59:14 +0000 | [diff] [blame] | 73 | AssemblerData() |
sbarati@apple.com | b5bee81 | 2016-06-19 19:42:18 +0000 | [diff] [blame] | 74 | : m_buffer(m_inlineBuffer) |
| 75 | , m_capacity(InlineCapacity) |
ggaren@apple.com | 58f417e | 2008-11-17 06:27:06 +0000 | [diff] [blame] | 76 | { |
| 77 | } |
| 78 | |
sbarati@apple.com | b5bee81 | 2016-06-19 19:42:18 +0000 | [diff] [blame] | 79 | AssemblerData(size_t initialCapacity) |
benjamin@webkit.org | f6de077 | 2014-07-15 23:59:14 +0000 | [diff] [blame] | 80 | { |
sbarati@apple.com | b5bee81 | 2016-06-19 19:42:18 +0000 | [diff] [blame] | 81 | if (initialCapacity <= InlineCapacity) { |
| 82 | m_capacity = InlineCapacity; |
| 83 | m_buffer = m_inlineBuffer; |
| 84 | } else { |
| 85 | m_capacity = initialCapacity; |
| 86 | m_buffer = static_cast<char*>(fastMalloc(m_capacity)); |
| 87 | } |
benjamin@webkit.org | f6de077 | 2014-07-15 23:59:14 +0000 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | AssemblerData(AssemblerData&& other) |
| 91 | { |
sbarati@apple.com | b5bee81 | 2016-06-19 19:42:18 +0000 | [diff] [blame] | 92 | if (other.isInlineBuffer()) { |
| 93 | ASSERT(other.m_capacity == InlineCapacity); |
| 94 | memcpy(m_inlineBuffer, other.m_inlineBuffer, InlineCapacity); |
| 95 | m_buffer = m_inlineBuffer; |
| 96 | } else |
| 97 | m_buffer = other.m_buffer; |
benjamin@webkit.org | f6de077 | 2014-07-15 23:59:14 +0000 | [diff] [blame] | 98 | m_capacity = other.m_capacity; |
sbarati@apple.com | b5bee81 | 2016-06-19 19:42:18 +0000 | [diff] [blame] | 99 | |
| 100 | other.m_buffer = nullptr; |
benjamin@webkit.org | f6de077 | 2014-07-15 23:59:14 +0000 | [diff] [blame] | 101 | other.m_capacity = 0; |
| 102 | } |
| 103 | |
| 104 | AssemblerData& operator=(AssemblerData&& other) |
| 105 | { |
sbarati@apple.com | b5bee81 | 2016-06-19 19:42:18 +0000 | [diff] [blame] | 106 | if (m_buffer && !isInlineBuffer()) |
| 107 | fastFree(m_buffer); |
| 108 | |
| 109 | if (other.isInlineBuffer()) { |
| 110 | ASSERT(other.m_capacity == InlineCapacity); |
| 111 | memcpy(m_inlineBuffer, other.m_inlineBuffer, InlineCapacity); |
| 112 | m_buffer = m_inlineBuffer; |
| 113 | } else |
| 114 | m_buffer = other.m_buffer; |
benjamin@webkit.org | f6de077 | 2014-07-15 23:59:14 +0000 | [diff] [blame] | 115 | m_capacity = other.m_capacity; |
sbarati@apple.com | b5bee81 | 2016-06-19 19:42:18 +0000 | [diff] [blame] | 116 | |
| 117 | other.m_buffer = nullptr; |
benjamin@webkit.org | f6de077 | 2014-07-15 23:59:14 +0000 | [diff] [blame] | 118 | other.m_capacity = 0; |
| 119 | return *this; |
| 120 | } |
| 121 | |
| 122 | ~AssemblerData() |
| 123 | { |
sbarati@apple.com | b5bee81 | 2016-06-19 19:42:18 +0000 | [diff] [blame] | 124 | if (m_buffer && !isInlineBuffer()) |
| 125 | fastFree(m_buffer); |
benjamin@webkit.org | f6de077 | 2014-07-15 23:59:14 +0000 | [diff] [blame] | 126 | } |
| 127 | |
| 128 | char* buffer() const { return m_buffer; } |
| 129 | |
| 130 | unsigned capacity() const { return m_capacity; } |
| 131 | |
| 132 | void grow(unsigned extraCapacity = 0) |
| 133 | { |
benjamin@webkit.org | 26dd417 | 2015-05-18 06:26:10 +0000 | [diff] [blame] | 134 | m_capacity = m_capacity + m_capacity / 2 + extraCapacity; |
sbarati@apple.com | b5bee81 | 2016-06-19 19:42:18 +0000 | [diff] [blame] | 135 | if (isInlineBuffer()) { |
| 136 | m_buffer = static_cast<char*>(fastMalloc(m_capacity)); |
| 137 | memcpy(m_buffer, m_inlineBuffer, InlineCapacity); |
| 138 | } else |
| 139 | m_buffer = static_cast<char*>(fastRealloc(m_buffer, m_capacity)); |
benjamin@webkit.org | f6de077 | 2014-07-15 23:59:14 +0000 | [diff] [blame] | 140 | } |
| 141 | |
| 142 | private: |
sbarati@apple.com | b5bee81 | 2016-06-19 19:42:18 +0000 | [diff] [blame] | 143 | bool isInlineBuffer() const { return m_buffer == m_inlineBuffer; } |
benjamin@webkit.org | f6de077 | 2014-07-15 23:59:14 +0000 | [diff] [blame] | 144 | char* m_buffer; |
sbarati@apple.com | b5bee81 | 2016-06-19 19:42:18 +0000 | [diff] [blame] | 145 | char m_inlineBuffer[InlineCapacity]; |
benjamin@webkit.org | f6de077 | 2014-07-15 23:59:14 +0000 | [diff] [blame] | 146 | unsigned m_capacity; |
| 147 | }; |
| 148 | |
sbarati@apple.com | 80c907f | 2018-09-28 05:34:38 +0000 | [diff] [blame] | 149 | #if CPU(ARM64E) |
| 150 | class ARM64EHash { |
| 151 | public: |
sbarati@apple.com | fc044cd | 2018-12-19 02:27:00 +0000 | [diff] [blame] | 152 | ARM64EHash() = default; |
| 153 | ALWAYS_INLINE void update(uint32_t value) |
sbarati@apple.com | 80c907f | 2018-09-28 05:34:38 +0000 | [diff] [blame] | 154 | { |
sbarati@apple.com | fc044cd | 2018-12-19 02:27:00 +0000 | [diff] [blame] | 155 | uint64_t input = value ^ m_hash; |
| 156 | uint64_t a = static_cast<uint32_t>(tagInt(input, static_cast<PtrTag>(0)) >> 39); |
| 157 | uint64_t b = tagInt(input, static_cast<PtrTag>(0xb7e151628aed2a6a)) >> 23; |
sbarati@apple.com | 0f1b423 | 2019-01-24 22:07:33 +0000 | [diff] [blame] | 158 | m_hash = a ^ b; |
sbarati@apple.com | 80c907f | 2018-09-28 05:34:38 +0000 | [diff] [blame] | 159 | } |
sbarati@apple.com | fc044cd | 2018-12-19 02:27:00 +0000 | [diff] [blame] | 160 | uint32_t finalHash() const |
| 161 | { |
| 162 | uint64_t hash = m_hash; |
| 163 | uint64_t a = static_cast<uint32_t>(tagInt(hash, static_cast<PtrTag>(0xbf7158809cf4f3c7)) >> 39); |
| 164 | uint64_t b = tagInt(hash, static_cast<PtrTag>(0x62e7160f38b4da56)) >> 23; |
sbarati@apple.com | 0f1b423 | 2019-01-24 22:07:33 +0000 | [diff] [blame] | 165 | return static_cast<uint32_t>(a ^ b); |
sbarati@apple.com | fc044cd | 2018-12-19 02:27:00 +0000 | [diff] [blame] | 166 | } |
sbarati@apple.com | 80c907f | 2018-09-28 05:34:38 +0000 | [diff] [blame] | 167 | private: |
sbarati@apple.com | fc044cd | 2018-12-19 02:27:00 +0000 | [diff] [blame] | 168 | uint32_t m_hash { 0 }; |
sbarati@apple.com | 80c907f | 2018-09-28 05:34:38 +0000 | [diff] [blame] | 169 | }; |
| 170 | #endif |
| 171 | |
benjamin@webkit.org | f6de077 | 2014-07-15 23:59:14 +0000 | [diff] [blame] | 172 | class AssemblerBuffer { |
benjamin@webkit.org | f6de077 | 2014-07-15 23:59:14 +0000 | [diff] [blame] | 173 | public: |
sbarati@apple.com | fc044cd | 2018-12-19 02:27:00 +0000 | [diff] [blame] | 174 | AssemblerBuffer() |
sbarati@apple.com | b5bee81 | 2016-06-19 19:42:18 +0000 | [diff] [blame] | 175 | : m_storage() |
benjamin@webkit.org | f6de077 | 2014-07-15 23:59:14 +0000 | [diff] [blame] | 176 | , m_index(0) |
ggaren@apple.com | 58f417e | 2008-11-17 06:27:06 +0000 | [diff] [blame] | 177 | { |
barraclough@apple.com | c5390ae | 2011-05-02 18:30:03 +0000 | [diff] [blame] | 178 | } |
| 179 | |
commit-queue@webkit.org | 932ba2d | 2016-03-26 03:47:23 +0000 | [diff] [blame] | 180 | bool isAvailable(unsigned space) |
barraclough@apple.com | c5390ae | 2011-05-02 18:30:03 +0000 | [diff] [blame] | 181 | { |
benjamin@webkit.org | f6de077 | 2014-07-15 23:59:14 +0000 | [diff] [blame] | 182 | return m_index + space <= m_storage.capacity(); |
ggaren@apple.com | 58f417e | 2008-11-17 06:27:06 +0000 | [diff] [blame] | 183 | } |
| 184 | |
commit-queue@webkit.org | 932ba2d | 2016-03-26 03:47:23 +0000 | [diff] [blame] | 185 | void ensureSpace(unsigned space) |
ggaren@apple.com | 58f417e | 2008-11-17 06:27:06 +0000 | [diff] [blame] | 186 | { |
sbarati@apple.com | b5bee81 | 2016-06-19 19:42:18 +0000 | [diff] [blame] | 187 | while (!isAvailable(space)) |
commit-queue@webkit.org | 932ba2d | 2016-03-26 03:47:23 +0000 | [diff] [blame] | 188 | outOfLineGrow(); |
ggaren@apple.com | 58f417e | 2008-11-17 06:27:06 +0000 | [diff] [blame] | 189 | } |
| 190 | |
barraclough@apple.com | 167270d | 2008-12-15 23:38:19 +0000 | [diff] [blame] | 191 | bool isAligned(int alignment) const |
ggaren@apple.com | 58f417e | 2008-11-17 06:27:06 +0000 | [diff] [blame] | 192 | { |
barraclough@apple.com | c5390ae | 2011-05-02 18:30:03 +0000 | [diff] [blame] | 193 | return !(m_index & (alignment - 1)); |
ggaren@apple.com | 58f417e | 2008-11-17 06:27:06 +0000 | [diff] [blame] | 194 | } |
| 195 | |
sbarati@apple.com | 80c907f | 2018-09-28 05:34:38 +0000 | [diff] [blame] | 196 | #if !CPU(ARM64) |
barraclough@apple.com | c5390ae | 2011-05-02 18:30:03 +0000 | [diff] [blame] | 197 | void putByteUnchecked(int8_t value) { putIntegralUnchecked(value); } |
| 198 | void putByte(int8_t value) { putIntegral(value); } |
| 199 | void putShortUnchecked(int16_t value) { putIntegralUnchecked(value); } |
| 200 | void putShort(int16_t value) { putIntegral(value); } |
barraclough@apple.com | c5390ae | 2011-05-02 18:30:03 +0000 | [diff] [blame] | 201 | void putInt64Unchecked(int64_t value) { putIntegralUnchecked(value); } |
| 202 | void putInt64(int64_t value) { putIntegral(value); } |
sbarati@apple.com | 80c907f | 2018-09-28 05:34:38 +0000 | [diff] [blame] | 203 | #endif |
| 204 | void putIntUnchecked(int32_t value) { putIntegralUnchecked(value); } |
| 205 | void putInt(int32_t value) { putIntegral(value); } |
ggaren@apple.com | 58f417e | 2008-11-17 06:27:06 +0000 | [diff] [blame] | 206 | |
barraclough@apple.com | e00c8ce | 2011-04-30 23:59:17 +0000 | [diff] [blame] | 207 | size_t codeSize() const |
| 208 | { |
barraclough@apple.com | c5390ae | 2011-05-02 18:30:03 +0000 | [diff] [blame] | 209 | return m_index; |
barraclough@apple.com | e00c8ce | 2011-04-30 23:59:17 +0000 | [diff] [blame] | 210 | } |
| 211 | |
sbarati@apple.com | 80c907f | 2018-09-28 05:34:38 +0000 | [diff] [blame] | 212 | #if !CPU(ARM64) |
sbarati@apple.com | b5bee81 | 2016-06-19 19:42:18 +0000 | [diff] [blame] | 213 | void setCodeSize(size_t index) |
| 214 | { |
| 215 | // Warning: Only use this if you know exactly what you are doing. |
| 216 | // For example, say you want 40 bytes of nops, it's ok to grow |
| 217 | // and then fill 40 bytes of nops using bigger instructions. |
| 218 | m_index = index; |
| 219 | ASSERT(m_index <= m_storage.capacity()); |
| 220 | } |
sbarati@apple.com | 80c907f | 2018-09-28 05:34:38 +0000 | [diff] [blame] | 221 | #endif |
sbarati@apple.com | b5bee81 | 2016-06-19 19:42:18 +0000 | [diff] [blame] | 222 | |
barraclough@apple.com | 0ec8712 | 2011-05-02 01:04:17 +0000 | [diff] [blame] | 223 | AssemblerLabel label() const |
ggaren@apple.com | 58f417e | 2008-11-17 06:27:06 +0000 | [diff] [blame] | 224 | { |
barraclough@apple.com | c5390ae | 2011-05-02 18:30:03 +0000 | [diff] [blame] | 225 | return AssemblerLabel(m_index); |
ggaren@apple.com | 58f417e | 2008-11-17 06:27:06 +0000 | [diff] [blame] | 226 | } |
| 227 | |
barraclough@apple.com | c5390ae | 2011-05-02 18:30:03 +0000 | [diff] [blame] | 228 | unsigned debugOffset() { return m_index; } |
benjamin@webkit.org | f6de077 | 2014-07-15 23:59:14 +0000 | [diff] [blame] | 229 | |
sbarati@apple.com | b5bee81 | 2016-06-19 19:42:18 +0000 | [diff] [blame] | 230 | AssemblerData&& releaseAssemblerData() { return WTFMove(m_storage); } |
barraclough@apple.com | 9cb663d | 2011-04-15 00:25:59 +0000 | [diff] [blame] | 231 | |
commit-queue@webkit.org | 932ba2d | 2016-03-26 03:47:23 +0000 | [diff] [blame] | 232 | // LocalWriter is a trick to keep the storage buffer and the index |
| 233 | // in memory while issuing multiple Stores. |
| 234 | // It is created in a block scope and its attribute can stay live |
| 235 | // between writes. |
| 236 | // |
| 237 | // LocalWriter *CANNOT* be mixed with other types of access to AssemblerBuffer. |
| 238 | // AssemblerBuffer cannot be used until its LocalWriter goes out of scope. |
sbarati@apple.com | 80c907f | 2018-09-28 05:34:38 +0000 | [diff] [blame] | 239 | #if !CPU(ARM64) // If we ever need to use this on arm64e, we would need to make the checksum aware of this. |
commit-queue@webkit.org | 932ba2d | 2016-03-26 03:47:23 +0000 | [diff] [blame] | 240 | class LocalWriter { |
| 241 | public: |
| 242 | LocalWriter(AssemblerBuffer& buffer, unsigned requiredSpace) |
| 243 | : m_buffer(buffer) |
| 244 | { |
| 245 | buffer.ensureSpace(requiredSpace); |
| 246 | m_storageBuffer = buffer.m_storage.buffer(); |
| 247 | m_index = buffer.m_index; |
| 248 | #if !defined(NDEBUG) |
| 249 | m_initialIndex = m_index; |
| 250 | m_requiredSpace = requiredSpace; |
| 251 | #endif |
| 252 | } |
| 253 | |
| 254 | ~LocalWriter() |
| 255 | { |
| 256 | ASSERT(m_index - m_initialIndex <= m_requiredSpace); |
| 257 | ASSERT(m_buffer.m_index == m_initialIndex); |
| 258 | ASSERT(m_storageBuffer == m_buffer.m_storage.buffer()); |
| 259 | m_buffer.m_index = m_index; |
| 260 | } |
| 261 | |
| 262 | void putByteUnchecked(int8_t value) { putIntegralUnchecked(value); } |
| 263 | void putShortUnchecked(int16_t value) { putIntegralUnchecked(value); } |
| 264 | void putIntUnchecked(int32_t value) { putIntegralUnchecked(value); } |
| 265 | void putInt64Unchecked(int64_t value) { putIntegralUnchecked(value); } |
| 266 | private: |
| 267 | template<typename IntegralType> |
| 268 | void putIntegralUnchecked(IntegralType value) |
| 269 | { |
| 270 | ASSERT(m_index + sizeof(IntegralType) <= m_buffer.m_storage.capacity()); |
yusukesuzuki@slowstart.org | 6836640 | 2018-08-19 22:50:05 +0000 | [diff] [blame] | 271 | WTF::unalignedStore<IntegralType>(m_storageBuffer + m_index, value); |
commit-queue@webkit.org | 932ba2d | 2016-03-26 03:47:23 +0000 | [diff] [blame] | 272 | m_index += sizeof(IntegralType); |
| 273 | } |
| 274 | AssemblerBuffer& m_buffer; |
| 275 | char* m_storageBuffer; |
| 276 | unsigned m_index; |
| 277 | #if !defined(NDEBUG) |
| 278 | unsigned m_initialIndex; |
| 279 | unsigned m_requiredSpace; |
| 280 | #endif |
| 281 | }; |
sbarati@apple.com | 80c907f | 2018-09-28 05:34:38 +0000 | [diff] [blame] | 282 | #endif // !CPU(ARM64) |
| 283 | |
| 284 | #if CPU(ARM64E) |
| 285 | ARM64EHash hash() const { return m_hash; } |
| 286 | #endif |
| 287 | |
| 288 | #if !CPU(ARM64) // If we were to define this on arm64e, we'd need a way to update the hash as we write directly into the buffer. |
| 289 | void* data() const { return m_storage.buffer(); } |
| 290 | #endif |
| 291 | |
commit-queue@webkit.org | 932ba2d | 2016-03-26 03:47:23 +0000 | [diff] [blame] | 292 | |
barraclough@apple.com | 3fa07df | 2009-07-17 21:17:45 +0000 | [diff] [blame] | 293 | protected: |
benjamin@webkit.org | f6de077 | 2014-07-15 23:59:14 +0000 | [diff] [blame] | 294 | template<typename IntegralType> |
| 295 | void putIntegral(IntegralType value) |
| 296 | { |
| 297 | unsigned nextIndex = m_index + sizeof(IntegralType); |
| 298 | if (UNLIKELY(nextIndex > m_storage.capacity())) |
commit-queue@webkit.org | 932ba2d | 2016-03-26 03:47:23 +0000 | [diff] [blame] | 299 | outOfLineGrow(); |
yusukesuzuki@slowstart.org | 6836640 | 2018-08-19 22:50:05 +0000 | [diff] [blame] | 300 | putIntegralUnchecked<IntegralType>(value); |
benjamin@webkit.org | f6de077 | 2014-07-15 23:59:14 +0000 | [diff] [blame] | 301 | } |
| 302 | |
| 303 | template<typename IntegralType> |
| 304 | void putIntegralUnchecked(IntegralType value) |
| 305 | { |
sbarati@apple.com | 80c907f | 2018-09-28 05:34:38 +0000 | [diff] [blame] | 306 | #if CPU(ARM64) |
| 307 | static_assert(sizeof(value) == 4, ""); |
| 308 | #if CPU(ARM64E) |
sbarati@apple.com | fc044cd | 2018-12-19 02:27:00 +0000 | [diff] [blame] | 309 | m_hash.update(value); |
sbarati@apple.com | 80c907f | 2018-09-28 05:34:38 +0000 | [diff] [blame] | 310 | #endif |
| 311 | #endif |
benjamin@webkit.org | f6de077 | 2014-07-15 23:59:14 +0000 | [diff] [blame] | 312 | ASSERT(isAvailable(sizeof(IntegralType))); |
yusukesuzuki@slowstart.org | 6836640 | 2018-08-19 22:50:05 +0000 | [diff] [blame] | 313 | WTF::unalignedStore<IntegralType>(m_storage.buffer() + m_index, value); |
benjamin@webkit.org | f6de077 | 2014-07-15 23:59:14 +0000 | [diff] [blame] | 314 | m_index += sizeof(IntegralType); |
| 315 | } |
| 316 | |
sbarati@apple.com | 80c907f | 2018-09-28 05:34:38 +0000 | [diff] [blame] | 317 | private: |
barraclough@apple.com | 3fa07df | 2009-07-17 21:17:45 +0000 | [diff] [blame] | 318 | void grow(int extraCapacity = 0) |
| 319 | { |
benjamin@webkit.org | f6de077 | 2014-07-15 23:59:14 +0000 | [diff] [blame] | 320 | m_storage.grow(extraCapacity); |
ggaren@apple.com | 58f417e | 2008-11-17 06:27:06 +0000 | [diff] [blame] | 321 | } |
| 322 | |
commit-queue@webkit.org | 932ba2d | 2016-03-26 03:47:23 +0000 | [diff] [blame] | 323 | NEVER_INLINE void outOfLineGrow() |
| 324 | { |
| 325 | m_storage.grow(); |
| 326 | } |
| 327 | |
sbarati@apple.com | 80c907f | 2018-09-28 05:34:38 +0000 | [diff] [blame] | 328 | #if !CPU(ARM64) |
commit-queue@webkit.org | 932ba2d | 2016-03-26 03:47:23 +0000 | [diff] [blame] | 329 | friend LocalWriter; |
sbarati@apple.com | 80c907f | 2018-09-28 05:34:38 +0000 | [diff] [blame] | 330 | #endif |
| 331 | friend LinkBuffer; |
commit-queue@webkit.org | 932ba2d | 2016-03-26 03:47:23 +0000 | [diff] [blame] | 332 | |
benjamin@webkit.org | f6de077 | 2014-07-15 23:59:14 +0000 | [diff] [blame] | 333 | AssemblerData m_storage; |
| 334 | unsigned m_index; |
sbarati@apple.com | 80c907f | 2018-09-28 05:34:38 +0000 | [diff] [blame] | 335 | #if CPU(ARM64E) |
| 336 | ARM64EHash m_hash; |
| 337 | #endif |
ggaren@apple.com | 58f417e | 2008-11-17 06:27:06 +0000 | [diff] [blame] | 338 | }; |
| 339 | |
| 340 | } // namespace JSC |
| 341 | |
| 342 | #endif // ENABLE(ASSEMBLER) |