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

Unified Diff: src/conversions-inl.h

Issue 6881003: Prevent deopt when assigning double values to typed arrays (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Fixes to make ia32 tests run Created 9 years, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/conversions.h ('k') | src/hydrogen.cc » ('j') | src/hydrogen.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/conversions-inl.h
diff --git a/src/conversions-inl.h b/src/conversions-inl.h
index cb7dbf88d2a32d7f132fcc5e9e76da60102b461e..eed64cd26f89668b86122c4963a261a2947d9475 100644
--- a/src/conversions-inl.h
+++ b/src/conversions-inl.h
@@ -1,4 +1,4 @@
-// Copyright 2006-2008 the V8 project authors. All rights reserved.
+// Copyright 2011 the V8 project authors. All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
@@ -77,6 +77,20 @@ static inline double DoubleToInteger(double x) {
}
+uint8_t ClampToUInt8(double double_value) {
+ if (!(double_value > 0)) {
+ // NaN and less than zero clamp to zero.
+ return 0;
+ } else if (double_value > 255) {
+ // Greater than 255 clamp to 255.
+ return 255;
+ } else {
+ // Other doubles are rounded to the nearest integer.
+ return static_cast<uint8_t>(double_value + 0.5);
+ }
+}
+
+
int32_t NumberToInt32(Object* number) {
if (number->IsSmi()) return Smi::cast(number)->value();
return DoubleToInt32(number->Number());
@@ -89,6 +103,28 @@ uint32_t NumberToUint32(Object* number) {
}
+uint8_t NumberToClampedUInt8(Object* number)
+{
+ if (number->IsSmi()) {
+ int32_t value = Smi::cast(number)->value();
+ if (value < 0) {
+ return 0;
+ } else if (value > 255) {
+ return 255;
+ } else {
+ return static_cast<uint8_t>(value);
+ }
+ } else if (number->IsHeapNumber()) {
+ return ClampToUInt8(number->Number());
+ } else {
+ // Clamp undefined to zero (default). All other types have been
+ // converted to a number type further up in the call chain.
+ ASSERT(number->IsUndefined());
+ return 0;
+ }
+}
+
+
int32_t DoubleToInt32(double x) {
int32_t i = FastD2I(x);
if (FastI2D(i) == x) return i;
« no previous file with comments | « src/conversions.h ('k') | src/hydrogen.cc » ('j') | src/hydrogen.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698