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

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

Issue 6670119: VM initialization refactoring. (Closed)
Patch Set: Created 9 years, 8 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
OLDNEW
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. 1 // Copyright 2006-2008 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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 v8::HandleScope scope;
62 62
63 v8::internal::byte buffer[256]; 63 v8::internal::byte buffer[256];
64 Assembler assm(buffer, sizeof buffer); 64 Assembler assm(Isolate::Current(), buffer, sizeof buffer);
65 65
66 __ mov(eax, Operand(esp, 4)); 66 __ mov(eax, Operand(esp, 4));
67 __ add(eax, Operand(esp, 8)); 67 __ add(eax, Operand(esp, 8));
68 __ ret(0); 68 __ ret(0);
69 69
70 CodeDesc desc; 70 CodeDesc desc;
71 assm.GetCode(&desc); 71 assm.GetCode(&desc);
72 Object* code = HEAP->CreateCode( 72 Object* code = HEAP->CreateCode(
73 desc, 73 desc,
74 Code::ComputeFlags(Code::STUB), 74 Code::ComputeFlags(Code::STUB),
75 Handle<Object>(HEAP->undefined_value()))->ToObjectChecked(); 75 Handle<Object>(HEAP->undefined_value()))->ToObjectChecked();
76 CHECK(code->IsCode()); 76 CHECK(code->IsCode());
77 #ifdef OBJECT_PRINT 77 #ifdef OBJECT_PRINT
78 Code::cast(code)->Print(); 78 Code::cast(code)->Print();
79 #endif 79 #endif
80 F2 f = FUNCTION_CAST<F2>(Code::cast(code)->entry()); 80 F2 f = FUNCTION_CAST<F2>(Code::cast(code)->entry());
81 int res = f(3, 4); 81 int res = f(3, 4);
82 ::printf("f() = %d\n", res); 82 ::printf("f() = %d\n", res);
83 CHECK_EQ(7, res); 83 CHECK_EQ(7, res);
84 } 84 }
85 85
86 86
87 TEST(AssemblerIa321) { 87 TEST(AssemblerIa321) {
88 InitializeVM(); 88 InitializeVM();
89 v8::HandleScope scope; 89 v8::HandleScope scope;
90 90
91 v8::internal::byte buffer[256]; 91 v8::internal::byte buffer[256];
92 Assembler assm(buffer, sizeof buffer); 92 Assembler assm(Isolate::Current(), buffer, sizeof buffer);
93 Label L, C; 93 Label L, C;
94 94
95 __ mov(edx, Operand(esp, 4)); 95 __ mov(edx, Operand(esp, 4));
96 __ xor_(eax, Operand(eax)); // clear eax 96 __ xor_(eax, Operand(eax)); // clear eax
97 __ jmp(&C); 97 __ jmp(&C);
98 98
99 __ bind(&L); 99 __ bind(&L);
100 __ add(eax, Operand(edx)); 100 __ add(eax, Operand(edx));
101 __ sub(Operand(edx), Immediate(1)); 101 __ sub(Operand(edx), Immediate(1));
102 102
(...skipping 17 matching lines...) Expand all
120 ::printf("f() = %d\n", res); 120 ::printf("f() = %d\n", res);
121 CHECK_EQ(5050, res); 121 CHECK_EQ(5050, res);
122 } 122 }
123 123
124 124
125 TEST(AssemblerIa322) { 125 TEST(AssemblerIa322) {
126 InitializeVM(); 126 InitializeVM();
127 v8::HandleScope scope; 127 v8::HandleScope scope;
128 128
129 v8::internal::byte buffer[256]; 129 v8::internal::byte buffer[256];
130 Assembler assm(buffer, sizeof buffer); 130 Assembler assm(Isolate::Current(), buffer, sizeof buffer);
131 Label L, C; 131 Label L, C;
132 132
133 __ mov(edx, Operand(esp, 4)); 133 __ mov(edx, Operand(esp, 4));
134 __ mov(eax, 1); 134 __ mov(eax, 1);
135 __ jmp(&C); 135 __ jmp(&C);
136 136
137 __ bind(&L); 137 __ bind(&L);
138 __ imul(eax, Operand(edx)); 138 __ imul(eax, Operand(edx));
139 __ sub(Operand(edx), Immediate(1)); 139 __ sub(Operand(edx), Immediate(1));
140 140
(...skipping 19 matching lines...) Expand all
160 F1 f = FUNCTION_CAST<F1>(Code::cast(code)->entry()); 160 F1 f = FUNCTION_CAST<F1>(Code::cast(code)->entry());
161 int res = f(10); 161 int res = f(10);
162 ::printf("f() = %d\n", res); 162 ::printf("f() = %d\n", res);
163 CHECK_EQ(3628800, res); 163 CHECK_EQ(3628800, res);
164 } 164 }
165 165
166 166
167 typedef int (*F3)(float x); 167 typedef int (*F3)(float x);
168 168
169 TEST(AssemblerIa323) { 169 TEST(AssemblerIa323) {
170 if (!Isolate::Current()->cpu_features()->IsSupported(SSE2)) return; 170 if (!CpuFeatures::IsSupported(SSE2)) return;
171 171
172 InitializeVM(); 172 InitializeVM();
173 v8::HandleScope scope; 173 v8::HandleScope scope;
174 174
175 v8::internal::byte buffer[256]; 175 v8::internal::byte buffer[256];
176 Assembler assm(buffer, sizeof buffer); 176 Assembler assm(Isolate::Current(), buffer, sizeof buffer);
177 177
178 CHECK(Isolate::Current()->cpu_features()->IsSupported(SSE2)); 178 CHECK(CpuFeatures::IsSupported(SSE2));
179 { CpuFeatures::Scope fscope(SSE2); 179 { CpuFeatures::Scope fscope(SSE2);
180 __ cvttss2si(eax, Operand(esp, 4)); 180 __ cvttss2si(eax, Operand(esp, 4));
181 __ ret(0); 181 __ ret(0);
182 } 182 }
183 183
184 CodeDesc desc; 184 CodeDesc desc;
185 assm.GetCode(&desc); 185 assm.GetCode(&desc);
186 Code* code = Code::cast(HEAP->CreateCode( 186 Code* code = Code::cast(HEAP->CreateCode(
187 desc, 187 desc,
188 Code::ComputeFlags(Code::STUB), 188 Code::ComputeFlags(Code::STUB),
189 Handle<Object>(HEAP->undefined_value()))->ToObjectChecked()); 189 Handle<Object>(HEAP->undefined_value()))->ToObjectChecked());
190 // don't print the code - our disassembler can't handle cvttss2si 190 // don't print the code - our disassembler can't handle cvttss2si
191 // instead print bytes 191 // instead print bytes
192 Disassembler::Dump(stdout, 192 Disassembler::Dump(stdout,
193 code->instruction_start(), 193 code->instruction_start(),
194 code->instruction_start() + code->instruction_size()); 194 code->instruction_start() + code->instruction_size());
195 F3 f = FUNCTION_CAST<F3>(code->entry()); 195 F3 f = FUNCTION_CAST<F3>(code->entry());
196 int res = f(static_cast<float>(-3.1415)); 196 int res = f(static_cast<float>(-3.1415));
197 ::printf("f() = %d\n", res); 197 ::printf("f() = %d\n", res);
198 CHECK_EQ(-3, res); 198 CHECK_EQ(-3, res);
199 } 199 }
200 200
201 201
202 typedef int (*F4)(double x); 202 typedef int (*F4)(double x);
203 203
204 TEST(AssemblerIa324) { 204 TEST(AssemblerIa324) {
205 if (!Isolate::Current()->cpu_features()->IsSupported(SSE2)) return; 205 if (!CpuFeatures::IsSupported(SSE2)) return;
206 206
207 InitializeVM(); 207 InitializeVM();
208 v8::HandleScope scope; 208 v8::HandleScope scope;
209 209
210 v8::internal::byte buffer[256]; 210 v8::internal::byte buffer[256];
211 Assembler assm(buffer, sizeof buffer); 211 Assembler assm(Isolate::Current(), buffer, sizeof buffer);
212 212
213 CHECK(Isolate::Current()->cpu_features()->IsSupported(SSE2)); 213 CHECK(CpuFeatures::IsSupported(SSE2));
214 CpuFeatures::Scope fscope(SSE2); 214 CpuFeatures::Scope fscope(SSE2);
215 __ cvttsd2si(eax, Operand(esp, 4)); 215 __ cvttsd2si(eax, Operand(esp, 4));
216 __ ret(0); 216 __ ret(0);
217 217
218 CodeDesc desc; 218 CodeDesc desc;
219 assm.GetCode(&desc); 219 assm.GetCode(&desc);
220 Code* code = Code::cast(HEAP->CreateCode( 220 Code* code = Code::cast(HEAP->CreateCode(
221 desc, 221 desc,
222 Code::ComputeFlags(Code::STUB), 222 Code::ComputeFlags(Code::STUB),
223 Handle<Object>(HEAP->undefined_value()))->ToObjectChecked()); 223 Handle<Object>(HEAP->undefined_value()))->ToObjectChecked());
224 // don't print the code - our disassembler can't handle cvttsd2si 224 // don't print the code - our disassembler can't handle cvttsd2si
225 // instead print bytes 225 // instead print bytes
226 Disassembler::Dump(stdout, 226 Disassembler::Dump(stdout,
227 code->instruction_start(), 227 code->instruction_start(),
228 code->instruction_start() + code->instruction_size()); 228 code->instruction_start() + code->instruction_size());
229 F4 f = FUNCTION_CAST<F4>(code->entry()); 229 F4 f = FUNCTION_CAST<F4>(code->entry());
230 int res = f(2.718281828); 230 int res = f(2.718281828);
231 ::printf("f() = %d\n", res); 231 ::printf("f() = %d\n", res);
232 CHECK_EQ(2, res); 232 CHECK_EQ(2, res);
233 } 233 }
234 234
235 235
236 static int baz = 42; 236 static int baz = 42;
237 TEST(AssemblerIa325) { 237 TEST(AssemblerIa325) {
238 InitializeVM(); 238 InitializeVM();
239 v8::HandleScope scope; 239 v8::HandleScope scope;
240 240
241 v8::internal::byte buffer[256]; 241 v8::internal::byte buffer[256];
242 Assembler assm(buffer, sizeof buffer); 242 Assembler assm(Isolate::Current(), buffer, sizeof buffer);
243 243
244 __ mov(eax, Operand(reinterpret_cast<intptr_t>(&baz), RelocInfo::NONE)); 244 __ mov(eax, Operand(reinterpret_cast<intptr_t>(&baz), RelocInfo::NONE));
245 __ ret(0); 245 __ ret(0);
246 246
247 CodeDesc desc; 247 CodeDesc desc;
248 assm.GetCode(&desc); 248 assm.GetCode(&desc);
249 Code* code = Code::cast(HEAP->CreateCode( 249 Code* code = Code::cast(HEAP->CreateCode(
250 desc, 250 desc,
251 Code::ComputeFlags(Code::STUB), 251 Code::ComputeFlags(Code::STUB),
252 Handle<Object>(HEAP->undefined_value()))->ToObjectChecked()); 252 Handle<Object>(HEAP->undefined_value()))->ToObjectChecked());
253 F0 f = FUNCTION_CAST<F0>(code->entry()); 253 F0 f = FUNCTION_CAST<F0>(code->entry());
254 int res = f(); 254 int res = f();
255 CHECK_EQ(42, res); 255 CHECK_EQ(42, res);
256 } 256 }
257 257
258 258
259 typedef double (*F5)(double x, double y); 259 typedef double (*F5)(double x, double y);
260 260
261 TEST(AssemblerIa326) { 261 TEST(AssemblerIa326) {
262 if (!Isolate::Current()->cpu_features()->IsSupported(SSE2)) return; 262 if (!CpuFeatures::IsSupported(SSE2)) return;
263 263
264 InitializeVM(); 264 InitializeVM();
265 v8::HandleScope scope; 265 v8::HandleScope scope;
266 CHECK(Isolate::Current()->cpu_features()->IsSupported(SSE2)); 266 CHECK(CpuFeatures::IsSupported(SSE2));
267 CpuFeatures::Scope fscope(SSE2); 267 CpuFeatures::Scope fscope(SSE2);
268 v8::internal::byte buffer[256]; 268 v8::internal::byte buffer[256];
269 Assembler assm(buffer, sizeof buffer); 269 Assembler assm(Isolate::Current(), buffer, sizeof buffer);
270 270
271 __ movdbl(xmm0, Operand(esp, 1 * kPointerSize)); 271 __ movdbl(xmm0, Operand(esp, 1 * kPointerSize));
272 __ movdbl(xmm1, Operand(esp, 3 * kPointerSize)); 272 __ movdbl(xmm1, Operand(esp, 3 * kPointerSize));
273 __ addsd(xmm0, xmm1); 273 __ addsd(xmm0, xmm1);
274 __ mulsd(xmm0, xmm1); 274 __ mulsd(xmm0, xmm1);
275 __ subsd(xmm0, xmm1); 275 __ subsd(xmm0, xmm1);
276 __ divsd(xmm0, xmm1); 276 __ divsd(xmm0, xmm1);
277 // Copy xmm0 to st(0) using eight bytes of stack. 277 // Copy xmm0 to st(0) using eight bytes of stack.
278 __ sub(Operand(esp), Immediate(8)); 278 __ sub(Operand(esp), Immediate(8));
279 __ movdbl(Operand(esp, 0), xmm0); 279 __ movdbl(Operand(esp, 0), xmm0);
(...skipping 18 matching lines...) Expand all
298 F5 f = FUNCTION_CAST<F5>(code->entry()); 298 F5 f = FUNCTION_CAST<F5>(code->entry());
299 double res = f(2.2, 1.1); 299 double res = f(2.2, 1.1);
300 ::printf("f() = %f\n", res); 300 ::printf("f() = %f\n", res);
301 CHECK(2.29 < res && res < 2.31); 301 CHECK(2.29 < res && res < 2.31);
302 } 302 }
303 303
304 304
305 typedef double (*F6)(int x); 305 typedef double (*F6)(int x);
306 306
307 TEST(AssemblerIa328) { 307 TEST(AssemblerIa328) {
308 if (!Isolate::Current()->cpu_features()->IsSupported(SSE2)) return; 308 if (!CpuFeatures::IsSupported(SSE2)) return;
309 309
310 InitializeVM(); 310 InitializeVM();
311 v8::HandleScope scope; 311 v8::HandleScope scope;
312 CHECK(Isolate::Current()->cpu_features()->IsSupported(SSE2)); 312 CHECK(CpuFeatures::IsSupported(SSE2));
313 CpuFeatures::Scope fscope(SSE2); 313 CpuFeatures::Scope fscope(SSE2);
314 v8::internal::byte buffer[256]; 314 v8::internal::byte buffer[256];
315 Assembler assm(buffer, sizeof buffer); 315 Assembler assm(Isolate::Current(), buffer, sizeof buffer);
316 __ mov(eax, Operand(esp, 4)); 316 __ mov(eax, Operand(esp, 4));
317 __ cvtsi2sd(xmm0, Operand(eax)); 317 __ cvtsi2sd(xmm0, Operand(eax));
318 // Copy xmm0 to st(0) using eight bytes of stack. 318 // Copy xmm0 to st(0) using eight bytes of stack.
319 __ sub(Operand(esp), Immediate(8)); 319 __ sub(Operand(esp), Immediate(8));
320 __ movdbl(Operand(esp, 0), xmm0); 320 __ movdbl(Operand(esp, 0), xmm0);
321 __ fld_d(Operand(esp, 0)); 321 __ fld_d(Operand(esp, 0));
322 __ add(Operand(esp), Immediate(8)); 322 __ add(Operand(esp), Immediate(8));
323 __ ret(0); 323 __ ret(0);
324 CodeDesc desc; 324 CodeDesc desc;
325 assm.GetCode(&desc); 325 assm.GetCode(&desc);
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
388 #endif 388 #endif
389 389
390 F7 f = FUNCTION_CAST<F7>(Code::cast(code)->entry()); 390 F7 f = FUNCTION_CAST<F7>(Code::cast(code)->entry());
391 CHECK_EQ(kLess, f(1.1, 2.2)); 391 CHECK_EQ(kLess, f(1.1, 2.2));
392 CHECK_EQ(kEqual, f(2.2, 2.2)); 392 CHECK_EQ(kEqual, f(2.2, 2.2));
393 CHECK_EQ(kGreater, f(3.3, 2.2)); 393 CHECK_EQ(kGreater, f(3.3, 2.2));
394 CHECK_EQ(kNaN, f(OS::nan_value(), 1.1)); 394 CHECK_EQ(kNaN, f(OS::nan_value(), 1.1));
395 } 395 }
396 396
397 #undef __ 397 #undef __
OLDNEW
« src/v8.cc ('K') | « src/x64/cpu-x64.cc ('k') | test/cctest/test-disasm-ia32.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698