-
-
Notifications
You must be signed in to change notification settings - Fork 64
Expand file tree
/
Copy pathilogbf.src
More file actions
70 lines (62 loc) · 1.01 KB
/
ilogbf.src
File metadata and controls
70 lines (62 loc) · 1.01 KB
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
60
61
62
63
64
65
66
67
68
69
70
.assume adl=1
.include "errno.inc"
.include "fenv.inc"
.include "math.inc"
.if !(FP_ILOGBNAN == 0x7FFFFF)
.print "ilogbf/ilogb assumes that FP_ILOGBNAN == 0x7FFFFF (INT_MAX)"
.err
.endif
.if !(FP_ILOGB0 - 1 == FP_ILOGBNAN)
.print "ilogbf/ilogb assumes FP_ILOGB0 - 1 == FP_ILOGBNAN"
.err
.endif
.section .text
.global _ilogbf
.type _ilogbf, @function
.global _ilogb
.type _ilogb, @function
; int ilogbf(float)
_ilogbf:
_ilogb:
ld hl, 6
add hl, sp
ld a, (hl)
dec hl
dec hl
dec hl
ld hl, (hl)
add hl, hl
adc a, a
jr z, .L.maybe_subnormal
inc a
jr z, .L.inf_nan
sub a, 128 ; float32_bias + 1
sbc hl, hl
ld l, a
ret
.L.maybe_subnormal:
add hl, de
or a, a
sbc hl, de
jr z, .L.ret_zero
call __ictlz
cpl
add a, 130
sbc hl, hl
ld l, a
ret
.L.inf_nan:
scf
.L.ret_zero:
ld hl, EDOM
ld (_errno), hl
ld hl, ___fe_cur_env
set FE_INVALID_BIT, (hl)
ld hl, $800000 ; FP_ILOGB0
ret nc
; FP_ILOGBNAN or INT_MAX when carry is set
dec hl
ret
.extern _errno
.extern ___fe_cur_env
.extern __ictlz