kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1 | // Copyright 2010 the V8 project authors. All rights reserved. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +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 | |
| 28 | #include "v8.h" |
| 29 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 30 | #if defined(V8_TARGET_ARCH_IA32) |
| 31 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 32 | #include "bootstrapper.h" |
| 33 | #include "codegen-inl.h" |
| 34 | #include "debug.h" |
| 35 | #include "runtime.h" |
| 36 | #include "serialize.h" |
| 37 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 38 | namespace v8 { |
| 39 | namespace internal { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 40 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 41 | // ------------------------------------------------------------------------- |
| 42 | // MacroAssembler implementation. |
| 43 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 44 | MacroAssembler::MacroAssembler(void* buffer, int size) |
| 45 | : Assembler(buffer, size), |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 46 | generating_stub_(false), |
kasperl@chromium.org | 061ef74 | 2009-02-27 12:16:20 +0000 | [diff] [blame] | 47 | allow_stub_calls_(true), |
| 48 | code_object_(Heap::undefined_value()) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 52 | void MacroAssembler::RecordWriteHelper(Register object, |
| 53 | Register addr, |
| 54 | Register scratch) { |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 55 | if (FLAG_debug_code) { |
| 56 | // Check that the object is not in new space. |
| 57 | Label not_in_new_space; |
| 58 | InNewSpace(object, scratch, not_equal, ¬_in_new_space); |
| 59 | Abort("new-space object passed to RecordWriteHelper"); |
| 60 | bind(¬_in_new_space); |
| 61 | } |
| 62 | |
christian.plesner.hansen@gmail.com | 5a6af92 | 2009-08-12 14:20:51 +0000 | [diff] [blame] | 63 | // Compute the page start address from the heap object pointer, and reuse |
| 64 | // the 'object' register for it. |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 65 | and_(object, ~Page::kPageAlignmentMask); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 66 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 67 | // Compute number of region covering addr. See Page::GetRegionNumberForAddress |
| 68 | // method for more details. |
| 69 | and_(addr, Page::kPageAlignmentMask); |
| 70 | shr(addr, Page::kRegionSizeLog2); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 71 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 72 | // Set dirty mark for region. |
| 73 | bts(Operand(object, Page::kDirtyFlagOffset), addr); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | |
fschneider@chromium.org | ed78ffd | 2010-07-21 11:05:19 +0000 | [diff] [blame] | 77 | void MacroAssembler::RecordWrite(Register object, |
| 78 | int offset, |
| 79 | Register value, |
| 80 | Register scratch) { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 81 | // The compiled code assumes that record write doesn't change the |
| 82 | // context register, so we check that none of the clobbered |
| 83 | // registers are esi. |
| 84 | ASSERT(!object.is(esi) && !value.is(esi) && !scratch.is(esi)); |
| 85 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 86 | // First, check if a write barrier is even needed. The tests below |
| 87 | // catch stores of Smis and stores into young gen. |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 88 | NearLabel done; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 89 | |
sgjesse@chromium.org | b9d7da1 | 2009-08-05 08:38:10 +0000 | [diff] [blame] | 90 | // Skip barrier if writing a smi. |
| 91 | ASSERT_EQ(0, kSmiTag); |
| 92 | test(value, Immediate(kSmiTagMask)); |
| 93 | j(zero, &done); |
| 94 | |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 95 | InNewSpace(object, value, equal, &done); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 96 | |
whesse@chromium.org | e88a9ed | 2010-04-15 15:07:46 +0000 | [diff] [blame] | 97 | // The offset is relative to a tagged or untagged HeapObject pointer, |
| 98 | // so either offset or offset + kHeapObjectTag must be a |
| 99 | // multiple of kPointerSize. |
| 100 | ASSERT(IsAligned(offset, kPointerSize) || |
| 101 | IsAligned(offset + kHeapObjectTag, kPointerSize)); |
| 102 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 103 | Register dst = scratch; |
| 104 | if (offset != 0) { |
| 105 | lea(dst, Operand(object, offset)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 106 | } else { |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 107 | // Array access: calculate the destination address in the same manner as |
| 108 | // KeyedStoreIC::GenerateGeneric. Multiply a smi by 2 to get an offset |
| 109 | // into an array of words. |
| 110 | ASSERT_EQ(1, kSmiTagSize); |
| 111 | ASSERT_EQ(0, kSmiTag); |
| 112 | lea(dst, Operand(object, dst, times_half_pointer_size, |
| 113 | FixedArray::kHeaderSize - kHeapObjectTag)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 114 | } |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 115 | RecordWriteHelper(object, dst, value); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 116 | |
| 117 | bind(&done); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 118 | |
| 119 | // Clobber all input registers when running with the debug-code flag |
| 120 | // turned on to provoke errors. |
| 121 | if (FLAG_debug_code) { |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 122 | mov(object, Immediate(BitCast<int32_t>(kZapValue))); |
| 123 | mov(value, Immediate(BitCast<int32_t>(kZapValue))); |
| 124 | mov(scratch, Immediate(BitCast<int32_t>(kZapValue))); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 125 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 126 | } |
| 127 | |
| 128 | |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 129 | void MacroAssembler::RecordWrite(Register object, |
| 130 | Register address, |
| 131 | Register value) { |
| 132 | // The compiled code assumes that record write doesn't change the |
| 133 | // context register, so we check that none of the clobbered |
| 134 | // registers are esi. |
| 135 | ASSERT(!object.is(esi) && !value.is(esi) && !address.is(esi)); |
| 136 | |
| 137 | // First, check if a write barrier is even needed. The tests below |
| 138 | // catch stores of Smis and stores into young gen. |
| 139 | Label done; |
| 140 | |
| 141 | // Skip barrier if writing a smi. |
| 142 | ASSERT_EQ(0, kSmiTag); |
| 143 | test(value, Immediate(kSmiTagMask)); |
| 144 | j(zero, &done); |
| 145 | |
| 146 | InNewSpace(object, value, equal, &done); |
| 147 | |
| 148 | RecordWriteHelper(object, address, value); |
| 149 | |
| 150 | bind(&done); |
| 151 | |
| 152 | // Clobber all input registers when running with the debug-code flag |
| 153 | // turned on to provoke errors. |
| 154 | if (FLAG_debug_code) { |
| 155 | mov(object, Immediate(BitCast<int32_t>(kZapValue))); |
| 156 | mov(address, Immediate(BitCast<int32_t>(kZapValue))); |
| 157 | mov(value, Immediate(BitCast<int32_t>(kZapValue))); |
| 158 | } |
| 159 | } |
| 160 | |
| 161 | |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 162 | #ifdef ENABLE_DEBUGGER_SUPPORT |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 163 | void MacroAssembler::DebugBreak() { |
| 164 | Set(eax, Immediate(0)); |
| 165 | mov(ebx, Immediate(ExternalReference(Runtime::kDebugBreak))); |
| 166 | CEntryStub ces(1); |
| 167 | call(ces.GetCode(), RelocInfo::DEBUG_BREAK); |
| 168 | } |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 169 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 170 | |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 171 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 172 | void MacroAssembler::Set(Register dst, const Immediate& x) { |
| 173 | if (x.is_zero()) { |
| 174 | xor_(dst, Operand(dst)); // shorter than mov |
| 175 | } else { |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 176 | mov(dst, x); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 177 | } |
| 178 | } |
| 179 | |
| 180 | |
| 181 | void MacroAssembler::Set(const Operand& dst, const Immediate& x) { |
| 182 | mov(dst, x); |
| 183 | } |
| 184 | |
| 185 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 186 | void MacroAssembler::CmpObjectType(Register heap_object, |
| 187 | InstanceType type, |
| 188 | Register map) { |
| 189 | mov(map, FieldOperand(heap_object, HeapObject::kMapOffset)); |
| 190 | CmpInstanceType(map, type); |
| 191 | } |
| 192 | |
| 193 | |
| 194 | void MacroAssembler::CmpInstanceType(Register map, InstanceType type) { |
| 195 | cmpb(FieldOperand(map, Map::kInstanceTypeOffset), |
| 196 | static_cast<int8_t>(type)); |
| 197 | } |
| 198 | |
| 199 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 200 | void MacroAssembler::CheckMap(Register obj, |
| 201 | Handle<Map> map, |
| 202 | Label* fail, |
| 203 | bool is_heap_object) { |
| 204 | if (!is_heap_object) { |
| 205 | test(obj, Immediate(kSmiTagMask)); |
| 206 | j(zero, fail); |
| 207 | } |
| 208 | cmp(FieldOperand(obj, HeapObject::kMapOffset), Immediate(map)); |
| 209 | j(not_equal, fail); |
| 210 | } |
| 211 | |
| 212 | |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 213 | Condition MacroAssembler::IsObjectStringType(Register heap_object, |
| 214 | Register map, |
| 215 | Register instance_type) { |
| 216 | mov(map, FieldOperand(heap_object, HeapObject::kMapOffset)); |
| 217 | movzx_b(instance_type, FieldOperand(map, Map::kInstanceTypeOffset)); |
| 218 | ASSERT(kNotStringTag != 0); |
| 219 | test(instance_type, Immediate(kIsNotStringMask)); |
| 220 | return zero; |
| 221 | } |
| 222 | |
| 223 | |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 224 | void MacroAssembler::IsObjectJSObjectType(Register heap_object, |
| 225 | Register map, |
| 226 | Register scratch, |
| 227 | Label* fail) { |
| 228 | mov(map, FieldOperand(heap_object, HeapObject::kMapOffset)); |
| 229 | IsInstanceJSObjectType(map, scratch, fail); |
| 230 | } |
| 231 | |
| 232 | |
| 233 | void MacroAssembler::IsInstanceJSObjectType(Register map, |
| 234 | Register scratch, |
| 235 | Label* fail) { |
| 236 | movzx_b(scratch, FieldOperand(map, Map::kInstanceTypeOffset)); |
| 237 | sub(Operand(scratch), Immediate(FIRST_JS_OBJECT_TYPE)); |
| 238 | cmp(scratch, LAST_JS_OBJECT_TYPE - FIRST_JS_OBJECT_TYPE); |
| 239 | j(above, fail); |
| 240 | } |
| 241 | |
| 242 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 243 | void MacroAssembler::FCmp() { |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 244 | if (CpuFeatures::IsSupported(CMOV)) { |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 245 | fucomip(); |
| 246 | ffree(0); |
| 247 | fincstp(); |
| 248 | } else { |
| 249 | fucompp(); |
| 250 | push(eax); |
| 251 | fnstsw_ax(); |
| 252 | sahf(); |
| 253 | pop(eax); |
| 254 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 255 | } |
| 256 | |
| 257 | |
whesse@chromium.org | cec079d | 2010-03-22 14:44:04 +0000 | [diff] [blame] | 258 | void MacroAssembler::AbortIfNotNumber(Register object) { |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 259 | Label ok; |
| 260 | test(object, Immediate(kSmiTagMask)); |
| 261 | j(zero, &ok); |
| 262 | cmp(FieldOperand(object, HeapObject::kMapOffset), |
| 263 | Factory::heap_number_map()); |
whesse@chromium.org | cec079d | 2010-03-22 14:44:04 +0000 | [diff] [blame] | 264 | Assert(equal, "Operand not a number"); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 265 | bind(&ok); |
| 266 | } |
| 267 | |
| 268 | |
whesse@chromium.org | cec079d | 2010-03-22 14:44:04 +0000 | [diff] [blame] | 269 | void MacroAssembler::AbortIfNotSmi(Register object) { |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 270 | test(object, Immediate(kSmiTagMask)); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 271 | Assert(equal, "Operand is not a smi"); |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 272 | } |
| 273 | |
| 274 | |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 275 | void MacroAssembler::AbortIfNotString(Register object) { |
| 276 | test(object, Immediate(kSmiTagMask)); |
| 277 | Assert(not_equal, "Operand is not a string"); |
| 278 | push(object); |
| 279 | mov(object, FieldOperand(object, HeapObject::kMapOffset)); |
| 280 | CmpInstanceType(object, FIRST_NONSTRING_TYPE); |
| 281 | pop(object); |
| 282 | Assert(below, "Operand is not a string"); |
| 283 | } |
| 284 | |
| 285 | |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 286 | void MacroAssembler::AbortIfSmi(Register object) { |
| 287 | test(object, Immediate(kSmiTagMask)); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 288 | Assert(not_equal, "Operand is a smi"); |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 289 | } |
| 290 | |
| 291 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 292 | void MacroAssembler::EnterFrame(StackFrame::Type type) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 293 | push(ebp); |
| 294 | mov(ebp, Operand(esp)); |
| 295 | push(esi); |
| 296 | push(Immediate(Smi::FromInt(type))); |
kasperl@chromium.org | 061ef74 | 2009-02-27 12:16:20 +0000 | [diff] [blame] | 297 | push(Immediate(CodeObject())); |
| 298 | if (FLAG_debug_code) { |
| 299 | cmp(Operand(esp, 0), Immediate(Factory::undefined_value())); |
| 300 | Check(not_equal, "code object not properly patched"); |
| 301 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 302 | } |
| 303 | |
| 304 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 305 | void MacroAssembler::LeaveFrame(StackFrame::Type type) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 306 | if (FLAG_debug_code) { |
| 307 | cmp(Operand(ebp, StandardFrameConstants::kMarkerOffset), |
| 308 | Immediate(Smi::FromInt(type))); |
| 309 | Check(equal, "stack frame types must match"); |
| 310 | } |
| 311 | leave(); |
| 312 | } |
| 313 | |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 314 | |
| 315 | void MacroAssembler::EnterExitFramePrologue() { |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 316 | // Setup the frame structure on the stack. |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 317 | ASSERT(ExitFrameConstants::kCallerSPDisplacement == +2 * kPointerSize); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 318 | ASSERT(ExitFrameConstants::kCallerPCOffset == +1 * kPointerSize); |
| 319 | ASSERT(ExitFrameConstants::kCallerFPOffset == 0 * kPointerSize); |
| 320 | push(ebp); |
| 321 | mov(ebp, Operand(esp)); |
| 322 | |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 323 | // Reserve room for entry stack pointer and push the code object. |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 324 | ASSERT(ExitFrameConstants::kSPOffset == -1 * kPointerSize); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 325 | push(Immediate(0)); // Saved entry sp, patched before call. |
| 326 | push(Immediate(CodeObject())); // Accessed from ExitFrame::code_slot. |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 327 | |
| 328 | // Save the frame pointer and the context in top. |
| 329 | ExternalReference c_entry_fp_address(Top::k_c_entry_fp_address); |
| 330 | ExternalReference context_address(Top::k_context_address); |
| 331 | mov(Operand::StaticVariable(c_entry_fp_address), ebp); |
| 332 | mov(Operand::StaticVariable(context_address), esi); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 333 | } |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 334 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 335 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 336 | void MacroAssembler::EnterExitFrameEpilogue(int argc, bool save_doubles) { |
| 337 | // Optionally save all XMM registers. |
| 338 | if (save_doubles) { |
| 339 | CpuFeatures::Scope scope(SSE2); |
| 340 | int space = XMMRegister::kNumRegisters * kDoubleSize + argc * kPointerSize; |
| 341 | sub(Operand(esp), Immediate(space)); |
| 342 | int offset = -2 * kPointerSize; |
| 343 | for (int i = 0; i < XMMRegister::kNumRegisters; i++) { |
| 344 | XMMRegister reg = XMMRegister::from_code(i); |
| 345 | movdbl(Operand(ebp, offset - ((i + 1) * kDoubleSize)), reg); |
| 346 | } |
| 347 | } else { |
| 348 | sub(Operand(esp), Immediate(argc * kPointerSize)); |
| 349 | } |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 350 | |
| 351 | // Get the required frame alignment for the OS. |
| 352 | static const int kFrameAlignment = OS::ActivationFrameAlignment(); |
| 353 | if (kFrameAlignment > 0) { |
| 354 | ASSERT(IsPowerOf2(kFrameAlignment)); |
| 355 | and_(esp, -kFrameAlignment); |
| 356 | } |
| 357 | |
| 358 | // Patch the saved entry sp. |
| 359 | mov(Operand(ebp, ExitFrameConstants::kSPOffset), esp); |
| 360 | } |
| 361 | |
| 362 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 363 | void MacroAssembler::EnterExitFrame(bool save_doubles) { |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 364 | EnterExitFramePrologue(); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 365 | |
| 366 | // Setup argc and argv in callee-saved registers. |
| 367 | int offset = StandardFrameConstants::kCallerSPOffset - kPointerSize; |
| 368 | mov(edi, Operand(eax)); |
| 369 | lea(esi, Operand(ebp, eax, times_4, offset)); |
| 370 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 371 | EnterExitFrameEpilogue(2, save_doubles); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 372 | } |
| 373 | |
| 374 | |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 375 | void MacroAssembler::EnterApiExitFrame(int argc) { |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 376 | EnterExitFramePrologue(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 377 | EnterExitFrameEpilogue(argc, false); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 378 | } |
| 379 | |
| 380 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 381 | void MacroAssembler::LeaveExitFrame(bool save_doubles) { |
| 382 | // Optionally restore all XMM registers. |
| 383 | if (save_doubles) { |
| 384 | CpuFeatures::Scope scope(SSE2); |
| 385 | int offset = -2 * kPointerSize; |
| 386 | for (int i = 0; i < XMMRegister::kNumRegisters; i++) { |
| 387 | XMMRegister reg = XMMRegister::from_code(i); |
| 388 | movdbl(reg, Operand(ebp, offset - ((i + 1) * kDoubleSize))); |
| 389 | } |
| 390 | } |
| 391 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 392 | // Get the return address from the stack and restore the frame pointer. |
| 393 | mov(ecx, Operand(ebp, 1 * kPointerSize)); |
| 394 | mov(ebp, Operand(ebp, 0 * kPointerSize)); |
| 395 | |
| 396 | // Pop the arguments and the receiver from the caller stack. |
| 397 | lea(esp, Operand(esi, 1 * kPointerSize)); |
| 398 | |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 399 | // Push the return address to get ready to return. |
| 400 | push(ecx); |
| 401 | |
| 402 | LeaveExitFrameEpilogue(); |
| 403 | } |
| 404 | |
| 405 | void MacroAssembler::LeaveExitFrameEpilogue() { |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 406 | // Restore current context from top and clear it in debug mode. |
| 407 | ExternalReference context_address(Top::k_context_address); |
| 408 | mov(esi, Operand::StaticVariable(context_address)); |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 409 | #ifdef DEBUG |
| 410 | mov(Operand::StaticVariable(context_address), Immediate(0)); |
| 411 | #endif |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 412 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 413 | // Clear the top frame. |
| 414 | ExternalReference c_entry_fp_address(Top::k_c_entry_fp_address); |
| 415 | mov(Operand::StaticVariable(c_entry_fp_address), Immediate(0)); |
| 416 | } |
| 417 | |
| 418 | |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 419 | void MacroAssembler::LeaveApiExitFrame() { |
| 420 | mov(esp, Operand(ebp)); |
| 421 | pop(ebp); |
| 422 | |
| 423 | LeaveExitFrameEpilogue(); |
| 424 | } |
| 425 | |
| 426 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 427 | void MacroAssembler::PushTryHandler(CodeLocation try_location, |
| 428 | HandlerType type) { |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 429 | // Adjust this code if not the case. |
| 430 | ASSERT(StackHandlerConstants::kSize == 4 * kPointerSize); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 431 | // The pc (return address) is already on TOS. |
| 432 | if (try_location == IN_JAVASCRIPT) { |
| 433 | if (type == TRY_CATCH_HANDLER) { |
| 434 | push(Immediate(StackHandler::TRY_CATCH)); |
| 435 | } else { |
| 436 | push(Immediate(StackHandler::TRY_FINALLY)); |
| 437 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 438 | push(ebp); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 439 | } else { |
| 440 | ASSERT(try_location == IN_JS_ENTRY); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 441 | // The frame pointer does not point to a JS frame so we save NULL |
| 442 | // for ebp. We expect the code throwing an exception to check ebp |
| 443 | // before dereferencing it to restore the context. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 444 | push(Immediate(StackHandler::ENTRY)); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 445 | push(Immediate(0)); // NULL frame pointer. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 446 | } |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 447 | // Save the current handler as the next handler. |
| 448 | push(Operand::StaticVariable(ExternalReference(Top::k_handler_address))); |
| 449 | // Link this handler as the new current one. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 450 | mov(Operand::StaticVariable(ExternalReference(Top::k_handler_address)), esp); |
| 451 | } |
| 452 | |
| 453 | |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 454 | void MacroAssembler::PopTryHandler() { |
| 455 | ASSERT_EQ(0, StackHandlerConstants::kNextOffset); |
| 456 | pop(Operand::StaticVariable(ExternalReference(Top::k_handler_address))); |
| 457 | add(Operand(esp), Immediate(StackHandlerConstants::kSize - kPointerSize)); |
| 458 | } |
| 459 | |
| 460 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 461 | void MacroAssembler::CheckAccessGlobalProxy(Register holder_reg, |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 462 | Register scratch, |
| 463 | Label* miss) { |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 464 | Label same_contexts; |
| 465 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 466 | ASSERT(!holder_reg.is(scratch)); |
| 467 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 468 | // Load current lexical context from the stack frame. |
| 469 | mov(scratch, Operand(ebp, StandardFrameConstants::kContextOffset)); |
| 470 | |
| 471 | // When generating debug code, make sure the lexical context is set. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 472 | if (FLAG_debug_code) { |
| 473 | cmp(Operand(scratch), Immediate(0)); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 474 | Check(not_equal, "we should not have an empty lexical context"); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 475 | } |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 476 | // Load the global context of the current context. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 477 | int offset = Context::kHeaderSize + Context::GLOBAL_INDEX * kPointerSize; |
| 478 | mov(scratch, FieldOperand(scratch, offset)); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 479 | mov(scratch, FieldOperand(scratch, GlobalObject::kGlobalContextOffset)); |
| 480 | |
| 481 | // Check the context is a global context. |
| 482 | if (FLAG_debug_code) { |
| 483 | push(scratch); |
| 484 | // Read the first word and compare to global_context_map. |
| 485 | mov(scratch, FieldOperand(scratch, HeapObject::kMapOffset)); |
| 486 | cmp(scratch, Factory::global_context_map()); |
| 487 | Check(equal, "JSGlobalObject::global_context should be a global context."); |
| 488 | pop(scratch); |
| 489 | } |
| 490 | |
| 491 | // Check if both contexts are the same. |
| 492 | cmp(scratch, FieldOperand(holder_reg, JSGlobalProxy::kContextOffset)); |
| 493 | j(equal, &same_contexts, taken); |
| 494 | |
| 495 | // Compare security tokens, save holder_reg on the stack so we can use it |
| 496 | // as a temporary register. |
| 497 | // |
| 498 | // TODO(119): avoid push(holder_reg)/pop(holder_reg) |
| 499 | push(holder_reg); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 500 | // Check that the security token in the calling global object is |
| 501 | // compatible with the security token in the receiving global |
| 502 | // object. |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 503 | mov(holder_reg, FieldOperand(holder_reg, JSGlobalProxy::kContextOffset)); |
| 504 | |
| 505 | // Check the context is a global context. |
| 506 | if (FLAG_debug_code) { |
| 507 | cmp(holder_reg, Factory::null_value()); |
| 508 | Check(not_equal, "JSGlobalProxy::context() should not be null."); |
| 509 | |
| 510 | push(holder_reg); |
| 511 | // Read the first word and compare to global_context_map(), |
| 512 | mov(holder_reg, FieldOperand(holder_reg, HeapObject::kMapOffset)); |
| 513 | cmp(holder_reg, Factory::global_context_map()); |
| 514 | Check(equal, "JSGlobalObject::global_context should be a global context."); |
| 515 | pop(holder_reg); |
| 516 | } |
| 517 | |
| 518 | int token_offset = Context::kHeaderSize + |
| 519 | Context::SECURITY_TOKEN_INDEX * kPointerSize; |
| 520 | mov(scratch, FieldOperand(scratch, token_offset)); |
| 521 | cmp(scratch, FieldOperand(holder_reg, token_offset)); |
| 522 | pop(holder_reg); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 523 | j(not_equal, miss, not_taken); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 524 | |
| 525 | bind(&same_contexts); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 526 | } |
| 527 | |
| 528 | |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 529 | void MacroAssembler::LoadAllocationTopHelper(Register result, |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 530 | Register scratch, |
| 531 | AllocationFlags flags) { |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 532 | ExternalReference new_space_allocation_top = |
| 533 | ExternalReference::new_space_allocation_top_address(); |
| 534 | |
| 535 | // Just return if allocation top is already known. |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 536 | if ((flags & RESULT_CONTAINS_TOP) != 0) { |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 537 | // No use of scratch if allocation top is provided. |
| 538 | ASSERT(scratch.is(no_reg)); |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 539 | #ifdef DEBUG |
| 540 | // Assert that result actually contains top on entry. |
| 541 | cmp(result, Operand::StaticVariable(new_space_allocation_top)); |
| 542 | Check(equal, "Unexpected allocation top"); |
| 543 | #endif |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 544 | return; |
| 545 | } |
| 546 | |
| 547 | // Move address of new object to result. Use scratch register if available. |
| 548 | if (scratch.is(no_reg)) { |
| 549 | mov(result, Operand::StaticVariable(new_space_allocation_top)); |
| 550 | } else { |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 551 | mov(Operand(scratch), Immediate(new_space_allocation_top)); |
| 552 | mov(result, Operand(scratch, 0)); |
| 553 | } |
| 554 | } |
| 555 | |
| 556 | |
| 557 | void MacroAssembler::UpdateAllocationTopHelper(Register result_end, |
| 558 | Register scratch) { |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 559 | if (FLAG_debug_code) { |
| 560 | test(result_end, Immediate(kObjectAlignmentMask)); |
| 561 | Check(zero, "Unaligned allocation in new space"); |
| 562 | } |
| 563 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 564 | ExternalReference new_space_allocation_top = |
| 565 | ExternalReference::new_space_allocation_top_address(); |
| 566 | |
| 567 | // Update new top. Use scratch if available. |
| 568 | if (scratch.is(no_reg)) { |
| 569 | mov(Operand::StaticVariable(new_space_allocation_top), result_end); |
| 570 | } else { |
| 571 | mov(Operand(scratch, 0), result_end); |
| 572 | } |
| 573 | } |
| 574 | |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 575 | |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 576 | void MacroAssembler::AllocateInNewSpace(int object_size, |
| 577 | Register result, |
| 578 | Register result_end, |
| 579 | Register scratch, |
| 580 | Label* gc_required, |
| 581 | AllocationFlags flags) { |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 582 | if (!FLAG_inline_new) { |
| 583 | if (FLAG_debug_code) { |
| 584 | // Trash the registers to simulate an allocation failure. |
| 585 | mov(result, Immediate(0x7091)); |
| 586 | if (result_end.is_valid()) { |
| 587 | mov(result_end, Immediate(0x7191)); |
| 588 | } |
| 589 | if (scratch.is_valid()) { |
| 590 | mov(scratch, Immediate(0x7291)); |
| 591 | } |
| 592 | } |
| 593 | jmp(gc_required); |
| 594 | return; |
| 595 | } |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 596 | ASSERT(!result.is(result_end)); |
| 597 | |
| 598 | // Load address of new object into result. |
ager@chromium.org | beb2571 | 2010-11-29 08:02:25 +0000 | [diff] [blame] | 599 | LoadAllocationTopHelper(result, scratch, flags); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 600 | |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 601 | Register top_reg = result_end.is_valid() ? result_end : result; |
| 602 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 603 | // Calculate new top and bail out if new space is exhausted. |
| 604 | ExternalReference new_space_allocation_limit = |
| 605 | ExternalReference::new_space_allocation_limit_address(); |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 606 | |
| 607 | if (top_reg.is(result)) { |
| 608 | add(Operand(top_reg), Immediate(object_size)); |
| 609 | } else { |
| 610 | lea(top_reg, Operand(result, object_size)); |
| 611 | } |
| 612 | cmp(top_reg, Operand::StaticVariable(new_space_allocation_limit)); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 613 | j(above, gc_required, not_taken); |
| 614 | |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 615 | // Update allocation top. |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 616 | UpdateAllocationTopHelper(top_reg, scratch); |
| 617 | |
| 618 | // Tag result if requested. |
| 619 | if (top_reg.is(result)) { |
| 620 | if ((flags & TAG_OBJECT) != 0) { |
| 621 | sub(Operand(result), Immediate(object_size - kHeapObjectTag)); |
| 622 | } else { |
| 623 | sub(Operand(result), Immediate(object_size)); |
| 624 | } |
| 625 | } else if ((flags & TAG_OBJECT) != 0) { |
| 626 | add(Operand(result), Immediate(kHeapObjectTag)); |
| 627 | } |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 628 | } |
| 629 | |
| 630 | |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 631 | void MacroAssembler::AllocateInNewSpace(int header_size, |
| 632 | ScaleFactor element_size, |
| 633 | Register element_count, |
| 634 | Register result, |
| 635 | Register result_end, |
| 636 | Register scratch, |
| 637 | Label* gc_required, |
| 638 | AllocationFlags flags) { |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 639 | if (!FLAG_inline_new) { |
| 640 | if (FLAG_debug_code) { |
| 641 | // Trash the registers to simulate an allocation failure. |
| 642 | mov(result, Immediate(0x7091)); |
| 643 | mov(result_end, Immediate(0x7191)); |
| 644 | if (scratch.is_valid()) { |
| 645 | mov(scratch, Immediate(0x7291)); |
| 646 | } |
| 647 | // Register element_count is not modified by the function. |
| 648 | } |
| 649 | jmp(gc_required); |
| 650 | return; |
| 651 | } |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 652 | ASSERT(!result.is(result_end)); |
| 653 | |
| 654 | // Load address of new object into result. |
ager@chromium.org | beb2571 | 2010-11-29 08:02:25 +0000 | [diff] [blame] | 655 | LoadAllocationTopHelper(result, scratch, flags); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 656 | |
| 657 | // Calculate new top and bail out if new space is exhausted. |
| 658 | ExternalReference new_space_allocation_limit = |
| 659 | ExternalReference::new_space_allocation_limit_address(); |
| 660 | lea(result_end, Operand(result, element_count, element_size, header_size)); |
| 661 | cmp(result_end, Operand::StaticVariable(new_space_allocation_limit)); |
| 662 | j(above, gc_required); |
| 663 | |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 664 | // Tag result if requested. |
| 665 | if ((flags & TAG_OBJECT) != 0) { |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 666 | lea(result, Operand(result, kHeapObjectTag)); |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 667 | } |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 668 | |
| 669 | // Update allocation top. |
| 670 | UpdateAllocationTopHelper(result_end, scratch); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 671 | } |
| 672 | |
| 673 | |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 674 | void MacroAssembler::AllocateInNewSpace(Register object_size, |
| 675 | Register result, |
| 676 | Register result_end, |
| 677 | Register scratch, |
| 678 | Label* gc_required, |
| 679 | AllocationFlags flags) { |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 680 | if (!FLAG_inline_new) { |
| 681 | if (FLAG_debug_code) { |
| 682 | // Trash the registers to simulate an allocation failure. |
| 683 | mov(result, Immediate(0x7091)); |
| 684 | mov(result_end, Immediate(0x7191)); |
| 685 | if (scratch.is_valid()) { |
| 686 | mov(scratch, Immediate(0x7291)); |
| 687 | } |
| 688 | // object_size is left unchanged by this function. |
| 689 | } |
| 690 | jmp(gc_required); |
| 691 | return; |
| 692 | } |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 693 | ASSERT(!result.is(result_end)); |
| 694 | |
| 695 | // Load address of new object into result. |
ager@chromium.org | beb2571 | 2010-11-29 08:02:25 +0000 | [diff] [blame] | 696 | LoadAllocationTopHelper(result, scratch, flags); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 697 | |
| 698 | // Calculate new top and bail out if new space is exhausted. |
| 699 | ExternalReference new_space_allocation_limit = |
| 700 | ExternalReference::new_space_allocation_limit_address(); |
| 701 | if (!object_size.is(result_end)) { |
| 702 | mov(result_end, object_size); |
| 703 | } |
| 704 | add(result_end, Operand(result)); |
| 705 | cmp(result_end, Operand::StaticVariable(new_space_allocation_limit)); |
| 706 | j(above, gc_required, not_taken); |
| 707 | |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 708 | // Tag result if requested. |
| 709 | if ((flags & TAG_OBJECT) != 0) { |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 710 | lea(result, Operand(result, kHeapObjectTag)); |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 711 | } |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 712 | |
| 713 | // Update allocation top. |
| 714 | UpdateAllocationTopHelper(result_end, scratch); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 715 | } |
| 716 | |
| 717 | |
| 718 | void MacroAssembler::UndoAllocationInNewSpace(Register object) { |
| 719 | ExternalReference new_space_allocation_top = |
| 720 | ExternalReference::new_space_allocation_top_address(); |
| 721 | |
| 722 | // Make sure the object has no tag before resetting top. |
| 723 | and_(Operand(object), Immediate(~kHeapObjectTagMask)); |
| 724 | #ifdef DEBUG |
| 725 | cmp(object, Operand::StaticVariable(new_space_allocation_top)); |
| 726 | Check(below, "Undo allocation of non allocated memory"); |
| 727 | #endif |
| 728 | mov(Operand::StaticVariable(new_space_allocation_top), object); |
| 729 | } |
| 730 | |
| 731 | |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 732 | void MacroAssembler::AllocateHeapNumber(Register result, |
| 733 | Register scratch1, |
| 734 | Register scratch2, |
| 735 | Label* gc_required) { |
| 736 | // Allocate heap number in new space. |
| 737 | AllocateInNewSpace(HeapNumber::kSize, |
| 738 | result, |
| 739 | scratch1, |
| 740 | scratch2, |
| 741 | gc_required, |
| 742 | TAG_OBJECT); |
| 743 | |
| 744 | // Set the map. |
| 745 | mov(FieldOperand(result, HeapObject::kMapOffset), |
| 746 | Immediate(Factory::heap_number_map())); |
| 747 | } |
| 748 | |
| 749 | |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 750 | void MacroAssembler::AllocateTwoByteString(Register result, |
| 751 | Register length, |
| 752 | Register scratch1, |
| 753 | Register scratch2, |
| 754 | Register scratch3, |
| 755 | Label* gc_required) { |
| 756 | // Calculate the number of bytes needed for the characters in the string while |
| 757 | // observing object alignment. |
| 758 | ASSERT((SeqTwoByteString::kHeaderSize & kObjectAlignmentMask) == 0); |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 759 | ASSERT(kShortSize == 2); |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 760 | // scratch1 = length * 2 + kObjectAlignmentMask. |
| 761 | lea(scratch1, Operand(length, length, times_1, kObjectAlignmentMask)); |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 762 | and_(Operand(scratch1), Immediate(~kObjectAlignmentMask)); |
| 763 | |
| 764 | // Allocate two byte string in new space. |
| 765 | AllocateInNewSpace(SeqTwoByteString::kHeaderSize, |
| 766 | times_1, |
| 767 | scratch1, |
| 768 | result, |
| 769 | scratch2, |
| 770 | scratch3, |
| 771 | gc_required, |
| 772 | TAG_OBJECT); |
| 773 | |
| 774 | // Set the map, length and hash field. |
| 775 | mov(FieldOperand(result, HeapObject::kMapOffset), |
| 776 | Immediate(Factory::string_map())); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 777 | mov(scratch1, length); |
| 778 | SmiTag(scratch1); |
| 779 | mov(FieldOperand(result, String::kLengthOffset), scratch1); |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 780 | mov(FieldOperand(result, String::kHashFieldOffset), |
| 781 | Immediate(String::kEmptyHashField)); |
| 782 | } |
| 783 | |
| 784 | |
| 785 | void MacroAssembler::AllocateAsciiString(Register result, |
| 786 | Register length, |
| 787 | Register scratch1, |
| 788 | Register scratch2, |
| 789 | Register scratch3, |
| 790 | Label* gc_required) { |
| 791 | // Calculate the number of bytes needed for the characters in the string while |
| 792 | // observing object alignment. |
| 793 | ASSERT((SeqAsciiString::kHeaderSize & kObjectAlignmentMask) == 0); |
| 794 | mov(scratch1, length); |
| 795 | ASSERT(kCharSize == 1); |
| 796 | add(Operand(scratch1), Immediate(kObjectAlignmentMask)); |
| 797 | and_(Operand(scratch1), Immediate(~kObjectAlignmentMask)); |
| 798 | |
| 799 | // Allocate ascii string in new space. |
| 800 | AllocateInNewSpace(SeqAsciiString::kHeaderSize, |
| 801 | times_1, |
| 802 | scratch1, |
| 803 | result, |
| 804 | scratch2, |
| 805 | scratch3, |
| 806 | gc_required, |
| 807 | TAG_OBJECT); |
| 808 | |
| 809 | // Set the map, length and hash field. |
| 810 | mov(FieldOperand(result, HeapObject::kMapOffset), |
| 811 | Immediate(Factory::ascii_string_map())); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 812 | mov(scratch1, length); |
| 813 | SmiTag(scratch1); |
| 814 | mov(FieldOperand(result, String::kLengthOffset), scratch1); |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 815 | mov(FieldOperand(result, String::kHashFieldOffset), |
| 816 | Immediate(String::kEmptyHashField)); |
| 817 | } |
| 818 | |
| 819 | |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 820 | void MacroAssembler::AllocateAsciiString(Register result, |
| 821 | int length, |
| 822 | Register scratch1, |
| 823 | Register scratch2, |
| 824 | Label* gc_required) { |
| 825 | ASSERT(length > 0); |
| 826 | |
| 827 | // Allocate ascii string in new space. |
| 828 | AllocateInNewSpace(SeqAsciiString::SizeFor(length), |
| 829 | result, |
| 830 | scratch1, |
| 831 | scratch2, |
| 832 | gc_required, |
| 833 | TAG_OBJECT); |
| 834 | |
| 835 | // Set the map, length and hash field. |
| 836 | mov(FieldOperand(result, HeapObject::kMapOffset), |
| 837 | Immediate(Factory::ascii_string_map())); |
| 838 | mov(FieldOperand(result, String::kLengthOffset), |
| 839 | Immediate(Smi::FromInt(length))); |
| 840 | mov(FieldOperand(result, String::kHashFieldOffset), |
| 841 | Immediate(String::kEmptyHashField)); |
| 842 | } |
| 843 | |
| 844 | |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 845 | void MacroAssembler::AllocateConsString(Register result, |
| 846 | Register scratch1, |
| 847 | Register scratch2, |
| 848 | Label* gc_required) { |
| 849 | // Allocate heap number in new space. |
| 850 | AllocateInNewSpace(ConsString::kSize, |
| 851 | result, |
| 852 | scratch1, |
| 853 | scratch2, |
| 854 | gc_required, |
| 855 | TAG_OBJECT); |
| 856 | |
| 857 | // Set the map. The other fields are left uninitialized. |
| 858 | mov(FieldOperand(result, HeapObject::kMapOffset), |
| 859 | Immediate(Factory::cons_string_map())); |
| 860 | } |
| 861 | |
| 862 | |
| 863 | void MacroAssembler::AllocateAsciiConsString(Register result, |
| 864 | Register scratch1, |
| 865 | Register scratch2, |
| 866 | Label* gc_required) { |
| 867 | // Allocate heap number in new space. |
| 868 | AllocateInNewSpace(ConsString::kSize, |
| 869 | result, |
| 870 | scratch1, |
| 871 | scratch2, |
| 872 | gc_required, |
| 873 | TAG_OBJECT); |
| 874 | |
| 875 | // Set the map. The other fields are left uninitialized. |
| 876 | mov(FieldOperand(result, HeapObject::kMapOffset), |
| 877 | Immediate(Factory::cons_ascii_string_map())); |
| 878 | } |
| 879 | |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 880 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame^] | 881 | // Copy memory, byte-by-byte, from source to destination. Not optimized for |
| 882 | // long or aligned copies. The contents of scratch and length are destroyed. |
| 883 | // Source and destination are incremented by length. |
| 884 | // Many variants of movsb, loop unrolling, word moves, and indexed operands |
| 885 | // have been tried here already, and this is fastest. |
| 886 | // A simpler loop is faster on small copies, but 30% slower on large ones. |
| 887 | // The cld() instruction must have been emitted, to set the direction flag(), |
| 888 | // before calling this function. |
| 889 | void MacroAssembler::CopyBytes(Register source, |
| 890 | Register destination, |
| 891 | Register length, |
| 892 | Register scratch) { |
| 893 | Label loop, done, short_string, short_loop; |
| 894 | // Experimentation shows that the short string loop is faster if length < 10. |
| 895 | cmp(Operand(length), Immediate(10)); |
| 896 | j(less_equal, &short_string); |
| 897 | |
| 898 | ASSERT(source.is(esi)); |
| 899 | ASSERT(destination.is(edi)); |
| 900 | ASSERT(length.is(ecx)); |
| 901 | |
| 902 | // Because source is 4-byte aligned in our uses of this function, |
| 903 | // we keep source aligned for the rep_movs call by copying the odd bytes |
| 904 | // at the end of the ranges. |
| 905 | mov(scratch, Operand(source, length, times_1, -4)); |
| 906 | mov(Operand(destination, length, times_1, -4), scratch); |
| 907 | mov(scratch, ecx); |
| 908 | shr(ecx, 2); |
| 909 | rep_movs(); |
| 910 | and_(Operand(scratch), Immediate(0x3)); |
| 911 | add(destination, Operand(scratch)); |
| 912 | jmp(&done); |
| 913 | |
| 914 | bind(&short_string); |
| 915 | test(length, Operand(length)); |
| 916 | j(zero, &done); |
| 917 | |
| 918 | bind(&short_loop); |
| 919 | mov_b(scratch, Operand(source, 0)); |
| 920 | mov_b(Operand(destination, 0), scratch); |
| 921 | inc(source); |
| 922 | inc(destination); |
| 923 | dec(length); |
| 924 | j(not_zero, &short_loop); |
| 925 | |
| 926 | bind(&done); |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 927 | } |
| 928 | |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 929 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 930 | void MacroAssembler::NegativeZeroTest(CodeGenerator* cgen, |
| 931 | Register result, |
| 932 | Register op, |
| 933 | JumpTarget* then_target) { |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 934 | JumpTarget ok; |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 935 | test(result, Operand(result)); |
| 936 | ok.Branch(not_zero, taken); |
| 937 | test(op, Operand(op)); |
| 938 | then_target->Branch(sign, not_taken); |
| 939 | ok.Bind(); |
| 940 | } |
| 941 | |
| 942 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 943 | void MacroAssembler::NegativeZeroTest(Register result, |
| 944 | Register op, |
| 945 | Label* then_label) { |
| 946 | Label ok; |
| 947 | test(result, Operand(result)); |
| 948 | j(not_zero, &ok, taken); |
| 949 | test(op, Operand(op)); |
| 950 | j(sign, then_label, not_taken); |
| 951 | bind(&ok); |
| 952 | } |
| 953 | |
| 954 | |
| 955 | void MacroAssembler::NegativeZeroTest(Register result, |
| 956 | Register op1, |
| 957 | Register op2, |
| 958 | Register scratch, |
| 959 | Label* then_label) { |
| 960 | Label ok; |
| 961 | test(result, Operand(result)); |
| 962 | j(not_zero, &ok, taken); |
| 963 | mov(scratch, Operand(op1)); |
| 964 | or_(scratch, Operand(op2)); |
| 965 | j(sign, then_label, not_taken); |
| 966 | bind(&ok); |
| 967 | } |
| 968 | |
| 969 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 970 | void MacroAssembler::TryGetFunctionPrototype(Register function, |
| 971 | Register result, |
| 972 | Register scratch, |
| 973 | Label* miss) { |
| 974 | // Check that the receiver isn't a smi. |
| 975 | test(function, Immediate(kSmiTagMask)); |
| 976 | j(zero, miss, not_taken); |
| 977 | |
| 978 | // Check that the function really is a function. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 979 | CmpObjectType(function, JS_FUNCTION_TYPE, result); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 980 | j(not_equal, miss, not_taken); |
| 981 | |
| 982 | // Make sure that the function has an instance prototype. |
| 983 | Label non_instance; |
| 984 | movzx_b(scratch, FieldOperand(result, Map::kBitFieldOffset)); |
| 985 | test(scratch, Immediate(1 << Map::kHasNonInstancePrototype)); |
| 986 | j(not_zero, &non_instance, not_taken); |
| 987 | |
| 988 | // Get the prototype or initial map from the function. |
| 989 | mov(result, |
| 990 | FieldOperand(function, JSFunction::kPrototypeOrInitialMapOffset)); |
| 991 | |
| 992 | // If the prototype or initial map is the hole, don't return it and |
| 993 | // simply miss the cache instead. This will allow us to allocate a |
| 994 | // prototype object on-demand in the runtime system. |
| 995 | cmp(Operand(result), Immediate(Factory::the_hole_value())); |
| 996 | j(equal, miss, not_taken); |
| 997 | |
| 998 | // If the function does not have an initial map, we're done. |
| 999 | Label done; |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1000 | CmpObjectType(result, MAP_TYPE, scratch); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1001 | j(not_equal, &done); |
| 1002 | |
| 1003 | // Get the prototype from the initial map. |
| 1004 | mov(result, FieldOperand(result, Map::kPrototypeOffset)); |
| 1005 | jmp(&done); |
| 1006 | |
| 1007 | // Non-instance prototype: Fetch prototype from constructor field |
| 1008 | // in initial map. |
| 1009 | bind(&non_instance); |
| 1010 | mov(result, FieldOperand(result, Map::kConstructorOffset)); |
| 1011 | |
| 1012 | // All done. |
| 1013 | bind(&done); |
| 1014 | } |
| 1015 | |
| 1016 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1017 | void MacroAssembler::CallStub(CodeStub* stub) { |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 1018 | ASSERT(allow_stub_calls()); // Calls are not allowed in some stubs. |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 1019 | call(stub->GetCode(), RelocInfo::CODE_TARGET); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1020 | } |
| 1021 | |
| 1022 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1023 | MaybeObject* MacroAssembler::TryCallStub(CodeStub* stub) { |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 1024 | ASSERT(allow_stub_calls()); // Calls are not allowed in some stubs. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1025 | Object* result; |
| 1026 | { MaybeObject* maybe_result = stub->TryGetCode(); |
| 1027 | if (!maybe_result->ToObject(&result)) return maybe_result; |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 1028 | } |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1029 | call(Handle<Code>(Code::cast(result)), RelocInfo::CODE_TARGET); |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 1030 | return result; |
| 1031 | } |
| 1032 | |
| 1033 | |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 1034 | void MacroAssembler::TailCallStub(CodeStub* stub) { |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 1035 | ASSERT(allow_stub_calls()); // Calls are not allowed in some stubs. |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 1036 | jmp(stub->GetCode(), RelocInfo::CODE_TARGET); |
| 1037 | } |
| 1038 | |
| 1039 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1040 | MaybeObject* MacroAssembler::TryTailCallStub(CodeStub* stub) { |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 1041 | ASSERT(allow_stub_calls()); // Calls are not allowed in some stubs. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1042 | Object* result; |
| 1043 | { MaybeObject* maybe_result = stub->TryGetCode(); |
| 1044 | if (!maybe_result->ToObject(&result)) return maybe_result; |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 1045 | } |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1046 | jmp(Handle<Code>(Code::cast(result)), RelocInfo::CODE_TARGET); |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 1047 | return result; |
| 1048 | } |
| 1049 | |
| 1050 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1051 | void MacroAssembler::StubReturn(int argc) { |
| 1052 | ASSERT(argc >= 1 && generating_stub()); |
| 1053 | ret((argc - 1) * kPointerSize); |
| 1054 | } |
| 1055 | |
| 1056 | |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 1057 | void MacroAssembler::IllegalOperation(int num_arguments) { |
| 1058 | if (num_arguments > 0) { |
| 1059 | add(Operand(esp), Immediate(num_arguments * kPointerSize)); |
| 1060 | } |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 1061 | mov(eax, Immediate(Factory::undefined_value())); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1062 | } |
| 1063 | |
| 1064 | |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1065 | void MacroAssembler::IndexFromHash(Register hash, Register index) { |
| 1066 | // The assert checks that the constants for the maximum number of digits |
| 1067 | // for an array index cached in the hash field and the number of bits |
| 1068 | // reserved for it does not conflict. |
| 1069 | ASSERT(TenToThe(String::kMaxCachedArrayIndexLength) < |
| 1070 | (1 << String::kArrayIndexValueBits)); |
| 1071 | // We want the smi-tagged index in key. kArrayIndexValueMask has zeros in |
| 1072 | // the low kHashShift bits. |
| 1073 | and_(hash, String::kArrayIndexValueMask); |
| 1074 | STATIC_ASSERT(String::kHashShift >= kSmiTagSize && kSmiTag == 0); |
| 1075 | if (String::kHashShift > kSmiTagSize) { |
| 1076 | shr(hash, String::kHashShift - kSmiTagSize); |
| 1077 | } |
| 1078 | if (!index.is(hash)) { |
| 1079 | mov(index, hash); |
| 1080 | } |
| 1081 | } |
| 1082 | |
| 1083 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1084 | void MacroAssembler::CallRuntime(Runtime::FunctionId id, int num_arguments) { |
| 1085 | CallRuntime(Runtime::FunctionForId(id), num_arguments); |
| 1086 | } |
| 1087 | |
| 1088 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1089 | void MacroAssembler::CallRuntimeSaveDoubles(Runtime::FunctionId id) { |
| 1090 | Runtime::Function* function = Runtime::FunctionForId(id); |
| 1091 | Set(eax, Immediate(function->nargs)); |
| 1092 | mov(ebx, Immediate(ExternalReference(function))); |
| 1093 | CEntryStub ces(1); |
| 1094 | ces.SaveDoubles(); |
| 1095 | CallStub(&ces); |
| 1096 | } |
| 1097 | |
| 1098 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1099 | MaybeObject* MacroAssembler::TryCallRuntime(Runtime::FunctionId id, |
| 1100 | int num_arguments) { |
kmillikin@chromium.org | 2d5475f | 2009-12-20 18:15:52 +0000 | [diff] [blame] | 1101 | return TryCallRuntime(Runtime::FunctionForId(id), num_arguments); |
| 1102 | } |
| 1103 | |
| 1104 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1105 | void MacroAssembler::CallRuntime(Runtime::Function* f, int num_arguments) { |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 1106 | // If the expected number of arguments of the runtime function is |
| 1107 | // constant, we check that the actual number of arguments match the |
| 1108 | // expectation. |
| 1109 | if (f->nargs >= 0 && f->nargs != num_arguments) { |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 1110 | IllegalOperation(num_arguments); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1111 | return; |
| 1112 | } |
| 1113 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1114 | // TODO(1236192): Most runtime routines don't need the number of |
| 1115 | // arguments passed in because it is constant. At some point we |
| 1116 | // should remove this need and make the runtime routine entry code |
| 1117 | // smarter. |
| 1118 | Set(eax, Immediate(num_arguments)); |
| 1119 | mov(ebx, Immediate(ExternalReference(f))); |
| 1120 | CEntryStub ces(1); |
| 1121 | CallStub(&ces); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1122 | } |
| 1123 | |
| 1124 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1125 | MaybeObject* MacroAssembler::TryCallRuntime(Runtime::Function* f, |
| 1126 | int num_arguments) { |
kmillikin@chromium.org | 2d5475f | 2009-12-20 18:15:52 +0000 | [diff] [blame] | 1127 | if (f->nargs >= 0 && f->nargs != num_arguments) { |
| 1128 | IllegalOperation(num_arguments); |
| 1129 | // Since we did not call the stub, there was no allocation failure. |
| 1130 | // Return some non-failure object. |
| 1131 | return Heap::undefined_value(); |
| 1132 | } |
| 1133 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1134 | // TODO(1236192): Most runtime routines don't need the number of |
| 1135 | // arguments passed in because it is constant. At some point we |
| 1136 | // should remove this need and make the runtime routine entry code |
| 1137 | // smarter. |
| 1138 | Set(eax, Immediate(num_arguments)); |
| 1139 | mov(ebx, Immediate(ExternalReference(f))); |
| 1140 | CEntryStub ces(1); |
| 1141 | return TryCallStub(&ces); |
kmillikin@chromium.org | 2d5475f | 2009-12-20 18:15:52 +0000 | [diff] [blame] | 1142 | } |
| 1143 | |
| 1144 | |
whesse@chromium.org | e90029b | 2010-08-02 11:52:17 +0000 | [diff] [blame] | 1145 | void MacroAssembler::CallExternalReference(ExternalReference ref, |
| 1146 | int num_arguments) { |
| 1147 | mov(eax, Immediate(num_arguments)); |
| 1148 | mov(ebx, Immediate(ref)); |
| 1149 | |
| 1150 | CEntryStub stub(1); |
| 1151 | CallStub(&stub); |
| 1152 | } |
| 1153 | |
| 1154 | |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 1155 | void MacroAssembler::TailCallExternalReference(const ExternalReference& ext, |
| 1156 | int num_arguments, |
| 1157 | int result_size) { |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 1158 | // TODO(1236192): Most runtime routines don't need the number of |
| 1159 | // arguments passed in because it is constant. At some point we |
| 1160 | // should remove this need and make the runtime routine entry code |
| 1161 | // smarter. |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 1162 | Set(eax, Immediate(num_arguments)); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 1163 | JumpToExternalReference(ext); |
| 1164 | } |
| 1165 | |
| 1166 | |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 1167 | MaybeObject* MacroAssembler::TryTailCallExternalReference( |
| 1168 | const ExternalReference& ext, int num_arguments, int result_size) { |
| 1169 | // TODO(1236192): Most runtime routines don't need the number of |
| 1170 | // arguments passed in because it is constant. At some point we |
| 1171 | // should remove this need and make the runtime routine entry code |
| 1172 | // smarter. |
| 1173 | Set(eax, Immediate(num_arguments)); |
| 1174 | return TryJumpToExternalReference(ext); |
| 1175 | } |
| 1176 | |
| 1177 | |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 1178 | void MacroAssembler::TailCallRuntime(Runtime::FunctionId fid, |
| 1179 | int num_arguments, |
| 1180 | int result_size) { |
| 1181 | TailCallExternalReference(ExternalReference(fid), num_arguments, result_size); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1182 | } |
| 1183 | |
| 1184 | |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 1185 | MaybeObject* MacroAssembler::TryTailCallRuntime(Runtime::FunctionId fid, |
| 1186 | int num_arguments, |
| 1187 | int result_size) { |
| 1188 | return TryTailCallExternalReference( |
| 1189 | ExternalReference(fid), num_arguments, result_size); |
| 1190 | } |
| 1191 | |
| 1192 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1193 | // If true, a Handle<T> returned by value from a function with cdecl calling |
| 1194 | // convention will be returned directly as a value of location_ field in a |
| 1195 | // register eax. |
| 1196 | // If false, it is returned as a pointer to a preallocated by caller memory |
| 1197 | // region. Pointer to this region should be passed to a function as an |
| 1198 | // implicit first argument. |
| 1199 | #if defined(USING_BSD_ABI) || defined(__MINGW32__) |
| 1200 | static const bool kReturnHandlesDirectly = true; |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1201 | #else |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1202 | static const bool kReturnHandlesDirectly = false; |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1203 | #endif |
| 1204 | |
| 1205 | |
| 1206 | Operand ApiParameterOperand(int index) { |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1207 | return Operand( |
| 1208 | esp, (index + (kReturnHandlesDirectly ? 0 : 1)) * kPointerSize); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1209 | } |
| 1210 | |
| 1211 | |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 1212 | void MacroAssembler::PrepareCallApiFunction(int argc, Register scratch) { |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1213 | if (kReturnHandlesDirectly) { |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 1214 | EnterApiExitFrame(argc); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1215 | // When handles are returned directly we don't have to allocate extra |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1216 | // space for and pass an out parameter. |
| 1217 | } else { |
| 1218 | // We allocate two additional slots: return value and pointer to it. |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 1219 | EnterApiExitFrame(argc + 2); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1220 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1221 | // The argument slots are filled as follows: |
| 1222 | // |
| 1223 | // n + 1: output cell |
| 1224 | // n: arg n |
| 1225 | // ... |
| 1226 | // 1: arg1 |
| 1227 | // 0: pointer to the output cell |
| 1228 | // |
| 1229 | // Note that this is one more "argument" than the function expects |
| 1230 | // so the out cell will have to be popped explicitly after returning |
| 1231 | // from the function. The out cell contains Handle. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1232 | |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 1233 | // pointer to out cell. |
| 1234 | lea(scratch, Operand(esp, (argc + 1) * kPointerSize)); |
| 1235 | mov(Operand(esp, 0 * kPointerSize), scratch); // output. |
| 1236 | if (FLAG_debug_code) { |
| 1237 | mov(Operand(esp, (argc + 1) * kPointerSize), Immediate(0)); // out cell. |
| 1238 | } |
| 1239 | } |
| 1240 | } |
| 1241 | |
| 1242 | |
| 1243 | MaybeObject* MacroAssembler::TryCallApiFunctionAndReturn(ApiFunction* function, |
| 1244 | int stack_space) { |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1245 | ExternalReference next_address = |
| 1246 | ExternalReference::handle_scope_next_address(); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1247 | ExternalReference limit_address = |
| 1248 | ExternalReference::handle_scope_limit_address(); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1249 | ExternalReference level_address = |
| 1250 | ExternalReference::handle_scope_level_address(); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1251 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1252 | // Allocate HandleScope in callee-save registers. |
| 1253 | mov(ebx, Operand::StaticVariable(next_address)); |
| 1254 | mov(edi, Operand::StaticVariable(limit_address)); |
| 1255 | add(Operand::StaticVariable(level_address), Immediate(1)); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1256 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1257 | // Call the api function! |
| 1258 | call(function->address(), RelocInfo::RUNTIME_ENTRY); |
| 1259 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1260 | if (!kReturnHandlesDirectly) { |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1261 | // The returned value is a pointer to the handle holding the result. |
| 1262 | // Dereference this to get to the location. |
| 1263 | mov(eax, Operand(eax, 0)); |
kmillikin@chromium.org | 2d5475f | 2009-12-20 18:15:52 +0000 | [diff] [blame] | 1264 | } |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1265 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1266 | Label empty_handle; |
| 1267 | Label prologue; |
| 1268 | Label promote_scheduled_exception; |
| 1269 | Label delete_allocated_handles; |
| 1270 | Label leave_exit_frame; |
kmillikin@chromium.org | 2d5475f | 2009-12-20 18:15:52 +0000 | [diff] [blame] | 1271 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1272 | // Check if the result handle holds 0. |
| 1273 | test(eax, Operand(eax)); |
| 1274 | j(zero, &empty_handle, not_taken); |
| 1275 | // It was non-zero. Dereference to get the result value. |
| 1276 | mov(eax, Operand(eax, 0)); |
| 1277 | bind(&prologue); |
| 1278 | // No more valid handles (the result handle was the last one). Restore |
| 1279 | // previous handle scope. |
| 1280 | mov(Operand::StaticVariable(next_address), ebx); |
| 1281 | sub(Operand::StaticVariable(level_address), Immediate(1)); |
| 1282 | Assert(above_equal, "Invalid HandleScope level"); |
| 1283 | cmp(edi, Operand::StaticVariable(limit_address)); |
| 1284 | j(not_equal, &delete_allocated_handles, not_taken); |
| 1285 | bind(&leave_exit_frame); |
kmillikin@chromium.org | 2d5475f | 2009-12-20 18:15:52 +0000 | [diff] [blame] | 1286 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1287 | // Check if the function scheduled an exception. |
| 1288 | ExternalReference scheduled_exception_address = |
| 1289 | ExternalReference::scheduled_exception_address(); |
| 1290 | cmp(Operand::StaticVariable(scheduled_exception_address), |
| 1291 | Immediate(Factory::the_hole_value())); |
| 1292 | j(not_equal, &promote_scheduled_exception, not_taken); |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 1293 | LeaveApiExitFrame(); |
| 1294 | ret(stack_space * kPointerSize); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1295 | bind(&promote_scheduled_exception); |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 1296 | MaybeObject* result = |
| 1297 | TryTailCallRuntime(Runtime::kPromoteScheduledException, 0, 1); |
| 1298 | if (result->IsFailure()) { |
| 1299 | return result; |
| 1300 | } |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1301 | bind(&empty_handle); |
| 1302 | // It was zero; the result is undefined. |
| 1303 | mov(eax, Factory::undefined_value()); |
| 1304 | jmp(&prologue); |
kmillikin@chromium.org | 2d5475f | 2009-12-20 18:15:52 +0000 | [diff] [blame] | 1305 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1306 | // HandleScope limit has changed. Delete allocated extensions. |
| 1307 | bind(&delete_allocated_handles); |
| 1308 | mov(Operand::StaticVariable(limit_address), edi); |
| 1309 | mov(edi, eax); |
| 1310 | mov(eax, Immediate(ExternalReference::delete_handle_scope_extensions())); |
| 1311 | call(Operand(eax)); |
| 1312 | mov(eax, edi); |
| 1313 | jmp(&leave_exit_frame); |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 1314 | |
| 1315 | return result; |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1316 | } |
| 1317 | |
| 1318 | |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 1319 | void MacroAssembler::JumpToExternalReference(const ExternalReference& ext) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1320 | // Set the entry point and jump to the C entry runtime stub. |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 1321 | mov(ebx, Immediate(ext)); |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 1322 | CEntryStub ces(1); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 1323 | jmp(ces.GetCode(), RelocInfo::CODE_TARGET); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1324 | } |
| 1325 | |
| 1326 | |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 1327 | MaybeObject* MacroAssembler::TryJumpToExternalReference( |
| 1328 | const ExternalReference& ext) { |
| 1329 | // Set the entry point and jump to the C entry runtime stub. |
| 1330 | mov(ebx, Immediate(ext)); |
| 1331 | CEntryStub ces(1); |
| 1332 | return TryTailCallStub(&ces); |
| 1333 | } |
| 1334 | |
| 1335 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1336 | void MacroAssembler::InvokePrologue(const ParameterCount& expected, |
| 1337 | const ParameterCount& actual, |
| 1338 | Handle<Code> code_constant, |
| 1339 | const Operand& code_operand, |
| 1340 | Label* done, |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1341 | InvokeFlag flag, |
| 1342 | PostCallGenerator* post_call_generator) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1343 | bool definitely_matches = false; |
| 1344 | Label invoke; |
| 1345 | if (expected.is_immediate()) { |
| 1346 | ASSERT(actual.is_immediate()); |
| 1347 | if (expected.immediate() == actual.immediate()) { |
| 1348 | definitely_matches = true; |
| 1349 | } else { |
| 1350 | mov(eax, actual.immediate()); |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 1351 | const int sentinel = SharedFunctionInfo::kDontAdaptArgumentsSentinel; |
| 1352 | if (expected.immediate() == sentinel) { |
| 1353 | // Don't worry about adapting arguments for builtins that |
| 1354 | // don't want that done. Skip adaption code by making it look |
| 1355 | // like we have a match between expected and actual number of |
| 1356 | // arguments. |
| 1357 | definitely_matches = true; |
| 1358 | } else { |
| 1359 | mov(ebx, expected.immediate()); |
| 1360 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1361 | } |
| 1362 | } else { |
| 1363 | if (actual.is_immediate()) { |
| 1364 | // Expected is in register, actual is immediate. This is the |
| 1365 | // case when we invoke function values without going through the |
| 1366 | // IC mechanism. |
| 1367 | cmp(expected.reg(), actual.immediate()); |
| 1368 | j(equal, &invoke); |
| 1369 | ASSERT(expected.reg().is(ebx)); |
| 1370 | mov(eax, actual.immediate()); |
| 1371 | } else if (!expected.reg().is(actual.reg())) { |
| 1372 | // Both expected and actual are in (different) registers. This |
| 1373 | // is the case when we invoke functions using call and apply. |
| 1374 | cmp(expected.reg(), Operand(actual.reg())); |
| 1375 | j(equal, &invoke); |
| 1376 | ASSERT(actual.reg().is(eax)); |
| 1377 | ASSERT(expected.reg().is(ebx)); |
| 1378 | } |
| 1379 | } |
| 1380 | |
| 1381 | if (!definitely_matches) { |
| 1382 | Handle<Code> adaptor = |
| 1383 | Handle<Code>(Builtins::builtin(Builtins::ArgumentsAdaptorTrampoline)); |
| 1384 | if (!code_constant.is_null()) { |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 1385 | mov(edx, Immediate(code_constant)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1386 | add(Operand(edx), Immediate(Code::kHeaderSize - kHeapObjectTag)); |
| 1387 | } else if (!code_operand.is_reg(edx)) { |
| 1388 | mov(edx, code_operand); |
| 1389 | } |
| 1390 | |
| 1391 | if (flag == CALL_FUNCTION) { |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 1392 | call(adaptor, RelocInfo::CODE_TARGET); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1393 | if (post_call_generator != NULL) post_call_generator->Generate(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1394 | jmp(done); |
| 1395 | } else { |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 1396 | jmp(adaptor, RelocInfo::CODE_TARGET); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1397 | } |
| 1398 | bind(&invoke); |
| 1399 | } |
| 1400 | } |
| 1401 | |
| 1402 | |
| 1403 | void MacroAssembler::InvokeCode(const Operand& code, |
| 1404 | const ParameterCount& expected, |
| 1405 | const ParameterCount& actual, |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1406 | InvokeFlag flag, |
| 1407 | PostCallGenerator* post_call_generator) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1408 | Label done; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1409 | InvokePrologue(expected, actual, Handle<Code>::null(), code, |
| 1410 | &done, flag, post_call_generator); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1411 | if (flag == CALL_FUNCTION) { |
| 1412 | call(code); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1413 | if (post_call_generator != NULL) post_call_generator->Generate(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1414 | } else { |
| 1415 | ASSERT(flag == JUMP_FUNCTION); |
| 1416 | jmp(code); |
| 1417 | } |
| 1418 | bind(&done); |
| 1419 | } |
| 1420 | |
| 1421 | |
| 1422 | void MacroAssembler::InvokeCode(Handle<Code> code, |
| 1423 | const ParameterCount& expected, |
| 1424 | const ParameterCount& actual, |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 1425 | RelocInfo::Mode rmode, |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1426 | InvokeFlag flag, |
| 1427 | PostCallGenerator* post_call_generator) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1428 | Label done; |
| 1429 | Operand dummy(eax); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1430 | InvokePrologue(expected, actual, code, dummy, &done, |
| 1431 | flag, post_call_generator); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1432 | if (flag == CALL_FUNCTION) { |
| 1433 | call(code, rmode); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1434 | if (post_call_generator != NULL) post_call_generator->Generate(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1435 | } else { |
| 1436 | ASSERT(flag == JUMP_FUNCTION); |
| 1437 | jmp(code, rmode); |
| 1438 | } |
| 1439 | bind(&done); |
| 1440 | } |
| 1441 | |
| 1442 | |
| 1443 | void MacroAssembler::InvokeFunction(Register fun, |
| 1444 | const ParameterCount& actual, |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1445 | InvokeFlag flag, |
| 1446 | PostCallGenerator* post_call_generator) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1447 | ASSERT(fun.is(edi)); |
| 1448 | mov(edx, FieldOperand(edi, JSFunction::kSharedFunctionInfoOffset)); |
| 1449 | mov(esi, FieldOperand(edi, JSFunction::kContextOffset)); |
| 1450 | mov(ebx, FieldOperand(edx, SharedFunctionInfo::kFormalParameterCountOffset)); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 1451 | SmiUntag(ebx); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1452 | |
| 1453 | ParameterCount expected(ebx); |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 1454 | InvokeCode(FieldOperand(edi, JSFunction::kCodeEntryOffset), |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1455 | expected, actual, flag, post_call_generator); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1456 | } |
| 1457 | |
| 1458 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1459 | void MacroAssembler::InvokeFunction(JSFunction* function, |
| 1460 | const ParameterCount& actual, |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1461 | InvokeFlag flag, |
| 1462 | PostCallGenerator* post_call_generator) { |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1463 | ASSERT(function->is_compiled()); |
| 1464 | // Get the function and setup the context. |
| 1465 | mov(edi, Immediate(Handle<JSFunction>(function))); |
| 1466 | mov(esi, FieldOperand(edi, JSFunction::kContextOffset)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1467 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1468 | ParameterCount expected(function->shared()->formal_parameter_count()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1469 | if (V8::UseCrankshaft()) { |
| 1470 | // TODO(kasperl): For now, we always call indirectly through the |
| 1471 | // code field in the function to allow recompilation to take effect |
| 1472 | // without changing any of the call sites. |
| 1473 | InvokeCode(FieldOperand(edi, JSFunction::kCodeEntryOffset), |
| 1474 | expected, actual, flag, post_call_generator); |
| 1475 | } else { |
| 1476 | Handle<Code> code(function->code()); |
| 1477 | InvokeCode(code, expected, actual, RelocInfo::CODE_TARGET, |
| 1478 | flag, post_call_generator); |
| 1479 | } |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1480 | } |
| 1481 | |
| 1482 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1483 | void MacroAssembler::InvokeBuiltin(Builtins::JavaScript id, |
| 1484 | InvokeFlag flag, |
| 1485 | PostCallGenerator* post_call_generator) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1486 | // Calls are not allowed in some stubs. |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 1487 | ASSERT(flag == JUMP_FUNCTION || allow_stub_calls()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1488 | |
| 1489 | // Rely on the assertion to check that the number of provided |
| 1490 | // arguments match the expected number of arguments. Fake a |
| 1491 | // parameter count to avoid emitting code to do the check. |
| 1492 | ParameterCount expected(0); |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 1493 | GetBuiltinFunction(edi, id); |
| 1494 | InvokeCode(FieldOperand(edi, JSFunction::kCodeEntryOffset), |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1495 | expected, expected, flag, post_call_generator); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1496 | } |
| 1497 | |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 1498 | void MacroAssembler::GetBuiltinFunction(Register target, |
| 1499 | Builtins::JavaScript id) { |
| 1500 | // Load the JavaScript builtin function from the builtins object. |
| 1501 | mov(target, Operand(esi, Context::SlotOffset(Context::GLOBAL_INDEX))); |
| 1502 | mov(target, FieldOperand(target, GlobalObject::kBuiltinsOffset)); |
| 1503 | mov(target, FieldOperand(target, |
| 1504 | JSBuiltinsObject::OffsetOfFunctionWithId(id))); |
| 1505 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1506 | |
| 1507 | void MacroAssembler::GetBuiltinEntry(Register target, Builtins::JavaScript id) { |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 1508 | ASSERT(!target.is(edi)); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1509 | // Load the JavaScript builtin function from the builtins object. |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 1510 | GetBuiltinFunction(edi, id); |
| 1511 | // Load the code entry point from the function into the target register. |
| 1512 | mov(target, FieldOperand(edi, JSFunction::kCodeEntryOffset)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1513 | } |
| 1514 | |
| 1515 | |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 1516 | void MacroAssembler::LoadContext(Register dst, int context_chain_length) { |
| 1517 | if (context_chain_length > 0) { |
| 1518 | // Move up the chain of contexts to the context containing the slot. |
| 1519 | mov(dst, Operand(esi, Context::SlotOffset(Context::CLOSURE_INDEX))); |
| 1520 | // Load the function context (which is the incoming, outer context). |
| 1521 | mov(dst, FieldOperand(dst, JSFunction::kContextOffset)); |
| 1522 | for (int i = 1; i < context_chain_length; i++) { |
| 1523 | mov(dst, Operand(dst, Context::SlotOffset(Context::CLOSURE_INDEX))); |
| 1524 | mov(dst, FieldOperand(dst, JSFunction::kContextOffset)); |
| 1525 | } |
| 1526 | // The context may be an intermediate context, not a function context. |
| 1527 | mov(dst, Operand(dst, Context::SlotOffset(Context::FCONTEXT_INDEX))); |
| 1528 | } else { // Slot is in the current function context. |
| 1529 | // The context may be an intermediate context, not a function context. |
| 1530 | mov(dst, Operand(esi, Context::SlotOffset(Context::FCONTEXT_INDEX))); |
| 1531 | } |
| 1532 | } |
| 1533 | |
| 1534 | |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1535 | void MacroAssembler::LoadGlobalFunction(int index, Register function) { |
| 1536 | // Load the global or builtins object from the current context. |
| 1537 | mov(function, Operand(esi, Context::SlotOffset(Context::GLOBAL_INDEX))); |
| 1538 | // Load the global context from the global or builtins object. |
| 1539 | mov(function, FieldOperand(function, GlobalObject::kGlobalContextOffset)); |
| 1540 | // Load the function from the global context. |
| 1541 | mov(function, Operand(function, Context::SlotOffset(index))); |
| 1542 | } |
| 1543 | |
| 1544 | |
| 1545 | void MacroAssembler::LoadGlobalFunctionInitialMap(Register function, |
| 1546 | Register map) { |
| 1547 | // Load the initial map. The global functions all have initial maps. |
| 1548 | mov(map, FieldOperand(function, JSFunction::kPrototypeOrInitialMapOffset)); |
| 1549 | if (FLAG_debug_code) { |
| 1550 | Label ok, fail; |
| 1551 | CheckMap(map, Factory::meta_map(), &fail, false); |
| 1552 | jmp(&ok); |
| 1553 | bind(&fail); |
| 1554 | Abort("Global functions must have initial map"); |
| 1555 | bind(&ok); |
| 1556 | } |
| 1557 | } |
| 1558 | |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 1559 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1560 | int MacroAssembler::SafepointRegisterStackIndex(int reg_code) { |
| 1561 | // The registers are pushed starting with the lowest encoding, |
| 1562 | // which means that lowest encodings are furthest away from |
| 1563 | // the stack pointer. |
| 1564 | ASSERT(reg_code >= 0 && reg_code < kNumSafepointRegisters); |
| 1565 | return kNumSafepointRegisters - reg_code - 1; |
| 1566 | } |
| 1567 | |
| 1568 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1569 | void MacroAssembler::Ret() { |
| 1570 | ret(0); |
| 1571 | } |
| 1572 | |
| 1573 | |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 1574 | void MacroAssembler::Drop(int stack_elements) { |
| 1575 | if (stack_elements > 0) { |
| 1576 | add(Operand(esp), Immediate(stack_elements * kPointerSize)); |
| 1577 | } |
| 1578 | } |
| 1579 | |
| 1580 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1581 | void MacroAssembler::Move(Register dst, Register src) { |
| 1582 | if (!dst.is(src)) { |
| 1583 | mov(dst, src); |
| 1584 | } |
| 1585 | } |
| 1586 | |
| 1587 | |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 1588 | void MacroAssembler::Move(Register dst, Handle<Object> value) { |
| 1589 | mov(dst, value); |
| 1590 | } |
| 1591 | |
| 1592 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1593 | void MacroAssembler::SetCounter(StatsCounter* counter, int value) { |
| 1594 | if (FLAG_native_code_counters && counter->Enabled()) { |
| 1595 | mov(Operand::StaticVariable(ExternalReference(counter)), Immediate(value)); |
| 1596 | } |
| 1597 | } |
| 1598 | |
| 1599 | |
| 1600 | void MacroAssembler::IncrementCounter(StatsCounter* counter, int value) { |
| 1601 | ASSERT(value > 0); |
| 1602 | if (FLAG_native_code_counters && counter->Enabled()) { |
| 1603 | Operand operand = Operand::StaticVariable(ExternalReference(counter)); |
| 1604 | if (value == 1) { |
| 1605 | inc(operand); |
| 1606 | } else { |
| 1607 | add(operand, Immediate(value)); |
| 1608 | } |
| 1609 | } |
| 1610 | } |
| 1611 | |
| 1612 | |
| 1613 | void MacroAssembler::DecrementCounter(StatsCounter* counter, int value) { |
| 1614 | ASSERT(value > 0); |
| 1615 | if (FLAG_native_code_counters && counter->Enabled()) { |
| 1616 | Operand operand = Operand::StaticVariable(ExternalReference(counter)); |
| 1617 | if (value == 1) { |
| 1618 | dec(operand); |
| 1619 | } else { |
| 1620 | sub(operand, Immediate(value)); |
| 1621 | } |
| 1622 | } |
| 1623 | } |
| 1624 | |
| 1625 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1626 | void MacroAssembler::IncrementCounter(Condition cc, |
| 1627 | StatsCounter* counter, |
| 1628 | int value) { |
| 1629 | ASSERT(value > 0); |
| 1630 | if (FLAG_native_code_counters && counter->Enabled()) { |
| 1631 | Label skip; |
| 1632 | j(NegateCondition(cc), &skip); |
| 1633 | pushfd(); |
| 1634 | IncrementCounter(counter, value); |
| 1635 | popfd(); |
| 1636 | bind(&skip); |
| 1637 | } |
| 1638 | } |
| 1639 | |
| 1640 | |
| 1641 | void MacroAssembler::DecrementCounter(Condition cc, |
| 1642 | StatsCounter* counter, |
| 1643 | int value) { |
| 1644 | ASSERT(value > 0); |
| 1645 | if (FLAG_native_code_counters && counter->Enabled()) { |
| 1646 | Label skip; |
| 1647 | j(NegateCondition(cc), &skip); |
| 1648 | pushfd(); |
| 1649 | DecrementCounter(counter, value); |
| 1650 | popfd(); |
| 1651 | bind(&skip); |
| 1652 | } |
| 1653 | } |
| 1654 | |
| 1655 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1656 | void MacroAssembler::Assert(Condition cc, const char* msg) { |
| 1657 | if (FLAG_debug_code) Check(cc, msg); |
| 1658 | } |
| 1659 | |
| 1660 | |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 1661 | void MacroAssembler::AssertFastElements(Register elements) { |
| 1662 | if (FLAG_debug_code) { |
| 1663 | Label ok; |
| 1664 | cmp(FieldOperand(elements, HeapObject::kMapOffset), |
| 1665 | Immediate(Factory::fixed_array_map())); |
| 1666 | j(equal, &ok); |
| 1667 | cmp(FieldOperand(elements, HeapObject::kMapOffset), |
| 1668 | Immediate(Factory::fixed_cow_array_map())); |
| 1669 | j(equal, &ok); |
| 1670 | Abort("JSObject with fast elements map has slow elements"); |
| 1671 | bind(&ok); |
| 1672 | } |
| 1673 | } |
| 1674 | |
| 1675 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1676 | void MacroAssembler::Check(Condition cc, const char* msg) { |
| 1677 | Label L; |
| 1678 | j(cc, &L, taken); |
| 1679 | Abort(msg); |
| 1680 | // will not return here |
| 1681 | bind(&L); |
| 1682 | } |
| 1683 | |
| 1684 | |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 1685 | void MacroAssembler::CheckStackAlignment() { |
| 1686 | int frame_alignment = OS::ActivationFrameAlignment(); |
| 1687 | int frame_alignment_mask = frame_alignment - 1; |
| 1688 | if (frame_alignment > kPointerSize) { |
| 1689 | ASSERT(IsPowerOf2(frame_alignment)); |
| 1690 | Label alignment_as_expected; |
| 1691 | test(esp, Immediate(frame_alignment_mask)); |
| 1692 | j(zero, &alignment_as_expected); |
| 1693 | // Abort if stack is not aligned. |
| 1694 | int3(); |
| 1695 | bind(&alignment_as_expected); |
| 1696 | } |
| 1697 | } |
| 1698 | |
| 1699 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1700 | void MacroAssembler::Abort(const char* msg) { |
| 1701 | // We want to pass the msg string like a smi to avoid GC |
| 1702 | // problems, however msg is not guaranteed to be aligned |
| 1703 | // properly. Instead, we pass an aligned pointer that is |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 1704 | // a proper v8 smi, but also pass the alignment difference |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1705 | // from the real pointer as a smi. |
| 1706 | intptr_t p1 = reinterpret_cast<intptr_t>(msg); |
| 1707 | intptr_t p0 = (p1 & ~kSmiTagMask) + kSmiTag; |
| 1708 | ASSERT(reinterpret_cast<Object*>(p0)->IsSmi()); |
| 1709 | #ifdef DEBUG |
| 1710 | if (msg != NULL) { |
| 1711 | RecordComment("Abort message: "); |
| 1712 | RecordComment(msg); |
| 1713 | } |
| 1714 | #endif |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 1715 | // Disable stub call restrictions to always allow calls to abort. |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 1716 | AllowStubCallsScope allow_scope(this, true); |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 1717 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1718 | push(eax); |
| 1719 | push(Immediate(p0)); |
| 1720 | push(Immediate(reinterpret_cast<intptr_t>(Smi::FromInt(p1 - p0)))); |
| 1721 | CallRuntime(Runtime::kAbort, 2); |
| 1722 | // will not return here |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 1723 | int3(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1724 | } |
| 1725 | |
| 1726 | |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 1727 | void MacroAssembler::JumpIfNotNumber(Register reg, |
| 1728 | TypeInfo info, |
| 1729 | Label* on_not_number) { |
| 1730 | if (FLAG_debug_code) AbortIfSmi(reg); |
| 1731 | if (!info.IsNumber()) { |
| 1732 | cmp(FieldOperand(reg, HeapObject::kMapOffset), |
| 1733 | Factory::heap_number_map()); |
| 1734 | j(not_equal, on_not_number); |
| 1735 | } |
| 1736 | } |
| 1737 | |
| 1738 | |
| 1739 | void MacroAssembler::ConvertToInt32(Register dst, |
| 1740 | Register source, |
| 1741 | Register scratch, |
| 1742 | TypeInfo info, |
| 1743 | Label* on_not_int32) { |
| 1744 | if (FLAG_debug_code) { |
| 1745 | AbortIfSmi(source); |
| 1746 | AbortIfNotNumber(source); |
| 1747 | } |
| 1748 | if (info.IsInteger32()) { |
| 1749 | cvttsd2si(dst, FieldOperand(source, HeapNumber::kValueOffset)); |
| 1750 | } else { |
| 1751 | Label done; |
| 1752 | bool push_pop = (scratch.is(no_reg) && dst.is(source)); |
| 1753 | ASSERT(!scratch.is(source)); |
| 1754 | if (push_pop) { |
| 1755 | push(dst); |
| 1756 | scratch = dst; |
| 1757 | } |
| 1758 | if (scratch.is(no_reg)) scratch = dst; |
| 1759 | cvttsd2si(scratch, FieldOperand(source, HeapNumber::kValueOffset)); |
| 1760 | cmp(scratch, 0x80000000u); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 1761 | if (push_pop) { |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 1762 | j(not_equal, &done); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 1763 | pop(dst); |
| 1764 | jmp(on_not_int32); |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 1765 | } else { |
| 1766 | j(equal, on_not_int32); |
| 1767 | } |
| 1768 | |
| 1769 | bind(&done); |
| 1770 | if (push_pop) { |
| 1771 | add(Operand(esp), Immediate(kPointerSize)); // Pop. |
| 1772 | } |
| 1773 | if (!scratch.is(dst)) { |
| 1774 | mov(dst, scratch); |
| 1775 | } |
| 1776 | } |
| 1777 | } |
| 1778 | |
| 1779 | |
fschneider@chromium.org | c20610a | 2010-09-22 09:44:58 +0000 | [diff] [blame] | 1780 | void MacroAssembler::LoadPowerOf2(XMMRegister dst, |
| 1781 | Register scratch, |
| 1782 | int power) { |
| 1783 | ASSERT(is_uintn(power + HeapNumber::kExponentBias, |
| 1784 | HeapNumber::kExponentBits)); |
| 1785 | mov(scratch, Immediate(power + HeapNumber::kExponentBias)); |
| 1786 | movd(dst, Operand(scratch)); |
| 1787 | psllq(dst, HeapNumber::kMantissaBits); |
| 1788 | } |
| 1789 | |
| 1790 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1791 | void MacroAssembler::JumpIfInstanceTypeIsNotSequentialAscii( |
| 1792 | Register instance_type, |
| 1793 | Register scratch, |
whesse@chromium.org | cec079d | 2010-03-22 14:44:04 +0000 | [diff] [blame] | 1794 | Label* failure) { |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1795 | if (!scratch.is(instance_type)) { |
| 1796 | mov(scratch, instance_type); |
| 1797 | } |
| 1798 | and_(scratch, |
| 1799 | kIsNotStringMask | kStringRepresentationMask | kStringEncodingMask); |
| 1800 | cmp(scratch, kStringTag | kSeqStringTag | kAsciiStringTag); |
| 1801 | j(not_equal, failure); |
| 1802 | } |
| 1803 | |
| 1804 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1805 | void MacroAssembler::JumpIfNotBothSequentialAsciiStrings(Register object1, |
| 1806 | Register object2, |
| 1807 | Register scratch1, |
| 1808 | Register scratch2, |
| 1809 | Label* failure) { |
| 1810 | // Check that both objects are not smis. |
| 1811 | ASSERT_EQ(0, kSmiTag); |
| 1812 | mov(scratch1, Operand(object1)); |
| 1813 | and_(scratch1, Operand(object2)); |
| 1814 | test(scratch1, Immediate(kSmiTagMask)); |
| 1815 | j(zero, failure); |
| 1816 | |
| 1817 | // Load instance type for both strings. |
| 1818 | mov(scratch1, FieldOperand(object1, HeapObject::kMapOffset)); |
| 1819 | mov(scratch2, FieldOperand(object2, HeapObject::kMapOffset)); |
| 1820 | movzx_b(scratch1, FieldOperand(scratch1, Map::kInstanceTypeOffset)); |
| 1821 | movzx_b(scratch2, FieldOperand(scratch2, Map::kInstanceTypeOffset)); |
| 1822 | |
| 1823 | // Check that both are flat ascii strings. |
| 1824 | const int kFlatAsciiStringMask = |
| 1825 | kIsNotStringMask | kStringRepresentationMask | kStringEncodingMask; |
| 1826 | const int kFlatAsciiStringTag = ASCII_STRING_TYPE; |
| 1827 | // Interleave bits from both instance types and compare them in one check. |
| 1828 | ASSERT_EQ(0, kFlatAsciiStringMask & (kFlatAsciiStringMask << 3)); |
| 1829 | and_(scratch1, kFlatAsciiStringMask); |
| 1830 | and_(scratch2, kFlatAsciiStringMask); |
| 1831 | lea(scratch1, Operand(scratch1, scratch2, times_8, 0)); |
| 1832 | cmp(scratch1, kFlatAsciiStringTag | (kFlatAsciiStringTag << 3)); |
| 1833 | j(not_equal, failure); |
| 1834 | } |
| 1835 | |
| 1836 | |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 1837 | void MacroAssembler::PrepareCallCFunction(int num_arguments, Register scratch) { |
| 1838 | int frameAlignment = OS::ActivationFrameAlignment(); |
| 1839 | if (frameAlignment != 0) { |
| 1840 | // Make stack end at alignment and make room for num_arguments words |
| 1841 | // and the original value of esp. |
| 1842 | mov(scratch, esp); |
| 1843 | sub(Operand(esp), Immediate((num_arguments + 1) * kPointerSize)); |
| 1844 | ASSERT(IsPowerOf2(frameAlignment)); |
| 1845 | and_(esp, -frameAlignment); |
| 1846 | mov(Operand(esp, num_arguments * kPointerSize), scratch); |
| 1847 | } else { |
| 1848 | sub(Operand(esp), Immediate(num_arguments * kPointerSize)); |
| 1849 | } |
| 1850 | } |
| 1851 | |
| 1852 | |
| 1853 | void MacroAssembler::CallCFunction(ExternalReference function, |
| 1854 | int num_arguments) { |
| 1855 | // Trashing eax is ok as it will be the return value. |
| 1856 | mov(Operand(eax), Immediate(function)); |
| 1857 | CallCFunction(eax, num_arguments); |
| 1858 | } |
| 1859 | |
| 1860 | |
| 1861 | void MacroAssembler::CallCFunction(Register function, |
| 1862 | int num_arguments) { |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 1863 | // Check stack alignment. |
| 1864 | if (FLAG_debug_code) { |
| 1865 | CheckStackAlignment(); |
| 1866 | } |
| 1867 | |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 1868 | call(Operand(function)); |
| 1869 | if (OS::ActivationFrameAlignment() != 0) { |
| 1870 | mov(esp, Operand(esp, num_arguments * kPointerSize)); |
| 1871 | } else { |
| 1872 | add(Operand(esp), Immediate(num_arguments * sizeof(int32_t))); |
| 1873 | } |
| 1874 | } |
| 1875 | |
| 1876 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1877 | CodePatcher::CodePatcher(byte* address, int size) |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 1878 | : address_(address), size_(size), masm_(address, size + Assembler::kGap) { |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 1879 | // Create a new macro assembler pointing to the address of the code to patch. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1880 | // The size is adjusted with kGap on order for the assembler to generate size |
| 1881 | // bytes of instructions without failing with buffer size constraints. |
| 1882 | ASSERT(masm_.reloc_info_writer.pos() == address_ + size_ + Assembler::kGap); |
| 1883 | } |
| 1884 | |
| 1885 | |
| 1886 | CodePatcher::~CodePatcher() { |
| 1887 | // Indicate that code has changed. |
| 1888 | CPU::FlushICache(address_, size_); |
| 1889 | |
| 1890 | // Check that the code was patched as expected. |
| 1891 | ASSERT(masm_.pc_ == address_ + size_); |
| 1892 | ASSERT(masm_.reloc_info_writer.pos() == address_ + size_ + Assembler::kGap); |
| 1893 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1894 | |
| 1895 | |
| 1896 | } } // namespace v8::internal |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1897 | |
| 1898 | #endif // V8_TARGET_ARCH_IA32 |