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 C3F586EC55; Tue, 20 Jul 2021 18:22:41 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org C3F586EC55 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1626794561; bh=Bf40h6cznY2uUVf2ynY6UYLTCy6BUP00QIzHO/errCs=; h=In-Reply-To:Date:References:To:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=rdPSuhERcRwhDmNV9eZzcwOtuzpx4IybhmhitP3vKf0CJqLG9dLOVwVSp2v8oMNQH ECQVkAACoZH7IL3qI2QT7CB8rJ8pz3OHoTMuLNR7hzWxyfH/eGSzxg7wIK+KasrUea Hm9ee45ygfYdYzAy9Q0H3w1evKq2xC3sOs50Behw= Received: from smtp34.i.mail.ru (smtp34.i.mail.ru [94.100.177.94]) (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 7D5466EC55 for ; Tue, 20 Jul 2021 18:22:40 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 7D5466EC55 Received: by smtp34.i.mail.ru with esmtpa (envelope-from ) id 1m5rZv-0004k7-Fc; Tue, 20 Jul 2021 18:22:39 +0300 Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 14.0 \(3654.100.0.2.22\)) In-Reply-To: <20210712120652.23695-1-skaplun@tarantool.org> Date: Tue, 20 Jul 2021 18:22:37 +0300 Content-Transfer-Encoding: quoted-printable Message-Id: <21E7212E-B193-4B79-9F1B-7AAA325188B0@tarantool.org> References: <20210712120652.23695-1-skaplun@tarantool.org> To: Sergey Kaplun X-Mailer: Apple Mail (2.3654.100.0.2.22) X-4EC0790: 10 X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD941C43E597735A9C30288BCF456A452EC92BAB6D044D5CCDE182A05F53808504084FC5E2D6AFAC3B0D8719B30B81419532051C05E47C6CC78ED63E94A470BA62A X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE782A779A89F7D69B2C2099A533E45F2D0395957E7521B51C2CFCAF695D4D8E9FCEA1F7E6F0F101C6778DA827A17800CE7AEF9C2E372EE2CB3EA1F7E6F0F101C6723150C8DA25C47586E58E00D9D99D84E1BDDB23E98D2D38BBCA57AF85F7723F22A0AC14AE5413AF398F532E48B0A1DDACC7F00164DA146DAFE8445B8C89999728AA50765F7900637CAEE156C82D3D7D9389733CBF5DBD5E9C8A9BA7A39EFB766F5D81C698A659EA7CC7F00164DA146DA9985D098DBDEAEC8B861051D4BA689FCF6B57BC7E6449061A352F6E88A58FB86F5D81C698A659EA7E827F84554CEF5019E625A9149C048EE9ECD01F8117BC8BEE2021AF6380DFAD18AA50765F790063735872C767BF85DA227C277FBC8AE2E8BBB46F953B4600AAB75ECD9A6C639B01B4E70A05D1297E1BBCB5012B2E24CD356 X-C1DE0DAB: 0D63561A33F958A595653B69887685B4D688D8F97FD5607C1FCF8E635B5873ECD59269BC5F550898D99A6476B3ADF6B47008B74DF8BB9EF7333BD3B22AA88B938A852937E12ACA7501A9DF589746230F410CA545F18667F91A7EA1CDA0B5A7A0 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D34E3E1DC0F9BD5530950B75A51F1C69E67D1B9DDDA774014D4C868DA34570362EE42331F0D85DB2F2F1D7E09C32AA3244C41F945F4852E51059FD123D3A59834D4A8CE788DE6831205FACE5A9C96DEB163 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojL49Xu4qyFBl9Onie7JDQDg== X-Mailru-Sender: 3B9A0136629DC912F4AABCEFC589C81E3ECA3EE5ADFDC81F6B32661D7FA3E9AD2FF8EDAED10B1A82AD07DD1419AC565FA614486B47F28B67C5E079CCF3B0523AED31B7EB2E253A9E112434F685709FCF0DA7A0AF5A3A8387 X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH luajit] Fix IR_BUFPUT assembly. 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 Ostanevich via Tarantool-patches Reply-To: Sergey Ostanevich Cc: tarantool-patches@dev.tarantool.org Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" Thanks for the patch! I want to assure myself: the link to the internal JIRA doesn=E2=80=99t = come to commit message? If so - LGTM with changes after Igor=E2=80=99s review. Sergos=20 > On 12 Jul 2021, at 15:06, Sergey Kaplun wrote: >=20 > From: Mike Pall >=20 > Thanks to Peter Cawley. >=20 > (cherry picked from commit 58d0dde0a2df49abc991decbabff15230010829a) >=20 > When recording IR_BUFPTR special variable holds -1 value to mark that > argument to store is not a single character. If it is, then it can be > stored in a register directly. When storing a single character we = store > it in the aforementioned variable first to reset the -1 value. But = when > the system has signed characters, and the character to store equals > \255, the check that the variable still holds -1 value becomes false > positive and either wrong value is stored or the LuaJIT crashes. >=20 > This patch changes the flag value to -129 to avoid intersections with > any `char` values. >=20 > Sergey Kaplun: > * added the description and the test for the problem > --- >=20 > The patch fixes the problem described in TNT-142. >=20 > Tarantool branch: = https://github.com/tarantool/tarantool/tree/skaplun/lj-375-fix-ir-bufput > Branch: = https://github.com/tarantool/luajit/tree/skaplun/lj-375-fix-ir-bufput > Issue: https://github.com/LuaJIT/LuaJIT/issues/375 >=20 > src/lj_asm.c | 6 +++--- > .../lj-375-ir-bufput-signed-char.test.lua | 17 +++++++++++++++++ > 2 files changed, 20 insertions(+), 3 deletions(-) > create mode 100644 = test/tarantool-tests/lj-375-ir-bufput-signed-char.test.lua >=20 > diff --git a/src/lj_asm.c b/src/lj_asm.c > index c2cf5a95..ab53fb47 100644 > --- a/src/lj_asm.c > +++ b/src/lj_asm.c > @@ -1115,7 +1115,7 @@ static void asm_bufput(ASMState *as, IRIns *ir) > const CCallInfo *ci =3D &lj_ir_callinfo[IRCALL_lj_buf_putstr]; > IRRef args[3]; > IRIns *irs; > - int kchar =3D -1; > + int kchar =3D -129; > args[0] =3D ir->op1; /* SBuf * */ > args[1] =3D ir->op2; /* GCstr * */ > irs =3D IR(ir->op2); > @@ -1123,7 +1123,7 @@ static void asm_bufput(ASMState *as, IRIns *ir) > if (irs->o =3D=3D IR_KGC) { > GCstr *s =3D ir_kstr(irs); > if (s->len =3D=3D 1) { /* Optimize put of single-char string = constant. */ > - kchar =3D strdata(s)[0]; > + kchar =3D (int8_t)strdata(s)[0]; /* Signed! */ > args[1] =3D ASMREF_TMP1; /* int, truncated to char */ > ci =3D &lj_ir_callinfo[IRCALL_lj_buf_putchar]; > } > @@ -1150,7 +1150,7 @@ static void asm_bufput(ASMState *as, IRIns *ir) > asm_gencall(as, ci, args); > if (args[1] =3D=3D ASMREF_TMP1) { > Reg tmp =3D ra_releasetmp(as, ASMREF_TMP1); > - if (kchar =3D=3D -1) > + if (kchar =3D=3D -129) > asm_tvptr(as, tmp, irs->op1); > else > ra_allockreg(as, kchar, tmp); > diff --git = a/test/tarantool-tests/lj-375-ir-bufput-signed-char.test.lua = b/test/tarantool-tests/lj-375-ir-bufput-signed-char.test.lua > new file mode 100644 > index 00000000..8ac138f7 > --- /dev/null > +++ b/test/tarantool-tests/lj-375-ir-bufput-signed-char.test.lua > @@ -0,0 +1,17 @@ > +local tap =3D require('tap') > + > +local test =3D tap.test('lj-375-ir-bufput-signed-char') > +test:plan(3) > + > +-- Avoid store forwarding optimization to store exactly 1 char. > +jit.opt.start(3, '-fwd', 'hotloop=3D1') > +for _ =3D 1, 3 do > + -- Check optimization for single char storing works correct > + -- for -1. Fast function `string.char()` is recorded with > + -- IR_BUFHDR and IR_BUFPUT IRs in case, when there are more than > + -- 1 arguments. > + local s =3D string.char(0xff, 0) > + test:ok(s:byte(1) =3D=3D 0xff, 'correct -1 signed char assembling') > +end > + > +os.exit(test:check() and 0 or 1) > --=20 > 2.31.0 >=20