1 // Copyright 2011 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
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.
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.
31 #include "stub-cache.h"
35 #include "disassembler.h"
36 #include "macro-assembler.h"
37 #include "serialize.h"
40 using namespace v8::internal;
46 static void DummyStaticFunction(Object* result) {
51 CcTest::InitializeVM();
52 Isolate* isolate = reinterpret_cast<Isolate*>(CcTest::isolate());
53 HandleScope scope(isolate);
54 v8::internal::byte buffer[2048];
55 Assembler assm(isolate, buffer, sizeof buffer);
56 DummyStaticFunction(NULL); // just bloody use it (DELETE; debugging)
58 // Short immediate instructions
59 __ adc(eax, 12345678);
60 __ add(eax, Immediate(12345678));
61 __ or_(eax, 12345678);
62 __ sub(eax, Immediate(12345678));
63 __ xor_(eax, 12345678);
64 __ and_(eax, 12345678);
65 Handle<FixedArray> foo = isolate->factory()->NewFixedArray(10, TENURED);
68 // ---- This one caused crash
69 __ mov(ebx, Operand(esp, ecx, times_2, 0)); // [esp+ecx*4]
71 // ---- All instructions that I can think of
73 __ add(edx, Operand(12, RelocInfo::NONE32));
74 __ add(edx, Operand(ebx, 0));
75 __ add(edx, Operand(ebx, 16));
76 __ add(edx, Operand(ebx, 1999));
77 __ add(edx, Operand(esp, 0));
78 __ add(edx, Operand(esp, 16));
79 __ add(edx, Operand(esp, 1999));
81 __ add(edi, Operand(ebp, ecx, times_4, 0));
82 __ add(edi, Operand(ebp, ecx, times_4, 12));
83 __ add(Operand(ebp, ecx, times_4, 12), Immediate(12));
86 __ add(ebx, Immediate(12));
92 __ and_(edx, Operand(esp, 4));
94 __ cmp(edx, Operand(esp, 4));
95 __ cmp(Operand(ebp, ecx, times_4, 0), Immediate(1000));
96 Handle<FixedArray> foo2 = isolate->factory()->NewFixedArray(10, TENURED);
98 __ cmpb(ebx, Operand(ebp, ecx, times_2, 0));
99 __ cmpb(Operand(ebp, ecx, times_2, 0), ebx);
104 __ movsx_b(edx, ecx);
105 __ movsx_w(edx, ecx);
106 __ movzx_b(edx, ecx);
107 __ movzx_w(edx, ecx);
114 __ bts(Operand(ebx, ecx, times_4, 0), ecx);
120 __ push(Immediate(12));
121 __ push(Immediate(23456));
124 __ push(Operand(ebp, JavaScriptFrameConstants::kFunctionOffset));
125 __ push(Operand(ebx, ecx, times_4, 0));
126 __ push(Operand(ebx, ecx, times_4, 0));
127 __ push(Operand(ebx, ecx, times_4, 10000));
130 __ pop(Operand(ebx, ecx, times_4, 0));
133 __ add(edx, Operand(esp, 16));
137 __ mov_b(Operand(ebx, ecx, times_4, 10000), 6);
138 __ mov_b(Operand(esp, 16), edx);
139 __ mov_w(edx, Operand(esp, 16));
140 __ mov_w(Operand(esp, 16), edx);
142 __ movsx_w(edx, Operand(esp, 12));
143 __ movsx_b(edx, Operand(esp, 12));
144 __ movzx_w(edx, Operand(esp, 12));
145 __ movzx_b(edx, Operand(esp, 12));
147 __ mov(edx, 1234567);
148 __ mov(edx, Operand(esp, 12));
149 __ mov(Operand(ebx, ecx, times_4, 10000), Immediate(12345));
150 __ mov(Operand(ebx, ecx, times_4, 10000), edx);
153 __ dec_b(Operand(eax, 10));
154 __ dec_b(Operand(ebx, ecx, times_4, 10000));
163 __ test(Operand(ebx, ecx, times_4, 10000), Immediate(123456));
165 __ imul(edx, Operand(ebx, ecx, times_4, 10000));
166 __ imul(edx, ecx, 12);
167 __ imul(edx, ecx, 1000);
170 __ inc(Operand(ebx, ecx, times_4, 10000));
171 __ push(Operand(ebx, ecx, times_4, 10000));
172 __ pop(Operand(ebx, ecx, times_4, 10000));
173 __ call(Operand(ebx, ecx, times_4, 10000));
174 __ jmp(Operand(ebx, ecx, times_4, 10000));
176 __ lea(edx, Operand(ebx, ecx, times_4, 10000));
178 __ or_(edx, Operand(ebx, ecx, times_4, 10000));
189 __ sbb(edx, Operand(ebx, ecx, times_4, 10000));
190 __ shld(edx, Operand(ebx, ecx, times_4, 10000));
194 __ shrd(edx, Operand(ebx, ecx, times_4, 10000));
204 __ add(ebx, Immediate(12));
205 __ add(Operand(edx, ecx, times_4, 10000), Immediate(12));
210 __ cmp(ebx, Immediate(12));
211 __ cmp(Operand(edx, ecx, times_4, 10000), Immediate(12));
216 __ sub(ebx, Immediate(12));
217 __ sub(Operand(edx, ecx, times_4, 10000), Immediate(12));
221 __ imul(edx, ecx, 12);
222 __ imul(edx, ecx, 1000);
229 __ sub(edx, Operand(ebx, ecx, times_4, 10000));
232 __ test(edx, Immediate(12345));
233 __ test(edx, Operand(ebx, ecx, times_8, 10000));
234 __ test(Operand(esi, edi, times_1, -20000000), Immediate(300000000));
235 __ test_b(edx, Operand(ecx, ebx, times_2, 1000));
236 __ test_b(Operand(eax, -20), 0x9A);
240 __ xor_(edx, Operand(ebx, ecx, times_8, 10000));
241 __ bts(Operand(ebx, ecx, times_8, 10000), edx);
256 __ call(Operand(ebx, ecx, times_4, 10000));
258 Handle<Code> ic(LoadIC::initialize_stub(isolate, NOT_CONTEXTUAL));
259 __ call(ic, RelocInfo::CODE_TARGET);
261 __ call(FUNCTION_ADDR(DummyStaticFunction), RelocInfo::RUNTIME_ENTRY);
265 __ jmp(Operand(ebx, ecx, times_4, 10000));
266 #ifdef ENABLE_DEBUGGER_SUPPORT
267 ExternalReference after_break_target =
268 ExternalReference(Debug_Address::AfterBreakTarget(), isolate);
269 __ jmp(Operand::StaticVariable(after_break_target));
270 #endif // ENABLE_DEBUGGER_SUPPORT
271 __ jmp(ic, RelocInfo::CODE_TARGET);
278 __ j(overflow, &Ljcc);
279 __ j(no_overflow, &Ljcc);
281 __ j(above_equal, &Ljcc);
283 __ j(not_equal, &Ljcc);
284 __ j(below_equal, &Ljcc);
287 __ j(not_sign, &Ljcc);
288 __ j(parity_even, &Ljcc);
289 __ j(parity_odd, &Ljcc);
291 __ j(greater_equal, &Ljcc);
292 __ j(less_equal, &Ljcc);
293 __ j(greater, &Ljcc);
297 __ j(overflow, &Ljcc);
298 __ j(no_overflow, &Ljcc);
300 __ j(above_equal, &Ljcc);
302 __ j(not_equal, &Ljcc);
303 __ j(below_equal, &Ljcc);
306 __ j(not_sign, &Ljcc);
307 __ j(parity_even, &Ljcc);
308 __ j(parity_odd, &Ljcc);
310 __ j(greater_equal, &Ljcc);
311 __ j(less_equal, &Ljcc);
312 __ j(greater, &Ljcc);
328 __ fld_s(Operand(ebx, ecx, times_4, 10000));
329 __ fstp_s(Operand(ebx, ecx, times_4, 10000));
331 __ fld_d(Operand(ebx, ecx, times_4, 10000));
332 __ fstp_d(Operand(ebx, ecx, times_4, 10000));
335 __ fild_s(Operand(ebx, ecx, times_4, 10000));
336 __ fistp_s(Operand(ebx, ecx, times_4, 10000));
337 __ fild_d(Operand(ebx, ecx, times_4, 10000));
338 __ fistp_d(Operand(ebx, ecx, times_4, 10000));
356 if (CpuFeatures::IsSupported(SSE2)) {
357 CpuFeatureScope fscope(&assm, SSE2);
359 __ movaps(xmm0, xmm1);
360 __ shufps(xmm0, xmm0, 0x0);
363 __ andps(xmm0, xmm1);
364 __ andps(xmm0, Operand(ebx, ecx, times_4, 10000));
366 __ orps(xmm0, Operand(ebx, ecx, times_4, 10000));
367 __ xorps(xmm0, xmm1);
368 __ xorps(xmm0, Operand(ebx, ecx, times_4, 10000));
370 // Arithmetic operation
371 __ addps(xmm1, xmm0);
372 __ addps(xmm1, Operand(ebx, ecx, times_4, 10000));
373 __ subps(xmm1, xmm0);
374 __ subps(xmm1, Operand(ebx, ecx, times_4, 10000));
375 __ mulps(xmm1, xmm0);
376 __ mulps(xmm1, Operand(ebx, ecx, times_4, 10000));
377 __ divps(xmm1, xmm0);
378 __ divps(xmm1, Operand(ebx, ecx, times_4, 10000));
382 if (CpuFeatures::IsSupported(SSE2)) {
383 CpuFeatureScope fscope(&assm, SSE2);
384 __ cvttss2si(edx, Operand(ebx, ecx, times_4, 10000));
385 __ cvtsi2sd(xmm1, Operand(ebx, ecx, times_4, 10000));
386 __ movsd(xmm1, Operand(ebx, ecx, times_4, 10000));
387 __ movsd(Operand(ebx, ecx, times_4, 10000), xmm1);
388 // 128 bit move instructions.
389 __ movdqa(xmm0, Operand(ebx, ecx, times_4, 10000));
390 __ movdqa(Operand(ebx, ecx, times_4, 10000), xmm0);
391 __ movdqu(xmm0, Operand(ebx, ecx, times_4, 10000));
392 __ movdqu(Operand(ebx, ecx, times_4, 10000), xmm0);
394 __ addsd(xmm1, xmm0);
395 __ mulsd(xmm1, xmm0);
396 __ subsd(xmm1, xmm0);
397 __ divsd(xmm1, xmm0);
398 __ ucomisd(xmm0, xmm1);
399 __ cmpltsd(xmm0, xmm1);
401 __ andpd(xmm0, xmm1);
403 __ psllq(xmm0, xmm1);
405 __ psrlq(xmm0, xmm1);
412 if (CpuFeatures::IsSupported(CMOV)) {
413 CpuFeatureScope use_cmov(&assm, CMOV);
414 __ cmov(overflow, eax, Operand(eax, 0));
415 __ cmov(no_overflow, eax, Operand(eax, 1));
416 __ cmov(below, eax, Operand(eax, 2));
417 __ cmov(above_equal, eax, Operand(eax, 3));
418 __ cmov(equal, eax, Operand(ebx, 0));
419 __ cmov(not_equal, eax, Operand(ebx, 1));
420 __ cmov(below_equal, eax, Operand(ebx, 2));
421 __ cmov(above, eax, Operand(ebx, 3));
422 __ cmov(sign, eax, Operand(ecx, 0));
423 __ cmov(not_sign, eax, Operand(ecx, 1));
424 __ cmov(parity_even, eax, Operand(ecx, 2));
425 __ cmov(parity_odd, eax, Operand(ecx, 3));
426 __ cmov(less, eax, Operand(edx, 0));
427 __ cmov(greater_equal, eax, Operand(edx, 1));
428 __ cmov(less_equal, eax, Operand(edx, 2));
429 __ cmov(greater, eax, Operand(edx, 3));
434 if (CpuFeatures::IsSupported(SSE2) &&
435 CpuFeatures::IsSupported(SSE4_1)) {
436 CpuFeatureScope scope(&assm, SSE4_1);
437 __ pextrd(eax, xmm0, 1);
438 __ pinsrd(xmm1, eax, 0);
439 __ extractps(eax, xmm1, 0);
444 for (int i = 0; i < 16; i++) {
452 Object* code = isolate->heap()->CreateCode(
454 Code::ComputeFlags(Code::STUB),
455 Handle<Code>())->ToObjectChecked();
456 CHECK(code->IsCode());
458 Code::cast(code)->Print();
459 byte* begin = Code::cast(code)->instruction_start();
460 byte* end = begin + Code::cast(code)->instruction_size();
461 disasm::Disassembler::Disassemble(stdout, begin, end);