The data contained in this repository can be downloaded to your computer using one of several clients.
Please see the documentation of your version control software client for more information.

Please select the desired protocol below to get the URL.

This URL has Read-Only access.

Statistics
| Branch: | Revision:

main_repo / deps / v8 / test / cctest / test-disasm-ia32.cc @ f230a1cf

History | View | Annotate | Download (11.8 KB)

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 "v8.h"
31

    
32
#include "debug.h"
33
#include "disasm.h"
34
#include "disassembler.h"
35
#include "macro-assembler.h"
36
#include "serialize.h"
37
#include "cctest.h"
38

    
39
using namespace v8::internal;
40

    
41

    
42
#define __ assm.
43

    
44

    
45
static void DummyStaticFunction(Object* result) {
46
}
47

    
48

    
49
TEST(DisasmIa320) {
50
  CcTest::InitializeVM();
51
  Isolate* isolate = reinterpret_cast<Isolate*>(CcTest::isolate());
52
  HandleScope scope(isolate);
53
  v8::internal::byte buffer[2048];
54
  Assembler assm(isolate, buffer, sizeof buffer);
55
  DummyStaticFunction(NULL);  // just bloody use it (DELETE; debugging)
56

    
57
  // Short immediate instructions
58
  __ adc(eax, 12345678);
59
  __ add(eax, Immediate(12345678));
60
  __ or_(eax, 12345678);
61
  __ sub(eax, Immediate(12345678));
62
  __ xor_(eax, 12345678);
63
  __ and_(eax, 12345678);
64
  Handle<FixedArray> foo = isolate->factory()->NewFixedArray(10, TENURED);
65
  __ cmp(eax, foo);
66

    
67
  // ---- This one caused crash
68
  __ mov(ebx,  Operand(esp, ecx, times_2, 0));  // [esp+ecx*4]
69

    
70
  // ---- All instructions that I can think of
71
  __ add(edx, ebx);
72
  __ add(edx, Operand(12, RelocInfo::NONE32));
73
  __ add(edx, Operand(ebx, 0));
74
  __ add(edx, Operand(ebx, 16));
75
  __ add(edx, Operand(ebx, 1999));
76
  __ add(edx, Operand(esp, 0));
77
  __ add(edx, Operand(esp, 16));
78
  __ add(edx, Operand(esp, 1999));
79
  __ nop();
80
  __ add(edi, Operand(ebp, ecx, times_4, 0));
81
  __ add(edi, Operand(ebp, ecx, times_4, 12));
82
  __ add(Operand(ebp, ecx, times_4, 12), Immediate(12));
83

    
84
  __ nop();
85
  __ add(ebx, Immediate(12));
86
  __ nop();
87
  __ adc(ecx, 12);
88
  __ adc(ecx, 1000);
89
  __ nop();
90
  __ and_(edx, 3);
91
  __ and_(edx, Operand(esp, 4));
92
  __ cmp(edx, 3);
93
  __ cmp(edx, Operand(esp, 4));
94
  __ cmp(Operand(ebp, ecx, times_4, 0), Immediate(1000));
95
  Handle<FixedArray> foo2 = isolate->factory()->NewFixedArray(10, TENURED);
96
  __ cmp(ebx, foo2);
97
  __ cmpb(ebx, Operand(ebp, ecx, times_2, 0));
98
  __ cmpb(Operand(ebp, ecx, times_2, 0), ebx);
99
  __ or_(edx, 3);
100
  __ xor_(edx, 3);
101
  __ nop();
102
  __ cpuid();
103
  __ movsx_b(edx, ecx);
104
  __ movsx_w(edx, ecx);
105
  __ movzx_b(edx, ecx);
106
  __ movzx_w(edx, ecx);
107

    
108
  __ nop();
109
  __ imul(edx, ecx);
110
  __ shld(edx, ecx);
111
  __ shrd(edx, ecx);
112
  __ bts(edx, ecx);
113
  __ bts(Operand(ebx, ecx, times_4, 0), ecx);
114
  __ nop();
115
  __ pushad();
116
  __ popad();
117
  __ pushfd();
118
  __ popfd();
119
  __ push(Immediate(12));
120
  __ push(Immediate(23456));
121
  __ push(ecx);
122
  __ push(esi);
123
  __ push(Operand(ebp, JavaScriptFrameConstants::kFunctionOffset));
124
  __ push(Operand(ebx, ecx, times_4, 0));
125
  __ push(Operand(ebx, ecx, times_4, 0));
126
  __ push(Operand(ebx, ecx, times_4, 10000));
127
  __ pop(edx);
128
  __ pop(eax);
129
  __ pop(Operand(ebx, ecx, times_4, 0));
130
  __ nop();
131

    
132
  __ add(edx, Operand(esp, 16));
133
  __ add(edx, ecx);
134
  __ mov_b(edx, ecx);
135
  __ mov_b(ecx, 6);
136
  __ mov_b(Operand(ebx, ecx, times_4, 10000), 6);
137
  __ mov_b(Operand(esp, 16), edx);
138
  __ mov_w(edx, Operand(esp, 16));
139
  __ mov_w(Operand(esp, 16), edx);
140
  __ nop();
141
  __ movsx_w(edx, Operand(esp, 12));
142
  __ movsx_b(edx, Operand(esp, 12));
143
  __ movzx_w(edx, Operand(esp, 12));
144
  __ movzx_b(edx, Operand(esp, 12));
145
  __ nop();
146
  __ mov(edx, 1234567);
147
  __ mov(edx, Operand(esp, 12));
148
  __ mov(Operand(ebx, ecx, times_4, 10000), Immediate(12345));
149
  __ mov(Operand(ebx, ecx, times_4, 10000), edx);
150
  __ nop();
151
  __ dec_b(edx);
152
  __ dec_b(Operand(eax, 10));
153
  __ dec_b(Operand(ebx, ecx, times_4, 10000));
154
  __ dec(edx);
155
  __ cdq();
156

    
157
  __ nop();
158
  __ idiv(edx);
159
  __ mul(edx);
160
  __ neg(edx);
161
  __ not_(edx);
162
  __ test(Operand(ebx, ecx, times_4, 10000), Immediate(123456));
163

    
164
  __ imul(edx, Operand(ebx, ecx, times_4, 10000));
165
  __ imul(edx, ecx, 12);
166
  __ imul(edx, ecx, 1000);
167

    
168
  __ inc(edx);
169
  __ inc(Operand(ebx, ecx, times_4, 10000));
170
  __ push(Operand(ebx, ecx, times_4, 10000));
171
  __ pop(Operand(ebx, ecx, times_4, 10000));
172
  __ call(Operand(ebx, ecx, times_4, 10000));
173
  __ jmp(Operand(ebx, ecx, times_4, 10000));
174

    
175
  __ lea(edx, Operand(ebx, ecx, times_4, 10000));
176
  __ or_(edx, 12345);
177
  __ or_(edx, Operand(ebx, ecx, times_4, 10000));
178

    
179
  __ nop();
180

    
181
  __ rcl(edx, 1);
182
  __ rcl(edx, 7);
183
  __ rcr(edx, 1);
184
  __ rcr(edx, 7);
185
  __ sar(edx, 1);
186
  __ sar(edx, 6);
187
  __ sar_cl(edx);
188
  __ sbb(edx, Operand(ebx, ecx, times_4, 10000));
189
  __ shld(edx, Operand(ebx, ecx, times_4, 10000));
190
  __ shl(edx, 1);
191
  __ shl(edx, 6);
192
  __ shl_cl(edx);
193
  __ shrd(edx, Operand(ebx, ecx, times_4, 10000));
194
  __ shr(edx, 1);
195
  __ shr(edx, 7);
196
  __ shr_cl(edx);
197

    
198

    
199
  // Immediates
200

    
201
  __ adc(edx, 12345);
202

    
203
  __ add(ebx, Immediate(12));
204
  __ add(Operand(edx, ecx, times_4, 10000), Immediate(12));
205

    
206
  __ and_(ebx, 12345);
207

    
208
  __ cmp(ebx, 12345);
209
  __ cmp(ebx, Immediate(12));
210
  __ cmp(Operand(edx, ecx, times_4, 10000), Immediate(12));
211
  __ cmpb(eax, 100);
212

    
213
  __ or_(ebx, 12345);
214

    
215
  __ sub(ebx, Immediate(12));
216
  __ sub(Operand(edx, ecx, times_4, 10000), Immediate(12));
217

    
218
  __ xor_(ebx, 12345);
219

    
220
  __ imul(edx, ecx, 12);
221
  __ imul(edx, ecx, 1000);
222

    
223
  __ cld();
224
  __ rep_movs();
225
  __ rep_stos();
226
  __ stos();
227

    
228
  __ sub(edx, Operand(ebx, ecx, times_4, 10000));
229
  __ sub(edx, ebx);
230

    
231
  __ test(edx, Immediate(12345));
232
  __ test(edx, Operand(ebx, ecx, times_8, 10000));
233
  __ test(Operand(esi, edi, times_1, -20000000), Immediate(300000000));
234
  __ test_b(edx, Operand(ecx, ebx, times_2, 1000));
235
  __ test_b(Operand(eax, -20), 0x9A);
236
  __ nop();
237

    
238
  __ xor_(edx, 12345);
239
  __ xor_(edx, Operand(ebx, ecx, times_8, 10000));
240
  __ bts(Operand(ebx, ecx, times_8, 10000), edx);
241
  __ hlt();
242
  __ int3();
243
  __ ret(0);
244
  __ ret(8);
245

    
246
  // Calls
247

    
248
  Label L1, L2;
249
  __ bind(&L1);
250
  __ nop();
251
  __ call(&L1);
252
  __ call(&L2);
253
  __ nop();
254
  __ bind(&L2);
255
  __ call(Operand(ebx, ecx, times_4, 10000));
256
  __ nop();
257
  Handle<Code> ic(isolate->builtins()->builtin(Builtins::kLoadIC_Initialize));
258
  __ call(ic, RelocInfo::CODE_TARGET);
259
  __ nop();
260
  __ call(FUNCTION_ADDR(DummyStaticFunction), RelocInfo::RUNTIME_ENTRY);
261
  __ nop();
262

    
263
  __ jmp(&L1);
264
  __ jmp(Operand(ebx, ecx, times_4, 10000));
265
#ifdef ENABLE_DEBUGGER_SUPPORT
266
  ExternalReference after_break_target =
267
      ExternalReference(Debug_Address::AfterBreakTarget(), isolate);
268
  __ jmp(Operand::StaticVariable(after_break_target));
269
#endif  // ENABLE_DEBUGGER_SUPPORT
270
  __ jmp(ic, RelocInfo::CODE_TARGET);
271
  __ nop();
272

    
273

    
274
  Label Ljcc;
275
  __ nop();
276
  // long jumps
277
  __ j(overflow, &Ljcc);
278
  __ j(no_overflow, &Ljcc);
279
  __ j(below, &Ljcc);
280
  __ j(above_equal, &Ljcc);
281
  __ j(equal, &Ljcc);
282
  __ j(not_equal, &Ljcc);
283
  __ j(below_equal, &Ljcc);
284
  __ j(above, &Ljcc);
285
  __ j(sign, &Ljcc);
286
  __ j(not_sign, &Ljcc);
287
  __ j(parity_even, &Ljcc);
288
  __ j(parity_odd, &Ljcc);
289
  __ j(less, &Ljcc);
290
  __ j(greater_equal, &Ljcc);
291
  __ j(less_equal, &Ljcc);
292
  __ j(greater, &Ljcc);
293
  __ nop();
294
  __ bind(&Ljcc);
295
  // short jumps
296
  __ j(overflow, &Ljcc);
297
  __ j(no_overflow, &Ljcc);
298
  __ j(below, &Ljcc);
299
  __ j(above_equal, &Ljcc);
300
  __ j(equal, &Ljcc);
301
  __ j(not_equal, &Ljcc);
302
  __ j(below_equal, &Ljcc);
303
  __ j(above, &Ljcc);
304
  __ j(sign, &Ljcc);
305
  __ j(not_sign, &Ljcc);
306
  __ j(parity_even, &Ljcc);
307
  __ j(parity_odd, &Ljcc);
308
  __ j(less, &Ljcc);
309
  __ j(greater_equal, &Ljcc);
310
  __ j(less_equal, &Ljcc);
311
  __ j(greater, &Ljcc);
312

    
313
  // 0xD9 instructions
314
  __ nop();
315

    
316
  __ fld(1);
317
  __ fld1();
318
  __ fldz();
319
  __ fldpi();
320
  __ fabs();
321
  __ fchs();
322
  __ fprem();
323
  __ fprem1();
324
  __ fincstp();
325
  __ ftst();
326
  __ fxch(3);
327
  __ fld_s(Operand(ebx, ecx, times_4, 10000));
328
  __ fstp_s(Operand(ebx, ecx, times_4, 10000));
329
  __ ffree(3);
330
  __ fld_d(Operand(ebx, ecx, times_4, 10000));
331
  __ fstp_d(Operand(ebx, ecx, times_4, 10000));
332
  __ nop();
333

    
334
  __ fild_s(Operand(ebx, ecx, times_4, 10000));
335
  __ fistp_s(Operand(ebx, ecx, times_4, 10000));
336
  __ fild_d(Operand(ebx, ecx, times_4, 10000));
337
  __ fistp_d(Operand(ebx, ecx, times_4, 10000));
338
  __ fnstsw_ax();
339
  __ nop();
340
  __ fadd(3);
341
  __ fsub(3);
342
  __ fmul(3);
343
  __ fdiv(3);
344

    
345
  __ faddp(3);
346
  __ fsubp(3);
347
  __ fmulp(3);
348
  __ fdivp(3);
349
  __ fcompp();
350
  __ fwait();
351
  __ nop();
352
  {
353
    if (CpuFeatures::IsSupported(SSE2)) {
354
      CpuFeatureScope fscope(&assm, SSE2);
355
      __ cvttss2si(edx, Operand(ebx, ecx, times_4, 10000));
356
      __ cvtsi2sd(xmm1, Operand(ebx, ecx, times_4, 10000));
357
      __ movsd(xmm1, Operand(ebx, ecx, times_4, 10000));
358
      __ movsd(Operand(ebx, ecx, times_4, 10000), xmm1);
359
      __ movaps(xmm0, xmm1);
360
      // 128 bit move instructions.
361
      __ movdqa(xmm0, Operand(ebx, ecx, times_4, 10000));
362
      __ movdqa(Operand(ebx, ecx, times_4, 10000), xmm0);
363
      __ movdqu(xmm0, Operand(ebx, ecx, times_4, 10000));
364
      __ movdqu(Operand(ebx, ecx, times_4, 10000), xmm0);
365

    
366
      __ addsd(xmm1, xmm0);
367
      __ mulsd(xmm1, xmm0);
368
      __ subsd(xmm1, xmm0);
369
      __ divsd(xmm1, xmm0);
370
      __ ucomisd(xmm0, xmm1);
371
      __ cmpltsd(xmm0, xmm1);
372

    
373
      __ andps(xmm0, xmm1);
374
      __ andpd(xmm0, xmm1);
375
      __ psllq(xmm0, 17);
376
      __ psllq(xmm0, xmm1);
377
      __ psrlq(xmm0, 17);
378
      __ psrlq(xmm0, xmm1);
379
      __ por(xmm0, xmm1);
380
    }
381
  }
382

    
383
  // cmov.
384
  {
385
    if (CpuFeatures::IsSupported(CMOV)) {
386
      CpuFeatureScope use_cmov(&assm, CMOV);
387
      __ cmov(overflow, eax, Operand(eax, 0));
388
      __ cmov(no_overflow, eax, Operand(eax, 1));
389
      __ cmov(below, eax, Operand(eax, 2));
390
      __ cmov(above_equal, eax, Operand(eax, 3));
391
      __ cmov(equal, eax, Operand(ebx, 0));
392
      __ cmov(not_equal, eax, Operand(ebx, 1));
393
      __ cmov(below_equal, eax, Operand(ebx, 2));
394
      __ cmov(above, eax, Operand(ebx, 3));
395
      __ cmov(sign, eax, Operand(ecx, 0));
396
      __ cmov(not_sign, eax, Operand(ecx, 1));
397
      __ cmov(parity_even, eax, Operand(ecx, 2));
398
      __ cmov(parity_odd, eax, Operand(ecx, 3));
399
      __ cmov(less, eax, Operand(edx, 0));
400
      __ cmov(greater_equal, eax, Operand(edx, 1));
401
      __ cmov(less_equal, eax, Operand(edx, 2));
402
      __ cmov(greater, eax, Operand(edx, 3));
403
    }
404
  }
405

    
406
  {
407
    if (CpuFeatures::IsSupported(SSE2) &&
408
        CpuFeatures::IsSupported(SSE4_1)) {
409
      CpuFeatureScope scope(&assm, SSE4_1);
410
      __ pextrd(eax, xmm0, 1);
411
      __ pinsrd(xmm1, eax, 0);
412
      __ extractps(eax, xmm1, 0);
413
    }
414
  }
415

    
416
  // Nop instructions
417
  for (int i = 0; i < 16; i++) {
418
    __ Nop(i);
419
  }
420

    
421
  __ ret(0);
422

    
423
  CodeDesc desc;
424
  assm.GetCode(&desc);
425
  Object* code = isolate->heap()->CreateCode(
426
      desc,
427
      Code::ComputeFlags(Code::STUB),
428
      Handle<Code>())->ToObjectChecked();
429
  CHECK(code->IsCode());
430
#ifdef OBJECT_PRINT
431
  Code::cast(code)->Print();
432
  byte* begin = Code::cast(code)->instruction_start();
433
  byte* end = begin + Code::cast(code)->instruction_size();
434
  disasm::Disassembler::Disassemble(stdout, begin, end);
435
#endif
436
}
437

    
438
#undef __