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

Side by Side Diff: src/arm/lithium-codegen-arm.cc

Issue 6347007: ARM: Implement Math.abs in lithium code generator for the integer and (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 9 years, 11 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 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 2321 matching lines...) Expand 10 before | Expand all | Expand 10 after
2332 2332
2333 2333
2334 void LCodeGen::DoCallConstantFunction(LCallConstantFunction* instr) { 2334 void LCodeGen::DoCallConstantFunction(LCallConstantFunction* instr) {
2335 ASSERT(ToRegister(instr->result()).is(r0)); 2335 ASSERT(ToRegister(instr->result()).is(r0));
2336 __ mov(r1, Operand(instr->function())); 2336 __ mov(r1, Operand(instr->function()));
2337 CallKnownFunction(instr->function(), instr->arity(), instr); 2337 CallKnownFunction(instr->function(), instr->arity(), instr);
2338 } 2338 }
2339 2339
2340 2340
2341 void LCodeGen::DoDeferredMathAbsTaggedHeapNumber(LUnaryMathOperation* instr) { 2341 void LCodeGen::DoDeferredMathAbsTaggedHeapNumber(LUnaryMathOperation* instr) {
2342 Abort("DoDeferredMathAbsTaggedHeapNumber unimplemented."); 2342 Register input = ToRegister(instr->input());
2343 Register scratch = scratch0();
2344
2345 // Deoptimize if not a heap number.
2346 __ ldr(scratch, FieldMemOperand(input, HeapObject::kMapOffset));
2347 __ LoadRoot(ip, Heap::kHeapNumberMapRootIndex);
2348 __ cmp(scratch, Operand(ip));
2349 DeoptimizeIf(ne, instr->environment());
2350
2351 Label done;
2352 Register tmp = input.is(r0) ? r1 : r0;
2353 Register tmp2 = r2;
2354 Register tmp3 = r3;
2355
2356 // Preserve the value of all registers.
2357 __ PushSafepointRegisters();
2358
2359 Label negative;
2360 __ ldr(tmp, FieldMemOperand(input, HeapNumber::kExponentOffset));
2361 // Check the sign of the argument. If the argument is positive,
2362 // just return it.
2363 __ tst(tmp, Operand(HeapNumber::kSignMask));
2364 __ b(ne, &negative);
2365 __ mov(tmp, Operand(input));
Alexandre 2011/01/19 16:34:45 In LCodeGen::DoMathAbs we know that input and resu
Mads Ager (chromium) 2011/01/20 07:32:17 Good catch. And that applies on ia32 as well. Chan
2366 __ jmp(&done);
2367
2368 __ bind(&negative);
2369
2370 Label allocated, slow;
2371 __ LoadRoot(scratch, Heap::kHeapNumberMapRootIndex);
Alexandre 2011/01/19 16:34:45 Since we save all registers on the stack, we could
Mads Ager (chromium) 2011/01/20 07:32:17 For this one it is not so clear because the heap n
2372 __ AllocateHeapNumber(tmp, tmp2, tmp3, scratch, &slow);
2373 __ b(&allocated);
2374
2375 // Slow case: Call the runtime system to do the number allocation.
2376 __ bind(&slow);
2377
2378 __ CallRuntimeSaveDoubles(Runtime::kAllocateHeapNumber);
2379 RecordSafepointWithRegisters(
2380 instr->pointer_map(), 0, Safepoint::kNoDeoptimizationIndex);
2381 // Set the pointer to the new heap number in tmp.
2382 if (!tmp.is(r0)) __ mov(tmp, Operand(r0));
2383
2384 // Restore input_reg after call to runtime.
2385 __ ldr(input, MemOperand(sp, SpIndexForPushAll(input) * kPointerSize));
2386
2387 __ bind(&allocated);
2388 __ ldr(tmp2, FieldMemOperand(input, HeapNumber::kExponentOffset));
Alexandre 2011/01/19 16:34:45 Same as before, we could use a scratch register to
Mads Ager (chromium) 2011/01/20 07:32:17 I'd rather not do that because of the runtime call
2389 __ and_(tmp2, tmp2, Operand(~HeapNumber::kSignMask));
Alexandre 2011/01/19 16:34:45 The bic (Bit Clear) instruction would be clearer.
Mads Ager (chromium) 2011/01/20 07:32:17 Done.
2390 __ str(tmp2, FieldMemOperand(tmp, HeapNumber::kExponentOffset));
2391 __ ldr(tmp2, FieldMemOperand(input, HeapNumber::kMantissaOffset));
2392 __ str(tmp2, FieldMemOperand(tmp, HeapNumber::kMantissaOffset));
2393
2394 __ bind(&done);
Alexandre 2011/01/19 16:34:45 Can be moved after the next store, as input and ou
Mads Ager (chromium) 2011/01/20 07:32:17 Done.
2395
2396 __ str(tmp, MemOperand(sp, SpIndexForPushAll(input) * kPointerSize));
Alexandre 2011/01/19 16:34:45 You can use MemOperand MacroAssembler::SafepointR
Mads Ager (chromium) 2011/01/20 07:32:17 Thanks, I'll do that. I have changed kInstrSize to
2397 __ PopSafepointRegisters();
2398 }
2399
2400
2401 void LCodeGen::EmitIntegerMathAbs(LUnaryMathOperation* instr) {
2402 Label is_positive;
2403 uint32_t kSignMask = 0x80000000u;
2404 Register input = ToRegister(instr->input());
2405 __ tst(input, Operand(kSignMask));
2406 __ b(eq, &is_positive);
2407 __ rsb(input, input, Operand(0), SetCC);
Alexandre 2011/01/19 16:34:45 We could remove the is_positive label and the bran
Mads Ager (chromium) 2011/01/20 07:32:17 I find that a little too indirect for my liking. D
2408 // Deoptimize on overflow.
2409 DeoptimizeIf(vs, instr->environment());
2410 __ bind(&is_positive);
2343 } 2411 }
2344 2412
2345 2413
2346 void LCodeGen::DoMathAbs(LUnaryMathOperation* instr) { 2414 void LCodeGen::DoMathAbs(LUnaryMathOperation* instr) {
2347 Abort("DoMathAbs unimplemented."); 2415 // Class for deferred case.
2416 class DeferredMathAbsTaggedHeapNumber: public LDeferredCode {
2417 public:
2418 DeferredMathAbsTaggedHeapNumber(LCodeGen* codegen,
2419 LUnaryMathOperation* instr)
2420 : LDeferredCode(codegen), instr_(instr) { }
2421 virtual void Generate() {
2422 codegen()->DoDeferredMathAbsTaggedHeapNumber(instr_);
2423 }
2424 private:
2425 LUnaryMathOperation* instr_;
2426 };
2427
2428 ASSERT(instr->input()->Equals(instr->result()));
2429 Representation r = instr->hydrogen()->value()->representation();
2430 if (r.IsDouble()) {
2431 DwVfpRegister input = ToDoubleRegister(instr->input());
2432 // __ vabs(input, input);
2433 Abort("Double DoMathAbs unimplemented");
2434 } else if (r.IsInteger32()) {
2435 EmitIntegerMathAbs(instr);
2436 } else {
2437 // Representation is tagged.
2438 DeferredMathAbsTaggedHeapNumber* deferred =
2439 new DeferredMathAbsTaggedHeapNumber(this, instr);
2440 Register input = ToRegister(instr->input());
2441 // Smi check.
2442 __ BranchOnNotSmi(input, deferred->entry());
2443 // If smi, handle it directly.
2444 EmitIntegerMathAbs(instr);
2445 __ bind(deferred->exit());
2446 }
2348 } 2447 }
2349 2448
2350 2449
2351 void LCodeGen::DoMathFloor(LUnaryMathOperation* instr) { 2450 void LCodeGen::DoMathFloor(LUnaryMathOperation* instr) {
2352 DoubleRegister input = ToDoubleRegister(instr->input()); 2451 DoubleRegister input = ToDoubleRegister(instr->input());
2353 Register result = ToRegister(instr->result()); 2452 Register result = ToRegister(instr->result());
2354 Register prev_fpscr = ToRegister(instr->temp()); 2453 Register prev_fpscr = ToRegister(instr->temp());
2355 SwVfpRegister single_scratch = double_scratch0().low(); 2454 SwVfpRegister single_scratch = double_scratch0().low();
2356 Register scratch = scratch0(); 2455 Register scratch = scratch0();
2357 2456
(...skipping 894 matching lines...) Expand 10 before | Expand all | Expand 10 after
3252 3351
3253 3352
3254 void LCodeGen::DoOsrEntry(LOsrEntry* instr) { 3353 void LCodeGen::DoOsrEntry(LOsrEntry* instr) {
3255 Abort("DoOsrEntry unimplemented."); 3354 Abort("DoOsrEntry unimplemented.");
3256 } 3355 }
3257 3356
3258 3357
3259 #undef __ 3358 #undef __
3260 3359
3261 } } // namespace v8::internal 3360 } } // namespace v8::internal
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698