// hasExit determines if the given program has at least one // unconditional EXIT instruction. func hasExit(bin []cpu.Word) bool { var op1, op2, a, b cpu.Word var size int for i := 0; i < len(bin); i++ { op1, a, b = cpu.Decode(bin[i]) // Not an EXIT. Skip with next word. if !(op1 == cpu.EXT && a == cpu.EXIT) { continue } // If the previous instruction is not a branching instruction, // we have found a non-conditional EXIT. op2, _, _ = cpu.Decode(bin[i-size]) if op2 < cpu.IFB || op2 > cpu.IFU { return true } // Determine size of instruction. // Some of them occupy multiple words. size = 1 if op1 != cpu.EXT && (a == 0x1e || a == 0x1f || (a >= 0x10 && a <= 0x17)) { size++ } if b == 0x1e || b == 0x1f || (b >= 0x10 && b <= 0x17) { size++ } } return false }
// Cost returns the cycle cost for this entry. func (p *ProfileData) Cost() uint8 { var c uint8 op, a, b := cpu.Decode(p.Data) if op == cpu.EXT { c = opcodes[a] if b <= 0x1f { c += operands[b] } } else { c = opcodes[op] if a <= 0x1f { c += operands[a] } if b <= 0x1f { c += operands[b] } } return c }