/** * Updates the CRC value based on Packet p. * * @param p The packet which is used to update the CRC. */ public void updateCRC(Packet p) { List<Integer> data = p.getData(); if (data.size() == 0) { // If there isn't any data, we don't need to update the CRC return; } int regAddress; if (p.getPacketType() == PacketType.ONE) { RegisterType regType = p.getRegType(); if (regType == RegisterType.NONE) { // Invalid register type return; } else if (regType == RegisterType.CMD && data.get(0) == 0x00000007) { // RCRC command crcValue = 0; return; } regAddress = regType.Address(); } else regAddress = 0x00000002; // If type 2, we will assume FDRI for (int d : data) { for (int i = 0; i < 32; i++) { // Shift in the data one bit at a time shiftIn_OneBit(d >> i); } for (int i = 0; i < 5; i++) { // Shift in the reg address one bit at a time shiftIn_OneBit(regAddress >> i); } } } // end UpdateCRC
/** * Iterates over the predecessors of this instruction, and merges all the post-instruction * register types for the given register. Any dead, unreachable, or odexed predecessor is ignored * * @param registerNumber the register number * @return The register type resulting from merging the post-instruction register types from all * predecessors */ protected RegisterType mergePreRegisterTypeFromPredecessors(int registerNumber) { RegisterType mergedRegisterType = null; for (AnalyzedInstruction predecessor : predecessors) { RegisterType predecessorRegisterType = predecessor.postRegisterMap[registerNumber]; assert predecessorRegisterType != null; mergedRegisterType = predecessorRegisterType.merge(mergedRegisterType); } return mergedRegisterType; }
/* * Sets the "post-instruction" register type as indicated. * @param registerNumber Which register to set * @param registerType The "post-instruction" register type * @returns true if the given register type is different than the existing post-instruction register type */ protected boolean setPostRegisterType(int registerNumber, RegisterType registerType) { assert registerNumber >= 0 && registerNumber < postRegisterMap.length; assert registerType != null; RegisterType oldRegisterType = postRegisterMap[registerNumber]; if (oldRegisterType.equals(registerType)) { return false; } postRegisterMap[registerNumber] = registerType; return true; }
public AnalyzedInstruction(Instruction instruction, int instructionIndex, int registerCount) { this.instruction = instruction; this.originalInstruction = instruction; this.instructionIndex = instructionIndex; this.postRegisterMap = new RegisterType[registerCount]; this.preRegisterMap = new RegisterType[registerCount]; RegisterType unknown = RegisterType.getRegisterType(RegisterType.UNKNOWN, null); for (int i = 0; i < registerCount; i++) { preRegisterMap[i] = unknown; postRegisterMap[i] = unknown; } }
/* * Merges the given register type into the specified pre-instruction register, and also sets the post-instruction * register type accordingly if it isn't a destination register for this instruction * @param registerNumber Which register to set * @param registerType The register type * @returns true If the post-instruction register type was changed. This might be false if either the specified * register is a destination register for this instruction, or if the pre-instruction register type didn't change * after merging in the given register type */ protected boolean mergeRegister( int registerNumber, RegisterType registerType, BitSet verifiedInstructions) { assert registerNumber >= 0 && registerNumber < postRegisterMap.length; assert registerType != null; RegisterType oldRegisterType = preRegisterMap[registerNumber]; RegisterType mergedRegisterType = oldRegisterType.merge(registerType); if (mergedRegisterType.equals(oldRegisterType)) { return false; } preRegisterMap[registerNumber] = mergedRegisterType; verifiedInstructions.clear(instructionIndex); if (!setsRegister(registerNumber)) { postRegisterMap[registerNumber] = mergedRegisterType; return true; } return false; }