From: Sergey Kaplun via Tarantool-patches <tarantool-patches@dev.tarantool.org>
To: Maxim Kokryashkin <m.kokryashkin@tarantool.org>
Cc: tarantool-patches@dev.tarantool.org
Subject: Re: [Tarantool-patches] [PATCH luajit 4/5] Fix pow() optimization inconsistencies.
Date: Mon, 21 Aug 2023 11:06:32 +0300 [thread overview]
Message-ID: <ZOMbCDYKe_9SJK8m@root> (raw)
In-Reply-To: <gzdy7dipsys3mpqeiru2m3idrtmfamueh4wxeu7jnwqvv2ypml@rbc2ezu6lnvp>
Hi, Maxim!
Thanks for the review!
See my answers below.
On 20.08.23, Maxim Kokryashkin wrote:
> Hi, Sergey!
> Thanks for the patch!
> Please consider my comments below.
>
> On Tue, Aug 15, 2023 at 12:36:30PM +0300, Sergey Kaplun wrote:
> > From: Mike Pall <mike>
> >
> > (cherry-picked from commit 9512d5c1aced61e13e7be2d3208ec7ae3516b458)
> >
> > This patch fixes different misbehaviour between JIT-compiled code and
> Typo: s/misbehaviour/misbehaviours/
Fixed.
> > the interpreter for power operator with the following ways:
> Typo: s/with the/in the/
Fixed.
> > * Drop folding optimizations for base ^ 0.5 => sqrt(base), as far as
> > pow(base, 0.5) isn't interchangeable and depends on the <math.h>
> > implementation.
> > * Drop folding optimizations for 2 ^ int_pow => ldexp(1.0, int_pow), to
> > avoid dependcy on the <math.h> implementation.
> > * Now `asm_pow()` always assemble a call to the `lj_vm_powi()` function,
> Typo: s/assemble/assembles/
Fixed.
> > that is general now for all CPU architectures. Using this internal
> > function instead of toolchain-provided `pow()` guarantees consistency
> Typo: s/of/of the/
Fixed.
> > between interpreter and JIT results. Also, it drops custom
> Typo: s/drops/drops the/
Fixed.
> > implementation for the `vm_powi_sse()` on x86_64.
> Typo: s/for the/for/
Fixed.
> > * `math_extern2` macro in the VM may take the second argument, that is
> > used as the target function to call. The first argument is still the
> > name for `func_nnsse` macro.
> > * Narrowing for power operation avoids range guard for non-constant base
> > IR. This leads to invalid result if value on trace is out of range.
> Typo: s/to invalid/to an invalid/
Fixed.
> > Now it is done unconditionally.
> >
> > Be aware, that [220/502] lib/string/format/num.lua test [1] from
> Typo: s/from the/from/
I suppose that it should be "from the"? Fixed.
> > LuaJIT-test suite fails after this commit.
> >
> > [1]: https://www.exploringbinary.com/incorrect-floating-point-to-decimal-conversions/
> >
> > Sergey Kaplun:
> > * added the description and the test for the problem
> >
> > Part of tarantool/tarantool#8825
> > ---
<snipped>
> > +local res = {}
> > +-- -0 ^ 0.5 = 0. Test sign with `tostring()`.
> Typo: s/Test/Test the/
Fixed.
> > +-- XXX: use local variable to prevent folding via parser.
<snipped>
> > +
> > +-- 2921 ^ 0.5 = 0x1.b05ec632536fap+5.
> We certainly need to add some explanation here about the precision, because
> it is not obvious why these magic numbers should cause any issues.
I suppose any really intererested in this reader may compare the
behaviour of the glibc implementation of `sqrt()` and `pow()`. Also, the
comment should mention this implementation, so it becomes too huge and
distracts the reader from the test case itself.
Ignoring for now.
> > +res = {}
<snipped>
> > +test:samevalues(res, ('consistent results for folding 2921 ^ 0.5'))
>
> I believe it is possible to make a single function with different
> parameters for all three cases above.
> Something like `test_power(value, power, extra_map)`, so you can do
> | res[i] = extra_map(value ^ power)
I afraid that this function doesn't give any improvement in readability,
also, it may change the trace semantics, so I prefer to leave it as is.
Ignoring for now.
>
> > +
<snipped>
> > +-- Need some value near 1, to avoid infinite result.
> Typo: s/Need/We need/
> Typo: s/avoid/avoid an/
Fixed.
See the iterative patch below.
===================================================================
diff --git a/test/tarantool-tests/lj-684-pow-inconsistencies.test.lua b/test/tarantool-tests/lj-684-pow-inconsistencies.test.lua
index 5129fc45..003fe957 100644
--- a/test/tarantool-tests/lj-684-pow-inconsistencies.test.lua
+++ b/test/tarantool-tests/lj-684-pow-inconsistencies.test.lua
@@ -18,7 +18,7 @@ jit.off()
jit.flush()
local res = {}
--- -0 ^ 0.5 = 0. Test sign with `tostring()`.
+-- -0 ^ 0.5 = 0. Test the sign with `tostring()`.
-- XXX: use local variable to prevent folding via parser.
-- XXX: use stack slot out of trace to prevent constant folding.
local minus_zero = -0
@@ -75,7 +75,7 @@ jit.on()
pow(1, 2)
pow(1, 2)
--- Need some value near 1, to avoid infinite result.
+-- We need some value near 1, to avoid an infinite result.
local base = 1.0000000001
local power = 65536 * 3
local resulting_value = pow(base, power)
===================================================================
> > +local base = 1.0000000001
<snipped>
> > --
> > 2.41.0
> >
--
Best regards,
Sergey Kaplun
next prev parent reply other threads:[~2023-08-21 8:11 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-15 9:36 [Tarantool-patches] [PATCH luajit 0/5] Fix pow inconsistencies and improve asserts Sergey Kaplun via Tarantool-patches
2023-08-15 9:36 ` [Tarantool-patches] [PATCH luajit 1/5] test: introduce `samevalues()` TAP checker Sergey Kaplun via Tarantool-patches
2023-08-17 14:03 ` Maxim Kokryashkin via Tarantool-patches
2023-08-17 15:03 ` Sergey Kaplun via Tarantool-patches
2023-08-18 10:43 ` Sergey Bronnikov via Tarantool-patches
2023-08-18 10:58 ` Sergey Kaplun via Tarantool-patches
2023-08-18 11:12 ` Sergey Bronnikov via Tarantool-patches
2023-08-21 10:47 ` Igor Munkin via Tarantool-patches
2023-08-24 7:44 ` Sergey Bronnikov via Tarantool-patches
2023-08-15 9:36 ` [Tarantool-patches] [PATCH luajit 2/5] Remove pow() splitting and cleanup backends Sergey Kaplun via Tarantool-patches
2023-08-17 14:52 ` Maxim Kokryashkin via Tarantool-patches
2023-08-17 15:33 ` Sergey Kaplun via Tarantool-patches
2023-08-20 9:48 ` Maxim Kokryashkin via Tarantool-patches
2023-08-18 11:08 ` Sergey Bronnikov via Tarantool-patches
2023-08-15 9:36 ` [Tarantool-patches] [PATCH luajit 3/5] Improve assertions Sergey Kaplun via Tarantool-patches
2023-08-17 14:58 ` Maxim Kokryashkin via Tarantool-patches
2023-08-18 7:56 ` Sergey Kaplun via Tarantool-patches
2023-08-18 11:20 ` Sergey Bronnikov via Tarantool-patches
2023-08-15 9:36 ` [Tarantool-patches] [PATCH luajit 4/5] Fix pow() optimization inconsistencies Sergey Kaplun via Tarantool-patches
2023-08-18 12:45 ` Sergey Bronnikov via Tarantool-patches
2023-08-21 8:07 ` Sergey Kaplun via Tarantool-patches
2023-08-20 9:26 ` Maxim Kokryashkin via Tarantool-patches
2023-08-21 8:06 ` Sergey Kaplun via Tarantool-patches [this message]
2023-08-21 9:00 ` Maxim Kokryashkin via Tarantool-patches
2023-08-21 9:31 ` Sergey Kaplun via Tarantool-patches
2023-08-15 9:36 ` [Tarantool-patches] [PATCH luajit 5/5] Revert to trival pow() optimizations to prevent inaccuracies Sergey Kaplun via Tarantool-patches
2023-08-18 12:49 ` Sergey Bronnikov via Tarantool-patches
2023-08-21 8:16 ` Sergey Kaplun via Tarantool-patches
2023-08-20 9:37 ` Maxim Kokryashkin via Tarantool-patches
2023-08-21 8:15 ` Sergey Kaplun via Tarantool-patches
2023-08-21 9:06 ` Maxim Kokryashkin via Tarantool-patches
2023-08-21 9:36 ` Sergey Kaplun via Tarantool-patches
2023-08-24 7:47 ` [Tarantool-patches] [PATCH luajit 0/5] Fix pow inconsistencies and improve asserts Sergey Bronnikov via Tarantool-patches
2023-08-31 15:18 ` Igor Munkin via Tarantool-patches
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ZOMbCDYKe_9SJK8m@root \
--to=tarantool-patches@dev.tarantool.org \
--cc=m.kokryashkin@tarantool.org \
--cc=skaplun@tarantool.org \
--subject='Re: [Tarantool-patches] [PATCH luajit 4/5] Fix pow() optimization inconsistencies.' \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox