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

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
« no previous file with comments | « 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);
1058 __ bgez(overflow, &error); // INT_MAX + 1 overflows.
1059
1060 __ LoadImmediate(left, 0x7fffffff);
1061 __ AdduDetectOverflow(result, left, left, overflow);
1062 __ bgez(overflow, &error); // INT_MAX + INT_MAX overflows.
1063
1064 __ LoadImmediate(left, 0x7fffffff);
1065 __ LoadImmediate(right, -1);
1066 __ AdduDetectOverflow(result, left, right, overflow);
1067 __ bltz(overflow, &error); // INT_MAX - 1 does not overflow.
1068
1069 __ LoadImmediate(left, -1);
1070 __ LoadImmediate(right, 1);
1071 __ AdduDetectOverflow(result, left, right, overflow);
1072 __ bltz(overflow, &error); // -1 + 1 does not overflow.
1073
1074 __ LoadImmediate(left, 123456);
1075 __ LoadImmediate(right, 654321);
1076 __ AdduDetectOverflow(result, left, right, overflow);
1077 __ bltz(overflow, &error); // 123456 + 654321 does not overflow.
1078
1079 __ LoadImmediate(left, 0x80000000);
1080 __ LoadImmediate(right, -1);
1081 __ AdduDetectOverflow(result, left, right, overflow);
1082 __ bgez(overflow, &error); // INT_MIN - 1 overflows.
1083
1084 // result has 0x7fffffff.
1085 __ AdduDetectOverflow(result, result, result, overflow, scratch);
1086 __ bgez(overflow, &error); // INT_MAX + INT_MAX overflows.
1087
1088 __ LoadImmediate(left, 0x80000000);
1089 __ LoadImmediate(right, 0x80000000);
1090 __ AdduDetectOverflow(result, left, right, overflow);
1091 __ bgez(overflow, &error); // INT_MIN + INT_MIN overflows.
1092
1093 __ LoadImmediate(left, -123456);
1094 __ LoadImmediate(right, -654321);
1095 __ AdduDetectOverflow(result, left, right, overflow);
1096 __ bltz(overflow, &error); // -123456 + -654321 does not overflow.
1097
1098 __ b(&done);
1099 __ Bind(&error);
1100 __ mov(V0, ZR);
1101 __ Bind(&done);
1102 __ Ret();
1103 }
1104
1105
1106 ASSEMBLER_TEST_RUN(AddOverflow_detect, test) {
1107 typedef int (*SimpleCode)();
1108 EXPECT_EQ(1, EXECUTE_TEST_CODE_INT32(SimpleCode, test->entry()));
1109 }
1110
1044 } // namespace dart 1111 } // namespace dart
1045 1112
1046 #endif // defined TARGET_ARCH_MIPS 1113 #endif // defined TARGET_ARCH_MIPS
OLDNEW
« no previous file with comments | « runtime/vm/assembler_mips.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698