ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +0000 | [diff] [blame] | 1 | // Copyright 2009 the V8 project authors. All rights reserved. |
| 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 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 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_X64) |
| 31 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 32 | #include "bootstrapper.h" |
| 33 | #include "codegen-inl.h" |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 34 | #include "assembler-x64.h" |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 35 | #include "macro-assembler-x64.h" |
sgjesse@chromium.org | b9d7da1 | 2009-08-05 08:38:10 +0000 | [diff] [blame] | 36 | #include "serialize.h" |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 37 | #include "debug.h" |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame^] | 38 | #include "heap.h" |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 39 | |
| 40 | namespace v8 { |
| 41 | namespace internal { |
| 42 | |
| 43 | MacroAssembler::MacroAssembler(void* buffer, int size) |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 44 | : Assembler(buffer, size), |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 45 | generating_stub_(false), |
| 46 | allow_stub_calls_(true), |
| 47 | code_object_(Heap::undefined_value()) { |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 48 | } |
| 49 | |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 50 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 51 | void MacroAssembler::LoadRoot(Register destination, Heap::RootListIndex index) { |
whesse@chromium.org | b6e43bb | 2010-04-14 09:36:28 +0000 | [diff] [blame] | 52 | movq(destination, Operand(kRootRegister, index << kPointerSizeLog2)); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 56 | void MacroAssembler::StoreRoot(Register source, Heap::RootListIndex index) { |
| 57 | movq(Operand(kRootRegister, index << kPointerSizeLog2), source); |
| 58 | } |
| 59 | |
| 60 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 61 | void MacroAssembler::PushRoot(Heap::RootListIndex index) { |
whesse@chromium.org | b6e43bb | 2010-04-14 09:36:28 +0000 | [diff] [blame] | 62 | push(Operand(kRootRegister, index << kPointerSizeLog2)); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 66 | void MacroAssembler::CompareRoot(Register with, Heap::RootListIndex index) { |
whesse@chromium.org | b6e43bb | 2010-04-14 09:36:28 +0000 | [diff] [blame] | 67 | cmpq(with, Operand(kRootRegister, index << kPointerSizeLog2)); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 68 | } |
| 69 | |
sgjesse@chromium.org | b9d7da1 | 2009-08-05 08:38:10 +0000 | [diff] [blame] | 70 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 71 | void MacroAssembler::CompareRoot(Operand with, Heap::RootListIndex index) { |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 72 | LoadRoot(kScratchRegister, index); |
| 73 | cmpq(with, kScratchRegister); |
| 74 | } |
| 75 | |
| 76 | |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 77 | void MacroAssembler::StackLimitCheck(Label* on_stack_overflow) { |
| 78 | CompareRoot(rsp, Heap::kStackLimitRootIndex); |
| 79 | j(below, on_stack_overflow); |
| 80 | } |
| 81 | |
| 82 | |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 83 | void MacroAssembler::RecordWriteHelper(Register object, |
| 84 | Register addr, |
| 85 | Register scratch) { |
| 86 | if (FLAG_debug_code) { |
| 87 | // Check that the object is not in new space. |
| 88 | Label not_in_new_space; |
| 89 | InNewSpace(object, scratch, not_equal, ¬_in_new_space); |
| 90 | Abort("new-space object passed to RecordWriteHelper"); |
| 91 | bind(¬_in_new_space); |
| 92 | } |
| 93 | |
christian.plesner.hansen@gmail.com | 5a6af92 | 2009-08-12 14:20:51 +0000 | [diff] [blame] | 94 | // Compute the page start address from the heap object pointer, and reuse |
| 95 | // the 'object' register for it. |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 96 | and_(object, Immediate(~Page::kPageAlignmentMask)); |
sgjesse@chromium.org | b9d7da1 | 2009-08-05 08:38:10 +0000 | [diff] [blame] | 97 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 98 | // Compute number of region covering addr. See Page::GetRegionNumberForAddress |
| 99 | // method for more details. |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 100 | shrl(addr, Immediate(Page::kRegionSizeLog2)); |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame^] | 101 | andl(addr, Immediate(Page::kPageAlignmentMask >> Page::kRegionSizeLog2)); |
sgjesse@chromium.org | b9d7da1 | 2009-08-05 08:38:10 +0000 | [diff] [blame] | 102 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 103 | // Set dirty mark for region. |
| 104 | bts(Operand(object, Page::kDirtyFlagOffset), addr); |
kmillikin@chromium.org | 4111b80 | 2010-05-03 10:34:42 +0000 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 108 | // For page containing |object| mark region covering [object+offset] dirty. |
sgjesse@chromium.org | b9d7da1 | 2009-08-05 08:38:10 +0000 | [diff] [blame] | 109 | // object is the object being stored into, value is the object being stored. |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame^] | 110 | // If offset is zero, then the index register contains the array index into |
| 111 | // the elements array represented a zero extended int32. Otherwise it can be |
| 112 | // used as a scratch register. |
sgjesse@chromium.org | b9d7da1 | 2009-08-05 08:38:10 +0000 | [diff] [blame] | 113 | // All registers are clobbered by the operation. |
| 114 | void MacroAssembler::RecordWrite(Register object, |
| 115 | int offset, |
| 116 | Register value, |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame^] | 117 | Register index) { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 118 | // The compiled code assumes that record write doesn't change the |
| 119 | // context register, so we check that none of the clobbered |
| 120 | // registers are rsi. |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame^] | 121 | ASSERT(!object.is(rsi) && !value.is(rsi) && !index.is(rsi)); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 122 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 123 | // First, check if a write barrier is even needed. The tests below |
| 124 | // catch stores of Smis and stores into young gen. |
sgjesse@chromium.org | b9d7da1 | 2009-08-05 08:38:10 +0000 | [diff] [blame] | 125 | Label done; |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 126 | JumpIfSmi(value, &done); |
sgjesse@chromium.org | b9d7da1 | 2009-08-05 08:38:10 +0000 | [diff] [blame] | 127 | |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame^] | 128 | RecordWriteNonSmi(object, offset, value, index); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 129 | bind(&done); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 130 | |
| 131 | // Clobber all input registers when running with the debug-code flag |
| 132 | // turned on to provoke errors. This clobbering repeats the |
| 133 | // clobbering done inside RecordWriteNonSmi but it's necessary to |
| 134 | // avoid having the fast case for smis leave the registers |
| 135 | // unchanged. |
| 136 | if (FLAG_debug_code) { |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 137 | movq(object, BitCast<int64_t>(kZapValue), RelocInfo::NONE); |
| 138 | movq(value, BitCast<int64_t>(kZapValue), RelocInfo::NONE); |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame^] | 139 | movq(index, BitCast<int64_t>(kZapValue), RelocInfo::NONE); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 140 | } |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 141 | } |
| 142 | |
| 143 | |
| 144 | void MacroAssembler::RecordWriteNonSmi(Register object, |
| 145 | int offset, |
| 146 | Register scratch, |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame^] | 147 | Register index) { |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 148 | Label done; |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 149 | |
| 150 | if (FLAG_debug_code) { |
| 151 | Label okay; |
| 152 | JumpIfNotSmi(object, &okay); |
| 153 | Abort("MacroAssembler::RecordWriteNonSmi cannot deal with smis"); |
| 154 | bind(&okay); |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame^] | 155 | |
| 156 | if (offset == 0) { |
| 157 | // index must be int32. |
| 158 | Register tmp = index.is(rax) ? rbx : rax; |
| 159 | push(tmp); |
| 160 | movl(tmp, index); |
| 161 | cmpq(tmp, index); |
| 162 | Check(equal, "Index register for RecordWrite must be untagged int32."); |
| 163 | pop(tmp); |
| 164 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 165 | } |
| 166 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 167 | // Test that the object address is not in the new space. We cannot |
| 168 | // update page dirty marks for new space pages. |
kmillikin@chromium.org | 4111b80 | 2010-05-03 10:34:42 +0000 | [diff] [blame] | 169 | InNewSpace(object, scratch, equal, &done); |
sgjesse@chromium.org | b9d7da1 | 2009-08-05 08:38:10 +0000 | [diff] [blame] | 170 | |
whesse@chromium.org | e88a9ed | 2010-04-15 15:07:46 +0000 | [diff] [blame] | 171 | // The offset is relative to a tagged or untagged HeapObject pointer, |
| 172 | // so either offset or offset + kHeapObjectTag must be a |
| 173 | // multiple of kPointerSize. |
| 174 | ASSERT(IsAligned(offset, kPointerSize) || |
| 175 | IsAligned(offset + kHeapObjectTag, kPointerSize)); |
| 176 | |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame^] | 177 | Register dst = index; |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 178 | if (offset != 0) { |
| 179 | lea(dst, Operand(object, offset)); |
sgjesse@chromium.org | b9d7da1 | 2009-08-05 08:38:10 +0000 | [diff] [blame] | 180 | } else { |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 181 | // array access: calculate the destination address in the same manner as |
| 182 | // KeyedStoreIC::GenerateGeneric. |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 183 | lea(dst, FieldOperand(object, |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame^] | 184 | index, |
| 185 | times_pointer_size, |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 186 | FixedArray::kHeaderSize)); |
sgjesse@chromium.org | b9d7da1 | 2009-08-05 08:38:10 +0000 | [diff] [blame] | 187 | } |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 188 | RecordWriteHelper(object, dst, scratch); |
sgjesse@chromium.org | b9d7da1 | 2009-08-05 08:38:10 +0000 | [diff] [blame] | 189 | |
| 190 | bind(&done); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 191 | |
| 192 | // Clobber all input registers when running with the debug-code flag |
| 193 | // turned on to provoke errors. |
| 194 | if (FLAG_debug_code) { |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 195 | movq(object, BitCast<int64_t>(kZapValue), RelocInfo::NONE); |
| 196 | movq(scratch, BitCast<int64_t>(kZapValue), RelocInfo::NONE); |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame^] | 197 | movq(index, BitCast<int64_t>(kZapValue), RelocInfo::NONE); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 198 | } |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 199 | } |
| 200 | |
| 201 | |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 202 | void MacroAssembler::InNewSpace(Register object, |
| 203 | Register scratch, |
| 204 | Condition cc, |
| 205 | Label* branch) { |
| 206 | if (Serializer::enabled()) { |
| 207 | // Can't do arithmetic on external references if it might get serialized. |
| 208 | // The mask isn't really an address. We load it as an external reference in |
| 209 | // case the size of the new space is different between the snapshot maker |
| 210 | // and the running system. |
| 211 | if (scratch.is(object)) { |
| 212 | movq(kScratchRegister, ExternalReference::new_space_mask()); |
| 213 | and_(scratch, kScratchRegister); |
| 214 | } else { |
| 215 | movq(scratch, ExternalReference::new_space_mask()); |
| 216 | and_(scratch, object); |
| 217 | } |
| 218 | movq(kScratchRegister, ExternalReference::new_space_start()); |
| 219 | cmpq(scratch, kScratchRegister); |
| 220 | j(cc, branch); |
| 221 | } else { |
| 222 | ASSERT(is_int32(static_cast<int64_t>(Heap::NewSpaceMask()))); |
| 223 | intptr_t new_space_start = |
| 224 | reinterpret_cast<intptr_t>(Heap::NewSpaceStart()); |
| 225 | movq(kScratchRegister, -new_space_start, RelocInfo::NONE); |
| 226 | if (scratch.is(object)) { |
| 227 | addq(scratch, kScratchRegister); |
| 228 | } else { |
| 229 | lea(scratch, Operand(object, kScratchRegister, times_1, 0)); |
| 230 | } |
| 231 | and_(scratch, Immediate(static_cast<int32_t>(Heap::NewSpaceMask()))); |
| 232 | j(cc, branch); |
| 233 | } |
| 234 | } |
| 235 | |
| 236 | |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 237 | void MacroAssembler::Assert(Condition cc, const char* msg) { |
| 238 | if (FLAG_debug_code) Check(cc, msg); |
| 239 | } |
| 240 | |
| 241 | |
| 242 | void MacroAssembler::Check(Condition cc, const char* msg) { |
| 243 | Label L; |
| 244 | j(cc, &L); |
| 245 | Abort(msg); |
| 246 | // will not return here |
| 247 | bind(&L); |
| 248 | } |
| 249 | |
| 250 | |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 251 | void MacroAssembler::CheckStackAlignment() { |
| 252 | int frame_alignment = OS::ActivationFrameAlignment(); |
| 253 | int frame_alignment_mask = frame_alignment - 1; |
| 254 | if (frame_alignment > kPointerSize) { |
| 255 | ASSERT(IsPowerOf2(frame_alignment)); |
| 256 | Label alignment_as_expected; |
| 257 | testq(rsp, Immediate(frame_alignment_mask)); |
| 258 | j(zero, &alignment_as_expected); |
| 259 | // Abort if stack is not aligned. |
| 260 | int3(); |
| 261 | bind(&alignment_as_expected); |
| 262 | } |
| 263 | } |
| 264 | |
| 265 | |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 266 | void MacroAssembler::NegativeZeroTest(Register result, |
| 267 | Register op, |
| 268 | Label* then_label) { |
| 269 | Label ok; |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 270 | testl(result, result); |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 271 | j(not_zero, &ok); |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 272 | testl(op, op); |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 273 | j(sign, then_label); |
| 274 | bind(&ok); |
| 275 | } |
| 276 | |
| 277 | |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 278 | void MacroAssembler::Abort(const char* msg) { |
| 279 | // We want to pass the msg string like a smi to avoid GC |
| 280 | // problems, however msg is not guaranteed to be aligned |
| 281 | // properly. Instead, we pass an aligned pointer that is |
| 282 | // a proper v8 smi, but also pass the alignment difference |
| 283 | // from the real pointer as a smi. |
| 284 | intptr_t p1 = reinterpret_cast<intptr_t>(msg); |
| 285 | intptr_t p0 = (p1 & ~kSmiTagMask) + kSmiTag; |
| 286 | // Note: p0 might not be a valid Smi *value*, but it has a valid Smi tag. |
| 287 | ASSERT(reinterpret_cast<Object*>(p0)->IsSmi()); |
| 288 | #ifdef DEBUG |
| 289 | if (msg != NULL) { |
| 290 | RecordComment("Abort message: "); |
| 291 | RecordComment(msg); |
| 292 | } |
| 293 | #endif |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 294 | // Disable stub call restrictions to always allow calls to abort. |
| 295 | set_allow_stub_calls(true); |
| 296 | |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 297 | push(rax); |
| 298 | movq(kScratchRegister, p0, RelocInfo::NONE); |
| 299 | push(kScratchRegister); |
| 300 | movq(kScratchRegister, |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 301 | reinterpret_cast<intptr_t>(Smi::FromInt(static_cast<int>(p1 - p0))), |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 302 | RelocInfo::NONE); |
| 303 | push(kScratchRegister); |
| 304 | CallRuntime(Runtime::kAbort, 2); |
| 305 | // will not return here |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 306 | int3(); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 307 | } |
| 308 | |
| 309 | |
| 310 | void MacroAssembler::CallStub(CodeStub* stub) { |
| 311 | ASSERT(allow_stub_calls()); // calls are not allowed in some stubs |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 312 | Call(stub->GetCode(), RelocInfo::CODE_TARGET); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 313 | } |
| 314 | |
| 315 | |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 316 | void MacroAssembler::TailCallStub(CodeStub* stub) { |
| 317 | ASSERT(allow_stub_calls()); // calls are not allowed in some stubs |
| 318 | Jump(stub->GetCode(), RelocInfo::CODE_TARGET); |
| 319 | } |
| 320 | |
| 321 | |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 322 | void MacroAssembler::StubReturn(int argc) { |
| 323 | ASSERT(argc >= 1 && generating_stub()); |
| 324 | ret((argc - 1) * kPointerSize); |
| 325 | } |
| 326 | |
| 327 | |
| 328 | void MacroAssembler::IllegalOperation(int num_arguments) { |
| 329 | if (num_arguments > 0) { |
| 330 | addq(rsp, Immediate(num_arguments * kPointerSize)); |
| 331 | } |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 332 | LoadRoot(rax, Heap::kUndefinedValueRootIndex); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 333 | } |
| 334 | |
| 335 | |
| 336 | void MacroAssembler::CallRuntime(Runtime::FunctionId id, int num_arguments) { |
| 337 | CallRuntime(Runtime::FunctionForId(id), num_arguments); |
| 338 | } |
| 339 | |
| 340 | |
| 341 | void MacroAssembler::CallRuntime(Runtime::Function* f, int num_arguments) { |
| 342 | // If the expected number of arguments of the runtime function is |
| 343 | // constant, we check that the actual number of arguments match the |
| 344 | // expectation. |
| 345 | if (f->nargs >= 0 && f->nargs != num_arguments) { |
| 346 | IllegalOperation(num_arguments); |
| 347 | return; |
| 348 | } |
| 349 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 350 | // TODO(1236192): Most runtime routines don't need the number of |
| 351 | // arguments passed in because it is constant. At some point we |
| 352 | // should remove this need and make the runtime routine entry code |
| 353 | // smarter. |
| 354 | movq(rax, Immediate(num_arguments)); |
| 355 | movq(rbx, ExternalReference(f)); |
| 356 | CEntryStub ces(f->result_size); |
| 357 | CallStub(&ces); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 358 | } |
| 359 | |
| 360 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 361 | void MacroAssembler::CallExternalReference(const ExternalReference& ext, |
| 362 | int num_arguments) { |
| 363 | movq(rax, Immediate(num_arguments)); |
| 364 | movq(rbx, ext); |
| 365 | |
| 366 | CEntryStub stub(1); |
| 367 | CallStub(&stub); |
| 368 | } |
| 369 | |
| 370 | |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 371 | void MacroAssembler::TailCallExternalReference(const ExternalReference& ext, |
| 372 | int num_arguments, |
| 373 | int result_size) { |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 374 | // ----------- S t a t e ------------- |
| 375 | // -- rsp[0] : return address |
| 376 | // -- rsp[8] : argument num_arguments - 1 |
| 377 | // ... |
| 378 | // -- rsp[8 * num_arguments] : argument 0 (receiver) |
| 379 | // ----------------------------------- |
| 380 | |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 381 | // TODO(1236192): Most runtime routines don't need the number of |
| 382 | // arguments passed in because it is constant. At some point we |
| 383 | // should remove this need and make the runtime routine entry code |
| 384 | // smarter. |
| 385 | movq(rax, Immediate(num_arguments)); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 386 | JumpToExternalReference(ext, result_size); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 387 | } |
| 388 | |
| 389 | |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 390 | void MacroAssembler::TailCallRuntime(Runtime::FunctionId fid, |
| 391 | int num_arguments, |
| 392 | int result_size) { |
| 393 | TailCallExternalReference(ExternalReference(fid), num_arguments, result_size); |
| 394 | } |
| 395 | |
| 396 | |
| 397 | void MacroAssembler::JumpToExternalReference(const ExternalReference& ext, |
| 398 | int result_size) { |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 399 | // Set the entry point and jump to the C entry runtime stub. |
| 400 | movq(rbx, ext); |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 401 | CEntryStub ces(result_size); |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 402 | jmp(ces.GetCode(), RelocInfo::CODE_TARGET); |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 403 | } |
| 404 | |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 405 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 406 | void MacroAssembler::InvokeBuiltin(Builtins::JavaScript id, InvokeFlag flag) { |
| 407 | // Calls are not allowed in some stubs. |
| 408 | ASSERT(flag == JUMP_FUNCTION || allow_stub_calls()); |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 409 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 410 | // Rely on the assertion to check that the number of provided |
| 411 | // arguments match the expected number of arguments. Fake a |
| 412 | // parameter count to avoid emitting code to do the check. |
| 413 | ParameterCount expected(0); |
| 414 | GetBuiltinEntry(rdx, id); |
| 415 | InvokeCode(rdx, expected, expected, flag); |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 416 | } |
| 417 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 418 | |
| 419 | void MacroAssembler::GetBuiltinEntry(Register target, Builtins::JavaScript id) { |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 420 | ASSERT(!target.is(rdi)); |
| 421 | |
| 422 | // Load the builtins object into target register. |
| 423 | movq(target, Operand(rsi, Context::SlotOffset(Context::GLOBAL_INDEX))); |
| 424 | movq(target, FieldOperand(target, GlobalObject::kBuiltinsOffset)); |
| 425 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 426 | // Load the JavaScript builtin function from the builtins object. |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 427 | movq(rdi, FieldOperand(target, JSBuiltinsObject::OffsetOfFunctionWithId(id))); |
| 428 | |
| 429 | // Load the code entry point from the builtins object. |
| 430 | movq(target, FieldOperand(target, JSBuiltinsObject::OffsetOfCodeWithId(id))); |
| 431 | if (FLAG_debug_code) { |
| 432 | // Make sure the code objects in the builtins object and in the |
| 433 | // builtin function are the same. |
| 434 | push(target); |
| 435 | movq(target, FieldOperand(rdi, JSFunction::kSharedFunctionInfoOffset)); |
| 436 | movq(target, FieldOperand(target, SharedFunctionInfo::kCodeOffset)); |
| 437 | cmpq(target, Operand(rsp, 0)); |
| 438 | Assert(equal, "Builtin code object changed"); |
| 439 | pop(target); |
| 440 | } |
| 441 | lea(target, FieldOperand(target, Code::kHeaderSize)); |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 442 | } |
| 443 | |
| 444 | |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 445 | void MacroAssembler::Set(Register dst, int64_t x) { |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 446 | if (x == 0) { |
| 447 | xor_(dst, dst); |
| 448 | } else if (is_int32(x)) { |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 449 | movq(dst, Immediate(static_cast<int32_t>(x))); |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 450 | } else if (is_uint32(x)) { |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 451 | movl(dst, Immediate(static_cast<uint32_t>(x))); |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 452 | } else { |
| 453 | movq(dst, x, RelocInfo::NONE); |
| 454 | } |
| 455 | } |
| 456 | |
| 457 | |
| 458 | void MacroAssembler::Set(const Operand& dst, int64_t x) { |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame^] | 459 | if (is_int32(x)) { |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 460 | movq(dst, Immediate(static_cast<int32_t>(x))); |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 461 | } else { |
| 462 | movq(kScratchRegister, x, RelocInfo::NONE); |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 463 | movq(dst, kScratchRegister); |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 464 | } |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 465 | } |
| 466 | |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 467 | // ---------------------------------------------------------------------------- |
| 468 | // Smi tagging, untagging and tag detection. |
| 469 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 470 | static int kSmiShift = kSmiTagSize + kSmiShiftSize; |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 471 | |
| 472 | void MacroAssembler::Integer32ToSmi(Register dst, Register src) { |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 473 | ASSERT_EQ(0, kSmiTag); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 474 | if (!dst.is(src)) { |
| 475 | movl(dst, src); |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 476 | } |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 477 | shl(dst, Immediate(kSmiShift)); |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 478 | } |
| 479 | |
| 480 | |
| 481 | void MacroAssembler::Integer32ToSmi(Register dst, |
| 482 | Register src, |
| 483 | Label* on_overflow) { |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 484 | ASSERT_EQ(0, kSmiTag); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 485 | // 32-bit integer always fits in a long smi. |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 486 | if (!dst.is(src)) { |
| 487 | movl(dst, src); |
| 488 | } |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 489 | shl(dst, Immediate(kSmiShift)); |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 490 | } |
| 491 | |
| 492 | |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame^] | 493 | void MacroAssembler::Integer32ToSmiField(const Operand& dst, Register src) { |
| 494 | if (FLAG_debug_code) { |
| 495 | testb(dst, Immediate(0x01)); |
| 496 | Label ok; |
| 497 | j(zero, &ok); |
| 498 | if (allow_stub_calls()) { |
| 499 | Abort("Integer32ToSmiField writing to non-smi location"); |
| 500 | } else { |
| 501 | int3(); |
| 502 | } |
| 503 | bind(&ok); |
| 504 | } |
| 505 | ASSERT(kSmiShift % kBitsPerByte == 0); |
| 506 | movl(Operand(dst, kSmiShift / kBitsPerByte), src); |
| 507 | } |
| 508 | |
| 509 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 510 | void MacroAssembler::Integer64PlusConstantToSmi(Register dst, |
| 511 | Register src, |
| 512 | int constant) { |
| 513 | if (dst.is(src)) { |
| 514 | addq(dst, Immediate(constant)); |
| 515 | } else { |
| 516 | lea(dst, Operand(src, constant)); |
| 517 | } |
| 518 | shl(dst, Immediate(kSmiShift)); |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 519 | } |
| 520 | |
| 521 | |
| 522 | void MacroAssembler::SmiToInteger32(Register dst, Register src) { |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 523 | ASSERT_EQ(0, kSmiTag); |
| 524 | if (!dst.is(src)) { |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 525 | movq(dst, src); |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 526 | } |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 527 | shr(dst, Immediate(kSmiShift)); |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 528 | } |
| 529 | |
| 530 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 531 | void MacroAssembler::SmiToInteger32(Register dst, const Operand& src) { |
| 532 | movl(dst, Operand(src, kSmiShift / kBitsPerByte)); |
| 533 | } |
| 534 | |
| 535 | |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 536 | void MacroAssembler::SmiToInteger64(Register dst, Register src) { |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 537 | ASSERT_EQ(0, kSmiTag); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 538 | if (!dst.is(src)) { |
| 539 | movq(dst, src); |
| 540 | } |
| 541 | sar(dst, Immediate(kSmiShift)); |
| 542 | } |
| 543 | |
| 544 | |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame^] | 545 | void MacroAssembler::SmiToInteger64(Register dst, const Operand& src) { |
| 546 | movsxlq(dst, Operand(src, kSmiShift / kBitsPerByte)); |
| 547 | } |
| 548 | |
| 549 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 550 | void MacroAssembler::SmiTest(Register src) { |
| 551 | testq(src, src); |
| 552 | } |
| 553 | |
| 554 | |
| 555 | void MacroAssembler::SmiCompare(Register dst, Register src) { |
| 556 | cmpq(dst, src); |
| 557 | } |
| 558 | |
| 559 | |
| 560 | void MacroAssembler::SmiCompare(Register dst, Smi* src) { |
| 561 | ASSERT(!dst.is(kScratchRegister)); |
| 562 | if (src->value() == 0) { |
| 563 | testq(dst, dst); |
| 564 | } else { |
| 565 | Move(kScratchRegister, src); |
| 566 | cmpq(dst, kScratchRegister); |
| 567 | } |
| 568 | } |
| 569 | |
| 570 | |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 571 | void MacroAssembler::SmiCompare(Register dst, const Operand& src) { |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 572 | cmpq(dst, src); |
| 573 | } |
| 574 | |
| 575 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 576 | void MacroAssembler::SmiCompare(const Operand& dst, Register src) { |
| 577 | cmpq(dst, src); |
| 578 | } |
| 579 | |
| 580 | |
| 581 | void MacroAssembler::SmiCompare(const Operand& dst, Smi* src) { |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 582 | cmpl(Operand(dst, kSmiShift / kBitsPerByte), Immediate(src->value())); |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 583 | } |
| 584 | |
| 585 | |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame^] | 586 | void MacroAssembler::SmiCompareInteger32(const Operand& dst, Register src) { |
| 587 | cmpl(Operand(dst, kSmiShift / kBitsPerByte), src); |
| 588 | } |
| 589 | |
| 590 | |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 591 | void MacroAssembler::PositiveSmiTimesPowerOfTwoToInteger64(Register dst, |
| 592 | Register src, |
| 593 | int power) { |
| 594 | ASSERT(power >= 0); |
| 595 | ASSERT(power < 64); |
| 596 | if (power == 0) { |
| 597 | SmiToInteger64(dst, src); |
| 598 | return; |
| 599 | } |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 600 | if (!dst.is(src)) { |
| 601 | movq(dst, src); |
| 602 | } |
| 603 | if (power < kSmiShift) { |
| 604 | sar(dst, Immediate(kSmiShift - power)); |
| 605 | } else if (power > kSmiShift) { |
| 606 | shl(dst, Immediate(power - kSmiShift)); |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 607 | } |
| 608 | } |
| 609 | |
| 610 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 611 | void MacroAssembler::PositiveSmiDivPowerOfTwoToInteger32(Register dst, |
| 612 | Register src, |
| 613 | int power) { |
| 614 | ASSERT((0 <= power) && (power < 32)); |
| 615 | if (dst.is(src)) { |
| 616 | shr(dst, Immediate(power + kSmiShift)); |
| 617 | } else { |
| 618 | UNIMPLEMENTED(); // Not used. |
| 619 | } |
| 620 | } |
| 621 | |
| 622 | |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 623 | Condition MacroAssembler::CheckSmi(Register src) { |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 624 | ASSERT_EQ(0, kSmiTag); |
| 625 | testb(src, Immediate(kSmiTagMask)); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 626 | return zero; |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 627 | } |
| 628 | |
| 629 | |
| 630 | Condition MacroAssembler::CheckPositiveSmi(Register src) { |
| 631 | ASSERT_EQ(0, kSmiTag); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 632 | movq(kScratchRegister, src); |
| 633 | rol(kScratchRegister, Immediate(1)); |
| 634 | testl(kScratchRegister, Immediate(0x03)); |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 635 | return zero; |
| 636 | } |
| 637 | |
| 638 | |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 639 | Condition MacroAssembler::CheckBothSmi(Register first, Register second) { |
| 640 | if (first.is(second)) { |
| 641 | return CheckSmi(first); |
| 642 | } |
| 643 | movl(kScratchRegister, first); |
| 644 | orl(kScratchRegister, second); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 645 | testb(kScratchRegister, Immediate(kSmiTagMask)); |
| 646 | return zero; |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 647 | } |
| 648 | |
| 649 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 650 | Condition MacroAssembler::CheckBothPositiveSmi(Register first, |
| 651 | Register second) { |
| 652 | if (first.is(second)) { |
| 653 | return CheckPositiveSmi(first); |
| 654 | } |
| 655 | movl(kScratchRegister, first); |
| 656 | orl(kScratchRegister, second); |
| 657 | rol(kScratchRegister, Immediate(1)); |
| 658 | testl(kScratchRegister, Immediate(0x03)); |
| 659 | return zero; |
| 660 | } |
| 661 | |
| 662 | |
| 663 | |
| 664 | Condition MacroAssembler::CheckEitherSmi(Register first, Register second) { |
| 665 | if (first.is(second)) { |
| 666 | return CheckSmi(first); |
| 667 | } |
| 668 | movl(kScratchRegister, first); |
| 669 | andl(kScratchRegister, second); |
| 670 | testb(kScratchRegister, Immediate(kSmiTagMask)); |
| 671 | return zero; |
| 672 | } |
| 673 | |
| 674 | |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 675 | Condition MacroAssembler::CheckIsMinSmi(Register src) { |
| 676 | ASSERT(kSmiTag == 0 && kSmiTagSize == 1); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 677 | movq(kScratchRegister, src); |
| 678 | rol(kScratchRegister, Immediate(1)); |
| 679 | cmpq(kScratchRegister, Immediate(1)); |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 680 | return equal; |
| 681 | } |
| 682 | |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 683 | |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 684 | Condition MacroAssembler::CheckInteger32ValidSmiValue(Register src) { |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 685 | // A 32-bit integer value can always be converted to a smi. |
| 686 | return always; |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 687 | } |
| 688 | |
| 689 | |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 690 | Condition MacroAssembler::CheckUInteger32ValidSmiValue(Register src) { |
| 691 | // An unsigned 32-bit integer value is valid as long as the high bit |
| 692 | // is not set. |
| 693 | testq(src, Immediate(0x80000000)); |
| 694 | return zero; |
| 695 | } |
| 696 | |
| 697 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 698 | void MacroAssembler::SmiNeg(Register dst, Register src, Label* on_smi_result) { |
| 699 | if (dst.is(src)) { |
| 700 | ASSERT(!dst.is(kScratchRegister)); |
| 701 | movq(kScratchRegister, src); |
| 702 | neg(dst); // Low 32 bits are retained as zero by negation. |
| 703 | // Test if result is zero or Smi::kMinValue. |
| 704 | cmpq(dst, kScratchRegister); |
| 705 | j(not_equal, on_smi_result); |
| 706 | movq(src, kScratchRegister); |
| 707 | } else { |
| 708 | movq(dst, src); |
| 709 | neg(dst); |
| 710 | cmpq(dst, src); |
| 711 | // If the result is zero or Smi::kMinValue, negation failed to create a smi. |
| 712 | j(not_equal, on_smi_result); |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 713 | } |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 714 | } |
| 715 | |
| 716 | |
| 717 | void MacroAssembler::SmiAdd(Register dst, |
| 718 | Register src1, |
| 719 | Register src2, |
| 720 | Label* on_not_smi_result) { |
| 721 | ASSERT(!dst.is(src2)); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 722 | if (on_not_smi_result == NULL) { |
| 723 | // No overflow checking. Use only when it's known that |
| 724 | // overflowing is impossible. |
| 725 | if (dst.is(src1)) { |
| 726 | addq(dst, src2); |
| 727 | } else { |
| 728 | movq(dst, src1); |
| 729 | addq(dst, src2); |
| 730 | } |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame^] | 731 | Assert(no_overflow, "Smi addition overflow"); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 732 | } else if (dst.is(src1)) { |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame^] | 733 | movq(kScratchRegister, src1); |
| 734 | addq(kScratchRegister, src2); |
| 735 | j(overflow, on_not_smi_result); |
| 736 | movq(dst, kScratchRegister); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 737 | } else { |
| 738 | movq(dst, src1); |
| 739 | addq(dst, src2); |
| 740 | j(overflow, on_not_smi_result); |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 741 | } |
| 742 | } |
| 743 | |
| 744 | |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 745 | void MacroAssembler::SmiSub(Register dst, |
| 746 | Register src1, |
| 747 | Register src2, |
| 748 | Label* on_not_smi_result) { |
| 749 | ASSERT(!dst.is(src2)); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 750 | if (on_not_smi_result == NULL) { |
| 751 | // No overflow checking. Use only when it's known that |
| 752 | // overflowing is impossible (e.g., subtracting two positive smis). |
| 753 | if (dst.is(src1)) { |
| 754 | subq(dst, src2); |
| 755 | } else { |
| 756 | movq(dst, src1); |
| 757 | subq(dst, src2); |
| 758 | } |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame^] | 759 | Assert(no_overflow, "Smi subtraction overflow"); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 760 | } else if (dst.is(src1)) { |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame^] | 761 | cmpq(dst, src2); |
| 762 | j(overflow, on_not_smi_result); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 763 | subq(dst, src2); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 764 | } else { |
| 765 | movq(dst, src1); |
| 766 | subq(dst, src2); |
| 767 | j(overflow, on_not_smi_result); |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 768 | } |
| 769 | } |
| 770 | |
| 771 | |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 772 | void MacroAssembler::SmiSub(Register dst, |
| 773 | Register src1, |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 774 | const Operand& src2, |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 775 | Label* on_not_smi_result) { |
| 776 | if (on_not_smi_result == NULL) { |
| 777 | // No overflow checking. Use only when it's known that |
| 778 | // overflowing is impossible (e.g., subtracting two positive smis). |
| 779 | if (dst.is(src1)) { |
| 780 | subq(dst, src2); |
| 781 | } else { |
| 782 | movq(dst, src1); |
| 783 | subq(dst, src2); |
| 784 | } |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame^] | 785 | Assert(no_overflow, "Smi subtraction overflow"); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 786 | } else if (dst.is(src1)) { |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame^] | 787 | movq(kScratchRegister, src1); |
| 788 | subq(kScratchRegister, src2); |
| 789 | j(overflow, on_not_smi_result); |
| 790 | movq(src1, kScratchRegister); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 791 | } else { |
| 792 | movq(dst, src1); |
| 793 | subq(dst, src2); |
| 794 | j(overflow, on_not_smi_result); |
| 795 | } |
| 796 | } |
| 797 | |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 798 | void MacroAssembler::SmiMul(Register dst, |
| 799 | Register src1, |
| 800 | Register src2, |
| 801 | Label* on_not_smi_result) { |
| 802 | ASSERT(!dst.is(src2)); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 803 | ASSERT(!dst.is(kScratchRegister)); |
| 804 | ASSERT(!src1.is(kScratchRegister)); |
| 805 | ASSERT(!src2.is(kScratchRegister)); |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 806 | |
| 807 | if (dst.is(src1)) { |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 808 | Label failure, zero_correct_result; |
| 809 | movq(kScratchRegister, src1); // Create backup for later testing. |
| 810 | SmiToInteger64(dst, src1); |
| 811 | imul(dst, src2); |
| 812 | j(overflow, &failure); |
| 813 | |
| 814 | // Check for negative zero result. If product is zero, and one |
| 815 | // argument is negative, go to slow case. |
| 816 | Label correct_result; |
| 817 | testq(dst, dst); |
| 818 | j(not_zero, &correct_result); |
| 819 | |
| 820 | movq(dst, kScratchRegister); |
| 821 | xor_(dst, src2); |
| 822 | j(positive, &zero_correct_result); // Result was positive zero. |
| 823 | |
| 824 | bind(&failure); // Reused failure exit, restores src1. |
| 825 | movq(src1, kScratchRegister); |
| 826 | jmp(on_not_smi_result); |
| 827 | |
| 828 | bind(&zero_correct_result); |
| 829 | xor_(dst, dst); |
| 830 | |
| 831 | bind(&correct_result); |
| 832 | } else { |
| 833 | SmiToInteger64(dst, src1); |
| 834 | imul(dst, src2); |
| 835 | j(overflow, on_not_smi_result); |
| 836 | // Check for negative zero result. If product is zero, and one |
| 837 | // argument is negative, go to slow case. |
| 838 | Label correct_result; |
| 839 | testq(dst, dst); |
| 840 | j(not_zero, &correct_result); |
| 841 | // One of src1 and src2 is zero, the check whether the other is |
| 842 | // negative. |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 843 | movq(kScratchRegister, src1); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 844 | xor_(kScratchRegister, src2); |
| 845 | j(negative, on_not_smi_result); |
| 846 | bind(&correct_result); |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 847 | } |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 848 | } |
| 849 | |
| 850 | |
| 851 | void MacroAssembler::SmiTryAddConstant(Register dst, |
| 852 | Register src, |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 853 | Smi* constant, |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 854 | Label* on_not_smi_result) { |
| 855 | // Does not assume that src is a smi. |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 856 | ASSERT_EQ(static_cast<int>(1), static_cast<int>(kSmiTagMask)); |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 857 | ASSERT_EQ(0, kSmiTag); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 858 | ASSERT(!dst.is(kScratchRegister)); |
| 859 | ASSERT(!src.is(kScratchRegister)); |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 860 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 861 | JumpIfNotSmi(src, on_not_smi_result); |
| 862 | Register tmp = (dst.is(src) ? kScratchRegister : dst); |
| 863 | Move(tmp, constant); |
| 864 | addq(tmp, src); |
| 865 | j(overflow, on_not_smi_result); |
| 866 | if (dst.is(src)) { |
| 867 | movq(dst, tmp); |
| 868 | } |
| 869 | } |
| 870 | |
| 871 | |
| 872 | void MacroAssembler::SmiAddConstant(Register dst, Register src, Smi* constant) { |
| 873 | if (constant->value() == 0) { |
| 874 | if (!dst.is(src)) { |
| 875 | movq(dst, src); |
| 876 | } |
| 877 | } else if (dst.is(src)) { |
| 878 | ASSERT(!dst.is(kScratchRegister)); |
| 879 | |
| 880 | Move(kScratchRegister, constant); |
| 881 | addq(dst, kScratchRegister); |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 882 | } else { |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 883 | Move(dst, constant); |
| 884 | addq(dst, src); |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 885 | } |
| 886 | } |
| 887 | |
| 888 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 889 | void MacroAssembler::SmiAddConstant(const Operand& dst, Smi* constant) { |
| 890 | if (constant->value() != 0) { |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 891 | addl(Operand(dst, kSmiShift / kBitsPerByte), Immediate(constant->value())); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 892 | } |
| 893 | } |
| 894 | |
| 895 | |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 896 | void MacroAssembler::SmiAddConstant(Register dst, |
| 897 | Register src, |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 898 | Smi* constant, |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 899 | Label* on_not_smi_result) { |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 900 | if (constant->value() == 0) { |
| 901 | if (!dst.is(src)) { |
| 902 | movq(dst, src); |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 903 | } |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 904 | } else if (dst.is(src)) { |
| 905 | ASSERT(!dst.is(kScratchRegister)); |
| 906 | |
| 907 | Move(kScratchRegister, constant); |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame^] | 908 | addq(kScratchRegister, dst); |
| 909 | j(overflow, on_not_smi_result); |
| 910 | movq(dst, kScratchRegister); |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 911 | } else { |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 912 | Move(dst, constant); |
| 913 | addq(dst, src); |
| 914 | j(overflow, on_not_smi_result); |
| 915 | } |
| 916 | } |
| 917 | |
| 918 | |
| 919 | void MacroAssembler::SmiSubConstant(Register dst, Register src, Smi* constant) { |
| 920 | if (constant->value() == 0) { |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 921 | if (!dst.is(src)) { |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 922 | movq(dst, src); |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 923 | } |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 924 | } else if (dst.is(src)) { |
| 925 | ASSERT(!dst.is(kScratchRegister)); |
| 926 | |
| 927 | Move(kScratchRegister, constant); |
| 928 | subq(dst, kScratchRegister); |
| 929 | } else { |
| 930 | // Subtract by adding the negative, to do it in two operations. |
| 931 | if (constant->value() == Smi::kMinValue) { |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame^] | 932 | Move(dst, constant); |
| 933 | // Adding and subtracting the min-value gives the same result, it only |
| 934 | // differs on the overflow bit, which we don't check here. |
| 935 | addq(dst, src); |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 936 | } else { |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame^] | 937 | // Subtract by adding the negation. |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 938 | Move(dst, Smi::FromInt(-constant->value())); |
| 939 | addq(dst, src); |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 940 | } |
| 941 | } |
| 942 | } |
| 943 | |
| 944 | |
| 945 | void MacroAssembler::SmiSubConstant(Register dst, |
| 946 | Register src, |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 947 | Smi* constant, |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 948 | Label* on_not_smi_result) { |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 949 | if (constant->value() == 0) { |
| 950 | if (!dst.is(src)) { |
| 951 | movq(dst, src); |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 952 | } |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 953 | } else if (dst.is(src)) { |
| 954 | ASSERT(!dst.is(kScratchRegister)); |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame^] | 955 | if (constant->value() == Smi::kMinValue) { |
| 956 | // Subtracting min-value from any non-negative value will overflow. |
| 957 | // We test the non-negativeness before doing the subtraction. |
| 958 | testq(src, src); |
| 959 | j(not_sign, on_not_smi_result); |
| 960 | Move(kScratchRegister, constant); |
| 961 | subq(dst, kScratchRegister); |
| 962 | } else { |
| 963 | // Subtract by adding the negation. |
| 964 | Move(kScratchRegister, Smi::FromInt(-constant->value())); |
| 965 | addq(kScratchRegister, dst); |
| 966 | j(overflow, on_not_smi_result); |
| 967 | movq(dst, kScratchRegister); |
| 968 | } |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 969 | } else { |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 970 | if (constant->value() == Smi::kMinValue) { |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame^] | 971 | // Subtracting min-value from any non-negative value will overflow. |
| 972 | // We test the non-negativeness before doing the subtraction. |
| 973 | testq(src, src); |
| 974 | j(not_sign, on_not_smi_result); |
| 975 | Move(dst, constant); |
| 976 | // Adding and subtracting the min-value gives the same result, it only |
| 977 | // differs on the overflow bit, which we don't check here. |
| 978 | addq(dst, src); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 979 | } else { |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame^] | 980 | // Subtract by adding the negation. |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 981 | Move(dst, Smi::FromInt(-(constant->value()))); |
| 982 | addq(dst, src); |
| 983 | j(overflow, on_not_smi_result); |
| 984 | } |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 985 | } |
| 986 | } |
| 987 | |
| 988 | |
| 989 | void MacroAssembler::SmiDiv(Register dst, |
| 990 | Register src1, |
| 991 | Register src2, |
| 992 | Label* on_not_smi_result) { |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 993 | ASSERT(!src1.is(kScratchRegister)); |
| 994 | ASSERT(!src2.is(kScratchRegister)); |
| 995 | ASSERT(!dst.is(kScratchRegister)); |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 996 | ASSERT(!src2.is(rax)); |
| 997 | ASSERT(!src2.is(rdx)); |
| 998 | ASSERT(!src1.is(rdx)); |
| 999 | |
| 1000 | // Check for 0 divisor (result is +/-Infinity). |
| 1001 | Label positive_divisor; |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1002 | testq(src2, src2); |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 1003 | j(zero, on_not_smi_result); |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 1004 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1005 | if (src1.is(rax)) { |
| 1006 | movq(kScratchRegister, src1); |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 1007 | } |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1008 | SmiToInteger32(rax, src1); |
| 1009 | // We need to rule out dividing Smi::kMinValue by -1, since that would |
| 1010 | // overflow in idiv and raise an exception. |
| 1011 | // We combine this with negative zero test (negative zero only happens |
| 1012 | // when dividing zero by a negative number). |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 1013 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1014 | // We overshoot a little and go to slow case if we divide min-value |
| 1015 | // by any negative value, not just -1. |
| 1016 | Label safe_div; |
| 1017 | testl(rax, Immediate(0x7fffffff)); |
| 1018 | j(not_zero, &safe_div); |
| 1019 | testq(src2, src2); |
| 1020 | if (src1.is(rax)) { |
| 1021 | j(positive, &safe_div); |
| 1022 | movq(src1, kScratchRegister); |
| 1023 | jmp(on_not_smi_result); |
| 1024 | } else { |
| 1025 | j(negative, on_not_smi_result); |
| 1026 | } |
| 1027 | bind(&safe_div); |
| 1028 | |
| 1029 | SmiToInteger32(src2, src2); |
| 1030 | // Sign extend src1 into edx:eax. |
| 1031 | cdq(); |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 1032 | idivl(src2); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1033 | Integer32ToSmi(src2, src2); |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 1034 | // Check that the remainder is zero. |
| 1035 | testl(rdx, rdx); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1036 | if (src1.is(rax)) { |
| 1037 | Label smi_result; |
| 1038 | j(zero, &smi_result); |
| 1039 | movq(src1, kScratchRegister); |
| 1040 | jmp(on_not_smi_result); |
| 1041 | bind(&smi_result); |
| 1042 | } else { |
| 1043 | j(not_zero, on_not_smi_result); |
| 1044 | } |
| 1045 | if (!dst.is(src1) && src1.is(rax)) { |
| 1046 | movq(src1, kScratchRegister); |
| 1047 | } |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 1048 | Integer32ToSmi(dst, rax); |
| 1049 | } |
| 1050 | |
| 1051 | |
| 1052 | void MacroAssembler::SmiMod(Register dst, |
| 1053 | Register src1, |
| 1054 | Register src2, |
| 1055 | Label* on_not_smi_result) { |
| 1056 | ASSERT(!dst.is(kScratchRegister)); |
| 1057 | ASSERT(!src1.is(kScratchRegister)); |
| 1058 | ASSERT(!src2.is(kScratchRegister)); |
| 1059 | ASSERT(!src2.is(rax)); |
| 1060 | ASSERT(!src2.is(rdx)); |
| 1061 | ASSERT(!src1.is(rdx)); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1062 | ASSERT(!src1.is(src2)); |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 1063 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1064 | testq(src2, src2); |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 1065 | j(zero, on_not_smi_result); |
| 1066 | |
| 1067 | if (src1.is(rax)) { |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1068 | movq(kScratchRegister, src1); |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 1069 | } |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1070 | SmiToInteger32(rax, src1); |
| 1071 | SmiToInteger32(src2, src2); |
| 1072 | |
| 1073 | // Test for the edge case of dividing Smi::kMinValue by -1 (will overflow). |
| 1074 | Label safe_div; |
| 1075 | cmpl(rax, Immediate(Smi::kMinValue)); |
| 1076 | j(not_equal, &safe_div); |
| 1077 | cmpl(src2, Immediate(-1)); |
| 1078 | j(not_equal, &safe_div); |
| 1079 | // Retag inputs and go slow case. |
| 1080 | Integer32ToSmi(src2, src2); |
| 1081 | if (src1.is(rax)) { |
| 1082 | movq(src1, kScratchRegister); |
| 1083 | } |
| 1084 | jmp(on_not_smi_result); |
| 1085 | bind(&safe_div); |
| 1086 | |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 1087 | // Sign extend eax into edx:eax. |
| 1088 | cdq(); |
| 1089 | idivl(src2); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1090 | // Restore smi tags on inputs. |
| 1091 | Integer32ToSmi(src2, src2); |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 1092 | if (src1.is(rax)) { |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1093 | movq(src1, kScratchRegister); |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 1094 | } |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1095 | // Check for a negative zero result. If the result is zero, and the |
| 1096 | // dividend is negative, go slow to return a floating point negative zero. |
| 1097 | Label smi_result; |
| 1098 | testl(rdx, rdx); |
| 1099 | j(not_zero, &smi_result); |
| 1100 | testq(src1, src1); |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 1101 | j(negative, on_not_smi_result); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1102 | bind(&smi_result); |
| 1103 | Integer32ToSmi(dst, rdx); |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 1104 | } |
| 1105 | |
| 1106 | |
| 1107 | void MacroAssembler::SmiNot(Register dst, Register src) { |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1108 | ASSERT(!dst.is(kScratchRegister)); |
| 1109 | ASSERT(!src.is(kScratchRegister)); |
| 1110 | // Set tag and padding bits before negating, so that they are zero afterwards. |
| 1111 | movl(kScratchRegister, Immediate(~0)); |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 1112 | if (dst.is(src)) { |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1113 | xor_(dst, kScratchRegister); |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 1114 | } else { |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1115 | lea(dst, Operand(src, kScratchRegister, times_1, 0)); |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 1116 | } |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1117 | not_(dst); |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 1118 | } |
| 1119 | |
| 1120 | |
| 1121 | void MacroAssembler::SmiAnd(Register dst, Register src1, Register src2) { |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1122 | ASSERT(!dst.is(src2)); |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 1123 | if (!dst.is(src1)) { |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1124 | movq(dst, src1); |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 1125 | } |
| 1126 | and_(dst, src2); |
| 1127 | } |
| 1128 | |
| 1129 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1130 | void MacroAssembler::SmiAndConstant(Register dst, Register src, Smi* constant) { |
| 1131 | if (constant->value() == 0) { |
| 1132 | xor_(dst, dst); |
| 1133 | } else if (dst.is(src)) { |
| 1134 | ASSERT(!dst.is(kScratchRegister)); |
| 1135 | Move(kScratchRegister, constant); |
| 1136 | and_(dst, kScratchRegister); |
| 1137 | } else { |
| 1138 | Move(dst, constant); |
| 1139 | and_(dst, src); |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 1140 | } |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 1141 | } |
| 1142 | |
| 1143 | |
| 1144 | void MacroAssembler::SmiOr(Register dst, Register src1, Register src2) { |
| 1145 | if (!dst.is(src1)) { |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1146 | movq(dst, src1); |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 1147 | } |
| 1148 | or_(dst, src2); |
| 1149 | } |
| 1150 | |
| 1151 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1152 | void MacroAssembler::SmiOrConstant(Register dst, Register src, Smi* constant) { |
| 1153 | if (dst.is(src)) { |
| 1154 | ASSERT(!dst.is(kScratchRegister)); |
| 1155 | Move(kScratchRegister, constant); |
| 1156 | or_(dst, kScratchRegister); |
| 1157 | } else { |
| 1158 | Move(dst, constant); |
| 1159 | or_(dst, src); |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 1160 | } |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 1161 | } |
| 1162 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1163 | |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 1164 | void MacroAssembler::SmiXor(Register dst, Register src1, Register src2) { |
| 1165 | if (!dst.is(src1)) { |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1166 | movq(dst, src1); |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 1167 | } |
| 1168 | xor_(dst, src2); |
| 1169 | } |
| 1170 | |
| 1171 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1172 | void MacroAssembler::SmiXorConstant(Register dst, Register src, Smi* constant) { |
| 1173 | if (dst.is(src)) { |
| 1174 | ASSERT(!dst.is(kScratchRegister)); |
| 1175 | Move(kScratchRegister, constant); |
| 1176 | xor_(dst, kScratchRegister); |
| 1177 | } else { |
| 1178 | Move(dst, constant); |
| 1179 | xor_(dst, src); |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 1180 | } |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 1181 | } |
| 1182 | |
| 1183 | |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 1184 | void MacroAssembler::SmiShiftArithmeticRightConstant(Register dst, |
| 1185 | Register src, |
| 1186 | int shift_value) { |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1187 | ASSERT(is_uint5(shift_value)); |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 1188 | if (shift_value > 0) { |
| 1189 | if (dst.is(src)) { |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1190 | sar(dst, Immediate(shift_value + kSmiShift)); |
| 1191 | shl(dst, Immediate(kSmiShift)); |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 1192 | } else { |
| 1193 | UNIMPLEMENTED(); // Not used. |
| 1194 | } |
| 1195 | } |
| 1196 | } |
| 1197 | |
| 1198 | |
| 1199 | void MacroAssembler::SmiShiftLogicalRightConstant(Register dst, |
| 1200 | Register src, |
| 1201 | int shift_value, |
| 1202 | Label* on_not_smi_result) { |
| 1203 | // Logic right shift interprets its result as an *unsigned* number. |
| 1204 | if (dst.is(src)) { |
| 1205 | UNIMPLEMENTED(); // Not used. |
| 1206 | } else { |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1207 | movq(dst, src); |
| 1208 | if (shift_value == 0) { |
| 1209 | testq(dst, dst); |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 1210 | j(negative, on_not_smi_result); |
| 1211 | } |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1212 | shr(dst, Immediate(shift_value + kSmiShift)); |
| 1213 | shl(dst, Immediate(kSmiShift)); |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 1214 | } |
| 1215 | } |
| 1216 | |
| 1217 | |
| 1218 | void MacroAssembler::SmiShiftLeftConstant(Register dst, |
| 1219 | Register src, |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 1220 | int shift_value) { |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1221 | if (!dst.is(src)) { |
| 1222 | movq(dst, src); |
| 1223 | } |
| 1224 | if (shift_value > 0) { |
| 1225 | shl(dst, Immediate(shift_value)); |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 1226 | } |
| 1227 | } |
| 1228 | |
| 1229 | |
| 1230 | void MacroAssembler::SmiShiftLeft(Register dst, |
| 1231 | Register src1, |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 1232 | Register src2) { |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 1233 | ASSERT(!dst.is(rcx)); |
| 1234 | Label result_ok; |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1235 | // Untag shift amount. |
| 1236 | if (!dst.is(src1)) { |
| 1237 | movq(dst, src1); |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 1238 | } |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1239 | SmiToInteger32(rcx, src2); |
| 1240 | // Shift amount specified by lower 5 bits, not six as the shl opcode. |
| 1241 | and_(rcx, Immediate(0x1f)); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1242 | shl_cl(dst); |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 1243 | } |
| 1244 | |
| 1245 | |
| 1246 | void MacroAssembler::SmiShiftLogicalRight(Register dst, |
| 1247 | Register src1, |
| 1248 | Register src2, |
| 1249 | Label* on_not_smi_result) { |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1250 | ASSERT(!dst.is(kScratchRegister)); |
| 1251 | ASSERT(!src1.is(kScratchRegister)); |
| 1252 | ASSERT(!src2.is(kScratchRegister)); |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 1253 | ASSERT(!dst.is(rcx)); |
| 1254 | Label result_ok; |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1255 | if (src1.is(rcx) || src2.is(rcx)) { |
| 1256 | movq(kScratchRegister, rcx); |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 1257 | } |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1258 | if (!dst.is(src1)) { |
| 1259 | movq(dst, src1); |
| 1260 | } |
| 1261 | SmiToInteger32(rcx, src2); |
| 1262 | orl(rcx, Immediate(kSmiShift)); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1263 | shr_cl(dst); // Shift is rcx modulo 0x1f + 32. |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1264 | shl(dst, Immediate(kSmiShift)); |
| 1265 | testq(dst, dst); |
| 1266 | if (src1.is(rcx) || src2.is(rcx)) { |
| 1267 | Label positive_result; |
| 1268 | j(positive, &positive_result); |
| 1269 | if (src1.is(rcx)) { |
| 1270 | movq(src1, kScratchRegister); |
| 1271 | } else { |
| 1272 | movq(src2, kScratchRegister); |
| 1273 | } |
| 1274 | jmp(on_not_smi_result); |
| 1275 | bind(&positive_result); |
| 1276 | } else { |
| 1277 | j(negative, on_not_smi_result); // src2 was zero and src1 negative. |
| 1278 | } |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 1279 | } |
| 1280 | |
| 1281 | |
| 1282 | void MacroAssembler::SmiShiftArithmeticRight(Register dst, |
| 1283 | Register src1, |
| 1284 | Register src2) { |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1285 | ASSERT(!dst.is(kScratchRegister)); |
| 1286 | ASSERT(!src1.is(kScratchRegister)); |
| 1287 | ASSERT(!src2.is(kScratchRegister)); |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 1288 | ASSERT(!dst.is(rcx)); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1289 | if (src1.is(rcx)) { |
| 1290 | movq(kScratchRegister, src1); |
| 1291 | } else if (src2.is(rcx)) { |
| 1292 | movq(kScratchRegister, src2); |
| 1293 | } |
| 1294 | if (!dst.is(src1)) { |
| 1295 | movq(dst, src1); |
| 1296 | } |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 1297 | SmiToInteger32(rcx, src2); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1298 | orl(rcx, Immediate(kSmiShift)); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1299 | sar_cl(dst); // Shift 32 + original rcx & 0x1f. |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1300 | shl(dst, Immediate(kSmiShift)); |
| 1301 | if (src1.is(rcx)) { |
| 1302 | movq(src1, kScratchRegister); |
| 1303 | } else if (src2.is(rcx)) { |
| 1304 | movq(src2, kScratchRegister); |
| 1305 | } |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 1306 | } |
| 1307 | |
| 1308 | |
| 1309 | void MacroAssembler::SelectNonSmi(Register dst, |
| 1310 | Register src1, |
| 1311 | Register src2, |
| 1312 | Label* on_not_smis) { |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1313 | ASSERT(!dst.is(kScratchRegister)); |
| 1314 | ASSERT(!src1.is(kScratchRegister)); |
| 1315 | ASSERT(!src2.is(kScratchRegister)); |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 1316 | ASSERT(!dst.is(src1)); |
| 1317 | ASSERT(!dst.is(src2)); |
| 1318 | // Both operands must not be smis. |
| 1319 | #ifdef DEBUG |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1320 | if (allow_stub_calls()) { // Check contains a stub call. |
| 1321 | Condition not_both_smis = NegateCondition(CheckBothSmi(src1, src2)); |
| 1322 | Check(not_both_smis, "Both registers were smis in SelectNonSmi."); |
| 1323 | } |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 1324 | #endif |
| 1325 | ASSERT_EQ(0, kSmiTag); |
| 1326 | ASSERT_EQ(0, Smi::FromInt(0)); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1327 | movl(kScratchRegister, Immediate(kSmiTagMask)); |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 1328 | and_(kScratchRegister, src1); |
| 1329 | testl(kScratchRegister, src2); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1330 | // If non-zero then both are smis. |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 1331 | j(not_zero, on_not_smis); |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 1332 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1333 | // Exactly one operand is a smi. |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 1334 | ASSERT_EQ(1, static_cast<int>(kSmiTagMask)); |
| 1335 | // kScratchRegister still holds src1 & kSmiTag, which is either zero or one. |
| 1336 | subq(kScratchRegister, Immediate(1)); |
| 1337 | // If src1 is a smi, then scratch register all 1s, else it is all 0s. |
| 1338 | movq(dst, src1); |
| 1339 | xor_(dst, src2); |
| 1340 | and_(dst, kScratchRegister); |
| 1341 | // If src1 is a smi, dst holds src1 ^ src2, else it is zero. |
| 1342 | xor_(dst, src1); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1343 | // If src1 is a smi, dst is src2, else it is src1, i.e., the non-smi. |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 1344 | } |
| 1345 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1346 | SmiIndex MacroAssembler::SmiToIndex(Register dst, |
| 1347 | Register src, |
| 1348 | int shift) { |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 1349 | ASSERT(is_uint6(shift)); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1350 | // There is a possible optimization if shift is in the range 60-63, but that |
| 1351 | // will (and must) never happen. |
| 1352 | if (!dst.is(src)) { |
| 1353 | movq(dst, src); |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 1354 | } |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1355 | if (shift < kSmiShift) { |
| 1356 | sar(dst, Immediate(kSmiShift - shift)); |
| 1357 | } else { |
| 1358 | shl(dst, Immediate(shift - kSmiShift)); |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 1359 | } |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 1360 | return SmiIndex(dst, times_1); |
| 1361 | } |
| 1362 | |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 1363 | SmiIndex MacroAssembler::SmiToNegativeIndex(Register dst, |
| 1364 | Register src, |
| 1365 | int shift) { |
| 1366 | // Register src holds a positive smi. |
| 1367 | ASSERT(is_uint6(shift)); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1368 | if (!dst.is(src)) { |
| 1369 | movq(dst, src); |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 1370 | } |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 1371 | neg(dst); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1372 | if (shift < kSmiShift) { |
| 1373 | sar(dst, Immediate(kSmiShift - shift)); |
| 1374 | } else { |
| 1375 | shl(dst, Immediate(shift - kSmiShift)); |
| 1376 | } |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 1377 | return SmiIndex(dst, times_1); |
| 1378 | } |
| 1379 | |
| 1380 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1381 | void MacroAssembler::JumpIfSmi(Register src, Label* on_smi) { |
| 1382 | ASSERT_EQ(0, kSmiTag); |
| 1383 | Condition smi = CheckSmi(src); |
| 1384 | j(smi, on_smi); |
| 1385 | } |
| 1386 | |
| 1387 | |
| 1388 | void MacroAssembler::JumpIfNotSmi(Register src, Label* on_not_smi) { |
| 1389 | Condition smi = CheckSmi(src); |
| 1390 | j(NegateCondition(smi), on_not_smi); |
| 1391 | } |
| 1392 | |
| 1393 | |
| 1394 | void MacroAssembler::JumpIfNotPositiveSmi(Register src, |
| 1395 | Label* on_not_positive_smi) { |
| 1396 | Condition positive_smi = CheckPositiveSmi(src); |
| 1397 | j(NegateCondition(positive_smi), on_not_positive_smi); |
| 1398 | } |
| 1399 | |
| 1400 | |
| 1401 | void MacroAssembler::JumpIfSmiEqualsConstant(Register src, |
| 1402 | Smi* constant, |
| 1403 | Label* on_equals) { |
| 1404 | SmiCompare(src, constant); |
| 1405 | j(equal, on_equals); |
| 1406 | } |
| 1407 | |
| 1408 | |
| 1409 | void MacroAssembler::JumpIfNotValidSmiValue(Register src, Label* on_invalid) { |
| 1410 | Condition is_valid = CheckInteger32ValidSmiValue(src); |
| 1411 | j(NegateCondition(is_valid), on_invalid); |
| 1412 | } |
| 1413 | |
| 1414 | |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 1415 | void MacroAssembler::JumpIfUIntNotValidSmiValue(Register src, |
| 1416 | Label* on_invalid) { |
| 1417 | Condition is_valid = CheckUInteger32ValidSmiValue(src); |
| 1418 | j(NegateCondition(is_valid), on_invalid); |
| 1419 | } |
| 1420 | |
| 1421 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1422 | void MacroAssembler::JumpIfNotBothSmi(Register src1, Register src2, |
| 1423 | Label* on_not_both_smi) { |
| 1424 | Condition both_smi = CheckBothSmi(src1, src2); |
| 1425 | j(NegateCondition(both_smi), on_not_both_smi); |
| 1426 | } |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 1427 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1428 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1429 | void MacroAssembler::JumpIfNotBothPositiveSmi(Register src1, Register src2, |
| 1430 | Label* on_not_both_smi) { |
| 1431 | Condition both_smi = CheckBothPositiveSmi(src1, src2); |
| 1432 | j(NegateCondition(both_smi), on_not_both_smi); |
| 1433 | } |
| 1434 | |
| 1435 | |
| 1436 | |
| 1437 | void MacroAssembler::JumpIfNotBothSequentialAsciiStrings(Register first_object, |
| 1438 | Register second_object, |
| 1439 | Register scratch1, |
| 1440 | Register scratch2, |
| 1441 | Label* on_fail) { |
| 1442 | // Check that both objects are not smis. |
| 1443 | Condition either_smi = CheckEitherSmi(first_object, second_object); |
| 1444 | j(either_smi, on_fail); |
| 1445 | |
| 1446 | // Load instance type for both strings. |
| 1447 | movq(scratch1, FieldOperand(first_object, HeapObject::kMapOffset)); |
| 1448 | movq(scratch2, FieldOperand(second_object, HeapObject::kMapOffset)); |
| 1449 | movzxbl(scratch1, FieldOperand(scratch1, Map::kInstanceTypeOffset)); |
| 1450 | movzxbl(scratch2, FieldOperand(scratch2, Map::kInstanceTypeOffset)); |
| 1451 | |
| 1452 | // Check that both are flat ascii strings. |
| 1453 | ASSERT(kNotStringTag != 0); |
| 1454 | const int kFlatAsciiStringMask = |
| 1455 | kIsNotStringMask | kStringRepresentationMask | kStringEncodingMask; |
| 1456 | const int kFlatAsciiStringTag = ASCII_STRING_TYPE; |
| 1457 | |
| 1458 | andl(scratch1, Immediate(kFlatAsciiStringMask)); |
| 1459 | andl(scratch2, Immediate(kFlatAsciiStringMask)); |
| 1460 | // Interleave the bits to check both scratch1 and scratch2 in one test. |
| 1461 | ASSERT_EQ(0, kFlatAsciiStringMask & (kFlatAsciiStringMask << 3)); |
| 1462 | lea(scratch1, Operand(scratch1, scratch2, times_8, 0)); |
| 1463 | cmpl(scratch1, |
| 1464 | Immediate(kFlatAsciiStringTag + (kFlatAsciiStringTag << 3))); |
| 1465 | j(not_equal, on_fail); |
| 1466 | } |
| 1467 | |
| 1468 | |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 1469 | void MacroAssembler::JumpIfInstanceTypeIsNotSequentialAscii( |
| 1470 | Register instance_type, |
| 1471 | Register scratch, |
| 1472 | Label *failure) { |
| 1473 | if (!scratch.is(instance_type)) { |
| 1474 | movl(scratch, instance_type); |
| 1475 | } |
| 1476 | |
| 1477 | const int kFlatAsciiStringMask = |
| 1478 | kIsNotStringMask | kStringRepresentationMask | kStringEncodingMask; |
| 1479 | |
| 1480 | andl(scratch, Immediate(kFlatAsciiStringMask)); |
| 1481 | cmpl(scratch, Immediate(kStringTag | kSeqStringTag | kAsciiStringTag)); |
| 1482 | j(not_equal, failure); |
| 1483 | } |
| 1484 | |
| 1485 | |
| 1486 | void MacroAssembler::JumpIfBothInstanceTypesAreNotSequentialAscii( |
| 1487 | Register first_object_instance_type, |
| 1488 | Register second_object_instance_type, |
| 1489 | Register scratch1, |
| 1490 | Register scratch2, |
| 1491 | Label* on_fail) { |
| 1492 | // Load instance type for both strings. |
| 1493 | movq(scratch1, first_object_instance_type); |
| 1494 | movq(scratch2, second_object_instance_type); |
| 1495 | |
| 1496 | // Check that both are flat ascii strings. |
| 1497 | ASSERT(kNotStringTag != 0); |
| 1498 | const int kFlatAsciiStringMask = |
| 1499 | kIsNotStringMask | kStringRepresentationMask | kStringEncodingMask; |
| 1500 | const int kFlatAsciiStringTag = ASCII_STRING_TYPE; |
| 1501 | |
| 1502 | andl(scratch1, Immediate(kFlatAsciiStringMask)); |
| 1503 | andl(scratch2, Immediate(kFlatAsciiStringMask)); |
| 1504 | // Interleave the bits to check both scratch1 and scratch2 in one test. |
| 1505 | ASSERT_EQ(0, kFlatAsciiStringMask & (kFlatAsciiStringMask << 3)); |
| 1506 | lea(scratch1, Operand(scratch1, scratch2, times_8, 0)); |
| 1507 | cmpl(scratch1, |
| 1508 | Immediate(kFlatAsciiStringTag + (kFlatAsciiStringTag << 3))); |
| 1509 | j(not_equal, on_fail); |
| 1510 | } |
| 1511 | |
| 1512 | |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 1513 | void MacroAssembler::Move(Register dst, Handle<Object> source) { |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 1514 | ASSERT(!source->IsFailure()); |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 1515 | if (source->IsSmi()) { |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1516 | Move(dst, Smi::cast(*source)); |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 1517 | } else { |
| 1518 | movq(dst, source, RelocInfo::EMBEDDED_OBJECT); |
| 1519 | } |
| 1520 | } |
| 1521 | |
| 1522 | |
| 1523 | void MacroAssembler::Move(const Operand& dst, Handle<Object> source) { |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1524 | ASSERT(!source->IsFailure()); |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 1525 | if (source->IsSmi()) { |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1526 | Move(dst, Smi::cast(*source)); |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 1527 | } else { |
| 1528 | movq(kScratchRegister, source, RelocInfo::EMBEDDED_OBJECT); |
| 1529 | movq(dst, kScratchRegister); |
| 1530 | } |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 1531 | } |
| 1532 | |
| 1533 | |
| 1534 | void MacroAssembler::Cmp(Register dst, Handle<Object> source) { |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1535 | if (source->IsSmi()) { |
| 1536 | SmiCompare(dst, Smi::cast(*source)); |
| 1537 | } else { |
| 1538 | Move(kScratchRegister, source); |
| 1539 | cmpq(dst, kScratchRegister); |
| 1540 | } |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 1541 | } |
| 1542 | |
| 1543 | |
ager@chromium.org | 3e87580 | 2009-06-29 08:26:34 +0000 | [diff] [blame] | 1544 | void MacroAssembler::Cmp(const Operand& dst, Handle<Object> source) { |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 1545 | if (source->IsSmi()) { |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1546 | SmiCompare(dst, Smi::cast(*source)); |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 1547 | } else { |
| 1548 | ASSERT(source->IsHeapObject()); |
| 1549 | movq(kScratchRegister, source, RelocInfo::EMBEDDED_OBJECT); |
| 1550 | cmpq(dst, kScratchRegister); |
| 1551 | } |
ager@chromium.org | 3e87580 | 2009-06-29 08:26:34 +0000 | [diff] [blame] | 1552 | } |
| 1553 | |
| 1554 | |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 1555 | void MacroAssembler::Push(Handle<Object> source) { |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 1556 | if (source->IsSmi()) { |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1557 | Push(Smi::cast(*source)); |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 1558 | } else { |
| 1559 | ASSERT(source->IsHeapObject()); |
| 1560 | movq(kScratchRegister, source, RelocInfo::EMBEDDED_OBJECT); |
| 1561 | push(kScratchRegister); |
| 1562 | } |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 1563 | } |
| 1564 | |
| 1565 | |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 1566 | void MacroAssembler::Push(Smi* source) { |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 1567 | intptr_t smi = reinterpret_cast<intptr_t>(source); |
| 1568 | if (is_int32(smi)) { |
| 1569 | push(Immediate(static_cast<int32_t>(smi))); |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 1570 | } else { |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 1571 | Set(kScratchRegister, smi); |
| 1572 | push(kScratchRegister); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1573 | } |
| 1574 | } |
| 1575 | |
| 1576 | |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 1577 | void MacroAssembler::Drop(int stack_elements) { |
| 1578 | if (stack_elements > 0) { |
| 1579 | addq(rsp, Immediate(stack_elements * kPointerSize)); |
| 1580 | } |
| 1581 | } |
| 1582 | |
| 1583 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1584 | void MacroAssembler::Test(const Operand& src, Smi* source) { |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1585 | testl(Operand(src, kIntSize), Immediate(source->value())); |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 1586 | } |
| 1587 | |
| 1588 | |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 1589 | void MacroAssembler::Jump(ExternalReference ext) { |
| 1590 | movq(kScratchRegister, ext); |
| 1591 | jmp(kScratchRegister); |
| 1592 | } |
| 1593 | |
| 1594 | |
| 1595 | void MacroAssembler::Jump(Address destination, RelocInfo::Mode rmode) { |
| 1596 | movq(kScratchRegister, destination, rmode); |
| 1597 | jmp(kScratchRegister); |
| 1598 | } |
| 1599 | |
| 1600 | |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 1601 | void MacroAssembler::Jump(Handle<Code> code_object, RelocInfo::Mode rmode) { |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 1602 | // TODO(X64): Inline this |
| 1603 | jmp(code_object, rmode); |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 1604 | } |
| 1605 | |
| 1606 | |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 1607 | void MacroAssembler::Call(ExternalReference ext) { |
| 1608 | movq(kScratchRegister, ext); |
| 1609 | call(kScratchRegister); |
| 1610 | } |
| 1611 | |
| 1612 | |
| 1613 | void MacroAssembler::Call(Address destination, RelocInfo::Mode rmode) { |
| 1614 | movq(kScratchRegister, destination, rmode); |
| 1615 | call(kScratchRegister); |
| 1616 | } |
| 1617 | |
| 1618 | |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 1619 | void MacroAssembler::Call(Handle<Code> code_object, RelocInfo::Mode rmode) { |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 1620 | ASSERT(RelocInfo::IsCodeTarget(rmode)); |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 1621 | WriteRecordedPositions(); |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 1622 | call(code_object, rmode); |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 1623 | } |
| 1624 | |
| 1625 | |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 1626 | void MacroAssembler::PushTryHandler(CodeLocation try_location, |
| 1627 | HandlerType type) { |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 1628 | // Adjust this code if not the case. |
| 1629 | ASSERT(StackHandlerConstants::kSize == 4 * kPointerSize); |
| 1630 | |
| 1631 | // The pc (return address) is already on TOS. This code pushes state, |
| 1632 | // frame pointer and current handler. Check that they are expected |
| 1633 | // next on the stack, in that order. |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 1634 | ASSERT_EQ(StackHandlerConstants::kStateOffset, |
| 1635 | StackHandlerConstants::kPCOffset - kPointerSize); |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 1636 | ASSERT_EQ(StackHandlerConstants::kFPOffset, |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 1637 | StackHandlerConstants::kStateOffset - kPointerSize); |
| 1638 | ASSERT_EQ(StackHandlerConstants::kNextOffset, |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 1639 | StackHandlerConstants::kFPOffset - kPointerSize); |
| 1640 | |
| 1641 | if (try_location == IN_JAVASCRIPT) { |
| 1642 | if (type == TRY_CATCH_HANDLER) { |
| 1643 | push(Immediate(StackHandler::TRY_CATCH)); |
| 1644 | } else { |
| 1645 | push(Immediate(StackHandler::TRY_FINALLY)); |
| 1646 | } |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 1647 | push(rbp); |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 1648 | } else { |
| 1649 | ASSERT(try_location == IN_JS_ENTRY); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 1650 | // The frame pointer does not point to a JS frame so we save NULL |
| 1651 | // for rbp. We expect the code throwing an exception to check rbp |
| 1652 | // before dereferencing it to restore the context. |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 1653 | push(Immediate(StackHandler::ENTRY)); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 1654 | push(Immediate(0)); // NULL frame pointer. |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 1655 | } |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 1656 | // Save the current handler. |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 1657 | movq(kScratchRegister, ExternalReference(Top::k_handler_address)); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 1658 | push(Operand(kScratchRegister, 0)); |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 1659 | // Link this handler. |
| 1660 | movq(Operand(kScratchRegister, 0), rsp); |
| 1661 | } |
| 1662 | |
| 1663 | |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 1664 | void MacroAssembler::PopTryHandler() { |
| 1665 | ASSERT_EQ(0, StackHandlerConstants::kNextOffset); |
| 1666 | // Unlink this handler. |
| 1667 | movq(kScratchRegister, ExternalReference(Top::k_handler_address)); |
| 1668 | pop(Operand(kScratchRegister, 0)); |
| 1669 | // Remove the remaining fields. |
| 1670 | addq(rsp, Immediate(StackHandlerConstants::kSize - kPointerSize)); |
| 1671 | } |
| 1672 | |
| 1673 | |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 1674 | void MacroAssembler::Ret() { |
| 1675 | ret(0); |
| 1676 | } |
| 1677 | |
| 1678 | |
ager@chromium.org | 3e87580 | 2009-06-29 08:26:34 +0000 | [diff] [blame] | 1679 | void MacroAssembler::FCmp() { |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 1680 | fucomip(); |
| 1681 | ffree(0); |
| 1682 | fincstp(); |
ager@chromium.org | 3e87580 | 2009-06-29 08:26:34 +0000 | [diff] [blame] | 1683 | } |
| 1684 | |
| 1685 | |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 1686 | void MacroAssembler::CmpObjectType(Register heap_object, |
| 1687 | InstanceType type, |
| 1688 | Register map) { |
| 1689 | movq(map, FieldOperand(heap_object, HeapObject::kMapOffset)); |
| 1690 | CmpInstanceType(map, type); |
| 1691 | } |
| 1692 | |
| 1693 | |
| 1694 | void MacroAssembler::CmpInstanceType(Register map, InstanceType type) { |
| 1695 | cmpb(FieldOperand(map, Map::kInstanceTypeOffset), |
| 1696 | Immediate(static_cast<int8_t>(type))); |
| 1697 | } |
| 1698 | |
| 1699 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1700 | void MacroAssembler::CheckMap(Register obj, |
| 1701 | Handle<Map> map, |
| 1702 | Label* fail, |
| 1703 | bool is_heap_object) { |
| 1704 | if (!is_heap_object) { |
| 1705 | JumpIfSmi(obj, fail); |
| 1706 | } |
| 1707 | Cmp(FieldOperand(obj, HeapObject::kMapOffset), map); |
| 1708 | j(not_equal, fail); |
| 1709 | } |
| 1710 | |
| 1711 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1712 | void MacroAssembler::AbortIfNotNumber(Register object) { |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1713 | Label ok; |
| 1714 | Condition is_smi = CheckSmi(object); |
| 1715 | j(is_smi, &ok); |
| 1716 | Cmp(FieldOperand(object, HeapObject::kMapOffset), |
| 1717 | Factory::heap_number_map()); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1718 | Assert(equal, "Operand not a number"); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1719 | bind(&ok); |
| 1720 | } |
| 1721 | |
| 1722 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1723 | void MacroAssembler::AbortIfNotSmi(Register object) { |
lrn@chromium.org | 25156de | 2010-04-06 13:10:27 +0000 | [diff] [blame] | 1724 | Label ok; |
| 1725 | Condition is_smi = CheckSmi(object); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1726 | Assert(is_smi, "Operand not a smi"); |
lrn@chromium.org | 25156de | 2010-04-06 13:10:27 +0000 | [diff] [blame] | 1727 | } |
| 1728 | |
| 1729 | |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame^] | 1730 | void MacroAssembler::AbortIfNotRootValue(Register src, |
| 1731 | Heap::RootListIndex root_value_index, |
| 1732 | const char* message) { |
| 1733 | ASSERT(!src.is(kScratchRegister)); |
| 1734 | LoadRoot(kScratchRegister, root_value_index); |
| 1735 | cmpq(src, kScratchRegister); |
| 1736 | Check(equal, message); |
| 1737 | } |
| 1738 | |
| 1739 | |
| 1740 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1741 | Condition MacroAssembler::IsObjectStringType(Register heap_object, |
| 1742 | Register map, |
| 1743 | Register instance_type) { |
| 1744 | movq(map, FieldOperand(heap_object, HeapObject::kMapOffset)); |
| 1745 | movzxbl(instance_type, FieldOperand(map, Map::kInstanceTypeOffset)); |
| 1746 | ASSERT(kNotStringTag != 0); |
| 1747 | testb(instance_type, Immediate(kIsNotStringMask)); |
| 1748 | return zero; |
| 1749 | } |
| 1750 | |
| 1751 | |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 1752 | void MacroAssembler::TryGetFunctionPrototype(Register function, |
| 1753 | Register result, |
| 1754 | Label* miss) { |
| 1755 | // Check that the receiver isn't a smi. |
| 1756 | testl(function, Immediate(kSmiTagMask)); |
| 1757 | j(zero, miss); |
| 1758 | |
| 1759 | // Check that the function really is a function. |
| 1760 | CmpObjectType(function, JS_FUNCTION_TYPE, result); |
| 1761 | j(not_equal, miss); |
| 1762 | |
| 1763 | // Make sure that the function has an instance prototype. |
| 1764 | Label non_instance; |
| 1765 | testb(FieldOperand(result, Map::kBitFieldOffset), |
| 1766 | Immediate(1 << Map::kHasNonInstancePrototype)); |
| 1767 | j(not_zero, &non_instance); |
| 1768 | |
| 1769 | // Get the prototype or initial map from the function. |
| 1770 | movq(result, |
| 1771 | FieldOperand(function, JSFunction::kPrototypeOrInitialMapOffset)); |
| 1772 | |
| 1773 | // If the prototype or initial map is the hole, don't return it and |
| 1774 | // simply miss the cache instead. This will allow us to allocate a |
| 1775 | // prototype object on-demand in the runtime system. |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 1776 | CompareRoot(result, Heap::kTheHoleValueRootIndex); |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 1777 | j(equal, miss); |
| 1778 | |
| 1779 | // If the function does not have an initial map, we're done. |
| 1780 | Label done; |
| 1781 | CmpObjectType(result, MAP_TYPE, kScratchRegister); |
| 1782 | j(not_equal, &done); |
| 1783 | |
| 1784 | // Get the prototype from the initial map. |
| 1785 | movq(result, FieldOperand(result, Map::kPrototypeOffset)); |
| 1786 | jmp(&done); |
| 1787 | |
| 1788 | // Non-instance prototype: Fetch prototype from constructor field |
| 1789 | // in initial map. |
| 1790 | bind(&non_instance); |
| 1791 | movq(result, FieldOperand(result, Map::kConstructorOffset)); |
| 1792 | |
| 1793 | // All done. |
| 1794 | bind(&done); |
| 1795 | } |
| 1796 | |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 1797 | |
| 1798 | void MacroAssembler::SetCounter(StatsCounter* counter, int value) { |
| 1799 | if (FLAG_native_code_counters && counter->Enabled()) { |
| 1800 | movq(kScratchRegister, ExternalReference(counter)); |
| 1801 | movl(Operand(kScratchRegister, 0), Immediate(value)); |
| 1802 | } |
| 1803 | } |
| 1804 | |
| 1805 | |
| 1806 | void MacroAssembler::IncrementCounter(StatsCounter* counter, int value) { |
| 1807 | ASSERT(value > 0); |
| 1808 | if (FLAG_native_code_counters && counter->Enabled()) { |
| 1809 | movq(kScratchRegister, ExternalReference(counter)); |
| 1810 | Operand operand(kScratchRegister, 0); |
| 1811 | if (value == 1) { |
| 1812 | incl(operand); |
| 1813 | } else { |
| 1814 | addl(operand, Immediate(value)); |
| 1815 | } |
| 1816 | } |
| 1817 | } |
| 1818 | |
| 1819 | |
| 1820 | void MacroAssembler::DecrementCounter(StatsCounter* counter, int value) { |
| 1821 | ASSERT(value > 0); |
| 1822 | if (FLAG_native_code_counters && counter->Enabled()) { |
| 1823 | movq(kScratchRegister, ExternalReference(counter)); |
| 1824 | Operand operand(kScratchRegister, 0); |
| 1825 | if (value == 1) { |
| 1826 | decl(operand); |
| 1827 | } else { |
| 1828 | subl(operand, Immediate(value)); |
| 1829 | } |
| 1830 | } |
| 1831 | } |
| 1832 | |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 1833 | #ifdef ENABLE_DEBUGGER_SUPPORT |
| 1834 | |
| 1835 | void MacroAssembler::PushRegistersFromMemory(RegList regs) { |
| 1836 | ASSERT((regs & ~kJSCallerSaved) == 0); |
| 1837 | // Push the content of the memory location to the stack. |
| 1838 | for (int i = 0; i < kNumJSCallerSaved; i++) { |
| 1839 | int r = JSCallerSavedCode(i); |
| 1840 | if ((regs & (1 << r)) != 0) { |
| 1841 | ExternalReference reg_addr = |
| 1842 | ExternalReference(Debug_Address::Register(i)); |
| 1843 | movq(kScratchRegister, reg_addr); |
| 1844 | push(Operand(kScratchRegister, 0)); |
| 1845 | } |
| 1846 | } |
| 1847 | } |
| 1848 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1849 | |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 1850 | void MacroAssembler::SaveRegistersToMemory(RegList regs) { |
| 1851 | ASSERT((regs & ~kJSCallerSaved) == 0); |
| 1852 | // Copy the content of registers to memory location. |
| 1853 | for (int i = 0; i < kNumJSCallerSaved; i++) { |
| 1854 | int r = JSCallerSavedCode(i); |
| 1855 | if ((regs & (1 << r)) != 0) { |
| 1856 | Register reg = { r }; |
| 1857 | ExternalReference reg_addr = |
| 1858 | ExternalReference(Debug_Address::Register(i)); |
| 1859 | movq(kScratchRegister, reg_addr); |
| 1860 | movq(Operand(kScratchRegister, 0), reg); |
| 1861 | } |
| 1862 | } |
| 1863 | } |
| 1864 | |
| 1865 | |
| 1866 | void MacroAssembler::RestoreRegistersFromMemory(RegList regs) { |
| 1867 | ASSERT((regs & ~kJSCallerSaved) == 0); |
| 1868 | // Copy the content of memory location to registers. |
| 1869 | for (int i = kNumJSCallerSaved - 1; i >= 0; i--) { |
| 1870 | int r = JSCallerSavedCode(i); |
| 1871 | if ((regs & (1 << r)) != 0) { |
| 1872 | Register reg = { r }; |
| 1873 | ExternalReference reg_addr = |
| 1874 | ExternalReference(Debug_Address::Register(i)); |
| 1875 | movq(kScratchRegister, reg_addr); |
| 1876 | movq(reg, Operand(kScratchRegister, 0)); |
| 1877 | } |
| 1878 | } |
| 1879 | } |
| 1880 | |
| 1881 | |
| 1882 | void MacroAssembler::PopRegistersToMemory(RegList regs) { |
| 1883 | ASSERT((regs & ~kJSCallerSaved) == 0); |
| 1884 | // Pop the content from the stack to the memory location. |
| 1885 | for (int i = kNumJSCallerSaved - 1; i >= 0; i--) { |
| 1886 | int r = JSCallerSavedCode(i); |
| 1887 | if ((regs & (1 << r)) != 0) { |
| 1888 | ExternalReference reg_addr = |
| 1889 | ExternalReference(Debug_Address::Register(i)); |
| 1890 | movq(kScratchRegister, reg_addr); |
| 1891 | pop(Operand(kScratchRegister, 0)); |
| 1892 | } |
| 1893 | } |
| 1894 | } |
| 1895 | |
| 1896 | |
| 1897 | void MacroAssembler::CopyRegistersFromStackToMemory(Register base, |
| 1898 | Register scratch, |
| 1899 | RegList regs) { |
| 1900 | ASSERT(!scratch.is(kScratchRegister)); |
| 1901 | ASSERT(!base.is(kScratchRegister)); |
| 1902 | ASSERT(!base.is(scratch)); |
| 1903 | ASSERT((regs & ~kJSCallerSaved) == 0); |
| 1904 | // Copy the content of the stack to the memory location and adjust base. |
| 1905 | for (int i = kNumJSCallerSaved - 1; i >= 0; i--) { |
| 1906 | int r = JSCallerSavedCode(i); |
| 1907 | if ((regs & (1 << r)) != 0) { |
| 1908 | movq(scratch, Operand(base, 0)); |
| 1909 | ExternalReference reg_addr = |
| 1910 | ExternalReference(Debug_Address::Register(i)); |
| 1911 | movq(kScratchRegister, reg_addr); |
| 1912 | movq(Operand(kScratchRegister, 0), scratch); |
| 1913 | lea(base, Operand(base, kPointerSize)); |
| 1914 | } |
| 1915 | } |
| 1916 | } |
| 1917 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1918 | void MacroAssembler::DebugBreak() { |
| 1919 | ASSERT(allow_stub_calls()); |
| 1920 | xor_(rax, rax); // no arguments |
| 1921 | movq(rbx, ExternalReference(Runtime::kDebugBreak)); |
| 1922 | CEntryStub ces(1); |
| 1923 | Call(ces.GetCode(), RelocInfo::DEBUG_BREAK); |
ager@chromium.org | 3e87580 | 2009-06-29 08:26:34 +0000 | [diff] [blame] | 1924 | } |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1925 | #endif // ENABLE_DEBUGGER_SUPPORT |
ager@chromium.org | 3e87580 | 2009-06-29 08:26:34 +0000 | [diff] [blame] | 1926 | |
| 1927 | |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 1928 | void MacroAssembler::InvokePrologue(const ParameterCount& expected, |
| 1929 | const ParameterCount& actual, |
| 1930 | Handle<Code> code_constant, |
| 1931 | Register code_register, |
| 1932 | Label* done, |
| 1933 | InvokeFlag flag) { |
| 1934 | bool definitely_matches = false; |
| 1935 | Label invoke; |
| 1936 | if (expected.is_immediate()) { |
| 1937 | ASSERT(actual.is_immediate()); |
| 1938 | if (expected.immediate() == actual.immediate()) { |
| 1939 | definitely_matches = true; |
| 1940 | } else { |
| 1941 | movq(rax, Immediate(actual.immediate())); |
| 1942 | if (expected.immediate() == |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1943 | SharedFunctionInfo::kDontAdaptArgumentsSentinel) { |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 1944 | // Don't worry about adapting arguments for built-ins that |
| 1945 | // don't want that done. Skip adaption code by making it look |
| 1946 | // like we have a match between expected and actual number of |
| 1947 | // arguments. |
| 1948 | definitely_matches = true; |
| 1949 | } else { |
| 1950 | movq(rbx, Immediate(expected.immediate())); |
| 1951 | } |
| 1952 | } |
| 1953 | } else { |
| 1954 | if (actual.is_immediate()) { |
| 1955 | // Expected is in register, actual is immediate. This is the |
| 1956 | // case when we invoke function values without going through the |
| 1957 | // IC mechanism. |
| 1958 | cmpq(expected.reg(), Immediate(actual.immediate())); |
| 1959 | j(equal, &invoke); |
| 1960 | ASSERT(expected.reg().is(rbx)); |
| 1961 | movq(rax, Immediate(actual.immediate())); |
| 1962 | } else if (!expected.reg().is(actual.reg())) { |
| 1963 | // Both expected and actual are in (different) registers. This |
| 1964 | // is the case when we invoke functions using call and apply. |
| 1965 | cmpq(expected.reg(), actual.reg()); |
| 1966 | j(equal, &invoke); |
| 1967 | ASSERT(actual.reg().is(rax)); |
| 1968 | ASSERT(expected.reg().is(rbx)); |
| 1969 | } |
| 1970 | } |
| 1971 | |
| 1972 | if (!definitely_matches) { |
| 1973 | Handle<Code> adaptor = |
| 1974 | Handle<Code>(Builtins::builtin(Builtins::ArgumentsAdaptorTrampoline)); |
| 1975 | if (!code_constant.is_null()) { |
| 1976 | movq(rdx, code_constant, RelocInfo::EMBEDDED_OBJECT); |
| 1977 | addq(rdx, Immediate(Code::kHeaderSize - kHeapObjectTag)); |
| 1978 | } else if (!code_register.is(rdx)) { |
| 1979 | movq(rdx, code_register); |
| 1980 | } |
| 1981 | |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 1982 | if (flag == CALL_FUNCTION) { |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 1983 | Call(adaptor, RelocInfo::CODE_TARGET); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 1984 | jmp(done); |
| 1985 | } else { |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 1986 | Jump(adaptor, RelocInfo::CODE_TARGET); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 1987 | } |
| 1988 | bind(&invoke); |
| 1989 | } |
| 1990 | } |
| 1991 | |
| 1992 | |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 1993 | void MacroAssembler::InvokeCode(Register code, |
| 1994 | const ParameterCount& expected, |
| 1995 | const ParameterCount& actual, |
| 1996 | InvokeFlag flag) { |
| 1997 | Label done; |
| 1998 | InvokePrologue(expected, actual, Handle<Code>::null(), code, &done, flag); |
| 1999 | if (flag == CALL_FUNCTION) { |
| 2000 | call(code); |
| 2001 | } else { |
| 2002 | ASSERT(flag == JUMP_FUNCTION); |
| 2003 | jmp(code); |
| 2004 | } |
| 2005 | bind(&done); |
| 2006 | } |
| 2007 | |
| 2008 | |
| 2009 | void MacroAssembler::InvokeCode(Handle<Code> code, |
| 2010 | const ParameterCount& expected, |
| 2011 | const ParameterCount& actual, |
| 2012 | RelocInfo::Mode rmode, |
| 2013 | InvokeFlag flag) { |
| 2014 | Label done; |
| 2015 | Register dummy = rax; |
| 2016 | InvokePrologue(expected, actual, code, dummy, &done, flag); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 2017 | if (flag == CALL_FUNCTION) { |
ager@chromium.org | 3e87580 | 2009-06-29 08:26:34 +0000 | [diff] [blame] | 2018 | Call(code, rmode); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 2019 | } else { |
| 2020 | ASSERT(flag == JUMP_FUNCTION); |
ager@chromium.org | 3e87580 | 2009-06-29 08:26:34 +0000 | [diff] [blame] | 2021 | Jump(code, rmode); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 2022 | } |
| 2023 | bind(&done); |
| 2024 | } |
| 2025 | |
| 2026 | |
| 2027 | void MacroAssembler::InvokeFunction(Register function, |
| 2028 | const ParameterCount& actual, |
| 2029 | InvokeFlag flag) { |
| 2030 | ASSERT(function.is(rdi)); |
| 2031 | movq(rdx, FieldOperand(function, JSFunction::kSharedFunctionInfoOffset)); |
| 2032 | movq(rsi, FieldOperand(function, JSFunction::kContextOffset)); |
ager@chromium.org | 3e87580 | 2009-06-29 08:26:34 +0000 | [diff] [blame] | 2033 | movsxlq(rbx, |
| 2034 | FieldOperand(rdx, SharedFunctionInfo::kFormalParameterCountOffset)); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 2035 | movq(rdx, FieldOperand(rdx, SharedFunctionInfo::kCodeOffset)); |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 2036 | // Advances rdx to the end of the Code object header, to the start of |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 2037 | // the executable code. |
| 2038 | lea(rdx, FieldOperand(rdx, Code::kHeaderSize)); |
| 2039 | |
| 2040 | ParameterCount expected(rbx); |
| 2041 | InvokeCode(rdx, expected, actual, flag); |
| 2042 | } |
| 2043 | |
| 2044 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2045 | void MacroAssembler::InvokeFunction(JSFunction* function, |
| 2046 | const ParameterCount& actual, |
| 2047 | InvokeFlag flag) { |
| 2048 | ASSERT(function->is_compiled()); |
| 2049 | // Get the function and setup the context. |
| 2050 | Move(rdi, Handle<JSFunction>(function)); |
| 2051 | movq(rsi, FieldOperand(rdi, JSFunction::kContextOffset)); |
| 2052 | |
| 2053 | // Invoke the cached code. |
| 2054 | Handle<Code> code(function->code()); |
| 2055 | ParameterCount expected(function->shared()->formal_parameter_count()); |
| 2056 | InvokeCode(code, expected, actual, RelocInfo::CODE_TARGET, flag); |
| 2057 | } |
| 2058 | |
| 2059 | |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 2060 | void MacroAssembler::EnterFrame(StackFrame::Type type) { |
| 2061 | push(rbp); |
| 2062 | movq(rbp, rsp); |
| 2063 | push(rsi); // Context. |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2064 | Push(Smi::FromInt(type)); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 2065 | movq(kScratchRegister, CodeObject(), RelocInfo::EMBEDDED_OBJECT); |
| 2066 | push(kScratchRegister); |
| 2067 | if (FLAG_debug_code) { |
| 2068 | movq(kScratchRegister, |
| 2069 | Factory::undefined_value(), |
| 2070 | RelocInfo::EMBEDDED_OBJECT); |
| 2071 | cmpq(Operand(rsp, 0), kScratchRegister); |
| 2072 | Check(not_equal, "code object not properly patched"); |
| 2073 | } |
| 2074 | } |
| 2075 | |
| 2076 | |
| 2077 | void MacroAssembler::LeaveFrame(StackFrame::Type type) { |
| 2078 | if (FLAG_debug_code) { |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2079 | Move(kScratchRegister, Smi::FromInt(type)); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 2080 | cmpq(Operand(rbp, StandardFrameConstants::kMarkerOffset), kScratchRegister); |
| 2081 | Check(equal, "stack frame types must match"); |
| 2082 | } |
| 2083 | movq(rsp, rbp); |
| 2084 | pop(rbp); |
| 2085 | } |
| 2086 | |
| 2087 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 2088 | void MacroAssembler::EnterExitFrame(ExitFrame::Mode mode, int result_size) { |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 2089 | // Setup the frame structure on the stack. |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 2090 | // All constants are relative to the frame pointer of the exit frame. |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 2091 | ASSERT(ExitFrameConstants::kCallerSPDisplacement == +2 * kPointerSize); |
| 2092 | ASSERT(ExitFrameConstants::kCallerPCOffset == +1 * kPointerSize); |
| 2093 | ASSERT(ExitFrameConstants::kCallerFPOffset == 0 * kPointerSize); |
| 2094 | push(rbp); |
| 2095 | movq(rbp, rsp); |
| 2096 | |
| 2097 | // Reserve room for entry stack pointer and push the debug marker. |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2098 | ASSERT(ExitFrameConstants::kSPOffset == -1 * kPointerSize); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2099 | push(Immediate(0)); // Saved entry sp, patched before call. |
| 2100 | movq(kScratchRegister, CodeObject(), RelocInfo::EMBEDDED_OBJECT); |
| 2101 | push(kScratchRegister); // Accessed from EditFrame::code_slot. |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 2102 | |
| 2103 | // Save the frame pointer and the context in top. |
| 2104 | ExternalReference c_entry_fp_address(Top::k_c_entry_fp_address); |
| 2105 | ExternalReference context_address(Top::k_context_address); |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 2106 | movq(r14, rax); // Backup rax before we use it. |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 2107 | |
| 2108 | movq(rax, rbp); |
| 2109 | store_rax(c_entry_fp_address); |
| 2110 | movq(rax, rsi); |
| 2111 | store_rax(context_address); |
| 2112 | |
| 2113 | // Setup argv in callee-saved register r15. It is reused in LeaveExitFrame, |
| 2114 | // so it must be retained across the C-call. |
| 2115 | int offset = StandardFrameConstants::kCallerSPOffset - kPointerSize; |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 2116 | lea(r15, Operand(rbp, r14, times_pointer_size, offset)); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 2117 | |
| 2118 | #ifdef ENABLE_DEBUGGER_SUPPORT |
| 2119 | // Save the state of all registers to the stack from the memory |
| 2120 | // location. This is needed to allow nested break points. |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 2121 | if (mode == ExitFrame::MODE_DEBUG) { |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 2122 | // TODO(1243899): This should be symmetric to |
| 2123 | // CopyRegistersFromStackToMemory() but it isn't! esp is assumed |
| 2124 | // correct here, but computed for the other call. Very error |
| 2125 | // prone! FIX THIS. Actually there are deeper problems with |
| 2126 | // register saving than this asymmetry (see the bug report |
| 2127 | // associated with this issue). |
| 2128 | PushRegistersFromMemory(kJSCallerSaved); |
| 2129 | } |
| 2130 | #endif |
| 2131 | |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 2132 | #ifdef _WIN64 |
| 2133 | // Reserve space on stack for result and argument structures, if necessary. |
| 2134 | int result_stack_space = (result_size < 2) ? 0 : result_size * kPointerSize; |
| 2135 | // Reserve space for the Arguments object. The Windows 64-bit ABI |
| 2136 | // requires us to pass this structure as a pointer to its location on |
| 2137 | // the stack. The structure contains 2 values. |
| 2138 | int argument_stack_space = 2 * kPointerSize; |
| 2139 | // We also need backing space for 4 parameters, even though |
| 2140 | // we only pass one or two parameter, and it is in a register. |
| 2141 | int argument_mirror_space = 4 * kPointerSize; |
| 2142 | int total_stack_space = |
| 2143 | argument_mirror_space + argument_stack_space + result_stack_space; |
| 2144 | subq(rsp, Immediate(total_stack_space)); |
| 2145 | #endif |
| 2146 | |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 2147 | // Get the required frame alignment for the OS. |
| 2148 | static const int kFrameAlignment = OS::ActivationFrameAlignment(); |
| 2149 | if (kFrameAlignment > 0) { |
| 2150 | ASSERT(IsPowerOf2(kFrameAlignment)); |
| 2151 | movq(kScratchRegister, Immediate(-kFrameAlignment)); |
| 2152 | and_(rsp, kScratchRegister); |
| 2153 | } |
| 2154 | |
| 2155 | // Patch the saved entry sp. |
| 2156 | movq(Operand(rbp, ExitFrameConstants::kSPOffset), rsp); |
| 2157 | } |
| 2158 | |
| 2159 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 2160 | void MacroAssembler::LeaveExitFrame(ExitFrame::Mode mode, int result_size) { |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 2161 | // Registers: |
| 2162 | // r15 : argv |
| 2163 | #ifdef ENABLE_DEBUGGER_SUPPORT |
| 2164 | // Restore the memory copy of the registers by digging them out from |
| 2165 | // the stack. This is needed to allow nested break points. |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 2166 | if (mode == ExitFrame::MODE_DEBUG) { |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 2167 | // It's okay to clobber register rbx below because we don't need |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 2168 | // the function pointer after this. |
| 2169 | const int kCallerSavedSize = kNumJSCallerSaved * kPointerSize; |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 2170 | int kOffset = ExitFrameConstants::kCodeOffset - kCallerSavedSize; |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 2171 | lea(rbx, Operand(rbp, kOffset)); |
| 2172 | CopyRegistersFromStackToMemory(rbx, rcx, kJSCallerSaved); |
| 2173 | } |
| 2174 | #endif |
| 2175 | |
| 2176 | // Get the return address from the stack and restore the frame pointer. |
| 2177 | movq(rcx, Operand(rbp, 1 * kPointerSize)); |
| 2178 | movq(rbp, Operand(rbp, 0 * kPointerSize)); |
| 2179 | |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 2180 | // Pop everything up to and including the arguments and the receiver |
| 2181 | // from the caller stack. |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 2182 | lea(rsp, Operand(r15, 1 * kPointerSize)); |
| 2183 | |
| 2184 | // Restore current context from top and clear it in debug mode. |
| 2185 | ExternalReference context_address(Top::k_context_address); |
| 2186 | movq(kScratchRegister, context_address); |
| 2187 | movq(rsi, Operand(kScratchRegister, 0)); |
| 2188 | #ifdef DEBUG |
| 2189 | movq(Operand(kScratchRegister, 0), Immediate(0)); |
| 2190 | #endif |
| 2191 | |
| 2192 | // Push the return address to get ready to return. |
| 2193 | push(rcx); |
| 2194 | |
| 2195 | // Clear the top frame. |
| 2196 | ExternalReference c_entry_fp_address(Top::k_c_entry_fp_address); |
| 2197 | movq(kScratchRegister, c_entry_fp_address); |
| 2198 | movq(Operand(kScratchRegister, 0), Immediate(0)); |
| 2199 | } |
| 2200 | |
| 2201 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2202 | Register MacroAssembler::CheckMaps(JSObject* object, |
| 2203 | Register object_reg, |
| 2204 | JSObject* holder, |
| 2205 | Register holder_reg, |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 2206 | Register scratch, |
kmillikin@chromium.org | 4111b80 | 2010-05-03 10:34:42 +0000 | [diff] [blame] | 2207 | int save_at_depth, |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 2208 | Label* miss) { |
| 2209 | // Make sure there's no overlap between scratch and the other |
| 2210 | // registers. |
| 2211 | ASSERT(!scratch.is(object_reg) && !scratch.is(holder_reg)); |
| 2212 | |
| 2213 | // Keep track of the current object in register reg. On the first |
| 2214 | // iteration, reg is an alias for object_reg, on later iterations, |
| 2215 | // it is an alias for holder_reg. |
| 2216 | Register reg = object_reg; |
kmillikin@chromium.org | 4111b80 | 2010-05-03 10:34:42 +0000 | [diff] [blame] | 2217 | int depth = 0; |
| 2218 | |
| 2219 | if (save_at_depth == depth) { |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 2220 | movq(Operand(rsp, kPointerSize), object_reg); |
kmillikin@chromium.org | 4111b80 | 2010-05-03 10:34:42 +0000 | [diff] [blame] | 2221 | } |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 2222 | |
| 2223 | // Check the maps in the prototype chain. |
| 2224 | // Traverse the prototype chain from the object and do map checks. |
| 2225 | while (object != holder) { |
| 2226 | depth++; |
| 2227 | |
| 2228 | // Only global objects and objects that do not require access |
| 2229 | // checks are allowed in stubs. |
| 2230 | ASSERT(object->IsJSGlobalProxy() || !object->IsAccessCheckNeeded()); |
| 2231 | |
| 2232 | JSObject* prototype = JSObject::cast(object->GetPrototype()); |
| 2233 | if (Heap::InNewSpace(prototype)) { |
| 2234 | // Get the map of the current object. |
| 2235 | movq(scratch, FieldOperand(reg, HeapObject::kMapOffset)); |
| 2236 | Cmp(scratch, Handle<Map>(object->map())); |
| 2237 | // Branch on the result of the map check. |
| 2238 | j(not_equal, miss); |
| 2239 | // Check access rights to the global object. This has to happen |
| 2240 | // after the map check so that we know that the object is |
| 2241 | // actually a global object. |
| 2242 | if (object->IsJSGlobalProxy()) { |
| 2243 | CheckAccessGlobalProxy(reg, scratch, miss); |
| 2244 | |
| 2245 | // Restore scratch register to be the map of the object. |
| 2246 | // We load the prototype from the map in the scratch register. |
| 2247 | movq(scratch, FieldOperand(reg, HeapObject::kMapOffset)); |
| 2248 | } |
| 2249 | // The prototype is in new space; we cannot store a reference |
| 2250 | // to it in the code. Load it from the map. |
| 2251 | reg = holder_reg; // from now the object is in holder_reg |
| 2252 | movq(reg, FieldOperand(scratch, Map::kPrototypeOffset)); |
| 2253 | |
| 2254 | } else { |
| 2255 | // Check the map of the current object. |
| 2256 | Cmp(FieldOperand(reg, HeapObject::kMapOffset), |
| 2257 | Handle<Map>(object->map())); |
| 2258 | // Branch on the result of the map check. |
| 2259 | j(not_equal, miss); |
| 2260 | // Check access rights to the global object. This has to happen |
| 2261 | // after the map check so that we know that the object is |
| 2262 | // actually a global object. |
| 2263 | if (object->IsJSGlobalProxy()) { |
| 2264 | CheckAccessGlobalProxy(reg, scratch, miss); |
| 2265 | } |
| 2266 | // The prototype is in old space; load it directly. |
| 2267 | reg = holder_reg; // from now the object is in holder_reg |
| 2268 | Move(reg, Handle<JSObject>(prototype)); |
| 2269 | } |
| 2270 | |
kmillikin@chromium.org | 4111b80 | 2010-05-03 10:34:42 +0000 | [diff] [blame] | 2271 | if (save_at_depth == depth) { |
| 2272 | movq(Operand(rsp, kPointerSize), reg); |
| 2273 | } |
| 2274 | |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 2275 | // Go to the next object in the prototype chain. |
| 2276 | object = prototype; |
| 2277 | } |
| 2278 | |
| 2279 | // Check the holder map. |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2280 | Cmp(FieldOperand(reg, HeapObject::kMapOffset), Handle<Map>(holder->map())); |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 2281 | j(not_equal, miss); |
| 2282 | |
| 2283 | // Log the check depth. |
kmillikin@chromium.org | 4111b80 | 2010-05-03 10:34:42 +0000 | [diff] [blame] | 2284 | LOG(IntEvent("check-maps-depth", depth + 1)); |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 2285 | |
| 2286 | // Perform security check for access to the global object and return |
| 2287 | // the holder register. |
| 2288 | ASSERT(object == holder); |
| 2289 | ASSERT(object->IsJSGlobalProxy() || !object->IsAccessCheckNeeded()); |
| 2290 | if (object->IsJSGlobalProxy()) { |
| 2291 | CheckAccessGlobalProxy(reg, scratch, miss); |
| 2292 | } |
| 2293 | return reg; |
| 2294 | } |
| 2295 | |
| 2296 | |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 2297 | void MacroAssembler::CheckAccessGlobalProxy(Register holder_reg, |
| 2298 | Register scratch, |
| 2299 | Label* miss) { |
| 2300 | Label same_contexts; |
| 2301 | |
| 2302 | ASSERT(!holder_reg.is(scratch)); |
| 2303 | ASSERT(!scratch.is(kScratchRegister)); |
| 2304 | // Load current lexical context from the stack frame. |
| 2305 | movq(scratch, Operand(rbp, StandardFrameConstants::kContextOffset)); |
| 2306 | |
| 2307 | // When generating debug code, make sure the lexical context is set. |
| 2308 | if (FLAG_debug_code) { |
| 2309 | cmpq(scratch, Immediate(0)); |
| 2310 | Check(not_equal, "we should not have an empty lexical context"); |
| 2311 | } |
| 2312 | // Load the global context of the current context. |
| 2313 | int offset = Context::kHeaderSize + Context::GLOBAL_INDEX * kPointerSize; |
| 2314 | movq(scratch, FieldOperand(scratch, offset)); |
| 2315 | movq(scratch, FieldOperand(scratch, GlobalObject::kGlobalContextOffset)); |
| 2316 | |
| 2317 | // Check the context is a global context. |
| 2318 | if (FLAG_debug_code) { |
| 2319 | Cmp(FieldOperand(scratch, HeapObject::kMapOffset), |
| 2320 | Factory::global_context_map()); |
| 2321 | Check(equal, "JSGlobalObject::global_context should be a global context."); |
| 2322 | } |
| 2323 | |
| 2324 | // Check if both contexts are the same. |
| 2325 | cmpq(scratch, FieldOperand(holder_reg, JSGlobalProxy::kContextOffset)); |
| 2326 | j(equal, &same_contexts); |
| 2327 | |
| 2328 | // Compare security tokens. |
| 2329 | // Check that the security token in the calling global object is |
| 2330 | // compatible with the security token in the receiving global |
| 2331 | // object. |
| 2332 | |
| 2333 | // Check the context is a global context. |
| 2334 | if (FLAG_debug_code) { |
| 2335 | // Preserve original value of holder_reg. |
| 2336 | push(holder_reg); |
| 2337 | movq(holder_reg, FieldOperand(holder_reg, JSGlobalProxy::kContextOffset)); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 2338 | CompareRoot(holder_reg, Heap::kNullValueRootIndex); |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 2339 | Check(not_equal, "JSGlobalProxy::context() should not be null."); |
| 2340 | |
| 2341 | // Read the first word and compare to global_context_map(), |
| 2342 | movq(holder_reg, FieldOperand(holder_reg, HeapObject::kMapOffset)); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 2343 | CompareRoot(holder_reg, Heap::kGlobalContextMapRootIndex); |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 2344 | Check(equal, "JSGlobalObject::global_context should be a global context."); |
| 2345 | pop(holder_reg); |
| 2346 | } |
| 2347 | |
| 2348 | movq(kScratchRegister, |
| 2349 | FieldOperand(holder_reg, JSGlobalProxy::kContextOffset)); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2350 | int token_offset = |
| 2351 | Context::kHeaderSize + Context::SECURITY_TOKEN_INDEX * kPointerSize; |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 2352 | movq(scratch, FieldOperand(scratch, token_offset)); |
| 2353 | cmpq(scratch, FieldOperand(kScratchRegister, token_offset)); |
| 2354 | j(not_equal, miss); |
| 2355 | |
| 2356 | bind(&same_contexts); |
| 2357 | } |
| 2358 | |
| 2359 | |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 2360 | void MacroAssembler::LoadAllocationTopHelper(Register result, |
| 2361 | Register result_end, |
| 2362 | Register scratch, |
| 2363 | AllocationFlags flags) { |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 2364 | ExternalReference new_space_allocation_top = |
| 2365 | ExternalReference::new_space_allocation_top_address(); |
| 2366 | |
| 2367 | // Just return if allocation top is already known. |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 2368 | if ((flags & RESULT_CONTAINS_TOP) != 0) { |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 2369 | // No use of scratch if allocation top is provided. |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 2370 | ASSERT(!scratch.is_valid()); |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 2371 | #ifdef DEBUG |
| 2372 | // Assert that result actually contains top on entry. |
| 2373 | movq(kScratchRegister, new_space_allocation_top); |
| 2374 | cmpq(result, Operand(kScratchRegister, 0)); |
| 2375 | Check(equal, "Unexpected allocation top"); |
| 2376 | #endif |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 2377 | return; |
| 2378 | } |
| 2379 | |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 2380 | // Move address of new object to result. Use scratch register if available, |
| 2381 | // and keep address in scratch until call to UpdateAllocationTopHelper. |
| 2382 | if (scratch.is_valid()) { |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 2383 | ASSERT(!scratch.is(result_end)); |
| 2384 | movq(scratch, new_space_allocation_top); |
| 2385 | movq(result, Operand(scratch, 0)); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 2386 | } else if (result.is(rax)) { |
| 2387 | load_rax(new_space_allocation_top); |
| 2388 | } else { |
| 2389 | movq(kScratchRegister, new_space_allocation_top); |
| 2390 | movq(result, Operand(kScratchRegister, 0)); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 2391 | } |
| 2392 | } |
| 2393 | |
| 2394 | |
| 2395 | void MacroAssembler::UpdateAllocationTopHelper(Register result_end, |
| 2396 | Register scratch) { |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 2397 | if (FLAG_debug_code) { |
| 2398 | testq(result_end, Immediate(kObjectAlignmentMask)); |
| 2399 | Check(zero, "Unaligned allocation in new space"); |
| 2400 | } |
| 2401 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 2402 | ExternalReference new_space_allocation_top = |
| 2403 | ExternalReference::new_space_allocation_top_address(); |
| 2404 | |
| 2405 | // Update new top. |
| 2406 | if (result_end.is(rax)) { |
| 2407 | // rax can be stored directly to a memory location. |
| 2408 | store_rax(new_space_allocation_top); |
| 2409 | } else { |
| 2410 | // Register required - use scratch provided if available. |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 2411 | if (scratch.is_valid()) { |
| 2412 | movq(Operand(scratch, 0), result_end); |
| 2413 | } else { |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 2414 | movq(kScratchRegister, new_space_allocation_top); |
| 2415 | movq(Operand(kScratchRegister, 0), result_end); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 2416 | } |
| 2417 | } |
| 2418 | } |
| 2419 | |
| 2420 | |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 2421 | void MacroAssembler::AllocateInNewSpace(int object_size, |
| 2422 | Register result, |
| 2423 | Register result_end, |
| 2424 | Register scratch, |
| 2425 | Label* gc_required, |
| 2426 | AllocationFlags flags) { |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 2427 | ASSERT(!result.is(result_end)); |
| 2428 | |
| 2429 | // Load address of new object into result. |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 2430 | LoadAllocationTopHelper(result, result_end, scratch, flags); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 2431 | |
| 2432 | // Calculate new top and bail out if new space is exhausted. |
| 2433 | ExternalReference new_space_allocation_limit = |
| 2434 | ExternalReference::new_space_allocation_limit_address(); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 2435 | |
| 2436 | Register top_reg = result_end.is_valid() ? result_end : result; |
| 2437 | |
| 2438 | if (top_reg.is(result)) { |
| 2439 | addq(top_reg, Immediate(object_size)); |
| 2440 | } else { |
| 2441 | lea(top_reg, Operand(result, object_size)); |
| 2442 | } |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 2443 | movq(kScratchRegister, new_space_allocation_limit); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 2444 | cmpq(top_reg, Operand(kScratchRegister, 0)); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 2445 | j(above, gc_required); |
| 2446 | |
| 2447 | // Update allocation top. |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 2448 | UpdateAllocationTopHelper(top_reg, scratch); |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 2449 | |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 2450 | if (top_reg.is(result)) { |
| 2451 | if ((flags & TAG_OBJECT) != 0) { |
| 2452 | subq(result, Immediate(object_size - kHeapObjectTag)); |
| 2453 | } else { |
| 2454 | subq(result, Immediate(object_size)); |
| 2455 | } |
| 2456 | } else if ((flags & TAG_OBJECT) != 0) { |
| 2457 | // Tag the result if requested. |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 2458 | addq(result, Immediate(kHeapObjectTag)); |
| 2459 | } |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 2460 | } |
| 2461 | |
| 2462 | |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 2463 | void MacroAssembler::AllocateInNewSpace(int header_size, |
| 2464 | ScaleFactor element_size, |
| 2465 | Register element_count, |
| 2466 | Register result, |
| 2467 | Register result_end, |
| 2468 | Register scratch, |
| 2469 | Label* gc_required, |
| 2470 | AllocationFlags flags) { |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 2471 | ASSERT(!result.is(result_end)); |
| 2472 | |
| 2473 | // Load address of new object into result. |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 2474 | LoadAllocationTopHelper(result, result_end, scratch, flags); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 2475 | |
| 2476 | // Calculate new top and bail out if new space is exhausted. |
| 2477 | ExternalReference new_space_allocation_limit = |
| 2478 | ExternalReference::new_space_allocation_limit_address(); |
| 2479 | lea(result_end, Operand(result, element_count, element_size, header_size)); |
| 2480 | movq(kScratchRegister, new_space_allocation_limit); |
| 2481 | cmpq(result_end, Operand(kScratchRegister, 0)); |
| 2482 | j(above, gc_required); |
| 2483 | |
| 2484 | // Update allocation top. |
| 2485 | UpdateAllocationTopHelper(result_end, scratch); |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 2486 | |
| 2487 | // Tag the result if requested. |
| 2488 | if ((flags & TAG_OBJECT) != 0) { |
| 2489 | addq(result, Immediate(kHeapObjectTag)); |
| 2490 | } |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 2491 | } |
| 2492 | |
| 2493 | |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 2494 | void MacroAssembler::AllocateInNewSpace(Register object_size, |
| 2495 | Register result, |
| 2496 | Register result_end, |
| 2497 | Register scratch, |
| 2498 | Label* gc_required, |
| 2499 | AllocationFlags flags) { |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 2500 | // Load address of new object into result. |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 2501 | LoadAllocationTopHelper(result, result_end, scratch, flags); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 2502 | |
| 2503 | // Calculate new top and bail out if new space is exhausted. |
| 2504 | ExternalReference new_space_allocation_limit = |
| 2505 | ExternalReference::new_space_allocation_limit_address(); |
| 2506 | if (!object_size.is(result_end)) { |
| 2507 | movq(result_end, object_size); |
| 2508 | } |
| 2509 | addq(result_end, result); |
| 2510 | movq(kScratchRegister, new_space_allocation_limit); |
| 2511 | cmpq(result_end, Operand(kScratchRegister, 0)); |
| 2512 | j(above, gc_required); |
| 2513 | |
| 2514 | // Update allocation top. |
| 2515 | UpdateAllocationTopHelper(result_end, scratch); |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 2516 | |
| 2517 | // Tag the result if requested. |
| 2518 | if ((flags & TAG_OBJECT) != 0) { |
| 2519 | addq(result, Immediate(kHeapObjectTag)); |
| 2520 | } |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 2521 | } |
| 2522 | |
| 2523 | |
| 2524 | void MacroAssembler::UndoAllocationInNewSpace(Register object) { |
| 2525 | ExternalReference new_space_allocation_top = |
| 2526 | ExternalReference::new_space_allocation_top_address(); |
| 2527 | |
| 2528 | // Make sure the object has no tag before resetting top. |
| 2529 | and_(object, Immediate(~kHeapObjectTagMask)); |
| 2530 | movq(kScratchRegister, new_space_allocation_top); |
| 2531 | #ifdef DEBUG |
| 2532 | cmpq(object, Operand(kScratchRegister, 0)); |
| 2533 | Check(below, "Undo allocation of non allocated memory"); |
| 2534 | #endif |
| 2535 | movq(Operand(kScratchRegister, 0), object); |
| 2536 | } |
| 2537 | |
| 2538 | |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 2539 | void MacroAssembler::AllocateHeapNumber(Register result, |
| 2540 | Register scratch, |
| 2541 | Label* gc_required) { |
| 2542 | // Allocate heap number in new space. |
| 2543 | AllocateInNewSpace(HeapNumber::kSize, |
| 2544 | result, |
| 2545 | scratch, |
| 2546 | no_reg, |
| 2547 | gc_required, |
| 2548 | TAG_OBJECT); |
| 2549 | |
| 2550 | // Set the map. |
| 2551 | LoadRoot(kScratchRegister, Heap::kHeapNumberMapRootIndex); |
| 2552 | movq(FieldOperand(result, HeapObject::kMapOffset), kScratchRegister); |
| 2553 | } |
| 2554 | |
| 2555 | |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 2556 | void MacroAssembler::AllocateTwoByteString(Register result, |
| 2557 | Register length, |
| 2558 | Register scratch1, |
| 2559 | Register scratch2, |
| 2560 | Register scratch3, |
| 2561 | Label* gc_required) { |
| 2562 | // Calculate the number of bytes needed for the characters in the string while |
| 2563 | // observing object alignment. |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 2564 | const int kHeaderAlignment = SeqTwoByteString::kHeaderSize & |
| 2565 | kObjectAlignmentMask; |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 2566 | ASSERT(kShortSize == 2); |
| 2567 | // scratch1 = length * 2 + kObjectAlignmentMask. |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 2568 | lea(scratch1, Operand(length, length, times_1, kObjectAlignmentMask + |
| 2569 | kHeaderAlignment)); |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 2570 | and_(scratch1, Immediate(~kObjectAlignmentMask)); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 2571 | if (kHeaderAlignment > 0) { |
| 2572 | subq(scratch1, Immediate(kHeaderAlignment)); |
| 2573 | } |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 2574 | |
| 2575 | // Allocate two byte string in new space. |
| 2576 | AllocateInNewSpace(SeqTwoByteString::kHeaderSize, |
| 2577 | times_1, |
| 2578 | scratch1, |
| 2579 | result, |
| 2580 | scratch2, |
| 2581 | scratch3, |
| 2582 | gc_required, |
| 2583 | TAG_OBJECT); |
| 2584 | |
| 2585 | // Set the map, length and hash field. |
| 2586 | LoadRoot(kScratchRegister, Heap::kStringMapRootIndex); |
| 2587 | movq(FieldOperand(result, HeapObject::kMapOffset), kScratchRegister); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 2588 | Integer32ToSmi(scratch1, length); |
| 2589 | movq(FieldOperand(result, String::kLengthOffset), scratch1); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2590 | movq(FieldOperand(result, String::kHashFieldOffset), |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 2591 | Immediate(String::kEmptyHashField)); |
| 2592 | } |
| 2593 | |
| 2594 | |
| 2595 | void MacroAssembler::AllocateAsciiString(Register result, |
| 2596 | Register length, |
| 2597 | Register scratch1, |
| 2598 | Register scratch2, |
| 2599 | Register scratch3, |
| 2600 | Label* gc_required) { |
| 2601 | // Calculate the number of bytes needed for the characters in the string while |
| 2602 | // observing object alignment. |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 2603 | const int kHeaderAlignment = SeqAsciiString::kHeaderSize & |
| 2604 | kObjectAlignmentMask; |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 2605 | movl(scratch1, length); |
| 2606 | ASSERT(kCharSize == 1); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 2607 | addq(scratch1, Immediate(kObjectAlignmentMask + kHeaderAlignment)); |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 2608 | and_(scratch1, Immediate(~kObjectAlignmentMask)); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 2609 | if (kHeaderAlignment > 0) { |
| 2610 | subq(scratch1, Immediate(kHeaderAlignment)); |
| 2611 | } |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 2612 | |
| 2613 | // Allocate ascii string in new space. |
| 2614 | AllocateInNewSpace(SeqAsciiString::kHeaderSize, |
| 2615 | times_1, |
| 2616 | scratch1, |
| 2617 | result, |
| 2618 | scratch2, |
| 2619 | scratch3, |
| 2620 | gc_required, |
| 2621 | TAG_OBJECT); |
| 2622 | |
| 2623 | // Set the map, length and hash field. |
| 2624 | LoadRoot(kScratchRegister, Heap::kAsciiStringMapRootIndex); |
| 2625 | movq(FieldOperand(result, HeapObject::kMapOffset), kScratchRegister); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 2626 | Integer32ToSmi(scratch1, length); |
| 2627 | movq(FieldOperand(result, String::kLengthOffset), scratch1); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2628 | movq(FieldOperand(result, String::kHashFieldOffset), |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 2629 | Immediate(String::kEmptyHashField)); |
| 2630 | } |
| 2631 | |
| 2632 | |
| 2633 | void MacroAssembler::AllocateConsString(Register result, |
| 2634 | Register scratch1, |
| 2635 | Register scratch2, |
| 2636 | Label* gc_required) { |
| 2637 | // Allocate heap number in new space. |
| 2638 | AllocateInNewSpace(ConsString::kSize, |
| 2639 | result, |
| 2640 | scratch1, |
| 2641 | scratch2, |
| 2642 | gc_required, |
| 2643 | TAG_OBJECT); |
| 2644 | |
| 2645 | // Set the map. The other fields are left uninitialized. |
| 2646 | LoadRoot(kScratchRegister, Heap::kConsStringMapRootIndex); |
| 2647 | movq(FieldOperand(result, HeapObject::kMapOffset), kScratchRegister); |
| 2648 | } |
| 2649 | |
| 2650 | |
| 2651 | void MacroAssembler::AllocateAsciiConsString(Register result, |
| 2652 | Register scratch1, |
| 2653 | Register scratch2, |
| 2654 | Label* gc_required) { |
| 2655 | // Allocate heap number in new space. |
| 2656 | AllocateInNewSpace(ConsString::kSize, |
| 2657 | result, |
| 2658 | scratch1, |
| 2659 | scratch2, |
| 2660 | gc_required, |
| 2661 | TAG_OBJECT); |
| 2662 | |
| 2663 | // Set the map. The other fields are left uninitialized. |
| 2664 | LoadRoot(kScratchRegister, Heap::kConsAsciiStringMapRootIndex); |
| 2665 | movq(FieldOperand(result, HeapObject::kMapOffset), kScratchRegister); |
| 2666 | } |
| 2667 | |
| 2668 | |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 2669 | void MacroAssembler::LoadContext(Register dst, int context_chain_length) { |
| 2670 | if (context_chain_length > 0) { |
| 2671 | // Move up the chain of contexts to the context containing the slot. |
| 2672 | movq(dst, Operand(rsi, Context::SlotOffset(Context::CLOSURE_INDEX))); |
| 2673 | // Load the function context (which is the incoming, outer context). |
lrn@chromium.org | d5649e3 | 2010-01-19 13:36:12 +0000 | [diff] [blame] | 2674 | movq(dst, FieldOperand(dst, JSFunction::kContextOffset)); |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 2675 | for (int i = 1; i < context_chain_length; i++) { |
| 2676 | movq(dst, Operand(dst, Context::SlotOffset(Context::CLOSURE_INDEX))); |
| 2677 | movq(dst, FieldOperand(dst, JSFunction::kContextOffset)); |
| 2678 | } |
| 2679 | // The context may be an intermediate context, not a function context. |
| 2680 | movq(dst, Operand(dst, Context::SlotOffset(Context::FCONTEXT_INDEX))); |
| 2681 | } else { // context is the current function context. |
| 2682 | // The context may be an intermediate context, not a function context. |
| 2683 | movq(dst, Operand(rsi, Context::SlotOffset(Context::FCONTEXT_INDEX))); |
| 2684 | } |
| 2685 | } |
| 2686 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2687 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2688 | int MacroAssembler::ArgumentStackSlotsForCFunctionCall(int num_arguments) { |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2689 | // On Windows 64 stack slots are reserved by the caller for all arguments |
| 2690 | // including the ones passed in registers, and space is always allocated for |
| 2691 | // the four register arguments even if the function takes fewer than four |
| 2692 | // arguments. |
| 2693 | // On AMD64 ABI (Linux/Mac) the first six arguments are passed in registers |
| 2694 | // and the caller does not reserve stack slots for them. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2695 | ASSERT(num_arguments >= 0); |
| 2696 | #ifdef _WIN64 |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2697 | static const int kMinimumStackSlots = 4; |
| 2698 | if (num_arguments < kMinimumStackSlots) return kMinimumStackSlots; |
| 2699 | return num_arguments; |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2700 | #else |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2701 | static const int kRegisterPassedArguments = 6; |
| 2702 | if (num_arguments < kRegisterPassedArguments) return 0; |
| 2703 | return num_arguments - kRegisterPassedArguments; |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2704 | #endif |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2705 | } |
| 2706 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2707 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2708 | void MacroAssembler::PrepareCallCFunction(int num_arguments) { |
| 2709 | int frame_alignment = OS::ActivationFrameAlignment(); |
| 2710 | ASSERT(frame_alignment != 0); |
| 2711 | ASSERT(num_arguments >= 0); |
| 2712 | // Make stack end at alignment and allocate space for arguments and old rsp. |
| 2713 | movq(kScratchRegister, rsp); |
| 2714 | ASSERT(IsPowerOf2(frame_alignment)); |
| 2715 | int argument_slots_on_stack = |
| 2716 | ArgumentStackSlotsForCFunctionCall(num_arguments); |
| 2717 | subq(rsp, Immediate((argument_slots_on_stack + 1) * kPointerSize)); |
| 2718 | and_(rsp, Immediate(-frame_alignment)); |
| 2719 | movq(Operand(rsp, argument_slots_on_stack * kPointerSize), kScratchRegister); |
| 2720 | } |
| 2721 | |
| 2722 | |
| 2723 | void MacroAssembler::CallCFunction(ExternalReference function, |
| 2724 | int num_arguments) { |
| 2725 | movq(rax, function); |
| 2726 | CallCFunction(rax, num_arguments); |
| 2727 | } |
| 2728 | |
| 2729 | |
| 2730 | void MacroAssembler::CallCFunction(Register function, int num_arguments) { |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 2731 | // Check stack alignment. |
| 2732 | if (FLAG_debug_code) { |
| 2733 | CheckStackAlignment(); |
| 2734 | } |
| 2735 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2736 | call(function); |
| 2737 | ASSERT(OS::ActivationFrameAlignment() != 0); |
| 2738 | ASSERT(num_arguments >= 0); |
| 2739 | int argument_slots_on_stack = |
| 2740 | ArgumentStackSlotsForCFunctionCall(num_arguments); |
| 2741 | movq(rsp, Operand(rsp, argument_slots_on_stack * kPointerSize)); |
| 2742 | } |
| 2743 | |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 2744 | |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 2745 | CodePatcher::CodePatcher(byte* address, int size) |
| 2746 | : address_(address), size_(size), masm_(address, size + Assembler::kGap) { |
| 2747 | // Create a new macro assembler pointing to the address of the code to patch. |
| 2748 | // The size is adjusted with kGap on order for the assembler to generate size |
| 2749 | // bytes of instructions without failing with buffer size constraints. |
| 2750 | ASSERT(masm_.reloc_info_writer.pos() == address_ + size_ + Assembler::kGap); |
| 2751 | } |
| 2752 | |
| 2753 | |
| 2754 | CodePatcher::~CodePatcher() { |
| 2755 | // Indicate that code has changed. |
| 2756 | CPU::FlushICache(address_, size_); |
| 2757 | |
| 2758 | // Check that the code was patched as expected. |
| 2759 | ASSERT(masm_.pc_ == address_ + size_); |
| 2760 | ASSERT(masm_.reloc_info_writer.pos() == address_ + size_ + Assembler::kGap); |
| 2761 | } |
| 2762 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 2763 | } } // namespace v8::internal |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2764 | |
| 2765 | #endif // V8_TARGET_ARCH_X64 |