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

Side by Side Diff: runtime/vm/assembler_ia32.cc

Issue 11573044: Inline Doubles truncate and round. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 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 (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "vm/globals.h" 5 #include "vm/globals.h"
6 #if defined(TARGET_ARCH_IA32) 6 #if defined(TARGET_ARCH_IA32)
7 7
8 #include "vm/assembler.h" 8 #include "vm/assembler.h"
9 #include "vm/code_generator.h" 9 #include "vm/code_generator.h"
10 #include "vm/heap.h" 10 #include "vm/heap.h"
(...skipping 791 matching lines...) Expand 10 before | Expand all | Expand 10 after
802 802
803 void Assembler::pxor(XmmRegister dst, XmmRegister src) { 803 void Assembler::pxor(XmmRegister dst, XmmRegister src) {
804 AssemblerBuffer::EnsureCapacity ensured(&buffer_); 804 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
805 EmitUint8(0x66); 805 EmitUint8(0x66);
806 EmitUint8(0x0F); 806 EmitUint8(0x0F);
807 EmitUint8(0xEF); 807 EmitUint8(0xEF);
808 EmitXmmRegisterOperand(dst, src); 808 EmitXmmRegisterOperand(dst, src);
809 } 809 }
810 810
811 811
812 void Assembler::roundsd(XmmRegister dst, XmmRegister src, RoundingMode mode) {
813 ASSERT(CPUFeatures::sse4_1_supported());
814 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
815 EmitUint8(0x66);
816 EmitUint8(0x0F);
817 EmitUint8(0x3A);
818 EmitUint8(0x0B);
819 EmitXmmRegisterOperand(dst, src);
820 // Mask precision exeption.
821 EmitUint8(static_cast<uint8_t>(mode) | 0x8);
822 }
823
824
812 void Assembler::fldl(const Address& src) { 825 void Assembler::fldl(const Address& src) {
813 AssemblerBuffer::EnsureCapacity ensured(&buffer_); 826 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
814 EmitUint8(0xDD); 827 EmitUint8(0xDD);
815 EmitOperand(0, src); 828 EmitOperand(0, src);
816 } 829 }
817 830
818 831
819 void Assembler::fstpl(const Address& dst) { 832 void Assembler::fstpl(const Address& dst) {
820 AssemblerBuffer::EnsureCapacity ensured(&buffer_); 833 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
821 EmitUint8(0xDD); 834 EmitUint8(0xDD);
(...skipping 899 matching lines...) Expand 10 before | Expand all | Expand 10 after
1721 void Assembler::DoubleAbs(XmmRegister reg) { 1734 void Assembler::DoubleAbs(XmmRegister reg) {
1722 static const struct ALIGN16 { 1735 static const struct ALIGN16 {
1723 uint64_t a; 1736 uint64_t a;
1724 uint64_t b; 1737 uint64_t b;
1725 } double_abs_constant = 1738 } double_abs_constant =
1726 {0x7FFFFFFFFFFFFFFFLL, 0x7FFFFFFFFFFFFFFFLL}; 1739 {0x7FFFFFFFFFFFFFFFLL, 0x7FFFFFFFFFFFFFFFLL};
1727 andpd(reg, Address::Absolute(reinterpret_cast<uword>(&double_abs_constant))); 1740 andpd(reg, Address::Absolute(reinterpret_cast<uword>(&double_abs_constant)));
1728 } 1741 }
1729 1742
1730 1743
1744 void Assembler::DoubleRound(XmmRegister dst, XmmRegister src, XmmRegister tmp) {
1745 ASSERT(tmp != src);
1746 static double kZeroFiveConst = 0.5;
1747 static double kNegZeroFiveConst = -0.5;
1748 Label is_negative, round;
1749 if (src != dst) {
1750 movsd(dst, src);
1751 }
1752 pxor(tmp, tmp);
1753 comisd(src, tmp);
1754 j(BELOW, &is_negative, Assembler::kNearJump);
1755 addsd(dst,
1756 Address::Absolute(reinterpret_cast<uword>(&kZeroFiveConst)));
1757 jmp(&round, Assembler::kNearJump);
1758 Bind(&is_negative);
1759 addsd(dst,
1760 Address::Absolute(reinterpret_cast<uword>(&kNegZeroFiveConst)));
1761 Bind(&round);
1762 roundsd(dst, dst, Assembler::kRoundToZero);
Florian Schneider 2013/01/08 14:24:04 truncate(x+0.5) does not work for some corner case
srdjan 2013/01/10 22:35:52 No, it doesn't. Round to nearest rounds 0.5 to 0 i
1763 }
1764
1765
1731 void Assembler::EnterFrame(intptr_t frame_size) { 1766 void Assembler::EnterFrame(intptr_t frame_size) {
1732 if (prologue_offset_ == -1) { 1767 if (prologue_offset_ == -1) {
1733 prologue_offset_ = CodeSize(); 1768 prologue_offset_ = CodeSize();
1734 } 1769 }
1735 pushl(EBP); 1770 pushl(EBP);
1736 movl(EBP, ESP); 1771 movl(EBP, ESP);
1737 if (frame_size != 0) { 1772 if (frame_size != 0) {
1738 Immediate frame_space(frame_size); 1773 Immediate frame_space(frame_size);
1739 subl(ESP, frame_space); 1774 subl(ESP, frame_space);
1740 } 1775 }
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after
2057 2092
2058 const char* Assembler::XmmRegisterName(XmmRegister reg) { 2093 const char* Assembler::XmmRegisterName(XmmRegister reg) {
2059 ASSERT((0 <= reg) && (reg < kNumberOfXmmRegisters)); 2094 ASSERT((0 <= reg) && (reg < kNumberOfXmmRegisters));
2060 return xmm_reg_names[reg]; 2095 return xmm_reg_names[reg];
2061 } 2096 }
2062 2097
2063 2098
2064 } // namespace dart 2099 } // namespace dart
2065 2100
2066 #endif // defined TARGET_ARCH_IA32 2101 #endif // defined TARGET_ARCH_IA32
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698