-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Base.issubnormal(::BFloat16)
is missing
#86
Comments
Could we not just check that the exponent bits are all zero? i.e. |
@milankl No; recall that zero has encoding |
Riiight my bad! But now I see what you mean by "clean", the conversion to Float32 (that I wanted to avoid) is indeed compiled away. Bit surprised to see that, but yes I would naively check for exponent = 0 and mantissa > 0. Not sure whether relying on the compiler translating to that is the best strategy though given we already know what we actually want to do in bitwise operations? Sure what you suggest is short but much less literal? |
Actually you write |
That's fair! I was also surprised to see the compiler could entirely reason away the conversion to |
As another data point, this also generates good assembly on x86-64. .text
.file "issubnormal"
.globl julia_issubnormal_787 # -- Begin function julia_issubnormal_787
.p2align 4, 0x90
.type julia_issubnormal_787,@function
julia_issubnormal_787: # @julia_issubnormal_787
# %bb.0: # %top
push rbp
mov rbp, rsp
test edi, 32640
sete cl
test dil, 127
setne al
and al, cl
pop rbp
ret
.Lfunc_end0:
.size julia_issubnormal_787, .Lfunc_end0-julia_issubnormal_787
# -- End function
.section ".note.GNU-stack","",@progbits |
The floating-point introspection function
issubnormal(x)
is not implemented forx::BFloat16
. Since BFloat16 has the same exponent range as Float32, I suggest the following implementation:This compiles to nice, clean assembly, at least on arm:
The text was updated successfully, but these errors were encountered: