-
Notifications
You must be signed in to change notification settings - Fork 0
/
pow_int.s
59 lines (48 loc) · 1.19 KB
/
pow_int.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
59
.intel_syntax noprefix
.text
.section .rodata
.LC0:
.text
.global pow_int
# Input: xmm0 = x, rdi = y
# Output: xmm0 = x^y (y is Integer)
pow_int:
push rbp # Stack-alignment
mov rbp, rsp
sub rsp, 16
pxor xmm2, xmm2
movsd xmm1, .LC1[rip] # res = 1 = xmm1 (start-value)
xor rax, rax # int neg = 0 = rax (flag for negative y)
cmp rdi, 0 # If (y > 0) -> y is negative
jg .L0
# If y negative -> set flag (neg) and negate y
mov rax, 1 # neg = 1
neg rdi # y = -y
.L0:
cmp rdi, 0
jle .L1
mulsd xmm1, xmm0 # res *= x
dec rdi # y--
comisd xmm1, xmm2 # If res = 0 -> return 0
jz .L3
cmp rdi, 0
jg .L0
.L1:
cmp rax, 1 # If (neg == 1) -> y is negative
je .L2
movsd xmm0, xmm1 # Else -> return res
leave
ret
.L2: # If y is negative -> return 1/res
movsd xmm0, .LC1[rip] # xmm0 = 1
divsd xmm0, xmm1 # 1/res
leave
ret
.L3:
pxor xmm0, xmm0
leave
ret
.section .rodata
.LC1: # 1
.long 0
.long 1072693248