| Deutsch English Français Italiano |
|
<vbeaap$nlm3$2@dont-email.me> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!news.mixmin.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: David Brown <david.brown@hesbynett.no>
Newsgroups: comp.arch
Subject: Re: Computer architects leaving Intel...
Date: Fri, 6 Sep 2024 09:17:45 +0200
Organization: A noiseless patient Spider
Lines: 54
Message-ID: <vbeaap$nlm3$2@dont-email.me>
References: <2024Aug30.161204@mips.complang.tuwien.ac.at>
<vb4q5o$12ukk$3@dont-email.me> <vb6a16$38aj5$1@dont-email.me>
<vb7evj$12ukk$4@dont-email.me> <vb8587$3gq7e$1@dont-email.me>
<vb91e7$3o797$1@dont-email.me> <vb9eeh$3q993$1@dont-email.me>
<vb9l7k$3r2c6$2@dont-email.me> <vba26l$3te44$1@dont-email.me>
<vbag2s$3vhih$1@dont-email.me> <vbbnf9$8j04$1@dont-email.me>
<vbbsl4$9hdg$1@dont-email.me> <vbcbob$bd22$3@dont-email.me>
<vbcob9$dvp4$1@dont-email.me> <vbd6ia$e0ld$2@dont-email.me>
<UxpCO.174965$Hld5.7714@fx15.iad>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Fri, 06 Sep 2024 09:17:45 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="6ee2407e3ebfa0481e4977a48a1e13c1";
logging-data="775875"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19AbFinMyhPoffjGo9nvlR6LJGbSi8FHko="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.11.0
Cancel-Lock: sha1:abVP05BkXgba4AbGoMbn2XV4ggE=
In-Reply-To: <UxpCO.174965$Hld5.7714@fx15.iad>
Content-Language: en-GB
Bytes: 3195
On 05/09/2024 23:39, Scott Lurndal wrote:
> Bernd Linsel <bl1-thispartdoesnotbelonghere@gmx.com> writes:
>> On 05.09.24 19:04, Terje Mathisen wrote:
>>> One of my alternatives are
>>>
>>> unsigned u = start; // Cannot be less than zero
>>> if (u) {
>>> u++;
>>> do {
>>> u--;
>>> data[u]...
>>> while (u);
>>> }
>>>
>>> This typically results in effectively the same asm code as the signed
>>> version, except for a bottom JGE (Jump (signed) Greater or Equal instead
>>> of JA (Jump Above or Equal, but my version is far more verbose.
>>>
>>> Alternatively, if you don't need all N bits of the unsigned type, then
>>> you can subtract and check if the top bit is set in the result:
>>>
>>> %G�%@| for (unsigned u = start; (u & TOPBIT) == 0; u--)
>>>
>>> Terje
>>>
>>
>> What about:
>>
>> for (unsigned u = start; u != ~0u; --u)
>
> This is the form we use most when we need
> to work in reverse.
>
In a code review, I would reject that - and all the other nonsenses
suggested here as a way to force all loop indices to be unsigned types
as though that rule was the 11th commandment.
Just write code that makes sense - it's /not/ hard in this case!
for (int i = start; i >= 0; i--) ...
If you need the loop counter to be an unsigned type inside the loop
code, make an unsigned version:
for (int i = start; i >= 0; i--) {
const unsigned int u = i;
...
}
Sometimes it amazes me the kind of nonsense people write in code because
of obsession about particular rules. Code clarity trumps /all/
stylistic rules.