Mercurial > hg > truffle
comparison graal/com.oracle.max.asmdis/src/com/sun/max/asm/gen/cisc/x86/X86TemplateAssembler.java @ 4142:bc8527f3071c
Adjust code base to new level of warnings.
author | Thomas Wuerthinger <thomas.wuerthinger@oracle.com> |
---|---|
date | Sun, 18 Dec 2011 05:24:06 +0100 |
parents | e233f5660da4 |
children |
comparison
equal
deleted
inserted
replaced
4141:04d21be7a24f | 4142:bc8527f3071c |
---|---|
39 | 39 |
40 private static final int MORE_BYTES_THAN_ANY_INSTRUCTION = 32; | 40 private static final int MORE_BYTES_THAN_ANY_INSTRUCTION = 32; |
41 private final byte[] bytes = new byte[MORE_BYTES_THAN_ANY_INSTRUCTION]; | 41 private final byte[] bytes = new byte[MORE_BYTES_THAN_ANY_INSTRUCTION]; |
42 private int n; | 42 private int n; |
43 | 43 |
44 private int rexByte; | |
45 | |
46 private void emit(byte b) { | 44 private void emit(byte b) { |
47 bytes[n++] = b; | 45 bytes[n++] = b; |
48 } | 46 } |
49 | 47 |
50 private void emit(int b) { | 48 private void emit(int b) { |
57 | 55 |
58 private int createRexData(int bitIndex, Argument argument, boolean unconditionalRexBit) { | 56 private int createRexData(int bitIndex, Argument argument, boolean unconditionalRexBit) { |
59 if (unconditionalRexBit) { | 57 if (unconditionalRexBit) { |
60 return ((int) argument.asLong() & 8) >> (3 - bitIndex); | 58 return ((int) argument.asLong() & 8) >> (3 - bitIndex); |
61 } | 59 } |
62 int rexByte = 0; | 60 int result = 0; |
63 if (argument instanceof AMD64GeneralRegister8) { | 61 if (argument instanceof AMD64GeneralRegister8) { |
64 final AMD64GeneralRegister8 reg8 = (AMD64GeneralRegister8) argument; | 62 final AMD64GeneralRegister8 reg8 = (AMD64GeneralRegister8) argument; |
65 if (reg8.requiresRexPrefix()) { | 63 if (reg8.requiresRexPrefix()) { |
66 rexByte |= basicRexValue(template); | 64 result |= basicRexValue(template); |
67 if (argument.asLong() >= 8) { | 65 if (argument.asLong() >= 8) { |
68 rexByte |= createRexData(bitIndex, argument.asLong()); | 66 result |= createRexData(bitIndex, argument.asLong()); |
69 } | 67 } |
70 } | 68 } |
71 } else { | 69 } else { |
72 if (argument.asLong() >= 8) { | 70 if (argument.asLong() >= 8) { |
73 rexByte |= createRexData(bitIndex, argument.asLong()) + basicRexValue(template); | 71 result |= createRexData(bitIndex, argument.asLong()) + basicRexValue(template); |
74 } | 72 } |
75 } | 73 } |
76 return rexByte; | 74 return result; |
77 } | 75 } |
78 | 76 |
79 private int createRexData(int bitIndex, long argument) { | 77 private static int createRexData(int bitIndex, long argument) { |
80 final byte b = (byte) (argument & 0xffL); | 78 final byte b = (byte) (argument & 0xffL); |
81 if (b == 0) { | 79 if (b == 0) { |
82 return 0; | 80 return 0; |
83 } | 81 } |
84 return X86Field.inRexPlace(bitIndex, b); | 82 return X86Field.inRexPlace(bitIndex, b); |
85 } | 83 } |
86 | 84 |
87 private int createFieldData(X86Field field, long argument) { | 85 private static int createFieldData(X86Field field, long argument) { |
88 return field.inPlace((byte) (argument & field.mask)); | 86 return field.inPlace((byte) (argument & field.mask)); |
89 } | 87 } |
90 | 88 |
91 private final X86Template template; | 89 private final X86Template template; |
92 private WordWidth addressWidth; | 90 private WordWidth addressWidth; |
113 return 5 << X86Field.BASE.shift(); | 111 return 5 << X86Field.BASE.shift(); |
114 } | 112 } |
115 return 0; | 113 return 0; |
116 } | 114 } |
117 | 115 |
118 private boolean modRMRequiresSib(int modRMByte) { | 116 private static boolean modRMRequiresSib(int modRMByte) { |
119 final byte m = (byte) modRMByte; | 117 final byte m = (byte) modRMByte; |
120 return X86Field.MOD.extract(m) != 3 && X86Field.RM.extract(m) == 4; | 118 return X86Field.MOD.extract(m) != 3 && X86Field.RM.extract(m) == 4; |
121 } | 119 } |
122 | 120 |
123 private boolean modRMRequiresImmediate(int modRMByte) { | 121 private static boolean modRMRequiresImmediate(int modRMByte) { |
124 final byte m = (byte) modRMByte; | 122 final byte m = (byte) modRMByte; |
125 return X86Field.MOD.extract(m) == 0 && X86Field.RM.extract(m) == 5; | 123 return X86Field.MOD.extract(m) == 0 && X86Field.RM.extract(m) == 5; |
126 } | 124 } |
127 | 125 |
128 private boolean sibRequiresImmediate(int sibRMByte) { | 126 private static boolean sibRequiresImmediate(int sibRMByte) { |
129 final byte s = (byte) sibRMByte; | 127 final byte s = (byte) sibRMByte; |
130 return X86Field.BASE.extract(s) == 5; | 128 return X86Field.BASE.extract(s) == 5; |
131 } | 129 } |
132 | 130 |
133 public byte[] assemble(List<Argument> arguments) { | 131 public byte[] assemble(List<Argument> arguments) { |
134 int rexByte = 0; | 132 int curRexByte = 0; |
135 final boolean unconditionalRexBit = template.operandSizeAttribute() == WordWidth.BITS_64 && template.instructionDescription().defaultOperandSize() != WordWidth.BITS_64; | 133 final boolean unconditionalRexBit = template.operandSizeAttribute() == WordWidth.BITS_64 && template.instructionDescription().defaultOperandSize() != WordWidth.BITS_64; |
136 if (unconditionalRexBit) { | 134 if (unconditionalRexBit) { |
137 rexByte = X86Opcode.REX_MIN.byteValue() | (1 << X86Field.REX_W_BIT_INDEX); | 135 curRexByte = X86Opcode.REX_MIN.byteValue() | (1 << X86Field.REX_W_BIT_INDEX); |
138 } | 136 } |
139 int opcode1 = template.opcode1().byteValue() & 0xff; | 137 int opcode1 = template.opcode1().byteValue() & 0xff; |
140 int opcode2 = template.opcode2() == null ? 0 : template.opcode2().byteValue() & 0xff; | 138 int opcode2 = template.opcode2() == null ? 0 : template.opcode2().byteValue() & 0xff; |
141 int modRMByte = createModRMByte(); | 139 int modRMByte = createModRMByte(); |
142 int sibByte = createSibByte(); | 140 int sibByte = createSibByte(); |
144 for (int i = 0; i < arguments.size(); i++) { | 142 for (int i = 0; i < arguments.size(); i++) { |
145 final X86Parameter parameter = template.parameters().get(i); | 143 final X86Parameter parameter = template.parameters().get(i); |
146 final long argument = arguments.get(i).asLong(); | 144 final long argument = arguments.get(i).asLong(); |
147 switch (parameter.place()) { | 145 switch (parameter.place()) { |
148 case MOD_REG_REXR: | 146 case MOD_REG_REXR: |
149 rexByte |= createRexData(X86Field.REX_R_BIT_INDEX, arguments.get(i), unconditionalRexBit); | 147 curRexByte |= createRexData(X86Field.REX_R_BIT_INDEX, arguments.get(i), unconditionalRexBit); |
150 // fall through... | 148 // fall through... |
151 case MOD_REG: | 149 case MOD_REG: |
152 modRMByte |= createFieldData(X86Field.REG, argument); | 150 modRMByte |= createFieldData(X86Field.REG, argument); |
153 break; | 151 break; |
154 case MOD_RM_REXB: | 152 case MOD_RM_REXB: |
155 rexByte |= createRexData(X86Field.REX_B_BIT_INDEX, arguments.get(i), unconditionalRexBit); | 153 curRexByte |= createRexData(X86Field.REX_B_BIT_INDEX, arguments.get(i), unconditionalRexBit); |
156 // fall through... | 154 // fall through... |
157 case MOD_RM: | 155 case MOD_RM: |
158 modRMByte |= createFieldData(X86Field.RM, argument); | 156 modRMByte |= createFieldData(X86Field.RM, argument); |
159 break; | 157 break; |
160 case SIB_BASE_REXB: | 158 case SIB_BASE_REXB: |
161 rexByte |= createRexData(X86Field.REX_B_BIT_INDEX, arguments.get(i), unconditionalRexBit); | 159 curRexByte |= createRexData(X86Field.REX_B_BIT_INDEX, arguments.get(i), unconditionalRexBit); |
162 // fall through... | 160 // fall through... |
163 case SIB_BASE: | 161 case SIB_BASE: |
164 sibByte |= createFieldData(X86Field.BASE, argument); | 162 sibByte |= createFieldData(X86Field.BASE, argument); |
165 break; | 163 break; |
166 case SIB_INDEX_REXX: | 164 case SIB_INDEX_REXX: |
167 rexByte |= createRexData(X86Field.REX_X_BIT_INDEX, arguments.get(i), unconditionalRexBit); | 165 curRexByte |= createRexData(X86Field.REX_X_BIT_INDEX, arguments.get(i), unconditionalRexBit); |
168 // fall through... | 166 // fall through... |
169 case SIB_INDEX: | 167 case SIB_INDEX: |
170 sibByte |= createFieldData(X86Field.INDEX, argument); | 168 sibByte |= createFieldData(X86Field.INDEX, argument); |
171 break; | 169 break; |
172 case SIB_SCALE: | 170 case SIB_SCALE: |
196 throw ProgramError.unexpected(); | 194 throw ProgramError.unexpected(); |
197 } | 195 } |
198 } | 196 } |
199 break; | 197 break; |
200 case OPCODE1_REXB: | 198 case OPCODE1_REXB: |
201 rexByte |= createRexData(X86Field.REX_B_BIT_INDEX, arguments.get(i), unconditionalRexBit); | 199 curRexByte |= createRexData(X86Field.REX_B_BIT_INDEX, arguments.get(i), unconditionalRexBit); |
202 // fall through... | 200 // fall through... |
203 case OPCODE1: | 201 case OPCODE1: |
204 opcode1 |= (int) argument & 7; | 202 opcode1 |= (int) argument & 7; |
205 break; | 203 break; |
206 case OPCODE2_REXB: | 204 case OPCODE2_REXB: |
207 rexByte |= createRexData(X86Field.REX_B_BIT_INDEX, arguments.get(i), unconditionalRexBit); | 205 curRexByte |= createRexData(X86Field.REX_B_BIT_INDEX, arguments.get(i), unconditionalRexBit); |
208 // fall through... | 206 // fall through... |
209 case OPCODE2: | 207 case OPCODE2: |
210 opcode2 |= (int) argument & 7; | 208 opcode2 |= (int) argument & 7; |
211 break; | 209 break; |
212 } | 210 } |
213 } | 211 } |
214 if (rexByte > 0) { | 212 if (curRexByte > 0) { |
215 emit(rexByte); | 213 emit(curRexByte); |
216 } | 214 } |
217 if (template.addressSizeAttribute() != addressWidth) { | 215 if (template.addressSizeAttribute() != addressWidth) { |
218 emit(X86Opcode.ADDRESS_SIZE); | 216 emit(X86Opcode.ADDRESS_SIZE); |
219 } | 217 } |
220 if (template.operandSizeAttribute() == WordWidth.BITS_16) { | 218 if (template.operandSizeAttribute() == WordWidth.BITS_16) { |