Repository navigation
Give a Dynamic Float taken as an Int what Std.int gives - #517
Open
dimensionscape wants to merge 1 commit into
Open
dimensionscape wants to merge 1 commit into
dimensionscape wants to merge 1 commit into
Conversation
A Float in a Dynamic, taken as an Int (a local, an argument, a field, an array element, a return, a Dynamic sum or a bit operation), went through a plain (int) cast in DoubleData::__ToInt and in cpp::Variant, whose result past the Int range is undefined, and under the JIT through the hardware's conversion. x86 gives -2147483648 there and for NaN, while arm64 saturates and gives 0 for NaN, so 1e10 gave -2147483648 on Windows and Linux and 2147483647 on macOS. Std.int already had a rule, in the runtime's __int__: truncation in the range, the low 32 bits of the 64-bit truncation past it, and 0 for NaN, the infinities and anything past 64 bits. Under the JIT, Std.int itself, which a script writes as a cast to Int, took the hardware's conversion too. hx::DoubleToInt in hx/StdLibs.h gives that rule, casting in the range and calling __int__ past it. DoubleData::__ToInt, Variant::asInt, the interpreter's Float to Int fallback and its float builtins use it. The JIT keeps the hardware's conversion, which is the rule's in the range, and sends only the results that may stand for a Float past it to the runtime: -2147483648, and on platforms that saturate 2147483647 as well. A Float box read in line goes to objToInt with the box still in hand, and any other Float converted to an Int to the new floatToInt. A target found through a scratch register, which a call would lose, keeps the hardware's answer as before. __int__ applies its rule under Emscripten too, which it left out when asm.js had no 64-bit integers. Against c65f8be, the two bench hosts alternating on one pinned core at high priority, 9 processes x 10 samples each: cppia_jit_closure_expr 33.98M to 33.89M per second (0.997x) cppia_jit_float_array 80.67M to 81.18M per second (1.006x) cppia_jit_bunny_update 20.52M to 20.54M per second (1.001x) float_array takes Std.int of a Float in its loop. Checking both results on x86 as well cost it 2.4%, so x86, which never saturates, checks only -2147483648. DynamicFloatToInt takes Floats as Ints eight ways, the five above, a Float field of a Dynamic object, a Dynamic sum and | 0, in compiled code and as a script with the JIT off and on, and checks each against Std.int: in the range, past an Int, past 64 bits, NaN, the infinities and negative zero. The code before this fails it in all three sections, and so does a plain cast in the Float box; a plain cast in Variant, or the JIT without the rule in its conversion or its box read, fails it too. CppiaJitDynamicNumbers converts its Floats past an Int again, with the rule's values, and still leaves out the Strings past an Int that #514 defines. Tests: DynamicFloatToInt, CppiaJitDynamicNumbers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #500. This is based on
feature/cppia-perf-b621b5rather than main because its JIT half changes code that only #500 has (the in-line read of a Float box inconvert), and because it puts back the Float cases #500's CppiaJitDynamicNumbers had to leave out. When #500 merges, this retargets to main and the diff becomes this commit alone.A Float in a Dynamic, taken as an Int, went through a plain
(int)cast inDoubleData::__ToIntand incpp::Variant, whose result past the Int range is undefined, and under the JIT through the hardware's conversion. x86 gives -2147483648 there and for NaN, while arm64 saturates and gives 0 for NaN. So1e10gave -2147483648 on Windows and Linux and 2147483647 on macOS. This showed up on #500's macOS job, in CppiaJitDynamicNumbers.Std.intalready had a rule, in the runtime's__int__: truncation in the range, the low 32 bits of the 64-bit truncation past it, and 0 for NaN, the infinities and anything past 64 bits. Every way of taking a Float as an Int follows it now:hx::DoubleToIntinhx/StdLibs.hcasts in the range and calls__int__past it.DoubleData::__ToInt,Variant::asInt, the interpreter's Float to Int fallback and its float builtins use it.Std.intin a script too, which cppia writes as a cast to Int and which took the hardware's conversion under the JIT. A Float box read in line goes toobjToIntwith the box still in hand; any other Float to Int goes to the newfloatToInt.__int__applies its rule under Emscripten too, which it left out when asm.js had no 64-bit integers.Results in the Int range are unchanged everywhere.
Bench
Against c65f8be (#500's head), the two bench hosts alternating on one pinned core at high priority, 9 processes x 10 samples each:
float_arraytakesStd.intof a Float in its loop. Checking both results on x86 as well cost it 2.4%, so x86, which never saturates, checks only -2147483648.Tests
New
DynamicFloatToInttakes Floats as Ints eight ways (a local, an argument, a field, an array element, a return, a Float field of a Dynamic object, a Dynamic sum and| 0), in compiled code and as a script with the JIT off and on, and checks each againstStd.int. Its cases cover the range, past an Int, past 64 bits, NaN, the infinities and negative zero.The code before this fails it in all three sections. Each of these fails it too: a plain cast in the Float box, a plain cast in
Variant, the JIT without the rule in its conversion, and the JIT without the rule in its box read.CppiaJitDynamicNumbers converts its Floats past an Int again, with the rule's values. It still leaves out the Strings past an Int, which #514 defines; that exclusion can go once both are in.
On Windows: the whole regression suite (401), test/haxe (2,880) and test/std (696). Other platforms are left to CI.