Modify FastD2I to use static_cast instead of lrint(). Benchmarks show that it's much faster this way.
Review URL: http://codereview.chromium.org/1128010 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@4223 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
This commit is contained in:
parent
17665cafbe
commit
f08648dc4c
@ -41,24 +41,6 @@
|
|||||||
namespace v8 {
|
namespace v8 {
|
||||||
namespace internal {
|
namespace internal {
|
||||||
|
|
||||||
// The fast double-to-int conversion routine does not guarantee
|
|
||||||
// rounding towards zero.
|
|
||||||
static inline int FastD2I(double x) {
|
|
||||||
#ifdef __USE_ISOC99
|
|
||||||
// The ISO C99 standard defines the lrint() function which rounds a
|
|
||||||
// double to an integer according to the current rounding direction.
|
|
||||||
return lrint(x);
|
|
||||||
#else
|
|
||||||
// This is incredibly slow on Intel x86. The reason is that rounding
|
|
||||||
// towards zero is implied by the C standard. This means that the
|
|
||||||
// status register of the FPU has to be changed with the 'fldcw'
|
|
||||||
// instruction. This completely stalls the pipeline and takes many
|
|
||||||
// hundreds of clock cycles.
|
|
||||||
return static_cast<int>(x);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// The fast double-to-unsigned-int conversion routine does not guarantee
|
// The fast double-to-unsigned-int conversion routine does not guarantee
|
||||||
// rounding towards zero, or any reasonable value if the argument is larger
|
// rounding towards zero, or any reasonable value if the argument is larger
|
||||||
// than what fits in an unsigned 32-bit integer.
|
// than what fits in an unsigned 32-bit integer.
|
||||||
|
@ -36,7 +36,12 @@ namespace internal {
|
|||||||
// rounding towards zero.
|
// rounding towards zero.
|
||||||
// The result is unspecified if x is infinite or NaN, or if the rounded
|
// The result is unspecified if x is infinite or NaN, or if the rounded
|
||||||
// integer value is outside the range of type int.
|
// integer value is outside the range of type int.
|
||||||
static inline int FastD2I(double x);
|
static inline int FastD2I(double x) {
|
||||||
|
// The static_cast convertion from double to int used to be slow, but
|
||||||
|
// as new benchmarks show, now it is much faster than lrint().
|
||||||
|
return static_cast<int>(x);
|
||||||
|
}
|
||||||
|
|
||||||
static inline unsigned int FastD2UI(double x);
|
static inline unsigned int FastD2UI(double x);
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user