OLD | NEW |
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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 | 62 |
63 v8::internal::byte buffer[256]; | 63 v8::internal::byte buffer[256]; |
64 Assembler assm(buffer, sizeof buffer); | 64 Assembler assm(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(desc, NULL, Code::ComputeFlags(Code::STUB)); | 72 Object* code = Heap::CreateCode(desc, |
| 73 NULL, |
| 74 Code::ComputeFlags(Code::STUB), |
| 75 Handle<Object>(Heap::undefined_value())); |
73 CHECK(code->IsCode()); | 76 CHECK(code->IsCode()); |
74 #ifdef DEBUG | 77 #ifdef DEBUG |
75 Code::cast(code)->Print(); | 78 Code::cast(code)->Print(); |
76 #endif | 79 #endif |
77 F2 f = FUNCTION_CAST<F2>(Code::cast(code)->entry()); | 80 F2 f = FUNCTION_CAST<F2>(Code::cast(code)->entry()); |
78 int res = f(3, 4); | 81 int res = f(3, 4); |
79 ::printf("f() = %d\n", res); | 82 ::printf("f() = %d\n", res); |
80 CHECK_EQ(7, res); | 83 CHECK_EQ(7, res); |
81 } | 84 } |
82 | 85 |
(...skipping 14 matching lines...) Expand all Loading... |
97 __ add(eax, Operand(edx)); | 100 __ add(eax, Operand(edx)); |
98 __ sub(Operand(edx), Immediate(1)); | 101 __ sub(Operand(edx), Immediate(1)); |
99 | 102 |
100 __ bind(&C); | 103 __ bind(&C); |
101 __ test(edx, Operand(edx)); | 104 __ test(edx, Operand(edx)); |
102 __ j(not_zero, &L, taken); | 105 __ j(not_zero, &L, taken); |
103 __ ret(0); | 106 __ ret(0); |
104 | 107 |
105 CodeDesc desc; | 108 CodeDesc desc; |
106 assm.GetCode(&desc); | 109 assm.GetCode(&desc); |
107 Object* code = Heap::CreateCode(desc, NULL, Code::ComputeFlags(Code::STUB)); | 110 Object* code = Heap::CreateCode(desc, |
| 111 NULL, |
| 112 Code::ComputeFlags(Code::STUB), |
| 113 Handle<Object>(Heap::undefined_value())); |
108 CHECK(code->IsCode()); | 114 CHECK(code->IsCode()); |
109 #ifdef DEBUG | 115 #ifdef DEBUG |
110 Code::cast(code)->Print(); | 116 Code::cast(code)->Print(); |
111 #endif | 117 #endif |
112 F1 f = FUNCTION_CAST<F1>(Code::cast(code)->entry()); | 118 F1 f = FUNCTION_CAST<F1>(Code::cast(code)->entry()); |
113 int res = f(100); | 119 int res = f(100); |
114 ::printf("f() = %d\n", res); | 120 ::printf("f() = %d\n", res); |
115 CHECK_EQ(5050, res); | 121 CHECK_EQ(5050, res); |
116 } | 122 } |
117 | 123 |
(...skipping 18 matching lines...) Expand all Loading... |
136 __ test(edx, Operand(edx)); | 142 __ test(edx, Operand(edx)); |
137 __ j(not_zero, &L, taken); | 143 __ j(not_zero, &L, taken); |
138 __ ret(0); | 144 __ ret(0); |
139 | 145 |
140 // some relocated stuff here, not executed | 146 // some relocated stuff here, not executed |
141 __ mov(eax, Factory::true_value()); | 147 __ mov(eax, Factory::true_value()); |
142 __ jmp(NULL, RelocInfo::RUNTIME_ENTRY); | 148 __ jmp(NULL, RelocInfo::RUNTIME_ENTRY); |
143 | 149 |
144 CodeDesc desc; | 150 CodeDesc desc; |
145 assm.GetCode(&desc); | 151 assm.GetCode(&desc); |
146 Object* code = Heap::CreateCode(desc, NULL, Code::ComputeFlags(Code::STUB)); | 152 Object* code = Heap::CreateCode(desc, |
| 153 NULL, |
| 154 Code::ComputeFlags(Code::STUB), |
| 155 Handle<Object>(Heap::undefined_value())); |
147 CHECK(code->IsCode()); | 156 CHECK(code->IsCode()); |
148 #ifdef DEBUG | 157 #ifdef DEBUG |
149 Code::cast(code)->Print(); | 158 Code::cast(code)->Print(); |
150 #endif | 159 #endif |
151 F1 f = FUNCTION_CAST<F1>(Code::cast(code)->entry()); | 160 F1 f = FUNCTION_CAST<F1>(Code::cast(code)->entry()); |
152 int res = f(10); | 161 int res = f(10); |
153 ::printf("f() = %d\n", res); | 162 ::printf("f() = %d\n", res); |
154 CHECK_EQ(3628800, res); | 163 CHECK_EQ(3628800, res); |
155 } | 164 } |
156 | 165 |
(...skipping 11 matching lines...) Expand all Loading... |
168 CpuFeatures::Probe(); | 177 CpuFeatures::Probe(); |
169 CHECK(CpuFeatures::IsSupported(CpuFeatures::SSE2)); | 178 CHECK(CpuFeatures::IsSupported(CpuFeatures::SSE2)); |
170 { CpuFeatures::Scope fscope(CpuFeatures::SSE2); | 179 { CpuFeatures::Scope fscope(CpuFeatures::SSE2); |
171 __ cvttss2si(eax, Operand(esp, 4)); | 180 __ cvttss2si(eax, Operand(esp, 4)); |
172 __ ret(0); | 181 __ ret(0); |
173 } | 182 } |
174 | 183 |
175 CodeDesc desc; | 184 CodeDesc desc; |
176 assm.GetCode(&desc); | 185 assm.GetCode(&desc); |
177 Code* code = | 186 Code* code = |
178 Code::cast(Heap::CreateCode(desc, NULL, Code::ComputeFlags(Code::STUB))); | 187 Code::cast(Heap::CreateCode(desc, |
| 188 NULL, |
| 189 Code::ComputeFlags(Code::STUB), |
| 190 Handle<Object>(Heap::undefined_value()))); |
179 // don't print the code - our disassembler can't handle cvttss2si | 191 // don't print the code - our disassembler can't handle cvttss2si |
180 // instead print bytes | 192 // instead print bytes |
181 Disassembler::Dump(stdout, | 193 Disassembler::Dump(stdout, |
182 code->instruction_start(), | 194 code->instruction_start(), |
183 code->instruction_start() + code->instruction_size()); | 195 code->instruction_start() + code->instruction_size()); |
184 F3 f = FUNCTION_CAST<F3>(code->entry()); | 196 F3 f = FUNCTION_CAST<F3>(code->entry()); |
185 int res = f(static_cast<float>(-3.1415)); | 197 int res = f(static_cast<float>(-3.1415)); |
186 ::printf("f() = %d\n", res); | 198 ::printf("f() = %d\n", res); |
187 CHECK_EQ(-3, res); | 199 CHECK_EQ(-3, res); |
188 } | 200 } |
(...skipping 11 matching lines...) Expand all Loading... |
200 Serializer::disable(); // Needed for Probe when running without snapshot. | 212 Serializer::disable(); // Needed for Probe when running without snapshot. |
201 CpuFeatures::Probe(); | 213 CpuFeatures::Probe(); |
202 CHECK(CpuFeatures::IsSupported(CpuFeatures::SSE2)); | 214 CHECK(CpuFeatures::IsSupported(CpuFeatures::SSE2)); |
203 CpuFeatures::Scope fscope(CpuFeatures::SSE2); | 215 CpuFeatures::Scope fscope(CpuFeatures::SSE2); |
204 __ cvttsd2si(eax, Operand(esp, 4)); | 216 __ cvttsd2si(eax, Operand(esp, 4)); |
205 __ ret(0); | 217 __ ret(0); |
206 | 218 |
207 CodeDesc desc; | 219 CodeDesc desc; |
208 assm.GetCode(&desc); | 220 assm.GetCode(&desc); |
209 Code* code = | 221 Code* code = |
210 Code::cast(Heap::CreateCode(desc, NULL, Code::ComputeFlags(Code::STUB))); | 222 Code::cast(Heap::CreateCode(desc, |
| 223 NULL, |
| 224 Code::ComputeFlags(Code::STUB), |
| 225 Handle<Object>(Heap::undefined_value()))); |
211 // don't print the code - our disassembler can't handle cvttsd2si | 226 // don't print the code - our disassembler can't handle cvttsd2si |
212 // instead print bytes | 227 // instead print bytes |
213 Disassembler::Dump(stdout, | 228 Disassembler::Dump(stdout, |
214 code->instruction_start(), | 229 code->instruction_start(), |
215 code->instruction_start() + code->instruction_size()); | 230 code->instruction_start() + code->instruction_size()); |
216 F4 f = FUNCTION_CAST<F4>(code->entry()); | 231 F4 f = FUNCTION_CAST<F4>(code->entry()); |
217 int res = f(2.718281828); | 232 int res = f(2.718281828); |
218 ::printf("f() = %d\n", res); | 233 ::printf("f() = %d\n", res); |
219 CHECK_EQ(2, res); | 234 CHECK_EQ(2, res); |
220 } | 235 } |
221 | 236 |
222 | 237 |
223 static int baz = 42; | 238 static int baz = 42; |
224 TEST(AssemblerIa325) { | 239 TEST(AssemblerIa325) { |
225 InitializeVM(); | 240 InitializeVM(); |
226 v8::HandleScope scope; | 241 v8::HandleScope scope; |
227 | 242 |
228 v8::internal::byte buffer[256]; | 243 v8::internal::byte buffer[256]; |
229 Assembler assm(buffer, sizeof buffer); | 244 Assembler assm(buffer, sizeof buffer); |
230 | 245 |
231 __ mov(eax, Operand(reinterpret_cast<intptr_t>(&baz), RelocInfo::NONE)); | 246 __ mov(eax, Operand(reinterpret_cast<intptr_t>(&baz), RelocInfo::NONE)); |
232 __ ret(0); | 247 __ ret(0); |
233 | 248 |
234 CodeDesc desc; | 249 CodeDesc desc; |
235 assm.GetCode(&desc); | 250 assm.GetCode(&desc); |
236 Code* code = | 251 Code* code = |
237 Code::cast(Heap::CreateCode(desc, NULL, Code::ComputeFlags(Code::STUB))); | 252 Code::cast(Heap::CreateCode(desc, |
| 253 NULL, |
| 254 Code::ComputeFlags(Code::STUB), |
| 255 Handle<Object>(Heap::undefined_value()))); |
238 F0 f = FUNCTION_CAST<F0>(code->entry()); | 256 F0 f = FUNCTION_CAST<F0>(code->entry()); |
239 int res = f(); | 257 int res = f(); |
240 CHECK_EQ(42, res); | 258 CHECK_EQ(42, res); |
241 } | 259 } |
242 | 260 |
243 | 261 |
244 typedef double (*F5)(double x, double y); | 262 typedef double (*F5)(double x, double y); |
245 | 263 |
246 TEST(AssemblerIa326) { | 264 TEST(AssemblerIa326) { |
247 InitializeVM(); | 265 InitializeVM(); |
(...skipping 14 matching lines...) Expand all Loading... |
262 // Copy xmm0 to st(0) using eight bytes of stack. | 280 // Copy xmm0 to st(0) using eight bytes of stack. |
263 __ sub(Operand(esp), Immediate(8)); | 281 __ sub(Operand(esp), Immediate(8)); |
264 __ movdbl(Operand(esp, 0), xmm0); | 282 __ movdbl(Operand(esp, 0), xmm0); |
265 __ fld_d(Operand(esp, 0)); | 283 __ fld_d(Operand(esp, 0)); |
266 __ add(Operand(esp), Immediate(8)); | 284 __ add(Operand(esp), Immediate(8)); |
267 __ ret(0); | 285 __ ret(0); |
268 | 286 |
269 CodeDesc desc; | 287 CodeDesc desc; |
270 assm.GetCode(&desc); | 288 assm.GetCode(&desc); |
271 Code* code = | 289 Code* code = |
272 Code::cast(Heap::CreateCode(desc, NULL, Code::ComputeFlags(Code::STUB))); | 290 Code::cast(Heap::CreateCode(desc, |
| 291 NULL, |
| 292 Code::ComputeFlags(Code::STUB), |
| 293 Handle<Object>(Heap::undefined_value()))); |
273 #ifdef DEBUG | 294 #ifdef DEBUG |
274 ::printf("\n---\n"); | 295 ::printf("\n---\n"); |
275 // don't print the code - our disassembler can't handle SSE instructions | 296 // don't print the code - our disassembler can't handle SSE instructions |
276 // instead print bytes | 297 // instead print bytes |
277 Disassembler::Dump(stdout, | 298 Disassembler::Dump(stdout, |
278 code->instruction_start(), | 299 code->instruction_start(), |
279 code->instruction_start() + code->instruction_size()); | 300 code->instruction_start() + code->instruction_size()); |
280 #endif | 301 #endif |
281 F5 f = FUNCTION_CAST<F5>(code->entry()); | 302 F5 f = FUNCTION_CAST<F5>(code->entry()); |
282 double res = f(2.2, 1.1); | 303 double res = f(2.2, 1.1); |
(...skipping 17 matching lines...) Expand all Loading... |
300 __ cvtsi2sd(xmm0, Operand(eax)); | 321 __ cvtsi2sd(xmm0, Operand(eax)); |
301 // Copy xmm0 to st(0) using eight bytes of stack. | 322 // Copy xmm0 to st(0) using eight bytes of stack. |
302 __ sub(Operand(esp), Immediate(8)); | 323 __ sub(Operand(esp), Immediate(8)); |
303 __ movdbl(Operand(esp, 0), xmm0); | 324 __ movdbl(Operand(esp, 0), xmm0); |
304 __ fld_d(Operand(esp, 0)); | 325 __ fld_d(Operand(esp, 0)); |
305 __ add(Operand(esp), Immediate(8)); | 326 __ add(Operand(esp), Immediate(8)); |
306 __ ret(0); | 327 __ ret(0); |
307 CodeDesc desc; | 328 CodeDesc desc; |
308 assm.GetCode(&desc); | 329 assm.GetCode(&desc); |
309 Code* code = | 330 Code* code = |
310 Code::cast(Heap::CreateCode(desc, NULL, Code::ComputeFlags(Code::STUB))); | 331 Code::cast(Heap::CreateCode(desc, |
| 332 NULL, |
| 333 Code::ComputeFlags(Code::STUB), |
| 334 Handle<Object>(Heap::undefined_value()))); |
311 CHECK(code->IsCode()); | 335 CHECK(code->IsCode()); |
312 #ifdef DEBUG | 336 #ifdef DEBUG |
313 Code::cast(code)->Print(); | 337 Code::cast(code)->Print(); |
314 #endif | 338 #endif |
315 F6 f = FUNCTION_CAST<F6>(Code::cast(code)->entry()); | 339 F6 f = FUNCTION_CAST<F6>(Code::cast(code)->entry()); |
316 double res = f(12); | 340 double res = f(12); |
317 | 341 |
318 ::printf("f() = %f\n", res); | 342 ::printf("f() = %f\n", res); |
319 CHECK(11.99 < res && res < 12.001); | 343 CHECK(11.99 < res && res < 12.001); |
320 } | 344 } |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
353 __ ret(0); | 377 __ ret(0); |
354 | 378 |
355 __ bind(&nan_l); | 379 __ bind(&nan_l); |
356 __ mov(eax, kNaN); | 380 __ mov(eax, kNaN); |
357 __ ret(0); | 381 __ ret(0); |
358 | 382 |
359 | 383 |
360 CodeDesc desc; | 384 CodeDesc desc; |
361 assm.GetCode(&desc); | 385 assm.GetCode(&desc); |
362 Code* code = | 386 Code* code = |
363 Code::cast(Heap::CreateCode(desc, NULL, Code::ComputeFlags(Code::STUB))); | 387 Code::cast(Heap::CreateCode(desc, |
| 388 NULL, |
| 389 Code::ComputeFlags(Code::STUB), |
| 390 Handle<Object>(Heap::undefined_value()))); |
364 CHECK(code->IsCode()); | 391 CHECK(code->IsCode()); |
365 #ifdef DEBUG | 392 #ifdef DEBUG |
366 Code::cast(code)->Print(); | 393 Code::cast(code)->Print(); |
367 #endif | 394 #endif |
368 | 395 |
369 F7 f = FUNCTION_CAST<F7>(Code::cast(code)->entry()); | 396 F7 f = FUNCTION_CAST<F7>(Code::cast(code)->entry()); |
370 CHECK_EQ(kLess, f(1.1, 2.2)); | 397 CHECK_EQ(kLess, f(1.1, 2.2)); |
371 CHECK_EQ(kEqual, f(2.2, 2.2)); | 398 CHECK_EQ(kEqual, f(2.2, 2.2)); |
372 CHECK_EQ(kGreater, f(3.3, 2.2)); | 399 CHECK_EQ(kGreater, f(3.3, 2.2)); |
373 CHECK_EQ(kNaN, f(OS::nan_value(), 1.1)); | 400 CHECK_EQ(kNaN, f(OS::nan_value(), 1.1)); |
374 } | 401 } |
375 | 402 |
376 #undef __ | 403 #undef __ |
OLD | NEW |