From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 13325 invoked by alias); 13 Oct 2017 13:03:51 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 13313 invoked by uid 89); 13 Oct 2017 13:03:50 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,SPF_PASS autolearn=ham version=3.3.2 spammy=finishes X-HELO: mx2.suse.de Received: from mx2.suse.de (HELO mx2.suse.de) (195.135.220.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 13 Oct 2017 13:03:49 +0000 Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 008A5AAC5; Fri, 13 Oct 2017 13:03:46 +0000 (UTC) Subject: Re: [PATCH] Fix bitmap_bit_in_range_p (PR tree-optimization/82493). From: =?UTF-8?Q?Martin_Li=c5=a1ka?= To: Jeff Law , gcc-patches@gcc.gnu.org References: <9c9fd60f-cb7a-e702-aabb-9e31dca6a92a@suse.cz> <2215478f-6715-189a-e6a4-8d171901d31f@redhat.com> <467ec34e-7af8-b5b8-264a-a336bd810e49@suse.cz> Message-ID: Date: Fri, 13 Oct 2017 13:13:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.3.0 MIME-Version: 1.0 In-Reply-To: <467ec34e-7af8-b5b8-264a-a336bd810e49@suse.cz> Content-Type: multipart/mixed; boundary="------------3B4952282AFD411A8FCF25D2" X-IsSubscribed: yes X-SW-Source: 2017-10/txt/msg00859.txt.bz2 This is a multi-part message in MIME format. --------------3B4952282AFD411A8FCF25D2 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Content-length: 863 On 10/13/2017 10:01 AM, Martin Liška wrote: > On 10/12/2017 11:54 PM, Jeff Law wrote: >> On 10/11/2017 12:13 AM, Martin Liška wrote: >>> 2017-10-10 Martin Liska >>> >>> PR tree-optimization/82493 >>> * sbitmap.c (bitmap_bit_in_range_p): Fix the implementation. >>> (test_range_functions): New function. >>> (sbitmap_c_tests): Likewise. >>> * selftest-run-tests.c (selftest::run_tests): Run new tests. >>> * selftest.h (sbitmap_c_tests): New function. >> I went ahead and committed this along with a patch to fix the off-by-one >> error in live_bytes_read. Bootstrapped and regression tested on x86. >> >> Actual patch attached for archival purposes. >> >> Jeff >> > > Thanks. > > I'll carry on and write another set of unit tests. > > Martin > Sending patch candidate, may I install it after it finishes regression tests? Martin --------------3B4952282AFD411A8FCF25D2 Content-Type: text/x-patch; name="0001-Add-selftests-for-bitmap_set_range.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="0001-Add-selftests-for-bitmap_set_range.patch" Content-length: 2916 >From 6114004455ffc534cdb895eb74b2018cea4b704a Mon Sep 17 00:00:00 2001 From: marxin Date: Fri, 13 Oct 2017 13:18:47 +0200 Subject: [PATCH 1/2] Add selftests for bitmap_set_range. gcc/ChangeLog: 2017-10-13 Martin Liska * sbitmap.c (bitmap_bit_in_range_p_checking): New function. (test_set_range): Likewise. (test_range_functions): Rename to ... (test_bit_in_range): ... this. (sbitmap_c_tests): Add new test. --- gcc/sbitmap.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 57 insertions(+), 3 deletions(-) diff --git a/gcc/sbitmap.c b/gcc/sbitmap.c index baef4d05f0d..fdcf5393e53 100644 --- a/gcc/sbitmap.c +++ b/gcc/sbitmap.c @@ -823,11 +823,64 @@ namespace selftest { /* Selftests for sbitmaps. */ +/* Checking function that uses both bitmap_bit_in_range_p and + loop of bitmap_bit_p and verifies consistent results. */ -/* Verify range functions for sbitmap. */ +static bool +bitmap_bit_in_range_p_checking (sbitmap s, unsigned int start, + unsigned end) +{ + bool r1 = bitmap_bit_in_range_p (s, start, end); + bool r2 = false; + + for (unsigned int i = start; i <= end; i++) + if (bitmap_bit_p (s, i)) + { + r2 = true; + break; + } + + ASSERT_EQ (r1, r2); + return r1; +} + +/* Verify bitmap_set_range functions for sbitmap. */ + +static void +test_set_range () +{ + sbitmap s = sbitmap_alloc (16); + bitmap_clear (s); + + bitmap_set_range (s, 0, 1); + ASSERT_TRUE (bitmap_bit_in_range_p_checking (s, 0, 0)); + ASSERT_FALSE (bitmap_bit_in_range_p_checking (s, 1, 15)); + bitmap_set_range (s, 15, 1); + ASSERT_FALSE (bitmap_bit_in_range_p_checking (s, 1, 14)); + ASSERT_TRUE (bitmap_bit_in_range_p_checking (s, 15, 15)); + + s = sbitmap_alloc (1024); + bitmap_clear (s); + bitmap_set_range (s, 512, 1); + ASSERT_FALSE (bitmap_bit_in_range_p_checking (s, 0, 511)); + ASSERT_FALSE (bitmap_bit_in_range_p_checking (s, 513, 1023)); + ASSERT_TRUE (bitmap_bit_in_range_p_checking (s, 512, 512)); + ASSERT_TRUE (bitmap_bit_in_range_p_checking (s, 508, 512)); + ASSERT_TRUE (bitmap_bit_in_range_p_checking (s, 508, 513)); + ASSERT_FALSE (bitmap_bit_in_range_p_checking (s, 508, 511)); + + bitmap_clear (s); + bitmap_set_range (s, 512, 64); + ASSERT_FALSE (bitmap_bit_in_range_p_checking (s, 0, 511)); + ASSERT_FALSE (bitmap_bit_in_range_p_checking (s, 512 + 64, 1023)); + ASSERT_TRUE (bitmap_bit_in_range_p_checking (s, 512, 512)); + ASSERT_TRUE (bitmap_bit_in_range_p_checking (s, 512 + 63, 512 + 63)); +} + +/* Verify bitmap_bit_in_range_p functions for sbitmap. */ static void -test_range_functions () +test_bit_in_range () { sbitmap s = sbitmap_alloc (1024); bitmap_clear (s); @@ -900,7 +953,8 @@ test_range_functions () void sbitmap_c_tests () { - test_range_functions (); + test_set_range (); + test_bit_in_range (); } } // namespace selftest -- 2.14.2 --------------3B4952282AFD411A8FCF25D2--