OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #include "vm/globals.h" | 5 #include "vm/globals.h" |
6 #if defined(TARGET_ARCH_MIPS) | 6 #if defined(TARGET_ARCH_MIPS) |
7 | 7 |
8 #include "vm/assembler.h" | 8 #include "vm/assembler.h" |
9 #include "vm/os.h" | 9 #include "vm/os.h" |
10 #include "vm/unit_test.h" | 10 #include "vm/unit_test.h" |
(...skipping 1029 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1040 typedef int (*SimpleCode)(); | 1040 typedef int (*SimpleCode)(); |
1041 EXPECT_EQ(42, EXECUTE_TEST_CODE_INT32(SimpleCode, test->entry())); | 1041 EXPECT_EQ(42, EXECUTE_TEST_CODE_INT32(SimpleCode, test->entry())); |
1042 } | 1042 } |
1043 | 1043 |
1044 | 1044 |
1045 ASSEMBLER_TEST_GENERATE(AddOverflow_detect, assembler) { | 1045 ASSEMBLER_TEST_GENERATE(AddOverflow_detect, assembler) { |
1046 Register left = T0; | 1046 Register left = T0; |
1047 Register right = T1; | 1047 Register right = T1; |
1048 Register result = T2; | 1048 Register result = T2; |
1049 Register overflow = T3; | 1049 Register overflow = T3; |
1050 Register scratch = T4; | |
1051 Label error, done; | 1050 Label error, done; |
1052 | 1051 |
1053 __ LoadImmediate(V0, 1); // Success value. | 1052 __ LoadImmediate(V0, 1); // Success value. |
1054 | 1053 |
1055 __ LoadImmediate(left, 0x7fffffff); | 1054 __ LoadImmediate(left, 0x7fffffff); |
1056 __ LoadImmediate(right, 1); | 1055 __ LoadImmediate(right, 1); |
1057 __ AdduDetectOverflow(result, left, right, overflow); | 1056 __ AdduDetectOverflow(result, left, right, overflow); |
1058 __ bgez(overflow, &error); // INT_MAX + 1 overflows. | 1057 __ bgez(overflow, &error); // INT_MAX + 1 overflows. |
1059 | 1058 |
1060 __ LoadImmediate(left, 0x7fffffff); | 1059 __ LoadImmediate(left, 0x7fffffff); |
(...skipping 14 matching lines...) Expand all Loading... |
1075 __ LoadImmediate(right, 654321); | 1074 __ LoadImmediate(right, 654321); |
1076 __ AdduDetectOverflow(result, left, right, overflow); | 1075 __ AdduDetectOverflow(result, left, right, overflow); |
1077 __ bltz(overflow, &error); // 123456 + 654321 does not overflow. | 1076 __ bltz(overflow, &error); // 123456 + 654321 does not overflow. |
1078 | 1077 |
1079 __ LoadImmediate(left, 0x80000000); | 1078 __ LoadImmediate(left, 0x80000000); |
1080 __ LoadImmediate(right, -1); | 1079 __ LoadImmediate(right, -1); |
1081 __ AdduDetectOverflow(result, left, right, overflow); | 1080 __ AdduDetectOverflow(result, left, right, overflow); |
1082 __ bgez(overflow, &error); // INT_MIN - 1 overflows. | 1081 __ bgez(overflow, &error); // INT_MIN - 1 overflows. |
1083 | 1082 |
1084 // result has 0x7fffffff. | 1083 // result has 0x7fffffff. |
1085 __ AdduDetectOverflow(result, result, result, overflow, scratch); | 1084 __ AdduDetectOverflow(result, result, result, overflow); |
1086 __ bgez(overflow, &error); // INT_MAX + INT_MAX overflows. | 1085 __ bgez(overflow, &error); // INT_MAX + INT_MAX overflows. |
1087 | 1086 |
1088 __ LoadImmediate(left, 0x80000000); | 1087 __ LoadImmediate(left, 0x80000000); |
1089 __ LoadImmediate(right, 0x80000000); | 1088 __ LoadImmediate(right, 0x80000000); |
1090 __ AdduDetectOverflow(result, left, right, overflow); | 1089 __ AdduDetectOverflow(result, left, right, overflow); |
1091 __ bgez(overflow, &error); // INT_MIN + INT_MIN overflows. | 1090 __ bgez(overflow, &error); // INT_MIN + INT_MIN overflows. |
1092 | 1091 |
1093 __ LoadImmediate(left, -123456); | 1092 __ LoadImmediate(left, -123456); |
1094 __ LoadImmediate(right, -654321); | 1093 __ LoadImmediate(right, -654321); |
1095 __ AdduDetectOverflow(result, left, right, overflow); | 1094 __ AdduDetectOverflow(result, left, right, overflow); |
1096 __ bltz(overflow, &error); // -123456 + -654321 does not overflow. | 1095 __ bltz(overflow, &error); // -123456 + -654321 does not overflow. |
1097 | 1096 |
1098 __ b(&done); | 1097 __ b(&done); |
1099 __ Bind(&error); | 1098 __ Bind(&error); |
1100 __ mov(V0, ZR); | 1099 __ mov(V0, ZR); |
1101 __ Bind(&done); | 1100 __ Bind(&done); |
1102 __ Ret(); | 1101 __ Ret(); |
1103 } | 1102 } |
1104 | 1103 |
1105 | 1104 |
1106 ASSEMBLER_TEST_RUN(AddOverflow_detect, test) { | 1105 ASSEMBLER_TEST_RUN(AddOverflow_detect, test) { |
1107 typedef int (*SimpleCode)(); | 1106 typedef int (*SimpleCode)(); |
1108 EXPECT_EQ(1, EXECUTE_TEST_CODE_INT32(SimpleCode, test->entry())); | 1107 EXPECT_EQ(1, EXECUTE_TEST_CODE_INT32(SimpleCode, test->entry())); |
1109 } | 1108 } |
1110 | 1109 |
1111 } // namespace dart | 1110 } // namespace dart |
1112 | 1111 |
1113 #endif // defined TARGET_ARCH_MIPS | 1112 #endif // defined TARGET_ARCH_MIPS |
OLD | NEW |