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

Side by Side Diff: src/hydrogen.cc

Issue 11033005: Add rotate-right instruction to hydrogen and use it instead of bitwise operations (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: rebase Created 8 years, 1 month 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 | « src/hydrogen.h ('k') | src/hydrogen-instructions.h » ('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 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 8208 matching lines...) Expand 10 before | Expand all | Expand 10 after
8219 HValue* index) { 8219 HValue* index) {
8220 AddInstruction(new(zone()) HCheckNonSmi(string)); 8220 AddInstruction(new(zone()) HCheckNonSmi(string));
8221 AddInstruction(HCheckInstanceType::NewIsString(string, zone())); 8221 AddInstruction(HCheckInstanceType::NewIsString(string, zone()));
8222 HStringLength* length = new(zone()) HStringLength(string); 8222 HStringLength* length = new(zone()) HStringLength(string);
8223 AddInstruction(length); 8223 AddInstruction(length);
8224 HInstruction* checked_index = 8224 HInstruction* checked_index =
8225 AddInstruction(new(zone()) HBoundsCheck(index, length)); 8225 AddInstruction(new(zone()) HBoundsCheck(index, length));
8226 return new(zone()) HStringCharCodeAt(context, string, checked_index); 8226 return new(zone()) HStringCharCodeAt(context, string, checked_index);
8227 } 8227 }
8228 8228
8229 // Checks if the given shift amounts have form: (sa) and (32 - sa).
8230 static bool ShiftAmountsAllowReplaceByRotate(HValue* sa,
8231 HValue* const32_minus_sa) {
8232 if (!const32_minus_sa->IsSub()) return false;
8233 HSub* sub = HSub::cast(const32_minus_sa);
8234 HValue* const32 = sub->left();
8235 if (!const32->IsConstant() ||
8236 HConstant::cast(const32)->Integer32Value() != 32) {
8237 return false;
8238 }
8239 return (sub->right() == sa);
8240 }
8241
8242
8243 // Checks if the left and the right are shift instructions with the oposite
8244 // directions that can be replaced by one rotate right instruction or not.
8245 // Returns the operand and the shift amount for the rotate instruction in the
8246 // former case.
8247 bool HGraphBuilder::MatchRotateRight(HValue* left,
8248 HValue* right,
8249 HValue** operand,
8250 HValue** shift_amount) {
8251 HShl* shl;
8252 HShr* shr;
8253 if (left->IsShl() && right->IsShr()) {
8254 shl = HShl::cast(left);
8255 shr = HShr::cast(right);
8256 } else if (left->IsShr() && right->IsShl()) {
8257 shl = HShl::cast(right);
8258 shr = HShr::cast(left);
8259 } else {
8260 return false;
8261 }
8262
8263 if (!ShiftAmountsAllowReplaceByRotate(shl->right(), shr->right()) &&
8264 !ShiftAmountsAllowReplaceByRotate(shr->right(), shl->right())) {
8265 return false;
8266 }
8267 *operand= shr->left();
8268 *shift_amount = shr->right();
8269 return true;
8270 }
8271
8272
8273 bool CanBeZero(HValue *right) {
8274 if (right->IsConstant()) {
8275 HConstant* right_const = HConstant::cast(right);
8276 if (right_const->HasInteger32Value() &&
8277 (right_const->Integer32Value() & 0x1f) != 0) {
8278 return false;
8279 }
8280 }
8281 return true;
8282 }
8283
8229 8284
8230 HInstruction* HGraphBuilder::BuildBinaryOperation(BinaryOperation* expr, 8285 HInstruction* HGraphBuilder::BuildBinaryOperation(BinaryOperation* expr,
8231 HValue* left, 8286 HValue* left,
8232 HValue* right) { 8287 HValue* right) {
8233 HValue* context = environment()->LookupContext(); 8288 HValue* context = environment()->LookupContext();
8234 TypeInfo info = oracle()->BinaryType(expr); 8289 TypeInfo info = oracle()->BinaryType(expr);
8235 if (info.IsUninitialized()) { 8290 if (info.IsUninitialized()) {
8236 AddInstruction(new(zone()) HSoftDeoptimize); 8291 AddInstruction(new(zone()) HSoftDeoptimize);
8237 current_block()->MarkAsDeoptimizing(); 8292 current_block()->MarkAsDeoptimizing();
8238 info = TypeInfo::Unknown(); 8293 info = TypeInfo::Unknown();
(...skipping 18 matching lines...) Expand all
8257 instr = HMul::NewHMul(zone(), context, left, right); 8312 instr = HMul::NewHMul(zone(), context, left, right);
8258 break; 8313 break;
8259 case Token::MOD: 8314 case Token::MOD:
8260 instr = HMod::NewHMod(zone(), context, left, right); 8315 instr = HMod::NewHMod(zone(), context, left, right);
8261 break; 8316 break;
8262 case Token::DIV: 8317 case Token::DIV:
8263 instr = HDiv::NewHDiv(zone(), context, left, right); 8318 instr = HDiv::NewHDiv(zone(), context, left, right);
8264 break; 8319 break;
8265 case Token::BIT_XOR: 8320 case Token::BIT_XOR:
8266 case Token::BIT_AND: 8321 case Token::BIT_AND:
8267 case Token::BIT_OR:
8268 instr = HBitwise::NewHBitwise(zone(), expr->op(), context, left, right); 8322 instr = HBitwise::NewHBitwise(zone(), expr->op(), context, left, right);
8269 break; 8323 break;
8324 case Token::BIT_OR: {
8325 HValue* operand, *shift_amount;
8326 if (info.IsInteger32() &&
8327 MatchRotateRight(left, right, &operand, &shift_amount)) {
8328 instr = new(zone()) HRor(context, operand, shift_amount);
8329 } else {
8330 instr = HBitwise::NewHBitwise(zone(), expr->op(), context, left, right);
8331 }
8332 break;
8333 }
8270 case Token::SAR: 8334 case Token::SAR:
8271 instr = HSar::NewHSar(zone(), context, left, right); 8335 instr = HSar::NewHSar(zone(), context, left, right);
8272 break; 8336 break;
8273 case Token::SHR: 8337 case Token::SHR:
8274 instr = HShr::NewHShr(zone(), context, left, right); 8338 instr = HShr::NewHShr(zone(), context, left, right);
8275 if (FLAG_opt_safe_uint32_operations && instr->IsShr()) { 8339 if (FLAG_opt_safe_uint32_operations && instr->IsShr() &&
8276 bool can_be_shift_by_zero = true; 8340 CanBeZero(right)) {
8277 if (right->IsConstant()) { 8341 graph()->RecordUint32Instruction(instr);
8278 HConstant* right_const = HConstant::cast(right);
8279 if (right_const->HasInteger32Value() &&
8280 (right_const->Integer32Value() & 0x1f) != 0) {
8281 can_be_shift_by_zero = false;
8282 }
8283 }
8284
8285 if (can_be_shift_by_zero) graph()->RecordUint32Instruction(instr);
8286 } 8342 }
8287 break; 8343 break;
8288 case Token::SHL: 8344 case Token::SHL:
8289 instr = HShl::NewHShl(zone(), context, left, right); 8345 instr = HShl::NewHShl(zone(), context, left, right);
8290 break; 8346 break;
8291 default: 8347 default:
8292 UNREACHABLE(); 8348 UNREACHABLE();
8293 } 8349 }
8294 8350
8295 // If we hit an uninitialized binary op stub we will get type info 8351 // If we hit an uninitialized binary op stub we will get type info
(...skipping 1659 matching lines...) Expand 10 before | Expand all | Expand 10 after
9955 } 10011 }
9956 } 10012 }
9957 10013
9958 #ifdef DEBUG 10014 #ifdef DEBUG
9959 if (graph_ != NULL) graph_->Verify(false); // No full verify. 10015 if (graph_ != NULL) graph_->Verify(false); // No full verify.
9960 if (allocator_ != NULL) allocator_->Verify(); 10016 if (allocator_ != NULL) allocator_->Verify();
9961 #endif 10017 #endif
9962 } 10018 }
9963 10019
9964 } } // namespace v8::internal 10020 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/hydrogen.h ('k') | src/hydrogen-instructions.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698