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

Side by Side Diff: src/x64/macro-assembler-x64.cc

Issue 7014033: Support conversion of clamped double values for pixel arrays in Crankshaft. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: tweaks Created 9 years, 7 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 2552 matching lines...) Expand 10 before | Expand all | Expand 10 after
2563 Label* fail, 2563 Label* fail,
2564 bool is_heap_object) { 2564 bool is_heap_object) {
2565 if (!is_heap_object) { 2565 if (!is_heap_object) {
2566 JumpIfSmi(obj, fail); 2566 JumpIfSmi(obj, fail);
2567 } 2567 }
2568 Cmp(FieldOperand(obj, HeapObject::kMapOffset), map); 2568 Cmp(FieldOperand(obj, HeapObject::kMapOffset), map);
2569 j(not_equal, fail); 2569 j(not_equal, fail);
2570 } 2570 }
2571 2571
2572 2572
2573 void MacroAssembler::ClampUint8(Register reg) {
2574 Label done;
2575 testl(reg, Immediate(0xFFFFFF00));
2576 j(zero, &done, Label::kNear);
2577 setcc(negative, reg); // 1 if negative, 0 if positive.
2578 decb(reg); // 0 if negative, 255 if positive.
2579 bind(&done);
2580 }
2581
2582
2583 void MacroAssembler::ClampDoubleToUint8(XMMRegister input_reg,
2584 XMMRegister temp_xmm_reg,
2585 Register result_reg,
2586 Register temp_reg) {
2587 Label above_zero;
2588 Label done;
2589 Label in_bounds;
2590 xorps(temp_xmm_reg, temp_xmm_reg);
2591 ucomisd(input_reg, temp_xmm_reg);
2592 j(above, &above_zero, Label::kNear);
Lasse Reichstein 2011/05/14 09:34:38 I believe NaN should also be converted to zero (i.
danno 2011/05/15 05:50:27 NaN does get set to zero, there is an explicit tes
Lasse Reichstein 2011/05/15 10:18:50 Ack, yes. I didn't consider that "above" would als
2593 Set(result_reg, 0);
Lasse Reichstein 2011/05/13 13:17:24 How about setting result to 0 prior to the compare
danno 2011/05/15 05:50:27 Done.
2594 jmp(&done, Label::kNear);
2595 bind(&above_zero);
2596 uint64_t max_clamp = BitCast<uint64_t, double>(255.0);
Lasse Reichstein 2011/05/13 13:17:24 How about not capping at 255 until after you have
danno 2011/05/15 05:50:27 Done.
2597 Set(temp_reg, max_clamp);
2598 movq(temp_xmm_reg, temp_reg);
Lasse Reichstein 2011/05/13 13:17:24 Use movsd here. Movq makes the CPU think the XMM r
danno 2011/05/15 05:50:27 Done.
2599 ucomisd(input_reg, temp_xmm_reg);
2600 j(below_equal, &in_bounds, Label::kNear);
2601 Set(result_reg, 255);
2602 jmp(&done, Label::kNear);
2603 bind(&in_bounds);
2604 if (CpuFeatures::IsSupported(SSE4_1)) {
2605 CpuFeatures::Scope scope(SSE4_1);
2606 roundsd(temp_xmm_reg, input_reg, kRoundToNearest);
Lasse Reichstein 2011/05/13 13:17:24 Roundsd's round-to-nearest rounds to even numbers
Lasse Reichstein 2011/05/14 09:34:38 I tried to look up a spec for typed arrays, and if
danno 2011/05/15 05:50:27 Done.
danno 2011/05/15 05:50:27 This code is specifically for CanvasPixelArrays (w
Lasse Reichstein 2011/05/15 10:18:50 I read that as clamping positions to the edge of t
2607 } else {
2608 uint64_t one_half = BitCast<uint64_t, double>(0.5);
2609 Set(temp_reg, one_half);
2610 movq(temp_xmm_reg, temp_reg);
Lasse Reichstein 2011/05/13 13:17:24 Movsd.
danno 2011/05/15 05:50:27 Done.
2611 addsd(temp_xmm_reg, input_reg);
Lasse Reichstein 2011/05/13 13:17:24 Adding 0.5 and truncating doesn't work perfectly a
danno 2011/05/15 05:50:27 I am aware of this imprecision, but this is exactl
Lasse Reichstein 2011/05/15 10:18:51 Good :)
2612 }
2613 cvttsd2si(result_reg, temp_xmm_reg);
2614 bind(&done);
2615 }
2616
2617
2573 void MacroAssembler::AbortIfNotNumber(Register object) { 2618 void MacroAssembler::AbortIfNotNumber(Register object) {
2574 Label ok; 2619 Label ok;
2575 Condition is_smi = CheckSmi(object); 2620 Condition is_smi = CheckSmi(object);
2576 j(is_smi, &ok, Label::kNear); 2621 j(is_smi, &ok, Label::kNear);
2577 Cmp(FieldOperand(object, HeapObject::kMapOffset), 2622 Cmp(FieldOperand(object, HeapObject::kMapOffset),
2578 isolate()->factory()->heap_number_map()); 2623 isolate()->factory()->heap_number_map());
2579 Assert(equal, "Operand not a number"); 2624 Assert(equal, "Operand not a number");
2580 bind(&ok); 2625 bind(&ok);
2581 } 2626 }
2582 2627
(...skipping 1070 matching lines...) Expand 10 before | Expand all | Expand 10 after
3653 CPU::FlushICache(address_, size_); 3698 CPU::FlushICache(address_, size_);
3654 3699
3655 // Check that the code was patched as expected. 3700 // Check that the code was patched as expected.
3656 ASSERT(masm_.pc_ == address_ + size_); 3701 ASSERT(masm_.pc_ == address_ + size_);
3657 ASSERT(masm_.reloc_info_writer.pos() == address_ + size_ + Assembler::kGap); 3702 ASSERT(masm_.reloc_info_writer.pos() == address_ + size_ + Assembler::kGap);
3658 } 3703 }
3659 3704
3660 } } // namespace v8::internal 3705 } } // namespace v8::internal
3661 3706
3662 #endif // V8_TARGET_ARCH_X64 3707 #endif // V8_TARGET_ARCH_X64
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698