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