def DecodeMaskedWords(src, dst, pos, n, tab, mask):
    """Decode n words using the specified lookup table under control of mask.
       Return new bitstream position.
    """
    if mask == 0:
        nBytes = n * 2
        dst.extend(src[pos:pos + nBytes])
        pos += nBytes
    else:
        for bn in range(7, 7 - n, -1):
            if mask & 1 << bn:
                word = tab[src[pos]]
                dst.extend(word.to_bytes(2, 'big'))
                pos += 1
            else:
                dst.extend(src[pos:pos + 2])
                pos += 2
    return pos
