Skip to content
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "BFloat16s"
uuid = "ab4f0b2a-ad5b-11e8-123f-65d77653426b"
authors = ["Keno Fischer <[email protected]>"]
version = "0.5.1"
version = "0.5.2"

[deps]
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Expand Down
4 changes: 3 additions & 1 deletion src/bfloat16.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import Base: isfinite, isnan, precision, iszero, eps,
exponent_one, exponent_half, leading_zeros,
signbit, exponent, significand, frexp, ldexp,
round, Int16, Int32, Int64,
+, -, *, /, ^, ==, <, <=, inv,
+, -, *, /, ^, fma, ==, <, <=, inv,
abs, abs2, uabs, sqrt, cbrt,
exp, exp2, exp10, expm1,
log, log2, log10, log1p,
Expand Down Expand Up @@ -440,5 +440,7 @@ for F in (:abs, :abs2, :sqrt, :cbrt,
end
end

Base.fma(x::BFloat16, y::BFloat16, z::BFloat16) = BFloat16(fma(Float32(x), Float32(y), Float32(z)))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks very inefficient on hardware with native bf16 support.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something like

ccall("llvm.fma.bf16", llvmcall, BFloat16, (BFloat16, BFloat16, BFloat16), x, y, z)

would be better (although this should probably be handled by julia's codegen directly)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not just use llvmcall?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would be better --
I was not sure it worked correctly (at one time it did not).
I am making the change.


# irrationals
BFloat16(x::AbstractIrrational) = BFloat16(Float32(x)::Float32)
2 changes: 2 additions & 0 deletions test/mathfuncs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ for F in (:abs, :abs2, :sqrt, :cbrt,
end
end

@test fma(phi, invphi, invphi) == BFloat16(fma(Float32(phi), Float32(invphi), Float32(invphi)))

for F in (:asec, :acsc, :cosh, :acosh, :acoth)
@eval begin
@test $F(phi) == BFloat16($F(Float32(phi)))
Expand Down
Loading