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 E8E34498158; Mon, 29 Jul 2024 20:51:16 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org E8E34498158 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1722275477; bh=ralRqyaIp3tY9bJE3dTn3AmdklitHnBpAznegOGEAC4=; h=To:Cc:Date:In-Reply-To:References:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=gGcMhsqdVvXd7UH5hxco1zkSKg7q42EdYBP/z5cITJECfNS19wK/4Xz70ZVDGfLRD abeQP94n6SsTMAfcGrVtrH+x78Jzx4SYIM/jcCFujI+upYWCOf1cwwdOSUuU5+zW4W oFM/1IaQFf8kf0t1qmGV0gVYLG4LRGGoukHxp65w= Received: from mail-lf1-f46.google.com (mail-lf1-f46.google.com [209.85.167.46]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 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 8D4B7BB00AE for ; Wed, 26 Jun 2024 15:27:38 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 8D4B7BB00AE Received: by mail-lf1-f46.google.com with SMTP id 2adb3069b0e04-52ce6c93103so4078644e87.3 for ; Wed, 26 Jun 2024 05:27:38 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719404858; x=1720009658; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Pzn2x1zdnkKD4BijzV1JVqJDnBdZxZBlY2waRAIKNbU=; b=tltLhlTpOcDPnubsL7Xubcyr1cQa6WLFuDqEKIhztKo5v4gBb8C3sHMOK+i0VYpJxO dOkBhlyQvom9HvdPP7f/qvj6MsPAvjuU4pWJMilaL+9u/gM/qbxhiFPyW/I1AULk5X/N odsT6PtcjV8RZlukkmhPG9zUIeoigQahO41SUFsPoAp1ATsuvkCR7otzNs/Gv7MUSDcN WTSVhpIaHNvjTxyK80SV+TTvJZqnMPSut4NLQYevMWMVWT8fnrtJHyuSsXocebr1fbYi kgMug0RrQKkC8uY2Jz9GZtvWMHVi4tHNZfM6SjzUMuUFQvm8wKCdwoX5PuzOPpoOhUui ucyw== X-Gm-Message-State: AOJu0YyO4wqJ1KQNenzNmHhk2NCo3QoZ/KXy/F7n+SEe/Aw6doJDwLh9 TQaP3UN9Tkzicjjx+Z4FLXR6UQymtWo50Soxq6cLPk4DSexZF+DcjVVHv+T4 X-Google-Smtp-Source: AGHT+IGykpg2LR777G3V81rnkC+czrLJZC8jnNlhL9WPZCdbPRWtFMyk2Z83haQLrRa2KkscnoJ/kA== X-Received: by 2002:a05:6512:1cd:b0:52c:83c7:936a with SMTP id 2adb3069b0e04-52ce18526d3mr8664453e87.42.1719404857400; Wed, 26 Jun 2024 05:27:37 -0700 (PDT) Received: from mandesero.mail.msk ([5.181.62.96]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-52cd84b23d9sm1508886e87.202.2024.06.26.05.27.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Jun 2024 05:27:37 -0700 (PDT) To: tarantool-patches@dev.tarantool.org, skaplun@tarantool.org, m.kokryashkin@tarantool.org Cc: mandesero Date: Wed, 26 Jun 2024 12:27:34 +0000 Message-Id: <20240626122735.165672-2-mandesero@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240626122735.165672-1-mandesero@gmail.com> References: <20240626122735.165672-1-mandesero@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Mailman-Approved-At: Mon, 29 Jul 2024 20:51:14 +0300 Subject: [Tarantool-patches] [PATCH luajit 1/2] c: disable strcmp optimization in Valgrind build 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: mandesero--- via Tarantool-patches Reply-To: mandesero@gmail.com Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" From: mandesero --- src/lj_str.c | 43 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 2 deletions(-) diff --git a/src/lj_str.c b/src/lj_str.c index 321e8c4f..00cced03 100644 --- a/src/lj_str.c +++ b/src/lj_str.c @@ -26,10 +26,29 @@ static LJ_AINLINE int str_fastcmp(const char *a, const char *b, MSize len) /* -- String helpers ------------------------------------------------------ */ +#if LUAJIT_USE_VALGRIND +int lj_str_cmp_no_opt(const char *a, const char *b, MSize len) +{ + for (MSize i = 0; i < len; i++) + if (a[i] != b[i]) + return 1; + return 0; +} +#endif + /* Ordered compare of strings. Assumes string data is 4-byte aligned. */ int32_t LJ_FASTCALL lj_str_cmp(GCstr *a, GCstr *b) { MSize i, n = a->len > b->len ? b->len : a->len; +#if LUAJIT_USE_VALGRIND + const uint8_t *sa = (const uint8_t *)strdata(a); + const uint8_t *sb = (const uint8_t *)strdata(b); + + for (i = 0; i < n; i++) { + if (sa[i] != sb[i]) + return (uint8_t)sa[i] < (uint8_t)sb[i] ? -1 : 1; + } +#else for (i = 0; i < n; i += 4) { /* Note: innocuous access up to end of string + 3. */ uint32_t va = *(const uint32_t *)(strdata(a)+i); @@ -46,6 +65,7 @@ int32_t LJ_FASTCALL lj_str_cmp(GCstr *a, GCstr *b) return va < vb ? -1 : 1; } } +#endif return (int32_t)(a->len - b->len); } @@ -53,6 +73,12 @@ int32_t LJ_FASTCALL lj_str_cmp(GCstr *a, GCstr *b) static LJ_AINLINE int str_fastcmp(const char *a, const char *b, MSize len) { MSize i = 0; +#if LUAJIT_USE_VALGRIND + for (i = 0; i < len; i++) { + if (a[i] != b[i]) + return (uint8_t)a[i] < (uint8_t)b[i] ? -1 : 1; + } +#else lj_assertX(len > 0, "fast string compare with zero length"); lj_assertX((((uintptr_t)a+len-1) & (LJ_PAGESIZE-1)) <= LJ_PAGESIZE-4, "fast string compare crossing page boundary"); @@ -68,6 +94,7 @@ static LJ_AINLINE int str_fastcmp(const char *a, const char *b, MSize len) } i += 4; } while (i < len); +#endif return 0; } @@ -83,7 +110,11 @@ const char *lj_str_find(const char *s, const char *p, MSize slen, MSize plen) while (slen) { const char *q = (const char *)memchr(s, c, slen); if (!q) break; +#if LUAJIT_USE_VALGRIND + if (lj_str_cmp_no_opt(q+1, p, plen) == 0) return q; +#else if (memcmp(q+1, p, plen) == 0) return q; +#endif q++; slen -= (MSize)(q-s); s = q; } } @@ -232,8 +263,13 @@ GCstr *lj_str_new(lua_State *L, const char *str, size_t lenx) } else { /* Slow path: end of string is too close to a page boundary. */ while (o != NULL) { GCstr *sx = gco2str(o); +#if LUAJIT_USE_VALGRIND + if (sx->hash == h && sx->len == len && inc_collision_hard() && + lj_str_cmp_no_opt(str, strdata(sx), len) == 0) { +#else if (sx->hash == h && sx->len == len && inc_collision_hard() && memcmp(str, strdata(sx), len) == 0) { +#endif /* Resurrect if dead. Can only happen with fixstring() (keywords). */ if (isdead(g, o)) flipwhite(o); g->strhash_hit++; @@ -277,7 +313,11 @@ GCstr *lj_str_new(lua_State *L, const char *str, size_t lenx) } else { /* Slow path: end of string is too close to a page boundary. */ while (o != NULL) { GCstr *sx = gco2str(o); +#if LUAJIT_USE_VALGRIND + if (sx->hash == fh && sx->len == len && lj_str_cmp_no_opt(str, strdata(sx), len) == 0) { +#else if (sx->hash == fh && sx->len == len && memcmp(str, strdata(sx), len) == 0) { +#endif /* Resurrect if dead. Can only happen with fixstring() (keywords). */ if (isdead(g, o)) flipwhite(o); g->strhash_hit++; @@ -323,5 +363,4 @@ void LJ_FASTCALL lj_str_free(global_State *g, GCstr *s) { g->strnum--; lj_mem_free(g, s, sizestring(s)); -} - +} \ No newline at end of file -- 2.34.1