-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[DNM] Implement Float16 #21738
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
[DNM] Implement Float16 #21738
Conversation
@swift-ci please test |
Build failed |
Build failed |
@stephentyrone I tried out Float16 locally and I have to say that constructing literals is painful: func x() {
var x: Float16 = 1.0
} results in the following SIL: https://gist.github.com/Azoy/12c131dd50b9d3610ac98e290123f8a8 . % if bits == 16:
// Trunc to Float then trunc to Float16
self = ${Self}(Float(_builtinFloatLiteral: value))
% elif ... which thankfully did get picked up by constant folding, but required adding float16 semantics: // lib/SILOptimizer/Utils/ConstantFolding.cpp Line: 963
case BuiltinFloatType::IEEE16:
return IEESemantics(16, 5, 10, false); this resulted in some very pleasing SIL: https://gist.github.com/Azoy/e9f644508454befd21c4b8cb1bfd99f0 We'd have to keep the workaround for the |
@rjmccall I also wanted to ask if it was at all feasible if floating point types could take advantage of a |
No, because that results in a double-rounding and gets some values wrong because of it. This is a temporary fix to get things working correctly, we can easily improve on it in the future. |
Yes, we can (and will) do this at some future point. In order to work efficiently and maintain ABI stability, it will probably be a bit more complex than the integer literals are, but it's on the radar. |
The biggest complexity with arbitrary-precision floating-point literals is that we cannot losslessly change the base of the source literal: if the user wrote The representation would therefore need to include:
And then maybe you'd also throw in a pre-computed |
@rjmccall Right. We want to have good support for radix 2 and 10, and nothing else really matters. There are some details to work out, but supporting those radices efficiently isn't too bad (and yes, one option is including a pre-computed |
7eb5f8a
to
29b9207
Compare
…ness of a member type
…ions inside Problem(s) which caused `ErrorExpr` to be added to AST should be diagnosed already and solver wouldn't be able to produce a viable solution in such case anyway.
… constraints for float literals
The Android CI machines cannot execute the test in the target devices. Marking the test as executable makes the test filtering know that this test needs to be executed in the target device.
…g the data structure by hand.
…-sillyness Runtime: Less eager instantiation of type metadata in the conformance cache
Tests seem to pass without these. Two calls still remain, in ModuleDecl::addFiles() and removeFiles(). It will take a bit more refactoring to eliminate those.
…a8a3deb651d2dd2fc3f8ad6 [ownership] Implement movable guaranteed scopes in ossa.
This fixes a recent source break. We need to perform the normal unqualified lookup before we handle the special case of 'Self', because there might be a type named Self defined in an outer context. Fixes <https://bugs.swift.org/browse/SR-12133> / <rdar://problem/59216636>
…gnostics Use single quotes instead of backticks in diagnostics
…g terminators when fed by load [copy], copy_value. This extends the (copy (guaranteed x)) -> (guaranteed x) optimization to handle transforming terminator arguments. This will begin to enable us to eliminate RC ops around optionals or casts. I still need to add support for eliminating copies that forward through br args and phis. <rdar://problem/56720436> <rdar://problem/56720519>
The implementation was done quite a while ago. Now, that we have support in lldb (swiftlang/llvm-project#773), we can enable it by default in the compiler. LLDB now shows the runtime failure reason, for example: * thread swiftlang#1, queue = 'com.apple.main-thread', stop reason = Swift runtime failure: arithmetic overflow frame swiftlang#1: 0x0000000100000f0d a.out`testit(a=127) at trap_message.swift:4 1 2 @inline(never) 3 func testit(_ a: Int8) -> Int8 { -> 4 return a + 1 5 } 6 For details, see swiftlang#25978 rdar://problem/51278690
…af73160c99cfaa4641e6b22
…isable-watchos-x86-simulator
…ndroidModules_RequiresCpuArm64
[docs] Updating doc list for the diagnostics ported to new framework
…-hacks [Constraint solver] Remove performance hacks for pattern type computation
build: bifurcate `_add_swift_executable_single`
[NFC] Minimize uses of 'fileprivate' after SE-0169
This isn't quite right, because it introduces double-rounding, but it will do in the short-term.
Hmm, that's a merge gone wrong. Let's try that again. |
2630 commits to implement Float16? I knew IEEE754 was tough but I didn’t know it was that tough. |
Look, I just take "keep commits small" really seriously. One character max. |
Easier for code review I see 😆 |
Real PR: #30130 |
Implement IEEE 754 binary16 as
Float16
in the stdlib conforming toBinaryFloatingPoint
andSIMDScalar
. This PR does not include availability tags to make it easier for people to experiment, but all of this API will be marked available(9999) in the final PR.Evolution proposal: swiftlang/swift-evolution#1120
Pitch thread: https://forums.swift.org/t/add-float16/33019/25