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 61C4758CF70; Mon, 21 Aug 2023 11:11:20 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 61C4758CF70 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1692605480; bh=2HLicx7yUQn4CQVJLE0j4Qc2uADcG3atNrXzJbelnxE=; 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=CHDVYkl4C7CgkFsu3Q4zQ+UkvIKOp8BmKNl1dpgZb25QBRDUO496J9Ob/d6YMO1Ad Wq8/GW9jFytxQguG3E0Avf4/wWD6p/rvrq74rWIvYVmAw0VCk05AncDlFp7RDGqDEL B1lPyvt5PhWEX6yLU3z2ytX0YW8DK4YA9BhaIW1Y= Received: from smtp30.i.mail.ru (smtp30.i.mail.ru [95.163.41.71]) (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 7ECC2572182 for ; Mon, 21 Aug 2023 11:11:18 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 7ECC2572182 Received: by smtp30.i.mail.ru with esmtpa (envelope-from ) id 1qY00K-00GiHE-1X; Mon, 21 Aug 2023 11:11:17 +0300 Date: Mon, 21 Aug 2023 11:06:32 +0300 To: Maxim Kokryashkin 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: 78E4E2B564C1792B X-77F55803: 4F1203BC0FB41BD93C8852532D76B9E3B62DC7F09619FD734679E2B1BE667DC6182A05F538085040221FF08D98938450195763105F774F62C3B11B00B040C2DFED95BB2A030C0A19 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7EC0B1A4921CAE631EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F790063719899BAB9B61B3948638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D8735F11A786EF8B1B677DCA8C89078725117882F4460429724CE54428C33FAD305F5C1EE8F4F765FCC2ED6D5310B1F811A471835C12D1D9774AD6D5ED66289B52BA9C0B312567BB23117882F446042972877693876707352033AC447995A7AD18618001F51B5FD3F9D2E47CDBA5A96583BA9C0B312567BB2376E601842F6C81A19E625A9149C048EE140C956E756FBB7A269E641683F5DD3FD8FC6C240DEA76429C9F4D5AE37F343AA9539A8B242431040A6AB1C7CE11FEE3E753FA5741D1AD02040F9FF01DFDA4A8C4224003CC836476E2F48590F00D11D6E2021AF6380DFAD1A18204E546F3947CB11811A4A51E3B096D1867E19FE1407978DA827A17800CE705056152E029236E2DBA43225CD8A89F0A35B161A8BF67C1C6EABA9B74D0DA47B5C8C57E37DE458BEDA766A37F9254B7 X-C1DE0DAB: 0D63561A33F958A52F84F1F16C530C7C7DB899E205E7515458D8DE786FBC178DF87CCE6106E1FC07E67D4AC08A07B9B01F9513A7CA91E555CB5012B2E24CD356 X-C8649E89: 1C3962B70DF3F0ADBF74143AD284FC7177DD89D51EBB7742424CF958EAFF5D571004E42C50DC4CA955A7F0CF078B5EC49A30900B95165D340EEB18E49183157193718A076D9CEE9FF391F225E5F6883B9C343F39E058C60BF97AB3E0122F5BDA1D7E09C32AA3244CACC5886DAF6942654AD1FA112197D96C30452B15D76AEC1485A42E4C463514DC5DA084F8E80FEBD3202CD0F03380D9577A83BD0C44CE203720ABEDE4BBDD9CDD X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojHJI2DMjVra24ut/G0VxWGQ== X-Mailru-Sender: 11C2EC085EDE56FAC07928AF2646A7697541F250A2136730195763105F774F628FF8BC079CCEBBDCDEDBA653FF35249392D99EB8CC7091A70E183A470755BFD208F19895AA18418972D6B4FCE48DF648AE208404248635DF 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: Sergey Kaplun via Tarantool-patches Reply-To: Sergey Kaplun Cc: tarantool-patches@dev.tarantool.org Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" 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. > > 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. 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. > > > + > > +-- 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