Commit Graph
390 Commits
Author SHA1 Message Date
Stephen Canon dbffff1ea5 Add some basic documentation. 2023-04-26 18:34:48 -04:00
Stephen Canon 7953ef315a First pass. 2023-04-26 16:43:50 -04:00
Stephen Canon 93e5499e54 Merge pull request #214 from stephentyrone/rilakkuma
Initial pass at "relaxed" multiply and add operations.
2023-04-26 09:14:35 -04:00
Stephen Canon 740cc5012f Some cleanups to relaxed arithmetic. 2023-04-26 09:05:28 -04:00
Stephen Canon f6b0aeb607 Remove _mulAdd in favor of Relaxed.multiplyAdd. 2023-04-26 08:56:43 -04:00
Stephen Canon 313ab7266a No longer need pre-5.4 clang workaround. 2023-04-26 08:56:43 -04:00
Steve (Numerics) Canon 30c01a9fc5 Possible spelling: Relaxed.sum/product. 2023-04-26 08:56:43 -04:00
Stephen Canon 9a23fdf1c9 Fewer iterations for debug; more for release. 2023-04-26 08:56:43 -04:00
Stephen Canon 86699a7f8a Undef what we def. 2023-04-26 08:56:43 -04:00
Stephen Canon b750c890b7 Don't use reassociate(on) on older clang toolchains. 2023-04-26 08:56:43 -04:00
Stephen Canon 79390164f5 CMake support for newer tests. 2023-04-26 08:56:43 -04:00
Stephen Canon 0fff91683a Disable _Float16 shims for relaxed operations on Intel.
The C type isn't available yet in clang on i386 or x86_64; once the calling conventions are stabilized in clang, we can reenable this.
2023-04-26 08:56:43 -04:00
Stephen Canon 9c0332d570 Initial pass at "relaxed" multiply and add operations.
This commit adds the following to the RealFunctions protocol:

    static func _relaxedAdd(_:Self, _:Self) -> Self
    static func _relaxedMul(_:Self, _:Self) -> Self

These are equivalent to + and *, but have "relaxed semantics"; specifically, they license the compiler to reassociate them and to form FMA nodes, which are both significant optimizations that can easily make many common loops 8-10x faster. These transformation perturb results slightly, so they should not be enabled without care, but the results with the relaxed operations are--for most purposes--"just as good as" (and often better than) what strict operations produce. The main thing to beware of is that they are no longer portable; different compiler versions and different targets and optimization flags will result in different results.

They are underscored because they are not stable API. In particular:
- `RealFunctions` is not really the right protocol for these (and neither is `Real`). I need to do some thinking about where to attach them.
- Even if it were the right protocol, these are more like implementation hooks than the API I really want people to use (TBD).
- I like "relaxed" more than other commonly used idioms ("fast"), but I'm not sure it's the name I ultimately want.
2023-04-26 08:56:43 -04:00
Stephen Canon 97c716ba37 Merge pull request #240 from stephentyrone/bump-to-5.5
Bump tools version to 5.5, add @swift-5.4 for legacy support.
2022-12-28 18:33:20 -05:00
Steve (Numerics) Canon 8353ce4c3d Bump tools version to 5.5, add @swift-5.4 for legacy support. 2022-12-28 18:25:22 -05:00
Stephen Canon 5428505255 Merge pull request #237 from stephentyrone/send-it
Mark Complex Sendable when the underlying RealType is.
2022-09-30 18:48:03 -04:00
Stephen Canon e601f16e20 Mark Complex Sendable when the underlying RealType is. 2022-09-30 14:07:49 -04:00
Stephen Canon 6c4accd836 Merge pull request #236 from stephentyrone/further-complex-pow-tweaks
Further improvement to Complex.pow(_:Self,_:Self) edge cases.
2022-09-17 15:01:40 -04:00
Stephen Canon 60a3edbaa9 Further improvement to Complex.pow(_:Self,_:Self) edge cases.
Bring pow(zero, w) in line with the behavior of pow for the underlying real type.
2022-09-17 14:56:29 -04:00
Stephen Canon 89cfa62803 Merge pull request #235 from stephentyrone/complex-pow
Fix edge-cases for Complex.pow(.zero, <Int>), and Real.pow(zero, zero)
2022-09-15 19:05:35 -04:00
Stephen Canon 2baff8fc30 Also fixup real edge cases for pow(0,0). 2022-09-15 16:10:17 -04:00
Stephen Canon b9e8b970f2 Fixup indentation. 2022-09-15 15:39:34 -04:00
Stephen Canon d34f5636c4 Fix the edge-case handling of Complex.pow(.zero, <int>) 2022-09-15 15:07:06 -04:00
Stephen Canon 2624562948 Merge pull request #233 from xymus/missing-import-for-conformance
Add missing import required to use a conformance
2022-07-12 14:31:29 -04:00
Alexis Laferrière c8e3d9f54b Add missing import required to use a conformance
A new compiler check reports a missing import for a conformance
implicitly imported:

```
Sources/_TestSupport/Error.swift:21:13: error: cannot use conformance of
'Float' to 'Real' here; 'RealModule' was not imported by this file
public func componentwiseError(_ tst: Complex<Float>, _ ref:
Complex<Double>) -> Double {
            ^
```

Address this issue in the project by adding the missing import.
2022-07-11 14:44:42 -07:00
Stephen Canon a7ceb774fe Merge pull request #231 from markuswntr/patch-1
Fix broken link to `IntegerUtilities` in README.md
2022-06-20 09:26:24 -10:00
Markus Winter 0ea36c3109 Update README.md 2022-06-16 08:16:18 +02:00
Stephen Canon 0dc8fef6e9 Merge pull request #227 from buttaface/math
Link math library on Android too
2022-04-07 22:35:51 -04:00
Stephen Canon 98a8a166df Merge pull request #226 from compnerd/patch-1
Update CMakeLists.txt to link math library on Linux.
2022-04-07 17:25:38 -04:00
Saleem Abdulrasool 0d9f0b2a98 Update CMakeLists.txt
Adjust the CMake build system to reflect the recent changes of requiring the explicit linking of libm on Linux platforms.
2022-04-07 14:24:06 -07:00
Butta 1db31ebdf0 Link math library on Android too 2022-04-07 23:27:42 +05:30
Stephen Canon 48003e8b7a Fixup banner comment on Scale.swift. 2022-04-07 10:18:54 -04:00
Stephen Canon 56db9b5ec9 Merge pull request #225 from apple/remove-differentiable
Remove conformance of Complex to Differentiable
2022-04-06 23:15:28 -04:00
Stephen Canon 5803eaf5bb Let's try a different approach. 2022-04-06 22:42:21 -04:00
Stephen Canon cc53a7b085 Make _NumericsShims a systemLibrary target. 2022-04-06 15:21:00 -04:00
Stephen Canon 027bcc5b8e Remove conformance of Complex to Differentiable
The conformance was breaking CI testing, because the CI bots use a macOS version that predates availability of the _Differentiation module, and the compiler-generated differentation operations have neither availability attributes nor checks, so any reference to those operations simply crashes in dyld because the library is not present. We can add availability, but that's not really accurate either, because these operations are not actually binary-stable, so while we wouldn't crash in dyld, we also might not work correctly in the future. We could mark them unavailable on Apple platforms, but that's also not quite right (and further means that they're not going to get a lot of attention). The best solution seems to be to remove the conformance (which was never source-stable).
2022-04-06 14:41:04 -04:00
Stephen Canon fc1b2d1e67 Merge pull request #224 from apple/documentation-formatting
Minor documentation formatting cleanup.
2022-04-06 13:21:32 -04:00
Stephen Canon 270972dd8a Minor documentation formatting cleanup. 2022-04-06 11:50:25 -04:00
Stephen Canon b6018fa8a9 Merge pull request #222 from NevinBR/patch-1
GCD bug fix
2022-04-06 10:04:39 -04:00
Stephen Canon 5bbf0e2229 Merge pull request #223 from stephentyrone/require-swift-5.4
Move baseline supported tools version to 5.4
2022-04-06 10:00:56 -04:00
Stephen Canon 27f8192a63 Attempt to work around CI misconfiguration by removing Complex Differentiable conformance. 2022-04-06 09:58:40 -04:00
Stephen Canon c4f8886a11 Move baseline supported tools version to 5.4. 2022-03-05 10:18:13 -05:00
NevinBR 7f2d022d3d GCD bug fix
The standard-library documentation for `trailingZeroBitCount` states:

> If the value is zero, then `trailingZeroBitCount` is equal to `bitWidth`.

Thus, if `T` is not a fixed-width integer type, and `x == 0`, and `y` has more trailing zeros than the representation of `x`, then the gcd calculation will be incorrect.

In particular, the left-shift by `min(xtz, ytz) == xtz` will not “undo” the earlier right-shift by `ytz`,  so the final result will be incorrectly right-shifted by `ytz - xtz`.

To fix this I have added an early exit when `x == 0`. I am not sure if this is the optimal solution, and I’m open to alternatives.

***

This change ensures that `x != 0` at the top of the loop, so I have also converted it from a `while` to a `repeat-while` loop, in order to eliminate a redundant extra comparison on the first iteration.

I don’t know if this actually affects performance, and I’m happy to change it back if that’s preferred.
2022-02-22 11:46:06 -05:00
Stephen Canon 4ce74b4235 Merge pull request #220 from stephentyrone/refactor-complex-cmake
Update complex cmake for refactoring.
2021-12-16 15:19:39 -05:00
Stephen Canon 445b0da15d Update complex cmake for refactoring. 2021-12-16 13:38:20 -05:00
Stephen Canon 9596f40d3b Merge pull request #219 from stephentyrone/refactor-complex
Refactor complex
2021-12-16 13:33:55 -05:00
Stephen Canon d329698498 remove F16/F80 stubs for complex elfns. 2021-12-11 14:57:36 -05:00
Stephen Canon ba65b0fc77 Refactor Complex module for finer granularity. 2021-12-11 11:19:29 -05:00
Stephen Canon 1939f34fde Merge pull request #217 from stephentyrone/double-width-testing-right-shift
Use DoubleWidth in stochastic rounding right-shift tests.
2021-11-24 11:40:29 -05:00
Stephen Canon 47a233758d Use DoubleWidth in stochastic rounding right-shift tests.
This lets us get rid of Double here, and get more meaningful test coverage for 64b values. Also test 128b to cover double-width itself somewhat.
2021-11-24 11:35:40 -05:00