From patchwork Wed Sep 4 16:01:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kuan-Wei Chiu X-Patchwork-Id: 1980916 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=K4jFWTOZ; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=libc-alpha-bounces~incoming=patchwork.ozlabs.org@sourceware.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WzS1p1Xfhz1yXY for ; Thu, 5 Sep 2024 02:02:38 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id BF0EA3864805 for ; Wed, 4 Sep 2024 16:02:35 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pl1-x633.google.com (mail-pl1-x633.google.com [IPv6:2607:f8b0:4864:20::633]) by sourceware.org (Postfix) with ESMTPS id B555C3861036 for ; Wed, 4 Sep 2024 16:02:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B555C3861036 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org B555C3861036 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::633 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1725465738; cv=none; b=ENLAtwWkLRVtd7KR5l8rdVB1I+XLaeRw0AyGl4rkeEMjklRdvnIILc+bCalNk51HsK0ExmAXqLfBP9LAul01qQY9Wk/KJpwoBOCUhKerf1QhV4uHbuEjjvz7fEz1xGnOtagXzMj8NwsBVOsirWpJWDudZFbSYjAYB4tcVhU1mI8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1725465738; c=relaxed/simple; bh=dQjAIzpVP6o9E5sJ6W0OLrbdWfOuQU0nS1DLpSNP3Ik=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=FsKSsBu8kee8HXs0PPWnk0W0Q9dDF6qxvtjkT44Asfekx22cg5Fz1y8s7ZYDeWF4j22K8wbLatI8HQwQFsX2QVLK9xe26F9sVMz6cSzhdu202GukAiefyuK7K+2gUxgpWYxZLYqUMDykWT0bheWYPLmc/4/cCRXKJEOcqFm0reA= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pl1-x633.google.com with SMTP id d9443c01a7336-2055f630934so26978795ad.1 for ; Wed, 04 Sep 2024 09:02:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1725465735; x=1726070535; darn=sourceware.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=jdGOEG7JmbbLRQXGg4yqF7s8DJdmkUcEjKJeB+oCRKs=; b=K4jFWTOZ5TM1uDFuq/AhYnlPg73vqT7Pp6SnGIK8cbH87cst+Y2mYngQ68bJbCUHeA 6GfuLIpgsiEuAIPHPPjyyBMIVMVdSddTQbmc19vE6iWhN58A//A82D1VuiycK120AK8y L+FlgfdmAquzZ9y1I29xjn51ynw+wwYGTfyI4/gCCaLEZN0keE32SyOjC0StHyQAr7Je jYpL+OyAG5VI6V672IfP713Zr1d9CUgaZZ7ptM6aay2kziv59pEoeC8AAF+vGrNcT8C3 DeYbAdWvYnK1MyaI3HNOkgX4QtueSnO8Wl2kbVds70rIteiEFOx9UYSA0hw1NFA/Puqo vedg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725465735; x=1726070535; 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=jdGOEG7JmbbLRQXGg4yqF7s8DJdmkUcEjKJeB+oCRKs=; b=blPmqonA7pKZoHZ3M8upYjJv05SPlyc8LrvktpamMF4aJU2OW1pskYlDMgO93o/tb6 OTw5M4xdSK2ppO8RE6akm5TMEwk3r3iOwcnjjs3ouOuvJaCySkaAYtuXqRhZqPGtxMX4 0EhdM1PjQpOX991GqAmLbSHTGWibrP2SICAZSWlb5v3Zq1rsS5O9YwxLHewL8kybBNTi 8Vdl4jwDdHJjA7vqPFTREcBSyeNSfWaOJproLfwtM8OYvUuADCnsyDfTIgDiwwZPjzUk 2zZRRy5S17ckzPYPkT4zVDD7ltmpPfC48bSLF6FaOW0qYtunIcoDqTHtQBN5Utr7sMh3 pITQ== X-Gm-Message-State: AOJu0Yy48Kjrt8APF3KEQnLFMhpCcg7GOpfQl9FgZfmVpJRHGj3pGfIw Gt93R6cT0C8A2/sRN/PEVr7v9TSiL8S81krp8LMuvPx4zhoirC30FvidqQ== X-Google-Smtp-Source: AGHT+IG/jgZSkXLnST2s0tdCy8Yiefy1hqmbnXOj8fdveb0vTgOFEC02faUwv3AnJA1yn/lT7DZgVw== X-Received: by 2002:a17:903:3608:b0:205:5005:957b with SMTP id d9443c01a7336-205500597a2mr163455105ad.37.1725465734716; Wed, 04 Sep 2024 09:02:14 -0700 (PDT) Received: from visitorckw-System-Product-Name.. ([140.113.216.168]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-206aea38c91sm15193565ad.169.2024.09.04.09.02.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Sep 2024 09:02:14 -0700 (PDT) From: Kuan-Wei Chiu To: libc-alpha@sourceware.org Cc: goldstein.w.n@gmail.com, jserv@ccns.ncku.edu.tw, Kuan-Wei Chiu Subject: [PATCH v4 1/2] benchtests: Add benchmark test for bsearch Date: Thu, 5 Sep 2024 00:01:39 +0800 Message-Id: <20240904160140.2743366-2-visitorckw@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240904160140.2743366-1-visitorckw@gmail.com> References: <20240904160140.2743366-1-visitorckw@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-10.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces~incoming=patchwork.ozlabs.org@sourceware.org Introduce a benchmark test for the bsearch function to evaluate its performance. Example bench-bsearch.out: { "timing_type": "hp_timing", "functions": { "bsearch": { "bench-variant": "default", "array-size": 100000, "key-pattern": "ascending", "contained": "yes", "results": [121.735] } } } Signed-off-by: Kuan-Wei Chiu --- Changes in v4: - Add three fields: "array-size," "key-pattern," and "contained" to benchmark json output. - Update the benchmark result format in commit messages. benchtests/Makefile | 1 + benchtests/bench-bsearch.c | 114 +++++++++++++++++++++++++++++++++++++ 2 files changed, 115 insertions(+) create mode 100644 benchtests/bench-bsearch.c diff --git a/benchtests/Makefile b/benchtests/Makefile index d228e9e68a..955b766756 100644 --- a/benchtests/Makefile +++ b/benchtests/Makefile @@ -253,6 +253,7 @@ hash-benchset := \ stdlib-benchset := \ arc4random \ + bsearch \ random-lock \ strtod \ # stdlib-benchset diff --git a/benchtests/bench-bsearch.c b/benchtests/bench-bsearch.c new file mode 100644 index 0000000000..75bf812290 --- /dev/null +++ b/benchtests/bench-bsearch.c @@ -0,0 +1,114 @@ +/* Measure bsearch functions. + Copyright (C) 2022-2024 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#define TEST_MAIN +#define TEST_NAME "bsearch" + +#define ARRAY_SIZE 100000 +#define LOOP_ITERS 100000000 + +/* Directly including leads to the use of an inline version + of bsearch(), which may cause our test cases to be optimized away by + the compiler due to predictability. To address this, we should + include directly and replace __extern_inline + with __attribute__((noinline)) to ensure the compiler does not + inline the function. Additionally, we need to add some macros + required for compilation. */ +#include +#define __extern_inline __attribute__((noinline)) +#define __GNUC_PREREQ(x, y) 0 +typedef int (*__compar_fn_t) (const void *, const void *); +#include +#undef __extern_inline +#undef __GNUC_PREREQ + +#include "json-lib.h" +#include "bench-timing.h" + +int arr[ARRAY_SIZE]; + +static int +comp (const void *p1, const void *p2) +{ + int x1 = *(int *) p1; + int x2 = *(int *) p2; + + if (x1 < x2) + return -1; + if (x1 > x2) + return 1; + return 0; +} + +static void +do_bench (json_ctx_t *json_ctx) +{ + size_t i, iters = LOOP_ITERS; + timing_t start, stop, cur; + int key; + volatile __attribute__((__unused__)) void *res; + + for (i = 0; i < ARRAY_SIZE; ++i) + { + arr[i] = i; + } + + TIMING_NOW (start); + + for (i = 0; i < iters; ++i) + { + key = i % ARRAY_SIZE; + res = bsearch(&key, arr, sizeof(arr) / sizeof(arr[0]), sizeof(arr[0]), comp); + } + + TIMING_NOW (stop); + + TIMING_DIFF (cur, start, stop); + + json_element_double (json_ctx, (double) cur / (double) iters); +} + +int +do_test (void) +{ + json_ctx_t json_ctx; + + json_init (&json_ctx, 0, stdout); + + json_document_begin (&json_ctx); + json_attr_string (&json_ctx, "timing_type", TIMING_TYPE); + json_attr_object_begin (&json_ctx, "functions"); + json_attr_object_begin (&json_ctx, TEST_NAME); + json_attr_string (&json_ctx, "bench-variant", "default"); + json_attr_uint (&json_ctx, "array-size", ARRAY_SIZE); + json_attr_string (&json_ctx, "key-pattern", "ascending"); + json_attr_string (&json_ctx, "contained", "yes"); + + json_array_begin (&json_ctx, "results"); + + do_bench(&json_ctx); + + json_array_end (&json_ctx); + json_attr_object_end (&json_ctx); + json_attr_object_end (&json_ctx); + json_document_end (&json_ctx); + + return 0; +} + +#include From patchwork Wed Sep 4 16:01:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kuan-Wei Chiu X-Patchwork-Id: 1980917 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=EHxdXZH0; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=libc-alpha-bounces~incoming=patchwork.ozlabs.org@sourceware.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WzS1z5vFgz1yXY for ; Thu, 5 Sep 2024 02:02:47 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9026C3861024 for ; Wed, 4 Sep 2024 16:02:45 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pl1-x62d.google.com (mail-pl1-x62d.google.com [IPv6:2607:f8b0:4864:20::62d]) by sourceware.org (Postfix) with ESMTPS id 404D13858406 for ; Wed, 4 Sep 2024 16:02:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 404D13858406 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 404D13858406 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::62d ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1725465750; cv=none; b=jXJGCiGsuhIhhkBgfBgaYtNhV8rwb4fscQf6PGV9++Oi86lqnVMxIY4/D/4HHYd55A6Ba7TblGaMOQoyHSt6bCIRKxaqiI5diKFlWXyqSjuvHaKI9nXlXl9uWiKcY4M3HCk3vLWmu/jgHCaJmyjyRMXLMdXWo+ZqNV+mPeKf5/c= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1725465750; c=relaxed/simple; bh=FR+n2LK9StFcXbx7w4mXoAWNiAK2rfrbhG/jRZPyLIc=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=Qcj0EihlZ+x1iG6fEDhE40RsMCcMN2BJGFh91lIJM7NoFSEOToaVs4QG+WV1Y3i+mlf9x5PZgOmppruRKY1ZSt8mdB2gSycOx4F1lUe7d2UqWGd1BaPuj3+PtuO+hfX26Hh6FnHh4tc4iLJSA300wukxYQrZrP8zNOzMs3fH0Ag= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pl1-x62d.google.com with SMTP id d9443c01a7336-2059112f0a7so28100055ad.3 for ; Wed, 04 Sep 2024 09:02:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1725465748; x=1726070548; darn=sourceware.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=k/OGZCbA5GLJe2ts9BIu9zt1v9DpbdHwINSg4SgBCoY=; b=EHxdXZH0ZFnFWnpOZly7bfjEjY36ES40lVk/mmHkIH2hPAEuxgCc67wAZFlGzza533 9ebyV6ZFYp6hEKSyNSIc23d4BCFsdqIQkuPozjEaYPtETfZZ6SiThb0RXs/SpdL7BQQo Ws5MXnNHMXqtno6cZKMOAzFGMM5IzUTdeXzYJqZUcArycrXN1WlOXzwP1mJzsWMo8VB/ 83Dlkf7/X386m27O/Vs+MEX/w6rmoe06VxUmDBM/+gYk8yyVjSIOIi1RJygXrt60ZrWc PMZc0tU5mDqW+ZJMHKKCOnZd6NePFubMobtG+H1dq+1zQhXPdcwnKzIDovnObO7U29Y+ TzYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725465748; x=1726070548; 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=k/OGZCbA5GLJe2ts9BIu9zt1v9DpbdHwINSg4SgBCoY=; b=gHDPy74gGSVDb1XngJlpoV0iSsgHE+93W6VGTvmlQAtc1ruFyGyviw2yVa5Ie5HGmA FB4i7USQvkZpda9B+fDzT8nfZADK0QsrOABa78kGacefGBkQ84nBTxEcpPGkMnoCuzOA 1ZpFQ5U12Zd4ETFimdI1NFmQyAdHH1vM/HKnlljBeoSnxRJpjTdnGjN2oaKkIdoW1HXP 4cwyL9F/GeAAVrwPmDKCPg66HUcgfX3AZuQ+FGyuC+6Q6XB8HTehwT1tKOs0NtsbboFu M2XDtekcAs6bmCM9P4UT4tzqRI5wZlHuzA/x6rFUy+lA0rBqj85HNLehYzUGZtcilEkd 7Zng== X-Gm-Message-State: AOJu0Yxa1vXx7/UxdE8mJ69jc9yaV0Q1YCdxDaTNuB0y+BOj992WECv0 ywYuz8bprGAUgPHdx/2QMmv0fbImhlWe7+Jw9XsLDIQdoITqkAondlhOaQ== X-Google-Smtp-Source: AGHT+IH67DP2fN9IYYe4icKtmCYE4gJSAaSFojp7ZQu7NwrBNgP90mbeKOxMR8aCOkY9/Rsu6xmxYg== X-Received: by 2002:a17:902:c40e:b0:202:4640:cc68 with SMTP id d9443c01a7336-2050c48fb65mr195399025ad.59.1725465747630; Wed, 04 Sep 2024 09:02:27 -0700 (PDT) Received: from visitorckw-System-Product-Name.. ([140.113.216.168]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-206aea38c91sm15193565ad.169.2024.09.04.09.02.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Sep 2024 09:02:27 -0700 (PDT) From: Kuan-Wei Chiu To: libc-alpha@sourceware.org Cc: goldstein.w.n@gmail.com, jserv@ccns.ncku.edu.tw, Kuan-Wei Chiu Subject: [PATCH v4 2/2] Optimize bsearch() implementation for performance Date: Thu, 5 Sep 2024 00:01:40 +0800 Message-Id: <20240904160140.2743366-3-visitorckw@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240904160140.2743366-1-visitorckw@gmail.com> References: <20240904160140.2743366-1-visitorckw@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-10.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces~incoming=patchwork.ozlabs.org@sourceware.org Optimize the bsearch() function to improve binary search performance. Although the code size grew by 8 bytes, the new implementation achieves a 15% reduction in execution time on my x86 machine, according to benchmark results. code size: * old: text data bss dec hex filename 250 0 0 250 fa ./stdlib/bsearch.o * new: text data bss dec hex filename 258 0 0 258 102 ./stdlib/bsearch.o benchmark: * old: { "timing_type": "hp_timing", "functions": { "bsearch": { "bench-variant": "default", "array-size": 100000, "key-pattern": "ascending", "contained": "yes", "results": [121.735] } } } * new: { "timing_type": "hp_timing", "functions": { "bsearch": { "bench-variant": "default", "array-size": 100000, "key-pattern": "ascending", "contained": "yes", "results": [103.063] } } } Signed-off-by: Kuan-Wei Chiu Reviewed-by: Noah Goldstein --- Changes in v4: - Update the benchmark result format in commit messages. bits/stdlib-bsearch.h | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/bits/stdlib-bsearch.h b/bits/stdlib-bsearch.h index 540d718952..57f060b504 100644 --- a/bits/stdlib-bsearch.h +++ b/bits/stdlib-bsearch.h @@ -20,22 +20,14 @@ __extern_inline void * bsearch (const void *__key, const void *__base, size_t __nmemb, size_t __size, __compar_fn_t __compar) { - size_t __l, __u, __idx; const void *__p; int __comparison; - __l = 0; - __u = __nmemb; - while (__l < __u) + while (__nmemb) { - __idx = (__l + __u) / 2; - __p = (const void *) (((const char *) __base) + (__idx * __size)); + __p = (const void *) (((const char *) __base) + ((__nmemb >> 1) * __size)); __comparison = (*__compar) (__key, __p); - if (__comparison < 0) - __u = __idx; - else if (__comparison > 0) - __l = __idx + 1; - else + if (__comparison == 0) { #if __GNUC_PREREQ(4, 6) # pragma GCC diagnostic push @@ -46,6 +38,12 @@ bsearch (const void *__key, const void *__base, size_t __nmemb, size_t __size, # pragma GCC diagnostic pop #endif } + if (__comparison > 0) + { + __base = ((const char *) __p) + __size; + --__nmemb; + } + __nmemb >>= 1; } return NULL;