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));
358 if (CpuFeatures::IsSupported(SSE2)) {
359 CpuFeatureScope fscope(&assm, SSE2);
361 __ movaps(xmm0, xmm1);
362 __ shufps(xmm0, xmm0, 0x0);
365 __ andps(xmm0, xmm1);
366 __ andps(xmm0, Operand(ebx, ecx, times_4, 10000));
368 __ orps(xmm0, Operand(ebx, ecx, times_4, 10000));
369 __ xorps(xmm0, xmm1);
370 __ xorps(xmm0, Operand(ebx, ecx, times_4, 10000));
372 // Arithmetic operation
373 __ addps(xmm1, xmm0);
374 __ addps(xmm1, Operand(ebx, ecx, times_4, 10000));
375 __ subps(xmm1, xmm0);
376 __ subps(xmm1, Operand(ebx, ecx, times_4, 10000));
377 __ mulps(xmm1, xmm0);
378 __ mulps(xmm1, Operand(ebx, ecx, times_4, 10000));
379 __ divps(xmm1, xmm0);
380 __ divps(xmm1, Operand(ebx, ecx, times_4, 10000));
384 if (CpuFeatures::IsSupported(SSE2)) {
385 CpuFeatureScope fscope(&assm, SSE2);
386 __ cvttss2si(edx, Operand(ebx, ecx, times_4, 10000));
387 __ cvtsi2sd(xmm1, Operand(ebx, ecx, times_4, 10000));
388 __ movsd(xmm1, Operand(ebx, ecx, times_4, 10000));
389 __ movsd(Operand(ebx, ecx, times_4, 10000), xmm1);
390 // 128 bit move instructions.
391 __ movdqa(xmm0, Operand(ebx, ecx, times_4, 10000));
392 __ movdqa(Operand(ebx, ecx, times_4, 10000), xmm0);
393 __ movdqu(xmm0, Operand(ebx, ecx, times_4, 10000));
394 __ movdqu(Operand(ebx, ecx, times_4, 10000), xmm0);
396 __ addsd(xmm1, xmm0);
397 __ mulsd(xmm1, xmm0);
398 __ subsd(xmm1, xmm0);
399 __ divsd(xmm1, xmm0);
400 __ ucomisd(xmm0, xmm1);
401 __ cmpltsd(xmm0, xmm1);
403 __ andpd(xmm0, xmm1);
405 __ psllq(xmm0, xmm1);
407 __ psrlq(xmm0, xmm1);
410 // new instruction introduced by SIMD
411 __ cvtdq2ps(xmm1, Operand(ebx, ecx, times_4, 10000));
412 __ cvtdq2ps(xmm1, xmm0);
413 __ cvtps2dq(xmm1, Operand(ebx, ecx, times_4, 10000));
414 __ cvtps2dq(xmm1, xmm0);
415 __ paddd(xmm1, Operand(ebx, ecx, times_4, 10000));
416 __ paddd(xmm1, xmm0);
417 __ psubd(xmm1, Operand(ebx, ecx, times_4, 10000));
418 __ psubd(xmm1, xmm0);
419 __ pmuludq(xmm1, Operand(ebx, ecx, times_4, 10000));
420 __ pmuludq(xmm1, xmm0);
421 __ punpackldq(xmm1, Operand(ebx, ecx, times_4, 10000));
422 __ punpackldq(xmm1, xmm0);
424 __ shufps(xmm1, xmm1, 0x0);
425 __ movups(xmm1, Operand(ebx, ecx, times_4, 10000));
426 __ movups(Operand(ebx, ecx, times_4, 10000), xmm1);
428 __ andps(xmm1, Operand(ebx, ecx, times_4, 10000));
429 __ andps(xmm1, xmm0);
430 __ xorps(xmm1, Operand(ebx, ecx, times_4, 10000));
431 __ xorps(xmm1, xmm0);
432 __ orps(xmm1, Operand(ebx, ecx, times_4, 10000));
435 __ addps(xmm1, Operand(ebx, ecx, times_4, 10000));
436 __ addps(xmm1, xmm0);
437 __ subps(xmm1, Operand(ebx, ecx, times_4, 10000));
438 __ subps(xmm1, xmm0);
439 __ mulps(xmm1, Operand(ebx, ecx, times_4, 10000));
440 __ mulps(xmm1, xmm0);
441 __ divps(xmm1, Operand(ebx, ecx, times_4, 10000));
442 __ divps(xmm1, xmm0);
443 __ minps(xmm1, Operand(ebx, ecx, times_4, 10000));
444 __ minps(xmm1, xmm0);
445 __ maxps(xmm1, Operand(ebx, ecx, times_4, 10000));
446 __ maxps(xmm1, xmm0);
447 __ rcpps(xmm1, Operand(ebx, ecx, times_4, 10000));
448 __ rcpps(xmm1, xmm0);
449 __ rsqrtps(xmm1, Operand(ebx, ecx, times_4, 10000));
450 __ rsqrtps(xmm1, xmm0);
451 __ sqrtps(xmm1, Operand(ebx, ecx, times_4, 10000));
452 __ sqrtps(xmm1, xmm0);
454 __ cmpeqps(xmm1, xmm0);
455 __ cmpltps(xmm1, xmm0);
456 __ cmpleps(xmm1, xmm0);
457 __ cmpneqps(xmm1, xmm0);
458 __ cmpnltps(xmm1, xmm0);
459 __ cmpnleps(xmm1, xmm0);
466 if (CpuFeatures::IsSupported(CMOV)) {
467 CpuFeatureScope use_cmov(&assm, CMOV);
468 __ cmov(overflow, eax, Operand(eax, 0));
469 __ cmov(no_overflow, eax, Operand(eax, 1));
470 __ cmov(below, eax, Operand(eax, 2));
471 __ cmov(above_equal, eax, Operand(eax, 3));
472 __ cmov(equal, eax, Operand(ebx, 0));
473 __ cmov(not_equal, eax, Operand(ebx, 1));
474 __ cmov(below_equal, eax, Operand(ebx, 2));
475 __ cmov(above, eax, Operand(ebx, 3));
476 __ cmov(sign, eax, Operand(ecx, 0));
477 __ cmov(not_sign, eax, Operand(ecx, 1));
478 __ cmov(parity_even, eax, Operand(ecx, 2));
479 __ cmov(parity_odd, eax, Operand(ecx, 3));
480 __ cmov(less, eax, Operand(edx, 0));
481 __ cmov(greater_equal, eax, Operand(edx, 1));
482 __ cmov(less_equal, eax, Operand(edx, 2));
483 __ cmov(greater, eax, Operand(edx, 3));
488 if (CpuFeatures::IsSupported(SSE2) &&
489 CpuFeatures::IsSupported(SSE4_1)) {
490 CpuFeatureScope scope(&assm, SSE4_1);
491 __ pextrd(eax, xmm0, 1);
492 __ pinsrd(xmm1, eax, 0);
493 __ extractps(eax, xmm1, 0);
494 __ insertps(xmm1, xmm0, 0);
495 __ pmulld(xmm1, Operand(ebx, ecx, times_4, 10000));
496 __ pmulld(xmm1, xmm0);
501 for (int i = 0; i < 16; i++) {
509 Object* code = isolate->heap()->CreateCode(
511 Code::ComputeFlags(Code::STUB),
512 Handle<Code>())->ToObjectChecked();
513 CHECK(code->IsCode());
515 Code::cast(code)->Print();
516 byte* begin = Code::cast(code)->instruction_start();
517 byte* end = begin + Code::cast(code)->instruction_size();
518 disasm::Disassembler::Disassemble(stdout, begin, end);