Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

"Flattery is all right -- if you don't inhale." -- Adlai Stevenson


devel / comp.lang.c++ / Most performant way to have "r % 2 ? -1.0 : 1.0"

SubjectAuthor
* Most performant way to have "r % 2 ? -1.0 : 1.0"Bonita Montero
`* Re: Most performant way to have "r % 2 ? -1.0 : 1.0"Marcel Mueller
 `* Re: Most performant way to have "r % 2 ? -1.0 : 1.0"Bonita Montero
  +* Re: Most performant way to have "r % 2 ? -1.0 : 1.0"Bonita Montero
  |+* Re: Most performant way to have "r % 2 ? -1.0 : 1.0"David Brown
  ||+* Re: Most performant way to have "r % 2 ? -1.0 : 1.0"Bonita Montero
  |||`* Re: Most performant way to have "r % 2 ? -1.0 : 1.0"David Brown
  ||| `* Re: Most performant way to have "r % 2 ? -1.0 : 1.0"Bonita Montero
  |||  `* Re: Most performant way to have "r % 2 ? -1.0 : 1.0"David Brown
  |||   `* Re: Most performant way to have "r % 2 ? -1.0 : 1.0"Bonita Montero
  |||    `* Re: Most performant way to have "r % 2 ? -1.0 : 1.0"David Brown
  |||     `* Re: Most performant way to have "r % 2 ? -1.0 : 1.0"Bonita Montero
  |||      `* Re: Most performant way to have "r % 2 ? -1.0 : 1.0"David Brown
  |||       `* Re: Most performant way to have "r % 2 ? -1.0 : 1.0"Bonita Montero
  |||        `- Re: Most performant way to have "r % 2 ? -1.0 : 1.0"Bonita Montero
  ||`* Re: Most performant way to have "r % 2 ? -1.0 : 1.0"red floyd
  || +- Re: Most performant way to have "r % 2 ? -1.0 : 1.0"red floyd
  || `* Re: Most performant way to have "r % 2 ? -1.0 : 1.0"Bonita Montero
  ||  `* Re: Most performant way to have "r % 2 ? -1.0 : 1.0"David Brown
  ||   `- Re: Most performant way to have "r % 2 ? -1.0 : 1.0"Bonita Montero
  |`* Re: Most performant way to have "r % 2 ? -1.0 : 1.0"Marcel Mueller
  | `* Re: Most performant way to have "r % 2 ? -1.0 : 1.0"Bonita Montero
  |  `- Re: Most performant way to have "r % 2 ? -1.0 : 1.0"Marcel Mueller
  `* Re: Most performant way to have "r % 2 ? -1.0 : 1.0"Scott Lurndal
   `- Re: Most performant way to have "r % 2 ? -1.0 : 1.0"Bonita Montero

1
Most performant way to have "r % 2 ? -1.0 : 1.0"

<v0qdvj$2clvq$1@raubtier-asyl.eternal-september.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=3763&group=comp.lang.c%2B%2B#3763

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!raubtier-asyl.eternal-september.org!.POSTED!not-for-mail
From: Bonita.M...@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c++
Subject: Most performant way to have "r % 2 ? -1.0 : 1.0"
Date: Tue, 30 Apr 2024 11:34:45 +0200
Organization: A noiseless patient Spider
Lines: 4
Message-ID: <v0qdvj$2clvq$1@raubtier-asyl.eternal-september.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 30 Apr 2024 11:34:43 +0200 (CEST)
Injection-Info: raubtier-asyl.eternal-september.org; posting-host="50660c7bf27b19b3bba1d0771662361a";
logging-data="2512890"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/xLWwdQjCb8SgwRQlZ13F/odjTYGbGBFU="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:x08uTPvy/s9IaDn0Hj8imZFD8fQ=
Content-Language: de-DE
 by: Bonita Montero - Tue, 30 Apr 2024 09:34 UTC

bit_cast<double>( (uint64_t)r << 63 | 0x3FFull << 52 )

Is more performant until AVX10 comes, which has conditional moves
for floating point values.

Re: Most performant way to have "r % 2 ? -1.0 : 1.0"

<v0tii2$1g6h8$5@gwaiyur.mb-net.net>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=3785&group=comp.lang.c%2B%2B#3785

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!news.swapon.de!news.mb-net.net!open-news-network.org!.POSTED!not-for-mail
From: news.5.m...@spamgourmet.org (Marcel Mueller)
Newsgroups: comp.lang.c++
Subject: Re: Most performant way to have "r % 2 ? -1.0 : 1.0"
Date: Wed, 1 May 2024 16:11:14 +0200
Organization: MB-NET.NET for Open-News-Network e.V.
Message-ID: <v0tii2$1g6h8$5@gwaiyur.mb-net.net>
References: <v0qdvj$2clvq$1@raubtier-asyl.eternal-september.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 1 May 2024 14:11:14 -0000 (UTC)
Injection-Info: gwaiyur.mb-net.net;
logging-data="1579560"; mail-complaints-to="abuse@open-news-network.org"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:XRbdxtRdjuM8OhWfVLhe+kdHv/I= sha256:omHVcW8AyCpFPTNfRyU9QOJHeIT4TubRQIPTb6F7oSE=
sha1:FsgKpa/WaWNyQ16tYFD9QAI88NE= sha256:9LuVVEvBleiqSjxdHm+OXd4BsGDKNnebMwLNGJlmVCE=
Content-Language: de-DE
In-Reply-To: <v0qdvj$2clvq$1@raubtier-asyl.eternal-september.org>
 by: Marcel Mueller - Wed, 1 May 2024 14:11 UTC

Am 30.04.24 um 11:34 schrieb Bonita Montero:
> bit_cast<double>( (uint64_t)r << 63 | 0x3FFull << 52 )

There is no need for conditional:

-((int)r&1) | 1

Marcel

Re: Most performant way to have "r % 2 ? -1.0 : 1.0"

<v0tlo3$37jjf$1@raubtier-asyl.eternal-september.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=3786&group=comp.lang.c%2B%2B#3786

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!raubtier-asyl.eternal-september.org!.POSTED!not-for-mail
From: Bonita.M...@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c++
Subject: Re: Most performant way to have "r % 2 ? -1.0 : 1.0"
Date: Wed, 1 May 2024 17:05:42 +0200
Organization: A noiseless patient Spider
Lines: 25
Message-ID: <v0tlo3$37jjf$1@raubtier-asyl.eternal-september.org>
References: <v0qdvj$2clvq$1@raubtier-asyl.eternal-september.org>
<v0tii2$1g6h8$5@gwaiyur.mb-net.net>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 01 May 2024 17:05:39 +0200 (CEST)
Injection-Info: raubtier-asyl.eternal-september.org; posting-host="d66863e752376af43732745fa2825b15";
logging-data="3395183"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX182w1HPWbJYT3fv4OBdrm3HAVj22hCSJv4="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:4DCviv7ulDav34wMs22kVFjGqic=
In-Reply-To: <v0tii2$1g6h8$5@gwaiyur.mb-net.net>
Content-Language: de-DE
 by: Bonita Montero - Wed, 1 May 2024 15:05 UTC

Am 01.05.2024 um 16:11 schrieb Marcel Mueller:
> Am 30.04.24 um 11:34 schrieb Bonita Montero:
>> bit_cast<double>( (uint64_t)r << 63 | 0x3FFull << 52 )
>
> There is no need for conditional:
>
> -((int)r&1) | 1
>
>
> Marcel

Looks simpler, but your code is one instruction more:

my code:
movabsq $4607182418800017408, %rax
salq $63, %rdi
orq %rax, %rdi
movq %rdi, %xmm0

your code:
andl $1, %edi
pxor %xmm0, %xmm0
negl %edi
orl $1, %edi
cvtsi2sdl %edi, %xmm0

Re: Most performant way to have "r % 2 ? -1.0 : 1.0"

<v0tm8f$37pqb$1@raubtier-asyl.eternal-september.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=3787&group=comp.lang.c%2B%2B#3787

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!raubtier-asyl.eternal-september.org!.POSTED!not-for-mail
From: Bonita.M...@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c++
Subject: Re: Most performant way to have "r % 2 ? -1.0 : 1.0"
Date: Wed, 1 May 2024 17:14:27 +0200
Organization: A noiseless patient Spider
Lines: 30
Message-ID: <v0tm8f$37pqb$1@raubtier-asyl.eternal-september.org>
References: <v0qdvj$2clvq$1@raubtier-asyl.eternal-september.org>
<v0tii2$1g6h8$5@gwaiyur.mb-net.net>
<v0tlo3$37jjf$1@raubtier-asyl.eternal-september.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Wed, 01 May 2024 17:14:23 +0200 (CEST)
Injection-Info: raubtier-asyl.eternal-september.org; posting-host="d66863e752376af43732745fa2825b15";
logging-data="3401547"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19d28N3JsMEwWHc0NIVdtKWX3odeMM4rjA="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:uycrmRBjdCRsQfr71vnhkrVGfE8=
Content-Language: de-DE
In-Reply-To: <v0tlo3$37jjf$1@raubtier-asyl.eternal-september.org>
 by: Bonita Montero - Wed, 1 May 2024 15:14 UTC

Am 01.05.2024 um 17:05 schrieb Bonita Montero:
> Am 01.05.2024 um 16:11 schrieb Marcel Mueller:
>> Am 30.04.24 um 11:34 schrieb Bonita Montero:
>>> bit_cast<double>( (uint64_t)r << 63 | 0x3FFull << 52 )
>>
>> There is no need for conditional:
>>
>> -((int)r&1) | 1
>>
>>
>> Marcel
>
> Looks simpler, but your code is one instruction more:
>
> my code:
>         movabsq $4607182418800017408, %rax
>         salq    $63, %rdi
>         orq     %rax, %rdi
>         movq    %rdi, %xmm0
>
> your code:
>         andl    $1, %edi
>         pxor    %xmm0, %xmm0
>         negl    %edi
>         orl     $1, %edi
>         cvtsi2sdl       %edi, %xmm0

And I've seen that cvtsi2sdl has a six cylcle latency on my
Zen4-CPU whereas the movq rdi, xmm0 only takes one clock cycle.

Re: Most performant way to have "r % 2 ? -1.0 : 1.0"

<9ntYN.42103$gF_b.12700@fx17.iad>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=3788&group=comp.lang.c%2B%2B#3788

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!news.bawue.net!npeer.as286.net!npeer-ng0.as286.net!peer02.ams1!peer.ams1.xlned.com!news.xlned.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx17.iad.POSTED!not-for-mail
X-newsreader: xrn 9.03-beta-14-64bit
Sender: scott@dragon.sl.home (Scott Lurndal)
From: sco...@slp53.sl.home (Scott Lurndal)
Reply-To: slp53@pacbell.net
Subject: Re: Most performant way to have "r % 2 ? -1.0 : 1.0"
Newsgroups: comp.lang.c++
References: <v0qdvj$2clvq$1@raubtier-asyl.eternal-september.org> <v0tii2$1g6h8$5@gwaiyur.mb-net.net> <v0tlo3$37jjf$1@raubtier-asyl.eternal-september.org>
Lines: 29
Message-ID: <9ntYN.42103$gF_b.12700@fx17.iad>
X-Complaints-To: abuse@usenetserver.com
NNTP-Posting-Date: Wed, 01 May 2024 15:39:49 UTC
Organization: UsenetServer - www.usenetserver.com
Date: Wed, 01 May 2024 15:39:49 GMT
X-Received-Bytes: 1547
 by: Scott Lurndal - Wed, 1 May 2024 15:39 UTC

Bonita Montero <Bonita.Montero@gmail.com> writes:
>Am 01.05.2024 um 16:11 schrieb Marcel Mueller:
>> Am 30.04.24 um 11:34 schrieb Bonita Montero:
>>> bit_cast<double>( (uint64_t)r << 63 | 0x3FFull << 52 )
>>
>> There is no need for conditional:
>>
>> -((int)r&1) | 1
>>
>>
>> Marcel
>
>Looks simpler, but your code is one instruction more:
>
>my code:
> movabsq $4607182418800017408, %rax
> salq $63, %rdi
> orq %rax, %rdi
> movq %rdi, %xmm0
>
>your code:
> andl $1, %edi
> pxor %xmm0, %xmm0
> negl %edi
> orl $1, %edi
> cvtsi2sdl %edi, %xmm0

the pxor is "executed" in the fetch stage, so adds no latency
(it is effectively a NOP).

Re: Most performant way to have "r % 2 ? -1.0 : 1.0"

<v0to81$388hq$1@raubtier-asyl.eternal-september.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=3789&group=comp.lang.c%2B%2B#3789

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!raubtier-asyl.eternal-september.org!.POSTED!not-for-mail
From: Bonita.M...@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c++
Subject: Re: Most performant way to have "r % 2 ? -1.0 : 1.0"
Date: Wed, 1 May 2024 17:48:21 +0200
Organization: A noiseless patient Spider
Lines: 34
Message-ID: <v0to81$388hq$1@raubtier-asyl.eternal-september.org>
References: <v0qdvj$2clvq$1@raubtier-asyl.eternal-september.org>
<v0tii2$1g6h8$5@gwaiyur.mb-net.net>
<v0tlo3$37jjf$1@raubtier-asyl.eternal-september.org>
<9ntYN.42103$gF_b.12700@fx17.iad>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 01 May 2024 17:48:17 +0200 (CEST)
Injection-Info: raubtier-asyl.eternal-september.org; posting-host="d66863e752376af43732745fa2825b15";
logging-data="3416634"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19qSK4t5snv7aywiAVuzNtOJ9BchI3/caM="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:P9Op1ezCGnYNuhZWRenl3qNpTPc=
Content-Language: de-DE
In-Reply-To: <9ntYN.42103$gF_b.12700@fx17.iad>
 by: Bonita Montero - Wed, 1 May 2024 15:48 UTC

Am 01.05.2024 um 17:39 schrieb Scott Lurndal:
> Bonita Montero <Bonita.Montero@gmail.com> writes:
>> Am 01.05.2024 um 16:11 schrieb Marcel Mueller:
>>> Am 30.04.24 um 11:34 schrieb Bonita Montero:
>>>> bit_cast<double>( (uint64_t)r << 63 | 0x3FFull << 52 )
>>>
>>> There is no need for conditional:
>>>
>>> -((int)r&1) | 1
>>>
>>>
>>> Marcel
>>
>> Looks simpler, but your code is one instruction more:
>>
>> my code:
>> movabsq $4607182418800017408, %rax
>> salq $63, %rdi
>> orq %rax, %rdi
>> movq %rdi, %xmm0
>>
>> your code:
>> andl $1, %edi
>> pxor %xmm0, %xmm0
>> negl %edi
>> orl $1, %edi
>> cvtsi2sdl %edi, %xmm0
>
> the pxor is "executed" in the fetch stage, so adds no latency
> (it is effectively a NOP).

According to Agner's instruction tables it has a one cycle
latency and there could be four PXOR-instrucitons executed
at the same time for my Zen4-CPU.

Re: Most performant way to have "r % 2 ? -1.0 : 1.0"

<v0trlb$392vj$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=3790&group=comp.lang.c%2B%2B#3790

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: david.br...@hesbynett.no (David Brown)
Newsgroups: comp.lang.c++
Subject: Re: Most performant way to have "r % 2 ? -1.0 : 1.0"
Date: Wed, 1 May 2024 18:46:31 +0200
Organization: A noiseless patient Spider
Lines: 58
Message-ID: <v0trlb$392vj$1@dont-email.me>
References: <v0qdvj$2clvq$1@raubtier-asyl.eternal-september.org>
<v0tii2$1g6h8$5@gwaiyur.mb-net.net>
<v0tlo3$37jjf$1@raubtier-asyl.eternal-september.org>
<v0tm8f$37pqb$1@raubtier-asyl.eternal-september.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Wed, 01 May 2024 18:46:35 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="221336019e0a39bf3f651794cd72aef5";
logging-data="3443699"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX182IVor/Kc6jvz6UHfLJmQRWi/PjiQkQKg="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:bVVxSbSNe3CxbTgA7XeGovRzHro=
Content-Language: en-GB
In-Reply-To: <v0tm8f$37pqb$1@raubtier-asyl.eternal-september.org>
 by: David Brown - Wed, 1 May 2024 16:46 UTC

On 01/05/2024 17:14, Bonita Montero wrote:
> Am 01.05.2024 um 17:05 schrieb Bonita Montero:
>> Am 01.05.2024 um 16:11 schrieb Marcel Mueller:
>>> Am 30.04.24 um 11:34 schrieb Bonita Montero:
>>>> bit_cast<double>( (uint64_t)r << 63 | 0x3FFull << 52 )
>>>
>>> There is no need for conditional:
>>>
>>> -((int)r&1) | 1
>>>
>>>
>>> Marcel
>>
>> Looks simpler, but your code is one instruction more:
>>
>> my code:
>>          movabsq $4607182418800017408, %rax
>>          salq    $63, %rdi
>>          orq     %rax, %rdi
>>          movq    %rdi, %xmm0
>>
>> your code:
>>          andl    $1, %edi
>>          pxor    %xmm0, %xmm0
>>          negl    %edi
>>          orl     $1, %edi
>>          cvtsi2sdl       %edi, %xmm0
>
> And I've seen that cvtsi2sdl has a six cylcle latency on my
> Zen4-CPU whereas the movq rdi, xmm0 only takes one clock cycle.
>

That's the kind of thing that is at least vaguely relevant here. The
number of instructions means little (especially when it is not clear
that your code involves fewer bytes) - the time taken for these
instructions is the important thing for claims of "most performant" code.

But even with that, all you've got is a claim that one obscure
expression might be slightly faster than some other obscure expression,
on some particular machine. No one cares if a program runs a few
nanoseconds faster - certainly not enough to accept a re-write like
yours (or Marcel's).

What you need to do is find some reason for wanting the original
expression, where you need to evaluate it vast numbers of times.
Perhaps use it in a big vector calculation or DSP algorithm. Write the
full code out. Time it on a real machine, first with the original
expression (from the subject line), then with your version, then with
Marcel's. Compile with a good optimising compiler (such gcc or clang,
not MSVC) with vectorisation appropriate for the processor you are using
(use "-march=native"). Time the differences.

My guess is that in real code, the difference will be negligible, but
that the original simple and clear expression has the edge because it
lets the compiler do more optimisations.

Feel free to prove my guess wrong - it is, after all, just a guess.

Re: Most performant way to have "r % 2 ? -1.0 : 1.0"

<v0tt66$39cmj$1@raubtier-asyl.eternal-september.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=3791&group=comp.lang.c%2B%2B#3791

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!raubtier-asyl.eternal-september.org!.POSTED!not-for-mail
From: Bonita.M...@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c++
Subject: Re: Most performant way to have "r % 2 ? -1.0 : 1.0"
Date: Wed, 1 May 2024 19:12:42 +0200
Organization: A noiseless patient Spider
Lines: 22
Message-ID: <v0tt66$39cmj$1@raubtier-asyl.eternal-september.org>
References: <v0qdvj$2clvq$1@raubtier-asyl.eternal-september.org>
<v0tii2$1g6h8$5@gwaiyur.mb-net.net>
<v0tlo3$37jjf$1@raubtier-asyl.eternal-september.org>
<v0tm8f$37pqb$1@raubtier-asyl.eternal-september.org>
<v0trlb$392vj$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Wed, 01 May 2024 19:12:39 +0200 (CEST)
Injection-Info: raubtier-asyl.eternal-september.org; posting-host="d66863e752376af43732745fa2825b15";
logging-data="3453651"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/ZP3qDQa120p1RM2YikwVyCF/T7YlZC2o="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:GX8TYxGEEdpUaaf/SQfuYAnAJ7k=
In-Reply-To: <v0trlb$392vj$1@dont-email.me>
Content-Language: de-DE
 by: Bonita Montero - Wed, 1 May 2024 17:12 UTC

Am 01.05.2024 um 18:46 schrieb David Brown:

> That's the kind of thing that is at least vaguely relevant here.  The
> number of instructions means little (especially when it is not clear
> that your code involves fewer bytes) - the time taken for these
> instructions is the important thing for claims of "most performant" code.

Every instruction for my code has a single cycle latency. Marcel's code
has single cycle latencies except for the last instruction, which takes
seven cyles on my Zen4-CPU. Take the numbers from Agner org, they're
similar for all modern x86-incarnations.

> But even with that, all you've got is a claim that one obscure
> expression might be slightly faster than some other obscure expression,

Optimized code is often less readable.

> What you need to do is find some reason for wanting the original
> expression, where you need to evaluate it vast numbers of times.

My code takes three clock cycles on all modern x86-CPUs.

Re: Most performant way to have "r % 2 ? -1.0 : 1.0"

<v0upu3$3fimf$1@redfloyd.dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=3800&group=comp.lang.c%2B%2B#3800

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!redfloyd.dont-email.me!.POSTED!not-for-mail
From: no.spam....@its.invalid (red floyd)
Newsgroups: comp.lang.c++
Subject: Re: Most performant way to have "r % 2 ? -1.0 : 1.0"
Date: Wed, 1 May 2024 18:23:15 -0700
Organization: A noiseless patient Spider
Lines: 19
Message-ID: <v0upu3$3fimf$1@redfloyd.dont-email.me>
References: <v0qdvj$2clvq$1@raubtier-asyl.eternal-september.org>
<v0tii2$1g6h8$5@gwaiyur.mb-net.net>
<v0tlo3$37jjf$1@raubtier-asyl.eternal-september.org>
<v0tm8f$37pqb$1@raubtier-asyl.eternal-september.org>
<v0trlb$392vj$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 02 May 2024 03:23:16 +0200 (CEST)
Injection-Info: redfloyd.dont-email.me; posting-host="c7cced95c35c244f9a8b8e997018612d";
logging-data="3656399"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18J9UdXkdpxVigTUV8sFo9Szv9T7bkLXLk="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:ORafFr4P/opnzb5g4zRLOB0E8Jg=
Content-Language: en-US
In-Reply-To: <v0trlb$392vj$1@dont-email.me>
 by: red floyd - Thu, 2 May 2024 01:23 UTC

On 5/1/2024 9:46 AM, David Brown wrote:
> On 01/05/2024 17:14, Bonita Montero wrote:
>> Am 01.05.2024 um 17:05 schrieb Bonita Montero:
>>> Am 01.05.2024 um 16:11 schrieb Marcel Mueller:
>>>> Am 30.04.24 um 11:34 schrieb Bonita Montero:
>>>>> bit_cast<double>( (uint64_t)r << 63 | 0x3FFull << 52 )
>>>>
>>>> There is no need for conditional:
>>>>
>>>> -((int)r&1) | 1
>>>>
>>>>
[redacted]
>

What the heck, I'll throw this in:

-1 + ((r & 1) << 1)

Re: Most performant way to have "r % 2 ? -1.0 : 1.0"

<v0uq1v$3fimf$2@redfloyd.dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=3801&group=comp.lang.c%2B%2B#3801

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!redfloyd.dont-email.me!.POSTED!not-for-mail
From: no.spam....@its.invalid (red floyd)
Newsgroups: comp.lang.c++
Subject: Re: Most performant way to have "r % 2 ? -1.0 : 1.0"
Date: Wed, 1 May 2024 18:25:19 -0700
Organization: A noiseless patient Spider
Lines: 23
Message-ID: <v0uq1v$3fimf$2@redfloyd.dont-email.me>
References: <v0qdvj$2clvq$1@raubtier-asyl.eternal-september.org>
<v0tii2$1g6h8$5@gwaiyur.mb-net.net>
<v0tlo3$37jjf$1@raubtier-asyl.eternal-september.org>
<v0tm8f$37pqb$1@raubtier-asyl.eternal-september.org>
<v0trlb$392vj$1@dont-email.me> <v0upu3$3fimf$1@redfloyd.dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 02 May 2024 03:25:20 +0200 (CEST)
Injection-Info: redfloyd.dont-email.me; posting-host="c7cced95c35c244f9a8b8e997018612d";
logging-data="3656399"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/kYvm36veD58Fvu/iEwVqFy6Rg7U4I28s="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:Y+0BXL7Cftwg2T1pWZGr7LrV9dk=
In-Reply-To: <v0upu3$3fimf$1@redfloyd.dont-email.me>
Content-Language: en-US
 by: red floyd - Thu, 2 May 2024 01:25 UTC

On 5/1/2024 6:23 PM, red floyd wrote:
> On 5/1/2024 9:46 AM, David Brown wrote:
>> On 01/05/2024 17:14, Bonita Montero wrote:
>>> Am 01.05.2024 um 17:05 schrieb Bonita Montero:
>>>> Am 01.05.2024 um 16:11 schrieb Marcel Mueller:
>>>>> Am 30.04.24 um 11:34 schrieb Bonita Montero:
>>>>>> bit_cast<double>( (uint64_t)r << 63 | 0x3FFull << 52 )
>>>>>
>>>>> There is no need for conditional:
>>>>>
>>>>> -((int)r&1) | 1
>>>>>
>>>>>
> [redacted]
>>
>
> What the heck, I'll throw this in:
>
> -1 + ((r & 1) << 1)
>
Oops. Sign reversal.

1 - ((r & 1) << 1)

Re: Most performant way to have "r % 2 ? -1.0 : 1.0"

<v0v2fv$3ku1r$3@raubtier-asyl.eternal-september.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=3805&group=comp.lang.c%2B%2B#3805

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!raubtier-asyl.eternal-september.org!.POSTED!not-for-mail
From: Bonita.M...@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c++
Subject: Re: Most performant way to have "r % 2 ? -1.0 : 1.0"
Date: Thu, 2 May 2024 05:49:19 +0200
Organization: A noiseless patient Spider
Lines: 23
Message-ID: <v0v2fv$3ku1r$3@raubtier-asyl.eternal-september.org>
References: <v0qdvj$2clvq$1@raubtier-asyl.eternal-september.org>
<v0tii2$1g6h8$5@gwaiyur.mb-net.net>
<v0tlo3$37jjf$1@raubtier-asyl.eternal-september.org>
<v0tm8f$37pqb$1@raubtier-asyl.eternal-september.org>
<v0trlb$392vj$1@dont-email.me> <v0upu3$3fimf$1@redfloyd.dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 02 May 2024 05:49:19 +0200 (CEST)
Injection-Info: raubtier-asyl.eternal-september.org; posting-host="fc01b5cced46b9bd2db0b176923fffe4";
logging-data="3831867"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19QmHWSYR2uFoLsyVyC61sTnAvhKlWc9e8="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:qZdaPiackdnXGsy/MiokKaeyDc4=
Content-Language: de-DE
In-Reply-To: <v0upu3$3fimf$1@redfloyd.dont-email.me>
 by: Bonita Montero - Thu, 2 May 2024 03:49 UTC

Am 02.05.2024 um 03:23 schrieb red floyd:
> On 5/1/2024 9:46 AM, David Brown wrote:
>> On 01/05/2024 17:14, Bonita Montero wrote:
>>> Am 01.05.2024 um 17:05 schrieb Bonita Montero:
>>>> Am 01.05.2024 um 16:11 schrieb Marcel Mueller:
>>>>> Am 30.04.24 um 11:34 schrieb Bonita Montero:
>>>>>> bit_cast<double>( (uint64_t)r << 63 | 0x3FFull << 52 )
>>>>>
>>>>> There is no need for conditional:
>>>>>
>>>>> -((int)r&1) | 1
>>>>>
>>>>>
> [redacted]
>>
>
> What the heck, I'll throw this in:
>
> -1 + ((r & 1) << 1)
>

The problem with that is that the result is converted to a floating
point value which is a rather slow operation.

Re: Most performant way to have "r % 2 ? -1.0 : 1.0"

<v106a4$3skqi$2@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=3814&group=comp.lang.c%2B%2B#3814

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!news.furie.org.uk!usenet.goja.nl.eu.org!3.eu.feeder.erje.net!feeder.erje.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: david.br...@hesbynett.no (David Brown)
Newsgroups: comp.lang.c++
Subject: Re: Most performant way to have "r % 2 ? -1.0 : 1.0"
Date: Thu, 2 May 2024 16:00:36 +0200
Organization: A noiseless patient Spider
Lines: 44
Message-ID: <v106a4$3skqi$2@dont-email.me>
References: <v0qdvj$2clvq$1@raubtier-asyl.eternal-september.org>
<v0tii2$1g6h8$5@gwaiyur.mb-net.net>
<v0tlo3$37jjf$1@raubtier-asyl.eternal-september.org>
<v0tm8f$37pqb$1@raubtier-asyl.eternal-september.org>
<v0trlb$392vj$1@dont-email.me>
<v0tt66$39cmj$1@raubtier-asyl.eternal-september.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Thu, 02 May 2024 16:00:36 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="c23ae3eb8bbb80fc577e6c20c92b3c18";
logging-data="4084562"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18B0pfM1/JB2o9WWre6mP881b7G+dmrGPo="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.11.0
Cancel-Lock: sha1:04IpNK36enIiC30ShpSs6XUKYqs=
Content-Language: en-GB
In-Reply-To: <v0tt66$39cmj$1@raubtier-asyl.eternal-september.org>
 by: David Brown - Thu, 2 May 2024 14:00 UTC

On 01/05/2024 19:12, Bonita Montero wrote:
> Am 01.05.2024 um 18:46 schrieb David Brown:
>
>> That's the kind of thing that is at least vaguely relevant here.  The
>> number of instructions means little (especially when it is not clear
>> that your code involves fewer bytes) - the time taken for these
>> instructions is the important thing for claims of "most performant" code.
>
> Every instruction for my code has a single cycle latency.

Surely you know that is not sufficient to justify claims of performance?
Latency is certainly a factor, but so is scheduling, parallel
execution, bandwidth for instruction caches and queues, pipeline hazards
and result forwarding, and a dozen other factors.

> Marcel's code
> has single cycle latencies except for the last instruction, which takes
> seven cyles on my Zen4-CPU. Take the numbers from Agner org, they're
> similar for all modern x86-incarnations.
>
>> But even with that, all you've got is a claim that one obscure
>> expression might be slightly faster than some other obscure expression,
>
> Optimized code is often less readable.

That makes it bad code. Sometimes it is acceptable because you need the
very fastest results for a piece of code, but that is very rare. This
is why I am asking you to justify the performance of your code in
practice - justify that it actually /is/ faster, and justify that it is
/usefully/ faster. Without that, it is smart-arse code, not smart code.

(If you are just playing around for fun and the challenge of making such
code sequences, that's fine.)

>
>> What you need to do is find some reason for wanting the original
>> expression, where you need to evaluate it vast numbers of times.
>
> My code takes three clock cycles on all modern x86-CPUs.
>

That is almost as far from answering my question as it is possible to get.

Re: Most performant way to have "r % 2 ? -1.0 : 1.0"

<v106hl$3skqi$3@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=3815&group=comp.lang.c%2B%2B#3815

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: david.br...@hesbynett.no (David Brown)
Newsgroups: comp.lang.c++
Subject: Re: Most performant way to have "r % 2 ? -1.0 : 1.0"
Date: Thu, 2 May 2024 16:04:37 +0200
Organization: A noiseless patient Spider
Lines: 36
Message-ID: <v106hl$3skqi$3@dont-email.me>
References: <v0qdvj$2clvq$1@raubtier-asyl.eternal-september.org>
<v0tii2$1g6h8$5@gwaiyur.mb-net.net>
<v0tlo3$37jjf$1@raubtier-asyl.eternal-september.org>
<v0tm8f$37pqb$1@raubtier-asyl.eternal-september.org>
<v0trlb$392vj$1@dont-email.me> <v0upu3$3fimf$1@redfloyd.dont-email.me>
<v0v2fv$3ku1r$3@raubtier-asyl.eternal-september.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 02 May 2024 16:04:37 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="c23ae3eb8bbb80fc577e6c20c92b3c18";
logging-data="4084562"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/Yi8udCXdbNL2ywltB0EFgzHlvkwndBUQ="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.11.0
Cancel-Lock: sha1:OM5RfmCYZSoJn0zbqRjx1eg+IIM=
Content-Language: en-GB
In-Reply-To: <v0v2fv$3ku1r$3@raubtier-asyl.eternal-september.org>
 by: David Brown - Thu, 2 May 2024 14:04 UTC

On 02/05/2024 05:49, Bonita Montero wrote:
> Am 02.05.2024 um 03:23 schrieb red floyd:
>> On 5/1/2024 9:46 AM, David Brown wrote:
>>> On 01/05/2024 17:14, Bonita Montero wrote:
>>>> Am 01.05.2024 um 17:05 schrieb Bonita Montero:
>>>>> Am 01.05.2024 um 16:11 schrieb Marcel Mueller:
>>>>>> Am 30.04.24 um 11:34 schrieb Bonita Montero:
>>>>>>> bit_cast<double>( (uint64_t)r << 63 | 0x3FFull << 52 )
>>>>>>
>>>>>> There is no need for conditional:
>>>>>>
>>>>>> -((int)r&1) | 1
>>>>>>
>>>>>>
>> [redacted]
>>>
>>
>> What the heck, I'll throw this in:
>>
>> -1 + ((r & 1) << 1)
>>
>
> The problem with that is that the result is converted to a floating
> point value which is a rather slow operation.

That's only a problem if it is a problem in real code. You haven't
shown any situation where it would be an issue.

In common real-world situations where you have a variable that is set to
-1 or 1 (integer or floating point), the next thing you will do is use
that to multiply other data which you will then accumulate. If the
-1/+1 expression is written simply, the compiler may optimise it away
entirely - turning things into a conditional code that either adds or
subtracts the later data. With your mess, it won't do that - it will
have to use real multiplication and miss out on optimisation opportunities.

Re: Most performant way to have "r % 2 ? -1.0 : 1.0"

<v107o9$3t57b$1@raubtier-asyl.eternal-september.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=3816&group=comp.lang.c%2B%2B#3816

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!news.nntp4.net!news.hispagatos.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!raubtier-asyl.eternal-september.org!.POSTED!not-for-mail
From: Bonita.M...@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c++
Subject: Re: Most performant way to have "r % 2 ? -1.0 : 1.0"
Date: Thu, 2 May 2024 16:25:14 +0200
Organization: A noiseless patient Spider
Lines: 18
Message-ID: <v107o9$3t57b$1@raubtier-asyl.eternal-september.org>
References: <v0qdvj$2clvq$1@raubtier-asyl.eternal-september.org>
<v0tii2$1g6h8$5@gwaiyur.mb-net.net>
<v0tlo3$37jjf$1@raubtier-asyl.eternal-september.org>
<v0tm8f$37pqb$1@raubtier-asyl.eternal-september.org>
<v0trlb$392vj$1@dont-email.me>
<v0tt66$39cmj$1@raubtier-asyl.eternal-september.org>
<v106a4$3skqi$2@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Thu, 02 May 2024 16:25:13 +0200 (CEST)
Injection-Info: raubtier-asyl.eternal-september.org; posting-host="fc01b5cced46b9bd2db0b176923fffe4";
logging-data="4101355"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/lDUxG7r/AiIbi6z4fUOvomzlaB2GB39M="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:vNlLTmlepiJdEnT0k2ycxS7XwMM=
Content-Language: de-DE
In-Reply-To: <v106a4$3skqi$2@dont-email.me>
 by: Bonita Montero - Thu, 2 May 2024 14:25 UTC

Am 02.05.2024 um 16:00 schrieb David Brown:

> Surely you know that is not sufficient to justify claims of performance?
>  Latency is certainly a factor, but so is scheduling, parallel
> execution, bandwidth for instruction caches and queues, pipeline hazards
> and result forwarding, and a dozen other factors.

Latency is the time until there's a result. Less instructions let other
instructions more likely occupy free execution units. So this can be
considered in the reduced way I did.

> That makes it bad code. ...

Absolutely not. A Bubblesort is easier to read than a qucksort but no
one woul chose Bubblesort for readability. And for me such tricks are
readable but they overburden you.

Re: Most performant way to have "r % 2 ? -1.0 : 1.0"

<v107s9$3t57b$2@raubtier-asyl.eternal-september.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=3817&group=comp.lang.c%2B%2B#3817

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!raubtier-asyl.eternal-september.org!.POSTED!not-for-mail
From: Bonita.M...@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c++
Subject: Re: Most performant way to have "r % 2 ? -1.0 : 1.0"
Date: Thu, 2 May 2024 16:27:22 +0200
Organization: A noiseless patient Spider
Lines: 17
Message-ID: <v107s9$3t57b$2@raubtier-asyl.eternal-september.org>
References: <v0qdvj$2clvq$1@raubtier-asyl.eternal-september.org>
<v0tii2$1g6h8$5@gwaiyur.mb-net.net>
<v0tlo3$37jjf$1@raubtier-asyl.eternal-september.org>
<v0tm8f$37pqb$1@raubtier-asyl.eternal-september.org>
<v0trlb$392vj$1@dont-email.me> <v0upu3$3fimf$1@redfloyd.dont-email.me>
<v0v2fv$3ku1r$3@raubtier-asyl.eternal-september.org>
<v106hl$3skqi$3@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Thu, 02 May 2024 16:27:21 +0200 (CEST)
Injection-Info: raubtier-asyl.eternal-september.org; posting-host="fc01b5cced46b9bd2db0b176923fffe4";
logging-data="4101355"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18n96dXYgSA7BTfgZVOcXP7PHzCuOZipCI="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:XHImwpsJP0ey4H99XBlomkOG1xY=
In-Reply-To: <v106hl$3skqi$3@dont-email.me>
Content-Language: de-DE
 by: Bonita Montero - Thu, 2 May 2024 14:27 UTC

Am 02.05.2024 um 16:04 schrieb David Brown:

> That's only a problem if it is a problem in real code.
> You haven't shown any situation where it would be an issue.

There are situation where this is imaginable; this is sufficient.

> In common real-world situations where you have a variable that is set to
> -1 or 1 (integer or floating point), the next thing you will do is use
> that to multiply other data which you will then accumulate.  If the
> -1/+1 expression is written simply, the compiler may optimise it away
> entirely - turning things into a conditional code that either adds or
> subtracts the later data.

For floating point operations this is likely to induce a jump which
isn't good to predict as there is no floating point conditional move
with x86. The upcoming AVX10.2 will have conditional moves for that.

Re: Most performant way to have "r % 2 ? -1.0 : 1.0"

<v11st4$211r9$2@gwaiyur.mb-net.net>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=3831&group=comp.lang.c%2B%2B#3831

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!news.swapon.de!news.mb-net.net!open-news-network.org!.POSTED!not-for-mail
From: news.5.m...@spamgourmet.org (Marcel Mueller)
Newsgroups: comp.lang.c++
Subject: Re: Most performant way to have "r % 2 ? -1.0 : 1.0"
Date: Fri, 3 May 2024 07:32:20 +0200
Organization: MB-NET.NET for Open-News-Network e.V.
Message-ID: <v11st4$211r9$2@gwaiyur.mb-net.net>
References: <v0qdvj$2clvq$1@raubtier-asyl.eternal-september.org>
<v0tii2$1g6h8$5@gwaiyur.mb-net.net>
<v0tlo3$37jjf$1@raubtier-asyl.eternal-september.org>
<v0tm8f$37pqb$1@raubtier-asyl.eternal-september.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 3 May 2024 05:32:20 -0000 (UTC)
Injection-Info: gwaiyur.mb-net.net;
logging-data="2131817"; mail-complaints-to="abuse@open-news-network.org"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:zDq/JEfVKNQ1ODUmK1yRnOx1g/k= sha256:DBak5F4VZ46n92HkTN00hfdNlXn/fRbWmwOeOvOHbJE=
sha1:bXYjRafOsi05umG9MqDnskdYDxI= sha256:BbCC74FIrZPqdoQcyXicNYdupD10EazZd4USIzmxdyM=
Content-Language: de-DE, en-US
In-Reply-To: <v0tm8f$37pqb$1@raubtier-asyl.eternal-september.org>
 by: Marcel Mueller - Fri, 3 May 2024 05:32 UTC

Am 01.05.24 um 17:14 schrieb Bonita Montero:
> And I've seen that cvtsi2sdl has a six cylcle latency on my
> Zen4-CPU whereas the movq rdi, xmm0 only takes one clock cycle.

You are right, int to float conversions are not that optimized. And they
require a dynamic shift operation for the integral logarithm of base 2.

So the only optimization you can do is r&1 ? -1. : 1. to avoid the
division. The compiler may optimize this to a conditional store.

Marcel

Re: Most performant way to have "r % 2 ? -1.0 : 1.0"

<v120o2$d305$1@raubtier-asyl.eternal-september.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=3832&group=comp.lang.c%2B%2B#3832

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!raubtier-asyl.eternal-september.org!.POSTED!not-for-mail
From: Bonita.M...@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c++
Subject: Re: Most performant way to have "r % 2 ? -1.0 : 1.0"
Date: Fri, 3 May 2024 08:37:55 +0200
Organization: A noiseless patient Spider
Lines: 10
Message-ID: <v120o2$d305$1@raubtier-asyl.eternal-september.org>
References: <v0qdvj$2clvq$1@raubtier-asyl.eternal-september.org>
<v0tii2$1g6h8$5@gwaiyur.mb-net.net>
<v0tlo3$37jjf$1@raubtier-asyl.eternal-september.org>
<v0tm8f$37pqb$1@raubtier-asyl.eternal-september.org>
<v11st4$211r9$2@gwaiyur.mb-net.net>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 03 May 2024 08:37:54 +0200 (CEST)
Injection-Info: raubtier-asyl.eternal-september.org; posting-host="c030ccadbcaefe746bb34fa5f5a5f34a";
logging-data="429061"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+KnUWr8t+Jiz5c9IAlk3VscBvVunC0Dvc="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:8kxVJz/jbp56QlLcjmaCf5AZm3E=
In-Reply-To: <v11st4$211r9$2@gwaiyur.mb-net.net>
Content-Language: de-DE
 by: Bonita Montero - Fri, 3 May 2024 06:37 UTC

Am 03.05.2024 um 07:32 schrieb Marcel Mueller:

> So the only optimization you can do is r&1 ? -1. : 1. to avoid the
> division. The compiler may optimize this to a conditional store.

There are currently no conditional moves for floating point values
with x86. clang does a table lookup for the above statement which
is also quite o.k., but a load from L1-cache is four cycles.

Re: Most performant way to have "r % 2 ? -1.0 : 1.0"

<v12a22$f4f1$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=3842&group=comp.lang.c%2B%2B#3842

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!news.swapon.de!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: david.br...@hesbynett.no (David Brown)
Newsgroups: comp.lang.c++
Subject: Re: Most performant way to have "r % 2 ? -1.0 : 1.0"
Date: Fri, 3 May 2024 11:16:49 +0200
Organization: A noiseless patient Spider
Lines: 47
Message-ID: <v12a22$f4f1$1@dont-email.me>
References: <v0qdvj$2clvq$1@raubtier-asyl.eternal-september.org>
<v0tii2$1g6h8$5@gwaiyur.mb-net.net>
<v0tlo3$37jjf$1@raubtier-asyl.eternal-september.org>
<v0tm8f$37pqb$1@raubtier-asyl.eternal-september.org>
<v0trlb$392vj$1@dont-email.me>
<v0tt66$39cmj$1@raubtier-asyl.eternal-september.org>
<v106a4$3skqi$2@dont-email.me>
<v107o9$3t57b$1@raubtier-asyl.eternal-september.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Fri, 03 May 2024 11:16:50 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="77e40aae3b22ade63afb79718be155c6";
logging-data="496097"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX182GQL4dVSBRk+yRRYCVePqr01eXgCY1RE="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.11.0
Cancel-Lock: sha1:GNlfxmQQZrtQXc7l3F1t09luNB0=
In-Reply-To: <v107o9$3t57b$1@raubtier-asyl.eternal-september.org>
Content-Language: en-GB
 by: David Brown - Fri, 3 May 2024 09:16 UTC

On 02/05/2024 16:25, Bonita Montero wrote:
> Am 02.05.2024 um 16:00 schrieb David Brown:
>
>> Surely you know that is not sufficient to justify claims of
>> performance?   Latency is certainly a factor, but so is scheduling,
>> parallel execution, bandwidth for instruction caches and queues,
>> pipeline hazards and result forwarding, and a dozen other factors.
>
> Latency is the time until there's a result. Less instructions let other
> instructions more likely occupy free execution units. So this can be
> considered in the reduced way I did.
>

I know what "latency" means, and why it is only one of many factors to
consider when looking at performance.

>> That makes it bad code. ...
>

Please stop snipping relevant parts of posts - such as the reason why
your expression is bad code.

> Absolutely not. A Bubblesort is easier to read than a qucksort but no
> one woul chose Bubblesort for readability. And for me such tricks are
> readable but they overburden you.
>

/You/ were the one who said your code was less readable. (No one else
had to say it because it is so obvious.)

You posted an expression that is an incomprehensible alternative to a
comprehensible but apparently useless expression. You are unable to
demonstrate that your re-write is actually faster in practice - you can
merely show that compilers generate fewer instructions for it than a
different variation of the original expression. You can't give any uses
of the expression, nor any measurements showing it is better in
practice. Without seeing the effect in context, your code is utterly
pointless and worse than useless.

It's just smart-arse coding - the kind that impresses new programmers
that haven't learned how to write code properly.

If you want to show anyone that your expression is actually a good idea,
you know what you have to do to demonstrate it.

Re: Most performant way to have "r % 2 ? -1.0 : 1.0"

<v12i6q$h25g$1@raubtier-asyl.eternal-september.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=3844&group=comp.lang.c%2B%2B#3844

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!raubtier-asyl.eternal-september.org!.POSTED!not-for-mail
From: Bonita.M...@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c++
Subject: Re: Most performant way to have "r % 2 ? -1.0 : 1.0"
Date: Fri, 3 May 2024 13:35:55 +0200
Organization: A noiseless patient Spider
Lines: 62
Message-ID: <v12i6q$h25g$1@raubtier-asyl.eternal-september.org>
References: <v0qdvj$2clvq$1@raubtier-asyl.eternal-september.org>
<v0tii2$1g6h8$5@gwaiyur.mb-net.net>
<v0tlo3$37jjf$1@raubtier-asyl.eternal-september.org>
<v0tm8f$37pqb$1@raubtier-asyl.eternal-september.org>
<v0trlb$392vj$1@dont-email.me>
<v0tt66$39cmj$1@raubtier-asyl.eternal-september.org>
<v106a4$3skqi$2@dont-email.me>
<v107o9$3t57b$1@raubtier-asyl.eternal-september.org>
<v12a22$f4f1$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Fri, 03 May 2024 13:35:55 +0200 (CEST)
Injection-Info: raubtier-asyl.eternal-september.org; posting-host="c030ccadbcaefe746bb34fa5f5a5f34a";
logging-data="559280"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+y2RFGKWDdjzJJApLo+CFG9i9Zzh6Ni4M="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:8do2L0HX/Un2KHrK9XIQpFG5Tuk=
Content-Language: de-DE
In-Reply-To: <v12a22$f4f1$1@dont-email.me>
 by: Bonita Montero - Fri, 3 May 2024 11:35 UTC

Am 03.05.2024 um 11:16 schrieb David Brown:
> On 02/05/2024 16:25, Bonita Montero wrote:
>> Am 02.05.2024 um 16:00 schrieb David Brown:
>>
>>> Surely you know that is not sufficient to justify claims of
>>> performance?   Latency is certainly a factor, but so is scheduling,
>>> parallel execution, bandwidth for instruction caches and queues,
>>> pipeline hazards and result forwarding, and a dozen other factors.
>>
>> Latency is the time until there's a result. Less instructions let other
>> instructions more likely occupy free execution units. So this can be
>> considered in the reduced way I did.
>>
>
> I know what "latency" means, and why it is only one of many factors to
> consider when looking at performance.

Latency is the time until there's a result, and this matters.

>
>
>>> That makes it bad code. ...
>>
>
> Please stop snipping relevant parts of posts - such as the reason why
> your expression is bad code.

It's currently the fastest solution on x86 for this purpose.
So this isn't bad code.

>
>> Absolutely not. A Bubblesort is easier to read than a qucksort but no
>> one woul chose Bubblesort for readability. And for me such tricks are
>> readable but they overburden you.
>>
>
> /You/ were the one who said your code was less readable.  (No one else
> had to say it because it is so obvious.)
>
> You posted an expression that is an incomprehensible alternative to a
> comprehensible but apparently useless expression.  You are unable to
> demonstrate that your re-write is actually faster in practice - you can
> merely show that compilers generate fewer instructions for it than a
> different variation of the original expression. ...

Compilers don't generate faster code for that. Try it on godbolt.

> You can't give any uses of the expression, ...

I've one use for that and I extracted the code.

> It's just smart-arse coding - the kind that impresses new programmers
> that haven't learned how to write code properly.

You're overburdened with that style of code and you want to discuss
it away.

> If you want to show anyone that your expression is actually a good idea,
> you know what you have to do to demonstrate it.
>
>

Re: Most performant way to have "r % 2 ? -1.0 : 1.0"

<v12lt3$htug$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=3845&group=comp.lang.c%2B%2B#3845

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!news.niel.me!news.gegeweb.eu!gegeweb.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: david.br...@hesbynett.no (David Brown)
Newsgroups: comp.lang.c++
Subject: Re: Most performant way to have "r % 2 ? -1.0 : 1.0"
Date: Fri, 3 May 2024 14:38:58 +0200
Organization: A noiseless patient Spider
Lines: 102
Message-ID: <v12lt3$htug$1@dont-email.me>
References: <v0qdvj$2clvq$1@raubtier-asyl.eternal-september.org>
<v0tii2$1g6h8$5@gwaiyur.mb-net.net>
<v0tlo3$37jjf$1@raubtier-asyl.eternal-september.org>
<v0tm8f$37pqb$1@raubtier-asyl.eternal-september.org>
<v0trlb$392vj$1@dont-email.me>
<v0tt66$39cmj$1@raubtier-asyl.eternal-september.org>
<v106a4$3skqi$2@dont-email.me>
<v107o9$3t57b$1@raubtier-asyl.eternal-september.org>
<v12a22$f4f1$1@dont-email.me>
<v12i6q$h25g$1@raubtier-asyl.eternal-september.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Fri, 03 May 2024 14:39:00 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="77e40aae3b22ade63afb79718be155c6";
logging-data="587728"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19yExpHABJc7rBa5ioOgIC812s8r023HDI="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.11.0
Cancel-Lock: sha1:19Qn0IHmvaDV/TfkF9cxKJ3GyZU=
Content-Language: en-GB
In-Reply-To: <v12i6q$h25g$1@raubtier-asyl.eternal-september.org>
 by: David Brown - Fri, 3 May 2024 12:38 UTC

On 03/05/2024 13:35, Bonita Montero wrote:
> Am 03.05.2024 um 11:16 schrieb David Brown:
>> On 02/05/2024 16:25, Bonita Montero wrote:
>>> Am 02.05.2024 um 16:00 schrieb David Brown:
>>>
>>>> Surely you know that is not sufficient to justify claims of
>>>> performance?   Latency is certainly a factor, but so is scheduling,
>>>> parallel execution, bandwidth for instruction caches and queues,
>>>> pipeline hazards and result forwarding, and a dozen other factors.
>>>
>>> Latency is the time until there's a result. Less instructions let other
>>> instructions more likely occupy free execution units. So this can be
>>> considered in the reduced way I did.
>>>
>>
>> I know what "latency" means, and why it is only one of many factors to
>> consider when looking at performance.
>
> Latency is the time until there's a result, and this matters.
>

We agree it matters - your mistake is thinking it is the only thing that
matters.

>>
>>
>>>> That makes it bad code. ...
>>>
>>
>> Please stop snipping relevant parts of posts - such as the reason why
>> your expression is bad code.
>
> It's currently the fastest solution on x86 for this purpose.

The only purpose you've demonstrated so far is for your bragging rights
as the biggest smart-arse in the group. (I know English is not your
first language, but to be clear, this is not a compliment.)

> So this isn't bad code.
>

Of course it is bad code - it is terrible, and would be rejected by any
code review for normal use. Obscure micro-optimisations like that are
worth considering in two situations - in compilers as code they might
generate for optimisations, and buried deep in very high performance
libraries as part of critical code. You are doing neither.

>>
>>> Absolutely not. A Bubblesort is easier to read than a qucksort but no
>>> one woul chose Bubblesort for readability. And for me such tricks are
>>> readable but they overburden you.
>>>
>>
>> /You/ were the one who said your code was less readable.  (No one else
>> had to say it because it is so obvious.)
>>
>> You posted an expression that is an incomprehensible alternative to a
>> comprehensible but apparently useless expression.  You are unable to
>> demonstrate that your re-write is actually faster in practice - you
>> can merely show that compilers generate fewer instructions for it than
>> a different variation of the original expression. ...
>
> Compilers don't generate faster code for that. Try it on godbolt.

Godbolt does not show how fast code is any more than you do.

Do you understand the importance of context in code performance? Do you
understand about the interaction between different parts of code? Or
that compilers are not dumb translators handling single expressions in
isolation? Have you any idea at all about what is /relevant/ in real
programming?

I realise that it is cool and clever to have figured out a trick for
this expression. I've nothing against that - it's fun, and fun is good.
If that's all you are trying to show, then that's fine. But if you
want to claim it is "good" code, or useful, or makes a difference, then
you have to show that. At the moment, what you have is of no use in
programming.

>
>> You can't give any uses of the expression, ...
>
> I've one use for that and I extracted the code.

Then show the rest of the code, along with the timing comparisons I
suggested.

>
>> It's just smart-arse coding - the kind that impresses new programmers
>> that haven't learned how to write code properly.
>
> You're overburdened with that style of code and you want to discuss
> it away.
>
>> If you want to show anyone that your expression is actually a good
>> idea, you know what you have to do to demonstrate it.
>>
>>
>

Re: Most performant way to have "r % 2 ? -1.0 : 1.0"

<v12mlb$i1dq$1@raubtier-asyl.eternal-september.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=3846&group=comp.lang.c%2B%2B#3846

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!news.swapon.de!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!raubtier-asyl.eternal-september.org!.POSTED!not-for-mail
From: Bonita.M...@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c++
Subject: Re: Most performant way to have "r % 2 ? -1.0 : 1.0"
Date: Fri, 3 May 2024 14:51:56 +0200
Organization: A noiseless patient Spider
Lines: 38
Message-ID: <v12mlb$i1dq$1@raubtier-asyl.eternal-september.org>
References: <v0qdvj$2clvq$1@raubtier-asyl.eternal-september.org>
<v0tii2$1g6h8$5@gwaiyur.mb-net.net>
<v0tlo3$37jjf$1@raubtier-asyl.eternal-september.org>
<v0tm8f$37pqb$1@raubtier-asyl.eternal-september.org>
<v0trlb$392vj$1@dont-email.me>
<v0tt66$39cmj$1@raubtier-asyl.eternal-september.org>
<v106a4$3skqi$2@dont-email.me>
<v107o9$3t57b$1@raubtier-asyl.eternal-september.org>
<v12a22$f4f1$1@dont-email.me>
<v12i6q$h25g$1@raubtier-asyl.eternal-september.org>
<v12lt3$htug$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Fri, 03 May 2024 14:51:55 +0200 (CEST)
Injection-Info: raubtier-asyl.eternal-september.org; posting-host="c030ccadbcaefe746bb34fa5f5a5f34a";
logging-data="591290"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/zgT5/xh/tHqBxZ22xzGf3GgR6LyGopQc="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:Jtn3TwVr7HeSLLNs0jTE7oOjEko=
Content-Language: de-DE
In-Reply-To: <v12lt3$htug$1@dont-email.me>
 by: Bonita Montero - Fri, 3 May 2024 12:51 UTC

Am 03.05.2024 um 14:38 schrieb David Brown:

> We agree it matters - your mistake is thinking it is the only thing that
> matters.

> Of course it is bad code - it is terrible, and would be rejected by any
> code review for normal use. ...

Look at the glibc math-Code, it's doing such tricks all over the lib.

> Godbolt does not show how fast code is any more than you do.

This can be easily estimated if you know the processing time of the
instructions.

> Do you understand the importance of context in code performance?  Do you
> understand about the interaction between different parts of code?  Or
> that compilers are not dumb translators handling single expressions in
> isolation?  Have you any idea at all about what is /relevant/ in real
> programming?

My use case was some code that alternately multiplies with 1.0 and
-1.0 depending on an i and performance was crucial with that. For
me such tricks are easy to read and they don't overburden me like
you.

> Then show the rest of the code, along with the timing comparisons I
> suggested.

That's the current version of the statement:
chain[i] = bit_cast<double>( bit_cast<uint64_t>( poly * reverseFacs[i]
) ^ (uint64_t)(i % 2) << 63 );
I even dropped the multiplication by alternately inverting the
sign bit. According to my measurements this makes the whole
routine about 11% fastet than the solution before.

Re: Most performant way to have "r % 2 ? -1.0 : 1.0"

<v12tc4$23klf$4@gwaiyur.mb-net.net>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=3848&group=comp.lang.c%2B%2B#3848

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!news.mb-net.net!open-news-network.org!.POSTED!not-for-mail
From: news.5.m...@spamgourmet.org (Marcel Mueller)
Newsgroups: comp.lang.c++
Subject: Re: Most performant way to have "r % 2 ? -1.0 : 1.0"
Date: Fri, 3 May 2024 16:46:28 +0200
Organization: MB-NET.NET for Open-News-Network e.V.
Message-ID: <v12tc4$23klf$4@gwaiyur.mb-net.net>
References: <v0qdvj$2clvq$1@raubtier-asyl.eternal-september.org>
<v0tii2$1g6h8$5@gwaiyur.mb-net.net>
<v0tlo3$37jjf$1@raubtier-asyl.eternal-september.org>
<v0tm8f$37pqb$1@raubtier-asyl.eternal-september.org>
<v11st4$211r9$2@gwaiyur.mb-net.net>
<v120o2$d305$1@raubtier-asyl.eternal-september.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 3 May 2024 14:46:28 -0000 (UTC)
Injection-Info: gwaiyur.mb-net.net;
logging-data="2216623"; mail-complaints-to="abuse@open-news-network.org"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:dDf+PUl6NfOaMcpXNWDlVVhwPRc= sha256:GaaGSsdA0GjSxEDSnOoCejRP5klsr2tNbFACTxJHS00=
sha1:cHUI+JsrUpZu0ighD9mkFDzBi3E= sha256:2WlByeKhLcd2/MVxYRt2JQyB0DponUDD/pyR1LQQZK0=
Content-Language: de-DE, en-US
In-Reply-To: <v120o2$d305$1@raubtier-asyl.eternal-september.org>
 by: Marcel Mueller - Fri, 3 May 2024 14:46 UTC

Am 03.05.24 um 08:37 schrieb Bonita Montero:
> Am 03.05.2024 um 07:32 schrieb Marcel Mueller:
>
>> So the only optimization you can do is r&1 ? -1. : 1. to avoid the
>> division. The compiler may optimize this to a conditional store.
>
> There are currently no conditional moves for floating point values
> with x86.

Interesting. The GPU of a Raspberry Pi Model 1 can do Job. :-)

Marcel

Re: Most performant way to have "r % 2 ? -1.0 : 1.0"

<v12v5c$jtia$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=3851&group=comp.lang.c%2B%2B#3851

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: david.br...@hesbynett.no (David Brown)
Newsgroups: comp.lang.c++
Subject: Re: Most performant way to have "r % 2 ? -1.0 : 1.0"
Date: Fri, 3 May 2024 17:16:59 +0200
Organization: A noiseless patient Spider
Lines: 14
Message-ID: <v12v5c$jtia$1@dont-email.me>
References: <v0qdvj$2clvq$1@raubtier-asyl.eternal-september.org>
<v0tii2$1g6h8$5@gwaiyur.mb-net.net>
<v0tlo3$37jjf$1@raubtier-asyl.eternal-september.org>
<v0tm8f$37pqb$1@raubtier-asyl.eternal-september.org>
<v0trlb$392vj$1@dont-email.me>
<v0tt66$39cmj$1@raubtier-asyl.eternal-september.org>
<v106a4$3skqi$2@dont-email.me>
<v107o9$3t57b$1@raubtier-asyl.eternal-september.org>
<v12a22$f4f1$1@dont-email.me>
<v12i6q$h25g$1@raubtier-asyl.eternal-september.org>
<v12lt3$htug$1@dont-email.me>
<v12mlb$i1dq$1@raubtier-asyl.eternal-september.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Fri, 03 May 2024 17:17:00 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="77e40aae3b22ade63afb79718be155c6";
logging-data="652874"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+MBdrqpAG0I7HTR+rwFHDp1EQInKwEUK4="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.11.0
Cancel-Lock: sha1:4eRwnnoXvLcz79V69t0EWP3PIqs=
Content-Language: en-GB
In-Reply-To: <v12mlb$i1dq$1@raubtier-asyl.eternal-september.org>
 by: David Brown - Fri, 3 May 2024 15:16 UTC

On 03/05/2024 14:51, Bonita Montero wrote:
> Am 03.05.2024 um 14:38 schrieb David Brown:
>
>> We agree it matters - your mistake is thinking it is the only thing
>> that matters.
>
>> Of course it is bad code - it is terrible, and would be rejected by
>> any code review for normal use. ...
>
> Look at the glibc math-Code, it's doing such tricks all over the lib.

There is not much point discussing anything with you until you learn the
basics of communication.

Re: Most performant way to have "r % 2 ? -1.0 : 1.0"

<v12ve8$ju1r$3@raubtier-asyl.eternal-september.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=3853&group=comp.lang.c%2B%2B#3853

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!rocksolid2!news.neodome.net!news.mixmin.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!raubtier-asyl.eternal-september.org!.POSTED!not-for-mail
From: Bonita.M...@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c++
Subject: Re: Most performant way to have "r % 2 ? -1.0 : 1.0"
Date: Fri, 3 May 2024 17:21:44 +0200
Organization: A noiseless patient Spider
Lines: 21
Message-ID: <v12ve8$ju1r$3@raubtier-asyl.eternal-september.org>
References: <v0qdvj$2clvq$1@raubtier-asyl.eternal-september.org>
<v0tii2$1g6h8$5@gwaiyur.mb-net.net>
<v0tlo3$37jjf$1@raubtier-asyl.eternal-september.org>
<v0tm8f$37pqb$1@raubtier-asyl.eternal-september.org>
<v0trlb$392vj$1@dont-email.me>
<v0tt66$39cmj$1@raubtier-asyl.eternal-september.org>
<v106a4$3skqi$2@dont-email.me>
<v107o9$3t57b$1@raubtier-asyl.eternal-september.org>
<v12a22$f4f1$1@dont-email.me>
<v12i6q$h25g$1@raubtier-asyl.eternal-september.org>
<v12lt3$htug$1@dont-email.me>
<v12mlb$i1dq$1@raubtier-asyl.eternal-september.org>
<v12v5c$jtia$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Fri, 03 May 2024 17:21:44 +0200 (CEST)
Injection-Info: raubtier-asyl.eternal-september.org; posting-host="c030ccadbcaefe746bb34fa5f5a5f34a";
logging-data="653371"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/QXkYCLboRrifBkBe5CVQrZUTQjtiXzl4="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:AK8+Jy4727GniB+4z+6DGz2g/ZE=
In-Reply-To: <v12v5c$jtia$1@dont-email.me>
Content-Language: de-DE
 by: Bonita Montero - Fri, 3 May 2024 15:21 UTC

Am 03.05.2024 um 17:16 schrieb David Brown:
> On 03/05/2024 14:51, Bonita Montero wrote:
>> Am 03.05.2024 um 14:38 schrieb David Brown:
>>
>>> We agree it matters - your mistake is thinking it is the only thing
>>> that matters.
>>
>>> Of course it is bad code - it is terrible, and would be rejected by
>>> any code review for normal use. ...
>>
>> Look at the glibc math-Code, it's doing such tricks all over the lib.
>
> There is not much point discussing anything with you until you learn the
> basics of communication.
>

You said that teams wouldn't chose such a style which includes such
tricks and I gave you an example of a very popular open source project.
Have a look at the current implementation of fmod() in the glibc, which
does a lot of such bit-fiddling.

Re: Most performant way to have "r % 2 ? -1.0 : 1.0"

<v1309s$k4vj$1@raubtier-asyl.eternal-september.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=3854&group=comp.lang.c%2B%2B#3854

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!raubtier-asyl.eternal-september.org!.POSTED!not-for-mail
From: Bonita.M...@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c++
Subject: Re: Most performant way to have "r % 2 ? -1.0 : 1.0"
Date: Fri, 3 May 2024 17:36:28 +0200
Organization: A noiseless patient Spider
Lines: 25
Message-ID: <v1309s$k4vj$1@raubtier-asyl.eternal-september.org>
References: <v0qdvj$2clvq$1@raubtier-asyl.eternal-september.org>
<v0tii2$1g6h8$5@gwaiyur.mb-net.net>
<v0tlo3$37jjf$1@raubtier-asyl.eternal-september.org>
<v0tm8f$37pqb$1@raubtier-asyl.eternal-september.org>
<v0trlb$392vj$1@dont-email.me>
<v0tt66$39cmj$1@raubtier-asyl.eternal-september.org>
<v106a4$3skqi$2@dont-email.me>
<v107o9$3t57b$1@raubtier-asyl.eternal-september.org>
<v12a22$f4f1$1@dont-email.me>
<v12i6q$h25g$1@raubtier-asyl.eternal-september.org>
<v12lt3$htug$1@dont-email.me>
<v12mlb$i1dq$1@raubtier-asyl.eternal-september.org>
<v12v5c$jtia$1@dont-email.me>
<v12ve8$ju1r$3@raubtier-asyl.eternal-september.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Fri, 03 May 2024 17:36:28 +0200 (CEST)
Injection-Info: raubtier-asyl.eternal-september.org; posting-host="c030ccadbcaefe746bb34fa5f5a5f34a";
logging-data="660467"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+IFODLpAzgJ/S8VAm1VrwljKIcpHLOGsk="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:fXHJOVoYUUHv0CsNY4K5l/BZeEY=
Content-Language: de-DE
In-Reply-To: <v12ve8$ju1r$3@raubtier-asyl.eternal-september.org>
 by: Bonita Montero - Fri, 3 May 2024 15:36 UTC

Am 03.05.2024 um 17:21 schrieb Bonita Montero:
> Am 03.05.2024 um 17:16 schrieb David Brown:
>> On 03/05/2024 14:51, Bonita Montero wrote:
>>> Am 03.05.2024 um 14:38 schrieb David Brown:
>>>
>>>> We agree it matters - your mistake is thinking it is the only thing
>>>> that matters.
>>>
>>>> Of course it is bad code - it is terrible, and would be rejected by
>>>> any code review for normal use. ...
>>>
>>> Look at the glibc math-Code, it's doing such tricks all over the lib.
>>
>> There is not much point discussing anything with you until you learn
>> the basics of communication.
>>
>
> You said that teams wouldn't chose such a style which includes such
> tricks and I gave you an example of a very popular open source project.
> Have a look at the current implementation of fmod() in the glibc, which
> does a lot of such bit-fiddling.
>

Here's the code:
https://github.com/bminor/glibc/blob/master/sysdeps/ieee754/dbl-64/e_fmod.c


devel / comp.lang.c++ / Most performant way to have "r % 2 ? -1.0 : 1.0"

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor