Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(67)

Side by Side Diff: test/cctest/test-assembler-ia32.cc

Issue 12716010: Added a version of the v8::HandleScope constructor with an Isolate and use that consistently. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Feedback. Rebased Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « test/cctest/test-assembler-arm.cc ('k') | test/cctest/test-assembler-mips.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 if (env.IsEmpty()) { 51 if (env.IsEmpty()) {
52 env = v8::Context::New(); 52 env = v8::Context::New();
53 } 53 }
54 } 54 }
55 55
56 56
57 #define __ assm. 57 #define __ assm.
58 58
59 TEST(AssemblerIa320) { 59 TEST(AssemblerIa320) {
60 InitializeVM(); 60 InitializeVM();
61 v8::HandleScope scope; 61 Isolate* isolate = reinterpret_cast<Isolate*>(env->GetIsolate());
62 HandleScope scope(isolate);
62 63
63 v8::internal::byte buffer[256]; 64 v8::internal::byte buffer[256];
64 Isolate* isolate = Isolate::Current();
65 Assembler assm(isolate, buffer, sizeof buffer); 65 Assembler assm(isolate, buffer, sizeof buffer);
66 66
67 __ mov(eax, Operand(esp, 4)); 67 __ mov(eax, Operand(esp, 4));
68 __ add(eax, Operand(esp, 8)); 68 __ add(eax, Operand(esp, 8));
69 __ ret(0); 69 __ ret(0);
70 70
71 CodeDesc desc; 71 CodeDesc desc;
72 assm.GetCode(&desc); 72 assm.GetCode(&desc);
73 Object* code = isolate->heap()->CreateCode( 73 Object* code = isolate->heap()->CreateCode(
74 desc, 74 desc,
75 Code::ComputeFlags(Code::STUB), 75 Code::ComputeFlags(Code::STUB),
76 Handle<Code>())->ToObjectChecked(); 76 Handle<Code>())->ToObjectChecked();
77 CHECK(code->IsCode()); 77 CHECK(code->IsCode());
78 #ifdef OBJECT_PRINT 78 #ifdef OBJECT_PRINT
79 Code::cast(code)->Print(); 79 Code::cast(code)->Print();
80 #endif 80 #endif
81 F2 f = FUNCTION_CAST<F2>(Code::cast(code)->entry()); 81 F2 f = FUNCTION_CAST<F2>(Code::cast(code)->entry());
82 int res = f(3, 4); 82 int res = f(3, 4);
83 ::printf("f() = %d\n", res); 83 ::printf("f() = %d\n", res);
84 CHECK_EQ(7, res); 84 CHECK_EQ(7, res);
85 } 85 }
86 86
87 87
88 TEST(AssemblerIa321) { 88 TEST(AssemblerIa321) {
89 InitializeVM(); 89 InitializeVM();
90 v8::HandleScope scope; 90 Isolate* isolate = reinterpret_cast<Isolate*>(env->GetIsolate());
91 HandleScope scope(isolate);
91 92
92 v8::internal::byte buffer[256]; 93 v8::internal::byte buffer[256];
93 Isolate* isolate = Isolate::Current();
94 Assembler assm(isolate, buffer, sizeof buffer); 94 Assembler assm(isolate, buffer, sizeof buffer);
95 Label L, C; 95 Label L, C;
96 96
97 __ mov(edx, Operand(esp, 4)); 97 __ mov(edx, Operand(esp, 4));
98 __ xor_(eax, eax); // clear eax 98 __ xor_(eax, eax); // clear eax
99 __ jmp(&C); 99 __ jmp(&C);
100 100
101 __ bind(&L); 101 __ bind(&L);
102 __ add(eax, edx); 102 __ add(eax, edx);
103 __ sub(edx, Immediate(1)); 103 __ sub(edx, Immediate(1));
(...skipping 15 matching lines...) Expand all
119 #endif 119 #endif
120 F1 f = FUNCTION_CAST<F1>(Code::cast(code)->entry()); 120 F1 f = FUNCTION_CAST<F1>(Code::cast(code)->entry());
121 int res = f(100); 121 int res = f(100);
122 ::printf("f() = %d\n", res); 122 ::printf("f() = %d\n", res);
123 CHECK_EQ(5050, res); 123 CHECK_EQ(5050, res);
124 } 124 }
125 125
126 126
127 TEST(AssemblerIa322) { 127 TEST(AssemblerIa322) {
128 InitializeVM(); 128 InitializeVM();
129 v8::HandleScope scope; 129 Isolate* isolate = reinterpret_cast<Isolate*>(env->GetIsolate());
130 HandleScope scope(isolate);
130 131
131 v8::internal::byte buffer[256]; 132 v8::internal::byte buffer[256];
132 Isolate* isolate = Isolate::Current();
133 Assembler assm(isolate, buffer, sizeof buffer); 133 Assembler assm(isolate, buffer, sizeof buffer);
134 Label L, C; 134 Label L, C;
135 135
136 __ mov(edx, Operand(esp, 4)); 136 __ mov(edx, Operand(esp, 4));
137 __ mov(eax, 1); 137 __ mov(eax, 1);
138 __ jmp(&C); 138 __ jmp(&C);
139 139
140 __ bind(&L); 140 __ bind(&L);
141 __ imul(eax, edx); 141 __ imul(eax, edx);
142 __ sub(edx, Immediate(1)); 142 __ sub(edx, Immediate(1));
(...skipping 23 matching lines...) Expand all
166 CHECK_EQ(3628800, res); 166 CHECK_EQ(3628800, res);
167 } 167 }
168 168
169 169
170 typedef int (*F3)(float x); 170 typedef int (*F3)(float x);
171 171
172 TEST(AssemblerIa323) { 172 TEST(AssemblerIa323) {
173 InitializeVM(); 173 InitializeVM();
174 if (!CpuFeatures::IsSupported(SSE2)) return; 174 if (!CpuFeatures::IsSupported(SSE2)) return;
175 175
176 v8::HandleScope scope; 176 Isolate* isolate = reinterpret_cast<Isolate*>(env->GetIsolate());
177 HandleScope scope(isolate);
177 178
178 v8::internal::byte buffer[256]; 179 v8::internal::byte buffer[256];
179 Isolate* isolate = Isolate::Current();
180 Assembler assm(isolate, buffer, sizeof buffer); 180 Assembler assm(isolate, buffer, sizeof buffer);
181 181
182 CHECK(CpuFeatures::IsSupported(SSE2)); 182 CHECK(CpuFeatures::IsSupported(SSE2));
183 { CpuFeatureScope fscope(&assm, SSE2); 183 { CpuFeatureScope fscope(&assm, SSE2);
184 __ cvttss2si(eax, Operand(esp, 4)); 184 __ cvttss2si(eax, Operand(esp, 4));
185 __ ret(0); 185 __ ret(0);
186 } 186 }
187 187
188 CodeDesc desc; 188 CodeDesc desc;
189 assm.GetCode(&desc); 189 assm.GetCode(&desc);
(...skipping 12 matching lines...) Expand all
202 CHECK_EQ(-3, res); 202 CHECK_EQ(-3, res);
203 } 203 }
204 204
205 205
206 typedef int (*F4)(double x); 206 typedef int (*F4)(double x);
207 207
208 TEST(AssemblerIa324) { 208 TEST(AssemblerIa324) {
209 InitializeVM(); 209 InitializeVM();
210 if (!CpuFeatures::IsSupported(SSE2)) return; 210 if (!CpuFeatures::IsSupported(SSE2)) return;
211 211
212 v8::HandleScope scope; 212 Isolate* isolate = reinterpret_cast<Isolate*>(env->GetIsolate());
213 HandleScope scope(isolate);
213 214
214 v8::internal::byte buffer[256]; 215 v8::internal::byte buffer[256];
215 Isolate* isolate = Isolate::Current();
216 Assembler assm(isolate, buffer, sizeof buffer); 216 Assembler assm(isolate, buffer, sizeof buffer);
217 217
218 CHECK(CpuFeatures::IsSupported(SSE2)); 218 CHECK(CpuFeatures::IsSupported(SSE2));
219 CpuFeatureScope fscope(&assm, SSE2); 219 CpuFeatureScope fscope(&assm, SSE2);
220 __ cvttsd2si(eax, Operand(esp, 4)); 220 __ cvttsd2si(eax, Operand(esp, 4));
221 __ ret(0); 221 __ ret(0);
222 222
223 CodeDesc desc; 223 CodeDesc desc;
224 assm.GetCode(&desc); 224 assm.GetCode(&desc);
225 Code* code = Code::cast(isolate->heap()->CreateCode( 225 Code* code = Code::cast(isolate->heap()->CreateCode(
226 desc, 226 desc,
227 Code::ComputeFlags(Code::STUB), 227 Code::ComputeFlags(Code::STUB),
228 Handle<Code>())->ToObjectChecked()); 228 Handle<Code>())->ToObjectChecked());
229 // don't print the code - our disassembler can't handle cvttsd2si 229 // don't print the code - our disassembler can't handle cvttsd2si
230 // instead print bytes 230 // instead print bytes
231 Disassembler::Dump(stdout, 231 Disassembler::Dump(stdout,
232 code->instruction_start(), 232 code->instruction_start(),
233 code->instruction_start() + code->instruction_size()); 233 code->instruction_start() + code->instruction_size());
234 F4 f = FUNCTION_CAST<F4>(code->entry()); 234 F4 f = FUNCTION_CAST<F4>(code->entry());
235 int res = f(2.718281828); 235 int res = f(2.718281828);
236 ::printf("f() = %d\n", res); 236 ::printf("f() = %d\n", res);
237 CHECK_EQ(2, res); 237 CHECK_EQ(2, res);
238 } 238 }
239 239
240 240
241 static int baz = 42; 241 static int baz = 42;
242 TEST(AssemblerIa325) { 242 TEST(AssemblerIa325) {
243 InitializeVM(); 243 InitializeVM();
244 v8::HandleScope scope; 244 Isolate* isolate = reinterpret_cast<Isolate*>(env->GetIsolate());
245 HandleScope scope(isolate);
245 246
246 v8::internal::byte buffer[256]; 247 v8::internal::byte buffer[256];
247 Isolate* isolate = Isolate::Current();
248 Assembler assm(isolate, buffer, sizeof buffer); 248 Assembler assm(isolate, buffer, sizeof buffer);
249 249
250 __ mov(eax, Operand(reinterpret_cast<intptr_t>(&baz), RelocInfo::NONE32)); 250 __ mov(eax, Operand(reinterpret_cast<intptr_t>(&baz), RelocInfo::NONE32));
251 __ ret(0); 251 __ ret(0);
252 252
253 CodeDesc desc; 253 CodeDesc desc;
254 assm.GetCode(&desc); 254 assm.GetCode(&desc);
255 Code* code = Code::cast(isolate->heap()->CreateCode( 255 Code* code = Code::cast(isolate->heap()->CreateCode(
256 desc, 256 desc,
257 Code::ComputeFlags(Code::STUB), 257 Code::ComputeFlags(Code::STUB),
258 Handle<Code>())->ToObjectChecked()); 258 Handle<Code>())->ToObjectChecked());
259 F0 f = FUNCTION_CAST<F0>(code->entry()); 259 F0 f = FUNCTION_CAST<F0>(code->entry());
260 int res = f(); 260 int res = f();
261 CHECK_EQ(42, res); 261 CHECK_EQ(42, res);
262 } 262 }
263 263
264 264
265 typedef double (*F5)(double x, double y); 265 typedef double (*F5)(double x, double y);
266 266
267 TEST(AssemblerIa326) { 267 TEST(AssemblerIa326) {
268 InitializeVM(); 268 InitializeVM();
269 if (!CpuFeatures::IsSupported(SSE2)) return; 269 if (!CpuFeatures::IsSupported(SSE2)) return;
270 270
271 v8::HandleScope scope; 271 Isolate* isolate = reinterpret_cast<Isolate*>(env->GetIsolate());
272 HandleScope scope(isolate);
272 v8::internal::byte buffer[256]; 273 v8::internal::byte buffer[256];
273 Isolate* isolate = Isolate::Current();
274 Assembler assm(isolate, buffer, sizeof buffer); 274 Assembler assm(isolate, buffer, sizeof buffer);
275 275
276 CpuFeatureScope fscope(&assm, SSE2); 276 CpuFeatureScope fscope(&assm, SSE2);
277 __ movdbl(xmm0, Operand(esp, 1 * kPointerSize)); 277 __ movdbl(xmm0, Operand(esp, 1 * kPointerSize));
278 __ movdbl(xmm1, Operand(esp, 3 * kPointerSize)); 278 __ movdbl(xmm1, Operand(esp, 3 * kPointerSize));
279 __ addsd(xmm0, xmm1); 279 __ addsd(xmm0, xmm1);
280 __ mulsd(xmm0, xmm1); 280 __ mulsd(xmm0, xmm1);
281 __ subsd(xmm0, xmm1); 281 __ subsd(xmm0, xmm1);
282 __ divsd(xmm0, xmm1); 282 __ divsd(xmm0, xmm1);
283 // Copy xmm0 to st(0) using eight bytes of stack. 283 // Copy xmm0 to st(0) using eight bytes of stack.
(...skipping 23 matching lines...) Expand all
307 CHECK(2.29 < res && res < 2.31); 307 CHECK(2.29 < res && res < 2.31);
308 } 308 }
309 309
310 310
311 typedef double (*F6)(int x); 311 typedef double (*F6)(int x);
312 312
313 TEST(AssemblerIa328) { 313 TEST(AssemblerIa328) {
314 InitializeVM(); 314 InitializeVM();
315 if (!CpuFeatures::IsSupported(SSE2)) return; 315 if (!CpuFeatures::IsSupported(SSE2)) return;
316 316
317 v8::HandleScope scope; 317 Isolate* isolate = reinterpret_cast<Isolate*>(env->GetIsolate());
318 HandleScope scope(isolate);
318 v8::internal::byte buffer[256]; 319 v8::internal::byte buffer[256];
319 Isolate* isolate = Isolate::Current();
320 Assembler assm(isolate, buffer, sizeof buffer); 320 Assembler assm(isolate, buffer, sizeof buffer);
321 CpuFeatureScope fscope(&assm, SSE2); 321 CpuFeatureScope fscope(&assm, SSE2);
322 __ mov(eax, Operand(esp, 4)); 322 __ mov(eax, Operand(esp, 4));
323 __ cvtsi2sd(xmm0, eax); 323 __ cvtsi2sd(xmm0, eax);
324 // Copy xmm0 to st(0) using eight bytes of stack. 324 // Copy xmm0 to st(0) using eight bytes of stack.
325 __ sub(esp, Immediate(8)); 325 __ sub(esp, Immediate(8));
326 __ movdbl(Operand(esp, 0), xmm0); 326 __ movdbl(Operand(esp, 0), xmm0);
327 __ fld_d(Operand(esp, 0)); 327 __ fld_d(Operand(esp, 0));
328 __ add(esp, Immediate(8)); 328 __ add(esp, Immediate(8));
329 __ ret(0); 329 __ ret(0);
(...skipping 12 matching lines...) Expand all
342 342
343 ::printf("f() = %f\n", res); 343 ::printf("f() = %f\n", res);
344 CHECK(11.99 < res && res < 12.001); 344 CHECK(11.99 < res && res < 12.001);
345 } 345 }
346 346
347 347
348 typedef int (*F7)(double x, double y); 348 typedef int (*F7)(double x, double y);
349 349
350 TEST(AssemblerIa329) { 350 TEST(AssemblerIa329) {
351 InitializeVM(); 351 InitializeVM();
352 v8::HandleScope scope; 352 Isolate* isolate = reinterpret_cast<Isolate*>(env->GetIsolate());
353 HandleScope scope(isolate);
353 v8::internal::byte buffer[256]; 354 v8::internal::byte buffer[256];
354 Isolate* isolate = Isolate::Current();
355 MacroAssembler assm(isolate, buffer, sizeof buffer); 355 MacroAssembler assm(isolate, buffer, sizeof buffer);
356 enum { kEqual = 0, kGreater = 1, kLess = 2, kNaN = 3, kUndefined = 4 }; 356 enum { kEqual = 0, kGreater = 1, kLess = 2, kNaN = 3, kUndefined = 4 };
357 Label equal_l, less_l, greater_l, nan_l; 357 Label equal_l, less_l, greater_l, nan_l;
358 __ fld_d(Operand(esp, 3 * kPointerSize)); 358 __ fld_d(Operand(esp, 3 * kPointerSize));
359 __ fld_d(Operand(esp, 1 * kPointerSize)); 359 __ fld_d(Operand(esp, 1 * kPointerSize));
360 __ FCmp(); 360 __ FCmp();
361 __ j(parity_even, &nan_l); 361 __ j(parity_even, &nan_l);
362 __ j(equal, &equal_l); 362 __ j(equal, &equal_l);
363 __ j(below, &less_l); 363 __ j(below, &less_l);
364 __ j(above, &greater_l); 364 __ j(above, &greater_l);
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
398 CHECK_EQ(kLess, f(1.1, 2.2)); 398 CHECK_EQ(kLess, f(1.1, 2.2));
399 CHECK_EQ(kEqual, f(2.2, 2.2)); 399 CHECK_EQ(kEqual, f(2.2, 2.2));
400 CHECK_EQ(kGreater, f(3.3, 2.2)); 400 CHECK_EQ(kGreater, f(3.3, 2.2));
401 CHECK_EQ(kNaN, f(OS::nan_value(), 1.1)); 401 CHECK_EQ(kNaN, f(OS::nan_value(), 1.1));
402 } 402 }
403 403
404 404
405 TEST(AssemblerIa3210) { 405 TEST(AssemblerIa3210) {
406 // Test chaining of label usages within instructions (issue 1644). 406 // Test chaining of label usages within instructions (issue 1644).
407 InitializeVM(); 407 InitializeVM();
408 v8::HandleScope scope; 408 Isolate* isolate = reinterpret_cast<Isolate*>(env->GetIsolate());
409 Isolate* isolate = Isolate::Current(); 409 HandleScope scope(isolate);
410 Assembler assm(isolate, NULL, 0); 410 Assembler assm(isolate, NULL, 0);
411 411
412 Label target; 412 Label target;
413 __ j(equal, &target); 413 __ j(equal, &target);
414 __ j(not_equal, &target); 414 __ j(not_equal, &target);
415 __ bind(&target); 415 __ bind(&target);
416 __ nop(); 416 __ nop();
417 } 417 }
418 418
419 419
420 TEST(AssemblerMultiByteNop) { 420 TEST(AssemblerMultiByteNop) {
421 InitializeVM(); 421 InitializeVM();
422 v8::HandleScope scope; 422 Isolate* isolate = reinterpret_cast<Isolate*>(env->GetIsolate());
423 HandleScope scope(isolate);
423 v8::internal::byte buffer[1024]; 424 v8::internal::byte buffer[1024];
424 Isolate* isolate = Isolate::Current();
425 Assembler assm(isolate, buffer, sizeof(buffer)); 425 Assembler assm(isolate, buffer, sizeof(buffer));
426 __ push(ebx); 426 __ push(ebx);
427 __ push(ecx); 427 __ push(ecx);
428 __ push(edx); 428 __ push(edx);
429 __ push(edi); 429 __ push(edi);
430 __ push(esi); 430 __ push(esi);
431 __ mov(eax, 1); 431 __ mov(eax, 1);
432 __ mov(ebx, 2); 432 __ mov(ebx, 2);
433 __ mov(ecx, 3); 433 __ mov(ecx, 3);
434 __ mov(edx, 4); 434 __ mov(edx, 4);
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
479 479
480 F0 f = FUNCTION_CAST<F0>(code->entry()); 480 F0 f = FUNCTION_CAST<F0>(code->entry());
481 int res = f(); 481 int res = f();
482 CHECK_EQ(42, res); 482 CHECK_EQ(42, res);
483 } 483 }
484 484
485 485
486 486
487 487
488 #undef __ 488 #undef __
OLDNEW
« no previous file with comments | « test/cctest/test-assembler-arm.cc ('k') | test/cctest/test-assembler-mips.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698