def compute(self, data):
        """Compute the CRC of all data words in :py:`data`.

        Parameters
        ----------
        data : iterable of :class:`int`
            Data words, each of which is :py:`data_width` bits wide.
        """
        # Precompute some constants we use every iteration.
        word_max = (1 << self.data_width) - 1
        top_bit = 1 << (self._crc_width + self.data_width - 1)
        crc_mask = (1 << (self._crc_width + self.data_width)) - 1
        poly_shifted = self._polynomial << self.data_width

        # Implementation notes:
        # We always compute most-significant bit first, which means the polynomial and initial
        # value may be used as-is, and the reflect_in and reflect_out values have their usual sense.
        # However, when computing word-at-a-time and MSbit-first, we must align the input word so
        # its MSbit lines up with the MSbit of the previous CRC value. When the CRC width is smaller
        # than the word width, this would normally truncate data bits. Instead, we shift the initial
        # CRC left by the data width, and the data word left by the crc width, lining up their
        # MSbits no matter the relation between the two widths. The new CRC is then shifted right by
        # the data width before output.

        crc = self._initial_crc << self.data_width
        for word in data:
            if not 0 <= word <= word_max:
                raise ValueError(f"data word must be between 0 and {word_max - 1}")

            if self._reflect_input:
                word = self._reflect(word, self.data_width)

            crc ^= word << self._crc_width
            for _ in range(self.data_width):
                if crc & top_bit:
                    crc = (crc << 1) ^ poly_shifted
                else:
                    crc <<= 1
            crc &= crc_mask

        crc >>= self.data_width
        if self._reflect_output:
            crc = self._reflect(crc, self._crc_width)

        crc ^= self._xor_output
        return crc
Compute the CRC of all data words in :py:`data`.

        Parameters
        ----------
        data : iterable of :class:`int`
            Data words, each of which is :py:`data_width` bits wide.
        
amaranth/lib/crc/__init__.py