// File: ctSkennerton[P]fxtract/util/fnvhash.c
// Function: fnv16
void
fnv16(char const *buf, int len, char out[16])
{
    XMM	hash = (__v2di) { 0x07BB01426C62272EULL, 0x6295C58D62B82175ULL };

    while (--len >= 0) {
        unsigned x = *buf++;
	//hash = _mm_xor_si128(hash, _mm_set_epi32(0, 0, 0, 255 & *buf++));
	hash = _mm_xor_si128(hash, _mm_set_epi32(x * 2, x * 3, x * 7, x * 11));
	/* This emulates 128bit mul of the FNV128 coefficient using shift/add/sub:
	 *	h := (h << 88) + (h << 8) + (h << 6) - (h << 2) - h
	 * "{add,sub}_epi64" each lose a carry bit (from [63] to [64]).
	 */
	hash =	_mm_sub_epi64(
		    _mm_sub_epi64(
			_mm_add_epi64(
			    _mm_add_epi64(xm_shl_013(hash),
                                          xm_shl_010(hash)),
			    xm_shl_006(hash)),
			xm_shl_002(hash)),
		    hash);
    }

    //XXX: add final mix-in!

    _mm_storeu_si128((XMM*)out, hash);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x160, %rsp            # imm = 0x160
movq %rdi, -0xe8(%rbp)
movl %esi, -0xec(%rbp)
movq %rdx, -0xf8(%rbp)
movaps 0x4e1a(%rip), %xmm0     # 0x9140
movaps %xmm0, -0x120(%rbp)
movdqa -0x120(%rbp), %xmm0
movdqa %xmm0, -0x110(%rbp)
movl -0xec(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0xec(%rbp)
cmpl $0x0, %eax
jl 0x44e4
movq -0xe8(%rbp), %rax
movq %rax, %rcx
incq %rcx
movq %rcx, -0xe8(%rbp)
movsbl (%rax), %eax
movl %eax, -0x124(%rbp)
movaps -0x110(%rbp), %xmm1
movl -0x124(%rbp), %edi
movl %edi, %esi
addl %esi, %esi
movl %edi, %eax
leal (%rax,%rax,2), %edx
movl %edi, %ecx
shll $0x3, %ecx
subl %edi, %ecx
leal (%rax,%rax,4), %r8d
movl %r8d, %edi
leal (%rax,%rdi,2), %eax
movl %esi, -0xa4(%rbp)
movl %edx, -0xa8(%rbp)
movl %ecx, -0xac(%rbp)
movl %eax, -0xb0(%rbp)
movd -0xa4(%rbp), %xmm0
movd -0xa8(%rbp), %xmm2
punpckldq %xmm0, %xmm2    # xmm2 = xmm2[0],xmm0[0],xmm2[1],xmm0[1]
movd -0xac(%rbp), %xmm3
movd -0xb0(%rbp), %xmm0
punpckldq %xmm3, %xmm0    # xmm0 = xmm0[0],xmm3[0],xmm0[1],xmm3[1]
punpcklqdq %xmm2, %xmm0    # xmm0 = xmm0[0],xmm2[0]
movdqa %xmm0, -0xc0(%rbp)
movdqa -0xc0(%rbp), %xmm0
movdqa %xmm1, -0xd0(%rbp)
movdqa %xmm0, -0xe0(%rbp)
movdqa -0xd0(%rbp), %xmm0
pxor -0xe0(%rbp), %xmm0
movdqa %xmm0, -0x110(%rbp)
movdqa -0x110(%rbp), %xmm0
callq 0x4520
movaps %xmm0, -0x160(%rbp)
movdqa -0x110(%rbp), %xmm0
callq 0x4590
movaps -0x160(%rbp), %xmm1
movdqa %xmm1, -0x30(%rbp)
movdqa %xmm0, -0x40(%rbp)
movdqa -0x30(%rbp), %xmm0
paddq -0x40(%rbp), %xmm0
movaps %xmm0, -0x150(%rbp)
movdqa -0x110(%rbp), %xmm0
callq 0x45b0
movaps -0x150(%rbp), %xmm1
movdqa %xmm1, -0x50(%rbp)
movdqa %xmm0, -0x60(%rbp)
movdqa -0x50(%rbp), %xmm0
paddq -0x60(%rbp), %xmm0
movaps %xmm0, -0x140(%rbp)
movdqa -0x110(%rbp), %xmm0
callq 0x4610
movaps -0x140(%rbp), %xmm1
movdqa %xmm1, -0x70(%rbp)
movdqa %xmm0, -0x80(%rbp)
movdqa -0x70(%rbp), %xmm1
psubq -0x80(%rbp), %xmm1
movdqa -0x110(%rbp), %xmm0
movdqa %xmm1, -0x90(%rbp)
movdqa %xmm0, -0xa0(%rbp)
movdqa -0x90(%rbp), %xmm0
psubq -0xa0(%rbp), %xmm0
movdqa %xmm0, -0x110(%rbp)
jmp 0x433d
movq -0xf8(%rbp), %rax
movdqa -0x110(%rbp), %xmm0
movq %rax, -0x8(%rbp)
movdqa %xmm0, -0x20(%rbp)
movdqa -0x20(%rbp), %xmm0
movq -0x8(%rbp), %rax
movdqu %xmm0, (%rax)
addq $0x160, %rsp            # imm = 0x160
popq %rbp
retq
nopw %cs:(%rax,%rax)