| 1631 | } |
| 1632 | |
| 1633 | void decode_ise(int quantization_level, int elements, const uint8_t* input_data, uint8_t* output_data, int bit_offset) |
| 1634 | { |
| 1635 | int i; |
| 1636 | // note: due to how the the trit/quint-block unpacking is done in this function, |
| 1637 | // we may write more temporary results than the number of outputs |
| 1638 | // The maximum actual number of results is 64 bit, but we keep 4 additional elements |
| 1639 | // of padding. |
| 1640 | uint8_t results[68]; |
| 1641 | uint8_t tq_blocks[22]; // trit-blocks or quint-blocks |
| 1642 | |
| 1643 | int bits, trits, quints; |
| 1644 | find_number_of_bits_trits_quints(quantization_level, &bits, &trits, &quints); |
| 1645 | |
| 1646 | int lcounter = 0; |
| 1647 | int hcounter = 0; |
| 1648 | |
| 1649 | // trit-blocks or quint-blocks must be zeroed out before we collect them in the loop below. |
| 1650 | for (i = 0; i < 22; i++) |
| 1651 | tq_blocks[i] = 0; |
| 1652 | |
| 1653 | // collect bits for each element, as well as bits for any trit-blocks and quint-blocks. |
| 1654 | for (i = 0; i < elements; i++) |
| 1655 | { |
| 1656 | results[i] = (uint8_t)read_bits(bits, bit_offset, input_data); |
| 1657 | bit_offset += bits; |
| 1658 | if (trits) |
| 1659 | { |
| 1660 | static const int bits_to_read[5] = {2, 2, 1, 2, 1}; |
| 1661 | static const int block_shift[5] = {0, 2, 4, 5, 7}; |
| 1662 | static const int next_lcounter[5] = {1, 2, 3, 4, 0}; |
| 1663 | static const int hcounter_incr[5] = {0, 0, 0, 0, 1}; |
| 1664 | int tdata = read_bits(bits_to_read[lcounter], bit_offset, input_data); |
| 1665 | bit_offset += bits_to_read[lcounter]; |
| 1666 | tq_blocks[hcounter] |= tdata << block_shift[lcounter]; |
| 1667 | hcounter += hcounter_incr[lcounter]; |
| 1668 | lcounter = next_lcounter[lcounter]; |
| 1669 | } |
| 1670 | if (quints) |
| 1671 | { |
| 1672 | static const int bits_to_read[3] = {3, 2, 2}; |
| 1673 | static const int block_shift[3] = {0, 3, 5}; |
| 1674 | static const int next_lcounter[3] = {1, 2, 0}; |
| 1675 | static const int hcounter_incr[3] = {0, 0, 1}; |
| 1676 | int tdata = read_bits(bits_to_read[lcounter], bit_offset, input_data); |
| 1677 | bit_offset += bits_to_read[lcounter]; |
| 1678 | tq_blocks[hcounter] |= tdata << block_shift[lcounter]; |
| 1679 | hcounter += hcounter_incr[lcounter]; |
| 1680 | lcounter = next_lcounter[lcounter]; |
| 1681 | } |
| 1682 | } |
| 1683 | |
| 1684 | // unpack trit-blocks or quint-blocks as needed |
| 1685 | if (trits) |
| 1686 | { |
| 1687 | int trit_blocks = (elements + 4) / 5; |
| 1688 | for (i = 0; i < trit_blocks; i++) |
| 1689 | { |
| 1690 | const uint8_t* tritptr = trits_of_integer[tq_blocks[i]]; |
no test coverage detected