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

Side by Side Diff: syzygy/core/disassembler_util.cc

Issue 2543673002: Add support for more AVX instructions. (Closed)
Patch Set: Address nit. Created 4 years 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 | syzygy/core/disassembler_util_unittest.cc » ('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 Google Inc. All Rights Reserved. 1 // Copyright 2012 Google Inc. All Rights Reserved.
2 // 2 //
3 // Licensed under the Apache License, Version 2.0 (the "License"); 3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License. 4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at 5 // You may obtain a copy of the License at
6 // 6 //
7 // http://www.apache.org/licenses/LICENSE-2.0 7 // http://www.apache.org/licenses/LICENSE-2.0
8 // 8 //
9 // Unless required by applicable law or agreed to in writing, software 9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS, 10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and 12 // See the License for the specific language governing permissions and
13 // limitations under the License. 13 // limitations under the License.
14 14
15 #include "syzygy/core/disassembler_util.h" 15 #include "syzygy/core/disassembler_util.h"
16 16
17 #include <algorithm>
18
17 #include "base/logging.h" 19 #include "base/logging.h"
18 #include "base/strings/stringprintf.h" 20 #include "base/strings/stringprintf.h"
19 #include "mnemonics.h" // NOLINT 21 #include "mnemonics.h" // NOLINT
20 22
21 namespace core { 23 namespace core {
22 24
23 namespace { 25 namespace {
24 26
25 // Return the size of a 3-byte VEX encoded instruction. 27 // Return the size of a 3-byte VEX encoded instruction.
26 // 28 //
(...skipping 15 matching lines...) Expand all
42 // 44 //
43 // |map_select| Indicates the opcode map that should be used for this 45 // |map_select| Indicates the opcode map that should be used for this
44 // instruction. 46 // instruction.
45 // 47 //
46 // See http://wiki.osdev.org/X86-64_Instruction_Encoding#Three_byte_VEX_escape_p refix 48 // See http://wiki.osdev.org/X86-64_Instruction_Encoding#Three_byte_VEX_escape_p refix
47 // for more details. 49 // for more details.
48 size_t Get3ByteVexEncodedInstructionSize(_CodeInfo* ci) { 50 size_t Get3ByteVexEncodedInstructionSize(_CodeInfo* ci) {
49 DCHECK_EQ(0xC4, ci->code[0]); 51 DCHECK_EQ(0xC4, ci->code[0]);
50 // Switch case based on the opcode map used by this instruction. 52 // Switch case based on the opcode map used by this instruction.
51 switch (ci->code[1] & 0x1F) { 53 switch (ci->code[1] & 0x1F) {
52 case 0x01: {
53 switch (ci->code[3]) {
54 case 0x1D: return 5; // vpermd
55 default: break;
56 }
57 break;
58 }
59 case 0x02: { 54 case 0x02: {
60 switch (ci->code[3]) { 55 switch (ci->code[3]) {
61 case 0x13: return 5; // vcvtps2ps 56 case 0x13: return 5; // vcvtps2ps
62 case 0x18: return 5; // vbroadcastss 57 case 0x18: return 5; // vbroadcastss
63 case 0x36: return 5; // vpermd 58 case 0x36: return 5; // vpermd
59 case 0x58: return 6; // vpbroadcastd
64 case 0x5A: return 6; // vbroadcasti128 60 case 0x5A: return 6; // vbroadcasti128
65 case 0x78: return 5; // vpbroadcastb 61 case 0x78: return 5; // vpbroadcastb
66 default: break; 62 case 0x8C: return 5; // vpmaskmovd
63 case 0x8E: return 5; // vpmaskmovd
64 case 0x90: return 6; // vpgatherdd
65 default:
66 break;
67 } 67 }
68 break; 68 break;
69 } 69 }
70 case 0x03: { 70 case 0x03: {
71 switch (ci->code[3]) { 71 switch (ci->code[3]) {
72 case 0x00: return 6; // vpermq 72 case 0x00: return 6; // vpermq
73 case 0x1D: return 6; // vcvtps2ph 73 case 0x1D: return 6; // vcvtps2ph
74 case 0x38: return 7; // vinserti128 74 case 0x38: return 7; // vinserti128
75 case 0x39: return 6; // vextracti128 75 case 0x39: return 6; // vextracti128
76 default: break; 76 default: break;
77 } 77 }
78 break; 78 break;
79 } 79 }
80 default: 80 default:
81 break; 81 break;
82 } 82 }
83
84 // Print the instructions that we haven't been able to decompose in a format
85 // that can easily be pasted into ODA (https://onlinedisassembler.com/).
86 const int kMaxBytes = 10;
87 size_t byte_count = std::min(ci->codeLen, kMaxBytes);
88 std::string instruction_bytes;
89 for (size_t i = 0; i < byte_count; ++i) {
90 base::StringAppendF(&instruction_bytes, "%02X", ci->code[i]);
91 if (i != byte_count - 1)
92 instruction_bytes += " ";
93 }
94 if (ci->codeLen > kMaxBytes)
95 instruction_bytes += "...";
96 LOG(WARNING) << "Failed to decompose a VEX encoded instructions with the "
97 << "following bytes: " << instruction_bytes;
83 return 0; 98 return 0;
84 } 99 }
85 100
86 void AdjustOperandSizeTo16Bit(_Operand* op) { 101 void AdjustOperandSizeTo16Bit(_Operand* op) {
87 DCHECK_EQ(32, op->size); 102 DCHECK_EQ(32, op->size);
88 103
89 op->size = 16; 104 op->size = 16;
90 if (op->type == O_REG) { 105 if (op->type == O_REG) {
91 DCHECK(op->index >= R_EAX && op->index < R_AX); 106 DCHECK(op->index >= R_EAX && op->index < R_AX);
92 // Size classes for registers are 16 indices apart. 107 // Size classes for registers are 16 indices apart.
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after
429 444
430 default: return assm::kRegisterNone; 445 default: return assm::kRegisterNone;
431 } 446 }
432 } 447 }
433 448
434 const Register& GetRegister(uint32_t distorm_reg_type) { 449 const Register& GetRegister(uint32_t distorm_reg_type) {
435 return Register::Get(GetRegisterId(distorm_reg_type)); 450 return Register::Get(GetRegisterId(distorm_reg_type));
436 } 451 }
437 452
438 } // namespace core 453 } // namespace core
OLDNEW
« no previous file with comments | « no previous file | syzygy/core/disassembler_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698