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
4// met:
5//
6//     * Redistributions of source code must retain the above copyright
7//       notice, this list of conditions and the following disclaimer.
8//     * Redistributions in binary form must reproduce the above
9//       copyright notice, this list of conditions and the following
10//       disclaimer in the documentation and/or other materials provided
11//       with the distribution.
12//     * Neither the name of Google Inc. nor the names of its
13//       contributors may be used to endorse or promote products derived
14//       from this software without specific prior written permission.
15//
16// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
28#include <stdlib.h>
29
30#include "src/v8.h"
31
32#include "src/code-factory.h"
33#include "src/debug/debug.h"
34#include "src/disasm.h"
35#include "src/disassembler.h"
36#include "src/macro-assembler.h"
37#include "test/cctest/cctest.h"
38
39using namespace v8::internal;
40
41
42#define __ assm.
43
44
45static void DummyStaticFunction(Object* result) {
46}
47
48
49TEST(DisasmX64) {
50  CcTest::InitializeVM();
51  Isolate* isolate = CcTest::i_isolate();
52  HandleScope scope(isolate);
53  v8::internal::byte buffer[4096];
54  Assembler assm(isolate, buffer, sizeof buffer);
55  DummyStaticFunction(NULL);  // just bloody use it (DELETE; debugging)
56
57  // Short immediate instructions
58  __ addq(rax, Immediate(12345678));
59  __ orq(rax, Immediate(12345678));
60  __ subq(rax, Immediate(12345678));
61  __ xorq(rax, Immediate(12345678));
62  __ andq(rax, Immediate(12345678));
63
64  // ---- This one caused crash
65  __ movq(rbx,  Operand(rsp, rcx, times_2, 0));  // [rsp+rcx*4]
66
67  // ---- All instructions that I can think of
68  __ addq(rdx, rbx);
69  __ addq(rdx, Operand(rbx, 0));
70  __ addq(rdx, Operand(rbx, 16));
71  __ addq(rdx, Operand(rbx, 1999));
72  __ addq(rdx, Operand(rbx, -4));
73  __ addq(rdx, Operand(rbx, -1999));
74  __ addq(rdx, Operand(rsp, 0));
75  __ addq(rdx, Operand(rsp, 16));
76  __ addq(rdx, Operand(rsp, 1999));
77  __ addq(rdx, Operand(rsp, -4));
78  __ addq(rdx, Operand(rsp, -1999));
79  __ nop();
80  __ addq(rsi, Operand(rcx, times_4, 0));
81  __ addq(rsi, Operand(rcx, times_4, 24));
82  __ addq(rsi, Operand(rcx, times_4, -4));
83  __ addq(rsi, Operand(rcx, times_4, -1999));
84  __ nop();
85  __ addq(rdi, Operand(rbp, rcx, times_4, 0));
86  __ addq(rdi, Operand(rbp, rcx, times_4, 12));
87  __ addq(rdi, Operand(rbp, rcx, times_4, -8));
88  __ addq(rdi, Operand(rbp, rcx, times_4, -3999));
89  __ addq(Operand(rbp, rcx, times_4, 12), Immediate(12));
90
91  __ bsrl(rax, r15);
92  __ bsrl(r9, Operand(rcx, times_8, 91919));
93
94  __ nop();
95  __ addq(rbx, Immediate(12));
96  __ nop();
97  __ nop();
98  __ andq(rdx, Immediate(3));
99  __ andq(rdx, Operand(rsp, 4));
100  __ cmpq(rdx, Immediate(3));
101  __ cmpq(rdx, Operand(rsp, 4));
102  __ cmpq(Operand(rbp, rcx, times_4, 0), Immediate(1000));
103  __ cmpb(rbx, Operand(rbp, rcx, times_2, 0));
104  __ cmpb(Operand(rbp, rcx, times_2, 0), rbx);
105  __ orq(rdx, Immediate(3));
106  __ xorq(rdx, Immediate(3));
107  __ nop();
108  __ cpuid();
109  __ movsxbl(rdx, Operand(rcx, 0));
110  __ movsxbq(rdx, Operand(rcx, 0));
111  __ movsxwl(rdx, Operand(rcx, 0));
112  __ movsxwq(rdx, Operand(rcx, 0));
113  __ movzxbl(rdx, Operand(rcx, 0));
114  __ movzxwl(rdx, Operand(rcx, 0));
115  __ movzxbq(rdx, Operand(rcx, 0));
116  __ movzxwq(rdx, Operand(rcx, 0));
117
118  __ nop();
119  __ imulq(rdx, rcx);
120  __ shld(rdx, rcx);
121  __ shrd(rdx, rcx);
122  __ shlq(Operand(rdi, rax, times_4, 100), Immediate(1));
123  __ shlq(Operand(rdi, rax, times_4, 100), Immediate(6));
124  __ shlq(Operand(r15, 0), Immediate(1));
125  __ shlq(Operand(r15, 0), Immediate(6));
126  __ shlq_cl(Operand(r15, 0));
127  __ shlq_cl(Operand(r15, 0));
128  __ shlq_cl(Operand(rdi, rax, times_4, 100));
129  __ shlq_cl(Operand(rdi, rax, times_4, 100));
130  __ shlq(rdx, Immediate(1));
131  __ shlq(rdx, Immediate(6));
132  __ shll(Operand(rdi, rax, times_4, 100), Immediate(1));
133  __ shll(Operand(rdi, rax, times_4, 100), Immediate(6));
134  __ shll(Operand(r15, 0), Immediate(1));
135  __ shll(Operand(r15, 0), Immediate(6));
136  __ shll_cl(Operand(r15, 0));
137  __ shll_cl(Operand(r15, 0));
138  __ shll_cl(Operand(rdi, rax, times_4, 100));
139  __ shll_cl(Operand(rdi, rax, times_4, 100));
140  __ shll(rdx, Immediate(1));
141  __ shll(rdx, Immediate(6));
142  __ bts(Operand(rdx, 0), rcx);
143  __ bts(Operand(rbx, rcx, times_4, 0), rcx);
144  __ nop();
145  __ pushq(Immediate(12));
146  __ pushq(Immediate(23456));
147  __ pushq(rcx);
148  __ pushq(rsi);
149  __ pushq(Operand(rbp, JavaScriptFrameConstants::kFunctionOffset));
150  __ pushq(Operand(rbx, rcx, times_4, 0));
151  __ pushq(Operand(rbx, rcx, times_4, 0));
152  __ pushq(Operand(rbx, rcx, times_4, 10000));
153  __ popq(rdx);
154  __ popq(rax);
155  __ popq(Operand(rbx, rcx, times_4, 0));
156  __ nop();
157
158  __ addq(rdx, Operand(rsp, 16));
159  __ addq(rdx, rcx);
160  __ movb(rdx, Operand(rcx, 0));
161  __ movb(rcx, Immediate(6));
162  __ movb(Operand(rsp, 16), rdx);
163  __ movw(Operand(rsp, 16), rdx);
164  __ nop();
165  __ movsxwq(rdx, Operand(rsp, 12));
166  __ movsxbq(rdx, Operand(rsp, 12));
167  __ movsxlq(rdx, Operand(rsp, 12));
168  __ movzxwq(rdx, Operand(rsp, 12));
169  __ movzxbq(rdx, Operand(rsp, 12));
170  __ nop();
171  __ movq(rdx, Immediate(1234567));
172  __ movq(rdx, Operand(rsp, 12));
173  __ movq(Operand(rbx, rcx, times_4, 10000), Immediate(12345));
174  __ movq(Operand(rbx, rcx, times_4, 10000), rdx);
175  __ nop();
176  __ decb(rdx);
177  __ decb(Operand(rax, 10));
178  __ decb(Operand(rbx, rcx, times_4, 10000));
179  __ decq(rdx);
180  __ cdq();
181
182  __ nop();
183  __ idivq(rdx);
184  __ mull(rdx);
185  __ mulq(rdx);
186  __ negq(rdx);
187  __ notq(rdx);
188  __ testq(Operand(rbx, rcx, times_4, 10000), rdx);
189
190  __ imulq(rdx, rcx, Immediate(12));
191  __ imulq(rdx, rcx, Immediate(1000));
192  __ imulq(rdx, Operand(rbx, rcx, times_4, 10000));
193  __ imulq(rdx, Operand(rbx, rcx, times_4, 10000), Immediate(12));
194  __ imulq(rdx, Operand(rbx, rcx, times_4, 10000), Immediate(1000));
195  __ imull(r15, rcx, Immediate(12));
196  __ imull(r15, rcx, Immediate(1000));
197  __ imull(r15, Operand(rbx, rcx, times_4, 10000));
198  __ imull(r15, Operand(rbx, rcx, times_4, 10000), Immediate(12));
199  __ imull(r15, Operand(rbx, rcx, times_4, 10000), Immediate(1000));
200
201  __ incq(rdx);
202  __ incq(Operand(rbx, rcx, times_4, 10000));
203  __ pushq(Operand(rbx, rcx, times_4, 10000));
204  __ popq(Operand(rbx, rcx, times_4, 10000));
205  // TODO(mstarzinger): The following is protected.
206  // __ jmp(Operand(rbx, rcx, times_4, 10000));
207
208  __ leaq(rdx, Operand(rbx, rcx, times_4, 10000));
209  __ orq(rdx, Immediate(12345));
210  __ orq(rdx, Operand(rbx, rcx, times_4, 10000));
211
212  __ nop();
213
214  __ rclq(rdx, Immediate(1));
215  __ rclq(rdx, Immediate(7));
216  __ rcrq(rdx, Immediate(1));
217  __ rcrq(rdx, Immediate(7));
218  __ sarq(rdx, Immediate(1));
219  __ sarq(rdx, Immediate(6));
220  __ sarq_cl(rdx);
221  __ sbbq(rdx, rbx);
222  __ shld(rdx, rbx);
223  __ shlq(rdx, Immediate(1));
224  __ shlq(rdx, Immediate(6));
225  __ shlq_cl(rdx);
226  __ shrd(rdx, rbx);
227  __ shrq(rdx, Immediate(1));
228  __ shrq(rdx, Immediate(7));
229  __ shrq_cl(rdx);
230
231
232  // Immediates
233
234  __ addq(rbx, Immediate(12));
235  __ addq(Operand(rdx, rcx, times_4, 10000), Immediate(12));
236
237  __ andq(rbx, Immediate(12345));
238
239  __ cmpq(rbx, Immediate(12345));
240  __ cmpq(rbx, Immediate(12));
241  __ cmpq(Operand(rdx, rcx, times_4, 10000), Immediate(12));
242  __ cmpb(rax, Immediate(100));
243
244  __ orq(rbx, Immediate(12345));
245
246  __ subq(rbx, Immediate(12));
247  __ subq(Operand(rdx, rcx, times_4, 10000), Immediate(12));
248
249  __ xorq(rbx, Immediate(12345));
250
251  __ imulq(rdx, rcx, Immediate(12));
252  __ imulq(rdx, rcx, Immediate(1000));
253
254  __ cld();
255
256  __ subq(rdx, Operand(rbx, rcx, times_4, 10000));
257  __ subq(rdx, rbx);
258
259  __ testq(rdx, Immediate(12345));
260  __ testq(Operand(rbx, rcx, times_8, 10000), rdx);
261  __ testb(Operand(rcx, rbx, times_2, 1000), rdx);
262  __ testb(Operand(rax, -20), Immediate(0x9A));
263  __ nop();
264
265  __ xorq(rdx, Immediate(12345));
266  __ xorq(rdx, Operand(rbx, rcx, times_8, 10000));
267  __ bts(Operand(rbx, rcx, times_8, 10000), rdx);
268  __ hlt();
269  __ int3();
270  __ ret(0);
271  __ ret(8);
272
273  // Calls
274
275  Label L1, L2;
276  __ bind(&L1);
277  __ nop();
278  __ call(&L1);
279  __ call(&L2);
280  __ nop();
281  __ bind(&L2);
282  // TODO(mstarzinger): The following is protected.
283  // __ call(Operand(rbx, rcx, times_4, 10000));
284  __ nop();
285  Handle<Code> ic(CodeFactory::LoadIC(isolate).code());
286  __ call(ic, RelocInfo::CODE_TARGET);
287  __ nop();
288  __ nop();
289
290  __ jmp(&L1);
291  // TODO(mstarzinger): The following is protected.
292  // __ jmp(Operand(rbx, rcx, times_4, 10000));
293  ExternalReference after_break_target =
294      ExternalReference::debug_after_break_target_address(isolate);
295  USE(after_break_target);
296  __ jmp(ic, RelocInfo::CODE_TARGET);
297  __ nop();
298
299
300  Label Ljcc;
301  __ nop();
302  // long jumps
303  __ j(overflow, &Ljcc);
304  __ j(no_overflow, &Ljcc);
305  __ j(below, &Ljcc);
306  __ j(above_equal, &Ljcc);
307  __ j(equal, &Ljcc);
308  __ j(not_equal, &Ljcc);
309  __ j(below_equal, &Ljcc);
310  __ j(above, &Ljcc);
311  __ j(sign, &Ljcc);
312  __ j(not_sign, &Ljcc);
313  __ j(parity_even, &Ljcc);
314  __ j(parity_odd, &Ljcc);
315  __ j(less, &Ljcc);
316  __ j(greater_equal, &Ljcc);
317  __ j(less_equal, &Ljcc);
318  __ j(greater, &Ljcc);
319  __ nop();
320  __ bind(&Ljcc);
321  // short jumps
322  __ j(overflow, &Ljcc);
323  __ j(no_overflow, &Ljcc);
324  __ j(below, &Ljcc);
325  __ j(above_equal, &Ljcc);
326  __ j(equal, &Ljcc);
327  __ j(not_equal, &Ljcc);
328  __ j(below_equal, &Ljcc);
329  __ j(above, &Ljcc);
330  __ j(sign, &Ljcc);
331  __ j(not_sign, &Ljcc);
332  __ j(parity_even, &Ljcc);
333  __ j(parity_odd, &Ljcc);
334  __ j(less, &Ljcc);
335  __ j(greater_equal, &Ljcc);
336  __ j(less_equal, &Ljcc);
337  __ j(greater, &Ljcc);
338
339  // 0xD9 instructions
340  __ nop();
341
342  __ fld(1);
343  __ fld1();
344  __ fldz();
345  __ fldpi();
346  __ fabs();
347  __ fchs();
348  __ fprem();
349  __ fprem1();
350  __ fincstp();
351  __ ftst();
352  __ fxch(3);
353  __ fld_s(Operand(rbx, rcx, times_4, 10000));
354  __ fstp_s(Operand(rbx, rcx, times_4, 10000));
355  __ ffree(3);
356  __ fld_d(Operand(rbx, rcx, times_4, 10000));
357  __ fstp_d(Operand(rbx, rcx, times_4, 10000));
358  __ nop();
359
360  __ fild_s(Operand(rbx, rcx, times_4, 10000));
361  __ fistp_s(Operand(rbx, rcx, times_4, 10000));
362  __ fild_d(Operand(rbx, rcx, times_4, 10000));
363  __ fistp_d(Operand(rbx, rcx, times_4, 10000));
364  __ fnstsw_ax();
365  __ nop();
366  __ fadd(3);
367  __ fsub(3);
368  __ fmul(3);
369  __ fdiv(3);
370
371  __ faddp(3);
372  __ fsubp(3);
373  __ fmulp(3);
374  __ fdivp(3);
375  __ fcompp();
376  __ fwait();
377  __ frndint();
378  __ fninit();
379  __ nop();
380
381  // SSE instruction
382  {
383    // Move operation
384    __ cvttss2si(rdx, Operand(rbx, rcx, times_4, 10000));
385    __ cvttss2si(rdx, xmm1);
386    __ cvtsd2ss(xmm0, xmm1);
387    __ cvtsd2ss(xmm0, Operand(rbx, rcx, times_4, 10000));
388    __ movaps(xmm0, xmm1);
389
390    // logic operation
391    __ andps(xmm0, xmm1);
392    __ andps(xmm0, Operand(rbx, rcx, times_4, 10000));
393    __ orps(xmm0, xmm1);
394    __ orps(xmm0, Operand(rbx, rcx, times_4, 10000));
395    __ xorps(xmm0, xmm1);
396    __ xorps(xmm0, Operand(rbx, rcx, times_4, 10000));
397
398    // Arithmetic operation
399    __ addss(xmm1, xmm0);
400    __ addss(xmm1, Operand(rbx, rcx, times_4, 10000));
401    __ mulss(xmm1, xmm0);
402    __ mulss(xmm1, Operand(rbx, rcx, times_4, 10000));
403    __ subss(xmm1, xmm0);
404    __ subss(xmm1, Operand(rbx, rcx, times_4, 10000));
405    __ divss(xmm1, xmm0);
406    __ divss(xmm1, Operand(rbx, rcx, times_4, 10000));
407    __ maxss(xmm1, xmm0);
408    __ maxss(xmm1, Operand(rbx, rcx, times_4, 10000));
409    __ minss(xmm1, xmm0);
410    __ minss(xmm1, Operand(rbx, rcx, times_4, 10000));
411    __ addps(xmm1, xmm0);
412    __ addps(xmm1, Operand(rbx, rcx, times_4, 10000));
413    __ subps(xmm1, xmm0);
414    __ subps(xmm1, Operand(rbx, rcx, times_4, 10000));
415    __ mulps(xmm1, xmm0);
416    __ mulps(xmm1, Operand(rbx, rcx, times_4, 10000));
417    __ divps(xmm1, xmm0);
418    __ divps(xmm1, Operand(rbx, rcx, times_4, 10000));
419
420    __ ucomiss(xmm0, xmm1);
421    __ ucomiss(xmm0, Operand(rbx, rcx, times_4, 10000));
422  }
423  // SSE 2 instructions
424  {
425    __ cvttsd2si(rdx, Operand(rbx, rcx, times_4, 10000));
426    __ cvttsd2si(rdx, xmm1);
427    __ cvttsd2siq(rdx, xmm1);
428    __ cvttsd2siq(rdx, Operand(rbx, rcx, times_4, 10000));
429    __ cvtqsi2sd(xmm1, Operand(rbx, rcx, times_4, 10000));
430    __ cvtqsi2sd(xmm1, rdx);
431    __ movsd(xmm1, Operand(rbx, rcx, times_4, 10000));
432    __ movsd(Operand(rbx, rcx, times_4, 10000), xmm1);
433    // 128 bit move instructions.
434    __ movdqa(xmm0, Operand(rbx, rcx, times_4, 10000));
435    __ movdqa(Operand(rbx, rcx, times_4, 10000), xmm0);
436
437    __ addsd(xmm1, xmm0);
438    __ addsd(xmm1, Operand(rbx, rcx, times_4, 10000));
439    __ mulsd(xmm1, xmm0);
440    __ mulsd(xmm1, Operand(rbx, rcx, times_4, 10000));
441    __ subsd(xmm1, xmm0);
442    __ subsd(xmm1, Operand(rbx, rcx, times_4, 10000));
443    __ divsd(xmm1, xmm0);
444    __ divsd(xmm1, Operand(rbx, rcx, times_4, 10000));
445    __ minsd(xmm1, xmm0);
446    __ minsd(xmm1, Operand(rbx, rcx, times_4, 10000));
447    __ maxsd(xmm1, xmm0);
448    __ maxsd(xmm1, Operand(rbx, rcx, times_4, 10000));
449    __ ucomisd(xmm0, xmm1);
450
451    __ andpd(xmm0, xmm1);
452
453    __ pslld(xmm0, 6);
454    __ psrld(xmm0, 6);
455    __ psllq(xmm0, 6);
456    __ psrlq(xmm0, 6);
457
458    __ pcmpeqd(xmm1, xmm0);
459
460    __ punpckldq(xmm1, xmm11);
461    __ punpckldq(xmm5, Operand(rdx, 4));
462    __ punpckhdq(xmm8, xmm15);
463  }
464
465  // cmov.
466  {
467    __ cmovq(overflow, rax, Operand(rax, 0));
468    __ cmovq(no_overflow, rax, Operand(rax, 1));
469    __ cmovq(below, rax, Operand(rax, 2));
470    __ cmovq(above_equal, rax, Operand(rax, 3));
471    __ cmovq(equal, rax, Operand(rbx, 0));
472    __ cmovq(not_equal, rax, Operand(rbx, 1));
473    __ cmovq(below_equal, rax, Operand(rbx, 2));
474    __ cmovq(above, rax, Operand(rbx, 3));
475    __ cmovq(sign, rax, Operand(rcx, 0));
476    __ cmovq(not_sign, rax, Operand(rcx, 1));
477    __ cmovq(parity_even, rax, Operand(rcx, 2));
478    __ cmovq(parity_odd, rax, Operand(rcx, 3));
479    __ cmovq(less, rax, Operand(rdx, 0));
480    __ cmovq(greater_equal, rax, Operand(rdx, 1));
481    __ cmovq(less_equal, rax, Operand(rdx, 2));
482    __ cmovq(greater, rax, Operand(rdx, 3));
483  }
484
485  {
486    if (CpuFeatures::IsSupported(SSE4_1)) {
487      CpuFeatureScope scope(&assm, SSE4_1);
488      __ insertps(xmm5, xmm1, 123);
489      __ extractps(rax, xmm1, 0);
490      __ pextrd(rbx, xmm15, 0);
491      __ pextrd(r12, xmm0, 1);
492      __ pinsrd(xmm9, r9, 0);
493      __ pinsrd(xmm5, Operand(rax, 4), 1);
494
495      __ cmpps(xmm5, xmm1, 1);
496      __ cmpeqps(xmm5, xmm1);
497      __ cmpltps(xmm5, xmm1);
498      __ cmpleps(xmm5, xmm1);
499      __ cmpneqps(xmm5, xmm1);
500      __ cmpnltps(xmm5, xmm1);
501      __ cmpnleps(xmm5, xmm1);
502
503      __ minps(xmm5, xmm1);
504      __ minps(xmm5, Operand(rdx, 4));
505      __ maxps(xmm5, xmm1);
506      __ maxps(xmm5, Operand(rdx, 4));
507      __ rcpps(xmm5, xmm1);
508      __ rcpps(xmm5, Operand(rdx, 4));
509      __ sqrtps(xmm5, xmm1);
510      __ sqrtps(xmm5, Operand(rdx, 4));
511      __ movups(xmm5, xmm1);
512      __ movups(xmm5, Operand(rdx, 4));
513      __ movups(Operand(rdx, 4), xmm5);
514      __ paddd(xmm5, xmm1);
515      __ paddd(xmm5, Operand(rdx, 4));
516      __ psubd(xmm5, xmm1);
517      __ psubd(xmm5, Operand(rdx, 4));
518      __ pmulld(xmm5, xmm1);
519      __ pmulld(xmm5, Operand(rdx, 4));
520      __ pmuludq(xmm5, xmm1);
521      __ pmuludq(xmm5, Operand(rdx, 4));
522      __ psrldq(xmm5, 123);
523      __ pshufd(xmm5, xmm1, 3);
524      __ cvtps2dq(xmm5, xmm1);
525      __ cvtps2dq(xmm5, Operand(rdx, 4));
526      __ cvtdq2ps(xmm5, xmm1);
527      __ cvtdq2ps(xmm5, Operand(rdx, 4));
528    }
529  }
530
531  // AVX instruction
532  {
533    if (CpuFeatures::IsSupported(AVX)) {
534      CpuFeatureScope scope(&assm, AVX);
535      __ vmovss(xmm6, xmm14, xmm2);
536      __ vmovss(xmm9, Operand(rbx, rcx, times_4, 10000));
537      __ vmovss(Operand(rbx, rcx, times_4, 10000), xmm0);
538
539      __ vaddss(xmm0, xmm1, xmm2);
540      __ vaddss(xmm0, xmm1, Operand(rbx, rcx, times_4, 10000));
541      __ vmulss(xmm0, xmm1, xmm2);
542      __ vmulss(xmm0, xmm1, Operand(rbx, rcx, times_4, 10000));
543      __ vsubss(xmm0, xmm1, xmm2);
544      __ vsubss(xmm0, xmm1, Operand(rbx, rcx, times_4, 10000));
545      __ vdivss(xmm0, xmm1, xmm2);
546      __ vdivss(xmm0, xmm1, Operand(rbx, rcx, times_2, 10000));
547      __ vminss(xmm8, xmm1, xmm2);
548      __ vminss(xmm9, xmm1, Operand(rbx, rcx, times_8, 10000));
549      __ vmaxss(xmm8, xmm1, xmm2);
550      __ vmaxss(xmm9, xmm1, Operand(rbx, rcx, times_1, 10000));
551      __ vmovss(xmm9, Operand(r11, rcx, times_8, -10000));
552      __ vmovss(Operand(rbx, r9, times_4, 10000), xmm1);
553      __ vucomiss(xmm9, xmm1);
554      __ vucomiss(xmm8, Operand(rbx, rdx, times_2, 10981));
555
556      __ vmovd(xmm5, rdi);
557      __ vmovd(xmm9, Operand(rbx, rcx, times_4, 10000));
558      __ vmovd(r9, xmm6);
559      __ vmovq(xmm5, rdi);
560      __ vmovq(xmm9, Operand(rbx, rcx, times_4, 10000));
561      __ vmovq(r9, xmm6);
562
563      __ vmovsd(xmm6, xmm14, xmm2);
564      __ vmovsd(xmm9, Operand(rbx, rcx, times_4, 10000));
565      __ vmovsd(Operand(rbx, rcx, times_4, 10000), xmm0);
566
567      __ vaddsd(xmm0, xmm1, xmm2);
568      __ vaddsd(xmm0, xmm1, Operand(rbx, rcx, times_4, 10000));
569      __ vmulsd(xmm0, xmm1, xmm2);
570      __ vmulsd(xmm0, xmm1, Operand(rbx, rcx, times_4, 10000));
571      __ vsubsd(xmm0, xmm1, xmm2);
572      __ vsubsd(xmm0, xmm1, Operand(rbx, rcx, times_4, 10000));
573      __ vdivsd(xmm0, xmm1, xmm2);
574      __ vdivsd(xmm0, xmm1, Operand(rbx, rcx, times_2, 10000));
575      __ vminsd(xmm8, xmm1, xmm2);
576      __ vminsd(xmm9, xmm1, Operand(rbx, rcx, times_8, 10000));
577      __ vmaxsd(xmm8, xmm1, xmm2);
578      __ vmaxsd(xmm9, xmm1, Operand(rbx, rcx, times_1, 10000));
579      __ vroundsd(xmm8, xmm3, xmm0, kRoundDown);
580      __ vsqrtsd(xmm8, xmm1, xmm2);
581      __ vsqrtsd(xmm9, xmm1, Operand(rbx, rcx, times_1, 10000));
582      __ vucomisd(xmm9, xmm1);
583      __ vucomisd(xmm8, Operand(rbx, rdx, times_2, 10981));
584
585      __ vcvtss2sd(xmm4, xmm9, xmm11);
586      __ vcvtsd2ss(xmm9, xmm3, xmm2);
587      __ vcvtss2sd(xmm4, xmm9, Operand(rbx, rcx, times_1, 10000));
588      __ vcvtsd2ss(xmm9, xmm3, Operand(rbx, rcx, times_1, 10000));
589      __ vcvtlsi2sd(xmm5, xmm9, rcx);
590      __ vcvtlsi2sd(xmm9, xmm3, Operand(rbx, r9, times_4, 10000));
591      __ vcvtqsi2sd(xmm5, xmm9, r11);
592      __ vcvttsd2si(r9, xmm6);
593      __ vcvttsd2si(rax, Operand(rbx, r9, times_4, 10000));
594      __ vcvttsd2siq(rdi, xmm9);
595      __ vcvttsd2siq(r8, Operand(r9, rbx, times_4, 10000));
596      __ vcvtsd2si(rdi, xmm9);
597
598      __ vmovaps(xmm10, xmm11);
599      __ vmovapd(xmm7, xmm0);
600      __ vmovmskpd(r9, xmm4);
601
602      __ vandps(xmm0, xmm9, xmm2);
603      __ vandps(xmm9, xmm1, Operand(rbx, rcx, times_4, 10000));
604      __ vxorps(xmm0, xmm1, xmm9);
605      __ vxorps(xmm0, xmm1, Operand(rbx, rcx, times_4, 10000));
606
607      __ vandpd(xmm0, xmm9, xmm2);
608      __ vandpd(xmm9, xmm1, Operand(rbx, rcx, times_4, 10000));
609      __ vorpd(xmm0, xmm1, xmm9);
610      __ vorpd(xmm0, xmm1, Operand(rbx, rcx, times_4, 10000));
611      __ vxorpd(xmm0, xmm1, xmm9);
612      __ vxorpd(xmm0, xmm1, Operand(rbx, rcx, times_4, 10000));
613
614      __ vpcmpeqd(xmm0, xmm15, xmm5);
615      __ vpcmpeqd(xmm15, xmm0, Operand(rbx, rcx, times_4, 10000));
616      __ vpsllq(xmm0, xmm15, 21);
617      __ vpsrlq(xmm15, xmm0, 21);
618    }
619  }
620
621  // FMA3 instruction
622  {
623    if (CpuFeatures::IsSupported(FMA3)) {
624      CpuFeatureScope scope(&assm, FMA3);
625      __ vfmadd132sd(xmm0, xmm1, xmm2);
626      __ vfmadd132sd(xmm0, xmm1, Operand(rbx, rcx, times_4, 10000));
627      __ vfmadd213sd(xmm0, xmm1, xmm2);
628      __ vfmadd213sd(xmm0, xmm1, Operand(rbx, rcx, times_4, 10000));
629      __ vfmadd231sd(xmm0, xmm1, xmm2);
630      __ vfmadd231sd(xmm0, xmm1, Operand(rbx, rcx, times_4, 10000));
631
632      __ vfmadd132sd(xmm9, xmm10, xmm11);
633      __ vfmadd132sd(xmm9, xmm10, Operand(r9, r11, times_4, 10000));
634      __ vfmadd213sd(xmm9, xmm10, xmm11);
635      __ vfmadd213sd(xmm9, xmm10, Operand(r9, r11, times_4, 10000));
636      __ vfmadd231sd(xmm9, xmm10, xmm11);
637      __ vfmadd231sd(xmm9, xmm10, Operand(r9, r11, times_4, 10000));
638
639      __ vfmsub132sd(xmm0, xmm1, xmm2);
640      __ vfmsub132sd(xmm0, xmm1, Operand(rbx, rcx, times_4, 10000));
641      __ vfmsub213sd(xmm0, xmm1, xmm2);
642      __ vfmsub213sd(xmm0, xmm1, Operand(rbx, rcx, times_4, 10000));
643      __ vfmsub231sd(xmm0, xmm1, xmm2);
644      __ vfmsub231sd(xmm0, xmm1, Operand(rbx, rcx, times_4, 10000));
645
646      __ vfnmadd132sd(xmm0, xmm1, xmm2);
647      __ vfnmadd132sd(xmm0, xmm1, Operand(rbx, rcx, times_4, 10000));
648      __ vfnmadd213sd(xmm0, xmm1, xmm2);
649      __ vfnmadd213sd(xmm0, xmm1, Operand(rbx, rcx, times_4, 10000));
650      __ vfnmadd231sd(xmm0, xmm1, xmm2);
651      __ vfnmadd231sd(xmm0, xmm1, Operand(rbx, rcx, times_4, 10000));
652
653      __ vfnmsub132sd(xmm0, xmm1, xmm2);
654      __ vfnmsub132sd(xmm0, xmm1, Operand(rbx, rcx, times_4, 10000));
655      __ vfnmsub213sd(xmm0, xmm1, xmm2);
656      __ vfnmsub213sd(xmm0, xmm1, Operand(rbx, rcx, times_4, 10000));
657      __ vfnmsub231sd(xmm0, xmm1, xmm2);
658      __ vfnmsub231sd(xmm0, xmm1, Operand(rbx, rcx, times_4, 10000));
659
660      __ vfmadd132ss(xmm0, xmm1, xmm2);
661      __ vfmadd132ss(xmm0, xmm1, Operand(rbx, rcx, times_4, 10000));
662      __ vfmadd213ss(xmm0, xmm1, xmm2);
663      __ vfmadd213ss(xmm0, xmm1, Operand(rbx, rcx, times_4, 10000));
664      __ vfmadd231ss(xmm0, xmm1, xmm2);
665      __ vfmadd231ss(xmm0, xmm1, Operand(rbx, rcx, times_4, 10000));
666
667      __ vfmsub132ss(xmm0, xmm1, xmm2);
668      __ vfmsub132ss(xmm0, xmm1, Operand(rbx, rcx, times_4, 10000));
669      __ vfmsub213ss(xmm0, xmm1, xmm2);
670      __ vfmsub213ss(xmm0, xmm1, Operand(rbx, rcx, times_4, 10000));
671      __ vfmsub231ss(xmm0, xmm1, xmm2);
672      __ vfmsub231ss(xmm0, xmm1, Operand(rbx, rcx, times_4, 10000));
673
674      __ vfnmadd132ss(xmm0, xmm1, xmm2);
675      __ vfnmadd132ss(xmm0, xmm1, Operand(rbx, rcx, times_4, 10000));
676      __ vfnmadd213ss(xmm0, xmm1, xmm2);
677      __ vfnmadd213ss(xmm0, xmm1, Operand(rbx, rcx, times_4, 10000));
678      __ vfnmadd231ss(xmm0, xmm1, xmm2);
679      __ vfnmadd231ss(xmm0, xmm1, Operand(rbx, rcx, times_4, 10000));
680
681      __ vfnmsub132ss(xmm0, xmm1, xmm2);
682      __ vfnmsub132ss(xmm0, xmm1, Operand(rbx, rcx, times_4, 10000));
683      __ vfnmsub213ss(xmm0, xmm1, xmm2);
684      __ vfnmsub213ss(xmm0, xmm1, Operand(rbx, rcx, times_4, 10000));
685      __ vfnmsub231ss(xmm0, xmm1, xmm2);
686      __ vfnmsub231ss(xmm0, xmm1, Operand(rbx, rcx, times_4, 10000));
687    }
688  }
689
690  // BMI1 instructions
691  {
692    if (CpuFeatures::IsSupported(BMI1)) {
693      CpuFeatureScope scope(&assm, BMI1);
694      __ andnq(rax, rbx, rcx);
695      __ andnq(rax, rbx, Operand(rbx, rcx, times_4, 10000));
696      __ andnl(rax, rbx, rcx);
697      __ andnl(rax, rbx, Operand(rbx, rcx, times_4, 10000));
698      __ bextrq(rax, rbx, rcx);
699      __ bextrq(rax, Operand(rbx, rcx, times_4, 10000), rbx);
700      __ bextrl(rax, rbx, rcx);
701      __ bextrl(rax, Operand(rbx, rcx, times_4, 10000), rbx);
702      __ blsiq(rax, rbx);
703      __ blsiq(rax, Operand(rbx, rcx, times_4, 10000));
704      __ blsil(rax, rbx);
705      __ blsil(rax, Operand(rbx, rcx, times_4, 10000));
706      __ blsmskq(rax, rbx);
707      __ blsmskq(rax, Operand(rbx, rcx, times_4, 10000));
708      __ blsmskl(rax, rbx);
709      __ blsmskl(rax, Operand(rbx, rcx, times_4, 10000));
710      __ blsrq(rax, rbx);
711      __ blsrq(rax, Operand(rbx, rcx, times_4, 10000));
712      __ blsrl(rax, rbx);
713      __ blsrl(rax, Operand(rbx, rcx, times_4, 10000));
714      __ tzcntq(rax, rbx);
715      __ tzcntq(rax, Operand(rbx, rcx, times_4, 10000));
716      __ tzcntl(rax, rbx);
717      __ tzcntl(rax, Operand(rbx, rcx, times_4, 10000));
718    }
719  }
720
721  // LZCNT instructions
722  {
723    if (CpuFeatures::IsSupported(LZCNT)) {
724      CpuFeatureScope scope(&assm, LZCNT);
725      __ lzcntq(rax, rbx);
726      __ lzcntq(rax, Operand(rbx, rcx, times_4, 10000));
727      __ lzcntl(rax, rbx);
728      __ lzcntl(rax, Operand(rbx, rcx, times_4, 10000));
729    }
730  }
731
732  // POPCNT instructions
733  {
734    if (CpuFeatures::IsSupported(POPCNT)) {
735      CpuFeatureScope scope(&assm, POPCNT);
736      __ popcntq(rax, rbx);
737      __ popcntq(rax, Operand(rbx, rcx, times_4, 10000));
738      __ popcntl(rax, rbx);
739      __ popcntl(rax, Operand(rbx, rcx, times_4, 10000));
740    }
741  }
742
743  // BMI2 instructions
744  {
745    if (CpuFeatures::IsSupported(BMI2)) {
746      CpuFeatureScope scope(&assm, BMI2);
747      __ bzhiq(rax, rbx, rcx);
748      __ bzhiq(rax, Operand(rbx, rcx, times_4, 10000), rbx);
749      __ bzhil(rax, rbx, rcx);
750      __ bzhil(rax, Operand(rbx, rcx, times_4, 10000), rbx);
751      __ mulxq(rax, rbx, rcx);
752      __ mulxq(rax, rbx, Operand(rbx, rcx, times_4, 10000));
753      __ mulxl(rax, rbx, rcx);
754      __ mulxl(rax, rbx, Operand(rbx, rcx, times_4, 10000));
755      __ pdepq(rax, rbx, rcx);
756      __ pdepq(rax, rbx, Operand(rbx, rcx, times_4, 10000));
757      __ pdepl(rax, rbx, rcx);
758      __ pdepl(rax, rbx, Operand(rbx, rcx, times_4, 10000));
759      __ pextq(rax, rbx, rcx);
760      __ pextq(rax, rbx, Operand(rbx, rcx, times_4, 10000));
761      __ pextl(rax, rbx, rcx);
762      __ pextl(rax, rbx, Operand(rbx, rcx, times_4, 10000));
763      __ sarxq(rax, rbx, rcx);
764      __ sarxq(rax, Operand(rbx, rcx, times_4, 10000), rbx);
765      __ sarxl(rax, rbx, rcx);
766      __ sarxl(rax, Operand(rbx, rcx, times_4, 10000), rbx);
767      __ shlxq(rax, rbx, rcx);
768      __ shlxq(rax, Operand(rbx, rcx, times_4, 10000), rbx);
769      __ shlxl(rax, rbx, rcx);
770      __ shlxl(rax, Operand(rbx, rcx, times_4, 10000), rbx);
771      __ shrxq(rax, rbx, rcx);
772      __ shrxq(rax, Operand(rbx, rcx, times_4, 10000), rbx);
773      __ shrxl(rax, rbx, rcx);
774      __ shrxl(rax, Operand(rbx, rcx, times_4, 10000), rbx);
775      __ rorxq(rax, rbx, 63);
776      __ rorxq(rax, Operand(rbx, rcx, times_4, 10000), 63);
777      __ rorxl(rax, rbx, 31);
778      __ rorxl(rax, Operand(rbx, rcx, times_4, 10000), 31);
779    }
780  }
781
782  // xchg.
783  {
784    __ xchgb(rax, Operand(rax, 8));
785    __ xchgw(rax, Operand(rbx, 8));
786    __ xchgq(rax, rax);
787    __ xchgq(rax, rbx);
788    __ xchgq(rbx, rbx);
789    __ xchgq(rbx, Operand(rsp, 12));
790  }
791
792  // cmpxchg.
793  {
794    __ cmpxchgb(Operand(rsp, 12), rax);
795    __ cmpxchgw(Operand(rbx, rcx, times_4, 10000), rax);
796    __ cmpxchgl(Operand(rbx, rcx, times_4, 10000), rax);
797    __ cmpxchgq(Operand(rbx, rcx, times_4, 10000), rax);
798  }
799
800  // lock prefix.
801  {
802    __ lock();
803    __ cmpxchgl(Operand(rsp, 12), rbx);
804
805    __ lock();
806    __ xchgw(rax, Operand(rcx, 8));
807  }
808
809  // Nop instructions
810  for (int i = 0; i < 16; i++) {
811    __ Nop(i);
812  }
813
814  __ ret(0);
815
816  CodeDesc desc;
817  assm.GetCode(&desc);
818  Handle<Code> code = isolate->factory()->NewCode(
819      desc, Code::ComputeFlags(Code::STUB), Handle<Code>());
820  USE(code);
821#ifdef OBJECT_PRINT
822  OFStream os(stdout);
823  code->Print(os);
824  byte* begin = code->instruction_start();
825  byte* end = begin + code->instruction_size();
826  disasm::Disassembler::Disassemble(stdout, begin, end);
827#endif
828}
829
830#undef __
831