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 A818036B297; Mon, 3 Apr 2023 12:10:06 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org A818036B297 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1680513006; bh=4d24A7fmHKrmcqcfJLhqt8PC6frUUTuZNXFkOaXbM/A=; 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=rAk1ewCHvl5t1hTaU+po74RVqbMfnlCoEiacHJLjbZEurcKXp0gZTPDA+2O1ZaXbg zM7LpblYRLbPMow3FZwvqVkhSLOtGRpzRiA8L7te6rquIOuNj1HL4iSTaIMl1Rd2xT 3McFQMvrlsYRcOqHrBY55ua7GCCoxpN9MTzoy3F4= Received: from smtp47.i.mail.ru (smtp47.i.mail.ru [95.163.41.85]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id 1D9B52B8A01 for ; Mon, 3 Apr 2023 12:10:05 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 1D9B52B8A01 Received: by smtp47.i.mail.ru with esmtpa (envelope-from ) id 1pjGCR-000YWe-LK; Mon, 03 Apr 2023 12:10:04 +0300 Date: Mon, 3 Apr 2023 09:02:16 +0000 To: Sergey Kaplun Message-ID: References: <20230322082739.25391-1-skaplun@tarantool.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20230322082739.25391-1-skaplun@tarantool.org> X-Clacks-Overhead: GNU Terry Pratchett X-Mailru-Src: smtp X-4EC0790: 10 X-7564579A: B8F34718100C35BD X-77F55803: 4F1203BC0FB41BD9381BDEF7E8905223B336BEBABBA06DCCB6C010CA664C617B182A05F538085040941B7C37EEA38F26018BC75A7DC57C133E7237F6F9FF0A2770B0D94B288C0AB8 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE73B2A9F8A35432468EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637C8DFB935205A313D8638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D8026F5BF1609041FA5255073F43E842BF117882F4460429724CE54428C33FAD305F5C1EE8F4F765FC6BA66BB79834B351A471835C12D1D9774AD6D5ED66289B52BA9C0B312567BB23117882F4460429728776938767073520CCD848CCB6FE560CCB629EEF1311BF91D2E47CDBA5A96583BA9C0B312567BB2376E601842F6C81A19E625A9149C048EED76C6ED7039589DE03CEA74F0D118906D8FC6C240DEA7642DBF02ECDB25306B2B78CF848AE20165D0A6AB1C7CE11FEE34E7D9683544204AF9735652A29929C6CC4224003CC836476E2F48590F00D11D6E2021AF6380DFAD1A18204E546F3947CB11811A4A51E3B096D1867E19FE1407959CC434672EE6371089D37D7C0E48F6C8AA50765F7900637870CFFD37CCFDD3AEFF80C71ABB335746BA297DBC24807EABDAD6C7F3747799A X-C1DE0DAB: 0D63561A33F958A5627F1CCCD031E0157F68CE8B89E17579EEF3207B4E8DB00DF87CCE6106E1FC07E67D4AC08A07B9B0DB8A315C1FF4794DBDAD6C7F3747799A X-C8649E89: 1C3962B70DF3F0ADBF74143AD284FC7177DD89D51EBB7742424CF958EAFF5D571004E42C50DC4CA955A7F0CF078B5EC49A30900B95165D34197948450CB5442A4A21A6C9C1DE6CE047A28A87FACF706B22900BBF89EC4C03ABFB7626C3A275C91D7E09C32AA3244C7DA83920C1A7E46489F94B389E90D4FF55E75C8D0ED9F6EE927AC6DF5659F194 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojDxrldwJ/igwwtXq2Bs0OwA== X-Mailru-Sender: 2FEBA92C8E508479FE7B9A1DF348D5316467E4CE287683040BF29D6C293B9AD2865673AD776DD92A2326FE6F2A341ACE0FB9F97486540B4CD9E8847AB8CFED4D9ABF8A61C016C2CFB0DAF586E7D11B3E67EA787935ED9F1B X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH luajit] x64/LJ_GC64: Fix emit_rma(). 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: Igor Munkin via Tarantool-patches Reply-To: Igor Munkin Cc: tarantool-patches@dev.tarantool.org Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" Sergey, Thanks for the patch! LGTM, considering the fixes for Max comments. On 22.03.23, Sergey Kaplun via Tarantool-patches wrote: > From: Mike Pall > > (cherry picked from commit 7e662e4f87134f1e84f7bea80933e033c5bf53a3) > > The accessing of memory address for some operation `emit_rma()` may be > encoded in one of the following ways: > a. If the offset of the accessing address from the dispatch table > (pinned to r14 that is not changed while trace execution) fits into > 32-bit, then encode this as an access to 32-bit displacement > relative to r14. > b. If the offset of the accessing address from the mcode (i.e. rip) > fits into 32-bit, then encode this as an access to 32-bit > displacement relative to rip (considering long mode specifics and > `RID_RIP` hack). > c. If the address doesn't fit into 32-bit one and we use `mov` or > `movsd`, then encode 64-bit load from this address. > d. Elsewhere, encode it as an access to 32-bit (the address should fit > into 32-bit one) displacement (the only option for non-GC64 mode). > > So, each instruction in GC64 mode differs from `mov` or `movsd` should > be encoded via the last option. But if we got a 64-bit address with a > big enough offset it can't be encoded and the assertion in `ptr2addr()` > will fail. > > There are several cases, when `emit_rma()` is used with non `mov` > instruction: > * `IR_LDEXP` with `fld` instruction for loading constant > number `TValue` by address. > * `IR_OBAR` with the corresponding `test` instruction on > `marked` field of `GCobj`. > All these instructions require an additional register to store value by > address. We can't truly allocate a register here due to possibility to > break IR assembling which depends on specific register usage. So, we use > and restore r14 here for emitting. > > Also, this patch removes `movsd` from condition from the `x86Op` type > check, as far as it never uses for the `emit_rma()` routine (see also > `emit_loadk64()` for details). > > Sergey Kaplun: > * added the description and the test for the problem > > Part of tarantool/tarantool#8069 > --- > > Branch: https://github.com/tarantool/luajit/tree/skaplun/gh-noticket-fix-emit-rma > PR: https://github.com/tarantool/tarantool/pull/8477 > Related issue: https://github.com/tarantool/tarantool/issues/8069 > > AFAICS, other places with `emit_rma()` usage are not related to the > patch as far as they take an offset for the address of JIT constants > stored in `jit_State`, so it always be near enough to dispatch. > > Side note: you may check test-correctness of the last check with GC by > changing the corresponding condition check on `GC_WHITES` in asm_obar to > CC_NZ (like it will be treated for incorrect check). Be carefull, member > that instructions are emitted from bottom to top! > > src/lj_emit_x86.h | 24 ++++- > test/tarantool-tests/fix-emit-rma.test.lua | 102 +++++++++++++++++++++ > 2 files changed, 123 insertions(+), 3 deletions(-) > create mode 100644 test/tarantool-tests/fix-emit-rma.test.lua > > -- > 2.34.1 > -- Best regards, IM