Skip to content

Instantly share code, notes, and snippets.

@leonardoeloy
Last active December 17, 2015 23:39
Show Gist options
  • Save leonardoeloy/5691141 to your computer and use it in GitHub Desktop.
Save leonardoeloy/5691141 to your computer and use it in GitHub Desktop.
O_O!
static inline unsigned short fe_ip_checksum(unsigned char *iph, unsigned int ihl) {
unsigned int soma;
asm volatile(
"movl (%1), %0" \
"subl $4, %2" \
"jbe 2f" \
"addl 4(%1), %0" \
"adcl 8(%1), %0" \
"adcl 12(%1), %0" \
"1: adcl 16(%1), %0" \
"lea 4(%1), %1" \
"decl %2" \
"jne 1b" \
"adcl $0, %0" \
"movl %0, %2" \
"shrl $16, %0" \
"addw %w2, %w0" \
"adcl $0, %0" \
"notl %0" \
"2:" \
" " \
: "=r" (soma), "=r" (iph), "=r" (ihl) : "1" (iph), "2" (ihl));
return soma;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment