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 C7F516F1841; Wed, 29 Nov 2023 17:35:13 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org C7F516F1841 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1701268513; bh=WoWlFnCm39m4WvP1zr67UhKZxmQwbURS707jearBF8Q=; h=Date:To:Cc:References:In-Reply-To:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=p7X7B+zC2FpkzCrlz3DCjdIfN/DYfURv4sfAN2qs7scKwDXu/Scbj7t9cbAxREFSz 4ca90ts+CqYowj3jiJR0J4XsL0fTAqIr02QLwFS2CYaTVxdkvfevteA20mZ18OPVkl yooBti2k0XgVczY7jyMJfEYDU6zMKjRwnE2HvHIc= Received: from smtp41.i.mail.ru (smtp41.i.mail.ru [95.163.41.64]) (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 075236F1841 for ; Wed, 29 Nov 2023 17:35:13 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 075236F1841 Received: by smtp41.i.mail.ru with esmtpa (envelope-from ) id 1r8Lei-001KjY-1E; Wed, 29 Nov 2023 17:35:12 +0300 Message-ID: Date: Wed, 29 Nov 2023 17:35:12 +0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Content-Language: en-US To: Sergey Kaplun , Maxim Kokryashkin Cc: tarantool-patches@dev.tarantool.org References: <89ded1daa0dcecf89e49055e5b87203c04fdda84.1698049570.git.skaplun@tarantool.org> In-Reply-To: <89ded1daa0dcecf89e49055e5b87203c04fdda84.1698049570.git.skaplun@tarantool.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Mailru-Src: smtp X-4EC0790: 10 X-7564579A: B8F34718100C35BD X-77F55803: 4F1203BC0FB41BD9D2A6479154BC7F418A5726D9682ECCAA7CCFA245F45915FF182A05F538085040AA681964BEBA1C4D4B0D3BBCADF269871D771ECA73A6A33931079C916BEEB66C X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE76C0A440987CA342DC2099A533E45F2D0395957E7521B51C2CFCAF695D4D8E9FCEA1F7E6F0F101C6778DA827A17800CE7257031E595304076EA1F7E6F0F101C6723150C8DA25C47586E58E00D9D99D84E1BDDB23E98D2D38B73AB1701401CD871747716027F006395F1215132847EB17DCC7F00164DA146DAFE8445B8C89999728AA50765F79006370BDD70ABAC747F53389733CBF5DBD5E9C8A9BA7A39EFB766F5D81C698A659EA7CC7F00164DA146DA9985D098DBDEAEC82D01283D1ACF37BAF6B57BC7E6449061A352F6E88A58FB86F5D81C698A659EA73AA81AA40904B5D9A18204E546F3947C632EDEA9CD5989A3C0837EA9F3D197644AD6D5ED66289B523666184CF4C3C14F6136E347CC761E07725E5C173C3A84C3BF1F585E929FBCC0BA3038C0950A5D36B5C8C57E37DE458B330BD67F2E7D9AF16D1867E19FE14079C09775C1D3CA48CFE478A468B35FE7671DD303D21008E298D5E8D9A59859A8B6957A4DEDD2346B4275ECD9A6C639B01B78DA827A17800CE79E6B27D82EEA174F731C566533BA786AA5CC5B56E945C8DA X-C1DE0DAB: 0D63561A33F958A5390D2932C140CDEA572C30E18FC6612F1A4508520D7C436EF87CCE6106E1FC07E67D4AC08A07B9B01F9513A7CA91E555CB5012B2E24CD356 X-C8649E89: 1C3962B70DF3F0ADE00A9FD3E00BEEDF3FED46C3ACD6F73ED3581295AF09D3DF87807E0823442EA2ED31085941D9CD0AF7F820E7B07EA4CF8E6AD07CC3650E6249801E30B55AF4512517CB7D4C39C0C6655A25F1918593EB3D7E4ABC8EFFEBBE153AE024B6FD08441142C4A5604D42422370AAB7255C0077E48CAC7CA610320002C26D483E81D6BE0DBAE6F56676BC7117BB6831D7356A2DEC5B5AD62611EEC62B5AFB4261A09AF0 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojxXIty/pLbainb/Ow+JEtJA== X-Mailru-Sender: 11C2EC085EDE56FAC07928AF2646A76917C313C2DF3302E94B0D3BBCADF2698752685D71546B8E9EEBA65886582A37BD66FEC6BF5C9C28D98A98C1125256619760D574B6FC815AB872D6B4FCE48DF648AE208404248635DF X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH luajit 1/6] Abstract out on-demand loading of FFI library. 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 Bronnikov via Tarantool-patches Reply-To: Sergey Bronnikov Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" Hello, Sergey thanks for the patch! LGTM On 10/23/23 12:22, Sergey Kaplun wrote: > From: Mike Pall > > (cherry-picked from commit 50d6883e6027c4c2f9a5e495fee6b7fff1bd73c9) > > This patch introduces the macro `ctype_loadffi(L)` to avoid code > duplication while loading the FFI library. > > Sergey Kaplun: > * added the description > > Part of tarantool/tarantool#9145 > --- > src/lib_jit.c | 6 +----- > src/lj_bcread.c | 6 +----- > src/lj_ctype.h | 10 ++++++++++ > src/lj_lex.c | 6 +----- > 4 files changed, 13 insertions(+), 15 deletions(-) > > diff --git a/src/lib_jit.c b/src/lib_jit.c > index b3c1c93c..f705f334 100644 > --- a/src/lib_jit.c > +++ b/src/lib_jit.c > @@ -339,11 +339,7 @@ LJLIB_CF(jit_util_tracek) > ir = &T->ir[ir->op1]; > } > #if LJ_HASFFI > - if (ir->o == IR_KINT64 && !ctype_ctsG(G(L))) { > - ptrdiff_t oldtop = savestack(L, L->top); > - luaopen_ffi(L); /* Load FFI library on-demand. */ > - L->top = restorestack(L, oldtop); > - } > + if (ir->o == IR_KINT64) ctype_loadffi(L); > #endif > lj_ir_kvalue(L, L->top-2, ir); > setintV(L->top-1, (int32_t)irt_type(ir->t)); > diff --git a/src/lj_bcread.c b/src/lj_bcread.c > index cddf6ff1..4915240f 100644 > --- a/src/lj_bcread.c > +++ b/src/lj_bcread.c > @@ -414,11 +414,7 @@ static int bcread_header(LexState *ls) > if ((flags & BCDUMP_F_FFI)) { > #if LJ_HASFFI > lua_State *L = ls->L; > - if (!ctype_ctsG(G(L))) { > - ptrdiff_t oldtop = savestack(L, L->top); > - luaopen_ffi(L); /* Load FFI library on-demand. */ > - L->top = restorestack(L, oldtop); > - } > + ctype_loadffi(L); > #else > return 0; > #endif > diff --git a/src/lj_ctype.h b/src/lj_ctype.h > index c4f3bdde..fce29409 100644 > --- a/src/lj_ctype.h > +++ b/src/lj_ctype.h > @@ -389,6 +389,16 @@ static LJ_AINLINE CTState *ctype_cts(lua_State *L) > return cts; > } > > +/* Load FFI library on-demand. */ > +#define ctype_loadffi(L) \ > + do { \ > + if (!ctype_ctsG(G(L))) { \ > + ptrdiff_t oldtop = (char *)L->top - mref(L->stack, char); \ > + luaopen_ffi(L); \ > + L->top = (TValue *)(mref(L->stack, char) + oldtop); \ > + } \ > + } while (0) > + > /* Save and restore state of C type table. */ > #define LJ_CTYPE_SAVE(cts) CTState savects_ = *(cts) > #define LJ_CTYPE_RESTORE(cts) \ > diff --git a/src/lj_lex.c b/src/lj_lex.c > index cef3c683..7c6319cc 100644 > --- a/src/lj_lex.c > +++ b/src/lj_lex.c > @@ -112,11 +112,7 @@ static void lex_number(LexState *ls, TValue *tv) > GCcdata *cd; > lj_assertLS(fmt == STRSCAN_I64 || fmt == STRSCAN_U64 || fmt == STRSCAN_IMAG, > "unexpected number format %d", fmt); > - if (!ctype_ctsG(G(L))) { > - ptrdiff_t oldtop = savestack(L, L->top); > - luaopen_ffi(L); /* Load FFI library on-demand. */ > - L->top = restorestack(L, oldtop); > - } > + ctype_loadffi(L); > if (fmt == STRSCAN_IMAG) { > cd = lj_cdata_new_(L, CTID_COMPLEX_DOUBLE, 2*sizeof(double)); > ((double *)cdataptr(cd))[0] = 0;