def _encode_read_operands(self,
            add_a=REGISTERS['r0'], add_b=REGISTERS['r0'],
            mul_a=REGISTERS['r0'], mul_b=REGISTERS['r0']):
        """Encode input muxes, raddr_a, raddr_b, unpack from given four source
        registers.
        """

        operands = [add_a, add_b, mul_a, mul_b]
        muxes = [None, None, None, None]
        unpack_bits = 0
        pm_bit = 0
        raddr_a = None
        raddr_b = None
        small_imm = None

        # Encode unpacking.
        for opd in operands:
            if not isinstance(opd, Register):
                continue
            if opd.unpack_bits:
                if unpack_bits == 0:
                    unpack_bits = opd.unpack_bits
                    pm_bit = opd.pm_bit
                elif (opd.unpack_bits != unpack_bits or opd.pm_bit != pm_bit):
                    raise AssembleError('Conflict of unpacking')

        # Assign input muxes for accumulators.
        for i, opd in enumerate(operands):
            if isinstance(opd, Register) and ACCUMULATORS in opd.name:
                muxes[i] = _INPUT_MUXES[opd.name]

        if all(m is not None for m in muxes):
            null_addr = REGISTERS['null'].addr
            return [muxes, null_addr, null_addr, False, unpack_bits, pm_bit]

        # Locate operands which have to be regfile B register.
        for i, opd in enumerate(operands):
            if muxes[i] is not None or not isinstance(opd, Register):
                continue
            if opd.spec & _REG_BR and not (opd.spec & _REG_AR):
                if raddr_b is None:
                    raddr_b = opd.addr
                    muxes[i] = _INPUT_MUXES['B']
                elif raddr_b == opd.addr:
                    muxes[i] = _INPUT_MUXES['B']
                else:
                    raise AssembleError('Too many regfile B source operand')

        # Locate small immediates.
        for i, opd in enumerate(operands):
            if muxes[i] is not None or isinstance(opd, Register):
                continue

            imm = _SMALL_IMM[repr(opd)]
            if small_imm is None:
                small_imm = imm
                muxes[i] = _INPUT_MUXES['B']
            elif small_imm == imm:
                muxes[i] = _INPUT_MUXES['B']
            else:
                raise AssembleError('Too many immediates')

        # Check of raddr_b conflict.
        if small_imm is not None and raddr_b is not None:
            raise AssembleError(
                'Conflict of regfile B source operand and immedaite value'
                )
        if small_imm is not None:
            raddr_b = small_imm

        # Locate operands which have to be regfile A register.
        for i, opd in enumerate(operands):
            if muxes[i] is not None:
                continue
            if opd.spec & _REG_AR and not (opd.spec & _REG_BR):
                if raddr_a is None:
                    raddr_a = opd.addr
                    muxes[i] = _INPUT_MUXES['A']
                elif raddr_a == opd.addr:
                    muxes[i] = _INPUT_MUXES['A']
                else:
                    raise AssembleError('Too many regfile A source operand')

        # Locate remaining operands.
        for i, opd in enumerate(operands):
            if muxes[i] is not None: continue

            if not (opd.spec & (_REG_AR | _REG_BR)):
                raise AssembleError('{} can not be a read operand'.format(opd))

            if raddr_a is None:
                raddr_a = opd.addr
                muxes[i] = _INPUT_MUXES['A']
            elif small_imm is None and raddr_b is None:
                raddr_b = opd.addr
                muxes[i] = _INPUT_MUXES['B']
            else:
                raise AssembleError('Failed to locate operand {}'.format(opd))

        if raddr_a is None:
            raddr_a = REGISTERS['null'].addr
        if raddr_b is None:
            raddr_b = REGISTERS['null'].addr

        use_small_imm = (small_imm is not None)
        return [muxes, raddr_a, raddr_b, use_small_imm, unpack_bits, pm_bit]
dataset/ETHPy150Open nineties/py-videocore/videocore/assembler.py/Emitter._encode_read_operands/swapped operands of `in`