From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from [87.239.111.99] (localhost [127.0.0.1]) by dev.tarantool.org (Postfix) with ESMTP id 948F058E22C; Mon, 21 Aug 2023 12:00:40 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 948F058E22C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1692608440; bh=LHyrIPY+85qbklqsKdkCuny32YqhtaJtY6SRGAugoiE=; h=Date:To:References:In-Reply-To:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=ajEChHoNs3IfoKCn6+AfNdP3Rd94lS/4TpTbpJjgpP9AHLkdaksu/ruo7urya38ju IkMmKTS0/AL/p36MLgaEcwUcqnN+c4WhBTmqgJP9Oez5QwBsXcd7Ja9DLULue7hFn1 uCS/TylwsihWffPgercbBl4mTT3Eq13rVlHbSKtQ= Received: from smtp34.i.mail.ru (smtp34.i.mail.ru [95.163.41.75]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id A6607572182 for ; Mon, 21 Aug 2023 12:00:39 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org A6607572182 Received: by smtp34.i.mail.ru with esmtpa (envelope-from ) id 1qY0m6-00Dghi-2h; Mon, 21 Aug 2023 12:00:39 +0300 Date: Mon, 21 Aug 2023 12:00:37 +0300 To: Sergey Kaplun Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Mailru-Src: smtp X-4EC0790: 10 X-7564579A: EEAE043A70213CC8 X-77F55803: 4F1203BC0FB41BD90D1D1AB54508998164C3387BA0FA5B81EA24825B1EA10A89182A05F5380850404C228DA9ACA6FE27581E6B1DA0C75F48EB7A559DEF24646B9032F62EB10D7F0BF79E071A378CBB10 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7F87C043BA75DB4CEEA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F79006375E7A1B5661595F038638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D8C406A607CA60146075C3F79979AF6F42117882F4460429724CE54428C33FAD305F5C1EE8F4F765FC5613D04DEA810176A471835C12D1D9774AD6D5ED66289B52BA9C0B312567BB23117882F446042972877693876707352033AC447995A7AD18618001F51B5FD3F9D2E47CDBA5A96583BA9C0B312567BB2376E601842F6C81A19E625A9149C048EE140C956E756FBB7A452896749CDDA0A6D8FC6C240DEA76429C9F4D5AE37F343AA9539A8B242431040A6AB1C7CE11FEE32A336C651863509103F1AB874ED89028C4224003CC836476E2F48590F00D11D6E2021AF6380DFAD1A18204E546F3947CB11811A4A51E3B096D1867E19FE1407978DA827A17800CE7CCE2CBE5DD1EA6582DBA43225CD8A89F83C798A30B85E16B6D8C47C27EEC5E9FB5C8C57E37DE458BEDA766A37F9254B7 X-C1DE0DAB: 0D63561A33F958A558846B4716B32B5B036D06BA7E855C94308E2C7912A1D467F87CCE6106E1FC07E67D4AC08A07B9B0735DFC8FA7AC1207CB5012B2E24CD356 X-C8649E89: 1C3962B70DF3F0ADBF74143AD284FC7177DD89D51EBB7742424CF958EAFF5D571004E42C50DC4CA955A7F0CF078B5EC49A30900B95165D34C264B329661203DA81AF0309BD6B7DD534E15BA021738904BBD91F137F61E1571DC759E98712D63C1D7E09C32AA3244C23D3906357C850976950EFE00C4384E4C86C126E7119A0FE85A42E4C463514DC5DA084F8E80FEBD396F07DFE06A4A8314E894E437E78228B66933FA05BD8EF0CAD958392AE682691 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojHJI2DMjVra2HyXeOMBc0ew== X-Mailru-Sender: 0E9E14D9EC491FBA05C0DE36F6206CB072EE9414166C602DEB7A559DEF24646B14D23FB96A9F340B04C9FB44FCBCE9EE92D99EB8CC7091A7ECEABDC5717908DEF544888E8238EB4872D6B4FCE48DF648AE208404248635DF X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH luajit 4/5] Fix pow() optimization inconsistencies. X-BeenThere: tarantool-patches@dev.tarantool.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Maxim Kokryashkin via Tarantool-patches Reply-To: Maxim Kokryashkin Cc: tarantool-patches@dev.tarantool.org Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" Hi, Sergey! Thanks for the fixes! LGTM now, see my answers below. On Mon, Aug 21, 2023 at 11:06:32AM +0300, Sergey Kaplun wrote: > 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 > > > > > > (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 > > > implementation. > > > * Drop folding optimizations for 2 ^ int_pow => ldexp(1.0, int_pow), to > > > avoid dependcy on the 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. Yep, I got the order wrong, sorry. > > > > 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 > > > --- > > > > > > +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. > > > > > > + > > > +-- 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. Something like the comment below is sufficient: | This number has no special meaning and is used as one that gives different | results when its square root is obtained with glibc's `sqrt` and `power` | operations, thanks to their implementation nuances. I strongly suggest adding it to make the test case more understandable. > > Ignoring for now. > > > > +res = {} > > > > > > +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. I've expressed my suggestion incomprehensively, sorry. Here is what I've meant someting like this: | local function pow_test_case(value, power, extra_map) | jit.on() | res = {} | jit.on() | for i = 1, 4 do | res[i] = extra_map(value ^ power) | end | | -- XXX: Prevent hotcount side effects. | jit.off() | jit.flush() | | test:samevalues(res, ('consistent results for <...>')) | end Anyway, I've checked the jit.dump by myself, and even for the simple cases traces are entirely different. With that in mind, I believe, this comment should be ignored, even though this is very sad. > > > > > > + > > > > > > +-- 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 > > > > > > -- > > > 2.41.0 > > > > > -- > Best regards, > Sergey Kaplun