Index: runtime/szrt.c |
diff --git a/runtime/szrt.c b/runtime/szrt.c |
index 472175860b7bb1ea8c33f6c8973b7150038252b4..8e094bc58a19c556860aa047053a208bd6b5a74f 100644 |
--- a/runtime/szrt.c |
+++ b/runtime/szrt.c |
@@ -7,17 +7,37 @@ |
// |
//===----------------------------------------------------------------------===// |
// |
-// This file implements the runtime helper routines that are needed by |
-// Subzero. This needs to be compiled by some non-Subzero compiler. |
+// This file implements wrappers for particular bitcode instructions |
+// that are too uncommon and complex for a particular target to bother |
+// implementing directly in Subzero target lowering. This needs to be |
+// compiled by some non-Subzero compiler. |
// |
//===----------------------------------------------------------------------===// |
#include <stdint.h> |
#include <stdlib.h> |
-uint32_t cvtftoui32(float value) { return (uint32_t)value; } |
+// TODO(stichnot): The various NaN cross tests try to map Subzero's |
+// undefined behavior to the same as llc's undefined behavior, as |
+// observed by the cross tests. This will have to be kept up to date |
+// with any future changes to llc, and may also have to be different |
+// for different targets. It would be better to find a more |
+// appropriate set of llc options when building the Subzero runtime. |
+// |
+// We test for NaN using "value==value" instead of using isnan(value) |
+// to avoid an external dependency on fpclassify(). |
+ |
+uint32_t cvtftoui32(float value) { |
+ if (value == value) // NaNaN |
+ return (uint32_t)value; |
+ return 0x80000000; |
+} |
-uint32_t cvtdtoui32(double value) { return (uint32_t)value; } |
+uint32_t cvtdtoui32(double value) { |
+ if (value == value) // NaNaN |
+ return (uint32_t)value; |
+ return 0x80000000; |
+} |
int64_t cvtftosi64(float value) { return (int64_t)value; } |