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.
34 #include "disassembler.h"
35 #include "macro-assembler.h"
36 #include "serialize.h"
37 #include "stub-cache.h"
40 using namespace v8::internal;
46 static void DummyStaticFunction(Object* result) {
51 CcTest::InitializeVM();
52 Isolate* isolate = CcTest::i_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(ebx, -4));
78 __ add(edx, Operand(ebx, -1999));
79 __ add(edx, Operand(esp, 0));
80 __ add(edx, Operand(esp, 16));
81 __ add(edx, Operand(esp, 1999));
82 __ add(edx, Operand(esp, -4));
83 __ add(edx, Operand(esp, -1999));
85 __ add(esi, Operand(ecx, times_4, 0));
86 __ add(esi, Operand(ecx, times_4, 24));
87 __ add(esi, Operand(ecx, times_4, -4));
88 __ add(esi, Operand(ecx, times_4, -1999));
90 __ add(edi, Operand(ebp, ecx, times_4, 0));
91 __ add(edi, Operand(ebp, ecx, times_4, 12));
92 __ add(edi, Operand(ebp, ecx, times_4, -8));
93 __ add(edi, Operand(ebp, ecx, times_4, -3999));
94 __ add(Operand(ebp, ecx, times_4, 12), Immediate(12));
97 __ add(ebx, Immediate(12));
103 __ and_(edx, Operand(esp, 4));
105 __ cmp(edx, Operand(esp, 4));
106 __ cmp(Operand(ebp, ecx, times_4, 0), Immediate(1000));
107 Handle<FixedArray> foo2 = isolate->factory()->NewFixedArray(10, TENURED);
109 __ cmpb(ebx, Operand(ebp, ecx, times_2, 0));
110 __ cmpb(Operand(ebp, ecx, times_2, 0), ebx);
115 __ movsx_b(edx, ecx);
116 __ movsx_w(edx, ecx);
117 __ movzx_b(edx, ecx);
118 __ movzx_w(edx, ecx);
125 __ bts(Operand(ebx, ecx, times_4, 0), ecx);
131 __ push(Immediate(12));
132 __ push(Immediate(23456));
135 __ push(Operand(ebp, JavaScriptFrameConstants::kFunctionOffset));
136 __ push(Operand(ebx, ecx, times_4, 0));
137 __ push(Operand(ebx, ecx, times_4, 0));
138 __ push(Operand(ebx, ecx, times_4, 10000));
141 __ pop(Operand(ebx, ecx, times_4, 0));
144 __ add(edx, Operand(esp, 16));
148 __ mov_b(Operand(ebx, ecx, times_4, 10000), 6);
149 __ mov_b(Operand(esp, 16), edx);
150 __ mov_w(edx, Operand(esp, 16));
151 __ mov_w(Operand(esp, 16), edx);
153 __ movsx_w(edx, Operand(esp, 12));
154 __ movsx_b(edx, Operand(esp, 12));
155 __ movzx_w(edx, Operand(esp, 12));
156 __ movzx_b(edx, Operand(esp, 12));
158 __ mov(edx, 1234567);
159 __ mov(edx, Operand(esp, 12));
160 __ mov(Operand(ebx, ecx, times_4, 10000), Immediate(12345));
161 __ mov(Operand(ebx, ecx, times_4, 10000), edx);
164 __ dec_b(Operand(eax, 10));
165 __ dec_b(Operand(ebx, ecx, times_4, 10000));
174 __ test(Operand(ebx, ecx, times_4, 10000), Immediate(123456));
176 __ imul(edx, Operand(ebx, ecx, times_4, 10000));
177 __ imul(edx, ecx, 12);
178 __ imul(edx, ecx, 1000);
181 __ inc(Operand(ebx, ecx, times_4, 10000));
182 __ push(Operand(ebx, ecx, times_4, 10000));
183 __ pop(Operand(ebx, ecx, times_4, 10000));
184 __ call(Operand(ebx, ecx, times_4, 10000));
185 __ jmp(Operand(ebx, ecx, times_4, 10000));
187 __ lea(edx, Operand(ebx, ecx, times_4, 10000));
189 __ or_(edx, Operand(ebx, ecx, times_4, 10000));
200 __ sbb(edx, Operand(ebx, ecx, times_4, 10000));
201 __ shld(edx, Operand(ebx, ecx, times_4, 10000));
205 __ shrd(edx, Operand(ebx, ecx, times_4, 10000));
215 __ add(ebx, Immediate(12));
216 __ add(Operand(edx, ecx, times_4, 10000), Immediate(12));
221 __ cmp(ebx, Immediate(12));
222 __ cmp(Operand(edx, ecx, times_4, 10000), Immediate(12));
227 __ sub(ebx, Immediate(12));
228 __ sub(Operand(edx, ecx, times_4, 10000), Immediate(12));
232 __ imul(edx, ecx, 12);
233 __ imul(edx, ecx, 1000);
240 __ sub(edx, Operand(ebx, ecx, times_4, 10000));
243 __ test(edx, Immediate(12345));
244 __ test(edx, Operand(ebx, ecx, times_8, 10000));
245 __ test(Operand(esi, edi, times_1, -20000000), Immediate(300000000));
246 __ test_b(edx, Operand(ecx, ebx, times_2, 1000));
247 __ test_b(Operand(eax, -20), 0x9A);
251 __ xor_(edx, Operand(ebx, ecx, times_8, 10000));
252 __ bts(Operand(ebx, ecx, times_8, 10000), edx);
267 __ call(Operand(ebx, ecx, times_4, 10000));
269 Handle<Code> ic(LoadIC::initialize_stub(isolate, NOT_CONTEXTUAL));
270 __ call(ic, RelocInfo::CODE_TARGET);
272 __ call(FUNCTION_ADDR(DummyStaticFunction), RelocInfo::RUNTIME_ENTRY);
276 __ jmp(Operand(ebx, ecx, times_4, 10000));
277 #ifdef ENABLE_DEBUGGER_SUPPORT
278 ExternalReference after_break_target =
279 ExternalReference(Debug_Address::AfterBreakTarget(), isolate);
280 __ jmp(Operand::StaticVariable(after_break_target));
281 #endif // ENABLE_DEBUGGER_SUPPORT
282 __ jmp(ic, RelocInfo::CODE_TARGET);
289 __ j(overflow, &Ljcc);
290 __ j(no_overflow, &Ljcc);
292 __ j(above_equal, &Ljcc);
294 __ j(not_equal, &Ljcc);
295 __ j(below_equal, &Ljcc);
298 __ j(not_sign, &Ljcc);
299 __ j(parity_even, &Ljcc);
300 __ j(parity_odd, &Ljcc);
302 __ j(greater_equal, &Ljcc);
303 __ j(less_equal, &Ljcc);
304 __ j(greater, &Ljcc);
308 __ j(overflow, &Ljcc);
309 __ j(no_overflow, &Ljcc);
311 __ j(above_equal, &Ljcc);
313 __ j(not_equal, &Ljcc);
314 __ j(below_equal, &Ljcc);
317 __ j(not_sign, &Ljcc);
318 __ j(parity_even, &Ljcc);
319 __ j(parity_odd, &Ljcc);
321 __ j(greater_equal, &Ljcc);
322 __ j(less_equal, &Ljcc);
323 __ j(greater, &Ljcc);
339 __ fld_s(Operand(ebx, ecx, times_4, 10000));
340 __ fstp_s(Operand(ebx, ecx, times_4, 10000));
342 __ fld_d(Operand(ebx, ecx, times_4, 10000));
343 __ fstp_d(Operand(ebx, ecx, times_4, 10000));
346 __ fild_s(Operand(ebx, ecx, times_4, 10000));
347 __ fistp_s(Operand(ebx, ecx, times_4, 10000));
348 __ fild_d(Operand(ebx, ecx, times_4, 10000));
349 __ fistp_d(Operand(ebx, ecx, times_4, 10000));
369 if (CpuFeatures::IsSupported(SSE2)) {
370 CpuFeatureScope fscope(&assm, SSE2);
372 __ movaps(xmm0, xmm1);
373 __ shufps(xmm0, xmm0, 0x0);
376 __ andps(xmm0, xmm1);
377 __ andps(xmm0, Operand(ebx, ecx, times_4, 10000));
379 __ orps(xmm0, Operand(ebx, ecx, times_4, 10000));
380 __ xorps(xmm0, xmm1);
381 __ xorps(xmm0, Operand(ebx, ecx, times_4, 10000));
383 // Arithmetic operation
384 __ addps(xmm1, xmm0);
385 __ addps(xmm1, Operand(ebx, ecx, times_4, 10000));
386 __ subps(xmm1, xmm0);
387 __ subps(xmm1, Operand(ebx, ecx, times_4, 10000));
388 __ mulps(xmm1, xmm0);
389 __ mulps(xmm1, Operand(ebx, ecx, times_4, 10000));
390 __ divps(xmm1, xmm0);
391 __ divps(xmm1, Operand(ebx, ecx, times_4, 10000));
395 if (CpuFeatures::IsSupported(SSE2)) {
396 CpuFeatureScope fscope(&assm, SSE2);
397 __ cvttss2si(edx, Operand(ebx, ecx, times_4, 10000));
398 __ cvtsi2sd(xmm1, Operand(ebx, ecx, times_4, 10000));
399 __ movsd(xmm1, Operand(ebx, ecx, times_4, 10000));
400 __ movsd(Operand(ebx, ecx, times_4, 10000), xmm1);
401 // 128 bit move instructions.
402 __ movdqa(xmm0, Operand(ebx, ecx, times_4, 10000));
403 __ movdqa(Operand(ebx, ecx, times_4, 10000), xmm0);
404 __ movdqu(xmm0, Operand(ebx, ecx, times_4, 10000));
405 __ movdqu(Operand(ebx, ecx, times_4, 10000), xmm0);
407 __ addsd(xmm1, xmm0);
408 __ mulsd(xmm1, xmm0);
409 __ subsd(xmm1, xmm0);
410 __ divsd(xmm1, xmm0);
411 __ ucomisd(xmm0, xmm1);
412 __ cmpltsd(xmm0, xmm1);
414 __ andpd(xmm0, xmm1);
416 __ psllq(xmm0, xmm1);
418 __ psrlq(xmm0, xmm1);
421 // new instruction introduced by SIMD
422 __ cvtdq2ps(xmm1, Operand(ebx, ecx, times_4, 10000));
423 __ cvtdq2ps(xmm1, xmm0);
424 __ cvtps2dq(xmm1, Operand(ebx, ecx, times_4, 10000));
425 __ cvtps2dq(xmm1, xmm0);
426 __ paddd(xmm1, Operand(ebx, ecx, times_4, 10000));
427 __ paddd(xmm1, xmm0);
428 __ psubd(xmm1, Operand(ebx, ecx, times_4, 10000));
429 __ psubd(xmm1, xmm0);
430 __ pmuludq(xmm1, Operand(ebx, ecx, times_4, 10000));
431 __ pmuludq(xmm1, xmm0);
432 __ punpackldq(xmm1, Operand(ebx, ecx, times_4, 10000));
433 __ punpackldq(xmm1, xmm0);
435 __ shufps(xmm1, xmm1, 0x0);
436 __ movups(xmm1, Operand(ebx, ecx, times_4, 10000));
437 __ movups(Operand(ebx, ecx, times_4, 10000), xmm1);
439 __ andps(xmm1, Operand(ebx, ecx, times_4, 10000));
440 __ andps(xmm1, xmm0);
441 __ xorps(xmm1, Operand(ebx, ecx, times_4, 10000));
442 __ xorps(xmm1, xmm0);
443 __ orps(xmm1, Operand(ebx, ecx, times_4, 10000));
446 __ addps(xmm1, Operand(ebx, ecx, times_4, 10000));
447 __ addps(xmm1, xmm0);
448 __ subps(xmm1, Operand(ebx, ecx, times_4, 10000));
449 __ subps(xmm1, xmm0);
450 __ mulps(xmm1, Operand(ebx, ecx, times_4, 10000));
451 __ mulps(xmm1, xmm0);
452 __ divps(xmm1, Operand(ebx, ecx, times_4, 10000));
453 __ divps(xmm1, xmm0);
454 __ minps(xmm1, Operand(ebx, ecx, times_4, 10000));
455 __ minps(xmm1, xmm0);
456 __ maxps(xmm1, Operand(ebx, ecx, times_4, 10000));
457 __ maxps(xmm1, xmm0);
458 __ rcpps(xmm1, Operand(ebx, ecx, times_4, 10000));
459 __ rcpps(xmm1, xmm0);
460 __ rsqrtps(xmm1, Operand(ebx, ecx, times_4, 10000));
461 __ rsqrtps(xmm1, xmm0);
462 __ sqrtps(xmm1, Operand(ebx, ecx, times_4, 10000));
463 __ sqrtps(xmm1, xmm0);
465 __ cmpeqps(xmm1, xmm0);
466 __ cmpltps(xmm1, xmm0);
467 __ cmpleps(xmm1, xmm0);
468 __ cmpneqps(xmm1, xmm0);
469 __ cmpnltps(xmm1, xmm0);
470 __ cmpnleps(xmm1, xmm0);
477 if (CpuFeatures::IsSupported(CMOV)) {
478 CpuFeatureScope use_cmov(&assm, CMOV);
479 __ cmov(overflow, eax, Operand(eax, 0));
480 __ cmov(no_overflow, eax, Operand(eax, 1));
481 __ cmov(below, eax, Operand(eax, 2));
482 __ cmov(above_equal, eax, Operand(eax, 3));
483 __ cmov(equal, eax, Operand(ebx, 0));
484 __ cmov(not_equal, eax, Operand(ebx, 1));
485 __ cmov(below_equal, eax, Operand(ebx, 2));
486 __ cmov(above, eax, Operand(ebx, 3));
487 __ cmov(sign, eax, Operand(ecx, 0));
488 __ cmov(not_sign, eax, Operand(ecx, 1));
489 __ cmov(parity_even, eax, Operand(ecx, 2));
490 __ cmov(parity_odd, eax, Operand(ecx, 3));
491 __ cmov(less, eax, Operand(edx, 0));
492 __ cmov(greater_equal, eax, Operand(edx, 1));
493 __ cmov(less_equal, eax, Operand(edx, 2));
494 __ cmov(greater, eax, Operand(edx, 3));
499 if (CpuFeatures::IsSupported(SSE2) &&
500 CpuFeatures::IsSupported(SSE4_1)) {
501 CpuFeatureScope scope(&assm, SSE4_1);
502 __ pextrd(eax, xmm0, 1);
503 __ pinsrd(xmm1, eax, 0);
504 __ extractps(eax, xmm1, 0);
505 __ insertps(xmm1, xmm0, 0);
506 __ pmulld(xmm1, Operand(ebx, ecx, times_4, 10000));
507 __ pmulld(xmm1, xmm0);
512 for (int i = 0; i < 16; i++) {
520 Object* code = isolate->heap()->CreateCode(
522 Code::ComputeFlags(Code::STUB),
523 Handle<Code>())->ToObjectChecked();
524 CHECK(code->IsCode());
526 Code::cast(code)->Print();
527 byte* begin = Code::cast(code)->instruction_start();
528 byte* end = begin + Code::cast(code)->instruction_size();
529 disasm::Disassembler::Disassemble(stdout, begin, end);