OLD | NEW |
(Empty) | |
| 1 // Copyright 2011 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are |
| 4 // met: |
| 5 // |
| 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided |
| 11 // with the distribution. |
| 12 // * Neither the name of Google Inc. nor the names of its |
| 13 // contributors may be used to endorse or promote products derived |
| 14 // from this software without specific prior written permission. |
| 15 // |
| 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 |
| 28 #include "v8.h" |
| 29 |
| 30 #include "macro-assembler.h" |
| 31 #include "code-stubs.h" |
| 32 #include "factory.h" |
| 33 #include "platform.h" |
| 34 #include "serialize.h" |
| 35 #include "cctest.h" |
| 36 |
| 37 using namespace v8::internal; |
| 38 |
| 39 Handle<JSFunction> |
| 40 CreateJSFunctionFromCode(const char *name, Code *code, Isolate* isolate) { |
| 41 Factory* factory = isolate->factory(); |
| 42 |
| 43 // Allocate the function |
| 44 Handle<String> symbol = factory->LookupAsciiSymbol(name); |
| 45 Handle<JSFunction> new_function = |
| 46 factory->NewFunctionWithoutPrototype(symbol, CLASSIC_MODE); |
| 47 |
| 48 // Bind the code |
| 49 new_function->set_code(code); |
| 50 new_function->shared()->set_code(code); |
| 51 Handle<String> source = factory->NewStringFromAscii(CStrVector("() {}")); |
| 52 Handle<Script> script = factory->NewScript(source); |
| 53 script->set_type(Smi::FromInt(Script::TYPE_NATIVE)); |
| 54 new_function->shared()->set_script(*script); |
| 55 new_function->shared()->set_start_position(0); |
| 56 new_function->shared()->set_end_position(source->length()); |
| 57 new_function->shared()->DontAdaptArguments(); |
| 58 |
| 59 return new_function; |
| 60 } |
| 61 |
| 62 #define BEGIN() \ |
| 63 FLAG_disable_native_files = true; \ |
| 64 FLAG_code_comments = true; \ |
| 65 v8::HandleScope scope; \ |
| 66 Isolate* isolate = Isolate::Current(); \ |
| 67 LocalContext env; \ |
| 68 MacroAssembler assm(Isolate::Current(), NULL, 0); |
| 69 |
| 70 |
| 71 #define JIT() \ |
| 72 CodeDesc desc; \ |
| 73 assm.GetCode(&desc); \ |
| 74 Code* code = Code::cast(HEAP-> \ |
| 75 CreateCode(desc, \ |
| 76 Code::ComputeFlags(Code::BUILTIN), \ |
| 77 Handle<Object>(HEAP->null_value()))-> \ |
| 78 ToObjectChecked()); \ |
| 79 Handle<JSFunction> func = CreateJSFunctionFromCode(__FUNCTION__, \ |
| 80 code, isolate); |
| 81 |
| 82 #define CALL() \ |
| 83 CHECK(func->code()->IsCode()); \ |
| 84 bool exc; \ |
| 85 Handle<Object> receiver(isolate->context()->global_proxy(), isolate); \ |
| 86 Handle<Object> result = Execution::Call(func, receiver, 0, NULL, &exc); \ |
| 87 if (exc) { result = isolate->factory()->nan_value(); } \ |
| 88 (void)0 |
| 89 |
| 90 // #define NOPRINT |
| 91 #if defined(DEBUG) && !defined(NOPRINT) |
| 92 #define PRINT() Code::cast(func->code())->Print() |
| 93 #else |
| 94 #define PRINT() (void)0 |
| 95 #endif |
| 96 |
| 97 #define GLOBAL_FUNCTION_PTR() (isolate->global_context()->closure()) |
| 98 #define GLOBAL_PTR() (*(isolate->global_object())) |
| 99 #define GLOBAL_CONTEXT_PTR() (*(isolate->global_context())) |
| 100 #define GLOBAL_CLOSURE_PTR() (isolate->global_context()->closure()) |
| 101 #define GLOBAL_OBJECT_FUNCTION_PTR() \ |
| 102 (isolate->global_context()->object_function()) |
| 103 #define GLOBAL_BUILTINS_PTR() (*isolate->builtins()) |
| 104 |
| 105 #define CMT(msg) do { Comment cmnt(&assm, msg); } while (0) |
| 106 |
| 107 #define __ assm. |
| 108 |
| 109 // This macro stores in r10 the line number before branching to the error label. |
| 110 // At the error label r10 can be moved to r0 such that return code of the |
| 111 // function if not 0 indicates an error at the line of the branch. |
| 112 #define B_LINE(cond, target) do { \ |
| 113 __ mov(r10, Operand(__LINE__)); \ |
| 114 if (cond == al) { \ |
| 115 __ b(target); \ |
| 116 } else { \ |
| 117 __ b(cond, target); \ |
| 118 } \ |
| 119 } while (0); |
| 120 |
| 121 |
| 122 // Test Empty function call |
| 123 // This covers JSEntryStub (call to the empty function) builtin. |
| 124 // This covers CEntryStub (call to kEmptyFunction) builtin. |
| 125 // This Covers also Generate_Adaptor() and JumpToExternalReference() |
| 126 TEST(sh4_cs_0) { |
| 127 BEGIN(); |
| 128 |
| 129 // Force use of empty function (global_context()->closure()) |
| 130 Handle<JSFunction> func = |
| 131 Handle<JSFunction>(isolate->global_context()->closure(), isolate); |
| 132 |
| 133 fprintf(stderr, "isolate = Isolate::Current(): %p\n", |
| 134 reinterpret_cast<void *>(isolate)); |
| 135 fprintf(stderr, "isolate_context = isolate->context(): %p\n", |
| 136 reinterpret_cast<void *>(isolate->context())); |
| 137 fprintf(stderr, "global_context = isolate->global_context(): %p\n", |
| 138 reinterpret_cast<void *>(*isolate->global_context())); |
| 139 fprintf(stderr, "global_context_closure = global_context->closure(): %p\n", |
| 140 reinterpret_cast<void *>(isolate->global_context()->closure())); |
| 141 fprintf(stderr, "global = isolate->global_object(): %p\n", |
| 142 reinterpret_cast<void *>(*isolate->global_object())); |
| 143 fprintf(stderr, "global_proxy = isolate->global_proxy(): %p\n", |
| 144 reinterpret_cast<void *>(isolate->context()->global_proxy())); |
| 145 fprintf(stderr, "closure_code = global_context_closure->code(): %p \n", |
| 146 reinterpret_cast<void *>(func->code())); |
| 147 fprintf(stderr, "closure_entry = code->entry(): %p \n", |
| 148 reinterpret_cast<void *>(func->code()->entry())); |
| 149 |
| 150 PRINT(); |
| 151 |
| 152 CALL(); |
| 153 |
| 154 // The empty function returns the undefined value. |
| 155 CHECK(result->IsHeapObject()); |
| 156 CHECK(HeapObject::cast(*result)->IsUndefined()); |
| 157 } |
| 158 |
| 159 // Test empty function that scratches all JS registers |
| 160 // (except roots, cp, fp, sp) |
| 161 TEST(sh4_cs_1) { |
| 162 BEGIN(); |
| 163 |
| 164 // We are in a JS context, thus we can scratch caller and callee saved |
| 165 __ Dead(r0, r1, r2, r3); |
| 166 __ Dead(r4, r5, r6, r7); |
| 167 __ Dead(r8, r9, r10, r11); |
| 168 |
| 169 __ mov(r0, Operand(Smi::FromInt(0))); |
| 170 __ rts(); |
| 171 |
| 172 JIT(); |
| 173 |
| 174 PRINT(); |
| 175 |
| 176 CALL(); |
| 177 |
| 178 // The function must return a result as Smi. |
| 179 CHECK(result->IsSmi()); |
| 180 CHECK_EQ(0, Smi::cast(*result)->value()); |
| 181 } |
| 182 |
| 183 |
| 184 // Test CompareInstanceType(), CompareObjectType() |
| 185 TEST(sh4_cs_2) { |
| 186 BEGIN(); |
| 187 |
| 188 Label error; |
| 189 |
| 190 // Check that roots is actually te root object |
| 191 CMT("Check roots"); |
| 192 __ mov(r0, Operand(ExternalReference::roots_array_start(assm.isolate()))); |
| 193 __ cmp(r0, roots); |
| 194 B_LINE(ne, &error); |
| 195 |
| 196 // Check that cp is actually the current context |
| 197 CMT("Check cp"); |
| 198 __ mov(r0, Operand((intptr_t)GLOBAL_CONTEXT_PTR(), |
| 199 RelocInfo::EXTERNAL_REFERENCE)); |
| 200 __ cmp(r0, cp); |
| 201 B_LINE(ne, &error); |
| 202 |
| 203 CMT("Check MemOperand(cp, GLOBAL_OBJECT_INDEX) == GLOBAL_PTR())"); |
| 204 __ ldr(r0, MemOperand(cp, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX))); |
| 205 __ mov(r1, Operand((intptr_t)GLOBAL_PTR(), RelocInfo::EXTERNAL_REFERENCE)); |
| 206 __ cmp(r0, r1); |
| 207 B_LINE(ne, &error); |
| 208 |
| 209 CMT("Check FieldMemOperand(GLOBAL_PTR(), GlobalContextOffset) " |
| 210 "== GLOBAL_CONTEXT_PTR())"); |
| 211 __ ldr(r0, FieldMemOperand(r0, |
| 212 GlobalObject::kGlobalContextOffset)); |
| 213 __ mov(r1, Operand((intptr_t)GLOBAL_CONTEXT_PTR(), |
| 214 RelocInfo::EXTERNAL_REFERENCE)); |
| 215 __ cmp(r0, r1); |
| 216 B_LINE(ne, &error); |
| 217 |
| 218 CMT("Check MemOperand(GLOBAL_CONTEXT_PTR(), CLOSURE_INDEX) " |
| 219 "== GLOBAL_CLOSURE_PTR())"); |
| 220 __ ldr(r0, MemOperand(r0, |
| 221 Context::SlotOffset(Context::CLOSURE_INDEX))); |
| 222 __ mov(r1, Operand((intptr_t)GLOBAL_CLOSURE_PTR(), |
| 223 RelocInfo::EXTERNAL_REFERENCE)); |
| 224 __ cmp(r0, r1); |
| 225 B_LINE(ne, &error); |
| 226 |
| 227 CMT("Check CompareInstanceType(GLOBAL_PTR()) == JS_GLOBAL_OBJECT_TYPE"); |
| 228 __ mov(r0, Operand((intptr_t)GLOBAL_PTR(), |
| 229 RelocInfo::EXTERNAL_REFERENCE)); |
| 230 __ ldr(r1, FieldMemOperand(r0, HeapObject::kMapOffset)); |
| 231 __ CompareInstanceType(r1, r2/*type*/ , JS_GLOBAL_OBJECT_TYPE, eq); |
| 232 B_LINE(f, &error); |
| 233 __ cmp(r2, Operand(JS_GLOBAL_OBJECT_TYPE)); |
| 234 B_LINE(f, &error); |
| 235 CMT("Check CompareInstanceType(GLOBAL_PTR()) != JS_VALUE_TYPE"); |
| 236 __ CompareInstanceType(r1, r2/*type*/ , JS_VALUE_TYPE, eq); |
| 237 B_LINE(t, &error); |
| 238 CMT("Check CompareInstanceType(GLOBAL_PTR()) >= (ge) FIRST_SPEC_OBJECT_TYPE"); |
| 239 __ CompareInstanceType(r1, r2/*type*/ , FIRST_SPEC_OBJECT_TYPE, ge); |
| 240 B_LINE(f, &error); |
| 241 CMT("Check CompareInstanceType(GLOBAL_PTR()) > (hs) FIRST_SPEC_OBJECT_TYPE"); |
| 242 __ CompareInstanceType(r1, r2/*type*/ , FIRST_SPEC_OBJECT_TYPE, hs); |
| 243 B_LINE(f, &error); |
| 244 |
| 245 CMT("Check CompareObjectType(GLOBAL_PTR()) == JS_GLOBAL_OBJECT_TYPE"); |
| 246 __ CompareObjectType(r0, r3/*map*/, r4/*type*/ , JS_GLOBAL_OBJECT_TYPE, eq); |
| 247 B_LINE(f, &error); |
| 248 __ cmp(r1, r3); // check that map matches |
| 249 B_LINE(f, &error); |
| 250 __ cmp(r2, r4); // check that type matches |
| 251 |
| 252 // All ok. |
| 253 __ mov(r0, Operand(Smi::FromInt(0))); |
| 254 __ rts(); |
| 255 |
| 256 __ bind(&error); |
| 257 __ SmiTag(r0, r10); |
| 258 __ rts(); |
| 259 |
| 260 JIT(); |
| 261 |
| 262 PRINT(); |
| 263 |
| 264 CALL(); |
| 265 |
| 266 // The function must return a result as Smi. |
| 267 CHECK(result->IsSmi()); |
| 268 CHECK_EQ(0, Smi::cast(*result)->value()); |
| 269 } |
| 270 |
| 271 |
| 272 // Test LoadGlobalFunction(), LoadContext(), LoadGlobalFunctionInitialMap() |
| 273 // TryGetFunctionPrototype() |
| 274 TEST(sh4_cs_3) { |
| 275 BEGIN(); |
| 276 |
| 277 Label error; |
| 278 |
| 279 CMT("Check LoadContext() == @(isolate+kContextAddress)"); |
| 280 __ LoadContext(r0, 0); |
| 281 __ mov(r1, Operand(ExternalReference(Isolate::kContextAddress, isolate))); |
| 282 __ ldr(r1, MemOperand(r1)); |
| 283 __ cmp(r0, r1); |
| 284 B_LINE(ne, &error); |
| 285 |
| 286 CMT("Check LoadContext() == isolate->context()"); |
| 287 __ mov(r1, Operand((intptr_t)isolate->context(), |
| 288 RelocInfo::EXTERNAL_REFERENCE)); |
| 289 __ cmp(r0, r1); |
| 290 B_LINE(ne, &error); |
| 291 |
| 292 CMT("Check LoadContext() == isolate->global_context()"); |
| 293 __ mov(r1, Operand((intptr_t)GLOBAL_CONTEXT_PTR(), |
| 294 RelocInfo::EXTERNAL_REFERENCE)); |
| 295 __ cmp(r0, r1); |
| 296 B_LINE(ne, &error); |
| 297 |
| 298 CMT("Check LoadContext() == LoadContext()->global_object->global_context"); |
| 299 __ ldr(r1, MemOperand(r0, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX))); |
| 300 __ ldr(r1, FieldMemOperand(r1, GlobalObject::kGlobalContextOffset)); |
| 301 __ cmp(r0, r1); |
| 302 B_LINE(ne, &error); |
| 303 |
| 304 CMT("Check LoadContext(level 1) == NULL"); |
| 305 __ LoadContext(r0, 1); |
| 306 __ mov(r1, Operand(0)); |
| 307 __ cmp(r0, r1); |
| 308 B_LINE(ne, &error); |
| 309 |
| 310 |
| 311 CMT("Check LoadGlobalFunction() == Global Closure"); |
| 312 // Check |
| 313 __ LoadGlobalFunction(Context::CLOSURE_INDEX, r0/* Resulting closure*/); |
| 314 __ mov(r1, Operand((intptr_t)GLOBAL_CLOSURE_PTR(), |
| 315 RelocInfo::EXTERNAL_REFERENCE)); |
| 316 __ cmp(r0, r1); |
| 317 B_LINE(ne, &error); |
| 318 |
| 319 CMT("Check LoadGlobalFunctionInitialMap() == " |
| 320 "Global Object Function->initial_map()"); |
| 321 __ LoadGlobalFunction(Context::OBJECT_FUNCTION_INDEX, |
| 322 r0/* Resulting closure*/); |
| 323 __ mov(r1, Operand((intptr_t)GLOBAL_OBJECT_FUNCTION_PTR(), |
| 324 RelocInfo::EXTERNAL_REFERENCE)); |
| 325 |
| 326 __ cmp(r0, r1); |
| 327 B_LINE(ne, &error); |
| 328 __ LoadGlobalFunctionInitialMap(r0, r1/*result map*/, r2/*scratch*/); |
| 329 __ mov(r0, Operand((intptr_t)GLOBAL_OBJECT_FUNCTION_PTR()-> |
| 330 prototype_or_initial_map(), |
| 331 RelocInfo::EXTERNAL_REFERENCE)); |
| 332 __ cmp(r1, r0); |
| 333 B_LINE(ne, &error); |
| 334 |
| 335 Label miss1, miss2, miss3, miss4, skip_proto4; |
| 336 CMT("Check TryGetFunctionPrototype: Smi"); |
| 337 __ mov(r0, Operand(Smi::FromInt(1))); |
| 338 __ TryGetFunctionPrototype(r0, r1 /*proto*/, r2 /*scratch*/, &miss1); |
| 339 B_LINE(al, &error); |
| 340 __ bind(&miss1); |
| 341 CMT("Check TryGetFunctionPrototype: Not a function"); |
| 342 __ LoadRoot(r0, Heap::kTheHoleValueRootIndex); |
| 343 __ TryGetFunctionPrototype(r0, r1 /*proto*/, r2 /*scratch*/, &miss2); |
| 344 B_LINE(al, &error); |
| 345 __ bind(&miss2); |
| 346 CMT("Check TryGetFunctionPrototype(empty_function) == the_hole_value"); |
| 347 __ LoadGlobalFunction(Context::CLOSURE_INDEX, r0/* Resulting closure*/); |
| 348 __ TryGetFunctionPrototype(r0, r1 /*proto*/, r2 /*scratch*/, &miss3); |
| 349 B_LINE(al, &error); |
| 350 __ bind(&miss3); |
| 351 __ LoadRoot(r2, Heap::kTheHoleValueRootIndex); |
| 352 __ cmp(r1, r2); |
| 353 B_LINE(ne, &error); |
| 354 |
| 355 CMT("Check TryGetFunctionPrototype(global_object_function) == " |
| 356 "initial_map->prototype()"); |
| 357 __ LoadGlobalFunction(Context::OBJECT_FUNCTION_INDEX, |
| 358 r0/* Resulting closure*/); |
| 359 __ TryGetFunctionPrototype(r0, r1 /*proto*/, r2 /*scratch*/, &miss4); |
| 360 __ jmp(&skip_proto4); |
| 361 __ bind(&miss4); |
| 362 B_LINE(al, &error); |
| 363 __ bind(&skip_proto4); |
| 364 __ LoadGlobalFunctionInitialMap(r0, r3/*result map*/, r2/*scratch*/); |
| 365 __ ldr(r3, FieldMemOperand(r3, Map::kPrototypeOffset)); |
| 366 __ cmp(r1, r3); |
| 367 B_LINE(ne, &error); |
| 368 |
| 369 // All ok. |
| 370 __ mov(r0, Operand(Smi::FromInt(0))); |
| 371 __ rts(); |
| 372 |
| 373 __ bind(&error); |
| 374 __ SmiTag(r0, r10); |
| 375 __ rts(); |
| 376 |
| 377 JIT(); |
| 378 |
| 379 PRINT(); |
| 380 |
| 381 CALL(); |
| 382 |
| 383 // The function must return a result as Smi. |
| 384 CHECK(result->IsSmi()); |
| 385 CHECK_EQ(0, Smi::cast(*result)->value()); |
| 386 } |
| 387 |
| 388 |
| 389 // Test GetBuiltinFunction()/GetBuiltinEntry() |
| 390 TEST(sh4_cs_4) { |
| 391 BEGIN(); |
| 392 |
| 393 Label error; |
| 394 |
| 395 // First check that the builtin function is actually undefined |
| 396 // as we do not activate natives. |
| 397 // Then install the empty function for the purpose of the tests. |
| 398 CHECK(isolate->global_object()->builtins()-> |
| 399 javascript_builtin(Builtins::MUL)->IsUndefined()); |
| 400 isolate->global_object()->builtins()-> |
| 401 set_javascript_builtin(Builtins::MUL, |
| 402 isolate->global_context()->closure()); |
| 403 isolate->global_object()->builtins()-> |
| 404 set_javascript_builtin_code(Builtins::MUL, |
| 405 isolate->global_context()->closure()->code()); |
| 406 CMT("Check GetBuiltinFunction(Builtins::MUL)"); |
| 407 __ GetBuiltinFunction(r0, Builtins::MUL); |
| 408 __ mov(r1, Operand((intptr_t)isolate->global_object()->builtins()-> |
| 409 javascript_builtin(Builtins::MUL), |
| 410 RelocInfo::EXTERNAL_REFERENCE)); |
| 411 __ cmp(r0, r1); |
| 412 B_LINE(ne, &error); |
| 413 |
| 414 CMT("Check GetBuiltinEntry(Builtins::MUL)"); |
| 415 __ GetBuiltinEntry(r0, Builtins::MUL); |
| 416 __ mov(r1, Operand((intptr_t)isolate->global_object()->builtins()-> |
| 417 javascript_builtin_code(Builtins::MUL)->entry(), |
| 418 RelocInfo::EXTERNAL_REFERENCE)); |
| 419 __ cmp(r0, r1); |
| 420 B_LINE(ne, &error); |
| 421 |
| 422 // All ok. |
| 423 __ mov(r0, Operand(Smi::FromInt(0))); |
| 424 __ rts(); |
| 425 |
| 426 __ bind(&error); |
| 427 __ SmiTag(r0, r10); |
| 428 __ rts(); |
| 429 |
| 430 JIT(); |
| 431 |
| 432 PRINT(); |
| 433 |
| 434 CALL(); |
| 435 |
| 436 // The function must return a result as Smi. |
| 437 CHECK(result->IsSmi()); |
| 438 CHECK_EQ(0, Smi::cast(*result)->value()); |
| 439 } |
| 440 |
| 441 |
| 442 static double |
| 443 ObjectToNumber(Object *object) { |
| 444 double cast_value; |
| 445 if (object->IsSmi()) { |
| 446 int int_value = Smi::cast(object)->value(); |
| 447 cast_value = static_cast<double>(int_value); |
| 448 } else if (object->IsHeapNumber()) { |
| 449 cast_value = HeapNumber::cast(object)->value(); |
| 450 } else { |
| 451 // Return 0 when not a number |
| 452 cast_value = 0; |
| 453 } |
| 454 return cast_value; |
| 455 } |
| 456 |
| 457 // Test TailCallRuntime() |
| 458 TEST(sh4_cs_5) { |
| 459 { |
| 460 BEGIN(); |
| 461 CMT("Check TailCallRuntime: NumberToJSint32(13)"); |
| 462 __ mov(r0, Operand(Smi::FromInt(13))); |
| 463 __ push(r0); |
| 464 __ TailCallRuntime(Runtime::kNumberToJSInt32, 1, 1); |
| 465 |
| 466 JIT(); |
| 467 PRINT(); |
| 468 CALL(); |
| 469 CHECK(result->IsNumber()); |
| 470 CHECK_EQ(13.0, ObjectToNumber(*result)); |
| 471 } |
| 472 { |
| 473 BEGIN(); |
| 474 CMT("Check CallRuntime: NumberAdd(7, 27)"); |
| 475 { |
| 476 FrameScope scpe(&assm, StackFrame::INTERNAL); |
| 477 __ mov(r0, Operand(Smi::FromInt(7))); |
| 478 __ mov(r1, Operand(Smi::FromInt(27))); |
| 479 __ Push(r0, r1); |
| 480 __ CallRuntime(Runtime::kNumberAdd, 2); |
| 481 } |
| 482 __ Ret(); |
| 483 JIT(); |
| 484 PRINT(); |
| 485 CALL(); |
| 486 CHECK(result->IsNumber()); |
| 487 CHECK_EQ(34.0, ObjectToNumber(*result)); |
| 488 } |
| 489 { |
| 490 BEGIN(); |
| 491 CMT("Check CallRuntime: NumberToString(1234)"); |
| 492 { |
| 493 FrameScope scpe(&assm, StackFrame::INTERNAL); |
| 494 __ mov(r0, Operand(Smi::FromInt(1234))); |
| 495 __ push(r0); |
| 496 __ CallRuntime(Runtime::kNumberToString, 1); |
| 497 CMT("Check CallRuntime: GlobalPrint(\"1234\")"); |
| 498 __ push(r0); |
| 499 __ CallRuntime(Runtime::kGlobalPrint, 1); |
| 500 } |
| 501 __ Ret(); |
| 502 JIT(); |
| 503 PRINT(); |
| 504 CALL(); |
| 505 CHECK(result->IsString()); |
| 506 CHECK(String::cast(*result)->IsEqualTo(CStrVector("1234"))); |
| 507 } |
| 508 } |
| 509 |
| 510 #undef __ |
| 511 #define __ assm-> |
| 512 static void |
| 513 GenerateNumberFromReg(MacroAssembler *assm, Register heap, Register reg) { |
| 514 ASSERT(!reg.is(r4) && !reg.is(r5) && !reg.is(r6) && !reg.is(r7)); |
| 515 Label gc_required, skip, not_smi; |
| 516 |
| 517 { |
| 518 FrameScope scpe(assm, StackFrame::INTERNAL); |
| 519 __ Push(r4, r5, r6, r7); |
| 520 __ TrySmiTag(reg, ¬_smi, r5/*scratch*/); |
| 521 __ mov(heap, reg); |
| 522 __ jmp(&skip); |
| 523 __ bind(¬_smi); |
| 524 __ LoadRoot(r7, Heap::kHeapNumberMapRootIndex); |
| 525 __ AllocateHeapNumber(r4/*result heap number*/, r5/*scratch*/, |
| 526 r6/*scratch*/, r7/*heap_number_map*/, &gc_required); |
| 527 WriteInt32ToHeapNumberStub stub(reg, r4, r5/*scratch*/); |
| 528 __ CallStub(&stub); |
| 529 __ mov(heap, r4); |
| 530 __ Pop(r6, r7); |
| 531 __ Pop(r4, r5); |
| 532 } |
| 533 __ jmp(&skip); |
| 534 __ bind(&gc_required); |
| 535 __ Abort("GC required while dumping number"); |
| 536 __ bind(&skip); |
| 537 } |
| 538 #undef __ |
| 539 #define __ assm. |
| 540 |
| 541 // Test WriteInt32ToHeapNumberStub() |
| 542 TEST(sh4_cs_6) { |
| 543 { |
| 544 BEGIN(); |
| 545 |
| 546 __ mov(r0, Operand(0)); |
| 547 GenerateNumberFromReg(&assm, r0, r0); |
| 548 __ Ret(); |
| 549 |
| 550 JIT(); |
| 551 PRINT(); |
| 552 CALL(); |
| 553 CHECK(result->IsNumber()); |
| 554 CHECK_EQ(0, static_cast<int>(ObjectToNumber(*result))); |
| 555 } |
| 556 { |
| 557 BEGIN(); |
| 558 |
| 559 __ mov(r0, Operand(1234)); |
| 560 GenerateNumberFromReg(&assm, r0, r0); |
| 561 __ Ret(); |
| 562 |
| 563 JIT(); |
| 564 PRINT(); |
| 565 CALL(); |
| 566 CHECK(result->IsNumber()); |
| 567 CHECK_EQ(1234, static_cast<int>(ObjectToNumber(*result))); |
| 568 } |
| 569 { |
| 570 BEGIN(); |
| 571 |
| 572 __ mov(r0, Operand(0x7fffffff)); |
| 573 GenerateNumberFromReg(&assm, r0, r0); |
| 574 __ Ret(); |
| 575 |
| 576 JIT(); |
| 577 PRINT(); |
| 578 CALL(); |
| 579 CHECK(result->IsNumber()); |
| 580 CHECK_EQ(0x7fffffff, static_cast<int>(ObjectToNumber(*result))); |
| 581 } |
| 582 { |
| 583 BEGIN(); |
| 584 |
| 585 __ mov(r0, Operand(0x80000000u)); |
| 586 GenerateNumberFromReg(&assm, r0, r0); |
| 587 __ Ret(); |
| 588 |
| 589 JIT(); |
| 590 PRINT(); |
| 591 CALL(); |
| 592 CHECK(result->IsNumber()); |
| 593 CHECK_EQ(0x80000000u, static_cast<int>(ObjectToNumber(*result))); |
| 594 } |
| 595 } |
| 596 |
| 597 #undef __ |
| 598 #define __ assm-> |
| 599 static void |
| 600 GeneratePrintReg(MacroAssembler *assm, Register reg) { |
| 601 ASSERT(!reg.is(r4) && !reg.is(r5) && !reg.is(r6) && !reg.is(r7)); |
| 602 Label gc_required, skip, not_smi; |
| 603 { |
| 604 FrameScope scpe(assm, StackFrame::INTERNAL); |
| 605 // Save reg as it is scratched by WriteInt32ToHeapNumberStub() |
| 606 __ push(reg); |
| 607 __ pushm(kJSCallerSaved); |
| 608 __ TrySmiTag(reg, ¬_smi, r5/*scratch*/); |
| 609 __ mov(r4, reg); |
| 610 __ jmp(&skip); |
| 611 __ bind(¬_smi); |
| 612 __ LoadRoot(r7, Heap::kHeapNumberMapRootIndex); |
| 613 __ AllocateHeapNumber(r4/*result heap number*/, r5/*scratch*/, |
| 614 r6/*scratch*/, r7/*heap_number_map*/, &gc_required); |
| 615 WriteInt32ToHeapNumberStub stub(reg, r4, r5/*scratch*/); |
| 616 __ CallStub(&stub); |
| 617 __ jmp(&skip); |
| 618 __ bind(&gc_required); |
| 619 __ Abort("GC required while dumping number"); |
| 620 __ bind(&skip); |
| 621 __ push(r4); |
| 622 __ CallRuntime(Runtime::kNumberToString, 1); |
| 623 __ push(r0); |
| 624 __ CallRuntime(Runtime::kGlobalPrint, 1); |
| 625 __ popm(kJSCallerSaved); |
| 626 __ pop(reg); |
| 627 } |
| 628 } |
| 629 #undef __ |
| 630 #define __ assm. |
| 631 |
| 632 // Test GeneratePrintReg() |
| 633 TEST(sh4_cs_7) { |
| 634 BEGIN(); |
| 635 |
| 636 __ mov(r0, Operand(1234)); |
| 637 GeneratePrintReg(&assm, r0); |
| 638 __ mov(r0, Operand(0x7fffffff)); |
| 639 GeneratePrintReg(&assm, r0); |
| 640 __ mov(r0, Operand(0x80000000)); |
| 641 GeneratePrintReg(&assm, r0); |
| 642 __ PrintRegisterValue(r0); |
| 643 __ mov(r0, Operand(0)); |
| 644 __ Ret(); |
| 645 |
| 646 JIT(); |
| 647 PRINT(); |
| 648 CALL(); |
| 649 CHECK(result->IsNumber()); |
| 650 CHECK_EQ(0.0, ObjectToNumber(*result)); |
| 651 } |
| 652 |
| 653 |
| 654 // Test CompareStub() |
| 655 TEST(sh4_cs_8) { |
| 656 BEGIN(); |
| 657 |
| 658 Label error; |
| 659 |
| 660 // Enter Fram before call stubs |
| 661 { |
| 662 FrameScope scpe(&assm, StackFrame::INTERNAL); |
| 663 |
| 664 CompareStub stub(eq/*cond*/, true/*strict*/, NO_COMPARE_FLAGS, r0, r1); |
| 665 #if 1 && defined(DEBUG) |
| 666 stub.GetCode()->Print(); |
| 667 #endif |
| 668 |
| 669 CMT("Check CompareStub(0, 0) == 0"); |
| 670 __ mov(r0, Operand(Smi::FromInt(0))); |
| 671 __ mov(r1, Operand(Smi::FromInt(0))); |
| 672 __ CallStub(&stub); |
| 673 __ cmp(r0, Operand(0)); |
| 674 B_LINE(ne, &error); |
| 675 |
| 676 CMT("Check CompareStub(1, 1) == 0"); |
| 677 __ mov(r0, Operand(Smi::FromInt(1))); |
| 678 __ mov(r1, Operand(Smi::FromInt(1))); |
| 679 __ CallStub(&stub); |
| 680 __ cmp(r0, Operand(0)); |
| 681 B_LINE(ne, &error); |
| 682 |
| 683 CMT("Check CompareStub(0, 1) > 0"); |
| 684 __ mov(r0, Operand(Smi::FromInt(0))); |
| 685 __ mov(r1, Operand(Smi::FromInt(1))); |
| 686 __ CallStub(&stub); |
| 687 __ cmpgt(r0, Operand(0)); |
| 688 B_LINE(ne, &error); |
| 689 |
| 690 CMT("Check CompareStub(-1, 2) > 0"); |
| 691 __ mov(r0, Operand(Smi::FromInt(-1))); |
| 692 __ mov(r1, Operand(Smi::FromInt(2))); |
| 693 __ CallStub(&stub); |
| 694 __ cmp(r0, Operand(0)); |
| 695 B_LINE(eq, &error); |
| 696 |
| 697 // CMT("Check CompareStub(0, heap(0)) == 0"); |
| 698 // __ mov(r0, Operand(Smi::FromInt(0))); |
| 699 // __ mov(r1, Operand(0)); |
| 700 // GenerateNumberFromReg(&assm, r1, r1); |
| 701 // __ CallStub(&stub); |
| 702 // __ cmp(r0, Operand(0)); |
| 703 // B_LINE(ne, &error); |
| 704 |
| 705 // All ok. |
| 706 __ mov(r0, Operand(Smi::FromInt(0))); |
| 707 __ rts(); |
| 708 |
| 709 __ bind(&error); |
| 710 __ SmiTag(r0, r10); |
| 711 __ rts(); |
| 712 } |
| 713 |
| 714 JIT(); |
| 715 PRINT(); |
| 716 CALL(); |
| 717 CHECK(result->IsNumber()); |
| 718 CHECK_EQ(0, static_cast<int>(ObjectToNumber(*result))); |
| 719 } |
OLD | NEW |