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

Side by Side Diff: src/mips64/simulator-mips64.cc

Issue 1691763002: MIPS: Refine 'MIPS: Fix FPU min, max, mina, maxa in simulator.' (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 10 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
« no previous file with comments | « src/mips64/simulator-mips64.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <limits.h> 5 #include <limits.h>
6 #include <stdarg.h> 6 #include <stdarg.h>
7 #include <stdlib.h> 7 #include <stdlib.h>
8 #include <cmath> 8 #include <cmath>
9 9
10 #if V8_TARGET_ARCH_MIPS64 10 #if V8_TARGET_ARCH_MIPS64
(...skipping 2315 matching lines...) Expand 10 before | Expand all | Expand 10 after
2326 } 2326 }
2327 } 2327 }
2328 } 2328 }
2329 2329
2330 2330
2331 void Simulator::SignalException(Exception e) { 2331 void Simulator::SignalException(Exception e) {
2332 V8_Fatal(__FILE__, __LINE__, "Error: Exception %i raised.", 2332 V8_Fatal(__FILE__, __LINE__, "Error: Exception %i raised.",
2333 static_cast<int>(e)); 2333 static_cast<int>(e));
2334 } 2334 }
2335 2335
2336 // Min/Max template functions for Double and Single arguments.
2337
2336 template <typename T> 2338 template <typename T>
2337 T FPAbs(T a); 2339 static T FPAbs(T a);
2338 2340
2339 template <> 2341 template <>
2340 double FPAbs<double>(double a) { 2342 double FPAbs<double>(double a) {
2341 return fabs(a); 2343 return fabs(a);
2342 } 2344 }
2343 2345
2344 template <> 2346 template <>
2345 float FPAbs<float>(float a) { 2347 float FPAbs<float>(float a) {
2346 return fabsf(a); 2348 return fabsf(a);
2347 } 2349 }
2348 2350
2349 template <typename T> 2351 template <typename T>
2350 bool Simulator::FPUProcessNaNsAndZeros(T a, T b, IsMin min, T& result) { 2352 static bool FPUProcessNaNsAndZeros(T a, T b, MaxMinKind kind, T& result) {
2351 if (std::isnan(a) && std::isnan(b)) { 2353 if (std::isnan(a) && std::isnan(b)) {
2352 result = a; 2354 result = a;
2353 } else if (std::isnan(a)) { 2355 } else if (std::isnan(a)) {
2354 result = b; 2356 result = b;
2355 } else if (std::isnan(b)) { 2357 } else if (std::isnan(b)) {
2356 result = a; 2358 result = a;
2357 } else if (b == a) { 2359 } else if (b == a) {
2358 // Handle -0.0 == 0.0 case. 2360 // Handle -0.0 == 0.0 case.
2359 // std::signbit() returns int 0 or 1 so substracting IsMin::kMax negates the 2361 // std::signbit() returns int 0 or 1 so substracting MaxMinKind::kMax
2360 // result. 2362 // negates the result.
2361 result = std::signbit(b) - static_cast<int>(min) ? b : a; 2363 result = std::signbit(b) - static_cast<int>(kind) ? b : a;
2362 } else { 2364 } else {
2363 return false; 2365 return false;
2364 } 2366 }
2365 return true; 2367 return true;
2366 } 2368 }
2367 2369
2368 template <typename T> 2370 template <typename T>
2369 T Simulator::FPUMin(T a, T b) { 2371 static T FPUMin(T a, T b) {
2370 T result; 2372 T result;
2371 if (FPUProcessNaNsAndZeros(a, b, IsMin::kMin, result)) { 2373 if (FPUProcessNaNsAndZeros(a, b, MaxMinKind::kMin, result)) {
2372 return result; 2374 return result;
2373 } else { 2375 } else {
2374 return b < a ? b : a; 2376 return b < a ? b : a;
2375 } 2377 }
2376 } 2378 }
2377 2379
2378 template <typename T> 2380 template <typename T>
2379 T Simulator::FPUMax(T a, T b) { 2381 static T FPUMax(T a, T b) {
2380 T result; 2382 T result;
2381 if (FPUProcessNaNsAndZeros(a, b, IsMin::kMax, result)) { 2383 if (FPUProcessNaNsAndZeros(a, b, MaxMinKind::kMax, result)) {
2382 return result; 2384 return result;
2383 } else { 2385 } else {
2384 return b > a ? b : a; 2386 return b > a ? b : a;
2385 } 2387 }
2386 } 2388 }
2387 2389
2388 template <typename T> 2390 template <typename T>
2389 T Simulator::FPUMinA(T a, T b) { 2391 static T FPUMinA(T a, T b) {
2390 T result; 2392 T result;
2391 if (!FPUProcessNaNsAndZeros(a, b, IsMin::kMin, result)) { 2393 if (!FPUProcessNaNsAndZeros(a, b, MaxMinKind::kMin, result)) {
2392 if (FPAbs(a) < FPAbs(b)) { 2394 if (FPAbs(a) < FPAbs(b)) {
2393 result = a; 2395 result = a;
2394 } else if (FPAbs(b) < FPAbs(a)) { 2396 } else if (FPAbs(b) < FPAbs(a)) {
2395 result = b; 2397 result = b;
2396 } else { 2398 } else {
2397 result = a < b ? a : b; 2399 result = a < b ? a : b;
2398 } 2400 }
2399 } 2401 }
2400 return result; 2402 return result;
2401 } 2403 }
2402 2404
2403 template <typename T> 2405 template <typename T>
2404 T Simulator::FPUMaxA(T a, T b) { 2406 static T FPUMaxA(T a, T b) {
2405 T result; 2407 T result;
2406 if (!FPUProcessNaNsAndZeros(a, b, IsMin::kMin, result)) { 2408 if (!FPUProcessNaNsAndZeros(a, b, MaxMinKind::kMin, result)) {
2407 if (FPAbs(a) > FPAbs(b)) { 2409 if (FPAbs(a) > FPAbs(b)) {
2408 result = a; 2410 result = a;
2409 } else if (FPAbs(b) > FPAbs(a)) { 2411 } else if (FPAbs(b) > FPAbs(a)) {
2410 result = b; 2412 result = b;
2411 } else { 2413 } else {
2412 result = a > b ? a : b; 2414 result = a > b ? a : b;
2413 } 2415 }
2414 } 2416 }
2415 return result; 2417 return result;
2416 } 2418 }
(...skipping 2444 matching lines...) Expand 10 before | Expand all | Expand 10 after
4861 } 4863 }
4862 4864
4863 4865
4864 #undef UNSUPPORTED 4866 #undef UNSUPPORTED
4865 } // namespace internal 4867 } // namespace internal
4866 } // namespace v8 4868 } // namespace v8
4867 4869
4868 #endif // USE_SIMULATOR 4870 #endif // USE_SIMULATOR
4869 4871
4870 #endif // V8_TARGET_ARCH_MIPS64 4872 #endif // V8_TARGET_ARCH_MIPS64
OLDNEW
« no previous file with comments | « src/mips64/simulator-mips64.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698