Deprecated: Function get_magic_quotes_gpc() is deprecated in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 99

Deprecated: The each() function is deprecated. This message will be suppressed on further calls in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 619

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1169

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176
8000 avm2: Convert float values representable as ints to `Value::Integer` by kjarosh · Pull Request #21907 · ruffle-rs/ruffle · GitHub
Nothing Special   »   [go: up one dir, main page]

Skip to content

Conversation

kjarosh
Copy link
Member
@kjarosh kjarosh commented Oct 12, 2025

This fixes some previously failing tests.

(A new test is included too.)

This test verifies whether floats that are representable as ints are
converted to ints.
@kjarosh kjarosh added A-avm2 Area: AVM2 (ActionScript 3) T-fix Type: Bug fix (in something that's supposed to work already) labels Oct 12, 2025
@kjarosh kjarosh changed the title avm2: Convert float values representable as ints to Value::Integer avm2: Convert float values representable as ints to Value::Integer Oct 12, 2025
@kjarosh kjarosh added the waiting-on-review Waiting on review from a Ruffle team member label Oct 12, 2025
@torokati44
Copy link
Member

If I was knowledgeable about AVM2 internals at all, I would submit an approval, but I wouldn't say that I am...
And I almost asked about the estimated perf impact of this, and benchmarks - but if the current code is incorrect (and it is, as the tests show), it doesn't matter how much faster it is... 😅

@kjarosh
Copy link
Member Author
kjarosh commented Oct 13, 2025

FWIW I benchmarked several condition expression and this was the fastest

@Lord-McSweeney
Copy link
Collaborator
Lord-McSweeney commented Oct 13, 2025

How much does this increase the size of the code generated for Value::from(f64)?

@kjarosh
Copy link
Member Author
kjarosh com 8000 mented Oct 13, 2025

Old:

 movsd   qword, ptr, [rdi, +, 8], xmm0
 mov     qword, ptr, [rdi], 48
 ret

New (3.7x slower):

 maxsd   xmm1, qword, ptr, [rip, +, .LCPI5792_0]
 minsd   xmm1, qword, ptr, [rip, +, .LCPI5792_1]
 cvttsd2si edx, xmm1
 xor     ecx, ecx
 ucomisd xmm0, xmm0
 mov     rax, rdi
 cmovnp  ecx, edx
 movq    rdx, xmm0
 xorps   xmm1, xmm1
 cvtsi2sd xmm1, ecx
 movq    rsi, xmm1
 cmp     rdx, rsi
 jne     .LBB5792_1
 mov     dword, ptr, [rax, +, 8], ecx
 mov     ecx, 49
 mov     qword, ptr, [rax], rcx
 ret
.LBB5792_1:
 movsd   qword, ptr, [rax, +, 8], xmm0
 mov     ecx, 48
 mov     qword, ptr, [rax], rcx
 ret

That's a lot of instructions sadly, but I think I can get rid of range and NaN checks with unsafe stuff.

@kjarosh
Copy link
Member Author
kjarosh commented Oct 13, 2025

Using the following code reduces the number of instructions (gets rid of range and NaN checks), but it's 2-6x slower :/ I don't know why

let value_i = unsafe { value.to_int_unchecked() };
if value.to_bits() == (value_i as f64).to_bits() {
    Value::Integer(value_i)
} else {
    Value::Number(value)
}
 movq    rcx, xmm0
 cvttpd2dq xmm1, xmm0
 cvtdq2pd xmm1, xmm1
 movq    rdx, xmm1
 cmp     rcx, rdx
 jne     .LBB5793_1
 cvttsd2si ecx, xmm0
 mov     dword, ptr, [rax, +, 8], ecx
 mov     ecx, 49
 mov     qword, ptr, [rax], rcx
 ret
.LBB5793_1:
 movsd   qword, ptr, [rax, +, 8], xmm0
 mov     ecx, 48
 mov     qword, ptr, [rax], rcx
 ret

(testing on x86_64)

Looks like for some reason rustc emits nonoptimal instructions (packed instead of scalar conversions)

@kjarosh
Copy link
Member Author
kjarosh commented Oct 13, 2025

Filed rust-lang/rust#147650

@kjarosh
Copy link
Member Author
kjarosh commented Oct 13, 2025

Sorry, I didn't do my benchmarks properly. Using the unchecked version prevents inlining. When always inlining we have the checked version 3.6x slower, the unchecked is only 2.6x slower.

But unfortunately the doc says it's UB, so we shouldn't use it anyway.

@kjarosh
Copy link
Member Author
kjarosh commented Oct 14, 2025

So benchmarking shows that this PR can in some cases improve performance by 25% but in other cases worsen it by over 50%. (See https://github.com/joelgwebber/bench2d/tree/master/as3)

I'll change this to a draft, and we can think about revisiting it in the future, but for now we should focus on covering observable behaviors resulting from this PR instead of doing it like Flash Player.

@kjarosh kjarosh removed the waiting-on-review Waiting on review from a Ruffle team member label Oct 14, 2025
@kjarosh kjarosh marked this pull request as draft October 14, 2025 07:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-avm2 Area: AVM2 (ActionScript 3) T-fix Type: Bug fix (in something that's supposed to work already)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

0