| 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 |
| 157 | 166 |
| 158 typedef int (*F3)(float x); | 167 typedef int (*F3)(float x); |
| 159 | 168 |
| 160 TEST(AssemblerIa323) { | 169 TEST(AssemblerIa323) { |
| 161 InitializeVM(); | 170 InitializeVM(); |
| 162 v8::HandleScope scope; | 171 v8::HandleScope scope; |
| 163 | 172 |
| 164 v8::internal::byte buffer[256]; | 173 v8::internal::byte buffer[256]; |
| 165 Assembler assm(buffer, sizeof buffer); | 174 Assembler assm(buffer, sizeof buffer); |
| 166 | 175 |
| 167 Serializer::disable(); // Needed for Probe when running without snapshot. | |
| 168 CpuFeatures::Probe(); | |
| 169 CHECK(CpuFeatures::IsSupported(CpuFeatures::SSE2)); | 176 CHECK(CpuFeatures::IsSupported(CpuFeatures::SSE2)); |
| 170 { CpuFeatures::Scope fscope(CpuFeatures::SSE2); | 177 { CpuFeatures::Scope fscope(CpuFeatures::SSE2); |
| 171 __ cvttss2si(eax, Operand(esp, 4)); | 178 __ cvttss2si(eax, Operand(esp, 4)); |
| 172 __ ret(0); | 179 __ ret(0); |
| 173 } | 180 } |
| 174 | 181 |
| 175 CodeDesc desc; | 182 CodeDesc desc; |
| 176 assm.GetCode(&desc); | 183 assm.GetCode(&desc); |
| 177 Code* code = | 184 Code* code = |
| 178 Code::cast(Heap::CreateCode(desc, NULL, Code::ComputeFlags(Code::STUB))); | 185 Code::cast(Heap::CreateCode(desc, |
| 186 NULL, |
| 187 Code::ComputeFlags(Code::STUB), |
| 188 Handle<Object>(Heap::undefined_value()))); |
| 179 // don't print the code - our disassembler can't handle cvttss2si | 189 // don't print the code - our disassembler can't handle cvttss2si |
| 180 // instead print bytes | 190 // instead print bytes |
| 181 Disassembler::Dump(stdout, | 191 Disassembler::Dump(stdout, |
| 182 code->instruction_start(), | 192 code->instruction_start(), |
| 183 code->instruction_start() + code->instruction_size()); | 193 code->instruction_start() + code->instruction_size()); |
| 184 F3 f = FUNCTION_CAST<F3>(code->entry()); | 194 F3 f = FUNCTION_CAST<F3>(code->entry()); |
| 185 int res = f(static_cast<float>(-3.1415)); | 195 int res = f(static_cast<float>(-3.1415)); |
| 186 ::printf("f() = %d\n", res); | 196 ::printf("f() = %d\n", res); |
| 187 CHECK_EQ(-3, res); | 197 CHECK_EQ(-3, res); |
| 188 } | 198 } |
| 189 | 199 |
| 190 | 200 |
| 191 typedef int (*F4)(double x); | 201 typedef int (*F4)(double x); |
| 192 | 202 |
| 193 TEST(AssemblerIa324) { | 203 TEST(AssemblerIa324) { |
| 194 InitializeVM(); | 204 InitializeVM(); |
| 195 v8::HandleScope scope; | 205 v8::HandleScope scope; |
| 196 | 206 |
| 197 v8::internal::byte buffer[256]; | 207 v8::internal::byte buffer[256]; |
| 198 Assembler assm(buffer, sizeof buffer); | 208 Assembler assm(buffer, sizeof buffer); |
| 199 | 209 |
| 200 Serializer::disable(); // Needed for Probe when running without snapshot. | |
| 201 CpuFeatures::Probe(); | |
| 202 CHECK(CpuFeatures::IsSupported(CpuFeatures::SSE2)); | 210 CHECK(CpuFeatures::IsSupported(CpuFeatures::SSE2)); |
| 203 CpuFeatures::Scope fscope(CpuFeatures::SSE2); | 211 CpuFeatures::Scope fscope(CpuFeatures::SSE2); |
| 204 __ cvttsd2si(eax, Operand(esp, 4)); | 212 __ cvttsd2si(eax, Operand(esp, 4)); |
| 205 __ ret(0); | 213 __ ret(0); |
| 206 | 214 |
| 207 CodeDesc desc; | 215 CodeDesc desc; |
| 208 assm.GetCode(&desc); | 216 assm.GetCode(&desc); |
| 209 Code* code = | 217 Code* code = |
| 210 Code::cast(Heap::CreateCode(desc, NULL, Code::ComputeFlags(Code::STUB))); | 218 Code::cast(Heap::CreateCode(desc, |
| 219 NULL, |
| 220 Code::ComputeFlags(Code::STUB), |
| 221 Handle<Object>(Heap::undefined_value()))); |
| 211 // don't print the code - our disassembler can't handle cvttsd2si | 222 // don't print the code - our disassembler can't handle cvttsd2si |
| 212 // instead print bytes | 223 // instead print bytes |
| 213 Disassembler::Dump(stdout, | 224 Disassembler::Dump(stdout, |
| 214 code->instruction_start(), | 225 code->instruction_start(), |
| 215 code->instruction_start() + code->instruction_size()); | 226 code->instruction_start() + code->instruction_size()); |
| 216 F4 f = FUNCTION_CAST<F4>(code->entry()); | 227 F4 f = FUNCTION_CAST<F4>(code->entry()); |
| 217 int res = f(2.718281828); | 228 int res = f(2.718281828); |
| 218 ::printf("f() = %d\n", res); | 229 ::printf("f() = %d\n", res); |
| 219 CHECK_EQ(2, res); | 230 CHECK_EQ(2, res); |
| 220 } | 231 } |
| 221 | 232 |
| 222 | 233 |
| 223 static int baz = 42; | 234 static int baz = 42; |
| 224 TEST(AssemblerIa325) { | 235 TEST(AssemblerIa325) { |
| 225 InitializeVM(); | 236 InitializeVM(); |
| 226 v8::HandleScope scope; | 237 v8::HandleScope scope; |
| 227 | 238 |
| 228 v8::internal::byte buffer[256]; | 239 v8::internal::byte buffer[256]; |
| 229 Assembler assm(buffer, sizeof buffer); | 240 Assembler assm(buffer, sizeof buffer); |
| 230 | 241 |
| 231 __ mov(eax, Operand(reinterpret_cast<intptr_t>(&baz), RelocInfo::NONE)); | 242 __ mov(eax, Operand(reinterpret_cast<intptr_t>(&baz), RelocInfo::NONE)); |
| 232 __ ret(0); | 243 __ ret(0); |
| 233 | 244 |
| 234 CodeDesc desc; | 245 CodeDesc desc; |
| 235 assm.GetCode(&desc); | 246 assm.GetCode(&desc); |
| 236 Code* code = | 247 Code* code = |
| 237 Code::cast(Heap::CreateCode(desc, NULL, Code::ComputeFlags(Code::STUB))); | 248 Code::cast(Heap::CreateCode(desc, |
| 249 NULL, |
| 250 Code::ComputeFlags(Code::STUB), |
| 251 Handle<Object>(Heap::undefined_value()))); |
| 238 F0 f = FUNCTION_CAST<F0>(code->entry()); | 252 F0 f = FUNCTION_CAST<F0>(code->entry()); |
| 239 int res = f(); | 253 int res = f(); |
| 240 CHECK_EQ(42, res); | 254 CHECK_EQ(42, res); |
| 241 } | 255 } |
| 242 | 256 |
| 243 | 257 |
| 244 typedef double (*F5)(double x, double y); | 258 typedef double (*F5)(double x, double y); |
| 245 | 259 |
| 246 TEST(AssemblerIa326) { | 260 TEST(AssemblerIa326) { |
| 247 InitializeVM(); | 261 InitializeVM(); |
| 248 v8::HandleScope scope; | 262 v8::HandleScope scope; |
| 249 Serializer::disable(); // Needed for Probe when running without snapshot. | |
| 250 CpuFeatures::Probe(); | |
| 251 CHECK(CpuFeatures::IsSupported(CpuFeatures::SSE2)); | 263 CHECK(CpuFeatures::IsSupported(CpuFeatures::SSE2)); |
| 252 CpuFeatures::Scope fscope(CpuFeatures::SSE2); | 264 CpuFeatures::Scope fscope(CpuFeatures::SSE2); |
| 253 v8::internal::byte buffer[256]; | 265 v8::internal::byte buffer[256]; |
| 254 Assembler assm(buffer, sizeof buffer); | 266 Assembler assm(buffer, sizeof buffer); |
| 255 | 267 |
| 256 __ movdbl(xmm0, Operand(esp, 1 * kPointerSize)); | 268 __ movdbl(xmm0, Operand(esp, 1 * kPointerSize)); |
| 257 __ movdbl(xmm1, Operand(esp, 3 * kPointerSize)); | 269 __ movdbl(xmm1, Operand(esp, 3 * kPointerSize)); |
| 258 __ addsd(xmm0, xmm1); | 270 __ addsd(xmm0, xmm1); |
| 259 __ mulsd(xmm0, xmm1); | 271 __ mulsd(xmm0, xmm1); |
| 260 __ subsd(xmm0, xmm1); | 272 __ subsd(xmm0, xmm1); |
| 261 __ divsd(xmm0, xmm1); | 273 __ divsd(xmm0, xmm1); |
| 262 // Copy xmm0 to st(0) using eight bytes of stack. | 274 // Copy xmm0 to st(0) using eight bytes of stack. |
| 263 __ sub(Operand(esp), Immediate(8)); | 275 __ sub(Operand(esp), Immediate(8)); |
| 264 __ movdbl(Operand(esp, 0), xmm0); | 276 __ movdbl(Operand(esp, 0), xmm0); |
| 265 __ fld_d(Operand(esp, 0)); | 277 __ fld_d(Operand(esp, 0)); |
| 266 __ add(Operand(esp), Immediate(8)); | 278 __ add(Operand(esp), Immediate(8)); |
| 267 __ ret(0); | 279 __ ret(0); |
| 268 | 280 |
| 269 CodeDesc desc; | 281 CodeDesc desc; |
| 270 assm.GetCode(&desc); | 282 assm.GetCode(&desc); |
| 271 Code* code = | 283 Code* code = |
| 272 Code::cast(Heap::CreateCode(desc, NULL, Code::ComputeFlags(Code::STUB))); | 284 Code::cast(Heap::CreateCode(desc, |
| 285 NULL, |
| 286 Code::ComputeFlags(Code::STUB), |
| 287 Handle<Object>(Heap::undefined_value()))); |
| 273 #ifdef DEBUG | 288 #ifdef DEBUG |
| 274 ::printf("\n---\n"); | 289 ::printf("\n---\n"); |
| 275 // don't print the code - our disassembler can't handle SSE instructions | 290 // don't print the code - our disassembler can't handle SSE instructions |
| 276 // instead print bytes | 291 // instead print bytes |
| 277 Disassembler::Dump(stdout, | 292 Disassembler::Dump(stdout, |
| 278 code->instruction_start(), | 293 code->instruction_start(), |
| 279 code->instruction_start() + code->instruction_size()); | 294 code->instruction_start() + code->instruction_size()); |
| 280 #endif | 295 #endif |
| 281 F5 f = FUNCTION_CAST<F5>(code->entry()); | 296 F5 f = FUNCTION_CAST<F5>(code->entry()); |
| 282 double res = f(2.2, 1.1); | 297 double res = f(2.2, 1.1); |
| 283 ::printf("f() = %f\n", res); | 298 ::printf("f() = %f\n", res); |
| 284 CHECK(2.29 < res && res < 2.31); | 299 CHECK(2.29 < res && res < 2.31); |
| 285 } | 300 } |
| 286 | 301 |
| 287 | 302 |
| 288 typedef double (*F6)(int x); | 303 typedef double (*F6)(int x); |
| 289 | 304 |
| 290 TEST(AssemblerIa328) { | 305 TEST(AssemblerIa328) { |
| 291 InitializeVM(); | 306 InitializeVM(); |
| 292 v8::HandleScope scope; | 307 v8::HandleScope scope; |
| 293 Serializer::disable(); // Needed for Probe when running without snapshot. | |
| 294 CpuFeatures::Probe(); | |
| 295 CHECK(CpuFeatures::IsSupported(CpuFeatures::SSE2)); | 308 CHECK(CpuFeatures::IsSupported(CpuFeatures::SSE2)); |
| 296 CpuFeatures::Scope fscope(CpuFeatures::SSE2); | 309 CpuFeatures::Scope fscope(CpuFeatures::SSE2); |
| 297 v8::internal::byte buffer[256]; | 310 v8::internal::byte buffer[256]; |
| 298 Assembler assm(buffer, sizeof buffer); | 311 Assembler assm(buffer, sizeof buffer); |
| 299 __ mov(eax, Operand(esp, 4)); | 312 __ mov(eax, Operand(esp, 4)); |
| 300 __ cvtsi2sd(xmm0, Operand(eax)); | 313 __ cvtsi2sd(xmm0, Operand(eax)); |
| 301 // Copy xmm0 to st(0) using eight bytes of stack. | 314 // Copy xmm0 to st(0) using eight bytes of stack. |
| 302 __ sub(Operand(esp), Immediate(8)); | 315 __ sub(Operand(esp), Immediate(8)); |
| 303 __ movdbl(Operand(esp, 0), xmm0); | 316 __ movdbl(Operand(esp, 0), xmm0); |
| 304 __ fld_d(Operand(esp, 0)); | 317 __ fld_d(Operand(esp, 0)); |
| 305 __ add(Operand(esp), Immediate(8)); | 318 __ add(Operand(esp), Immediate(8)); |
| 306 __ ret(0); | 319 __ ret(0); |
| 307 CodeDesc desc; | 320 CodeDesc desc; |
| 308 assm.GetCode(&desc); | 321 assm.GetCode(&desc); |
| 309 Code* code = | 322 Code* code = |
| 310 Code::cast(Heap::CreateCode(desc, NULL, Code::ComputeFlags(Code::STUB))); | 323 Code::cast(Heap::CreateCode(desc, |
| 324 NULL, |
| 325 Code::ComputeFlags(Code::STUB), |
| 326 Handle<Object>(Heap::undefined_value()))); |
| 311 CHECK(code->IsCode()); | 327 CHECK(code->IsCode()); |
| 312 #ifdef DEBUG | 328 #ifdef DEBUG |
| 313 Code::cast(code)->Print(); | 329 Code::cast(code)->Print(); |
| 314 #endif | 330 #endif |
| 315 F6 f = FUNCTION_CAST<F6>(Code::cast(code)->entry()); | 331 F6 f = FUNCTION_CAST<F6>(Code::cast(code)->entry()); |
| 316 double res = f(12); | 332 double res = f(12); |
| 317 | 333 |
| 318 ::printf("f() = %f\n", res); | 334 ::printf("f() = %f\n", res); |
| 319 CHECK(11.99 < res && res < 12.001); | 335 CHECK(11.99 < res && res < 12.001); |
| 320 } | 336 } |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 353 __ ret(0); | 369 __ ret(0); |
| 354 | 370 |
| 355 __ bind(&nan_l); | 371 __ bind(&nan_l); |
| 356 __ mov(eax, kNaN); | 372 __ mov(eax, kNaN); |
| 357 __ ret(0); | 373 __ ret(0); |
| 358 | 374 |
| 359 | 375 |
| 360 CodeDesc desc; | 376 CodeDesc desc; |
| 361 assm.GetCode(&desc); | 377 assm.GetCode(&desc); |
| 362 Code* code = | 378 Code* code = |
| 363 Code::cast(Heap::CreateCode(desc, NULL, Code::ComputeFlags(Code::STUB))); | 379 Code::cast(Heap::CreateCode(desc, |
| 380 NULL, |
| 381 Code::ComputeFlags(Code::STUB), |
| 382 Handle<Object>(Heap::undefined_value()))); |
| 364 CHECK(code->IsCode()); | 383 CHECK(code->IsCode()); |
| 365 #ifdef DEBUG | 384 #ifdef DEBUG |
| 366 Code::cast(code)->Print(); | 385 Code::cast(code)->Print(); |
| 367 #endif | 386 #endif |
| 368 | 387 |
| 369 F7 f = FUNCTION_CAST<F7>(Code::cast(code)->entry()); | 388 F7 f = FUNCTION_CAST<F7>(Code::cast(code)->entry()); |
| 370 CHECK_EQ(kLess, f(1.1, 2.2)); | 389 CHECK_EQ(kLess, f(1.1, 2.2)); |
| 371 CHECK_EQ(kEqual, f(2.2, 2.2)); | 390 CHECK_EQ(kEqual, f(2.2, 2.2)); |
| 372 CHECK_EQ(kGreater, f(3.3, 2.2)); | 391 CHECK_EQ(kGreater, f(3.3, 2.2)); |
| 373 CHECK_EQ(kNaN, f(OS::nan_value(), 1.1)); | 392 CHECK_EQ(kNaN, f(OS::nan_value(), 1.1)); |
| 374 } | 393 } |
| 375 | 394 |
| 376 #undef __ | 395 #undef __ |
| OLD | NEW |