Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1 | // Copyright 2011 the V8 project authors. All rights reserved. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2 | // Redistribution and use in source and binary forms, with or without |
| 3 | // modification, are permitted provided that the following conditions are |
| 4 | // met: |
| 5 | // |
| 6 | // * Redistributions of source code must retain the above copyright |
| 7 | // notice, this list of conditions and the following disclaimer. |
| 8 | // * Redistributions in binary form must reproduce the above |
| 9 | // copyright notice, this list of conditions and the following |
| 10 | // disclaimer in the documentation and/or other materials provided |
| 11 | // with the distribution. |
| 12 | // * Neither the name of Google Inc. nor the names of its |
| 13 | // contributors may be used to endorse or promote products derived |
| 14 | // from this software without specific prior written permission. |
| 15 | // |
| 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | |
Iain Merrick | 9ac36c9 | 2010-09-13 15:29:50 +0100 | [diff] [blame] | 28 | #include <limits.h> // For LONG_MIN, LONG_MAX. |
| 29 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 30 | #include "v8.h" |
| 31 | |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 32 | #if defined(V8_TARGET_ARCH_ARM) |
| 33 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 34 | #include "bootstrapper.h" |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 35 | #include "codegen.h" |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 36 | #include "debug.h" |
| 37 | #include "runtime.h" |
| 38 | |
| 39 | namespace v8 { |
| 40 | namespace internal { |
| 41 | |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 42 | MacroAssembler::MacroAssembler(Isolate* arg_isolate, void* buffer, int size) |
| 43 | : Assembler(arg_isolate, buffer, size), |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 44 | generating_stub_(false), |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 45 | allow_stub_calls_(true) { |
| 46 | if (isolate() != NULL) { |
| 47 | code_object_ = Handle<Object>(isolate()->heap()->undefined_value(), |
| 48 | isolate()); |
| 49 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | |
| 53 | // We always generate arm code, never thumb code, even if V8 is compiled to |
| 54 | // thumb, so we require inter-working support |
| 55 | #if defined(__thumb__) && !defined(USE_THUMB_INTERWORK) |
| 56 | #error "flag -mthumb-interwork missing" |
| 57 | #endif |
| 58 | |
| 59 | |
| 60 | // We do not support thumb inter-working with an arm architecture not supporting |
| 61 | // the blx instruction (below v5t). If you know what CPU you are compiling for |
| 62 | // you can use -march=armv7 or similar. |
| 63 | #if defined(USE_THUMB_INTERWORK) && !defined(CAN_USE_THUMB_INSTRUCTIONS) |
| 64 | # error "For thumb inter-working we require an architecture which supports blx" |
| 65 | #endif |
| 66 | |
| 67 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 68 | // Using bx does not yield better code, so use it only when required |
| 69 | #if defined(USE_THUMB_INTERWORK) |
| 70 | #define USE_BX 1 |
| 71 | #endif |
| 72 | |
| 73 | |
| 74 | void MacroAssembler::Jump(Register target, Condition cond) { |
| 75 | #if USE_BX |
| 76 | bx(target, cond); |
| 77 | #else |
| 78 | mov(pc, Operand(target), LeaveCC, cond); |
| 79 | #endif |
| 80 | } |
| 81 | |
| 82 | |
| 83 | void MacroAssembler::Jump(intptr_t target, RelocInfo::Mode rmode, |
| 84 | Condition cond) { |
| 85 | #if USE_BX |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 86 | mov(ip, Operand(target, rmode)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 87 | bx(ip, cond); |
| 88 | #else |
| 89 | mov(pc, Operand(target, rmode), LeaveCC, cond); |
| 90 | #endif |
| 91 | } |
| 92 | |
| 93 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame^] | 94 | void MacroAssembler::Jump(Address target, RelocInfo::Mode rmode, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 95 | Condition cond) { |
| 96 | ASSERT(!RelocInfo::IsCodeTarget(rmode)); |
| 97 | Jump(reinterpret_cast<intptr_t>(target), rmode, cond); |
| 98 | } |
| 99 | |
| 100 | |
| 101 | void MacroAssembler::Jump(Handle<Code> code, RelocInfo::Mode rmode, |
| 102 | Condition cond) { |
| 103 | ASSERT(RelocInfo::IsCodeTarget(rmode)); |
| 104 | // 'code' is always generated ARM code, never THUMB code |
| 105 | Jump(reinterpret_cast<intptr_t>(code.location()), rmode, cond); |
| 106 | } |
| 107 | |
| 108 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 109 | int MacroAssembler::CallSize(Register target, Condition cond) { |
| 110 | #if USE_BLX |
| 111 | return kInstrSize; |
| 112 | #else |
| 113 | return 2 * kInstrSize; |
| 114 | #endif |
| 115 | } |
| 116 | |
| 117 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 118 | void MacroAssembler::Call(Register target, Condition cond) { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 119 | // Block constant pool for the call instruction sequence. |
| 120 | BlockConstPoolScope block_const_pool(this); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame^] | 121 | Label start; |
| 122 | bind(&start); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 123 | #if USE_BLX |
| 124 | blx(target, cond); |
| 125 | #else |
| 126 | // set lr for return at current pc + 8 |
| 127 | mov(lr, Operand(pc), LeaveCC, cond); |
| 128 | mov(pc, Operand(target), LeaveCC, cond); |
| 129 | #endif |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame^] | 130 | ASSERT_EQ(CallSize(target, cond), SizeOfCodeGeneratedSince(&start)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 131 | } |
| 132 | |
| 133 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 134 | int MacroAssembler::CallSize( |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame^] | 135 | Address target, RelocInfo::Mode rmode, Condition cond) { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 136 | int size = 2 * kInstrSize; |
| 137 | Instr mov_instr = cond | MOV | LeaveCC; |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame^] | 138 | intptr_t immediate = reinterpret_cast<intptr_t>(target); |
| 139 | if (!Operand(immediate, rmode).is_single_instruction(mov_instr)) { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 140 | size += kInstrSize; |
| 141 | } |
| 142 | return size; |
| 143 | } |
| 144 | |
| 145 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame^] | 146 | void MacroAssembler::Call(Address target, |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 147 | RelocInfo::Mode rmode, |
| 148 | Condition cond) { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 149 | // Block constant pool for the call instruction sequence. |
| 150 | BlockConstPoolScope block_const_pool(this); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame^] | 151 | Label start; |
| 152 | bind(&start); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 153 | #if USE_BLX |
| 154 | // On ARMv5 and after the recommended call sequence is: |
| 155 | // ldr ip, [pc, #...] |
| 156 | // blx ip |
| 157 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 158 | // Statement positions are expected to be recorded when the target |
| 159 | // address is loaded. The mov method will automatically record |
| 160 | // positions when pc is the target, since this is not the case here |
| 161 | // we have to do it explicitly. |
| 162 | positions_recorder()->WriteRecordedPositions(); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 163 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame^] | 164 | mov(ip, Operand(reinterpret_cast<int32_t>(target), rmode)); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 165 | blx(ip, cond); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 166 | |
| 167 | ASSERT(kCallTargetAddressOffset == 2 * kInstrSize); |
| 168 | #else |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 169 | // Set lr for return at current pc + 8. |
| 170 | mov(lr, Operand(pc), LeaveCC, cond); |
| 171 | // Emit a ldr<cond> pc, [pc + offset of target in constant pool]. |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame^] | 172 | mov(pc, Operand(reinterpret_cast<int32_t>(target), rmode), LeaveCC, cond); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 173 | ASSERT(kCallTargetAddressOffset == kInstrSize); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 174 | #endif |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame^] | 175 | ASSERT_EQ(CallSize(target, rmode, cond), SizeOfCodeGeneratedSince(&start)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 176 | } |
| 177 | |
| 178 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame^] | 179 | int MacroAssembler::CallSize(Handle<Code> code, |
| 180 | RelocInfo::Mode rmode, |
| 181 | unsigned ast_id, |
| 182 | Condition cond) { |
| 183 | return CallSize(reinterpret_cast<Address>(code.location()), rmode, cond); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 184 | } |
| 185 | |
| 186 | |
| 187 | void MacroAssembler::Call(Handle<Code> code, |
| 188 | RelocInfo::Mode rmode, |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame^] | 189 | unsigned ast_id, |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 190 | Condition cond) { |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame^] | 191 | Label start; |
| 192 | bind(&start); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 193 | ASSERT(RelocInfo::IsCodeTarget(rmode)); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame^] | 194 | if (rmode == RelocInfo::CODE_TARGET && ast_id != kNoASTId) { |
| 195 | SetRecordedAstId(ast_id); |
| 196 | rmode = RelocInfo::CODE_TARGET_WITH_ID; |
| 197 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 198 | // 'code' is always generated ARM code, never THUMB code |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame^] | 199 | Call(reinterpret_cast<Address>(code.location()), rmode, cond); |
| 200 | ASSERT_EQ(CallSize(code, rmode, ast_id, cond), |
| 201 | SizeOfCodeGeneratedSince(&start)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 202 | } |
| 203 | |
| 204 | |
| 205 | void MacroAssembler::Ret(Condition cond) { |
| 206 | #if USE_BX |
| 207 | bx(lr, cond); |
| 208 | #else |
| 209 | mov(pc, Operand(lr), LeaveCC, cond); |
| 210 | #endif |
| 211 | } |
| 212 | |
| 213 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 214 | void MacroAssembler::Drop(int count, Condition cond) { |
| 215 | if (count > 0) { |
| 216 | add(sp, sp, Operand(count * kPointerSize), LeaveCC, cond); |
| 217 | } |
| 218 | } |
| 219 | |
| 220 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 221 | void MacroAssembler::Ret(int drop, Condition cond) { |
| 222 | Drop(drop, cond); |
| 223 | Ret(cond); |
| 224 | } |
| 225 | |
| 226 | |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 227 | void MacroAssembler::Swap(Register reg1, |
| 228 | Register reg2, |
| 229 | Register scratch, |
| 230 | Condition cond) { |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 231 | if (scratch.is(no_reg)) { |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 232 | eor(reg1, reg1, Operand(reg2), LeaveCC, cond); |
| 233 | eor(reg2, reg2, Operand(reg1), LeaveCC, cond); |
| 234 | eor(reg1, reg1, Operand(reg2), LeaveCC, cond); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 235 | } else { |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 236 | mov(scratch, reg1, LeaveCC, cond); |
| 237 | mov(reg1, reg2, LeaveCC, cond); |
| 238 | mov(reg2, scratch, LeaveCC, cond); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 239 | } |
| 240 | } |
| 241 | |
| 242 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 243 | void MacroAssembler::Call(Label* target) { |
| 244 | bl(target); |
| 245 | } |
| 246 | |
| 247 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame^] | 248 | void MacroAssembler::Push(Handle<Object> handle) { |
| 249 | mov(ip, Operand(handle)); |
| 250 | push(ip); |
| 251 | } |
| 252 | |
| 253 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 254 | void MacroAssembler::Move(Register dst, Handle<Object> value) { |
| 255 | mov(dst, Operand(value)); |
| 256 | } |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 257 | |
| 258 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame^] | 259 | void MacroAssembler::Move(Register dst, Register src, Condition cond) { |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 260 | if (!dst.is(src)) { |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame^] | 261 | mov(dst, src, LeaveCC, cond); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 262 | } |
| 263 | } |
| 264 | |
| 265 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 266 | void MacroAssembler::Move(DoubleRegister dst, DoubleRegister src) { |
| 267 | ASSERT(CpuFeatures::IsSupported(VFP3)); |
| 268 | CpuFeatures::Scope scope(VFP3); |
| 269 | if (!dst.is(src)) { |
| 270 | vmov(dst, src); |
| 271 | } |
| 272 | } |
| 273 | |
| 274 | |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 275 | void MacroAssembler::And(Register dst, Register src1, const Operand& src2, |
| 276 | Condition cond) { |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 277 | if (!src2.is_reg() && |
| 278 | !src2.must_use_constant_pool() && |
| 279 | src2.immediate() == 0) { |
Iain Merrick | 9ac36c9 | 2010-09-13 15:29:50 +0100 | [diff] [blame] | 280 | mov(dst, Operand(0, RelocInfo::NONE), LeaveCC, cond); |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 281 | |
| 282 | } else if (!src2.is_single_instruction() && |
| 283 | !src2.must_use_constant_pool() && |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 284 | CpuFeatures::IsSupported(ARMv7) && |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 285 | IsPowerOf2(src2.immediate() + 1)) { |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame^] | 286 | ubfx(dst, src1, 0, |
| 287 | WhichPowerOf2(static_cast<uint32_t>(src2.immediate()) + 1), cond); |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 288 | |
| 289 | } else { |
| 290 | and_(dst, src1, src2, LeaveCC, cond); |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 291 | } |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 292 | } |
| 293 | |
| 294 | |
| 295 | void MacroAssembler::Ubfx(Register dst, Register src1, int lsb, int width, |
| 296 | Condition cond) { |
| 297 | ASSERT(lsb < 32); |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 298 | if (!CpuFeatures::IsSupported(ARMv7)) { |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 299 | int mask = (1 << (width + lsb)) - 1 - ((1 << lsb) - 1); |
| 300 | and_(dst, src1, Operand(mask), LeaveCC, cond); |
| 301 | if (lsb != 0) { |
| 302 | mov(dst, Operand(dst, LSR, lsb), LeaveCC, cond); |
| 303 | } |
| 304 | } else { |
| 305 | ubfx(dst, src1, lsb, width, cond); |
| 306 | } |
| 307 | } |
| 308 | |
| 309 | |
| 310 | void MacroAssembler::Sbfx(Register dst, Register src1, int lsb, int width, |
| 311 | Condition cond) { |
| 312 | ASSERT(lsb < 32); |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 313 | if (!CpuFeatures::IsSupported(ARMv7)) { |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 314 | int mask = (1 << (width + lsb)) - 1 - ((1 << lsb) - 1); |
| 315 | and_(dst, src1, Operand(mask), LeaveCC, cond); |
| 316 | int shift_up = 32 - lsb - width; |
| 317 | int shift_down = lsb + shift_up; |
| 318 | if (shift_up != 0) { |
| 319 | mov(dst, Operand(dst, LSL, shift_up), LeaveCC, cond); |
| 320 | } |
| 321 | if (shift_down != 0) { |
| 322 | mov(dst, Operand(dst, ASR, shift_down), LeaveCC, cond); |
| 323 | } |
| 324 | } else { |
| 325 | sbfx(dst, src1, lsb, width, cond); |
| 326 | } |
| 327 | } |
| 328 | |
| 329 | |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 330 | void MacroAssembler::Bfi(Register dst, |
| 331 | Register src, |
| 332 | Register scratch, |
| 333 | int lsb, |
| 334 | int width, |
| 335 | Condition cond) { |
| 336 | ASSERT(0 <= lsb && lsb < 32); |
| 337 | ASSERT(0 <= width && width < 32); |
| 338 | ASSERT(lsb + width < 32); |
| 339 | ASSERT(!scratch.is(dst)); |
| 340 | if (width == 0) return; |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 341 | if (!CpuFeatures::IsSupported(ARMv7)) { |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 342 | int mask = (1 << (width + lsb)) - 1 - ((1 << lsb) - 1); |
| 343 | bic(dst, dst, Operand(mask)); |
| 344 | and_(scratch, src, Operand((1 << width) - 1)); |
| 345 | mov(scratch, Operand(scratch, LSL, lsb)); |
| 346 | orr(dst, dst, scratch); |
| 347 | } else { |
| 348 | bfi(dst, src, lsb, width, cond); |
| 349 | } |
| 350 | } |
| 351 | |
| 352 | |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 353 | void MacroAssembler::Bfc(Register dst, int lsb, int width, Condition cond) { |
| 354 | ASSERT(lsb < 32); |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 355 | if (!CpuFeatures::IsSupported(ARMv7)) { |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 356 | int mask = (1 << (width + lsb)) - 1 - ((1 << lsb) - 1); |
| 357 | bic(dst, dst, Operand(mask)); |
| 358 | } else { |
| 359 | bfc(dst, lsb, width, cond); |
| 360 | } |
| 361 | } |
| 362 | |
| 363 | |
Kristian Monsen | 50ef84f | 2010-07-29 15:18:00 +0100 | [diff] [blame] | 364 | void MacroAssembler::Usat(Register dst, int satpos, const Operand& src, |
| 365 | Condition cond) { |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 366 | if (!CpuFeatures::IsSupported(ARMv7)) { |
Kristian Monsen | 50ef84f | 2010-07-29 15:18:00 +0100 | [diff] [blame] | 367 | ASSERT(!dst.is(pc) && !src.rm().is(pc)); |
| 368 | ASSERT((satpos >= 0) && (satpos <= 31)); |
| 369 | |
| 370 | // These asserts are required to ensure compatibility with the ARMv7 |
| 371 | // implementation. |
| 372 | ASSERT((src.shift_op() == ASR) || (src.shift_op() == LSL)); |
| 373 | ASSERT(src.rs().is(no_reg)); |
| 374 | |
| 375 | Label done; |
| 376 | int satval = (1 << satpos) - 1; |
| 377 | |
| 378 | if (cond != al) { |
| 379 | b(NegateCondition(cond), &done); // Skip saturate if !condition. |
| 380 | } |
| 381 | if (!(src.is_reg() && dst.is(src.rm()))) { |
| 382 | mov(dst, src); |
| 383 | } |
| 384 | tst(dst, Operand(~satval)); |
| 385 | b(eq, &done); |
Iain Merrick | 9ac36c9 | 2010-09-13 15:29:50 +0100 | [diff] [blame] | 386 | mov(dst, Operand(0, RelocInfo::NONE), LeaveCC, mi); // 0 if negative. |
Kristian Monsen | 50ef84f | 2010-07-29 15:18:00 +0100 | [diff] [blame] | 387 | mov(dst, Operand(satval), LeaveCC, pl); // satval if positive. |
| 388 | bind(&done); |
| 389 | } else { |
| 390 | usat(dst, satpos, src, cond); |
| 391 | } |
| 392 | } |
| 393 | |
| 394 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 395 | void MacroAssembler::LoadRoot(Register destination, |
| 396 | Heap::RootListIndex index, |
| 397 | Condition cond) { |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 398 | ldr(destination, MemOperand(roots, index << kPointerSizeLog2), cond); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 399 | } |
| 400 | |
| 401 | |
Kristian Monsen | 25f6136 | 2010-05-21 11:50:48 +0100 | [diff] [blame] | 402 | void MacroAssembler::StoreRoot(Register source, |
| 403 | Heap::RootListIndex index, |
| 404 | Condition cond) { |
| 405 | str(source, MemOperand(roots, index << kPointerSizeLog2), cond); |
| 406 | } |
| 407 | |
| 408 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 409 | void MacroAssembler::RecordWriteHelper(Register object, |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 410 | Register address, |
| 411 | Register scratch) { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 412 | if (emit_debug_code()) { |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 413 | // Check that the object is not in new space. |
| 414 | Label not_in_new_space; |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 415 | InNewSpace(object, scratch, ne, ¬_in_new_space); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 416 | Abort("new-space object passed to RecordWriteHelper"); |
| 417 | bind(¬_in_new_space); |
| 418 | } |
Leon Clarke | 4515c47 | 2010-02-03 11:58:03 +0000 | [diff] [blame] | 419 | |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 420 | // Calculate page address. |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 421 | Bfc(object, 0, kPageSizeBits); |
| 422 | |
| 423 | // Calculate region number. |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 424 | Ubfx(address, address, Page::kRegionSizeLog2, |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 425 | kPageSizeBits - Page::kRegionSizeLog2); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 426 | |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 427 | // Mark region dirty. |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 428 | ldr(scratch, MemOperand(object, Page::kDirtyFlagOffset)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 429 | mov(ip, Operand(1)); |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 430 | orr(scratch, scratch, Operand(ip, LSL, address)); |
| 431 | str(scratch, MemOperand(object, Page::kDirtyFlagOffset)); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 432 | } |
| 433 | |
| 434 | |
| 435 | void MacroAssembler::InNewSpace(Register object, |
| 436 | Register scratch, |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 437 | Condition cond, |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 438 | Label* branch) { |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 439 | ASSERT(cond == eq || cond == ne); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 440 | and_(scratch, object, Operand(ExternalReference::new_space_mask(isolate()))); |
| 441 | cmp(scratch, Operand(ExternalReference::new_space_start(isolate()))); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 442 | b(cond, branch); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 443 | } |
| 444 | |
| 445 | |
| 446 | // Will clobber 4 registers: object, offset, scratch, ip. The |
| 447 | // register 'object' contains a heap object pointer. The heap object |
| 448 | // tag is shifted away. |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 449 | void MacroAssembler::RecordWrite(Register object, |
| 450 | Operand offset, |
| 451 | Register scratch0, |
| 452 | Register scratch1) { |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 453 | // The compiled code assumes that record write doesn't change the |
| 454 | // context register, so we check that none of the clobbered |
| 455 | // registers are cp. |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 456 | ASSERT(!object.is(cp) && !scratch0.is(cp) && !scratch1.is(cp)); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 457 | |
| 458 | Label done; |
| 459 | |
| 460 | // First, test that the object is not in the new space. We cannot set |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 461 | // region marks for new space pages. |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 462 | InNewSpace(object, scratch0, eq, &done); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 463 | |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 464 | // Add offset into the object. |
| 465 | add(scratch0, object, offset); |
| 466 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 467 | // Record the actual write. |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 468 | RecordWriteHelper(object, scratch0, scratch1); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 469 | |
| 470 | bind(&done); |
Leon Clarke | 4515c47 | 2010-02-03 11:58:03 +0000 | [diff] [blame] | 471 | |
| 472 | // Clobber all input registers when running with the debug-code flag |
| 473 | // turned on to provoke errors. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 474 | if (emit_debug_code()) { |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 475 | mov(object, Operand(BitCast<int32_t>(kZapValue))); |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 476 | mov(scratch0, Operand(BitCast<int32_t>(kZapValue))); |
| 477 | mov(scratch1, Operand(BitCast<int32_t>(kZapValue))); |
Leon Clarke | 4515c47 | 2010-02-03 11:58:03 +0000 | [diff] [blame] | 478 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 479 | } |
| 480 | |
| 481 | |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 482 | // Will clobber 4 registers: object, address, scratch, ip. The |
| 483 | // register 'object' contains a heap object pointer. The heap object |
| 484 | // tag is shifted away. |
| 485 | void MacroAssembler::RecordWrite(Register object, |
| 486 | Register address, |
| 487 | Register scratch) { |
| 488 | // The compiled code assumes that record write doesn't change the |
| 489 | // context register, so we check that none of the clobbered |
| 490 | // registers are cp. |
| 491 | ASSERT(!object.is(cp) && !address.is(cp) && !scratch.is(cp)); |
| 492 | |
| 493 | Label done; |
| 494 | |
| 495 | // First, test that the object is not in the new space. We cannot set |
| 496 | // region marks for new space pages. |
| 497 | InNewSpace(object, scratch, eq, &done); |
| 498 | |
| 499 | // Record the actual write. |
| 500 | RecordWriteHelper(object, address, scratch); |
| 501 | |
| 502 | bind(&done); |
| 503 | |
| 504 | // Clobber all input registers when running with the debug-code flag |
| 505 | // turned on to provoke errors. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 506 | if (emit_debug_code()) { |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 507 | mov(object, Operand(BitCast<int32_t>(kZapValue))); |
| 508 | mov(address, Operand(BitCast<int32_t>(kZapValue))); |
| 509 | mov(scratch, Operand(BitCast<int32_t>(kZapValue))); |
| 510 | } |
| 511 | } |
| 512 | |
| 513 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 514 | // Push and pop all registers that can hold pointers. |
| 515 | void MacroAssembler::PushSafepointRegisters() { |
| 516 | // Safepoints expect a block of contiguous register values starting with r0: |
| 517 | ASSERT(((1 << kNumSafepointSavedRegisters) - 1) == kSafepointSavedRegisters); |
| 518 | // Safepoints expect a block of kNumSafepointRegisters values on the |
| 519 | // stack, so adjust the stack for unsaved registers. |
| 520 | const int num_unsaved = kNumSafepointRegisters - kNumSafepointSavedRegisters; |
| 521 | ASSERT(num_unsaved >= 0); |
| 522 | sub(sp, sp, Operand(num_unsaved * kPointerSize)); |
| 523 | stm(db_w, sp, kSafepointSavedRegisters); |
| 524 | } |
| 525 | |
| 526 | |
| 527 | void MacroAssembler::PopSafepointRegisters() { |
| 528 | const int num_unsaved = kNumSafepointRegisters - kNumSafepointSavedRegisters; |
| 529 | ldm(ia_w, sp, kSafepointSavedRegisters); |
| 530 | add(sp, sp, Operand(num_unsaved * kPointerSize)); |
| 531 | } |
| 532 | |
| 533 | |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 534 | void MacroAssembler::PushSafepointRegistersAndDoubles() { |
| 535 | PushSafepointRegisters(); |
| 536 | sub(sp, sp, Operand(DwVfpRegister::kNumAllocatableRegisters * |
| 537 | kDoubleSize)); |
| 538 | for (int i = 0; i < DwVfpRegister::kNumAllocatableRegisters; i++) { |
| 539 | vstr(DwVfpRegister::FromAllocationIndex(i), sp, i * kDoubleSize); |
| 540 | } |
| 541 | } |
| 542 | |
| 543 | |
| 544 | void MacroAssembler::PopSafepointRegistersAndDoubles() { |
| 545 | for (int i = 0; i < DwVfpRegister::kNumAllocatableRegisters; i++) { |
| 546 | vldr(DwVfpRegister::FromAllocationIndex(i), sp, i * kDoubleSize); |
| 547 | } |
| 548 | add(sp, sp, Operand(DwVfpRegister::kNumAllocatableRegisters * |
| 549 | kDoubleSize)); |
| 550 | PopSafepointRegisters(); |
| 551 | } |
| 552 | |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 553 | void MacroAssembler::StoreToSafepointRegistersAndDoublesSlot(Register src, |
| 554 | Register dst) { |
| 555 | str(src, SafepointRegistersAndDoublesSlot(dst)); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 556 | } |
| 557 | |
| 558 | |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 559 | void MacroAssembler::StoreToSafepointRegisterSlot(Register src, Register dst) { |
| 560 | str(src, SafepointRegisterSlot(dst)); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 561 | } |
| 562 | |
| 563 | |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 564 | void MacroAssembler::LoadFromSafepointRegisterSlot(Register dst, Register src) { |
| 565 | ldr(dst, SafepointRegisterSlot(src)); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 566 | } |
| 567 | |
| 568 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 569 | int MacroAssembler::SafepointRegisterStackIndex(int reg_code) { |
| 570 | // The registers are pushed starting with the highest encoding, |
| 571 | // which means that lowest encodings are closest to the stack pointer. |
| 572 | ASSERT(reg_code >= 0 && reg_code < kNumSafepointRegisters); |
| 573 | return reg_code; |
| 574 | } |
| 575 | |
| 576 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 577 | MemOperand MacroAssembler::SafepointRegisterSlot(Register reg) { |
| 578 | return MemOperand(sp, SafepointRegisterStackIndex(reg.code()) * kPointerSize); |
| 579 | } |
| 580 | |
| 581 | |
| 582 | MemOperand MacroAssembler::SafepointRegistersAndDoublesSlot(Register reg) { |
| 583 | // General purpose registers are pushed last on the stack. |
| 584 | int doubles_size = DwVfpRegister::kNumAllocatableRegisters * kDoubleSize; |
| 585 | int register_offset = SafepointRegisterStackIndex(reg.code()) * kPointerSize; |
| 586 | return MemOperand(sp, doubles_size + register_offset); |
| 587 | } |
| 588 | |
| 589 | |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 590 | void MacroAssembler::Ldrd(Register dst1, Register dst2, |
| 591 | const MemOperand& src, Condition cond) { |
| 592 | ASSERT(src.rm().is(no_reg)); |
| 593 | ASSERT(!dst1.is(lr)); // r14. |
| 594 | ASSERT_EQ(0, dst1.code() % 2); |
| 595 | ASSERT_EQ(dst1.code() + 1, dst2.code()); |
| 596 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame^] | 597 | // V8 does not use this addressing mode, so the fallback code |
| 598 | // below doesn't support it yet. |
| 599 | ASSERT((src.am() != PreIndex) && (src.am() != NegPreIndex)); |
| 600 | |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 601 | // Generate two ldr instructions if ldrd is not available. |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 602 | if (CpuFeatures::IsSupported(ARMv7)) { |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 603 | CpuFeatures::Scope scope(ARMv7); |
| 604 | ldrd(dst1, dst2, src, cond); |
| 605 | } else { |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame^] | 606 | if ((src.am() == Offset) || (src.am() == NegOffset)) { |
| 607 | MemOperand src2(src); |
| 608 | src2.set_offset(src2.offset() + 4); |
| 609 | if (dst1.is(src.rn())) { |
| 610 | ldr(dst2, src2, cond); |
| 611 | ldr(dst1, src, cond); |
| 612 | } else { |
| 613 | ldr(dst1, src, cond); |
| 614 | ldr(dst2, src2, cond); |
| 615 | } |
| 616 | } else { // PostIndex or NegPostIndex. |
| 617 | ASSERT((src.am() == PostIndex) || (src.am() == NegPostIndex)); |
| 618 | if (dst1.is(src.rn())) { |
| 619 | ldr(dst2, MemOperand(src.rn(), 4, Offset), cond); |
| 620 | ldr(dst1, src, cond); |
| 621 | } else { |
| 622 | MemOperand src2(src); |
| 623 | src2.set_offset(src2.offset() - 4); |
| 624 | ldr(dst1, MemOperand(src.rn(), 4, PostIndex), cond); |
| 625 | ldr(dst2, src2, cond); |
| 626 | } |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 627 | } |
| 628 | } |
| 629 | } |
| 630 | |
| 631 | |
| 632 | void MacroAssembler::Strd(Register src1, Register src2, |
| 633 | const MemOperand& dst, Condition cond) { |
| 634 | ASSERT(dst.rm().is(no_reg)); |
| 635 | ASSERT(!src1.is(lr)); // r14. |
| 636 | ASSERT_EQ(0, src1.code() % 2); |
| 637 | ASSERT_EQ(src1.code() + 1, src2.code()); |
| 638 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame^] | 639 | // V8 does not use this addressing mode, so the fallback code |
| 640 | // below doesn't support it yet. |
| 641 | ASSERT((dst.am() != PreIndex) && (dst.am() != NegPreIndex)); |
| 642 | |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 643 | // Generate two str instructions if strd is not available. |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 644 | if (CpuFeatures::IsSupported(ARMv7)) { |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 645 | CpuFeatures::Scope scope(ARMv7); |
| 646 | strd(src1, src2, dst, cond); |
| 647 | } else { |
| 648 | MemOperand dst2(dst); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame^] | 649 | if ((dst.am() == Offset) || (dst.am() == NegOffset)) { |
| 650 | dst2.set_offset(dst2.offset() + 4); |
| 651 | str(src1, dst, cond); |
| 652 | str(src2, dst2, cond); |
| 653 | } else { // PostIndex or NegPostIndex. |
| 654 | ASSERT((dst.am() == PostIndex) || (dst.am() == NegPostIndex)); |
| 655 | dst2.set_offset(dst2.offset() - 4); |
| 656 | str(src1, MemOperand(dst.rn(), 4, PostIndex), cond); |
| 657 | str(src2, dst2, cond); |
| 658 | } |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 659 | } |
| 660 | } |
| 661 | |
| 662 | |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 663 | void MacroAssembler::ClearFPSCRBits(const uint32_t bits_to_clear, |
| 664 | const Register scratch, |
| 665 | const Condition cond) { |
| 666 | vmrs(scratch, cond); |
| 667 | bic(scratch, scratch, Operand(bits_to_clear), LeaveCC, cond); |
| 668 | vmsr(scratch, cond); |
| 669 | } |
| 670 | |
| 671 | |
| 672 | void MacroAssembler::VFPCompareAndSetFlags(const DwVfpRegister src1, |
| 673 | const DwVfpRegister src2, |
| 674 | const Condition cond) { |
| 675 | // Compare and move FPSCR flags to the normal condition flags. |
| 676 | VFPCompareAndLoadFlags(src1, src2, pc, cond); |
| 677 | } |
| 678 | |
| 679 | void MacroAssembler::VFPCompareAndSetFlags(const DwVfpRegister src1, |
| 680 | const double src2, |
| 681 | const Condition cond) { |
| 682 | // Compare and move FPSCR flags to the normal condition flags. |
| 683 | VFPCompareAndLoadFlags(src1, src2, pc, cond); |
| 684 | } |
| 685 | |
| 686 | |
| 687 | void MacroAssembler::VFPCompareAndLoadFlags(const DwVfpRegister src1, |
| 688 | const DwVfpRegister src2, |
| 689 | const Register fpscr_flags, |
| 690 | const Condition cond) { |
| 691 | // Compare and load FPSCR. |
| 692 | vcmp(src1, src2, cond); |
| 693 | vmrs(fpscr_flags, cond); |
| 694 | } |
| 695 | |
| 696 | void MacroAssembler::VFPCompareAndLoadFlags(const DwVfpRegister src1, |
| 697 | const double src2, |
| 698 | const Register fpscr_flags, |
| 699 | const Condition cond) { |
| 700 | // Compare and load FPSCR. |
| 701 | vcmp(src1, src2, cond); |
| 702 | vmrs(fpscr_flags, cond); |
Ben Murdoch | 086aeea | 2011-05-13 15:57:08 +0100 | [diff] [blame] | 703 | } |
| 704 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame^] | 705 | void MacroAssembler::Vmov(const DwVfpRegister dst, |
| 706 | const double imm, |
| 707 | const Condition cond) { |
| 708 | ASSERT(CpuFeatures::IsEnabled(VFP3)); |
| 709 | static const DoubleRepresentation minus_zero(-0.0); |
| 710 | static const DoubleRepresentation zero(0.0); |
| 711 | DoubleRepresentation value(imm); |
| 712 | // Handle special values first. |
| 713 | if (value.bits == zero.bits) { |
| 714 | vmov(dst, kDoubleRegZero, cond); |
| 715 | } else if (value.bits == minus_zero.bits) { |
| 716 | vneg(dst, kDoubleRegZero, cond); |
| 717 | } else { |
| 718 | vmov(dst, imm, cond); |
| 719 | } |
| 720 | } |
| 721 | |
Ben Murdoch | 086aeea | 2011-05-13 15:57:08 +0100 | [diff] [blame] | 722 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 723 | void MacroAssembler::EnterFrame(StackFrame::Type type) { |
| 724 | // r0-r3: preserved |
| 725 | stm(db_w, sp, cp.bit() | fp.bit() | lr.bit()); |
| 726 | mov(ip, Operand(Smi::FromInt(type))); |
| 727 | push(ip); |
| 728 | mov(ip, Operand(CodeObject())); |
| 729 | push(ip); |
| 730 | add(fp, sp, Operand(3 * kPointerSize)); // Adjust FP to point to saved FP. |
| 731 | } |
| 732 | |
| 733 | |
| 734 | void MacroAssembler::LeaveFrame(StackFrame::Type type) { |
| 735 | // r0: preserved |
| 736 | // r1: preserved |
| 737 | // r2: preserved |
| 738 | |
| 739 | // Drop the execution stack down to the frame pointer and restore |
| 740 | // the caller frame pointer and return address. |
| 741 | mov(sp, fp); |
| 742 | ldm(ia_w, sp, fp.bit() | lr.bit()); |
| 743 | } |
| 744 | |
| 745 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 746 | void MacroAssembler::EnterExitFrame(bool save_doubles, int stack_space) { |
| 747 | // Setup the frame structure on the stack. |
| 748 | ASSERT_EQ(2 * kPointerSize, ExitFrameConstants::kCallerSPDisplacement); |
| 749 | ASSERT_EQ(1 * kPointerSize, ExitFrameConstants::kCallerPCOffset); |
| 750 | ASSERT_EQ(0 * kPointerSize, ExitFrameConstants::kCallerFPOffset); |
| 751 | Push(lr, fp); |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 752 | mov(fp, Operand(sp)); // Setup new frame pointer. |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 753 | // Reserve room for saved entry sp and code object. |
| 754 | sub(sp, sp, Operand(2 * kPointerSize)); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 755 | if (emit_debug_code()) { |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 756 | mov(ip, Operand(0)); |
| 757 | str(ip, MemOperand(fp, ExitFrameConstants::kSPOffset)); |
| 758 | } |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 759 | mov(ip, Operand(CodeObject())); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 760 | str(ip, MemOperand(fp, ExitFrameConstants::kCodeOffset)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 761 | |
| 762 | // Save the frame pointer and the context in top. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 763 | mov(ip, Operand(ExternalReference(Isolate::k_c_entry_fp_address, isolate()))); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 764 | str(fp, MemOperand(ip)); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 765 | mov(ip, Operand(ExternalReference(Isolate::k_context_address, isolate()))); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 766 | str(cp, MemOperand(ip)); |
| 767 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 768 | // Optionally save all double registers. |
| 769 | if (save_doubles) { |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 770 | DwVfpRegister first = d0; |
| 771 | DwVfpRegister last = |
| 772 | DwVfpRegister::from_code(DwVfpRegister::kNumRegisters - 1); |
| 773 | vstm(db_w, sp, first, last); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 774 | // Note that d0 will be accessible at |
| 775 | // fp - 2 * kPointerSize - DwVfpRegister::kNumRegisters * kDoubleSize, |
| 776 | // since the sp slot and code slot were pushed after the fp. |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 777 | } |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 778 | |
| 779 | // Reserve place for the return address and stack space and align the frame |
| 780 | // preparing for calling the runtime function. |
| 781 | const int frame_alignment = MacroAssembler::ActivationFrameAlignment(); |
| 782 | sub(sp, sp, Operand((stack_space + 1) * kPointerSize)); |
| 783 | if (frame_alignment > 0) { |
| 784 | ASSERT(IsPowerOf2(frame_alignment)); |
| 785 | and_(sp, sp, Operand(-frame_alignment)); |
| 786 | } |
| 787 | |
| 788 | // Set the exit frame sp value to point just before the return address |
| 789 | // location. |
| 790 | add(ip, sp, Operand(kPointerSize)); |
| 791 | str(ip, MemOperand(fp, ExitFrameConstants::kSPOffset)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 792 | } |
| 793 | |
| 794 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 795 | void MacroAssembler::InitializeNewString(Register string, |
| 796 | Register length, |
| 797 | Heap::RootListIndex map_index, |
| 798 | Register scratch1, |
| 799 | Register scratch2) { |
| 800 | mov(scratch1, Operand(length, LSL, kSmiTagSize)); |
| 801 | LoadRoot(scratch2, map_index); |
| 802 | str(scratch1, FieldMemOperand(string, String::kLengthOffset)); |
| 803 | mov(scratch1, Operand(String::kEmptyHashField)); |
| 804 | str(scratch2, FieldMemOperand(string, HeapObject::kMapOffset)); |
| 805 | str(scratch1, FieldMemOperand(string, String::kHashFieldOffset)); |
| 806 | } |
| 807 | |
| 808 | |
| 809 | int MacroAssembler::ActivationFrameAlignment() { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 810 | #if defined(V8_HOST_ARCH_ARM) |
| 811 | // Running on the real platform. Use the alignment as mandated by the local |
| 812 | // environment. |
| 813 | // Note: This will break if we ever start generating snapshots on one ARM |
| 814 | // platform for another ARM platform with a different alignment. |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 815 | return OS::ActivationFrameAlignment(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 816 | #else // defined(V8_HOST_ARCH_ARM) |
| 817 | // If we are using the simulator then we should always align to the expected |
| 818 | // alignment. As the simulator is used to generate snapshots we do not know |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 819 | // if the target platform will need alignment, so this is controlled from a |
| 820 | // flag. |
| 821 | return FLAG_sim_stack_alignment; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 822 | #endif // defined(V8_HOST_ARCH_ARM) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 823 | } |
| 824 | |
| 825 | |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 826 | void MacroAssembler::LeaveExitFrame(bool save_doubles, |
| 827 | Register argument_count) { |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 828 | // Optionally restore all double registers. |
| 829 | if (save_doubles) { |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 830 | // Calculate the stack location of the saved doubles and restore them. |
| 831 | const int offset = 2 * kPointerSize; |
| 832 | sub(r3, fp, Operand(offset + DwVfpRegister::kNumRegisters * kDoubleSize)); |
| 833 | DwVfpRegister first = d0; |
| 834 | DwVfpRegister last = |
| 835 | DwVfpRegister::from_code(DwVfpRegister::kNumRegisters - 1); |
| 836 | vldm(ia, r3, first, last); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 837 | } |
| 838 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 839 | // Clear top frame. |
Iain Merrick | 9ac36c9 | 2010-09-13 15:29:50 +0100 | [diff] [blame] | 840 | mov(r3, Operand(0, RelocInfo::NONE)); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 841 | mov(ip, Operand(ExternalReference(Isolate::k_c_entry_fp_address, isolate()))); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 842 | str(r3, MemOperand(ip)); |
| 843 | |
| 844 | // Restore current context from top and clear it in debug mode. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 845 | mov(ip, Operand(ExternalReference(Isolate::k_context_address, isolate()))); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 846 | ldr(cp, MemOperand(ip)); |
| 847 | #ifdef DEBUG |
| 848 | str(r3, MemOperand(ip)); |
| 849 | #endif |
| 850 | |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 851 | // Tear down the exit frame, pop the arguments, and return. |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 852 | mov(sp, Operand(fp)); |
| 853 | ldm(ia_w, sp, fp.bit() | lr.bit()); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 854 | if (argument_count.is_valid()) { |
| 855 | add(sp, sp, Operand(argument_count, LSL, kPointerSizeLog2)); |
| 856 | } |
| 857 | } |
| 858 | |
| 859 | void MacroAssembler::GetCFunctionDoubleResult(const DoubleRegister dst) { |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 860 | if (use_eabi_hardfloat()) { |
| 861 | Move(dst, d0); |
| 862 | } else { |
| 863 | vmov(dst, r0, r1); |
| 864 | } |
| 865 | } |
| 866 | |
| 867 | |
| 868 | void MacroAssembler::SetCallKind(Register dst, CallKind call_kind) { |
| 869 | // This macro takes the dst register to make the code more readable |
| 870 | // at the call sites. However, the dst register has to be r5 to |
| 871 | // follow the calling convention which requires the call type to be |
| 872 | // in r5. |
| 873 | ASSERT(dst.is(r5)); |
| 874 | if (call_kind == CALL_AS_FUNCTION) { |
| 875 | mov(dst, Operand(Smi::FromInt(1))); |
| 876 | } else { |
| 877 | mov(dst, Operand(Smi::FromInt(0))); |
| 878 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 879 | } |
| 880 | |
| 881 | |
| 882 | void MacroAssembler::InvokePrologue(const ParameterCount& expected, |
| 883 | const ParameterCount& actual, |
| 884 | Handle<Code> code_constant, |
| 885 | Register code_reg, |
| 886 | Label* done, |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 887 | InvokeFlag flag, |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 888 | const CallWrapper& call_wrapper, |
| 889 | CallKind call_kind) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 890 | bool definitely_matches = false; |
| 891 | Label regular_invoke; |
| 892 | |
| 893 | // Check whether the expected and actual arguments count match. If not, |
| 894 | // setup registers according to contract with ArgumentsAdaptorTrampoline: |
| 895 | // r0: actual arguments count |
| 896 | // r1: function (passed through to callee) |
| 897 | // r2: expected arguments count |
| 898 | // r3: callee code entry |
| 899 | |
| 900 | // The code below is made a lot easier because the calling code already sets |
| 901 | // up actual and expected registers according to the contract if values are |
| 902 | // passed in registers. |
| 903 | ASSERT(actual.is_immediate() || actual.reg().is(r0)); |
| 904 | ASSERT(expected.is_immediate() || expected.reg().is(r2)); |
| 905 | ASSERT((!code_constant.is_null() && code_reg.is(no_reg)) || code_reg.is(r3)); |
| 906 | |
| 907 | if (expected.is_immediate()) { |
| 908 | ASSERT(actual.is_immediate()); |
| 909 | if (expected.immediate() == actual.immediate()) { |
| 910 | definitely_matches = true; |
| 911 | } else { |
| 912 | mov(r0, Operand(actual.immediate())); |
| 913 | const int sentinel = SharedFunctionInfo::kDontAdaptArgumentsSentinel; |
| 914 | if (expected.immediate() == sentinel) { |
| 915 | // Don't worry about adapting arguments for builtins that |
| 916 | // don't want that done. Skip adaption code by making it look |
| 917 | // like we have a match between expected and actual number of |
| 918 | // arguments. |
| 919 | definitely_matches = true; |
| 920 | } else { |
| 921 | mov(r2, Operand(expected.immediate())); |
| 922 | } |
| 923 | } |
| 924 | } else { |
| 925 | if (actual.is_immediate()) { |
| 926 | cmp(expected.reg(), Operand(actual.immediate())); |
| 927 | b(eq, ®ular_invoke); |
| 928 | mov(r0, Operand(actual.immediate())); |
| 929 | } else { |
| 930 | cmp(expected.reg(), Operand(actual.reg())); |
| 931 | b(eq, ®ular_invoke); |
| 932 | } |
| 933 | } |
| 934 | |
| 935 | if (!definitely_matches) { |
| 936 | if (!code_constant.is_null()) { |
| 937 | mov(r3, Operand(code_constant)); |
| 938 | add(r3, r3, Operand(Code::kHeaderSize - kHeapObjectTag)); |
| 939 | } |
| 940 | |
| 941 | Handle<Code> adaptor = |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 942 | isolate()->builtins()->ArgumentsAdaptorTrampoline(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 943 | if (flag == CALL_FUNCTION) { |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame^] | 944 | call_wrapper.BeforeCall(CallSize(adaptor)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 945 | SetCallKind(r5, call_kind); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame^] | 946 | Call(adaptor); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 947 | call_wrapper.AfterCall(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 948 | b(done); |
| 949 | } else { |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 950 | SetCallKind(r5, call_kind); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 951 | Jump(adaptor, RelocInfo::CODE_TARGET); |
| 952 | } |
| 953 | bind(®ular_invoke); |
| 954 | } |
| 955 | } |
| 956 | |
| 957 | |
| 958 | void MacroAssembler::InvokeCode(Register code, |
| 959 | const ParameterCount& expected, |
| 960 | const ParameterCount& actual, |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 961 | InvokeFlag flag, |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 962 | const CallWrapper& call_wrapper, |
| 963 | CallKind call_kind) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 964 | Label done; |
| 965 | |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 966 | InvokePrologue(expected, actual, Handle<Code>::null(), code, &done, flag, |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 967 | call_wrapper, call_kind); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 968 | if (flag == CALL_FUNCTION) { |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 969 | call_wrapper.BeforeCall(CallSize(code)); |
| 970 | SetCallKind(r5, call_kind); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 971 | Call(code); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 972 | call_wrapper.AfterCall(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 973 | } else { |
| 974 | ASSERT(flag == JUMP_FUNCTION); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 975 | SetCallKind(r5, call_kind); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 976 | Jump(code); |
| 977 | } |
| 978 | |
| 979 | // Continue here if InvokePrologue does handle the invocation due to |
| 980 | // mismatched parameter counts. |
| 981 | bind(&done); |
| 982 | } |
| 983 | |
| 984 | |
| 985 | void MacroAssembler::InvokeCode(Handle<Code> code, |
| 986 | const ParameterCount& expected, |
| 987 | const ParameterCount& actual, |
| 988 | RelocInfo::Mode rmode, |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 989 | InvokeFlag flag, |
| 990 | CallKind call_kind) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 991 | Label done; |
| 992 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 993 | InvokePrologue(expected, actual, code, no_reg, &done, flag, |
| 994 | NullCallWrapper(), call_kind); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 995 | if (flag == CALL_FUNCTION) { |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 996 | SetCallKind(r5, call_kind); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 997 | Call(code, rmode); |
| 998 | } else { |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 999 | SetCallKind(r5, call_kind); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1000 | Jump(code, rmode); |
| 1001 | } |
| 1002 | |
| 1003 | // Continue here if InvokePrologue does handle the invocation due to |
| 1004 | // mismatched parameter counts. |
| 1005 | bind(&done); |
| 1006 | } |
| 1007 | |
| 1008 | |
| 1009 | void MacroAssembler::InvokeFunction(Register fun, |
| 1010 | const ParameterCount& actual, |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 1011 | InvokeFlag flag, |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1012 | const CallWrapper& call_wrapper, |
| 1013 | CallKind call_kind) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1014 | // Contract with called JS functions requires that function is passed in r1. |
| 1015 | ASSERT(fun.is(r1)); |
| 1016 | |
| 1017 | Register expected_reg = r2; |
| 1018 | Register code_reg = r3; |
| 1019 | |
| 1020 | ldr(code_reg, FieldMemOperand(r1, JSFunction::kSharedFunctionInfoOffset)); |
| 1021 | ldr(cp, FieldMemOperand(r1, JSFunction::kContextOffset)); |
| 1022 | ldr(expected_reg, |
| 1023 | FieldMemOperand(code_reg, |
| 1024 | SharedFunctionInfo::kFormalParameterCountOffset)); |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 1025 | mov(expected_reg, Operand(expected_reg, ASR, kSmiTagSize)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1026 | ldr(code_reg, |
Steve Block | 791712a | 2010-08-27 10:21:07 +0100 | [diff] [blame] | 1027 | FieldMemOperand(r1, JSFunction::kCodeEntryOffset)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1028 | |
| 1029 | ParameterCount expected(expected_reg); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1030 | InvokeCode(code_reg, expected, actual, flag, call_wrapper, call_kind); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1031 | } |
| 1032 | |
| 1033 | |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 1034 | void MacroAssembler::InvokeFunction(JSFunction* function, |
| 1035 | const ParameterCount& actual, |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1036 | InvokeFlag flag, |
| 1037 | CallKind call_kind) { |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 1038 | ASSERT(function->is_compiled()); |
| 1039 | |
| 1040 | // Get the function and setup the context. |
| 1041 | mov(r1, Operand(Handle<JSFunction>(function))); |
| 1042 | ldr(cp, FieldMemOperand(r1, JSFunction::kContextOffset)); |
| 1043 | |
| 1044 | // Invoke the cached code. |
| 1045 | Handle<Code> code(function->code()); |
| 1046 | ParameterCount expected(function->shared()->formal_parameter_count()); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1047 | if (V8::UseCrankshaft()) { |
| 1048 | // TODO(kasperl): For now, we always call indirectly through the |
| 1049 | // code field in the function to allow recompilation to take effect |
| 1050 | // without changing any of the call sites. |
| 1051 | ldr(r3, FieldMemOperand(r1, JSFunction::kCodeEntryOffset)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1052 | InvokeCode(r3, expected, actual, flag, NullCallWrapper(), call_kind); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1053 | } else { |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1054 | InvokeCode(code, expected, actual, RelocInfo::CODE_TARGET, flag, call_kind); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1055 | } |
| 1056 | } |
| 1057 | |
| 1058 | |
| 1059 | void MacroAssembler::IsObjectJSObjectType(Register heap_object, |
| 1060 | Register map, |
| 1061 | Register scratch, |
| 1062 | Label* fail) { |
| 1063 | ldr(map, FieldMemOperand(heap_object, HeapObject::kMapOffset)); |
| 1064 | IsInstanceJSObjectType(map, scratch, fail); |
| 1065 | } |
| 1066 | |
| 1067 | |
| 1068 | void MacroAssembler::IsInstanceJSObjectType(Register map, |
| 1069 | Register scratch, |
| 1070 | Label* fail) { |
| 1071 | ldrb(scratch, FieldMemOperand(map, Map::kInstanceTypeOffset)); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame^] | 1072 | cmp(scratch, Operand(FIRST_NONCALLABLE_SPEC_OBJECT_TYPE)); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1073 | b(lt, fail); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame^] | 1074 | cmp(scratch, Operand(LAST_NONCALLABLE_SPEC_OBJECT_TYPE)); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1075 | b(gt, fail); |
| 1076 | } |
| 1077 | |
| 1078 | |
| 1079 | void MacroAssembler::IsObjectJSStringType(Register object, |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 1080 | Register scratch, |
| 1081 | Label* fail) { |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1082 | ASSERT(kNotStringTag != 0); |
| 1083 | |
| 1084 | ldr(scratch, FieldMemOperand(object, HeapObject::kMapOffset)); |
| 1085 | ldrb(scratch, FieldMemOperand(scratch, Map::kInstanceTypeOffset)); |
| 1086 | tst(scratch, Operand(kIsNotStringMask)); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1087 | b(ne, fail); |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 1088 | } |
| 1089 | |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1090 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1091 | #ifdef ENABLE_DEBUGGER_SUPPORT |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 1092 | void MacroAssembler::DebugBreak() { |
| 1093 | ASSERT(allow_stub_calls()); |
Iain Merrick | 9ac36c9 | 2010-09-13 15:29:50 +0100 | [diff] [blame] | 1094 | mov(r0, Operand(0, RelocInfo::NONE)); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1095 | mov(r1, Operand(ExternalReference(Runtime::kDebugBreak, isolate()))); |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 1096 | CEntryStub ces(1); |
| 1097 | Call(ces.GetCode(), RelocInfo::DEBUG_BREAK); |
| 1098 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1099 | #endif |
| 1100 | |
| 1101 | |
| 1102 | void MacroAssembler::PushTryHandler(CodeLocation try_location, |
| 1103 | HandlerType type) { |
| 1104 | // Adjust this code if not the case. |
| 1105 | ASSERT(StackHandlerConstants::kSize == 4 * kPointerSize); |
| 1106 | // The pc (return address) is passed in register lr. |
| 1107 | if (try_location == IN_JAVASCRIPT) { |
| 1108 | if (type == TRY_CATCH_HANDLER) { |
| 1109 | mov(r3, Operand(StackHandler::TRY_CATCH)); |
| 1110 | } else { |
| 1111 | mov(r3, Operand(StackHandler::TRY_FINALLY)); |
| 1112 | } |
| 1113 | ASSERT(StackHandlerConstants::kStateOffset == 1 * kPointerSize |
| 1114 | && StackHandlerConstants::kFPOffset == 2 * kPointerSize |
| 1115 | && StackHandlerConstants::kPCOffset == 3 * kPointerSize); |
| 1116 | stm(db_w, sp, r3.bit() | fp.bit() | lr.bit()); |
| 1117 | // Save the current handler as the next handler. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1118 | mov(r3, Operand(ExternalReference(Isolate::k_handler_address, isolate()))); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1119 | ldr(r1, MemOperand(r3)); |
| 1120 | ASSERT(StackHandlerConstants::kNextOffset == 0); |
| 1121 | push(r1); |
| 1122 | // Link this handler as the new current one. |
| 1123 | str(sp, MemOperand(r3)); |
| 1124 | } else { |
| 1125 | // Must preserve r0-r4, r5-r7 are available. |
| 1126 | ASSERT(try_location == IN_JS_ENTRY); |
| 1127 | // The frame pointer does not point to a JS frame so we save NULL |
| 1128 | // for fp. We expect the code throwing an exception to check fp |
| 1129 | // before dereferencing it to restore the context. |
Iain Merrick | 9ac36c9 | 2010-09-13 15:29:50 +0100 | [diff] [blame] | 1130 | mov(ip, Operand(0, RelocInfo::NONE)); // To save a NULL frame pointer. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1131 | mov(r6, Operand(StackHandler::ENTRY)); |
| 1132 | ASSERT(StackHandlerConstants::kStateOffset == 1 * kPointerSize |
| 1133 | && StackHandlerConstants::kFPOffset == 2 * kPointerSize |
| 1134 | && StackHandlerConstants::kPCOffset == 3 * kPointerSize); |
| 1135 | stm(db_w, sp, r6.bit() | ip.bit() | lr.bit()); |
| 1136 | // Save the current handler as the next handler. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1137 | mov(r7, Operand(ExternalReference(Isolate::k_handler_address, isolate()))); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1138 | ldr(r6, MemOperand(r7)); |
| 1139 | ASSERT(StackHandlerConstants::kNextOffset == 0); |
| 1140 | push(r6); |
| 1141 | // Link this handler as the new current one. |
| 1142 | str(sp, MemOperand(r7)); |
| 1143 | } |
| 1144 | } |
| 1145 | |
| 1146 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 1147 | void MacroAssembler::PopTryHandler() { |
| 1148 | ASSERT_EQ(0, StackHandlerConstants::kNextOffset); |
| 1149 | pop(r1); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1150 | mov(ip, Operand(ExternalReference(Isolate::k_handler_address, isolate()))); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 1151 | add(sp, sp, Operand(StackHandlerConstants::kSize - kPointerSize)); |
| 1152 | str(r1, MemOperand(ip)); |
| 1153 | } |
| 1154 | |
| 1155 | |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 1156 | void MacroAssembler::Throw(Register value) { |
| 1157 | // r0 is expected to hold the exception. |
| 1158 | if (!value.is(r0)) { |
| 1159 | mov(r0, value); |
| 1160 | } |
| 1161 | |
| 1162 | // Adjust this code if not the case. |
| 1163 | STATIC_ASSERT(StackHandlerConstants::kSize == 4 * kPointerSize); |
| 1164 | |
| 1165 | // Drop the sp to the top of the handler. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1166 | mov(r3, Operand(ExternalReference(Isolate::k_handler_address, isolate()))); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 1167 | ldr(sp, MemOperand(r3)); |
| 1168 | |
| 1169 | // Restore the next handler and frame pointer, discard handler state. |
| 1170 | STATIC_ASSERT(StackHandlerConstants::kNextOffset == 0); |
| 1171 | pop(r2); |
| 1172 | str(r2, MemOperand(r3)); |
| 1173 | STATIC_ASSERT(StackHandlerConstants::kFPOffset == 2 * kPointerSize); |
| 1174 | ldm(ia_w, sp, r3.bit() | fp.bit()); // r3: discarded state. |
| 1175 | |
| 1176 | // Before returning we restore the context from the frame pointer if |
| 1177 | // not NULL. The frame pointer is NULL in the exception handler of a |
| 1178 | // JS entry frame. |
| 1179 | cmp(fp, Operand(0, RelocInfo::NONE)); |
| 1180 | // Set cp to NULL if fp is NULL. |
| 1181 | mov(cp, Operand(0, RelocInfo::NONE), LeaveCC, eq); |
| 1182 | // Restore cp otherwise. |
| 1183 | ldr(cp, MemOperand(fp, StandardFrameConstants::kContextOffset), ne); |
| 1184 | #ifdef DEBUG |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1185 | if (emit_debug_code()) { |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 1186 | mov(lr, Operand(pc)); |
| 1187 | } |
| 1188 | #endif |
| 1189 | STATIC_ASSERT(StackHandlerConstants::kPCOffset == 3 * kPointerSize); |
| 1190 | pop(pc); |
| 1191 | } |
| 1192 | |
| 1193 | |
| 1194 | void MacroAssembler::ThrowUncatchable(UncatchableExceptionType type, |
| 1195 | Register value) { |
| 1196 | // Adjust this code if not the case. |
| 1197 | STATIC_ASSERT(StackHandlerConstants::kSize == 4 * kPointerSize); |
| 1198 | |
| 1199 | // r0 is expected to hold the exception. |
| 1200 | if (!value.is(r0)) { |
| 1201 | mov(r0, value); |
| 1202 | } |
| 1203 | |
| 1204 | // Drop sp to the top stack handler. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1205 | mov(r3, Operand(ExternalReference(Isolate::k_handler_address, isolate()))); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 1206 | ldr(sp, MemOperand(r3)); |
| 1207 | |
| 1208 | // Unwind the handlers until the ENTRY handler is found. |
| 1209 | Label loop, done; |
| 1210 | bind(&loop); |
| 1211 | // Load the type of the current stack handler. |
| 1212 | const int kStateOffset = StackHandlerConstants::kStateOffset; |
| 1213 | ldr(r2, MemOperand(sp, kStateOffset)); |
| 1214 | cmp(r2, Operand(StackHandler::ENTRY)); |
| 1215 | b(eq, &done); |
| 1216 | // Fetch the next handler in the list. |
| 1217 | const int kNextOffset = StackHandlerConstants::kNextOffset; |
| 1218 | ldr(sp, MemOperand(sp, kNextOffset)); |
| 1219 | jmp(&loop); |
| 1220 | bind(&done); |
| 1221 | |
| 1222 | // Set the top handler address to next handler past the current ENTRY handler. |
| 1223 | STATIC_ASSERT(StackHandlerConstants::kNextOffset == 0); |
| 1224 | pop(r2); |
| 1225 | str(r2, MemOperand(r3)); |
| 1226 | |
| 1227 | if (type == OUT_OF_MEMORY) { |
| 1228 | // Set external caught exception to false. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1229 | ExternalReference external_caught( |
| 1230 | Isolate::k_external_caught_exception_address, isolate()); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 1231 | mov(r0, Operand(false, RelocInfo::NONE)); |
| 1232 | mov(r2, Operand(external_caught)); |
| 1233 | str(r0, MemOperand(r2)); |
| 1234 | |
| 1235 | // Set pending exception and r0 to out of memory exception. |
| 1236 | Failure* out_of_memory = Failure::OutOfMemoryException(); |
| 1237 | mov(r0, Operand(reinterpret_cast<int32_t>(out_of_memory))); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1238 | mov(r2, Operand(ExternalReference(Isolate::k_pending_exception_address, |
| 1239 | isolate()))); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 1240 | str(r0, MemOperand(r2)); |
| 1241 | } |
| 1242 | |
| 1243 | // Stack layout at this point. See also StackHandlerConstants. |
| 1244 | // sp -> state (ENTRY) |
| 1245 | // fp |
| 1246 | // lr |
| 1247 | |
| 1248 | // Discard handler state (r2 is not used) and restore frame pointer. |
| 1249 | STATIC_ASSERT(StackHandlerConstants::kFPOffset == 2 * kPointerSize); |
| 1250 | ldm(ia_w, sp, r2.bit() | fp.bit()); // r2: discarded state. |
| 1251 | // Before returning we restore the context from the frame pointer if |
| 1252 | // not NULL. The frame pointer is NULL in the exception handler of a |
| 1253 | // JS entry frame. |
| 1254 | cmp(fp, Operand(0, RelocInfo::NONE)); |
| 1255 | // Set cp to NULL if fp is NULL. |
| 1256 | mov(cp, Operand(0, RelocInfo::NONE), LeaveCC, eq); |
| 1257 | // Restore cp otherwise. |
| 1258 | ldr(cp, MemOperand(fp, StandardFrameConstants::kContextOffset), ne); |
| 1259 | #ifdef DEBUG |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1260 | if (emit_debug_code()) { |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 1261 | mov(lr, Operand(pc)); |
| 1262 | } |
| 1263 | #endif |
| 1264 | STATIC_ASSERT(StackHandlerConstants::kPCOffset == 3 * kPointerSize); |
| 1265 | pop(pc); |
| 1266 | } |
| 1267 | |
| 1268 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1269 | void MacroAssembler::CheckAccessGlobalProxy(Register holder_reg, |
| 1270 | Register scratch, |
| 1271 | Label* miss) { |
| 1272 | Label same_contexts; |
| 1273 | |
| 1274 | ASSERT(!holder_reg.is(scratch)); |
| 1275 | ASSERT(!holder_reg.is(ip)); |
| 1276 | ASSERT(!scratch.is(ip)); |
| 1277 | |
| 1278 | // Load current lexical context from the stack frame. |
| 1279 | ldr(scratch, MemOperand(fp, StandardFrameConstants::kContextOffset)); |
| 1280 | // In debug mode, make sure the lexical context is set. |
| 1281 | #ifdef DEBUG |
Iain Merrick | 9ac36c9 | 2010-09-13 15:29:50 +0100 | [diff] [blame] | 1282 | cmp(scratch, Operand(0, RelocInfo::NONE)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1283 | Check(ne, "we should not have an empty lexical context"); |
| 1284 | #endif |
| 1285 | |
| 1286 | // Load the global context of the current context. |
| 1287 | int offset = Context::kHeaderSize + Context::GLOBAL_INDEX * kPointerSize; |
| 1288 | ldr(scratch, FieldMemOperand(scratch, offset)); |
| 1289 | ldr(scratch, FieldMemOperand(scratch, GlobalObject::kGlobalContextOffset)); |
| 1290 | |
| 1291 | // Check the context is a global context. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1292 | if (emit_debug_code()) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1293 | // TODO(119): avoid push(holder_reg)/pop(holder_reg) |
| 1294 | // Cannot use ip as a temporary in this verification code. Due to the fact |
| 1295 | // that ip is clobbered as part of cmp with an object Operand. |
| 1296 | push(holder_reg); // Temporarily save holder on the stack. |
| 1297 | // Read the first word and compare to the global_context_map. |
| 1298 | ldr(holder_reg, FieldMemOperand(scratch, HeapObject::kMapOffset)); |
| 1299 | LoadRoot(ip, Heap::kGlobalContextMapRootIndex); |
| 1300 | cmp(holder_reg, ip); |
| 1301 | Check(eq, "JSGlobalObject::global_context should be a global context."); |
| 1302 | pop(holder_reg); // Restore holder. |
| 1303 | } |
| 1304 | |
| 1305 | // Check if both contexts are the same. |
| 1306 | ldr(ip, FieldMemOperand(holder_reg, JSGlobalProxy::kContextOffset)); |
| 1307 | cmp(scratch, Operand(ip)); |
| 1308 | b(eq, &same_contexts); |
| 1309 | |
| 1310 | // Check the context is a global context. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1311 | if (emit_debug_code()) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1312 | // TODO(119): avoid push(holder_reg)/pop(holder_reg) |
| 1313 | // Cannot use ip as a temporary in this verification code. Due to the fact |
| 1314 | // that ip is clobbered as part of cmp with an object Operand. |
| 1315 | push(holder_reg); // Temporarily save holder on the stack. |
| 1316 | mov(holder_reg, ip); // Move ip to its holding place. |
| 1317 | LoadRoot(ip, Heap::kNullValueRootIndex); |
| 1318 | cmp(holder_reg, ip); |
| 1319 | Check(ne, "JSGlobalProxy::context() should not be null."); |
| 1320 | |
| 1321 | ldr(holder_reg, FieldMemOperand(holder_reg, HeapObject::kMapOffset)); |
| 1322 | LoadRoot(ip, Heap::kGlobalContextMapRootIndex); |
| 1323 | cmp(holder_reg, ip); |
| 1324 | Check(eq, "JSGlobalObject::global_context should be a global context."); |
| 1325 | // Restore ip is not needed. ip is reloaded below. |
| 1326 | pop(holder_reg); // Restore holder. |
| 1327 | // Restore ip to holder's context. |
| 1328 | ldr(ip, FieldMemOperand(holder_reg, JSGlobalProxy::kContextOffset)); |
| 1329 | } |
| 1330 | |
| 1331 | // Check that the security token in the calling global object is |
| 1332 | // compatible with the security token in the receiving global |
| 1333 | // object. |
| 1334 | int token_offset = Context::kHeaderSize + |
| 1335 | Context::SECURITY_TOKEN_INDEX * kPointerSize; |
| 1336 | |
| 1337 | ldr(scratch, FieldMemOperand(scratch, token_offset)); |
| 1338 | ldr(ip, FieldMemOperand(ip, token_offset)); |
| 1339 | cmp(scratch, Operand(ip)); |
| 1340 | b(ne, miss); |
| 1341 | |
| 1342 | bind(&same_contexts); |
| 1343 | } |
| 1344 | |
| 1345 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame^] | 1346 | void MacroAssembler::LoadFromNumberDictionary(Label* miss, |
| 1347 | Register elements, |
| 1348 | Register key, |
| 1349 | Register result, |
| 1350 | Register t0, |
| 1351 | Register t1, |
| 1352 | Register t2) { |
| 1353 | // Register use: |
| 1354 | // |
| 1355 | // elements - holds the slow-case elements of the receiver on entry. |
| 1356 | // Unchanged unless 'result' is the same register. |
| 1357 | // |
| 1358 | // key - holds the smi key on entry. |
| 1359 | // Unchanged unless 'result' is the same register. |
| 1360 | // |
| 1361 | // result - holds the result on exit if the load succeeded. |
| 1362 | // Allowed to be the same as 'key' or 'result'. |
| 1363 | // Unchanged on bailout so 'key' or 'result' can be used |
| 1364 | // in further computation. |
| 1365 | // |
| 1366 | // Scratch registers: |
| 1367 | // |
| 1368 | // t0 - holds the untagged key on entry and holds the hash once computed. |
| 1369 | // |
| 1370 | // t1 - used to hold the capacity mask of the dictionary |
| 1371 | // |
| 1372 | // t2 - used for the index into the dictionary. |
| 1373 | Label done; |
| 1374 | |
| 1375 | // Compute the hash code from the untagged key. This must be kept in sync |
| 1376 | // with ComputeIntegerHash in utils.h. |
| 1377 | // |
| 1378 | // hash = ~hash + (hash << 15); |
| 1379 | mvn(t1, Operand(t0)); |
| 1380 | add(t0, t1, Operand(t0, LSL, 15)); |
| 1381 | // hash = hash ^ (hash >> 12); |
| 1382 | eor(t0, t0, Operand(t0, LSR, 12)); |
| 1383 | // hash = hash + (hash << 2); |
| 1384 | add(t0, t0, Operand(t0, LSL, 2)); |
| 1385 | // hash = hash ^ (hash >> 4); |
| 1386 | eor(t0, t0, Operand(t0, LSR, 4)); |
| 1387 | // hash = hash * 2057; |
| 1388 | mov(t1, Operand(2057)); |
| 1389 | mul(t0, t0, t1); |
| 1390 | // hash = hash ^ (hash >> 16); |
| 1391 | eor(t0, t0, Operand(t0, LSR, 16)); |
| 1392 | |
| 1393 | // Compute the capacity mask. |
| 1394 | ldr(t1, FieldMemOperand(elements, NumberDictionary::kCapacityOffset)); |
| 1395 | mov(t1, Operand(t1, ASR, kSmiTagSize)); // convert smi to int |
| 1396 | sub(t1, t1, Operand(1)); |
| 1397 | |
| 1398 | // Generate an unrolled loop that performs a few probes before giving up. |
| 1399 | static const int kProbes = 4; |
| 1400 | for (int i = 0; i < kProbes; i++) { |
| 1401 | // Use t2 for index calculations and keep the hash intact in t0. |
| 1402 | mov(t2, t0); |
| 1403 | // Compute the masked index: (hash + i + i * i) & mask. |
| 1404 | if (i > 0) { |
| 1405 | add(t2, t2, Operand(NumberDictionary::GetProbeOffset(i))); |
| 1406 | } |
| 1407 | and_(t2, t2, Operand(t1)); |
| 1408 | |
| 1409 | // Scale the index by multiplying by the element size. |
| 1410 | ASSERT(NumberDictionary::kEntrySize == 3); |
| 1411 | add(t2, t2, Operand(t2, LSL, 1)); // t2 = t2 * 3 |
| 1412 | |
| 1413 | // Check if the key is identical to the name. |
| 1414 | add(t2, elements, Operand(t2, LSL, kPointerSizeLog2)); |
| 1415 | ldr(ip, FieldMemOperand(t2, NumberDictionary::kElementsStartOffset)); |
| 1416 | cmp(key, Operand(ip)); |
| 1417 | if (i != kProbes - 1) { |
| 1418 | b(eq, &done); |
| 1419 | } else { |
| 1420 | b(ne, miss); |
| 1421 | } |
| 1422 | } |
| 1423 | |
| 1424 | bind(&done); |
| 1425 | // Check that the value is a normal property. |
| 1426 | // t2: elements + (index * kPointerSize) |
| 1427 | const int kDetailsOffset = |
| 1428 | NumberDictionary::kElementsStartOffset + 2 * kPointerSize; |
| 1429 | ldr(t1, FieldMemOperand(t2, kDetailsOffset)); |
| 1430 | tst(t1, Operand(Smi::FromInt(PropertyDetails::TypeField::mask()))); |
| 1431 | b(ne, miss); |
| 1432 | |
| 1433 | // Get the value at the masked, scaled index and return. |
| 1434 | const int kValueOffset = |
| 1435 | NumberDictionary::kElementsStartOffset + kPointerSize; |
| 1436 | ldr(result, FieldMemOperand(t2, kValueOffset)); |
| 1437 | } |
| 1438 | |
| 1439 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1440 | void MacroAssembler::AllocateInNewSpace(int object_size, |
| 1441 | Register result, |
| 1442 | Register scratch1, |
| 1443 | Register scratch2, |
| 1444 | Label* gc_required, |
| 1445 | AllocationFlags flags) { |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1446 | if (!FLAG_inline_new) { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1447 | if (emit_debug_code()) { |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1448 | // Trash the registers to simulate an allocation failure. |
| 1449 | mov(result, Operand(0x7091)); |
| 1450 | mov(scratch1, Operand(0x7191)); |
| 1451 | mov(scratch2, Operand(0x7291)); |
| 1452 | } |
| 1453 | jmp(gc_required); |
| 1454 | return; |
| 1455 | } |
| 1456 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1457 | ASSERT(!result.is(scratch1)); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1458 | ASSERT(!result.is(scratch2)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1459 | ASSERT(!scratch1.is(scratch2)); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 1460 | ASSERT(!scratch1.is(ip)); |
| 1461 | ASSERT(!scratch2.is(ip)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1462 | |
Kristian Monsen | 25f6136 | 2010-05-21 11:50:48 +0100 | [diff] [blame] | 1463 | // Make object size into bytes. |
| 1464 | if ((flags & SIZE_IN_WORDS) != 0) { |
| 1465 | object_size *= kPointerSize; |
| 1466 | } |
| 1467 | ASSERT_EQ(0, object_size & kObjectAlignmentMask); |
| 1468 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1469 | // Check relative positions of allocation top and limit addresses. |
| 1470 | // The values must be adjacent in memory to allow the use of LDM. |
| 1471 | // Also, assert that the registers are numbered such that the values |
| 1472 | // are loaded in the correct order. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1473 | ExternalReference new_space_allocation_top = |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1474 | ExternalReference::new_space_allocation_top_address(isolate()); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1475 | ExternalReference new_space_allocation_limit = |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1476 | ExternalReference::new_space_allocation_limit_address(isolate()); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1477 | intptr_t top = |
| 1478 | reinterpret_cast<intptr_t>(new_space_allocation_top.address()); |
| 1479 | intptr_t limit = |
| 1480 | reinterpret_cast<intptr_t>(new_space_allocation_limit.address()); |
| 1481 | ASSERT((limit - top) == kPointerSize); |
| 1482 | ASSERT(result.code() < ip.code()); |
| 1483 | |
| 1484 | // Set up allocation top address and object size registers. |
| 1485 | Register topaddr = scratch1; |
| 1486 | Register obj_size_reg = scratch2; |
| 1487 | mov(topaddr, Operand(new_space_allocation_top)); |
| 1488 | mov(obj_size_reg, Operand(object_size)); |
| 1489 | |
| 1490 | // This code stores a temporary value in ip. This is OK, as the code below |
| 1491 | // does not need ip for implicit literal generation. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1492 | if ((flags & RESULT_CONTAINS_TOP) == 0) { |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1493 | // Load allocation top into result and allocation limit into ip. |
| 1494 | ldm(ia, topaddr, result.bit() | ip.bit()); |
| 1495 | } else { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1496 | if (emit_debug_code()) { |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1497 | // Assert that result actually contains top on entry. ip is used |
| 1498 | // immediately below so this use of ip does not cause difference with |
| 1499 | // respect to register content between debug and release mode. |
| 1500 | ldr(ip, MemOperand(topaddr)); |
| 1501 | cmp(result, ip); |
| 1502 | Check(eq, "Unexpected allocation top"); |
| 1503 | } |
| 1504 | // Load allocation limit into ip. Result already contains allocation top. |
| 1505 | ldr(ip, MemOperand(topaddr, limit - top)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1506 | } |
| 1507 | |
| 1508 | // Calculate new top and bail out if new space is exhausted. Use result |
| 1509 | // to calculate the new top. |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1510 | add(scratch2, result, Operand(obj_size_reg), SetCC); |
| 1511 | b(cs, gc_required); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1512 | cmp(scratch2, Operand(ip)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1513 | b(hi, gc_required); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1514 | str(scratch2, MemOperand(topaddr)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1515 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1516 | // Tag object if requested. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1517 | if ((flags & TAG_OBJECT) != 0) { |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1518 | add(result, result, Operand(kHeapObjectTag)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1519 | } |
| 1520 | } |
| 1521 | |
| 1522 | |
| 1523 | void MacroAssembler::AllocateInNewSpace(Register object_size, |
| 1524 | Register result, |
| 1525 | Register scratch1, |
| 1526 | Register scratch2, |
| 1527 | Label* gc_required, |
| 1528 | AllocationFlags flags) { |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1529 | if (!FLAG_inline_new) { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1530 | if (emit_debug_code()) { |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1531 | // Trash the registers to simulate an allocation failure. |
| 1532 | mov(result, Operand(0x7091)); |
| 1533 | mov(scratch1, Operand(0x7191)); |
| 1534 | mov(scratch2, Operand(0x7291)); |
| 1535 | } |
| 1536 | jmp(gc_required); |
| 1537 | return; |
| 1538 | } |
| 1539 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1540 | // Assert that the register arguments are different and that none of |
| 1541 | // them are ip. ip is used explicitly in the code generated below. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1542 | ASSERT(!result.is(scratch1)); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1543 | ASSERT(!result.is(scratch2)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1544 | ASSERT(!scratch1.is(scratch2)); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1545 | ASSERT(!result.is(ip)); |
| 1546 | ASSERT(!scratch1.is(ip)); |
| 1547 | ASSERT(!scratch2.is(ip)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1548 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1549 | // Check relative positions of allocation top and limit addresses. |
| 1550 | // The values must be adjacent in memory to allow the use of LDM. |
| 1551 | // Also, assert that the registers are numbered such that the values |
| 1552 | // are loaded in the correct order. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1553 | ExternalReference new_space_allocation_top = |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1554 | ExternalReference::new_space_allocation_top_address(isolate()); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1555 | ExternalReference new_space_allocation_limit = |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1556 | ExternalReference::new_space_allocation_limit_address(isolate()); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1557 | intptr_t top = |
| 1558 | reinterpret_cast<intptr_t>(new_space_allocation_top.address()); |
| 1559 | intptr_t limit = |
| 1560 | reinterpret_cast<intptr_t>(new_space_allocation_limit.address()); |
| 1561 | ASSERT((limit - top) == kPointerSize); |
| 1562 | ASSERT(result.code() < ip.code()); |
| 1563 | |
| 1564 | // Set up allocation top address. |
| 1565 | Register topaddr = scratch1; |
| 1566 | mov(topaddr, Operand(new_space_allocation_top)); |
| 1567 | |
| 1568 | // This code stores a temporary value in ip. This is OK, as the code below |
| 1569 | // does not need ip for implicit literal generation. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1570 | if ((flags & RESULT_CONTAINS_TOP) == 0) { |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1571 | // Load allocation top into result and allocation limit into ip. |
| 1572 | ldm(ia, topaddr, result.bit() | ip.bit()); |
| 1573 | } else { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1574 | if (emit_debug_code()) { |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1575 | // Assert that result actually contains top on entry. ip is used |
| 1576 | // immediately below so this use of ip does not cause difference with |
| 1577 | // respect to register content between debug and release mode. |
| 1578 | ldr(ip, MemOperand(topaddr)); |
| 1579 | cmp(result, ip); |
| 1580 | Check(eq, "Unexpected allocation top"); |
| 1581 | } |
| 1582 | // Load allocation limit into ip. Result already contains allocation top. |
| 1583 | ldr(ip, MemOperand(topaddr, limit - top)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1584 | } |
| 1585 | |
| 1586 | // Calculate new top and bail out if new space is exhausted. Use result |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1587 | // to calculate the new top. Object size may be in words so a shift is |
| 1588 | // required to get the number of bytes. |
Kristian Monsen | 25f6136 | 2010-05-21 11:50:48 +0100 | [diff] [blame] | 1589 | if ((flags & SIZE_IN_WORDS) != 0) { |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1590 | add(scratch2, result, Operand(object_size, LSL, kPointerSizeLog2), SetCC); |
Kristian Monsen | 25f6136 | 2010-05-21 11:50:48 +0100 | [diff] [blame] | 1591 | } else { |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1592 | add(scratch2, result, Operand(object_size), SetCC); |
Kristian Monsen | 25f6136 | 2010-05-21 11:50:48 +0100 | [diff] [blame] | 1593 | } |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1594 | b(cs, gc_required); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1595 | cmp(scratch2, Operand(ip)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1596 | b(hi, gc_required); |
| 1597 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 1598 | // Update allocation top. result temporarily holds the new top. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1599 | if (emit_debug_code()) { |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1600 | tst(scratch2, Operand(kObjectAlignmentMask)); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 1601 | Check(eq, "Unaligned allocation in new space"); |
| 1602 | } |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1603 | str(scratch2, MemOperand(topaddr)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1604 | |
| 1605 | // Tag object if requested. |
| 1606 | if ((flags & TAG_OBJECT) != 0) { |
| 1607 | add(result, result, Operand(kHeapObjectTag)); |
| 1608 | } |
| 1609 | } |
| 1610 | |
| 1611 | |
| 1612 | void MacroAssembler::UndoAllocationInNewSpace(Register object, |
| 1613 | Register scratch) { |
| 1614 | ExternalReference new_space_allocation_top = |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1615 | ExternalReference::new_space_allocation_top_address(isolate()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1616 | |
| 1617 | // Make sure the object has no tag before resetting top. |
| 1618 | and_(object, object, Operand(~kHeapObjectTagMask)); |
| 1619 | #ifdef DEBUG |
| 1620 | // Check that the object un-allocated is below the current top. |
| 1621 | mov(scratch, Operand(new_space_allocation_top)); |
| 1622 | ldr(scratch, MemOperand(scratch)); |
| 1623 | cmp(object, scratch); |
| 1624 | Check(lt, "Undo allocation of non allocated memory"); |
| 1625 | #endif |
| 1626 | // Write the address of the object to un-allocate as the current top. |
| 1627 | mov(scratch, Operand(new_space_allocation_top)); |
| 1628 | str(object, MemOperand(scratch)); |
| 1629 | } |
| 1630 | |
| 1631 | |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 1632 | void MacroAssembler::AllocateTwoByteString(Register result, |
| 1633 | Register length, |
| 1634 | Register scratch1, |
| 1635 | Register scratch2, |
| 1636 | Register scratch3, |
| 1637 | Label* gc_required) { |
| 1638 | // Calculate the number of bytes needed for the characters in the string while |
| 1639 | // observing object alignment. |
| 1640 | ASSERT((SeqTwoByteString::kHeaderSize & kObjectAlignmentMask) == 0); |
| 1641 | mov(scratch1, Operand(length, LSL, 1)); // Length in bytes, not chars. |
| 1642 | add(scratch1, scratch1, |
| 1643 | Operand(kObjectAlignmentMask + SeqTwoByteString::kHeaderSize)); |
Kristian Monsen | 25f6136 | 2010-05-21 11:50:48 +0100 | [diff] [blame] | 1644 | and_(scratch1, scratch1, Operand(~kObjectAlignmentMask)); |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 1645 | |
| 1646 | // Allocate two-byte string in new space. |
| 1647 | AllocateInNewSpace(scratch1, |
| 1648 | result, |
| 1649 | scratch2, |
| 1650 | scratch3, |
| 1651 | gc_required, |
| 1652 | TAG_OBJECT); |
| 1653 | |
| 1654 | // Set the map, length and hash field. |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1655 | InitializeNewString(result, |
| 1656 | length, |
| 1657 | Heap::kStringMapRootIndex, |
| 1658 | scratch1, |
| 1659 | scratch2); |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 1660 | } |
| 1661 | |
| 1662 | |
| 1663 | void MacroAssembler::AllocateAsciiString(Register result, |
| 1664 | Register length, |
| 1665 | Register scratch1, |
| 1666 | Register scratch2, |
| 1667 | Register scratch3, |
| 1668 | Label* gc_required) { |
| 1669 | // Calculate the number of bytes needed for the characters in the string while |
| 1670 | // observing object alignment. |
| 1671 | ASSERT((SeqAsciiString::kHeaderSize & kObjectAlignmentMask) == 0); |
| 1672 | ASSERT(kCharSize == 1); |
| 1673 | add(scratch1, length, |
| 1674 | Operand(kObjectAlignmentMask + SeqAsciiString::kHeaderSize)); |
Kristian Monsen | 25f6136 | 2010-05-21 11:50:48 +0100 | [diff] [blame] | 1675 | and_(scratch1, scratch1, Operand(~kObjectAlignmentMask)); |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 1676 | |
| 1677 | // Allocate ASCII string in new space. |
| 1678 | AllocateInNewSpace(scratch1, |
| 1679 | result, |
| 1680 | scratch2, |
| 1681 | scratch3, |
| 1682 | gc_required, |
| 1683 | TAG_OBJECT); |
| 1684 | |
| 1685 | // Set the map, length and hash field. |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1686 | InitializeNewString(result, |
| 1687 | length, |
| 1688 | Heap::kAsciiStringMapRootIndex, |
| 1689 | scratch1, |
| 1690 | scratch2); |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 1691 | } |
| 1692 | |
| 1693 | |
| 1694 | void MacroAssembler::AllocateTwoByteConsString(Register result, |
| 1695 | Register length, |
| 1696 | Register scratch1, |
| 1697 | Register scratch2, |
| 1698 | Label* gc_required) { |
Kristian Monsen | 25f6136 | 2010-05-21 11:50:48 +0100 | [diff] [blame] | 1699 | AllocateInNewSpace(ConsString::kSize, |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 1700 | result, |
| 1701 | scratch1, |
| 1702 | scratch2, |
| 1703 | gc_required, |
| 1704 | TAG_OBJECT); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1705 | |
| 1706 | InitializeNewString(result, |
| 1707 | length, |
| 1708 | Heap::kConsStringMapRootIndex, |
| 1709 | scratch1, |
| 1710 | scratch2); |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 1711 | } |
| 1712 | |
| 1713 | |
| 1714 | void MacroAssembler::AllocateAsciiConsString(Register result, |
| 1715 | Register length, |
| 1716 | Register scratch1, |
| 1717 | Register scratch2, |
| 1718 | Label* gc_required) { |
Kristian Monsen | 25f6136 | 2010-05-21 11:50:48 +0100 | [diff] [blame] | 1719 | AllocateInNewSpace(ConsString::kSize, |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 1720 | result, |
| 1721 | scratch1, |
| 1722 | scratch2, |
| 1723 | gc_required, |
| 1724 | TAG_OBJECT); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1725 | |
| 1726 | InitializeNewString(result, |
| 1727 | length, |
| 1728 | Heap::kConsAsciiStringMapRootIndex, |
| 1729 | scratch1, |
| 1730 | scratch2); |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 1731 | } |
| 1732 | |
| 1733 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1734 | void MacroAssembler::CompareObjectType(Register object, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1735 | Register map, |
| 1736 | Register type_reg, |
| 1737 | InstanceType type) { |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1738 | ldr(map, FieldMemOperand(object, HeapObject::kMapOffset)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1739 | CompareInstanceType(map, type_reg, type); |
| 1740 | } |
| 1741 | |
| 1742 | |
| 1743 | void MacroAssembler::CompareInstanceType(Register map, |
| 1744 | Register type_reg, |
| 1745 | InstanceType type) { |
| 1746 | ldrb(type_reg, FieldMemOperand(map, Map::kInstanceTypeOffset)); |
| 1747 | cmp(type_reg, Operand(type)); |
| 1748 | } |
| 1749 | |
| 1750 | |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 1751 | void MacroAssembler::CompareRoot(Register obj, |
| 1752 | Heap::RootListIndex index) { |
| 1753 | ASSERT(!obj.is(ip)); |
| 1754 | LoadRoot(ip, index); |
| 1755 | cmp(obj, ip); |
| 1756 | } |
| 1757 | |
| 1758 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame^] | 1759 | void MacroAssembler::CheckFastElements(Register map, |
| 1760 | Register scratch, |
| 1761 | Label* fail) { |
| 1762 | STATIC_ASSERT(JSObject::FAST_ELEMENTS == 0); |
| 1763 | ldrb(scratch, FieldMemOperand(map, Map::kBitField2Offset)); |
| 1764 | cmp(scratch, Operand(Map::kMaximumBitField2FastElementValue)); |
| 1765 | b(hi, fail); |
| 1766 | } |
| 1767 | |
| 1768 | |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 1769 | void MacroAssembler::CheckMap(Register obj, |
| 1770 | Register scratch, |
| 1771 | Handle<Map> map, |
| 1772 | Label* fail, |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1773 | SmiCheckType smi_check_type) { |
| 1774 | if (smi_check_type == DO_SMI_CHECK) { |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1775 | JumpIfSmi(obj, fail); |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 1776 | } |
| 1777 | ldr(scratch, FieldMemOperand(obj, HeapObject::kMapOffset)); |
| 1778 | mov(ip, Operand(map)); |
| 1779 | cmp(scratch, ip); |
| 1780 | b(ne, fail); |
| 1781 | } |
| 1782 | |
| 1783 | |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 1784 | void MacroAssembler::CheckMap(Register obj, |
| 1785 | Register scratch, |
| 1786 | Heap::RootListIndex index, |
| 1787 | Label* fail, |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1788 | SmiCheckType smi_check_type) { |
| 1789 | if (smi_check_type == DO_SMI_CHECK) { |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1790 | JumpIfSmi(obj, fail); |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 1791 | } |
| 1792 | ldr(scratch, FieldMemOperand(obj, HeapObject::kMapOffset)); |
| 1793 | LoadRoot(ip, index); |
| 1794 | cmp(scratch, ip); |
| 1795 | b(ne, fail); |
| 1796 | } |
| 1797 | |
| 1798 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1799 | void MacroAssembler::DispatchMap(Register obj, |
| 1800 | Register scratch, |
| 1801 | Handle<Map> map, |
| 1802 | Handle<Code> success, |
| 1803 | SmiCheckType smi_check_type) { |
| 1804 | Label fail; |
| 1805 | if (smi_check_type == DO_SMI_CHECK) { |
| 1806 | JumpIfSmi(obj, &fail); |
| 1807 | } |
| 1808 | ldr(scratch, FieldMemOperand(obj, HeapObject::kMapOffset)); |
| 1809 | mov(ip, Operand(map)); |
| 1810 | cmp(scratch, ip); |
| 1811 | Jump(success, RelocInfo::CODE_TARGET, eq); |
| 1812 | bind(&fail); |
| 1813 | } |
| 1814 | |
| 1815 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1816 | void MacroAssembler::TryGetFunctionPrototype(Register function, |
| 1817 | Register result, |
| 1818 | Register scratch, |
| 1819 | Label* miss) { |
| 1820 | // Check that the receiver isn't a smi. |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1821 | JumpIfSmi(function, miss); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1822 | |
| 1823 | // Check that the function really is a function. Load map into result reg. |
| 1824 | CompareObjectType(function, result, scratch, JS_FUNCTION_TYPE); |
| 1825 | b(ne, miss); |
| 1826 | |
| 1827 | // Make sure that the function has an instance prototype. |
| 1828 | Label non_instance; |
| 1829 | ldrb(scratch, FieldMemOperand(result, Map::kBitFieldOffset)); |
| 1830 | tst(scratch, Operand(1 << Map::kHasNonInstancePrototype)); |
| 1831 | b(ne, &non_instance); |
| 1832 | |
| 1833 | // Get the prototype or initial map from the function. |
| 1834 | ldr(result, |
| 1835 | FieldMemOperand(function, JSFunction::kPrototypeOrInitialMapOffset)); |
| 1836 | |
| 1837 | // If the prototype or initial map is the hole, don't return it and |
| 1838 | // simply miss the cache instead. This will allow us to allocate a |
| 1839 | // prototype object on-demand in the runtime system. |
| 1840 | LoadRoot(ip, Heap::kTheHoleValueRootIndex); |
| 1841 | cmp(result, ip); |
| 1842 | b(eq, miss); |
| 1843 | |
| 1844 | // If the function does not have an initial map, we're done. |
| 1845 | Label done; |
| 1846 | CompareObjectType(result, scratch, scratch, MAP_TYPE); |
| 1847 | b(ne, &done); |
| 1848 | |
| 1849 | // Get the prototype from the initial map. |
| 1850 | ldr(result, FieldMemOperand(result, Map::kPrototypeOffset)); |
| 1851 | jmp(&done); |
| 1852 | |
| 1853 | // Non-instance prototype: Fetch prototype from constructor field |
| 1854 | // in initial map. |
| 1855 | bind(&non_instance); |
| 1856 | ldr(result, FieldMemOperand(result, Map::kConstructorOffset)); |
| 1857 | |
| 1858 | // All done. |
| 1859 | bind(&done); |
| 1860 | } |
| 1861 | |
| 1862 | |
| 1863 | void MacroAssembler::CallStub(CodeStub* stub, Condition cond) { |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1864 | ASSERT(allow_stub_calls()); // Stub calls are not allowed in some stubs. |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame^] | 1865 | Call(stub->GetCode(), RelocInfo::CODE_TARGET, kNoASTId, cond); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1866 | } |
| 1867 | |
| 1868 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1869 | MaybeObject* MacroAssembler::TryCallStub(CodeStub* stub, Condition cond) { |
| 1870 | ASSERT(allow_stub_calls()); // Stub calls are not allowed in some stubs. |
| 1871 | Object* result; |
| 1872 | { MaybeObject* maybe_result = stub->TryGetCode(); |
| 1873 | if (!maybe_result->ToObject(&result)) return maybe_result; |
| 1874 | } |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame^] | 1875 | Handle<Code> code(Code::cast(result)); |
| 1876 | Call(code, RelocInfo::CODE_TARGET, kNoASTId, cond); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1877 | return result; |
| 1878 | } |
| 1879 | |
| 1880 | |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 1881 | void MacroAssembler::TailCallStub(CodeStub* stub, Condition cond) { |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1882 | ASSERT(allow_stub_calls()); // Stub calls are not allowed in some stubs. |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 1883 | Jump(stub->GetCode(), RelocInfo::CODE_TARGET, cond); |
| 1884 | } |
| 1885 | |
| 1886 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1887 | MaybeObject* MacroAssembler::TryTailCallStub(CodeStub* stub, Condition cond) { |
| 1888 | ASSERT(allow_stub_calls()); // Stub calls are not allowed in some stubs. |
| 1889 | Object* result; |
| 1890 | { MaybeObject* maybe_result = stub->TryGetCode(); |
| 1891 | if (!maybe_result->ToObject(&result)) return maybe_result; |
| 1892 | } |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1893 | Jump(Handle<Code>(Code::cast(result)), RelocInfo::CODE_TARGET, cond); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1894 | return result; |
| 1895 | } |
| 1896 | |
| 1897 | |
| 1898 | static int AddressOffset(ExternalReference ref0, ExternalReference ref1) { |
| 1899 | return ref0.address() - ref1.address(); |
| 1900 | } |
| 1901 | |
| 1902 | |
| 1903 | MaybeObject* MacroAssembler::TryCallApiFunctionAndReturn( |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 1904 | ExternalReference function, int stack_space) { |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1905 | ExternalReference next_address = |
| 1906 | ExternalReference::handle_scope_next_address(); |
| 1907 | const int kNextOffset = 0; |
| 1908 | const int kLimitOffset = AddressOffset( |
| 1909 | ExternalReference::handle_scope_limit_address(), |
| 1910 | next_address); |
| 1911 | const int kLevelOffset = AddressOffset( |
| 1912 | ExternalReference::handle_scope_level_address(), |
| 1913 | next_address); |
| 1914 | |
| 1915 | // Allocate HandleScope in callee-save registers. |
| 1916 | mov(r7, Operand(next_address)); |
| 1917 | ldr(r4, MemOperand(r7, kNextOffset)); |
| 1918 | ldr(r5, MemOperand(r7, kLimitOffset)); |
| 1919 | ldr(r6, MemOperand(r7, kLevelOffset)); |
| 1920 | add(r6, r6, Operand(1)); |
| 1921 | str(r6, MemOperand(r7, kLevelOffset)); |
| 1922 | |
| 1923 | // Native call returns to the DirectCEntry stub which redirects to the |
| 1924 | // return address pushed on stack (could have moved after GC). |
| 1925 | // DirectCEntry stub itself is generated early and never moves. |
| 1926 | DirectCEntryStub stub; |
| 1927 | stub.GenerateCall(this, function); |
| 1928 | |
| 1929 | Label promote_scheduled_exception; |
| 1930 | Label delete_allocated_handles; |
| 1931 | Label leave_exit_frame; |
| 1932 | |
| 1933 | // If result is non-zero, dereference to get the result value |
| 1934 | // otherwise set it to undefined. |
| 1935 | cmp(r0, Operand(0)); |
| 1936 | LoadRoot(r0, Heap::kUndefinedValueRootIndex, eq); |
| 1937 | ldr(r0, MemOperand(r0), ne); |
| 1938 | |
| 1939 | // No more valid handles (the result handle was the last one). Restore |
| 1940 | // previous handle scope. |
| 1941 | str(r4, MemOperand(r7, kNextOffset)); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1942 | if (emit_debug_code()) { |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1943 | ldr(r1, MemOperand(r7, kLevelOffset)); |
| 1944 | cmp(r1, r6); |
| 1945 | Check(eq, "Unexpected level after return from api call"); |
| 1946 | } |
| 1947 | sub(r6, r6, Operand(1)); |
| 1948 | str(r6, MemOperand(r7, kLevelOffset)); |
| 1949 | ldr(ip, MemOperand(r7, kLimitOffset)); |
| 1950 | cmp(r5, ip); |
| 1951 | b(ne, &delete_allocated_handles); |
| 1952 | |
| 1953 | // Check if the function scheduled an exception. |
| 1954 | bind(&leave_exit_frame); |
| 1955 | LoadRoot(r4, Heap::kTheHoleValueRootIndex); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1956 | mov(ip, Operand(ExternalReference::scheduled_exception_address(isolate()))); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1957 | ldr(r5, MemOperand(ip)); |
| 1958 | cmp(r4, r5); |
| 1959 | b(ne, &promote_scheduled_exception); |
| 1960 | |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 1961 | // LeaveExitFrame expects unwind space to be in a register. |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1962 | mov(r4, Operand(stack_space)); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 1963 | LeaveExitFrame(false, r4); |
| 1964 | mov(pc, lr); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1965 | |
| 1966 | bind(&promote_scheduled_exception); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1967 | MaybeObject* result |
| 1968 | = TryTailCallExternalReference( |
| 1969 | ExternalReference(Runtime::kPromoteScheduledException, isolate()), |
| 1970 | 0, |
| 1971 | 1); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1972 | if (result->IsFailure()) { |
| 1973 | return result; |
| 1974 | } |
| 1975 | |
| 1976 | // HandleScope limit has changed. Delete allocated extensions. |
| 1977 | bind(&delete_allocated_handles); |
| 1978 | str(r5, MemOperand(r7, kLimitOffset)); |
| 1979 | mov(r4, r0); |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 1980 | PrepareCallCFunction(1, r5); |
| 1981 | mov(r0, Operand(ExternalReference::isolate_address())); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1982 | CallCFunction( |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 1983 | ExternalReference::delete_handle_scope_extensions(isolate()), 1); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1984 | mov(r0, r4); |
| 1985 | jmp(&leave_exit_frame); |
| 1986 | |
| 1987 | return result; |
| 1988 | } |
| 1989 | |
| 1990 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1991 | void MacroAssembler::IllegalOperation(int num_arguments) { |
| 1992 | if (num_arguments > 0) { |
| 1993 | add(sp, sp, Operand(num_arguments * kPointerSize)); |
| 1994 | } |
| 1995 | LoadRoot(r0, Heap::kUndefinedValueRootIndex); |
| 1996 | } |
| 1997 | |
| 1998 | |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1999 | void MacroAssembler::IndexFromHash(Register hash, Register index) { |
| 2000 | // If the hash field contains an array index pick it out. The assert checks |
| 2001 | // that the constants for the maximum number of digits for an array index |
| 2002 | // cached in the hash field and the number of bits reserved for it does not |
| 2003 | // conflict. |
| 2004 | ASSERT(TenToThe(String::kMaxCachedArrayIndexLength) < |
| 2005 | (1 << String::kArrayIndexValueBits)); |
| 2006 | // We want the smi-tagged index in key. kArrayIndexValueMask has zeros in |
| 2007 | // the low kHashShift bits. |
| 2008 | STATIC_ASSERT(kSmiTag == 0); |
| 2009 | Ubfx(hash, hash, String::kHashShift, String::kArrayIndexValueBits); |
| 2010 | mov(index, Operand(hash, LSL, kSmiTagSize)); |
| 2011 | } |
| 2012 | |
| 2013 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 2014 | void MacroAssembler::IntegerToDoubleConversionWithVFP3(Register inReg, |
| 2015 | Register outHighReg, |
| 2016 | Register outLowReg) { |
| 2017 | // ARMv7 VFP3 instructions to implement integer to double conversion. |
| 2018 | mov(r7, Operand(inReg, ASR, kSmiTagSize)); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 2019 | vmov(s15, r7); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 2020 | vcvt_f64_s32(d7, s15); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 2021 | vmov(outLowReg, outHighReg, d7); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 2022 | } |
| 2023 | |
| 2024 | |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 2025 | void MacroAssembler::ObjectToDoubleVFPRegister(Register object, |
| 2026 | DwVfpRegister result, |
| 2027 | Register scratch1, |
| 2028 | Register scratch2, |
| 2029 | Register heap_number_map, |
| 2030 | SwVfpRegister scratch3, |
| 2031 | Label* not_number, |
| 2032 | ObjectToDoubleFlags flags) { |
| 2033 | Label done; |
| 2034 | if ((flags & OBJECT_NOT_SMI) == 0) { |
| 2035 | Label not_smi; |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2036 | JumpIfNotSmi(object, ¬_smi); |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 2037 | // Remove smi tag and convert to double. |
| 2038 | mov(scratch1, Operand(object, ASR, kSmiTagSize)); |
| 2039 | vmov(scratch3, scratch1); |
| 2040 | vcvt_f64_s32(result, scratch3); |
| 2041 | b(&done); |
| 2042 | bind(¬_smi); |
| 2043 | } |
| 2044 | // Check for heap number and load double value from it. |
| 2045 | ldr(scratch1, FieldMemOperand(object, HeapObject::kMapOffset)); |
| 2046 | sub(scratch2, object, Operand(kHeapObjectTag)); |
| 2047 | cmp(scratch1, heap_number_map); |
| 2048 | b(ne, not_number); |
| 2049 | if ((flags & AVOID_NANS_AND_INFINITIES) != 0) { |
| 2050 | // If exponent is all ones the number is either a NaN or +/-Infinity. |
| 2051 | ldr(scratch1, FieldMemOperand(object, HeapNumber::kExponentOffset)); |
| 2052 | Sbfx(scratch1, |
| 2053 | scratch1, |
| 2054 | HeapNumber::kExponentShift, |
| 2055 | HeapNumber::kExponentBits); |
| 2056 | // All-one value sign extend to -1. |
| 2057 | cmp(scratch1, Operand(-1)); |
| 2058 | b(eq, not_number); |
| 2059 | } |
| 2060 | vldr(result, scratch2, HeapNumber::kValueOffset); |
| 2061 | bind(&done); |
| 2062 | } |
| 2063 | |
| 2064 | |
| 2065 | void MacroAssembler::SmiToDoubleVFPRegister(Register smi, |
| 2066 | DwVfpRegister value, |
| 2067 | Register scratch1, |
| 2068 | SwVfpRegister scratch2) { |
| 2069 | mov(scratch1, Operand(smi, ASR, kSmiTagSize)); |
| 2070 | vmov(scratch2, scratch1); |
| 2071 | vcvt_f64_s32(value, scratch2); |
| 2072 | } |
| 2073 | |
| 2074 | |
Iain Merrick | 9ac36c9 | 2010-09-13 15:29:50 +0100 | [diff] [blame] | 2075 | // Tries to get a signed int32 out of a double precision floating point heap |
| 2076 | // number. Rounds towards 0. Branch to 'not_int32' if the double is out of the |
| 2077 | // 32bits signed integer range. |
| 2078 | void MacroAssembler::ConvertToInt32(Register source, |
| 2079 | Register dest, |
| 2080 | Register scratch, |
| 2081 | Register scratch2, |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2082 | DwVfpRegister double_scratch, |
Iain Merrick | 9ac36c9 | 2010-09-13 15:29:50 +0100 | [diff] [blame] | 2083 | Label *not_int32) { |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 2084 | if (CpuFeatures::IsSupported(VFP3)) { |
Iain Merrick | 9ac36c9 | 2010-09-13 15:29:50 +0100 | [diff] [blame] | 2085 | CpuFeatures::Scope scope(VFP3); |
| 2086 | sub(scratch, source, Operand(kHeapObjectTag)); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2087 | vldr(double_scratch, scratch, HeapNumber::kValueOffset); |
| 2088 | vcvt_s32_f64(double_scratch.low(), double_scratch); |
| 2089 | vmov(dest, double_scratch.low()); |
Iain Merrick | 9ac36c9 | 2010-09-13 15:29:50 +0100 | [diff] [blame] | 2090 | // Signed vcvt instruction will saturate to the minimum (0x80000000) or |
| 2091 | // maximun (0x7fffffff) signed 32bits integer when the double is out of |
| 2092 | // range. When substracting one, the minimum signed integer becomes the |
| 2093 | // maximun signed integer. |
| 2094 | sub(scratch, dest, Operand(1)); |
| 2095 | cmp(scratch, Operand(LONG_MAX - 1)); |
| 2096 | // If equal then dest was LONG_MAX, if greater dest was LONG_MIN. |
| 2097 | b(ge, not_int32); |
| 2098 | } else { |
| 2099 | // This code is faster for doubles that are in the ranges -0x7fffffff to |
| 2100 | // -0x40000000 or 0x40000000 to 0x7fffffff. This corresponds almost to |
| 2101 | // the range of signed int32 values that are not Smis. Jumps to the label |
| 2102 | // 'not_int32' if the double isn't in the range -0x80000000.0 to |
| 2103 | // 0x80000000.0 (excluding the endpoints). |
| 2104 | Label right_exponent, done; |
| 2105 | // Get exponent word. |
| 2106 | ldr(scratch, FieldMemOperand(source, HeapNumber::kExponentOffset)); |
| 2107 | // Get exponent alone in scratch2. |
| 2108 | Ubfx(scratch2, |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 2109 | scratch, |
| 2110 | HeapNumber::kExponentShift, |
| 2111 | HeapNumber::kExponentBits); |
Iain Merrick | 9ac36c9 | 2010-09-13 15:29:50 +0100 | [diff] [blame] | 2112 | // Load dest with zero. We use this either for the final shift or |
| 2113 | // for the answer. |
| 2114 | mov(dest, Operand(0, RelocInfo::NONE)); |
| 2115 | // Check whether the exponent matches a 32 bit signed int that is not a Smi. |
| 2116 | // A non-Smi integer is 1.xxx * 2^30 so the exponent is 30 (biased). This is |
| 2117 | // the exponent that we are fastest at and also the highest exponent we can |
| 2118 | // handle here. |
| 2119 | const uint32_t non_smi_exponent = HeapNumber::kExponentBias + 30; |
| 2120 | // The non_smi_exponent, 0x41d, is too big for ARM's immediate field so we |
| 2121 | // split it up to avoid a constant pool entry. You can't do that in general |
| 2122 | // for cmp because of the overflow flag, but we know the exponent is in the |
| 2123 | // range 0-2047 so there is no overflow. |
| 2124 | int fudge_factor = 0x400; |
| 2125 | sub(scratch2, scratch2, Operand(fudge_factor)); |
| 2126 | cmp(scratch2, Operand(non_smi_exponent - fudge_factor)); |
| 2127 | // If we have a match of the int32-but-not-Smi exponent then skip some |
| 2128 | // logic. |
| 2129 | b(eq, &right_exponent); |
| 2130 | // If the exponent is higher than that then go to slow case. This catches |
| 2131 | // numbers that don't fit in a signed int32, infinities and NaNs. |
| 2132 | b(gt, not_int32); |
| 2133 | |
| 2134 | // We know the exponent is smaller than 30 (biased). If it is less than |
| 2135 | // 0 (biased) then the number is smaller in magnitude than 1.0 * 2^0, ie |
| 2136 | // it rounds to zero. |
| 2137 | const uint32_t zero_exponent = HeapNumber::kExponentBias + 0; |
| 2138 | sub(scratch2, scratch2, Operand(zero_exponent - fudge_factor), SetCC); |
| 2139 | // Dest already has a Smi zero. |
| 2140 | b(lt, &done); |
| 2141 | |
| 2142 | // We have an exponent between 0 and 30 in scratch2. Subtract from 30 to |
| 2143 | // get how much to shift down. |
| 2144 | rsb(dest, scratch2, Operand(30)); |
| 2145 | |
| 2146 | bind(&right_exponent); |
| 2147 | // Get the top bits of the mantissa. |
| 2148 | and_(scratch2, scratch, Operand(HeapNumber::kMantissaMask)); |
| 2149 | // Put back the implicit 1. |
| 2150 | orr(scratch2, scratch2, Operand(1 << HeapNumber::kExponentShift)); |
| 2151 | // Shift up the mantissa bits to take up the space the exponent used to |
| 2152 | // take. We just orred in the implicit bit so that took care of one and |
| 2153 | // we want to leave the sign bit 0 so we subtract 2 bits from the shift |
| 2154 | // distance. |
| 2155 | const int shift_distance = HeapNumber::kNonMantissaBitsInTopWord - 2; |
| 2156 | mov(scratch2, Operand(scratch2, LSL, shift_distance)); |
| 2157 | // Put sign in zero flag. |
| 2158 | tst(scratch, Operand(HeapNumber::kSignMask)); |
| 2159 | // Get the second half of the double. For some exponents we don't |
| 2160 | // actually need this because the bits get shifted out again, but |
| 2161 | // it's probably slower to test than just to do it. |
| 2162 | ldr(scratch, FieldMemOperand(source, HeapNumber::kMantissaOffset)); |
| 2163 | // Shift down 22 bits to get the last 10 bits. |
| 2164 | orr(scratch, scratch2, Operand(scratch, LSR, 32 - shift_distance)); |
| 2165 | // Move down according to the exponent. |
| 2166 | mov(dest, Operand(scratch, LSR, dest)); |
| 2167 | // Fix sign if sign bit was set. |
| 2168 | rsb(dest, dest, Operand(0, RelocInfo::NONE), LeaveCC, ne); |
| 2169 | bind(&done); |
| 2170 | } |
| 2171 | } |
| 2172 | |
| 2173 | |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 2174 | void MacroAssembler::EmitVFPTruncate(VFPRoundingMode rounding_mode, |
| 2175 | SwVfpRegister result, |
| 2176 | DwVfpRegister double_input, |
| 2177 | Register scratch1, |
| 2178 | Register scratch2, |
| 2179 | CheckForInexactConversion check_inexact) { |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 2180 | ASSERT(CpuFeatures::IsSupported(VFP3)); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 2181 | CpuFeatures::Scope scope(VFP3); |
| 2182 | Register prev_fpscr = scratch1; |
| 2183 | Register scratch = scratch2; |
| 2184 | |
| 2185 | int32_t check_inexact_conversion = |
| 2186 | (check_inexact == kCheckForInexactConversion) ? kVFPInexactExceptionBit : 0; |
| 2187 | |
| 2188 | // Set custom FPCSR: |
| 2189 | // - Set rounding mode. |
| 2190 | // - Clear vfp cumulative exception flags. |
| 2191 | // - Make sure Flush-to-zero mode control bit is unset. |
| 2192 | vmrs(prev_fpscr); |
| 2193 | bic(scratch, |
| 2194 | prev_fpscr, |
| 2195 | Operand(kVFPExceptionMask | |
| 2196 | check_inexact_conversion | |
| 2197 | kVFPRoundingModeMask | |
| 2198 | kVFPFlushToZeroMask)); |
| 2199 | // 'Round To Nearest' is encoded by 0b00 so no bits need to be set. |
| 2200 | if (rounding_mode != kRoundToNearest) { |
| 2201 | orr(scratch, scratch, Operand(rounding_mode)); |
| 2202 | } |
| 2203 | vmsr(scratch); |
| 2204 | |
| 2205 | // Convert the argument to an integer. |
| 2206 | vcvt_s32_f64(result, |
| 2207 | double_input, |
| 2208 | (rounding_mode == kRoundToZero) ? kDefaultRoundToZero |
| 2209 | : kFPSCRRounding); |
| 2210 | |
| 2211 | // Retrieve FPSCR. |
| 2212 | vmrs(scratch); |
| 2213 | // Restore FPSCR. |
| 2214 | vmsr(prev_fpscr); |
| 2215 | // Check for vfp exceptions. |
| 2216 | tst(scratch, Operand(kVFPExceptionMask | check_inexact_conversion)); |
| 2217 | } |
| 2218 | |
| 2219 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2220 | void MacroAssembler::EmitOutOfInt32RangeTruncate(Register result, |
| 2221 | Register input_high, |
| 2222 | Register input_low, |
| 2223 | Register scratch) { |
| 2224 | Label done, normal_exponent, restore_sign; |
| 2225 | |
| 2226 | // Extract the biased exponent in result. |
| 2227 | Ubfx(result, |
| 2228 | input_high, |
| 2229 | HeapNumber::kExponentShift, |
| 2230 | HeapNumber::kExponentBits); |
| 2231 | |
| 2232 | // Check for Infinity and NaNs, which should return 0. |
| 2233 | cmp(result, Operand(HeapNumber::kExponentMask)); |
| 2234 | mov(result, Operand(0), LeaveCC, eq); |
| 2235 | b(eq, &done); |
| 2236 | |
| 2237 | // Express exponent as delta to (number of mantissa bits + 31). |
| 2238 | sub(result, |
| 2239 | result, |
| 2240 | Operand(HeapNumber::kExponentBias + HeapNumber::kMantissaBits + 31), |
| 2241 | SetCC); |
| 2242 | |
| 2243 | // If the delta is strictly positive, all bits would be shifted away, |
| 2244 | // which means that we can return 0. |
| 2245 | b(le, &normal_exponent); |
| 2246 | mov(result, Operand(0)); |
| 2247 | b(&done); |
| 2248 | |
| 2249 | bind(&normal_exponent); |
| 2250 | const int kShiftBase = HeapNumber::kNonMantissaBitsInTopWord - 1; |
| 2251 | // Calculate shift. |
| 2252 | add(scratch, result, Operand(kShiftBase + HeapNumber::kMantissaBits), SetCC); |
| 2253 | |
| 2254 | // Save the sign. |
| 2255 | Register sign = result; |
| 2256 | result = no_reg; |
| 2257 | and_(sign, input_high, Operand(HeapNumber::kSignMask)); |
| 2258 | |
| 2259 | // Set the implicit 1 before the mantissa part in input_high. |
| 2260 | orr(input_high, |
| 2261 | input_high, |
| 2262 | Operand(1 << HeapNumber::kMantissaBitsInTopWord)); |
| 2263 | // Shift the mantissa bits to the correct position. |
| 2264 | // We don't need to clear non-mantissa bits as they will be shifted away. |
| 2265 | // If they weren't, it would mean that the answer is in the 32bit range. |
| 2266 | mov(input_high, Operand(input_high, LSL, scratch)); |
| 2267 | |
| 2268 | // Replace the shifted bits with bits from the lower mantissa word. |
| 2269 | Label pos_shift, shift_done; |
| 2270 | rsb(scratch, scratch, Operand(32), SetCC); |
| 2271 | b(&pos_shift, ge); |
| 2272 | |
| 2273 | // Negate scratch. |
| 2274 | rsb(scratch, scratch, Operand(0)); |
| 2275 | mov(input_low, Operand(input_low, LSL, scratch)); |
| 2276 | b(&shift_done); |
| 2277 | |
| 2278 | bind(&pos_shift); |
| 2279 | mov(input_low, Operand(input_low, LSR, scratch)); |
| 2280 | |
| 2281 | bind(&shift_done); |
| 2282 | orr(input_high, input_high, Operand(input_low)); |
| 2283 | // Restore sign if necessary. |
| 2284 | cmp(sign, Operand(0)); |
| 2285 | result = sign; |
| 2286 | sign = no_reg; |
| 2287 | rsb(result, input_high, Operand(0), LeaveCC, ne); |
| 2288 | mov(result, input_high, LeaveCC, eq); |
| 2289 | bind(&done); |
| 2290 | } |
| 2291 | |
| 2292 | |
| 2293 | void MacroAssembler::EmitECMATruncate(Register result, |
| 2294 | DwVfpRegister double_input, |
| 2295 | SwVfpRegister single_scratch, |
| 2296 | Register scratch, |
| 2297 | Register input_high, |
| 2298 | Register input_low) { |
| 2299 | CpuFeatures::Scope scope(VFP3); |
| 2300 | ASSERT(!input_high.is(result)); |
| 2301 | ASSERT(!input_low.is(result)); |
| 2302 | ASSERT(!input_low.is(input_high)); |
| 2303 | ASSERT(!scratch.is(result) && |
| 2304 | !scratch.is(input_high) && |
| 2305 | !scratch.is(input_low)); |
| 2306 | ASSERT(!single_scratch.is(double_input.low()) && |
| 2307 | !single_scratch.is(double_input.high())); |
| 2308 | |
| 2309 | Label done; |
| 2310 | |
| 2311 | // Clear cumulative exception flags. |
| 2312 | ClearFPSCRBits(kVFPExceptionMask, scratch); |
| 2313 | // Try a conversion to a signed integer. |
| 2314 | vcvt_s32_f64(single_scratch, double_input); |
| 2315 | vmov(result, single_scratch); |
| 2316 | // Retrieve he FPSCR. |
| 2317 | vmrs(scratch); |
| 2318 | // Check for overflow and NaNs. |
| 2319 | tst(scratch, Operand(kVFPOverflowExceptionBit | |
| 2320 | kVFPUnderflowExceptionBit | |
| 2321 | kVFPInvalidOpExceptionBit)); |
| 2322 | // If we had no exceptions we are done. |
| 2323 | b(eq, &done); |
| 2324 | |
| 2325 | // Load the double value and perform a manual truncation. |
| 2326 | vmov(input_low, input_high, double_input); |
| 2327 | EmitOutOfInt32RangeTruncate(result, |
| 2328 | input_high, |
| 2329 | input_low, |
| 2330 | scratch); |
| 2331 | bind(&done); |
| 2332 | } |
| 2333 | |
| 2334 | |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 2335 | void MacroAssembler::GetLeastBitsFromSmi(Register dst, |
| 2336 | Register src, |
| 2337 | int num_least_bits) { |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 2338 | if (CpuFeatures::IsSupported(ARMv7)) { |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 2339 | ubfx(dst, src, kSmiTagSize, num_least_bits); |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 2340 | } else { |
| 2341 | mov(dst, Operand(src, ASR, kSmiTagSize)); |
| 2342 | and_(dst, dst, Operand((1 << num_least_bits) - 1)); |
| 2343 | } |
| 2344 | } |
| 2345 | |
| 2346 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2347 | void MacroAssembler::GetLeastBitsFromInt32(Register dst, |
| 2348 | Register src, |
| 2349 | int num_least_bits) { |
| 2350 | and_(dst, src, Operand((1 << num_least_bits) - 1)); |
| 2351 | } |
| 2352 | |
| 2353 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2354 | void MacroAssembler::CallRuntime(const Runtime::Function* f, |
| 2355 | int num_arguments) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2356 | // All parameters are on the stack. r0 has the return value after call. |
| 2357 | |
| 2358 | // If the expected number of arguments of the runtime function is |
| 2359 | // constant, we check that the actual number of arguments match the |
| 2360 | // expectation. |
| 2361 | if (f->nargs >= 0 && f->nargs != num_arguments) { |
| 2362 | IllegalOperation(num_arguments); |
| 2363 | return; |
| 2364 | } |
| 2365 | |
Leon Clarke | 4515c47 | 2010-02-03 11:58:03 +0000 | [diff] [blame] | 2366 | // TODO(1236192): Most runtime routines don't need the number of |
| 2367 | // arguments passed in because it is constant. At some point we |
| 2368 | // should remove this need and make the runtime routine entry code |
| 2369 | // smarter. |
| 2370 | mov(r0, Operand(num_arguments)); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2371 | mov(r1, Operand(ExternalReference(f, isolate()))); |
Leon Clarke | 4515c47 | 2010-02-03 11:58:03 +0000 | [diff] [blame] | 2372 | CEntryStub stub(1); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2373 | CallStub(&stub); |
| 2374 | } |
| 2375 | |
| 2376 | |
| 2377 | void MacroAssembler::CallRuntime(Runtime::FunctionId fid, int num_arguments) { |
| 2378 | CallRuntime(Runtime::FunctionForId(fid), num_arguments); |
| 2379 | } |
| 2380 | |
| 2381 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 2382 | void MacroAssembler::CallRuntimeSaveDoubles(Runtime::FunctionId id) { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2383 | const Runtime::Function* function = Runtime::FunctionForId(id); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 2384 | mov(r0, Operand(function->nargs)); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2385 | mov(r1, Operand(ExternalReference(function, isolate()))); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 2386 | CEntryStub stub(1); |
| 2387 | stub.SaveDoubles(); |
| 2388 | CallStub(&stub); |
| 2389 | } |
| 2390 | |
| 2391 | |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 2392 | void MacroAssembler::CallExternalReference(const ExternalReference& ext, |
| 2393 | int num_arguments) { |
| 2394 | mov(r0, Operand(num_arguments)); |
| 2395 | mov(r1, Operand(ext)); |
| 2396 | |
| 2397 | CEntryStub stub(1); |
| 2398 | CallStub(&stub); |
| 2399 | } |
| 2400 | |
| 2401 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 2402 | void MacroAssembler::TailCallExternalReference(const ExternalReference& ext, |
| 2403 | int num_arguments, |
| 2404 | int result_size) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2405 | // TODO(1236192): Most runtime routines don't need the number of |
| 2406 | // arguments passed in because it is constant. At some point we |
| 2407 | // should remove this need and make the runtime routine entry code |
| 2408 | // smarter. |
| 2409 | mov(r0, Operand(num_arguments)); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 2410 | JumpToExternalReference(ext); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2411 | } |
| 2412 | |
| 2413 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2414 | MaybeObject* MacroAssembler::TryTailCallExternalReference( |
| 2415 | const ExternalReference& ext, int num_arguments, int result_size) { |
| 2416 | // TODO(1236192): Most runtime routines don't need the number of |
| 2417 | // arguments passed in because it is constant. At some point we |
| 2418 | // should remove this need and make the runtime routine entry code |
| 2419 | // smarter. |
| 2420 | mov(r0, Operand(num_arguments)); |
| 2421 | return TryJumpToExternalReference(ext); |
| 2422 | } |
| 2423 | |
| 2424 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 2425 | void MacroAssembler::TailCallRuntime(Runtime::FunctionId fid, |
| 2426 | int num_arguments, |
| 2427 | int result_size) { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2428 | TailCallExternalReference(ExternalReference(fid, isolate()), |
| 2429 | num_arguments, |
| 2430 | result_size); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 2431 | } |
| 2432 | |
| 2433 | |
| 2434 | void MacroAssembler::JumpToExternalReference(const ExternalReference& builtin) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2435 | #if defined(__thumb__) |
| 2436 | // Thumb mode builtin. |
| 2437 | ASSERT((reinterpret_cast<intptr_t>(builtin.address()) & 1) == 1); |
| 2438 | #endif |
| 2439 | mov(r1, Operand(builtin)); |
| 2440 | CEntryStub stub(1); |
| 2441 | Jump(stub.GetCode(), RelocInfo::CODE_TARGET); |
| 2442 | } |
| 2443 | |
| 2444 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2445 | MaybeObject* MacroAssembler::TryJumpToExternalReference( |
| 2446 | const ExternalReference& builtin) { |
| 2447 | #if defined(__thumb__) |
| 2448 | // Thumb mode builtin. |
| 2449 | ASSERT((reinterpret_cast<intptr_t>(builtin.address()) & 1) == 1); |
| 2450 | #endif |
| 2451 | mov(r1, Operand(builtin)); |
| 2452 | CEntryStub stub(1); |
| 2453 | return TryTailCallStub(&stub); |
| 2454 | } |
| 2455 | |
| 2456 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2457 | void MacroAssembler::InvokeBuiltin(Builtins::JavaScript id, |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2458 | InvokeFlag flag, |
| 2459 | const CallWrapper& call_wrapper) { |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 2460 | GetBuiltinEntry(r2, id); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2461 | if (flag == CALL_FUNCTION) { |
| 2462 | call_wrapper.BeforeCall(CallSize(r2)); |
| 2463 | SetCallKind(r5, CALL_AS_METHOD); |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 2464 | Call(r2); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2465 | call_wrapper.AfterCall(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2466 | } else { |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2467 | ASSERT(flag == JUMP_FUNCTION); |
| 2468 | SetCallKind(r5, CALL_AS_METHOD); |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 2469 | Jump(r2); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2470 | } |
| 2471 | } |
| 2472 | |
| 2473 | |
Steve Block | 791712a | 2010-08-27 10:21:07 +0100 | [diff] [blame] | 2474 | void MacroAssembler::GetBuiltinFunction(Register target, |
| 2475 | Builtins::JavaScript id) { |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 2476 | // Load the builtins object into target register. |
| 2477 | ldr(target, MemOperand(cp, Context::SlotOffset(Context::GLOBAL_INDEX))); |
| 2478 | ldr(target, FieldMemOperand(target, GlobalObject::kBuiltinsOffset)); |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 2479 | // Load the JavaScript builtin function from the builtins object. |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 2480 | ldr(target, FieldMemOperand(target, |
Steve Block | 791712a | 2010-08-27 10:21:07 +0100 | [diff] [blame] | 2481 | JSBuiltinsObject::OffsetOfFunctionWithId(id))); |
| 2482 | } |
| 2483 | |
| 2484 | |
| 2485 | void MacroAssembler::GetBuiltinEntry(Register target, Builtins::JavaScript id) { |
| 2486 | ASSERT(!target.is(r1)); |
| 2487 | GetBuiltinFunction(r1, id); |
| 2488 | // Load the code entry point from the builtins object. |
| 2489 | ldr(target, FieldMemOperand(r1, JSFunction::kCodeEntryOffset)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2490 | } |
| 2491 | |
| 2492 | |
| 2493 | void MacroAssembler::SetCounter(StatsCounter* counter, int value, |
| 2494 | Register scratch1, Register scratch2) { |
| 2495 | if (FLAG_native_code_counters && counter->Enabled()) { |
| 2496 | mov(scratch1, Operand(value)); |
| 2497 | mov(scratch2, Operand(ExternalReference(counter))); |
| 2498 | str(scratch1, MemOperand(scratch2)); |
| 2499 | } |
| 2500 | } |
| 2501 | |
| 2502 | |
| 2503 | void MacroAssembler::IncrementCounter(StatsCounter* counter, int value, |
| 2504 | Register scratch1, Register scratch2) { |
| 2505 | ASSERT(value > 0); |
| 2506 | if (FLAG_native_code_counters && counter->Enabled()) { |
| 2507 | mov(scratch2, Operand(ExternalReference(counter))); |
| 2508 | ldr(scratch1, MemOperand(scratch2)); |
| 2509 | add(scratch1, scratch1, Operand(value)); |
| 2510 | str(scratch1, MemOperand(scratch2)); |
| 2511 | } |
| 2512 | } |
| 2513 | |
| 2514 | |
| 2515 | void MacroAssembler::DecrementCounter(StatsCounter* counter, int value, |
| 2516 | Register scratch1, Register scratch2) { |
| 2517 | ASSERT(value > 0); |
| 2518 | if (FLAG_native_code_counters && counter->Enabled()) { |
| 2519 | mov(scratch2, Operand(ExternalReference(counter))); |
| 2520 | ldr(scratch1, MemOperand(scratch2)); |
| 2521 | sub(scratch1, scratch1, Operand(value)); |
| 2522 | str(scratch1, MemOperand(scratch2)); |
| 2523 | } |
| 2524 | } |
| 2525 | |
| 2526 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2527 | void MacroAssembler::Assert(Condition cond, const char* msg) { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2528 | if (emit_debug_code()) |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2529 | Check(cond, msg); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2530 | } |
| 2531 | |
| 2532 | |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 2533 | void MacroAssembler::AssertRegisterIsRoot(Register reg, |
| 2534 | Heap::RootListIndex index) { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2535 | if (emit_debug_code()) { |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 2536 | LoadRoot(ip, index); |
| 2537 | cmp(reg, ip); |
| 2538 | Check(eq, "Register did not match expected root"); |
| 2539 | } |
| 2540 | } |
| 2541 | |
| 2542 | |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 2543 | void MacroAssembler::AssertFastElements(Register elements) { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2544 | if (emit_debug_code()) { |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 2545 | ASSERT(!elements.is(ip)); |
| 2546 | Label ok; |
| 2547 | push(elements); |
| 2548 | ldr(elements, FieldMemOperand(elements, HeapObject::kMapOffset)); |
| 2549 | LoadRoot(ip, Heap::kFixedArrayMapRootIndex); |
| 2550 | cmp(elements, ip); |
| 2551 | b(eq, &ok); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame^] | 2552 | LoadRoot(ip, Heap::kFixedDoubleArrayMapRootIndex); |
| 2553 | cmp(elements, ip); |
| 2554 | b(eq, &ok); |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 2555 | LoadRoot(ip, Heap::kFixedCOWArrayMapRootIndex); |
| 2556 | cmp(elements, ip); |
| 2557 | b(eq, &ok); |
| 2558 | Abort("JSObject with fast elements map has slow elements"); |
| 2559 | bind(&ok); |
| 2560 | pop(elements); |
| 2561 | } |
| 2562 | } |
| 2563 | |
| 2564 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2565 | void MacroAssembler::Check(Condition cond, const char* msg) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2566 | Label L; |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2567 | b(cond, &L); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2568 | Abort(msg); |
| 2569 | // will not return here |
| 2570 | bind(&L); |
| 2571 | } |
| 2572 | |
| 2573 | |
| 2574 | void MacroAssembler::Abort(const char* msg) { |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 2575 | Label abort_start; |
| 2576 | bind(&abort_start); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2577 | // We want to pass the msg string like a smi to avoid GC |
| 2578 | // problems, however msg is not guaranteed to be aligned |
| 2579 | // properly. Instead, we pass an aligned pointer that is |
| 2580 | // a proper v8 smi, but also pass the alignment difference |
| 2581 | // from the real pointer as a smi. |
| 2582 | intptr_t p1 = reinterpret_cast<intptr_t>(msg); |
| 2583 | intptr_t p0 = (p1 & ~kSmiTagMask) + kSmiTag; |
| 2584 | ASSERT(reinterpret_cast<Object*>(p0)->IsSmi()); |
| 2585 | #ifdef DEBUG |
| 2586 | if (msg != NULL) { |
| 2587 | RecordComment("Abort message: "); |
| 2588 | RecordComment(msg); |
| 2589 | } |
| 2590 | #endif |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 2591 | // Disable stub call restrictions to always allow calls to abort. |
Ben Murdoch | 086aeea | 2011-05-13 15:57:08 +0100 | [diff] [blame] | 2592 | AllowStubCallsScope allow_scope(this, true); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 2593 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2594 | mov(r0, Operand(p0)); |
| 2595 | push(r0); |
| 2596 | mov(r0, Operand(Smi::FromInt(p1 - p0))); |
| 2597 | push(r0); |
| 2598 | CallRuntime(Runtime::kAbort, 2); |
| 2599 | // will not return here |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 2600 | if (is_const_pool_blocked()) { |
| 2601 | // If the calling code cares about the exact number of |
| 2602 | // instructions generated, we insert padding here to keep the size |
| 2603 | // of the Abort macro constant. |
| 2604 | static const int kExpectedAbortInstructions = 10; |
| 2605 | int abort_instructions = InstructionsGeneratedSince(&abort_start); |
| 2606 | ASSERT(abort_instructions <= kExpectedAbortInstructions); |
| 2607 | while (abort_instructions++ < kExpectedAbortInstructions) { |
| 2608 | nop(); |
| 2609 | } |
| 2610 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2611 | } |
| 2612 | |
| 2613 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 2614 | void MacroAssembler::LoadContext(Register dst, int context_chain_length) { |
| 2615 | if (context_chain_length > 0) { |
| 2616 | // Move up the chain of contexts to the context containing the slot. |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame^] | 2617 | ldr(dst, MemOperand(cp, Context::SlotOffset(Context::PREVIOUS_INDEX))); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 2618 | for (int i = 1; i < context_chain_length; i++) { |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame^] | 2619 | ldr(dst, MemOperand(dst, Context::SlotOffset(Context::PREVIOUS_INDEX))); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 2620 | } |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 2621 | } else { |
| 2622 | // Slot is in the current function context. Move it into the |
| 2623 | // destination register in case we store into it (the write barrier |
| 2624 | // cannot be allowed to destroy the context in esi). |
| 2625 | mov(dst, cp); |
| 2626 | } |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 2627 | } |
| 2628 | |
| 2629 | |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 2630 | void MacroAssembler::LoadGlobalFunction(int index, Register function) { |
| 2631 | // Load the global or builtins object from the current context. |
| 2632 | ldr(function, MemOperand(cp, Context::SlotOffset(Context::GLOBAL_INDEX))); |
| 2633 | // Load the global context from the global or builtins object. |
| 2634 | ldr(function, FieldMemOperand(function, |
| 2635 | GlobalObject::kGlobalContextOffset)); |
| 2636 | // Load the function from the global context. |
| 2637 | ldr(function, MemOperand(function, Context::SlotOffset(index))); |
| 2638 | } |
| 2639 | |
| 2640 | |
| 2641 | void MacroAssembler::LoadGlobalFunctionInitialMap(Register function, |
| 2642 | Register map, |
| 2643 | Register scratch) { |
| 2644 | // Load the initial map. The global functions all have initial maps. |
| 2645 | ldr(map, FieldMemOperand(function, JSFunction::kPrototypeOrInitialMapOffset)); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2646 | if (emit_debug_code()) { |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 2647 | Label ok, fail; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2648 | CheckMap(map, scratch, Heap::kMetaMapRootIndex, &fail, DO_SMI_CHECK); |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 2649 | b(&ok); |
| 2650 | bind(&fail); |
| 2651 | Abort("Global functions must have initial map"); |
| 2652 | bind(&ok); |
| 2653 | } |
| 2654 | } |
| 2655 | |
| 2656 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2657 | void MacroAssembler::JumpIfNotPowerOfTwoOrZero( |
| 2658 | Register reg, |
| 2659 | Register scratch, |
| 2660 | Label* not_power_of_two_or_zero) { |
| 2661 | sub(scratch, reg, Operand(1), SetCC); |
| 2662 | b(mi, not_power_of_two_or_zero); |
| 2663 | tst(scratch, reg); |
| 2664 | b(ne, not_power_of_two_or_zero); |
| 2665 | } |
| 2666 | |
| 2667 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2668 | void MacroAssembler::JumpIfNotPowerOfTwoOrZeroAndNeg( |
| 2669 | Register reg, |
| 2670 | Register scratch, |
| 2671 | Label* zero_and_neg, |
| 2672 | Label* not_power_of_two) { |
| 2673 | sub(scratch, reg, Operand(1), SetCC); |
| 2674 | b(mi, zero_and_neg); |
| 2675 | tst(scratch, reg); |
| 2676 | b(ne, not_power_of_two); |
| 2677 | } |
| 2678 | |
| 2679 | |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 2680 | void MacroAssembler::JumpIfNotBothSmi(Register reg1, |
| 2681 | Register reg2, |
| 2682 | Label* on_not_both_smi) { |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2683 | STATIC_ASSERT(kSmiTag == 0); |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 2684 | tst(reg1, Operand(kSmiTagMask)); |
| 2685 | tst(reg2, Operand(kSmiTagMask), eq); |
| 2686 | b(ne, on_not_both_smi); |
| 2687 | } |
| 2688 | |
| 2689 | |
| 2690 | void MacroAssembler::JumpIfEitherSmi(Register reg1, |
| 2691 | Register reg2, |
| 2692 | Label* on_either_smi) { |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2693 | STATIC_ASSERT(kSmiTag == 0); |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 2694 | tst(reg1, Operand(kSmiTagMask)); |
| 2695 | tst(reg2, Operand(kSmiTagMask), ne); |
| 2696 | b(eq, on_either_smi); |
| 2697 | } |
| 2698 | |
| 2699 | |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 2700 | void MacroAssembler::AbortIfSmi(Register object) { |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2701 | STATIC_ASSERT(kSmiTag == 0); |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 2702 | tst(object, Operand(kSmiTagMask)); |
| 2703 | Assert(ne, "Operand is a smi"); |
| 2704 | } |
| 2705 | |
| 2706 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2707 | void MacroAssembler::AbortIfNotSmi(Register object) { |
| 2708 | STATIC_ASSERT(kSmiTag == 0); |
| 2709 | tst(object, Operand(kSmiTagMask)); |
| 2710 | Assert(eq, "Operand is not smi"); |
| 2711 | } |
| 2712 | |
| 2713 | |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 2714 | void MacroAssembler::AbortIfNotString(Register object) { |
| 2715 | STATIC_ASSERT(kSmiTag == 0); |
| 2716 | tst(object, Operand(kSmiTagMask)); |
| 2717 | Assert(ne, "Operand is not a string"); |
| 2718 | push(object); |
| 2719 | ldr(object, FieldMemOperand(object, HeapObject::kMapOffset)); |
| 2720 | CompareInstanceType(object, object, FIRST_NONSTRING_TYPE); |
| 2721 | pop(object); |
| 2722 | Assert(lo, "Operand is not a string"); |
| 2723 | } |
| 2724 | |
| 2725 | |
| 2726 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2727 | void MacroAssembler::AbortIfNotRootValue(Register src, |
| 2728 | Heap::RootListIndex root_value_index, |
| 2729 | const char* message) { |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 2730 | CompareRoot(src, root_value_index); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2731 | Assert(eq, message); |
| 2732 | } |
| 2733 | |
| 2734 | |
| 2735 | void MacroAssembler::JumpIfNotHeapNumber(Register object, |
| 2736 | Register heap_number_map, |
| 2737 | Register scratch, |
| 2738 | Label* on_not_heap_number) { |
| 2739 | ldr(scratch, FieldMemOperand(object, HeapObject::kMapOffset)); |
| 2740 | AssertRegisterIsRoot(heap_number_map, Heap::kHeapNumberMapRootIndex); |
| 2741 | cmp(scratch, heap_number_map); |
| 2742 | b(ne, on_not_heap_number); |
| 2743 | } |
| 2744 | |
| 2745 | |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 2746 | void MacroAssembler::JumpIfNonSmisNotBothSequentialAsciiStrings( |
| 2747 | Register first, |
| 2748 | Register second, |
| 2749 | Register scratch1, |
| 2750 | Register scratch2, |
| 2751 | Label* failure) { |
| 2752 | // Test that both first and second are sequential ASCII strings. |
| 2753 | // Assume that they are non-smis. |
| 2754 | ldr(scratch1, FieldMemOperand(first, HeapObject::kMapOffset)); |
| 2755 | ldr(scratch2, FieldMemOperand(second, HeapObject::kMapOffset)); |
| 2756 | ldrb(scratch1, FieldMemOperand(scratch1, Map::kInstanceTypeOffset)); |
| 2757 | ldrb(scratch2, FieldMemOperand(scratch2, Map::kInstanceTypeOffset)); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 2758 | |
| 2759 | JumpIfBothInstanceTypesAreNotSequentialAscii(scratch1, |
| 2760 | scratch2, |
| 2761 | scratch1, |
| 2762 | scratch2, |
| 2763 | failure); |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 2764 | } |
| 2765 | |
| 2766 | void MacroAssembler::JumpIfNotBothSequentialAsciiStrings(Register first, |
| 2767 | Register second, |
| 2768 | Register scratch1, |
| 2769 | Register scratch2, |
| 2770 | Label* failure) { |
| 2771 | // Check that neither is a smi. |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2772 | STATIC_ASSERT(kSmiTag == 0); |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 2773 | and_(scratch1, first, Operand(second)); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame^] | 2774 | JumpIfSmi(scratch1, failure); |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 2775 | JumpIfNonSmisNotBothSequentialAsciiStrings(first, |
| 2776 | second, |
| 2777 | scratch1, |
| 2778 | scratch2, |
| 2779 | failure); |
| 2780 | } |
| 2781 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 2782 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 2783 | // Allocates a heap number or jumps to the need_gc label if the young space |
| 2784 | // is full and a scavenge is needed. |
| 2785 | void MacroAssembler::AllocateHeapNumber(Register result, |
| 2786 | Register scratch1, |
| 2787 | Register scratch2, |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 2788 | Register heap_number_map, |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 2789 | Label* gc_required) { |
| 2790 | // Allocate an object in the heap for the heap number and tag it as a heap |
| 2791 | // object. |
Kristian Monsen | 25f6136 | 2010-05-21 11:50:48 +0100 | [diff] [blame] | 2792 | AllocateInNewSpace(HeapNumber::kSize, |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 2793 | result, |
| 2794 | scratch1, |
| 2795 | scratch2, |
| 2796 | gc_required, |
| 2797 | TAG_OBJECT); |
| 2798 | |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 2799 | // Store heap number map in the allocated object. |
| 2800 | AssertRegisterIsRoot(heap_number_map, Heap::kHeapNumberMapRootIndex); |
| 2801 | str(heap_number_map, FieldMemOperand(result, HeapObject::kMapOffset)); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 2802 | } |
| 2803 | |
| 2804 | |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 2805 | void MacroAssembler::AllocateHeapNumberWithValue(Register result, |
| 2806 | DwVfpRegister value, |
| 2807 | Register scratch1, |
| 2808 | Register scratch2, |
| 2809 | Register heap_number_map, |
| 2810 | Label* gc_required) { |
| 2811 | AllocateHeapNumber(result, scratch1, scratch2, heap_number_map, gc_required); |
| 2812 | sub(scratch1, result, Operand(kHeapObjectTag)); |
| 2813 | vstr(value, scratch1, HeapNumber::kValueOffset); |
| 2814 | } |
| 2815 | |
| 2816 | |
Ben Murdoch | bb769b2 | 2010-08-11 14:56:33 +0100 | [diff] [blame] | 2817 | // Copies a fixed number of fields of heap objects from src to dst. |
| 2818 | void MacroAssembler::CopyFields(Register dst, |
| 2819 | Register src, |
| 2820 | RegList temps, |
| 2821 | int field_count) { |
| 2822 | // At least one bit set in the first 15 registers. |
| 2823 | ASSERT((temps & ((1 << 15) - 1)) != 0); |
| 2824 | ASSERT((temps & dst.bit()) == 0); |
| 2825 | ASSERT((temps & src.bit()) == 0); |
| 2826 | // Primitive implementation using only one temporary register. |
| 2827 | |
| 2828 | Register tmp = no_reg; |
| 2829 | // Find a temp register in temps list. |
| 2830 | for (int i = 0; i < 15; i++) { |
| 2831 | if ((temps & (1 << i)) != 0) { |
| 2832 | tmp.set_code(i); |
| 2833 | break; |
| 2834 | } |
| 2835 | } |
| 2836 | ASSERT(!tmp.is(no_reg)); |
| 2837 | |
| 2838 | for (int i = 0; i < field_count; i++) { |
| 2839 | ldr(tmp, FieldMemOperand(src, i * kPointerSize)); |
| 2840 | str(tmp, FieldMemOperand(dst, i * kPointerSize)); |
| 2841 | } |
| 2842 | } |
| 2843 | |
| 2844 | |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 2845 | void MacroAssembler::CopyBytes(Register src, |
| 2846 | Register dst, |
| 2847 | Register length, |
| 2848 | Register scratch) { |
| 2849 | Label align_loop, align_loop_1, word_loop, byte_loop, byte_loop_1, done; |
| 2850 | |
| 2851 | // Align src before copying in word size chunks. |
| 2852 | bind(&align_loop); |
| 2853 | cmp(length, Operand(0)); |
| 2854 | b(eq, &done); |
| 2855 | bind(&align_loop_1); |
| 2856 | tst(src, Operand(kPointerSize - 1)); |
| 2857 | b(eq, &word_loop); |
| 2858 | ldrb(scratch, MemOperand(src, 1, PostIndex)); |
| 2859 | strb(scratch, MemOperand(dst, 1, PostIndex)); |
| 2860 | sub(length, length, Operand(1), SetCC); |
| 2861 | b(ne, &byte_loop_1); |
| 2862 | |
| 2863 | // Copy bytes in word size chunks. |
| 2864 | bind(&word_loop); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2865 | if (emit_debug_code()) { |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 2866 | tst(src, Operand(kPointerSize - 1)); |
| 2867 | Assert(eq, "Expecting alignment for CopyBytes"); |
| 2868 | } |
| 2869 | cmp(length, Operand(kPointerSize)); |
| 2870 | b(lt, &byte_loop); |
| 2871 | ldr(scratch, MemOperand(src, kPointerSize, PostIndex)); |
| 2872 | #if CAN_USE_UNALIGNED_ACCESSES |
| 2873 | str(scratch, MemOperand(dst, kPointerSize, PostIndex)); |
| 2874 | #else |
| 2875 | strb(scratch, MemOperand(dst, 1, PostIndex)); |
| 2876 | mov(scratch, Operand(scratch, LSR, 8)); |
| 2877 | strb(scratch, MemOperand(dst, 1, PostIndex)); |
| 2878 | mov(scratch, Operand(scratch, LSR, 8)); |
| 2879 | strb(scratch, MemOperand(dst, 1, PostIndex)); |
| 2880 | mov(scratch, Operand(scratch, LSR, 8)); |
| 2881 | strb(scratch, MemOperand(dst, 1, PostIndex)); |
| 2882 | #endif |
| 2883 | sub(length, length, Operand(kPointerSize)); |
| 2884 | b(&word_loop); |
| 2885 | |
| 2886 | // Copy the last bytes if any left. |
| 2887 | bind(&byte_loop); |
| 2888 | cmp(length, Operand(0)); |
| 2889 | b(eq, &done); |
| 2890 | bind(&byte_loop_1); |
| 2891 | ldrb(scratch, MemOperand(src, 1, PostIndex)); |
| 2892 | strb(scratch, MemOperand(dst, 1, PostIndex)); |
| 2893 | sub(length, length, Operand(1), SetCC); |
| 2894 | b(ne, &byte_loop_1); |
| 2895 | bind(&done); |
| 2896 | } |
| 2897 | |
| 2898 | |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 2899 | void MacroAssembler::CountLeadingZeros(Register zeros, // Answer. |
| 2900 | Register source, // Input. |
| 2901 | Register scratch) { |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2902 | ASSERT(!zeros.is(source) || !source.is(scratch)); |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 2903 | ASSERT(!zeros.is(scratch)); |
| 2904 | ASSERT(!scratch.is(ip)); |
| 2905 | ASSERT(!source.is(ip)); |
| 2906 | ASSERT(!zeros.is(ip)); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 2907 | #ifdef CAN_USE_ARMV5_INSTRUCTIONS |
| 2908 | clz(zeros, source); // This instruction is only supported after ARM5. |
| 2909 | #else |
Iain Merrick | 9ac36c9 | 2010-09-13 15:29:50 +0100 | [diff] [blame] | 2910 | mov(zeros, Operand(0, RelocInfo::NONE)); |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 2911 | Move(scratch, source); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 2912 | // Top 16. |
| 2913 | tst(scratch, Operand(0xffff0000)); |
| 2914 | add(zeros, zeros, Operand(16), LeaveCC, eq); |
| 2915 | mov(scratch, Operand(scratch, LSL, 16), LeaveCC, eq); |
| 2916 | // Top 8. |
| 2917 | tst(scratch, Operand(0xff000000)); |
| 2918 | add(zeros, zeros, Operand(8), LeaveCC, eq); |
| 2919 | mov(scratch, Operand(scratch, LSL, 8), LeaveCC, eq); |
| 2920 | // Top 4. |
| 2921 | tst(scratch, Operand(0xf0000000)); |
| 2922 | add(zeros, zeros, Operand(4), LeaveCC, eq); |
| 2923 | mov(scratch, Operand(scratch, LSL, 4), LeaveCC, eq); |
| 2924 | // Top 2. |
| 2925 | tst(scratch, Operand(0xc0000000)); |
| 2926 | add(zeros, zeros, Operand(2), LeaveCC, eq); |
| 2927 | mov(scratch, Operand(scratch, LSL, 2), LeaveCC, eq); |
| 2928 | // Top bit. |
| 2929 | tst(scratch, Operand(0x80000000u)); |
| 2930 | add(zeros, zeros, Operand(1), LeaveCC, eq); |
| 2931 | #endif |
| 2932 | } |
| 2933 | |
| 2934 | |
| 2935 | void MacroAssembler::JumpIfBothInstanceTypesAreNotSequentialAscii( |
| 2936 | Register first, |
| 2937 | Register second, |
| 2938 | Register scratch1, |
| 2939 | Register scratch2, |
| 2940 | Label* failure) { |
| 2941 | int kFlatAsciiStringMask = |
| 2942 | kIsNotStringMask | kStringEncodingMask | kStringRepresentationMask; |
| 2943 | int kFlatAsciiStringTag = ASCII_STRING_TYPE; |
| 2944 | and_(scratch1, first, Operand(kFlatAsciiStringMask)); |
| 2945 | and_(scratch2, second, Operand(kFlatAsciiStringMask)); |
| 2946 | cmp(scratch1, Operand(kFlatAsciiStringTag)); |
| 2947 | // Ignore second test if first test failed. |
| 2948 | cmp(scratch2, Operand(kFlatAsciiStringTag), eq); |
| 2949 | b(ne, failure); |
| 2950 | } |
| 2951 | |
| 2952 | |
| 2953 | void MacroAssembler::JumpIfInstanceTypeIsNotSequentialAscii(Register type, |
| 2954 | Register scratch, |
| 2955 | Label* failure) { |
| 2956 | int kFlatAsciiStringMask = |
| 2957 | kIsNotStringMask | kStringEncodingMask | kStringRepresentationMask; |
| 2958 | int kFlatAsciiStringTag = ASCII_STRING_TYPE; |
| 2959 | and_(scratch, type, Operand(kFlatAsciiStringMask)); |
| 2960 | cmp(scratch, Operand(kFlatAsciiStringTag)); |
| 2961 | b(ne, failure); |
| 2962 | } |
| 2963 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2964 | static const int kRegisterPassedArguments = 4; |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 2965 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2966 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2967 | int MacroAssembler::CalculateStackPassedWords(int num_reg_arguments, |
| 2968 | int num_double_arguments) { |
| 2969 | int stack_passed_words = 0; |
| 2970 | if (use_eabi_hardfloat()) { |
| 2971 | // In the hard floating point calling convention, we can use |
| 2972 | // all double registers to pass doubles. |
| 2973 | if (num_double_arguments > DoubleRegister::kNumRegisters) { |
| 2974 | stack_passed_words += |
| 2975 | 2 * (num_double_arguments - DoubleRegister::kNumRegisters); |
| 2976 | } |
| 2977 | } else { |
| 2978 | // In the soft floating point calling convention, every double |
| 2979 | // argument is passed using two registers. |
| 2980 | num_reg_arguments += 2 * num_double_arguments; |
| 2981 | } |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 2982 | // Up to four simple arguments are passed in registers r0..r3. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2983 | if (num_reg_arguments > kRegisterPassedArguments) { |
| 2984 | stack_passed_words += num_reg_arguments - kRegisterPassedArguments; |
| 2985 | } |
| 2986 | return stack_passed_words; |
| 2987 | } |
| 2988 | |
| 2989 | |
| 2990 | void MacroAssembler::PrepareCallCFunction(int num_reg_arguments, |
| 2991 | int num_double_arguments, |
| 2992 | Register scratch) { |
| 2993 | int frame_alignment = ActivationFrameAlignment(); |
| 2994 | int stack_passed_arguments = CalculateStackPassedWords( |
| 2995 | num_reg_arguments, num_double_arguments); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 2996 | if (frame_alignment > kPointerSize) { |
| 2997 | // Make stack end at alignment and make room for num_arguments - 4 words |
| 2998 | // and the original value of sp. |
| 2999 | mov(scratch, sp); |
| 3000 | sub(sp, sp, Operand((stack_passed_arguments + 1) * kPointerSize)); |
| 3001 | ASSERT(IsPowerOf2(frame_alignment)); |
| 3002 | and_(sp, sp, Operand(-frame_alignment)); |
| 3003 | str(scratch, MemOperand(sp, stack_passed_arguments * kPointerSize)); |
| 3004 | } else { |
| 3005 | sub(sp, sp, Operand(stack_passed_arguments * kPointerSize)); |
| 3006 | } |
| 3007 | } |
| 3008 | |
| 3009 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3010 | void MacroAssembler::PrepareCallCFunction(int num_reg_arguments, |
| 3011 | Register scratch) { |
| 3012 | PrepareCallCFunction(num_reg_arguments, 0, scratch); |
| 3013 | } |
| 3014 | |
| 3015 | |
| 3016 | void MacroAssembler::SetCallCDoubleArguments(DoubleRegister dreg) { |
| 3017 | if (use_eabi_hardfloat()) { |
| 3018 | Move(d0, dreg); |
| 3019 | } else { |
| 3020 | vmov(r0, r1, dreg); |
| 3021 | } |
| 3022 | } |
| 3023 | |
| 3024 | |
| 3025 | void MacroAssembler::SetCallCDoubleArguments(DoubleRegister dreg1, |
| 3026 | DoubleRegister dreg2) { |
| 3027 | if (use_eabi_hardfloat()) { |
| 3028 | if (dreg2.is(d0)) { |
| 3029 | ASSERT(!dreg1.is(d1)); |
| 3030 | Move(d1, dreg2); |
| 3031 | Move(d0, dreg1); |
| 3032 | } else { |
| 3033 | Move(d0, dreg1); |
| 3034 | Move(d1, dreg2); |
| 3035 | } |
| 3036 | } else { |
| 3037 | vmov(r0, r1, dreg1); |
| 3038 | vmov(r2, r3, dreg2); |
| 3039 | } |
| 3040 | } |
| 3041 | |
| 3042 | |
| 3043 | void MacroAssembler::SetCallCDoubleArguments(DoubleRegister dreg, |
| 3044 | Register reg) { |
| 3045 | if (use_eabi_hardfloat()) { |
| 3046 | Move(d0, dreg); |
| 3047 | Move(r0, reg); |
| 3048 | } else { |
| 3049 | Move(r2, reg); |
| 3050 | vmov(r0, r1, dreg); |
| 3051 | } |
| 3052 | } |
| 3053 | |
| 3054 | |
| 3055 | void MacroAssembler::CallCFunction(ExternalReference function, |
| 3056 | int num_reg_arguments, |
| 3057 | int num_double_arguments) { |
| 3058 | CallCFunctionHelper(no_reg, |
| 3059 | function, |
| 3060 | ip, |
| 3061 | num_reg_arguments, |
| 3062 | num_double_arguments); |
| 3063 | } |
| 3064 | |
| 3065 | |
| 3066 | void MacroAssembler::CallCFunction(Register function, |
| 3067 | Register scratch, |
| 3068 | int num_reg_arguments, |
| 3069 | int num_double_arguments) { |
| 3070 | CallCFunctionHelper(function, |
| 3071 | ExternalReference::the_hole_value_location(isolate()), |
| 3072 | scratch, |
| 3073 | num_reg_arguments, |
| 3074 | num_double_arguments); |
| 3075 | } |
| 3076 | |
| 3077 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 3078 | void MacroAssembler::CallCFunction(ExternalReference function, |
| 3079 | int num_arguments) { |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3080 | CallCFunction(function, num_arguments, 0); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 3081 | } |
| 3082 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3083 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 3084 | void MacroAssembler::CallCFunction(Register function, |
| 3085 | Register scratch, |
| 3086 | int num_arguments) { |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3087 | CallCFunction(function, scratch, num_arguments, 0); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 3088 | } |
| 3089 | |
| 3090 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 3091 | void MacroAssembler::CallCFunctionHelper(Register function, |
| 3092 | ExternalReference function_reference, |
| 3093 | Register scratch, |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3094 | int num_reg_arguments, |
| 3095 | int num_double_arguments) { |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 3096 | // Make sure that the stack is aligned before calling a C function unless |
| 3097 | // running in the simulator. The simulator has its own alignment check which |
| 3098 | // provides more information. |
| 3099 | #if defined(V8_HOST_ARCH_ARM) |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 3100 | if (emit_debug_code()) { |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 3101 | int frame_alignment = OS::ActivationFrameAlignment(); |
| 3102 | int frame_alignment_mask = frame_alignment - 1; |
| 3103 | if (frame_alignment > kPointerSize) { |
| 3104 | ASSERT(IsPowerOf2(frame_alignment)); |
| 3105 | Label alignment_as_expected; |
| 3106 | tst(sp, Operand(frame_alignment_mask)); |
| 3107 | b(eq, &alignment_as_expected); |
| 3108 | // Don't use Check here, as it will call Runtime_Abort possibly |
| 3109 | // re-entering here. |
| 3110 | stop("Unexpected alignment"); |
| 3111 | bind(&alignment_as_expected); |
| 3112 | } |
| 3113 | } |
| 3114 | #endif |
| 3115 | |
| 3116 | // Just call directly. The function called cannot cause a GC, or |
| 3117 | // allow preemption, so the return address in the link register |
| 3118 | // stays correct. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 3119 | if (function.is(no_reg)) { |
| 3120 | mov(scratch, Operand(function_reference)); |
| 3121 | function = scratch; |
| 3122 | } |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 3123 | Call(function); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3124 | int stack_passed_arguments = CalculateStackPassedWords( |
| 3125 | num_reg_arguments, num_double_arguments); |
| 3126 | if (ActivationFrameAlignment() > kPointerSize) { |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 3127 | ldr(sp, MemOperand(sp, stack_passed_arguments * kPointerSize)); |
| 3128 | } else { |
| 3129 | add(sp, sp, Operand(stack_passed_arguments * sizeof(kPointerSize))); |
| 3130 | } |
| 3131 | } |
| 3132 | |
| 3133 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 3134 | void MacroAssembler::GetRelocatedValueLocation(Register ldr_location, |
| 3135 | Register result) { |
| 3136 | const uint32_t kLdrOffsetMask = (1 << 12) - 1; |
| 3137 | const int32_t kPCRegOffset = 2 * kPointerSize; |
| 3138 | ldr(result, MemOperand(ldr_location)); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 3139 | if (emit_debug_code()) { |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 3140 | // Check that the instruction is a ldr reg, [pc + offset] . |
| 3141 | and_(result, result, Operand(kLdrPCPattern)); |
| 3142 | cmp(result, Operand(kLdrPCPattern)); |
| 3143 | Check(eq, "The instruction to patch should be a load from pc."); |
| 3144 | // Result was clobbered. Restore it. |
| 3145 | ldr(result, MemOperand(ldr_location)); |
| 3146 | } |
| 3147 | // Get the address of the constant. |
| 3148 | and_(result, result, Operand(kLdrOffsetMask)); |
| 3149 | add(result, ldr_location, Operand(result)); |
| 3150 | add(result, result, Operand(kPCRegOffset)); |
| 3151 | } |
| 3152 | |
| 3153 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3154 | void MacroAssembler::ClampUint8(Register output_reg, Register input_reg) { |
| 3155 | Usat(output_reg, 8, Operand(input_reg)); |
| 3156 | } |
| 3157 | |
| 3158 | |
| 3159 | void MacroAssembler::ClampDoubleToUint8(Register result_reg, |
| 3160 | DoubleRegister input_reg, |
| 3161 | DoubleRegister temp_double_reg) { |
| 3162 | Label above_zero; |
| 3163 | Label done; |
| 3164 | Label in_bounds; |
| 3165 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame^] | 3166 | Vmov(temp_double_reg, 0.0); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3167 | VFPCompareAndSetFlags(input_reg, temp_double_reg); |
| 3168 | b(gt, &above_zero); |
| 3169 | |
| 3170 | // Double value is less than zero, NaN or Inf, return 0. |
| 3171 | mov(result_reg, Operand(0)); |
| 3172 | b(al, &done); |
| 3173 | |
| 3174 | // Double value is >= 255, return 255. |
| 3175 | bind(&above_zero); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame^] | 3176 | Vmov(temp_double_reg, 255.0); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3177 | VFPCompareAndSetFlags(input_reg, temp_double_reg); |
| 3178 | b(le, &in_bounds); |
| 3179 | mov(result_reg, Operand(255)); |
| 3180 | b(al, &done); |
| 3181 | |
| 3182 | // In 0-255 range, round and truncate. |
| 3183 | bind(&in_bounds); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame^] | 3184 | Vmov(temp_double_reg, 0.5); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3185 | vadd(temp_double_reg, input_reg, temp_double_reg); |
| 3186 | vcvt_u32_f64(s0, temp_double_reg); |
| 3187 | vmov(result_reg, s0); |
| 3188 | bind(&done); |
| 3189 | } |
| 3190 | |
| 3191 | |
| 3192 | void MacroAssembler::LoadInstanceDescriptors(Register map, |
| 3193 | Register descriptors) { |
| 3194 | ldr(descriptors, |
| 3195 | FieldMemOperand(map, Map::kInstanceDescriptorsOrBitField3Offset)); |
| 3196 | Label not_smi; |
| 3197 | JumpIfNotSmi(descriptors, ¬_smi); |
| 3198 | mov(descriptors, Operand(FACTORY->empty_descriptor_array())); |
| 3199 | bind(¬_smi); |
| 3200 | } |
| 3201 | |
| 3202 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3203 | CodePatcher::CodePatcher(byte* address, int instructions) |
| 3204 | : address_(address), |
| 3205 | instructions_(instructions), |
| 3206 | size_(instructions * Assembler::kInstrSize), |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 3207 | masm_(Isolate::Current(), address, size_ + Assembler::kGap) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3208 | // Create a new macro assembler pointing to the address of the code to patch. |
| 3209 | // The size is adjusted with kGap on order for the assembler to generate size |
| 3210 | // bytes of instructions without failing with buffer size constraints. |
| 3211 | ASSERT(masm_.reloc_info_writer.pos() == address_ + size_ + Assembler::kGap); |
| 3212 | } |
| 3213 | |
| 3214 | |
| 3215 | CodePatcher::~CodePatcher() { |
| 3216 | // Indicate that code has changed. |
| 3217 | CPU::FlushICache(address_, size_); |
| 3218 | |
| 3219 | // Check that the code was patched as expected. |
| 3220 | ASSERT(masm_.pc_ == address_ + size_); |
| 3221 | ASSERT(masm_.reloc_info_writer.pos() == address_ + size_ + Assembler::kGap); |
| 3222 | } |
| 3223 | |
| 3224 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 3225 | void CodePatcher::Emit(Instr instr) { |
| 3226 | masm()->emit(instr); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3227 | } |
| 3228 | |
| 3229 | |
| 3230 | void CodePatcher::Emit(Address addr) { |
| 3231 | masm()->emit(reinterpret_cast<Instr>(addr)); |
| 3232 | } |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 3233 | |
| 3234 | |
| 3235 | void CodePatcher::EmitCondition(Condition cond) { |
| 3236 | Instr instr = Assembler::instr_at(masm_.pc_); |
| 3237 | instr = (instr & ~kCondMask) | cond; |
| 3238 | masm_.emit(instr); |
| 3239 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3240 | |
| 3241 | |
| 3242 | } } // namespace v8::internal |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3243 | |
| 3244 | #endif // V8_TARGET_ARCH_ARM |