Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.os.linux.development.system > #765

Re: Using likely/unlikely in a while loop

From Richard Kettlewell <invalid@invalid.invalid>
Newsgroups comp.os.linux.development.system
Subject Re: Using likely/unlikely in a while loop
Date 2017-03-17 23:34 +0000
Organization terraraq NNTP server
Message-ID <87wpbn5vgp.fsf@LkoBDZeT.terraraq.uk> (permalink)
References <oahr5b$hv6$1@dont-email.me>

Show all headers | View raw


TDH1978 <thedeerhunter1978@movie.uni> writes:
> I googled this and could not find an answer.  I know that the
> gcc-specific keywords "likely" and "unlikely" can be useful in 'if'
> conditions
>
>    if (unlikely(i < 0))
>        // action
>
> but can they be used in a 'while' loop?
>
>    while (likely(i > 0))
>        // action

The GCC-specific keyword is __builtin_expect, documented in
https://gcc.gnu.org/onlinedocs/gcc-6.3.0/gcc/Other-Builtins.html

‘likely’ and ‘unlikely’ are macros defined using this keyword in some
projects (e.g. the Linux kernel).

-- 
http://www.greenend.org.uk/rjk/

Back to comp.os.linux.development.system | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

Using likely/unlikely in a while loop TDH1978 <thedeerhunter1978@movie.uni> - 2017-03-17 19:26 -0400
  Re: Using likely/unlikely in a while loop Richard Kettlewell <invalid@invalid.invalid> - 2017-03-17 23:34 +0000
  Re: Using likely/unlikely in a while loop Jorgen Grahn <grahn+nntp@snipabacken.se> - 2017-03-19 06:53 +0000

csiph-web