From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 13871 invoked by alias); 15 Jul 2019 14:17:08 -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 13859 invoked by uid 89); 15 Jul 2019 14:17:07 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-2.2 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 spammy=HTo:D*cz, HX-Languages-Length:1007, HContent-Transfer-Encoding:8bit X-HELO: gate.crashing.org Received: from gate.crashing.org (HELO gate.crashing.org) (63.228.1.57) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 15 Jul 2019 14:17:04 +0000 Received: from gate.crashing.org (localhost.localdomain [127.0.0.1]) by gate.crashing.org (8.14.1/8.14.1) with ESMTP id x6FEH2Ct008770; Mon, 15 Jul 2019 09:17:02 -0500 Received: (from segher@localhost) by gate.crashing.org (8.14.1/8.14.1/Submit) id x6FEH1T8008769; Mon, 15 Jul 2019 09:17:01 -0500 Date: Mon, 15 Jul 2019 14:23:00 -0000 From: Segher Boessenkool To: Martin =?utf-8?B?TGnFoWth?= Cc: Xiong Hu Luo , gcc-patches@gcc.gnu.org, hubicka@ucw.cz, wschmidt@linux.ibm.com Subject: Re: [PATCH v2] Generalize get_most_common_single_value to return k_th value & count Message-ID: <20190715141701.GC20882@gate.crashing.org> References: <20190715082043.24541-1-luoxhu@linux.ibm.com> <622d5e32-f430-2b07-2902-463f8770e984@suse.cz> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <622d5e32-f430-2b07-2902-463f8770e984@suse.cz> User-Agent: Mutt/1.4.2.3i X-IsSubscribed: yes X-SW-Source: 2019-07/txt/msg01062.txt.bz2 On Mon, Jul 15, 2019 at 11:20:34AM +0200, Martin Liška wrote: > On 7/15/19 10:20 AM, Xiong Hu Luo wrote: > > -/* Return most common value of TOPN_VALUE histogram. If > > - there's a unique value, return true and set VALUE and COUNT > > +struct value_count_t { > > + gcov_type value; > > + gcov_type count; > > +}; > > I like introduction of the tuple, please fix GNU coding style: '{' shoud > be on the next line. Only in function definitions. > > +static int > > +cmp_counts (const void *v1, const void *v2) > > +{ > > + const_value_count h1 = (const_value_count) v1; > > + const_value_count h2 = (const_value_count) v2; > > + if (h1->count < h2->count) > > + return 1; > > + if (h1->count > h2->count) > > + return -1; > > + return 0; > > +} > > In order to provide stable results, we want secondary comparison based on 'value'. Is that enough? Can there be two entries with the same count as well as value? Segher