OLD | NEW |
1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 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 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
219 ASSERT(IsLdrLiteral()); | 219 ASSERT(IsLdrLiteral()); |
220 // The offset is always shifted by 2 bits, even for loads to 64-bits | 220 // The offset is always shifted by 2 bits, even for loads to 64-bits |
221 // registers. | 221 // registers. |
222 offset = ImmLLiteral() << kInstructionSizeLog2; | 222 offset = ImmLLiteral() << kInstructionSizeLog2; |
223 } | 223 } |
224 return offset; | 224 return offset; |
225 } | 225 } |
226 | 226 |
227 | 227 |
228 Instruction* Instruction::ImmPCOffsetTarget() { | 228 Instruction* Instruction::ImmPCOffsetTarget() { |
229 return this + ImmPCOffset(); | 229 return InstructionAtOffset(ImmPCOffset()); |
230 } | 230 } |
231 | 231 |
232 | 232 |
233 bool Instruction::IsValidImmPCOffset(ImmBranchType branch_type, | 233 bool Instruction::IsValidImmPCOffset(ImmBranchType branch_type, |
234 int32_t offset) { | 234 int32_t offset) { |
235 return is_intn(offset, ImmBranchRangeBitwidth(branch_type)); | 235 return is_intn(offset, ImmBranchRangeBitwidth(branch_type)); |
236 } | 236 } |
237 | 237 |
238 | 238 |
239 bool Instruction::IsTargetInImmPCOffsetRange(Instruction* target) { | 239 bool Instruction::IsTargetInImmPCOffsetRange(Instruction* target) { |
240 int offset = target - this; | 240 return IsValidImmPCOffset(BranchType(), DistanceTo(target)); |
241 return IsValidImmPCOffset(BranchType(), offset); | |
242 } | 241 } |
243 | 242 |
244 | 243 |
245 void Instruction::SetImmPCOffsetTarget(Instruction* target) { | 244 void Instruction::SetImmPCOffsetTarget(Instruction* target) { |
246 if (IsPCRelAddressing()) { | 245 if (IsPCRelAddressing()) { |
247 SetPCRelImmTarget(target); | 246 SetPCRelImmTarget(target); |
248 } else if (BranchType() != UnknownBranchType) { | 247 } else if (BranchType() != UnknownBranchType) { |
249 SetBranchImmTarget(target); | 248 SetBranchImmTarget(target); |
250 } else { | 249 } else { |
251 SetImmLLiteral(target); | 250 SetImmLLiteral(target); |
252 } | 251 } |
253 } | 252 } |
254 | 253 |
255 | 254 |
256 void Instruction::SetPCRelImmTarget(Instruction* target) { | 255 void Instruction::SetPCRelImmTarget(Instruction* target) { |
257 // ADRP is not supported, so 'this' must point to an ADR instruction. | 256 // ADRP is not supported, so 'this' must point to an ADR instruction. |
258 ASSERT(Mask(PCRelAddressingMask) == ADR); | 257 ASSERT(Mask(PCRelAddressingMask) == ADR); |
259 | 258 |
260 Instr imm = Assembler::ImmPCRelAddress(target - this); | 259 Instr imm = Assembler::ImmPCRelAddress(DistanceTo(target)); |
261 | 260 |
262 SetInstructionBits(Mask(~ImmPCRel_mask) | imm); | 261 SetInstructionBits(Mask(~ImmPCRel_mask) | imm); |
263 } | 262 } |
264 | 263 |
265 | 264 |
266 void Instruction::SetBranchImmTarget(Instruction* target) { | 265 void Instruction::SetBranchImmTarget(Instruction* target) { |
267 ASSERT(((target - this) & 3) == 0); | 266 ASSERT(IsAligned(DistanceTo(target), kInstructionSize)); |
268 Instr branch_imm = 0; | 267 Instr branch_imm = 0; |
269 uint32_t imm_mask = 0; | 268 uint32_t imm_mask = 0; |
270 int offset = (target - this) >> kInstructionSizeLog2; | 269 ptrdiff_t offset = DistanceTo(target) >> kInstructionSizeLog2; |
271 switch (BranchType()) { | 270 switch (BranchType()) { |
272 case CondBranchType: { | 271 case CondBranchType: { |
273 branch_imm = Assembler::ImmCondBranch(offset); | 272 branch_imm = Assembler::ImmCondBranch(offset); |
274 imm_mask = ImmCondBranch_mask; | 273 imm_mask = ImmCondBranch_mask; |
275 break; | 274 break; |
276 } | 275 } |
277 case UncondBranchType: { | 276 case UncondBranchType: { |
278 branch_imm = Assembler::ImmUncondBranch(offset); | 277 branch_imm = Assembler::ImmUncondBranch(offset); |
279 imm_mask = ImmUncondBranch_mask; | 278 imm_mask = ImmUncondBranch_mask; |
280 break; | 279 break; |
281 } | 280 } |
282 case CompareBranchType: { | 281 case CompareBranchType: { |
283 branch_imm = Assembler::ImmCmpBranch(offset); | 282 branch_imm = Assembler::ImmCmpBranch(offset); |
284 imm_mask = ImmCmpBranch_mask; | 283 imm_mask = ImmCmpBranch_mask; |
285 break; | 284 break; |
286 } | 285 } |
287 case TestBranchType: { | 286 case TestBranchType: { |
288 branch_imm = Assembler::ImmTestBranch(offset); | 287 branch_imm = Assembler::ImmTestBranch(offset); |
289 imm_mask = ImmTestBranch_mask; | 288 imm_mask = ImmTestBranch_mask; |
290 break; | 289 break; |
291 } | 290 } |
292 default: UNREACHABLE(); | 291 default: UNREACHABLE(); |
293 } | 292 } |
294 SetInstructionBits(Mask(~imm_mask) | branch_imm); | 293 SetInstructionBits(Mask(~imm_mask) | branch_imm); |
295 } | 294 } |
296 | 295 |
297 | 296 |
298 void Instruction::SetImmLLiteral(Instruction* source) { | 297 void Instruction::SetImmLLiteral(Instruction* source) { |
299 ASSERT(((source - this) & 3) == 0); | 298 ASSERT(IsAligned(DistanceTo(source), kInstructionSize)); |
300 int offset = (source - this) >> kLiteralEntrySizeLog2; | 299 ptrdiff_t offset = DistanceTo(source) >> kLiteralEntrySizeLog2; |
301 Instr imm = Assembler::ImmLLiteral(offset); | 300 Instr imm = Assembler::ImmLLiteral(offset); |
302 Instr mask = ImmLLiteral_mask; | 301 Instr mask = ImmLLiteral_mask; |
303 | 302 |
304 SetInstructionBits(Mask(~mask) | imm); | 303 SetInstructionBits(Mask(~mask) | imm); |
305 } | 304 } |
306 | 305 |
307 | 306 |
308 // TODO(jbramley): We can't put this inline in the class because things like | 307 // TODO(jbramley): We can't put this inline in the class because things like |
309 // xzr and Register are not defined in that header. Consider adding | 308 // xzr and Register are not defined in that header. Consider adding |
310 // instructions-a64-inl.h to work around this. | 309 // instructions-a64-inl.h to work around this. |
(...skipping 14 matching lines...) Expand all Loading... |
325 uint64_t payload = ImmMoveWide(); | 324 uint64_t payload = ImmMoveWide(); |
326 // TODO(all): If we extend ::InlineData() to support bigger data, we need | 325 // TODO(all): If we extend ::InlineData() to support bigger data, we need |
327 // to update this method too. | 326 // to update this method too. |
328 return payload; | 327 return payload; |
329 } | 328 } |
330 | 329 |
331 | 330 |
332 } } // namespace v8::internal | 331 } } // namespace v8::internal |
333 | 332 |
334 #endif // V8_TARGET_ARCH_A64 | 333 #endif // V8_TARGET_ARCH_A64 |
OLD | NEW |