-
Notifications
You must be signed in to change notification settings - Fork 19
/
isamax_amd64.s
58 lines (47 loc) · 873 Bytes
/
isamax_amd64.s
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// func Isamax(N int, X []float32, incX int) int
TEXT ·Isamax(SB), 7, $0
MOVQ N+0(FP), BP
MOVQ X+8(FP), SI // X.data
MOVQ incX+32(FP), AX
// Check data bounaries
MOVQ BP, CX
DECQ CX
IMULQ AX, CX // CX = incX * (N - 1)
CMPQ CX, X_len+16(FP)
JGE panic
// Max value
XORPS X0, X0
// Index
XORQ DI, DI
// Max index
XORQ BX, BX
// Mask for sign bit clear
PCMPEQW X4, X4
PSRLL $1, X4
// Setup stride
SALQ $2, AX // AX = sizeof(float32) * incX
loop:
CMPQ BP, DI
JE end
// Load value
MOVSS (SI), X1
// Clear sign of loaded value
ANDPS X4, X1
// Is loaded value less or equal to max value?
UCOMISS X0, X1
JBE less_or_equal
// Save max index and value
MOVQ DI, BX
MOVSS X1, X0
less_or_equal:
// Update data pointers
ADDQ AX, SI
INCQ DI
JMP loop
end:
// Return the max index
MOVQ BX, r+40(FP)
RET
panic:
CALL ·panicIndex(SB)
RET