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

Side by Side Diff: runtime/vm/assembler_mips_test.cc

Issue 13722022: Adds macros to the MIPS assembler for detecting overflow. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 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 unified diff | Download patch | Annotate | Revision Log
« runtime/vm/assembler_mips.h ('K') | « runtime/vm/assembler_mips.cc ('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 (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 1023 matching lines...) Expand 10 before | Expand all | Expand 10 after
1034 __ jalr(R2, RA); 1034 __ jalr(R2, RA);
1035 __ delay_slot()->ori(V0, ZR, Immediate(42)); 1035 __ delay_slot()->ori(V0, ZR, Immediate(42));
1036 } 1036 }
1037 1037
1038 1038
1039 ASSEMBLER_TEST_RUN(Jalr_delay, test) { 1039 ASSEMBLER_TEST_RUN(Jalr_delay, test) {
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
1045 ASSEMBLER_TEST_GENERATE(AddOverflow_detect, assembler) {
1046 Register left = T0;
1047 Register right = T1;
1048 Register result = T2;
1049 Register overflow = T3;
1050 Register scratch = T4;
1051 Label error, done;
1052
1053 __ LoadImmediate(V0, 1); // Success value.
1054
1055 __ LoadImmediate(left, 0x7fffffff);
1056 __ LoadImmediate(right, 1);
1057 __ AdduDetectOverflow(result, left, right, overflow, scratch);
1058 __ bgez(T3, &error); // INT_MAX + 1 overflows.
1059
1060 __ LoadImmediate(left, 0x7fffffff);
1061 __ LoadImmediate(right, 0x7fffffff);
1062 __ AdduDetectOverflow(result, left, right, overflow, scratch);
1063 __ bgez(T3, &error); // INT_MAX + INT_MAX overflows.
1064
1065 __ LoadImmediate(left, 0x7fffffff);
1066 __ LoadImmediate(right, -1);
1067 __ AdduDetectOverflow(result, left, right, overflow, scratch);
1068 __ bltz(T3, &error); // INT_MAX - 1 does not overflow.
1069
1070 __ LoadImmediate(left, -1);
1071 __ LoadImmediate(right, 1);
1072 __ AdduDetectOverflow(result, left, right, overflow, scratch);
1073 __ bltz(T3, &error); // -1 + 1 does not overflow.
1074
1075 __ LoadImmediate(left, 123456);
1076 __ LoadImmediate(right, 654321);
1077 __ AdduDetectOverflow(result, left, right, overflow, scratch);
1078 __ bltz(T3, &error); // 123456 + 654321 does not overflow.
1079
1080 __ LoadImmediate(left, 0x80000000);
1081 __ LoadImmediate(right, -1);
1082 __ AdduDetectOverflow(result, left, right, overflow, scratch);
1083 __ bgez(T3, &error); // INT_MIN - 1 overflows.
1084
1085 __ LoadImmediate(left, 0x80000000);
1086 __ LoadImmediate(right, 0x80000000);
1087 __ AdduDetectOverflow(result, left, right, overflow, scratch);
1088 __ bgez(T3, &error); // INT_MIN + INT_MIN overflows.
1089
1090 __ LoadImmediate(left, -123456);
1091 __ LoadImmediate(right, -654321);
1092 __ AdduDetectOverflow(result, left, right, overflow, scratch);
1093 __ bltz(T3, &error); // -123456 + -654321 does not overflow.
1094
1095 __ b(&done);
1096 __ Bind(&error);
1097 __ mov(V0, ZR);
1098 __ Bind(&done);
1099 __ Ret();
1100 }
1101
1102
1103 ASSEMBLER_TEST_RUN(AddOverflow_detect, test) {
1104 typedef int (*SimpleCode)();
1105 EXPECT_EQ(1, EXECUTE_TEST_CODE_INT32(SimpleCode, test->entry()));
1106 }
1107
1044 } // namespace dart 1108 } // namespace dart
1045 1109
1046 #endif // defined TARGET_ARCH_MIPS 1110 #endif // defined TARGET_ARCH_MIPS
OLDNEW
« runtime/vm/assembler_mips.h ('K') | « runtime/vm/assembler_mips.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698