- if (ostream->num_bytes_remaining + (ostream->output -
- ostream->bit_output) < 2)
- return 1;
-
- /* It is tricky to output the bits correctly. The correct way
- * is to output little-endian 2-byte words, such that the bits
- * in the SECOND byte logically precede those in the FIRST byte.
- * While the byte order is little-endian, the bit order is
- * big-endian; the first bit in a byte is the high-order one.
- * Any multi-bit numbers are in bit-big-endian form, so the
- * low-order bit of a multi-bit number is the LAST bit to be
- * output. */
- rem_bits = num_bits - ostream->free_bits;
- ostream->bitbuf <<= ostream->free_bits;
- ostream->bitbuf |= bits >> rem_bits;
- flush_bits(ostream);
- ostream->free_bits = 16 - rem_bits;
- ostream->bitbuf = bits;
+ *(le16*)ostream->bit_output = cpu_to_le16(ostream->bitbuf);
+ ostream->bit_output = ostream->next_bit_output;
+ ostream->next_bit_output = ostream->output;
+ ostream->output += 2;
+ ostream->bytes_remaining -= 2;