//+build !noasm !appengine

// func Sum(x []uint64) uint64
TEXT ·Sum(SB),4, $32-32
    MOVQ x_ptr+0(FP), DI
    MOVQ x_len+8(FP), AX
    XORQ R8, R8
    CMPQ AX, $0
    JE done
loop:
    MOVQ (DI), R9
    ADDQ $8, DI
    ADDQ R9, R8
    DECQ AX
    JNZ loop
done:
    MOVQ R8, ret+24(FP)
    RET

//func _dp_int32(a *int32, b *int32, gN *int32, res *int32)
TEXT    ·_dp_int32(SB),4,  $0-32        
        MOVQ a+0(FP), DI
        MOVQ b+8(FP), SI
        MOVQ gN+16(FP), DX
        MOVQ res+24(FP), CX
        MOVQ (DX),R8  				// mov    r8d, dword [rdx]
        CMPQ R8,$0 					// test    r8d, r8d
        JLE  LBB0_1
        XORQ AX, AX 				// xor    eax, eax
        XORQ R9, R9 				// xor    r9d, r9d

LBB0_4: 
        MOVQ (SI)(AX*4),DX           // mov    edx, dword [rsi + 4*rax]
        MOVQ (DI)(AX*4),BX          // imul    edx, dword [rdi + 4*rax]
        IMULL BX,DX
        INCL    AX	                // inc    rax
        ADDL DX,R9                   // add    r9d, edx
        CMPL AX, R8                  // cmp    r8, rax
        JNE  LBB0_4
        JMP  LBB0_2

LBB0_1:
        XORQ R9, R9				 	// xor    r9d, r9d

LBB0_2:
        MOVQ R9,(CX) 				// mov    dword [rcx], r9d
        RET
        
        
        
        