Skip to content

Instantly share code, notes, and snippets.

@silvioq
Created July 12, 2011 15:49
Show Gist options
  • Save silvioq/1078249 to your computer and use it in GitHub Desktop.
Save silvioq/1078249 to your computer and use it in GitHub Desktop.
#ifdef __GNUC__
#include <stdint.h>
static int32_t wordval;
static int32_t start_neg_pow2 ;
uint16_t lookKbits(uint8_t k)
{
__asm__("movb %0,%%dl" : : "g"(k) );
__asm__("movb 6,%cl");
__asm__("subb %dl,%cl");
__asm__("movl wordval, %eax" );
__asm__("shrl %cl,%eax");
}
uint16_t WORD_hi_lo(uint8_t byte_high,uint8_t byte_low)
{
__asm__("movb %0,%%ah" : : "g"(byte_high));
__asm__("movb %0,%%al" : : "g"(byte_low));
}
int16_t get_svalue(uint8_t k)
// k>0 always
// Takes k bits out of the BIT stream (wordval), and makes them a signed value
{
__asm__("xorl %ecx,%ecx");
__asm__("movb %0,%%cl" : : "g"(k) );
__asm__("movl wordval,%eax");
__asm__("shll %cl,%eax");
__asm__("shrl $16,%eax");
__asm__("decb %cl");
__asm__("btl %ecx,%eax");
__asm__("jc end_macro");
__asm__("signed_value:incb %cl");
__asm__("movl start_neg_pow2,%ebx");
__asm__("addw (%ebx,%ecx,2),%ax");
__asm__("end_macro:");
}
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment