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

Side by Side Diff: src/compiler/mips/code-generator-mips.cc

Issue 1588383002: MIPS: [turbofan] Implement Word32Ctz, Word64Ctz, Word32Popcnt and Word64Popcnt (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Remove unneccesary mov instructions Created 4 years, 10 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
« no previous file with comments | « no previous file | src/compiler/mips/instruction-codes-mips.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 2014 the V8 project authors. All rights reserved. 1 // Copyright 2014 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/ast/scopes.h" 5 #include "src/ast/scopes.h"
6 #include "src/compiler/code-generator.h" 6 #include "src/compiler/code-generator.h"
7 #include "src/compiler/code-generator-impl.h" 7 #include "src/compiler/code-generator-impl.h"
8 #include "src/compiler/gap-resolver.h" 8 #include "src/compiler/gap-resolver.h"
9 #include "src/compiler/node-matchers.h" 9 #include "src/compiler/node-matchers.h"
10 #include "src/compiler/osr.h" 10 #include "src/compiler/osr.h"
(...skipping 670 matching lines...) Expand 10 before | Expand all | Expand 10 after
681 DCHECK(i.InputOperand(1).immediate() == 0); 681 DCHECK(i.InputOperand(1).immediate() == 0);
682 __ Nor(i.OutputRegister(), i.InputRegister(0), zero_reg); 682 __ Nor(i.OutputRegister(), i.InputRegister(0), zero_reg);
683 } 683 }
684 break; 684 break;
685 case kMipsXor: 685 case kMipsXor:
686 __ Xor(i.OutputRegister(), i.InputRegister(0), i.InputOperand(1)); 686 __ Xor(i.OutputRegister(), i.InputRegister(0), i.InputOperand(1));
687 break; 687 break;
688 case kMipsClz: 688 case kMipsClz:
689 __ Clz(i.OutputRegister(), i.InputRegister(0)); 689 __ Clz(i.OutputRegister(), i.InputRegister(0));
690 break; 690 break;
691 case kMipsCtz: {
692 Register reg1 = kScratchReg;
693 Register reg2 = kScratchReg2;
694 Label skip_for_zero;
695 Label end;
696 // Branch if the operand is zero
697 __ Branch(&skip_for_zero, eq, i.InputRegister(0), Operand(zero_reg));
698 // Find the number of bits before the last bit set to 1.
699 __ Subu(reg2, zero_reg, i.InputRegister(0));
700 __ And(reg2, reg2, i.InputRegister(0));
701 __ clz(reg2, reg2);
702 // Get the number of bits after the last bit set to 1.
703 __ li(reg1, 0x1F);
704 __ Subu(i.OutputRegister(), reg1, reg2);
705 __ Branch(&end);
706 __ bind(&skip_for_zero);
707 // If the operand is zero, return word length as the result.
708 __ li(i.OutputRegister(), 0x20);
709 __ bind(&end);
710 } break;
711 case kMipsPopcnt: {
712 Register reg1 = kScratchReg;
713 Register reg2 = kScratchReg2;
714 uint32_t m1 = 0x55555555;
715 uint32_t m2 = 0x33333333;
716 uint32_t m4 = 0x0f0f0f0f;
717 uint32_t m8 = 0x00ff00ff;
718 uint32_t m16 = 0x0000ffff;
719
720 // Put count of ones in every 2 bits into those 2 bits.
721 __ li(at, m1);
722 __ srl(reg1, i.InputRegister(0), 1);
723 __ And(reg2, i.InputRegister(0), at);
724 __ And(reg1, reg1, at);
725 __ addu(reg1, reg1, reg2);
726
727 // Put count of ones in every 4 bits into those 4 bits.
728 __ li(at, m2);
729 __ srl(reg2, reg1, 2);
730 __ And(reg2, reg2, at);
731 __ And(reg1, reg1, at);
732 __ addu(reg1, reg1, reg2);
733
734 // Put count of ones in every 8 bits into those 8 bits.
735 __ li(at, m4);
736 __ srl(reg2, reg1, 4);
737 __ And(reg2, reg2, at);
738 __ And(reg1, reg1, at);
739 __ addu(reg1, reg1, reg2);
740
741 // Put count of ones in every 16 bits into those 16 bits.
742 __ li(at, m8);
743 __ srl(reg2, reg1, 8);
744 __ And(reg2, reg2, at);
745 __ And(reg1, reg1, at);
746 __ addu(reg1, reg1, reg2);
747
748 // Calculate total number of ones.
749 __ li(at, m16);
750 __ srl(reg2, reg1, 16);
751 __ And(reg2, reg2, at);
752 __ And(reg1, reg1, at);
753 __ addu(i.OutputRegister(), reg1, reg2);
754 } break;
691 case kMipsShl: 755 case kMipsShl:
692 if (instr->InputAt(1)->IsRegister()) { 756 if (instr->InputAt(1)->IsRegister()) {
693 __ sllv(i.OutputRegister(), i.InputRegister(0), i.InputRegister(1)); 757 __ sllv(i.OutputRegister(), i.InputRegister(0), i.InputRegister(1));
694 } else { 758 } else {
695 int32_t imm = i.InputOperand(1).immediate(); 759 int32_t imm = i.InputOperand(1).immediate();
696 __ sll(i.OutputRegister(), i.InputRegister(0), imm); 760 __ sll(i.OutputRegister(), i.InputRegister(0), imm);
697 } 761 }
698 break; 762 break;
699 case kMipsShr: 763 case kMipsShr:
700 if (instr->InputAt(1)->IsRegister()) { 764 if (instr->InputAt(1)->IsRegister()) {
(...skipping 1043 matching lines...) Expand 10 before | Expand all | Expand 10 after
1744 padding_size -= v8::internal::Assembler::kInstrSize; 1808 padding_size -= v8::internal::Assembler::kInstrSize;
1745 } 1809 }
1746 } 1810 }
1747 } 1811 }
1748 1812
1749 #undef __ 1813 #undef __
1750 1814
1751 } // namespace compiler 1815 } // namespace compiler
1752 } // namespace internal 1816 } // namespace internal
1753 } // namespace v8 1817 } // namespace v8
OLDNEW
« no previous file with comments | « no previous file | src/compiler/mips/instruction-codes-mips.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698