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

Side by Side Diff: src/IceAssemblerARM32.cpp

Issue 1429003002: Add SDIV to ARM integrated assembler. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: Created 5 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
« no previous file with comments | « src/IceAssemblerARM32.h ('k') | src/IceInstARM32.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 //===- subzero/src/IceAssemblerARM32.cpp - Assembler for ARM32 --*- C++ -*-===// 1 //===- subzero/src/IceAssemblerARM32.cpp - Assembler for ARM32 --*- C++ -*-===//
2 // 2 //
3 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 3 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
4 // for details. All rights reserved. Use of this source code is governed by a 4 // for details. All rights reserved. Use of this source code is governed by a
5 // BSD-style license that can be found in the LICENSE file. 5 // BSD-style license that can be found in the LICENSE file.
6 // 6 //
7 // Modified by the Subzero authors. 7 // Modified by the Subzero authors.
8 // 8 //
9 //===----------------------------------------------------------------------===// 9 //===----------------------------------------------------------------------===//
10 // 10 //
(...skipping 20 matching lines...) Expand all
31 31
32 // The following define individual bits. 32 // The following define individual bits.
33 static constexpr IValueT B0 = 1; 33 static constexpr IValueT B0 = 1;
34 static constexpr IValueT B1 = 1 << 1; 34 static constexpr IValueT B1 = 1 << 1;
35 static constexpr IValueT B2 = 1 << 2; 35 static constexpr IValueT B2 = 1 << 2;
36 static constexpr IValueT B3 = 1 << 3; 36 static constexpr IValueT B3 = 1 << 3;
37 static constexpr IValueT B4 = 1 << 4; 37 static constexpr IValueT B4 = 1 << 4;
38 static constexpr IValueT B5 = 1 << 5; 38 static constexpr IValueT B5 = 1 << 5;
39 static constexpr IValueT B6 = 1 << 6; 39 static constexpr IValueT B6 = 1 << 6;
40 static constexpr IValueT B7 = 1 << 7; 40 static constexpr IValueT B7 = 1 << 7;
41 static constexpr IValueT B12 = 1 << 12;
42 static constexpr IValueT B13 = 1 << 13;
43 static constexpr IValueT B14 = 1 << 14;
44 static constexpr IValueT B15 = 1 << 15;
45 static constexpr IValueT B20 = 1 << 20;
41 static constexpr IValueT B21 = 1 << 21; 46 static constexpr IValueT B21 = 1 << 21;
42 static constexpr IValueT B22 = 1 << 22; 47 static constexpr IValueT B22 = 1 << 22;
43 static constexpr IValueT B24 = 1 << 24; 48 static constexpr IValueT B24 = 1 << 24;
44 static constexpr IValueT B25 = 1 << 25; 49 static constexpr IValueT B25 = 1 << 25;
50 static constexpr IValueT B26 = 1 << 26;
45 51
46 // Constants used for the decoding or encoding of the individual fields of 52 // Constants used for the decoding or encoding of the individual fields of
47 // instructions. Based on ARM section A5.1. 53 // instructions. Based on ARM section A5.1.
48 static constexpr IValueT L = 1 << 20; // load (or store) 54 static constexpr IValueT L = 1 << 20; // load (or store)
49 static constexpr IValueT W = 1 << 21; // writeback base register 55 static constexpr IValueT W = 1 << 21; // writeback base register
50 // (or leave unchanged) 56 // (or leave unchanged)
51 static constexpr IValueT B = 1 << 22; // unsigned byte (or word) 57 static constexpr IValueT B = 1 << 22; // unsigned byte (or word)
52 static constexpr IValueT U = 1 << 23; // positive (or negative) 58 static constexpr IValueT U = 1 << 23; // positive (or negative)
53 // offset/index 59 // offset/index
54 static constexpr IValueT P = 1 << 24; // offset/pre-indexed 60 static constexpr IValueT P = 1 << 24; // offset/pre-indexed
(...skipping 17 matching lines...) Expand all
72 static constexpr IValueT kRotateShift = 8; 78 static constexpr IValueT kRotateShift = 8;
73 79
74 // Shift instruction register fields encodings. 80 // Shift instruction register fields encodings.
75 static constexpr IValueT kShiftImmShift = 7; 81 static constexpr IValueT kShiftImmShift = 7;
76 static constexpr IValueT kShiftImmBits = 5; 82 static constexpr IValueT kShiftImmBits = 5;
77 static constexpr IValueT kShiftShift = 5; 83 static constexpr IValueT kShiftShift = 5;
78 84
79 static constexpr IValueT kImmed12Bits = 12; 85 static constexpr IValueT kImmed12Bits = 12;
80 static constexpr IValueT kImm12Shift = 0; 86 static constexpr IValueT kImm12Shift = 0;
81 87
88 // Div instruction register field encodings.
89 static constexpr IValueT kDivRdShift = 16;
90 static constexpr IValueT kDivRmShift = 8;
91 static constexpr IValueT kDivRnShift = 0;
92
82 // Type of instruction encoding (bits 25-27). See ARM section A5.1 93 // Type of instruction encoding (bits 25-27). See ARM section A5.1
83 static constexpr IValueT kInstTypeDataRegister = 0; // i.e. 000 94 static constexpr IValueT kInstTypeDataRegister = 0; // i.e. 000
84 static constexpr IValueT kInstTypeDataImmediate = 1; // i.e. 001 95 static constexpr IValueT kInstTypeDataImmediate = 1; // i.e. 001
85 static constexpr IValueT kInstTypeMemImmediate = 2; // i.e. 010 96 static constexpr IValueT kInstTypeMemImmediate = 2; // i.e. 010
86 97
87 // Offset modifier to current PC for next instruction. The offset is off by 8 98 // Offset modifier to current PC for next instruction. The offset is off by 8
88 // due to the way the ARM CPUs read PC. 99 // due to the way the ARM CPUs read PC.
89 static constexpr IOffsetT kPCReadOffset = 8; 100 static constexpr IOffsetT kPCReadOffset = 8;
90 101
91 // Mask to pull out PC offset from branch (b) instruction. 102 // Mask to pull out PC offset from branch (b) instruction.
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after
432 IValueT Address) { 443 IValueT Address) {
433 if (!isGPRRegisterDefined(Rt) || !isConditionDefined(Cond)) 444 if (!isGPRRegisterDefined(Rt) || !isConditionDefined(Cond))
434 return setNeedsTextFixup(); 445 return setNeedsTextFixup();
435 AssemblerBuffer::EnsureCapacity ensured(&Buffer); 446 AssemblerBuffer::EnsureCapacity ensured(&Buffer);
436 const IValueT Encoding = (encodeCondition(Cond) << kConditionShift) | 447 const IValueT Encoding = (encodeCondition(Cond) << kConditionShift) |
437 (InstType << kTypeShift) | (IsLoad ? L : 0) | 448 (InstType << kTypeShift) | (IsLoad ? L : 0) |
438 (IsByte ? B : 0) | (Rt << kRdShift) | Address; 449 (IsByte ? B : 0) | (Rt << kRdShift) | Address;
439 emitInst(Encoding); 450 emitInst(Encoding);
440 } 451 }
441 452
453 void AssemblerARM32::emitDivOp(CondARM32::Cond Cond, IValueT Opcode, IValueT Rd,
454 IValueT Rn, IValueT Rm) {
455 if (!isGPRRegisterDefined(Rd) || !isGPRRegisterDefined(Rn) ||
456 !isGPRRegisterDefined(Rm) || !isConditionDefined(Cond))
457 return setNeedsTextFixup();
458 AssemblerBuffer::EnsureCapacity ensured(&Buffer);
459 const IValueT Encoding = Opcode | (encodeCondition(Cond) << kConditionShift) |
460 (Rn << kDivRnShift) | (Rd << kDivRdShift) | B26 |
461 B25 | B24 | B20 | B15 | B14 | B13 | B12 | B4 |
462 (Rm << kDivRmShift);
463 emitInst(Encoding);
464 }
465
442 void AssemblerARM32::emitMulOp(CondARM32::Cond Cond, IValueT Opcode, IValueT Rd, 466 void AssemblerARM32::emitMulOp(CondARM32::Cond Cond, IValueT Opcode, IValueT Rd,
443 IValueT Rn, IValueT Rm, IValueT Rs, bool SetCc) { 467 IValueT Rn, IValueT Rm, IValueT Rs, bool SetCc) {
444 if (!isGPRRegisterDefined(Rd) || !isGPRRegisterDefined(Rn) || 468 if (!isGPRRegisterDefined(Rd) || !isGPRRegisterDefined(Rn) ||
445 !isGPRRegisterDefined(Rm) || !isGPRRegisterDefined(Rs) || 469 !isGPRRegisterDefined(Rm) || !isGPRRegisterDefined(Rs) ||
446 !isConditionDefined(Cond)) 470 !isConditionDefined(Cond))
447 return setNeedsTextFixup(); 471 return setNeedsTextFixup();
448 AssemblerBuffer::EnsureCapacity ensured(&Buffer); 472 AssemblerBuffer::EnsureCapacity ensured(&Buffer);
449 IValueT Encoding = Opcode | (encodeCondition(Cond) << kConditionShift) | 473 IValueT Encoding = Opcode | (encodeCondition(Cond) << kConditionShift) |
450 (encodeBool(SetCc) << kSShift) | (Rn << kRnShift) | 474 (encodeBool(SetCc) << kSShift) | (Rn << kRnShift) |
451 (Rd << kRdShift) | (Rs << kRsShift) | B7 | B4 | 475 (Rd << kRdShift) | (Rs << kRsShift) | B7 | B4 |
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
684 // 708 //
685 // SBC (Immediate) - ARM section A8.8.161, encoding A1: 709 // SBC (Immediate) - ARM section A8.8.161, encoding A1:
686 // sbc{s}<c> <Rd>, <Rn>, #<RotatedImm8> 710 // sbc{s}<c> <Rd>, <Rn>, #<RotatedImm8>
687 // 711 //
688 // cccc0010110snnnnddddiiiiiiiiiiii where cccc=Cond, dddd=Rd, nnnn=Rn, 712 // cccc0010110snnnnddddiiiiiiiiiiii where cccc=Cond, dddd=Rd, nnnn=Rn,
689 // s=SetFlags and iiiiiiiiiiii=Src1Value=RotatedImm8. 713 // s=SetFlags and iiiiiiiiiiii=Src1Value=RotatedImm8.
690 constexpr IValueT Sbc = B2 | B1; // 0110 714 constexpr IValueT Sbc = B2 | B1; // 0110
691 emitType01(Sbc, OpRd, OpRn, OpSrc1, SetFlags, Cond); 715 emitType01(Sbc, OpRd, OpRn, OpSrc1, SetFlags, Cond);
692 } 716 }
693 717
718 void AssemblerARM32::sdiv(const Operand *OpRd, const Operand *OpRn,
719 const Operand *OpSrc1, CondARM32::Cond Cond) {
720 // SDIV - ARM section A8.8.165, encoding A1.
721 // sdiv<c> <Rd>, <Rn>, <Rm>
722 //
723 // cccc01110001dddd1111mmmm0001nnnn where cccc=Cond, dddd=Rd, nnnn=Rn, and
724 // mmmm=Rm.
725 IValueT Rd;
726 if (decodeOperand(OpRd, Rd) != DecodedAsRegister)
727 return setNeedsTextFixup();
728 IValueT Rn;
729 if (decodeOperand(OpRn, Rn) != DecodedAsRegister)
730 return setNeedsTextFixup();
731 IValueT Rm;
732 if (decodeOperand(OpSrc1, Rm) != DecodedAsRegister)
733 return setNeedsTextFixup();
734 if (Rd == RegARM32::Encoded_Reg_pc || Rn == RegARM32::Encoded_Reg_pc ||
735 Rm == RegARM32::Encoded_Reg_pc)
736 llvm::report_fatal_error("Sdiv instruction unpredictable on pc");
737 // Assembler registers rd, rn, rm are encoded as rn, rm, rs.
738 constexpr IValueT Opcode = 0;
739 emitDivOp(Cond, Opcode, Rd, Rn, Rm);
740 }
741
694 void AssemblerARM32::str(const Operand *OpRt, const Operand *OpAddress, 742 void AssemblerARM32::str(const Operand *OpRt, const Operand *OpAddress,
695 CondARM32::Cond Cond) { 743 CondARM32::Cond Cond) {
696 IValueT Rt; 744 IValueT Rt;
697 if (decodeOperand(OpRt, Rt) != DecodedAsRegister) 745 if (decodeOperand(OpRt, Rt) != DecodedAsRegister)
698 return setNeedsTextFixup(); 746 return setNeedsTextFixup();
699 IValueT Address; 747 IValueT Address;
700 if (decodeAddress(OpAddress, Address) != DecodedAsImmRegOffset) 748 if (decodeAddress(OpAddress, Address) != DecodedAsImmRegOffset)
701 return setNeedsTextFixup(); 749 return setNeedsTextFixup();
702 // STR (immediate) - ARM section A8.8.204, encoding A1: 750 // STR (immediate) - ARM section A8.8.204, encoding A1:
703 // str<c> <Rt>, [<Rn>{, #+/-<imm12>}] ; p=1, w=0 751 // str<c> <Rt>, [<Rn>{, #+/-<imm12>}] ; p=1, w=0
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
813 // sub{s}<c> sp, <Rn>, #<RotatedImm8> 861 // sub{s}<c> sp, <Rn>, #<RotatedImm8>
814 // 862 //
815 // cccc0010010snnnnddddiiiiiiiiiiii where cccc=Cond, dddd=Rd, nnnn=Rn, 863 // cccc0010010snnnnddddiiiiiiiiiiii where cccc=Cond, dddd=Rd, nnnn=Rn,
816 // s=SetFlags and iiiiiiiiiiii=Src1Value=RotatedImm8 864 // s=SetFlags and iiiiiiiiiiii=Src1Value=RotatedImm8
817 constexpr IValueT Sub = B1; // 0010 865 constexpr IValueT Sub = B1; // 0010
818 emitType01(Sub, OpRd, OpRn, OpSrc1, SetFlags, Cond); 866 emitType01(Sub, OpRd, OpRn, OpSrc1, SetFlags, Cond);
819 } 867 }
820 868
821 } // end of namespace ARM32 869 } // end of namespace ARM32
822 } // end of namespace Ice 870 } // end of namespace Ice
OLDNEW
« no previous file with comments | « src/IceAssemblerARM32.h ('k') | src/IceInstARM32.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698