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

Side by Side Diff: lib/compiler/implementation/ssa/codegen.dart

Issue 10912147: Change our 'is int' check to use Math.floor instead of a smi check. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 3 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 | « lib/compiler/implementation/lib/js_helper.dart ('k') | pkg/intl/number_format.dart » ('j') | 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) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 class SsaCodeGeneratorTask extends CompilerTask { 5 class SsaCodeGeneratorTask extends CompilerTask {
6 6
7 final JavaScriptBackend backend; 7 final JavaScriptBackend backend;
8 8
9 SsaCodeGeneratorTask(JavaScriptBackend backend) 9 SsaCodeGeneratorTask(JavaScriptBackend backend)
10 : this.backend = backend, 10 : this.backend = backend,
(...skipping 2132 matching lines...) Expand 10 before | Expand all | Expand 10 after
2143 } 2143 }
2144 2144
2145 void checkInt(HInstruction input, String cmp) { 2145 void checkInt(HInstruction input, String cmp) {
2146 use(input); 2146 use(input);
2147 js.Expression left = pop(); 2147 js.Expression left = pop();
2148 use(input); 2148 use(input);
2149 js.Expression or0 = new js.Binary("|", pop(), new js.LiteralNumber("0")); 2149 js.Expression or0 = new js.Binary("|", pop(), new js.LiteralNumber("0"));
2150 push(new js.Binary(cmp, left, or0)); 2150 push(new js.Binary(cmp, left, or0));
2151 } 2151 }
2152 2152
2153 void checkBigInt(HInstruction input, String cmp) {
2154 use(input);
2155 js.Expression left = pop();
2156 use(input);
2157 js.Expression right = pop();
2158 // TODO(ngeoffray,floitsch): Deal with infinity.
floitsch 2012/09/07 11:56:47 file bug.
ngeoffray 2012/09/07 12:06:26 Done: http://code.google.com/p/dart/issues/detail?
2159 push(new js.LiteralExpression.withData('Math.floor(#) === #',
2160 <js.Expression>[left, right]));
2161 }
2162
2153 void checkTypeOf(HInstruction input, String cmp, String typeName) { 2163 void checkTypeOf(HInstruction input, String cmp, String typeName) {
2154 use(input); 2164 use(input);
2155 js.Expression typeOf = new js.Prefix("typeof", pop()); 2165 js.Expression typeOf = new js.Prefix("typeof", pop());
2156 push(new js.Binary(cmp, typeOf, new js.LiteralString("'$typeName'"))); 2166 push(new js.Binary(cmp, typeOf, new js.LiteralString("'$typeName'")));
2157 } 2167 }
2158 2168
2159 void checkNum(HInstruction input, String cmp) 2169 void checkNum(HInstruction input, String cmp)
2160 => checkTypeOf(input, cmp, 'number'); 2170 => checkTypeOf(input, cmp, 'number');
2161 2171
2162 void checkDouble(HInstruction input, String cmp) => checkNum(input, cmp); 2172 void checkDouble(HInstruction input, String cmp) => checkNum(input, cmp);
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
2298 } else if (element == compiler.numClass) { 2308 } else if (element == compiler.numClass) {
2299 checkNum(input, '==='); 2309 checkNum(input, '===');
2300 attachLocationToLast(node); 2310 attachLocationToLast(node);
2301 } else if (element == compiler.boolClass) { 2311 } else if (element == compiler.boolClass) {
2302 checkBool(input, '==='); 2312 checkBool(input, '===');
2303 attachLocationToLast(node); 2313 attachLocationToLast(node);
2304 } else if (element == compiler.functionClass) { 2314 } else if (element == compiler.functionClass) {
2305 checkFunction(input, type); 2315 checkFunction(input, type);
2306 attachLocationToLast(node); 2316 attachLocationToLast(node);
2307 } else if (element == compiler.intClass) { 2317 } else if (element == compiler.intClass) {
2318 // The is check in the code tells us that it might not be an
2319 // int. So we do a typeof first to avoid possible
2320 // deoptimizations on the JS engine due to the Math.floor check.
2308 checkNum(input, '==='); 2321 checkNum(input, '===');
2309 js.Expression numTest = pop(); 2322 js.Expression numTest = pop();
2310 checkInt(input, '==='); 2323 checkBigInt(input, '===');
2311 push(new js.Binary('&&', numTest, pop()), node); 2324 push(new js.Binary('&&', numTest, pop()), node);
2312 } else if (Elements.isStringSupertype(element, compiler)) { 2325 } else if (Elements.isStringSupertype(element, compiler)) {
2313 handleStringSupertypeCheck(input, type); 2326 handleStringSupertypeCheck(input, type);
2314 attachLocationToLast(node); 2327 attachLocationToLast(node);
2315 } else if (element === compiler.listClass 2328 } else if (element === compiler.listClass
2316 || Elements.isListSupertype(element, compiler)) { 2329 || Elements.isListSupertype(element, compiler)) {
2317 handleListOrSupertypeCheck(input, type); 2330 handleListOrSupertypeCheck(input, type);
2318 attachLocationToLast(node); 2331 attachLocationToLast(node);
2319 } else if (types[input].canBePrimitive() || types[input].canBeNull()) { 2332 } else if (types[input].canBePrimitive() || types[input].canBeNull()) {
2320 checkObject(input, '==='); 2333 checkObject(input, '===');
(...skipping 614 matching lines...) Expand 10 before | Expand all | Expand 10 after
2935 if (leftType.canBeNull() && rightType.canBeNull()) { 2948 if (leftType.canBeNull() && rightType.canBeNull()) {
2936 if (left.isConstantNull() || right.isConstantNull() || 2949 if (left.isConstantNull() || right.isConstantNull() ||
2937 (leftType.isPrimitive() && leftType == rightType)) { 2950 (leftType.isPrimitive() && leftType == rightType)) {
2938 return '=='; 2951 return '==';
2939 } 2952 }
2940 return null; 2953 return null;
2941 } else { 2954 } else {
2942 return '==='; 2955 return '===';
2943 } 2956 }
2944 } 2957 }
OLDNEW
« no previous file with comments | « lib/compiler/implementation/lib/js_helper.dart ('k') | pkg/intl/number_format.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698