From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from xry111.site (xry111.site [IPv6:2001:470:683e::1]) by sourceware.org (Postfix) with ESMTPS id D36753858D33 for ; Tue, 3 Oct 2023 06:28:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D36753858D33 Authentication-Results: sourceware.org; dmarc=pass (p=reject dis=none) header.from=xry111.site Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=xry111.site DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=xry111.site; s=default; t=1696314527; bh=CeKkkJHcy1YgHAIAgrveR8JrCBI7/EgbGK27hS9VBT8=; h=Subject:From:To:Date:In-Reply-To:References:From; b=HC7zuilQ3NR0CxqGT07zGu32T11X2CIXfHRQIj0h6A2zl+QZSOPI7kQyB6KuhDe05 mNu3HoBm3CUQK18ng4vk4vUjV9BCLpxcuI/Fq4WBfKUwKvPjQNARcCRcuh1ZOjainG YAd6DTDaDAiO560D7UMETyytXFY8kQGpL4waqUKk= Received: from [127.0.0.1] (unknown [IPv6:2001:470:683e::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature ECDSA (P-384) server-digest SHA384) (Client did not present a certificate) (Authenticated sender: xry111@xry111.site) by xry111.site (Postfix) with ESMTPSA id 4C4CA66992; Tue, 3 Oct 2023 02:28:46 -0400 (EDT) Message-ID: Subject: Re: [PATCH] ftw.c: Use unlikely for unlikely taken branches such that taken ones are placed closer From: Xi Ruoyao To: James Tirta Halim , libc-alpha@sourceware.org Date: Tue, 03 Oct 2023 14:28:44 +0800 In-Reply-To: <20231003034056.140938-1-tirtajames45@gmail.com> References: <20231003034056.140938-1-tirtajames45@gmail.com> Autocrypt: addr=xry111@xry111.site; prefer-encrypt=mutual; keydata=mDMEYnkdPhYJKwYBBAHaRw8BAQdAsY+HvJs3EVKpwIu2gN89cQT/pnrbQtlvd6Yfq7egugi0HlhpIFJ1b3lhbyA8eHJ5MTExQHhyeTExMS5zaXRlPoiTBBMWCgA7FiEEkdD1djAfkk197dzorKrSDhnnEOMFAmJ5HT4CGwMFCwkIBwICIgIGFQoJCAsCBBYCAwECHgcCF4AACgkQrKrSDhnnEOPHFgD8D9vUToTd1MF5bng9uPJq5y3DfpcxDp+LD3joA3U2TmwA/jZtN9xLH7CGDHeClKZK/ZYELotWfJsqRcthOIGjsdAPuDgEYnkdPhIKKwYBBAGXVQEFAQEHQG+HnNiPZseiBkzYBHwq/nN638o0NPwgYwH70wlKMZhRAwEIB4h4BBgWCgAgFiEEkdD1djAfkk197dzorKrSDhnnEOMFAmJ5HT4CGwwACgkQrKrSDhnnEOPjXgD/euD64cxwqDIqckUaisT3VCst11RcnO5iRHm6meNIwj0BALLmWplyi7beKrOlqKfuZtCLbiAPywGfCNg8LOTt4iMD Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.50.0 MIME-Version: 1.0 X-Spam-Status: No, score=-6.1 required=5.0 tests=BAYES_00,BODY_8BITS,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,LIKELY_SPAM_FROM,SPF_HELO_PASS,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On Tue, 2023-10-03 at 10:40 +0700, James Tirta Halim wrote: > --- > =C2=A0io/ftw.c | 12 ++++++------ > =C2=A01 file changed, 6 insertions(+), 6 deletions(-) >=20 > diff --git a/io/ftw.c b/io/ftw.c > index a72c7d5171..94fb2842d2 100644 > --- a/io/ftw.c > +++ b/io/ftw.c > @@ -209,7 +209,7 @@ ftw_allocate (struct ftw_data *data, size_t newsize) > =C2=A0=C2=A0 void *newp =3D realloc (data->dirstreams, data->maxdir > =C2=A0 =C2=A0 * sizeof (struct dir_data *) > =C2=A0 =C2=A0 + newsize); > -=C2=A0 if (newp =3D=3D NULL) > +=C2=A0 if (__glibc_unlikely(newp =3D=3D NULL)) AFAIK the compiler should automatically mark malloc and realloc failures as unlikely. On x86_64 GCC 7 predicts the probability of such a failure 1.74%, and GCC 13 predicts it 0.04%. /* snip */ > @@ -298,12 +298,12 @@ open_dir_stream (int *dfdp, struct ftw_data *data, = struct dir_data *dirp) > =C2=A0 =C2=A0 while ((d =3D __readdir64 (st)) !=3D NULL) > =C2=A0 =C2=A0=C2=A0=C2=A0 { > =C2=A0 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 size_t this_len =3D NAMLEN (d); > - =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if (actsize + this_len + 2 >=3D bufsize) > + =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if (glibc_unlikely(actsize + this_len + = 2 >=3D bufsize)) It seems only this one might be mispredicted by GCC. But there should be a white space between "glibc_unlikely" and "(". And should it be "__glibc_unlikely" (what's the difference between __glibc_unlikely and glibc_unlikely)? --=20 Xi Ruoyao School of Aerospace Science and Technology, Xidian University