Index: runtime/lib/simd128.cc |
diff --git a/runtime/lib/simd128.cc b/runtime/lib/simd128.cc |
index f1563b8415a0b93505079001d7abc24947987313..8f3cc3ec0610d836570c65dfa9e36ae0377f9e16 100644 |
--- a/runtime/lib/simd128.cc |
+++ b/runtime/lib/simd128.cc |
@@ -195,14 +195,16 @@ DEFINE_NATIVE_ENTRY(Float32x4_clamp, 3) { |
GET_NON_NULL_NATIVE_ARGUMENT(Float32x4, self, arguments->NativeArgAt(0)); |
GET_NON_NULL_NATIVE_ARGUMENT(Float32x4, lo, arguments->NativeArgAt(1)); |
GET_NON_NULL_NATIVE_ARGUMENT(Float32x4, hi, arguments->NativeArgAt(2)); |
- float _x = self.x() > lo.x() ? self.x() : lo.x(); |
- float _y = self.y() > lo.y() ? self.y() : lo.y(); |
- float _z = self.z() > lo.z() ? self.z() : lo.z(); |
- float _w = self.w() > lo.w() ? self.w() : lo.w(); |
- _x = _x > hi.x() ? hi.x() : _x; |
- _y = _y > hi.y() ? hi.y() : _y; |
- _z = _z > hi.z() ? hi.z() : _z; |
- _w = _w > hi.w() ? hi.w() : _w; |
+ // The order of the clamping must match the order of the optimized code: |
+ // MAX(MIN(self, hi), lo). |
+ float _x = self.x() < hi.x() ? self.x() : hi.x(); |
+ float _y = self.y() < hi.y() ? self.y() : hi.y(); |
+ float _z = self.z() < hi.z() ? self.z() : hi.z(); |
+ float _w = self.w() < hi.w() ? self.w() : hi.w(); |
+ _x = _x < lo.x() ? lo.x() : _x; |
+ _y = _y < lo.y() ? lo.y() : _y; |
+ _z = _z < lo.z() ? lo.z() : _z; |
+ _w = _w < lo.w() ? lo.w() : _w; |
return Float32x4::New(_x, _y, _z, _w); |
} |