#// Copyright 2010 The Code Cavern

#//	bda_nand_n(bda_ptr,bda_srcptr,bda_srcptr,bda_len)

.global bda_nand_n
bda_nand_n:
lea (%rdx,%rcx,8),%rdx
lea (%rsi,%rcx,8),%rsi
lea (%rdi,%rcx,8),%rdi
neg %rcx
add $3,%rcx
jc skip
	mov -24(%rdx,%rcx,8),%r8
	mov -16(%rdx,%rcx,8),%r9
	mov -24(%rdx,%rcx,8),%r8
	mov -16(%rdx,%rcx,8),%r9
add $4,%rcx
	mov -8-32(%rdx,%rcx,8),%r10
	mov -32(%rdx,%rcx,8),%r11
jc skiplp
.align 16
lp:
	and -24-32(%rsi,%rcx,8),%r8
	not %r8
	and -16-32(%rsi,%rcx,8),%r9
	and -8-32(%rsi,%rcx,8),%r10
	and -32(%rsi,%rcx,8),%r11
	mov %r8,-24-32(%rdi,%rcx,8)
	not %r9
	not %r10
	mov %r9,-16-32(%rdi,%rcx,8)
	not %r11
	mov -24(%rdx,%rcx,8),%r8
	mov -16(%rdx,%rcx,8),%r9
	mov %r10,-8-32(%rdi,%rcx,8)
	mov %r11,-32(%rdi,%rcx,8)
	add $4,%rcx
	mov -8-32(%rdx,%rcx,8),%r10
	mov -32(%rdx,%rcx,8),%r11
	jnc lp
skiplp:
	and -24-32(%rsi,%rcx,8),%r8
	not %r8
	and -16-32(%rsi,%rcx,8),%r9
	and -8-32(%rsi,%rcx,8),%r10
	and -32(%rsi,%rcx,8),%r11
	mov %r8,-24-32(%rdi,%rcx,8)
	not %r9
	not %r10
	mov %r9,-16-32(%rdi,%rcx,8)
	not %r11
	mov %r10,-8-32(%rdi,%rcx,8)
	mov %r11,-32(%rdi,%rcx,8)
skip:
cmp $2,%rcx
jg case0
je case1
jp case2
case3:	mov -24(%rdx),%r8
	and -24(%rsi),%r8
	not %r8
	mov %r8,-24(%rdi)
case2:	mov -16(%rdx),%r8
	and -16(%rsi),%r8
	not %r8
	mov %r8,-16(%rdi)
case1:	mov -8(%rdx),%r8
	and -8(%rsi),%r8
	not %r8
	mov %r8,-8(%rdi)
case0:	ret
