Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

You're at Witt's End.


devel / comp.lang.c / Effect of CPP tags

SubjectAuthor
* Effect of CPP tagsJanis Papanagnou
+- Re: Effect of CPP tagsLowell Gilbert
+* Re: Effect of CPP tagsKaz Kylheku
|`* Re: Effect of CPP tagsSpiros Bousbouras
| `- Re: Effect of CPP tagsTim Rentsch
+* Re: Effect of CPP tagsJanis Papanagnou
|+* Re: Effect of CPP tagsLowell Gilbert
||+* Re: Effect of CPP tagsKeith Thompson
|||`* Re: Effect of CPP tagsKaz Kylheku
||| `* Re: Effect of CPP tagsKeith Thompson
|||  `* Re: Effect of CPP tagsTim Rentsch
|||   `* Re: Effect of CPP tagsKaz Kylheku
|||    +- Re: Effect of CPP tagsJames Kuyper
|||    +* Re: Effect of CPP tagsJames Kuyper
|||    |`* Re: Effect of CPP tagsKaz Kylheku
|||    | +* Re: Effect of CPP tagsJames Kuyper
|||    | |`- Re: Effect of CPP tagsTim Rentsch
|||    | `* Re: Effect of CPP tagsTim Rentsch
|||    |  `* Re: Effect of CPP tagsKeith Thompson
|||    |   +- Re: Effect of CPP tagsDavid Brown
|||    |   +* Re: Effect of CPP tagsTim Rentsch
|||    |   |`- Re: Effect of CPP tagsKeith Thompson
|||    |   `- Re: Effect of CPP tagsTim Rentsch
|||    `- Re: Effect of CPP tagsTim Rentsch
||+* Re: Effect of CPP tagsKaz Kylheku
|||+- Re: Effect of CPP tagsKaz Kylheku
|||`* Re: Effect of CPP tagsLowell Gilbert
||| `- Re: Effect of CPP tagsJanis Papanagnou
||`* Re: Effect of CPP tagsJanis Papanagnou
|| `- Re: Effect of CPP tagsKaz Kylheku
|+- Re: Effect of CPP tagsKaz Kylheku
|`* Re: Effect of CPP tagsScott Lurndal
| +* Re: Effect of CPP tagsJanis Papanagnou
| |`* Re: Effect of CPP tagsKeith Thompson
| | +* Re: Effect of CPP tagsScott Lurndal
| | |`* Re: Effect of CPP tagsDavid Brown
| | | `* Re: Effect of CPP tagsJames Kuyper
| | |  `- Re: Effect of CPP tagsDavid Brown
| | `- Re: Effect of CPP tagsTim Rentsch
| `- usleep (Was: Effect of CPP tags)Kenny McCormack
+* Re: Effect of CPP tagsLawrence D'Oliveiro
|`* Re: Effect of CPP tagsBart
| +* Re: Effect of CPP tagsDavid Brown
| |`* Re: Effect of CPP tagsKeith Thompson
| | `* Re: Effect of CPP tagsKaz Kylheku
| |  `* Re: Effect of CPP tagsBart
| |   +* Re: Effect of CPP tagsLawrence D'Oliveiro
| |   |`* Re: Effect of CPP tagsBart
| |   | `* Re: Effect of CPP tagsLawrence D'Oliveiro
| |   |  `* Re: Effect of CPP tagsBart
| |   |   +* Re: Effect of CPP tagsScott Lurndal
| |   |   |+* Re: Effect of CPP tagsDavid Brown
| |   |   ||`- Re: Effect of CPP tagsBGB
| |   |   |`* Re: Effect of CPP tagsBart
| |   |   | `- Re: Effect of CPP tagsDavid Brown
| |   |   `- Re: Effect of CPP tagsLawrence D'Oliveiro
| |   `* Re: Effect of CPP tagsDavid Brown
| |    +* Re: Effect of CPP tagsBart
| |    |+- Re: Effect of CPP tagsScott Lurndal
| |    |+* Re: Effect of CPP tagsKaz Kylheku
| |    ||+* Re: Effect of CPP tagsBart
| |    |||`* Re: Effect of CPP tagsBart
| |    ||| +- Re: Effect of CPP tagsKeith Thompson
| |    ||| `* Re: Effect of CPP tagsKaz Kylheku
| |    |||  `* Re: Effect of CPP tagsKeith Thompson
| |    |||   +* Re: Effect of CPP tagsJanis Papanagnou
| |    |||   |`- Re: Effect of CPP tagsKeith Thompson
| |    |||   `- Re: Effect of CPP tagsKaz Kylheku
| |    ||`- Re: Effect of CPP tagsScott Lurndal
| |    |`- Re: Effect of CPP tagsDavid Brown
| |    `* Re: Effect of CPP tagsLawrence D'Oliveiro
| |     +* Re: Effect of CPP tagsChris M. Thomasson
| |     |`* Re: Effect of CPP tagsLawrence D'Oliveiro
| |     | `* Re: Effect of CPP tagsChris M. Thomasson
| |     |  `* Re: Effect of CPP tagsLawrence D'Oliveiro
| |     |   +- Re: Effect of CPP tagsChris M. Thomasson
| |     |   +- Re: Effect of CPP tagsChris M. Thomasson
| |     |   +- Re: Effect of CPP tagsKaz Kylheku
| |     |   `- Re: Effect of CPP tagsBlue-Maned_Hawk
| |     +* Re: Effect of CPP tagsDavid Brown
| |     |+* Re: Effect of CPP tagsBart
| |     ||+* Re: Effect of CPP tagsDavid Brown
| |     |||+- Re: Effect of CPP tagsBlue-Maned_Hawk
| |     |||`* Re: Effect of CPP tagsBart
| |     ||| `* Re: Effect of CPP tagsDavid Brown
| |     |||  `* Re: Effect of CPP tagsBart
| |     |||   +* Re: Effect of CPP tagsChris M. Thomasson
| |     |||   |`- Re: Effect of CPP tagsChris M. Thomasson
| |     |||   +* Re: Effect of CPP tagstTh
| |     |||   |+- Re: Effect of CPP tagsLawrence D'Oliveiro
| |     |||   |+- Re: Effect of CPP tagsKaz Kylheku
| |     |||   |`* Re: Effect of CPP tagsBart
| |     |||   | `* Re: Effect of CPP tagsScott Lurndal
| |     |||   |  `* Re: Effect of CPP tagsBart
| |     |||   |   `* Re: Effect of CPP tagsDavid Brown
| |     |||   |    +* Re: Effect of CPP tagsKaz Kylheku
| |     |||   |    |`* Re: Effect of CPP tagsDavid Brown
| |     |||   |    | `- Re: Effect of CPP tagsKaz Kylheku
| |     |||   |    `* Re: Effect of CPP tagsBart
| |     |||   |     +* Re: Effect of CPP tagsScott Lurndal
| |     |||   |     |`* Re: Effect of CPP tagsBart
| |     |||   |     `* Re: Effect of CPP tagsDavid Brown
| |     |||   `* Re: Effect of CPP tagsDavid Brown
| |     ||`* Re: Effect of CPP tagsBlue-Maned_Hawk
| |     |`* Re: Effect of CPP tagsLawrence D'Oliveiro
| |     `* Re: Effect of CPP tagsKaz Kylheku
| +- Re: Effect of CPP tagsRichard Damon
| +* Re: Effect of CPP tagsKaz Kylheku
| +* Re: Effect of CPP tagsBlue-Maned_Hawk
| `- Re: Effect of CPP tagsLawrence D'Oliveiro
`* Re: Effect of CPP tagsTim Rentsch

Pages:123456789101112131415161718192021222324252627
Re: Effect of CPP tags

<uo75um$1lq3e$1@dont-email.me>

  copy mid

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

  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: bc...@freeuk.com (bart)
Newsgroups: comp.lang.c
Subject: Re: Effect of CPP tags
Date: Wed, 17 Jan 2024 00:11:01 +0000
Organization: A noiseless patient Spider
Lines: 88
Message-ID: <uo75um$1lq3e$1@dont-email.me>
References: <umet9d$3hir9$1@dont-email.me> <20240111081109.274@kylheku.com>
<unpd89$33jlu$1@dont-email.me> <20240111133742.530@kylheku.com>
<unpt44$35qn1$1@dont-email.me> <unrfgs$3fo6l$1@dont-email.me>
<unrocu$3h2ah$1@dont-email.me> <20240112132216.285@kylheku.com>
<uo0je6$e8fv$1@dont-email.me> <20240114115640.506@kylheku.com>
<uo24di$lo8r$1@dont-email.me> <20240114222417.720@kylheku.com>
<uo3eli$uv97$1@dont-email.me> <6pbpN.200172$7sbb.118143@fx16.iad>
<uo3jth$vqg9$1@dont-email.me> <B1epN.177806$c3Ea.53953@fx10.iad>
<uo3v2u$11mbu$1@dont-email.me> <20240115152928.267@kylheku.com>
<uo5pdi$1dgnv$1@dont-email.me> <20240116100845.82@kylheku.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 17 Jan 2024 00:11:02 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="6268282b8239d0a8c360e6001c42a605";
logging-data="1763438"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+MaUs8gIDiWL1V+FJVrp/gZNAFxsHGVWY="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:/m27W2+wl3d1dVw6uJlRiL8Zmj8=
Content-Language: en-GB
In-Reply-To: <20240116100845.82@kylheku.com>
 by: bart - Wed, 17 Jan 2024 00:11 UTC

On 16/01/2024 18:39, Kaz Kylheku wrote:
> On 2024-01-16, bart <bc@freeuk.com> wrote:

>> gcc is a project 10s of 1000s of files. If a particular configuration
>> targets one architecture out of 100, it can also support the ASM syntax
>> for that architecture.
>
> Not reasonably so. The parser of every front end would have to have
> a special case for that assembly language.
>
> The proposal does not pass a cost/benefit analysis, due to the
> high cost and low benefit.
>
>> You don't need to have the ASM syntax embedded within the C grammar. Not
>> so specifically anyway; you allow a bunch of keyword and register tokens
>> within asm{...}.
>
> keywords and tokens are grammar.

So how does the grammar of HTML work: does it also include the entire
grammar of JavaScript?

JS appears inside <script> ... </script> tags.

My assemble appears in a 'assem ... end block', or there's a one-liner
version which starts with 'asm'.

When my parser sees 'assem' or 'asm', it calls one of these functions:

if lx.subcode=0 then
p:=readassemline()
else
p:=readassemblock()
fi

They are in a 250-line module that deals with assembly. They return an
'assem' AST node.

Now, my assembly syntax is not Intel, just Intel style, and is flavoured
with elements of my HLL syntax (so uses 'u32' for example rather than
'dword').

There is a separate set of tables within the target-specific backend,
which contains all the supported x64 opcodes and registgers for example.
This part is needed anyway to generate x64 native code, whether assembly
source or binary.

When the global symbol table is initialised, the contents of those
opcode and register tables are added to it.

It's done in a way so that, if not in an ASM block, those can be used as
normal identifiers:

int mov, rax, push

mov := rax + push

If I wanted to refer to those from inline assembly, I have to escape them:

asm push [`push]

So, with a different architecture, I have a different backend and
different set opcode and register names.

The 250-line parsing module could possibly be made to deal with more
than one target, otherwise it's not a great imposition.

This stuff needn't be that hard. There just seems unwillingness to make
things easy and sensible.

Perhaps in a world full of C macros, makefile syntax and bash scripts,
the assembly syntax isn't considered too outre.

But, you say assembly isn't used much; have you considered that that
might be because it's such a pig to use?

> How things look does become important when you are writing tens of
> thousands of lines of code.

But not thousands, or even hundreds? Or dozens? Code can always benefit
from being readable and also not being painful to type.

Personally I think /any/ conventional assembly looks dreadful in even
small amounts, including mine. But gcc-style is a LOT worse.

Re: Effect of CPP tags

<uo78ik$1lvso$1@dont-email.me>

  copy mid

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

  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: chris.m....@gmail.com (Chris M. Thomasson)
Newsgroups: comp.lang.c
Subject: Re: Effect of CPP tags
Date: Tue, 16 Jan 2024 16:55:48 -0800
Organization: A noiseless patient Spider
Lines: 29
Message-ID: <uo78ik$1lvso$1@dont-email.me>
References: <umet9d$3hir9$1@dont-email.me> <unkuhp$27i0v$2@dont-email.me>
<unlqqa$2eqts$2@dont-email.me> <U7ynN.143065$Wp_8.30410@fx17.iad>
<unmmnd$2jair$1@dont-email.me> <87edepnich.fsf@nosuchdomain.example.com>
<unmqsg$2jvva$1@dont-email.me> <unmu6b$2kh81$1@dont-email.me>
<20240110133135.834@kylheku.com> <unn65q$2lr2i$1@dont-email.me>
<20240110182957.444@kylheku.com> <unokb1$2vmkh$1@dont-email.me>
<20240111081109.274@kylheku.com> <unpd89$33jlu$1@dont-email.me>
<20240111133742.530@kylheku.com> <unpt44$35qn1$1@dont-email.me>
<unrfgs$3fo6l$1@dont-email.me> <unrocu$3h2ah$1@dont-email.me>
<20240112132216.285@kylheku.com> <uo0je6$e8fv$1@dont-email.me>
<20240114115640.506@kylheku.com> <uo24di$lo8r$1@dont-email.me>
<20240114222417.720@kylheku.com> <20240114231905.155@kylheku.com>
<uo3l28$1010j$1@dont-email.me> <uo3mhi$1073t$1@dont-email.me>
<uo44fg$12ct8$2@dont-email.me> <20240115152033.334@kylheku.com>
<uo4p1q$15bb0$1@dont-email.me> <uo60su$1f9o7$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Wed, 17 Jan 2024 00:55:48 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="9d60b08ecf7f21a413a4c560ba63b788";
logging-data="1769368"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX194Cn8abyfHsChChFl9axmdfWy2dlaWy3M="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:l9sJlHO61wdLiW80IC+WiWDAwBc=
Content-Language: en-US
In-Reply-To: <uo60su$1f9o7$1@dont-email.me>
 by: Chris M. Thomasson - Wed, 17 Jan 2024 00:55 UTC

On 1/16/2024 5:38 AM, David Brown wrote:
> On 16/01/2024 03:18, Chris M. Thomasson wrote:
>> On 1/15/2024 3:24 PM, Kaz Kylheku wrote:
>>> On 2024-01-15, Chris M. Thomasson <chris.m.thomasson.1@gmail.com> wrote:
>>>> On 1/15/2024 8:29 AM, David Brown wrote:
>>>>> On 15/01/2024 17:04, David Brown wrote:
>>>>>> On 15/01/2024 08:40, Kaz Kylheku wrote:
[...]
>> No rouge compiler thinking that link-time optimizations are all fun
>> and joy, lets dance around the sync instructions... Step on them, ruin
>> them, make them incorrect. Even GCC had a nasty error with an
>> optimization wrt Pthread pthread_mutex_trylock(). Simply ruined is
>> correctness wrt the standard.
>>
>
> You've mentioned this many times - do you have a reference that gives
> the source of this function (at the time when there was an issue), and a
> description or report of what you think gcc did wrong?  I am curious as
> to whether it was a bug in the code or a bug in gcc (gcc is certainly
> not bug-free).

It was a bug in GCC itself. It was posted over on
comp.programming.threads. Just of the top of my head, it was from a
smart guy by the name of David Schwartz... I probably butchered his last
name wrt spelling! I just need to find it again. Argh.

I created my own externally assembled sync primitives because, well, I
wanted to try to make sure no compiler can mess around with them. One
little mistake and is does not work at all.

Re: Effect of CPP tags

<uo793d$1lvso$2@dont-email.me>

  copy mid

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

  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: chris.m....@gmail.com (Chris M. Thomasson)
Newsgroups: comp.lang.c
Subject: Re: Effect of CPP tags
Date: Tue, 16 Jan 2024 17:04:44 -0800
Organization: A noiseless patient Spider
Lines: 68
Message-ID: <uo793d$1lvso$2@dont-email.me>
References: <umet9d$3hir9$1@dont-email.me> <20240111081109.274@kylheku.com>
<unpd89$33jlu$1@dont-email.me> <20240111133742.530@kylheku.com>
<unpt44$35qn1$1@dont-email.me> <unrfgs$3fo6l$1@dont-email.me>
<unrocu$3h2ah$1@dont-email.me> <20240112132216.285@kylheku.com>
<uo0je6$e8fv$1@dont-email.me> <20240114115640.506@kylheku.com>
<uo24di$lo8r$1@dont-email.me> <20240114222417.720@kylheku.com>
<uo3eli$uv97$1@dont-email.me> <6pbpN.200172$7sbb.118143@fx16.iad>
<uo3jth$vqg9$1@dont-email.me> <B1epN.177806$c3Ea.53953@fx10.iad>
<uo3v2u$11mbu$1@dont-email.me> <20240115152928.267@kylheku.com>
<uo5pdi$1dgnv$1@dont-email.me> <uo62gj$1finu$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Wed, 17 Jan 2024 01:04:45 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="9d60b08ecf7f21a413a4c560ba63b788";
logging-data="1769368"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19keCOKYw2iXmVcIe3nThhA6pYof20tQKA="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:g/J46mECGzm9xogwyJB0nqC/QZQ=
In-Reply-To: <uo62gj$1finu$1@dont-email.me>
Content-Language: en-US
 by: Chris M. Thomasson - Wed, 17 Jan 2024 01:04 UTC

On 1/16/2024 6:06 AM, David Brown wrote:
> On 16/01/2024 12:30, bart wrote:
>> On 16/01/2024 01:21, Kaz Kylheku wrote:
>>> On 2024-01-15, bart <bc@freeuk.com> wrote:
>>
>> [Inline assembly]
>>
>>> The instruction template is just a string literal to the
>>> compiler. It specifies text to be inserted into the assembly
>>> output.
>>>
>>> Some assembly languages require the whitespace; you need
>>> instructions to be on separate lines.
>>>
>>> GCC does not look inside this template other than to replace
>>> % codes like %0 (the first register).
>>>
>>> In my example, I put the newlines and tabs together on the right
>>>
>>>    "imul %3, %2\n\t"
>>>    "add %1, %2\n\t"
>>>    "mov %1, %0\n\t"
>>>
>>> Thanks to these newlines and tabs, the textual output (generated .s
>>> file if we use gcc -S) has this in it:
>>>
>>> #APP
>>> # 24 "inline.c" 1
>>>          imul %edx, %esi
>>>          add %esi, %edi
>>>          mov %edi, %edi
>>>
>>> # 0 "" 2
>>> #NO_APP
>>>          movl    8(%rsp), %eax
>>>          movl    16(%rsp), %edx
>>>
>>
>> This is still peculiar: why prioritise the appearance of the
>> intermediate code which I assume you're rarely going to look at?
>
> It's often just habit.  The tab character is entirely unnecessary, at
> least for gas (other assemblers may complain about instructions
> appearing at the start of the line).  You do need some kind of
> separation between the assembly instructions - if you don't use "\n",
> then you could also use ";" (again, I know it works for gas).  "\n\t" is
> a common habit, however, and has the benefit of looking nice if you
> examine the generated assembly - and if you are working with inline
> assembly, sometimes that is a very useful thing to check.
>
>>
>> It's the version with strings and escape codes that you're going to be
>> writing and maintaining, and that people will see in the C sources!
>>
>
> Well, you don't often write inline assembly - its rare to write it. It's
> typically the kind of thing you write once for your particular
> instruction, then stick it away in a header somewhere.  You might use it
> often, but you don't need to read or edit the code often.[...]

As soon as you use inline assembler in a file, you sort of "need" to?
Alter the name of the file, or add in sufficient comments that says this
is arch specific! Damn it. ;^) Ahhh, bust out the macros.

ct_foo.c becomes ct_foo_i686.c ?

;^D Been there done that...

Re: Effect of CPP tags

<uo79at$1lvso$3@dont-email.me>

  copy mid

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

  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: chris.m....@gmail.com (Chris M. Thomasson)
Newsgroups: comp.lang.c
Subject: Re: Effect of CPP tags
Date: Tue, 16 Jan 2024 17:08:44 -0800
Organization: A noiseless patient Spider
Lines: 22
Message-ID: <uo79at$1lvso$3@dont-email.me>
References: <umet9d$3hir9$1@dont-email.me> <unkuhp$27i0v$2@dont-email.me>
<unlqqa$2eqts$2@dont-email.me> <U7ynN.143065$Wp_8.30410@fx17.iad>
<unmmnd$2jair$1@dont-email.me> <87edepnich.fsf@nosuchdomain.example.com>
<unmqsg$2jvva$1@dont-email.me> <unmu6b$2kh81$1@dont-email.me>
<20240110133135.834@kylheku.com> <unn65q$2lr2i$1@dont-email.me>
<20240110182957.444@kylheku.com> <unokb1$2vmkh$1@dont-email.me>
<20240111081109.274@kylheku.com> <unpd89$33jlu$1@dont-email.me>
<20240111133742.530@kylheku.com> <unpt44$35qn1$1@dont-email.me>
<unrfgs$3fo6l$1@dont-email.me> <unrocu$3h2ah$1@dont-email.me>
<20240112132216.285@kylheku.com> <uo0je6$e8fv$1@dont-email.me>
<20240114115640.506@kylheku.com> <uo24di$lo8r$1@dont-email.me>
<20240114222417.720@kylheku.com> <20240114231905.155@kylheku.com>
<uo3l28$1010j$1@dont-email.me> <uo3mhi$1073t$1@dont-email.me>
<uo44fg$12ct8$2@dont-email.me> <20240115152033.334@kylheku.com>
<uo4p1q$15bb0$1@dont-email.me> <uo60su$1f9o7$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Wed, 17 Jan 2024 01:08:45 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="9d60b08ecf7f21a413a4c560ba63b788";
logging-data="1769368"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18btewUZZA50MOyb8mn8U+fg/osbxQcK2k="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:pS3AtGZPGU1qt67FAamg3rYKu2Y=
In-Reply-To: <uo60su$1f9o7$1@dont-email.me>
Content-Language: en-US
 by: Chris M. Thomasson - Wed, 17 Jan 2024 01:08 UTC

On 1/16/2024 5:38 AM, David Brown wrote:
> On 16/01/2024 03:18, Chris M. Thomasson wrote:
>> On 1/15/2024 3:24 PM, Kaz Kylheku wrote:
>>> On 2024-01-15, Chris M. Thomasson <chris.m.thomasson.1@gmail.com> wrote:
>>>> On 1/15/2024 8:29 AM, David Brown wrote:
>>>>> On 15/01/2024 17:04, David Brown wrote:
>>>>>> On 15/01/2024 08:40, Kaz Kylheku wrote:
[...]
> You've mentioned this many times - do you have a reference that gives
> the source of this function (at the time when there was an issue), and a
> description or report of what you think gcc did wrong?  I am curious as
> to whether it was a bug in the code or a bug in gcc (gcc is certainly
> not bug-free).
>

I think I found it David!

https://groups.google.com/g/comp.programming.threads/c/Y_Y2DZOWErM/m/nuyEoKq0onUJ

Re: Effect of CPP tags

<20240116172414.760@kylheku.com>

  copy mid

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

  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!.POSTED!not-for-mail
From: 433-929-...@kylheku.com (Kaz Kylheku)
Newsgroups: comp.lang.c
Subject: Re: Effect of CPP tags
Date: Wed, 17 Jan 2024 02:21:57 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 29
Message-ID: <20240116172414.760@kylheku.com>
References: <umet9d$3hir9$1@dont-email.me> <unlqqa$2eqts$2@dont-email.me>
<U7ynN.143065$Wp_8.30410@fx17.iad> <unmmnd$2jair$1@dont-email.me>
<87edepnich.fsf@nosuchdomain.example.com> <unmqsg$2jvva$1@dont-email.me>
<unmu6b$2kh81$1@dont-email.me> <20240110133135.834@kylheku.com>
<unn65q$2lr2i$1@dont-email.me> <20240110182957.444@kylheku.com>
<unokb1$2vmkh$1@dont-email.me> <20240111081109.274@kylheku.com>
<unpd89$33jlu$1@dont-email.me> <20240111133742.530@kylheku.com>
<unpt44$35qn1$1@dont-email.me> <unrfgs$3fo6l$1@dont-email.me>
<unrocu$3h2ah$1@dont-email.me> <20240112132216.285@kylheku.com>
<uo0je6$e8fv$1@dont-email.me> <20240114115640.506@kylheku.com>
<uo24di$lo8r$1@dont-email.me> <20240114222417.720@kylheku.com>
<20240114231905.155@kylheku.com> <uo3l28$1010j$1@dont-email.me>
<uo3mhi$1073t$1@dont-email.me> <uo44fg$12ct8$2@dont-email.me>
<20240115152033.334@kylheku.com> <uo4p1q$15bb0$1@dont-email.me>
<uo60su$1f9o7$1@dont-email.me> <uo79at$1lvso$3@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Wed, 17 Jan 2024 02:21:57 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="30353e714807d76ba68823a6307c7dd8";
logging-data="1796752"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18jC++Wf0ZrdG0kBpiuh9LTzVDIprS1t/Q="
User-Agent: slrn/pre1.0.4-9 (Linux)
Cancel-Lock: sha1:bc2JODri06OFKREAI4IdtSUvqH4=
 by: Kaz Kylheku - Wed, 17 Jan 2024 02:21 UTC

On 2024-01-17, Chris M. Thomasson <chris.m.thomasson.1@gmail.com> wrote:
> On 1/16/2024 5:38 AM, David Brown wrote:
>> On 16/01/2024 03:18, Chris M. Thomasson wrote:
>>> On 1/15/2024 3:24 PM, Kaz Kylheku wrote:
>>>> On 2024-01-15, Chris M. Thomasson <chris.m.thomasson.1@gmail.com> wrote:
>>>>> On 1/15/2024 8:29 AM, David Brown wrote:
>>>>>> On 15/01/2024 17:04, David Brown wrote:
>>>>>>> On 15/01/2024 08:40, Kaz Kylheku wrote:
> [...]
>> You've mentioned this many times - do you have a reference that gives
>> the source of this function (at the time when there was an issue), and a
>> description or report of what you think gcc did wrong?  I am curious as
>> to whether it was a bug in the code or a bug in gcc (gcc is certainly
>> not bug-free).
>>
>
> I think I found it David!
>
> https://groups.google.com/g/comp.programming.threads/c/Y_Y2DZOWErM/m/nuyEoKq0onUJ

David Schwartz has since been acquired by and merged with David
Butenhoff, to form David Schwartzenhoff. The new motto is "bigger living
through slightly less concurrency".

--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca
NOTE: If you use Google Groups, I don't see you, unless you're whitelisted.

Re: Effect of CPP tags

<uo7ee5$1mtqj$1@dont-email.me>

  copy mid

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

  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: chris.m....@gmail.com (Chris M. Thomasson)
Newsgroups: comp.lang.c
Subject: Re: Effect of CPP tags
Date: Tue, 16 Jan 2024 18:35:48 -0800
Organization: A noiseless patient Spider
Lines: 61
Message-ID: <uo7ee5$1mtqj$1@dont-email.me>
References: <umet9d$3hir9$1@dont-email.me> <unlqqa$2eqts$2@dont-email.me>
<U7ynN.143065$Wp_8.30410@fx17.iad> <unmmnd$2jair$1@dont-email.me>
<87edepnich.fsf@nosuchdomain.example.com> <unmqsg$2jvva$1@dont-email.me>
<unmu6b$2kh81$1@dont-email.me> <20240110133135.834@kylheku.com>
<unn65q$2lr2i$1@dont-email.me> <20240110182957.444@kylheku.com>
<unokb1$2vmkh$1@dont-email.me> <20240111081109.274@kylheku.com>
<unpd89$33jlu$1@dont-email.me> <20240111133742.530@kylheku.com>
<unpt44$35qn1$1@dont-email.me> <unrfgs$3fo6l$1@dont-email.me>
<unrocu$3h2ah$1@dont-email.me> <20240112132216.285@kylheku.com>
<uo0je6$e8fv$1@dont-email.me> <20240114115640.506@kylheku.com>
<uo24di$lo8r$1@dont-email.me> <20240114222417.720@kylheku.com>
<20240114231905.155@kylheku.com> <uo3l28$1010j$1@dont-email.me>
<uo3mhi$1073t$1@dont-email.me> <uo44fg$12ct8$2@dont-email.me>
<20240115152033.334@kylheku.com> <uo4p1q$15bb0$1@dont-email.me>
<uo60su$1f9o7$1@dont-email.me> <uo79at$1lvso$3@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Wed, 17 Jan 2024 02:35:49 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="9d60b08ecf7f21a413a4c560ba63b788";
logging-data="1800019"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1++yqnmTEarMPb0JMJfqWWdUuhuZ5YpbLI="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:Ey65fu4va1OoensuOgrakHpGmpA=
In-Reply-To: <uo79at$1lvso$3@dont-email.me>
Content-Language: en-US
 by: Chris M. Thomasson - Wed, 17 Jan 2024 02:35 UTC

On 1/16/2024 5:08 PM, Chris M. Thomasson wrote:
> On 1/16/2024 5:38 AM, David Brown wrote:
>> On 16/01/2024 03:18, Chris M. Thomasson wrote:
>>> On 1/15/2024 3:24 PM, Kaz Kylheku wrote:
>>>> On 2024-01-15, Chris M. Thomasson <chris.m.thomasson.1@gmail.com>
>>>> wrote:
>>>>> On 1/15/2024 8:29 AM, David Brown wrote:
>>>>>> On 15/01/2024 17:04, David Brown wrote:
>>>>>>> On 15/01/2024 08:40, Kaz Kylheku wrote:
> [...]
>> You've mentioned this many times - do you have a reference that gives
>> the source of this function (at the time when there was an issue), and
>> a description or report of what you think gcc did wrong?  I am curious
>> as to whether it was a bug in the code or a bug in gcc (gcc is
>> certainly not bug-free).
>>
>
> I think I found it David!
>
> https://groups.google.com/g/comp.programming.threads/c/Y_Y2DZOWErM/m/nuyEoKq0onUJ
>
>
>
>

Here is a nice quote from Dave Butenhof in that thread:
____________________________

Dave Butenhof's profile photo
Dave Butenhof
Nov 15, 2007, 3:12:14 PM
to
Chris Thomasson wrote:
> "Zeljko Vrba" <zvrba....@ieee-sb1.cc.fer.hr> wrote in message
> news:slrnfjnt6l...@ieee-sb1.cc.fer.hr...
>> On 2007-11-14, Chris Thomasson <cri...@comcast.net> wrote:
>>>
>>> If GCC performs the optimization that David Schwartz pointer out, your
>>> basically screwed. AFAICT, GCC is totally busted if it allows stores to
>>> escape a critical-section. This is a race-condition waiting to
>>> happen. I am
>>>
>> How is the compiler supposed to know where a CS begins and ends? should
>> it have a knowledge of every imaginable official and unofficial API?
>
> I was under the impression that POSIX puts some restrictions on
> compilers. Humm... I can't really remember where I heard that right now,
> but I sure think I did. Humm...
The point is that POSIX puts restrictions on the behavior of a
conforming system. That includes library, kernel, and compiler. If the
RESULT doesn't behave like POSIX, then it's not POSIX.

A compiler that's part of a conforming POSIX system environment can't
generate code that breaks synchronization. How it and the rest of the
system accomplish that is unspecified.

Often, it means simply not performing risky optimizations. But if they
are enabled, then the system needs to be able to detect and avoid
performing them in "dangerous" areas of code. (A complicated problem,
but nothing's impossible.)
____________________________

Re: Effect of CPP tags

<20240116185341.795@kylheku.com>

  copy mid

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

  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: 433-929-...@kylheku.com (Kaz Kylheku)
Newsgroups: comp.lang.c
Subject: Re: Effect of CPP tags
Date: Wed, 17 Jan 2024 03:03:47 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 111
Message-ID: <20240116185341.795@kylheku.com>
References: <umet9d$3hir9$1@dont-email.me>
<U7ynN.143065$Wp_8.30410@fx17.iad> <unmmnd$2jair$1@dont-email.me>
<87edepnich.fsf@nosuchdomain.example.com> <unmqsg$2jvva$1@dont-email.me>
<unmu6b$2kh81$1@dont-email.me> <20240110133135.834@kylheku.com>
<unn65q$2lr2i$1@dont-email.me> <20240110182957.444@kylheku.com>
<unokb1$2vmkh$1@dont-email.me> <20240111081109.274@kylheku.com>
<unpd89$33jlu$1@dont-email.me> <20240111133742.530@kylheku.com>
<unpt44$35qn1$1@dont-email.me> <unrfgs$3fo6l$1@dont-email.me>
<unrocu$3h2ah$1@dont-email.me> <20240112132216.285@kylheku.com>
<uo0je6$e8fv$1@dont-email.me> <20240114115640.506@kylheku.com>
<uo24di$lo8r$1@dont-email.me> <20240114222417.720@kylheku.com>
<20240114231905.155@kylheku.com> <uo3l28$1010j$1@dont-email.me>
<uo3mhi$1073t$1@dont-email.me> <uo44fg$12ct8$2@dont-email.me>
<20240115152033.334@kylheku.com> <uo4p1q$15bb0$1@dont-email.me>
<uo60su$1f9o7$1@dont-email.me> <uo79at$1lvso$3@dont-email.me>
<uo7ee5$1mtqj$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Wed, 17 Jan 2024 03:03:47 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="30353e714807d76ba68823a6307c7dd8";
logging-data="1933020"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18auBoV6M+ESRTT4N3PrkJPgkav7SiewIY="
User-Agent: slrn/pre1.0.4-9 (Linux)
Cancel-Lock: sha1:z02qTcPy47b1CdgOvcUDnwexg/4=
 by: Kaz Kylheku - Wed, 17 Jan 2024 03:03 UTC

On 2024-01-17, Chris M. Thomasson <chris.m.thomasson.1@gmail.com> wrote:
> On 1/16/2024 5:08 PM, Chris M. Thomasson wrote:
>> On 1/16/2024 5:38 AM, David Brown wrote:
>>> On 16/01/2024 03:18, Chris M. Thomasson wrote:
>>>> On 1/15/2024 3:24 PM, Kaz Kylheku wrote:
>>>>> On 2024-01-15, Chris M. Thomasson <chris.m.thomasson.1@gmail.com>
>>>>> wrote:
>>>>>> On 1/15/2024 8:29 AM, David Brown wrote:
>>>>>>> On 15/01/2024 17:04, David Brown wrote:
>>>>>>>> On 15/01/2024 08:40, Kaz Kylheku wrote:
>> [...]
>>> You've mentioned this many times - do you have a reference that gives
>>> the source of this function (at the time when there was an issue), and
>>> a description or report of what you think gcc did wrong?  I am curious
>>> as to whether it was a bug in the code or a bug in gcc (gcc is
>>> certainly not bug-free).
>>>
>>
>> I think I found it David!
>>
>> https://groups.google.com/g/comp.programming.threads/c/Y_Y2DZOWErM/m/nuyEoKq0onUJ
>>
>>
>>
>>
>
> Here is a nice quote from Dave Butenhof in that thread:
> ____________________________
>
> Dave Butenhof's profile photo
> Dave Butenhof
> Nov 15, 2007, 3:12:14 PM
> to
> Chris Thomasson wrote:
> > "Zeljko Vrba" <zvrba....@ieee-sb1.cc.fer.hr> wrote in message
> > news:slrnfjnt6l...@ieee-sb1.cc.fer.hr...
> >> On 2007-11-14, Chris Thomasson <cri...@comcast.net> wrote:
> >>>
> >>> If GCC performs the optimization that David Schwartz pointer out, your
> >>> basically screwed. AFAICT, GCC is totally busted if it allows stores to
> >>> escape a critical-section. This is a race-condition waiting to
> >>> happen. I am
> >>>
> >> How is the compiler supposed to know where a CS begins and ends? should
> >> it have a knowledge of every imaginable official and unofficial API?
> >
> > I was under the impression that POSIX puts some restrictions on
> > compilers. Humm... I can't really remember where I heard that right now,
> > but I sure think I did. Humm...
> The point is that POSIX puts restrictions on the behavior of a
> conforming system. That includes library, kernel, and compiler. If the
> RESULT doesn't behave like POSIX, then it's not POSIX.
>
> A compiler that's part of a conforming POSIX system environment can't
> generate code that breaks synchronization. How it and the rest of the
> system accomplish that is unspecified.
>
> Often, it means simply not performing risky optimizations. But if they
> are enabled, then the system needs to be able to detect and avoid
> performing them in "dangerous" areas of code. (A complicated problem,
> but nothing's impossible.)

Basically, the optimization can only be performed when the value
which controls the selection statement can be shown not to have
been derived from the result of a pthread function, such that the value
indicates whether the caller owns or does not own a lock.

This is very difficult.

Even a value scanned from a stream can be such a value:

int result = pthred_mutex_trylock(...);

FILE *f = fopen("foo.txt", "w");
fprintf(f, "%d\n", result);
fclose(f);
system("mv foo.txt bar.txt");

int x;
FILE *g = fopen("bar.txt", "r");
fscanf(g, "%d", &f);
fclose(g);

if (x == 0) {
a++;
}

A better angle on it would be not to pursue the analysis of x at all,
but concentrate on a. If the variable a isn't something that can be
thread shared, then the optimization is okay.

If a is a local variable whose address has never been taken (or
else has never escaped from this scope), then it's should be
to convert this to:

int __inc = (x == 0);
a += __inc;

If a is something potentially shared, then no.

Programs that want good optimization should concentrate on using
automatic (not static) local variables as much as possible, in such a
way that it's clear that those variables don't escape into other scopes.
Those kinds of variables can be aggressively optimized, threads or not.

--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca
NOTE: If you use Google Groups, I don't see you, unless you're whitelisted.

Re: Effect of CPP tags

<uo7jap$1rb6c$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!usenet.network!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: chris.m....@gmail.com (Chris M. Thomasson)
Newsgroups: comp.lang.c
Subject: Re: Effect of CPP tags
Date: Tue, 16 Jan 2024 19:59:21 -0800
Organization: A noiseless patient Spider
Lines: 112
Message-ID: <uo7jap$1rb6c$1@dont-email.me>
References: <umet9d$3hir9$1@dont-email.me> <unmmnd$2jair$1@dont-email.me>
<87edepnich.fsf@nosuchdomain.example.com> <unmqsg$2jvva$1@dont-email.me>
<unmu6b$2kh81$1@dont-email.me> <20240110133135.834@kylheku.com>
<unn65q$2lr2i$1@dont-email.me> <20240110182957.444@kylheku.com>
<unokb1$2vmkh$1@dont-email.me> <20240111081109.274@kylheku.com>
<unpd89$33jlu$1@dont-email.me> <20240111133742.530@kylheku.com>
<unpt44$35qn1$1@dont-email.me> <unrfgs$3fo6l$1@dont-email.me>
<unrocu$3h2ah$1@dont-email.me> <20240112132216.285@kylheku.com>
<uo0je6$e8fv$1@dont-email.me> <20240114115640.506@kylheku.com>
<uo24di$lo8r$1@dont-email.me> <20240114222417.720@kylheku.com>
<20240114231905.155@kylheku.com> <uo3l28$1010j$1@dont-email.me>
<uo3mhi$1073t$1@dont-email.me> <uo44fg$12ct8$2@dont-email.me>
<20240115152033.334@kylheku.com> <uo4p1q$15bb0$1@dont-email.me>
<uo60su$1f9o7$1@dont-email.me> <uo79at$1lvso$3@dont-email.me>
<uo7ee5$1mtqj$1@dont-email.me> <20240116185341.795@kylheku.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Wed, 17 Jan 2024 03:59:22 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="9d60b08ecf7f21a413a4c560ba63b788";
logging-data="1944780"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+I8HkEMuUCmwo0lWpPZzjI7usTM4uy6tU="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:6hIL5zYrybnb8KHGJCBzFI66d6c=
Content-Language: en-US
In-Reply-To: <20240116185341.795@kylheku.com>
 by: Chris M. Thomasson - Wed, 17 Jan 2024 03:59 UTC

On 1/16/2024 7:03 PM, Kaz Kylheku wrote:
> On 2024-01-17, Chris M. Thomasson <chris.m.thomasson.1@gmail.com> wrote:
>> On 1/16/2024 5:08 PM, Chris M. Thomasson wrote:
>>> On 1/16/2024 5:38 AM, David Brown wrote:
>>>> On 16/01/2024 03:18, Chris M. Thomasson wrote:
>>>>> On 1/15/2024 3:24 PM, Kaz Kylheku wrote:
>>>>>> On 2024-01-15, Chris M. Thomasson <chris.m.thomasson.1@gmail.com>
>>>>>> wrote:
>>>>>>> On 1/15/2024 8:29 AM, David Brown wrote:
>>>>>>>> On 15/01/2024 17:04, David Brown wrote:
>>>>>>>>> On 15/01/2024 08:40, Kaz Kylheku wrote:
>>> [...]
>>>> You've mentioned this many times - do you have a reference that gives
>>>> the source of this function (at the time when there was an issue), and
>>>> a description or report of what you think gcc did wrong?  I am curious
>>>> as to whether it was a bug in the code or a bug in gcc (gcc is
>>>> certainly not bug-free).
>>>>
>>>
>>> I think I found it David!
>>>
>>> https://groups.google.com/g/comp.programming.threads/c/Y_Y2DZOWErM/m/nuyEoKq0onUJ
>>>
>>>
>>>
>>>
>>
>> Here is a nice quote from Dave Butenhof in that thread:
>> ____________________________
>>
>> Dave Butenhof's profile photo
>> Dave Butenhof
>> Nov 15, 2007, 3:12:14 PM
>> to
>> Chris Thomasson wrote:
>>> "Zeljko Vrba" <zvrba....@ieee-sb1.cc.fer.hr> wrote in message
>>> news:slrnfjnt6l...@ieee-sb1.cc.fer.hr...
>>>> On 2007-11-14, Chris Thomasson <cri...@comcast.net> wrote:
>>>>>
>>>>> If GCC performs the optimization that David Schwartz pointer out, your
>>>>> basically screwed. AFAICT, GCC is totally busted if it allows stores to
>>>>> escape a critical-section. This is a race-condition waiting to
>>>>> happen. I am
>>>>>
>>>> How is the compiler supposed to know where a CS begins and ends? should
>>>> it have a knowledge of every imaginable official and unofficial API?
>>>
>>> I was under the impression that POSIX puts some restrictions on
>>> compilers. Humm... I can't really remember where I heard that right now,
>>> but I sure think I did. Humm...
>> The point is that POSIX puts restrictions on the behavior of a
>> conforming system. That includes library, kernel, and compiler. If the
>> RESULT doesn't behave like POSIX, then it's not POSIX.
>>
>> A compiler that's part of a conforming POSIX system environment can't
>> generate code that breaks synchronization. How it and the rest of the
>> system accomplish that is unspecified.
>>
>> Often, it means simply not performing risky optimizations. But if they
>> are enabled, then the system needs to be able to detect and avoid
>> performing them in "dangerous" areas of code. (A complicated problem,
>> but nothing's impossible.)
>
> Basically, the optimization can only be performed when the value
> which controls the selection statement can be shown not to have
> been derived from the result of a pthread function, such that the value
> indicates whether the caller owns or does not own a lock.
>
> This is very difficult.
>
> Even a value scanned from a stream can be such a value:
>
> int result = pthred_mutex_trylock(...);
>
> FILE *f = fopen("foo.txt", "w");
> fprintf(f, "%d\n", result);
> fclose(f);
> system("mv foo.txt bar.txt");
>
> int x;
> FILE *g = fopen("bar.txt", "r");
> fscanf(g, "%d", &f);
> fclose(g);
>
> if (x == 0) {
> a++;
> }
>
> A better angle on it would be not to pursue the analysis of x at all,
> but concentrate on a. If the variable a isn't something that can be
> thread shared, then the optimization is okay.
>
> If a is a local variable whose address has never been taken (or
> else has never escaped from this scope), then it's should be
> to convert this to:
>
> int __inc = (x == 0);
> a += __inc;
>
> If a is something potentially shared, then no.
>
> Programs that want good optimization should concentrate on using
> automatic (not static) local variables as much as possible, in such a
> way that it's clear that those variables don't escape into other scopes.
> Those kinds of variables can be aggressively optimized, threads or not.
>
>

Fwiw, I created my own externally assembled sync primitives to try to
get around a "rogue" compiler from altering anything within them. Link
time optimizations could get at my code... Turn them off? Well, this was
some years ago.

Re: Effect of CPP tags

<uo7jh0$1rb6c$2@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!paganini.bofh.team!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: chris.m....@gmail.com (Chris M. Thomasson)
Newsgroups: comp.lang.c
Subject: Re: Effect of CPP tags
Date: Tue, 16 Jan 2024 20:02:39 -0800
Organization: A noiseless patient Spider
Lines: 33
Message-ID: <uo7jh0$1rb6c$2@dont-email.me>
References: <umet9d$3hir9$1@dont-email.me> <unkp1b$270v8$1@dont-email.me>
<ZSmnN.151217$c3Ea.70659@fx10.iad> <unkuhp$27i0v$2@dont-email.me>
<unlqqa$2eqts$2@dont-email.me> <U7ynN.143065$Wp_8.30410@fx17.iad>
<unmmnd$2jair$1@dont-email.me> <87edepnich.fsf@nosuchdomain.example.com>
<unmqsg$2jvva$1@dont-email.me> <unmu6b$2kh81$1@dont-email.me>
<20240110133135.834@kylheku.com> <unn65q$2lr2i$1@dont-email.me>
<20240110182957.444@kylheku.com> <unokb1$2vmkh$1@dont-email.me>
<20240111081109.274@kylheku.com> <unpd89$33jlu$1@dont-email.me>
<20240111133742.530@kylheku.com> <unpt44$35qn1$1@dont-email.me>
<unrfgs$3fo6l$1@dont-email.me> <unrocu$3h2ah$1@dont-email.me>
<20240112132216.285@kylheku.com> <uo0je6$e8fv$1@dont-email.me>
<20240114115640.506@kylheku.com> <uo24di$lo8r$1@dont-email.me>
<20240114222417.720@kylheku.com> <20240114231905.155@kylheku.com>
<uo3l28$1010j$1@dont-email.me> <uo3mhi$1073t$1@dont-email.me>
<uo44fg$12ct8$2@dont-email.me> <uo6023$1f4l9$2@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Wed, 17 Jan 2024 04:02:40 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="9d60b08ecf7f21a413a4c560ba63b788";
logging-data="1944780"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/zO5u6hT2WQWTnwgCb24tINdAvXsjKfbg="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:zMOs7w1SeXhIlwdF+QogJy8skLs=
In-Reply-To: <uo6023$1f4l9$2@dont-email.me>
Content-Language: en-US
 by: Chris M. Thomasson - Wed, 17 Jan 2024 04:02 UTC

On 1/16/2024 5:24 AM, David Brown wrote:
> On 15/01/2024 21:27, Chris M. Thomasson wrote:
>> On 1/15/2024 8:29 AM, David Brown wrote:
>>> On 15/01/2024 17:04, David Brown wrote:
>>>> On 15/01/2024 08:40, Kaz Kylheku wrote:
>>>
>>>>> A mul_add primitive might make sense if the processor had such a thing
>>>>> in one instruction.
>>>>>
>>>>> With GCC inline assembly, you want to only put the essentials into it:
>>>>> only do what is necessary and only bundle together what must be
>>>>> bundled.
>>>>>
>>>>
>>>> Yes.  For inline assembly, simple is not really important, but small
>>>> is beautiful!  Say exactly what you mean, no more and no less, and
>>>> let the compiler do what it does best.
>> [...]
>>
>> Wrt inline GCC assembly, remember __volatile__ and memory? ;^)
>>
>
> Yes, these are useful, and I use them - when appropriate.
>

Exactly. I could get inline asm to work with my sync code, but since I
disliked inline asm and MS dropped support for it for 64-bit targets
around the time, I felt _much_ safer to implement my sync code in
external assembly, trying to isolate them from the meat hooks of the
compiler.

Also, I would check the generated asm from any of my inline asm to make
sure it was correct. This was a pain in the ass.

Switch fallthrough considered harmful? (was Re: Effect of CPP tags)

<uo7mvp$1s1cr$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!usenet.goja.nl.eu.org!weretis.net!feeder8.news.weretis.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: janis_pa...@hotmail.com (Janis Papanagnou)
Newsgroups: comp.lang.c
Subject: Switch fallthrough considered harmful? (was Re: Effect of CPP tags)
Date: Wed, 17 Jan 2024 06:01:45 +0100
Organization: A noiseless patient Spider
Lines: 14
Message-ID: <uo7mvp$1s1cr$1@dont-email.me>
References: <umet9d$3hir9$1@dont-email.me> <unrocu$3h2ah$1@dont-email.me>
<unrpn1$3h8jl$1@dont-email.me> <unrro8$3hj71$1@dont-email.me>
<unruru$3i29g$1@dont-email.me> <uns9c6$3jis4$1@dont-email.me>
<20240112134536.695@kylheku.com> <unskit$3l154$1@dont-email.me>
<87zfxakqjd.fsf@nosuchdomain.example.com> <unso1g$3lb69$2@dont-email.me>
<20240112200241.728@kylheku.com> <untu7e$3u3nv$1@dont-email.me>
<87o7dolxkj.fsf@nosuchdomain.example.com> <unv3ec$48rm$1@dont-email.me>
<87jzoclss6.fsf@nosuchdomain.example.com> <86h6jfls0e.fsf@linuxsc.com>
<uo18fc$ht87$2@dont-email.me> <fYVoN.171150$c3Ea.139646@fx10.iad>
<uo1ec0$iquj$1@dont-email.me> <87o7dndln6.fsf@gmail.com>
<uo35hj$th5s$1@dont-email.me> <87h6jev9c6.fsf@gmail.com>
<uo3u9h$11i75$1@dont-email.me> <uo43r7$12f4m$1@dont-email.me>
<uo672q$1g9n5$2@dont-email.me> <uo68aq$1ge1j$3@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 17 Jan 2024 05:01:45 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="06e828e566a5b13877b773d3dbf6f7bf";
logging-data="1967515"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX189xQ++fcNhfyD6Gv6BO50l"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
Cancel-Lock: sha1:ZWylE+BDRxsH8HMfpmay2fcqrME=
In-Reply-To: <uo68aq$1ge1j$3@dont-email.me>
 by: Janis Papanagnou - Wed, 17 Jan 2024 05:01 UTC

On 16.01.2024 16:45, David Brown wrote:
>
> Default fallthrough switch behaviour is different in that it is
> potentially counter-productive and dangerous. As someone who uses good
> tools, and knows how to use them, it is not an issue for my own code -
> but it can be a source of error in other people's code.

It can also just be a useful code pattern, as in Duff's Device.

> I can imagine bugs in real, released code as a result of default
> fallthrough in switches. [...]

Janis

CPU's MAC instructions (was Re: Effect of CPP tags)

<uo7oce$1s7q3$1@dont-email.me>

  copy mid

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

  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!.POSTED!not-for-mail
From: janis_pa...@hotmail.com (Janis Papanagnou)
Newsgroups: comp.lang.c
Subject: CPU's MAC instructions (was Re: Effect of CPP tags)
Date: Wed, 17 Jan 2024 06:25:34 +0100
Organization: A noiseless patient Spider
Lines: 33
Message-ID: <uo7oce$1s7q3$1@dont-email.me>
References: <umet9d$3hir9$1@dont-email.me> <unpt44$35qn1$1@dont-email.me>
<unrfgs$3fo6l$1@dont-email.me> <unrocu$3h2ah$1@dont-email.me>
<20240112132216.285@kylheku.com> <uo0je6$e8fv$1@dont-email.me>
<20240114115640.506@kylheku.com> <uo24di$lo8r$1@dont-email.me>
<20240114222417.720@kylheku.com> <20240114231905.155@kylheku.com>
<uo3l28$1010j$1@dont-email.me> <uo3mhi$1073t$1@dont-email.me>
<uo5qp3$1dn2m$1@dont-email.me> <uo6143$1f9o7$2@dont-email.me>
<uo62ke$1fjel$1@dont-email.me> <ZHxpN.207475$PuZ9.131537@fx11.iad>
MIME-Version: 1.0
Content-Type: text/plain; charset=windows-1252
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 17 Jan 2024 05:25:34 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="6c05b96dd049916a493c20a1220bbe1b";
logging-data="1974083"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX187MrvsWaDwBKDXMHxcJhaS"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
Cancel-Lock: sha1:5VSMlA0KAtza5/MJ3tAtYMrUrwY=
X-Enigmail-Draft-Status: N1110
In-Reply-To: <ZHxpN.207475$PuZ9.131537@fx11.iad>
 by: Janis Papanagnou - Wed, 17 Jan 2024 05:25 UTC

On 16.01.2024 16:57, Scott Lurndal wrote:
> Janis Papanagnou <janis_papanagnou+ng@hotmail.com> writes:
>> On 16.01.2024 14:42, David Brown wrote:
>>> On 16/01/2024 12:54, bart wrote:
>>>>
>>>> Which processor is this for again?
>>>
>>> It's for a cpu with a "madd" instruction that implements "x = x + y * z"
>>> in a single instruction - as Kaz pointed out, doing this in inline
>>> assembly would make sense if it the cpu had such a dedicated
>>> instruction. [...]
>>
>> I recall such a feature from a 35+ years old assembler project I did.
>> It was on the TI TMS320C25 DSP, and the instruction was called 'MAC'
>> (Multiply and ACcumulate). - Not sure it clarifies anything but just
>> as an amendment if someone is interested in searching for keywords
>> on such a function.
>
> Pretty much every modern architecture has multiply and accumulate
> instructions, even the ARM Cortex-M7 cores (MLA instruction).

Yeah, I inferred that already from David's response. At these days,
though, I hadn't seen 'MAC' in the common standard CPUs. (And since
that time I didn't do any assembler any more, so I don't know the
contemporary architectures.)

It's maybe noteworthy that despite such advanced CPU functions I
didn't make use of them, despite I had functions like sum(x[i]*y[i])
to implement. The reason was that an algorithmic transformation,
an optimization, made use of that 1-cycle MAC an inferior solution!

Janis

Optimization and inline assembly (was Re: Effect of CPP tags)

<uo7qro$1sj6e$1@dont-email.me>

  copy mid

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

  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!.POSTED!not-for-mail
From: janis_pa...@hotmail.com (Janis Papanagnou)
Newsgroups: comp.lang.c
Subject: Optimization and inline assembly (was Re: Effect of CPP tags)
Date: Wed, 17 Jan 2024 07:07:51 +0100
Organization: A noiseless patient Spider
Lines: 26
Message-ID: <uo7qro$1sj6e$1@dont-email.me>
References: <umet9d$3hir9$1@dont-email.me> <unkhql$25uof$1@dont-email.me>
<unkkp3$26g9o$1@dont-email.me> <87ttnmnjdb.fsf@nosuchdomain.example.com>
<unkp1b$270v8$1@dont-email.me> <ZSmnN.151217$c3Ea.70659@fx10.iad>
<unkuhp$27i0v$2@dont-email.me> <unlqqa$2eqts$2@dont-email.me>
<U7ynN.143065$Wp_8.30410@fx17.iad> <unmmnd$2jair$1@dont-email.me>
<87edepnich.fsf@nosuchdomain.example.com> <unmqsg$2jvva$1@dont-email.me>
<unmu6b$2kh81$1@dont-email.me> <20240110133135.834@kylheku.com>
<unn65q$2lr2i$1@dont-email.me> <20240110182957.444@kylheku.com>
<unokb1$2vmkh$1@dont-email.me> <20240111081109.274@kylheku.com>
<unpd89$33jlu$1@dont-email.me> <20240111133742.530@kylheku.com>
<unpt44$35qn1$1@dont-email.me> <unrfgs$3fo6l$1@dont-email.me>
<unrocu$3h2ah$1@dont-email.me> <20240112132216.285@kylheku.com>
<uo0je6$e8fv$1@dont-email.me> <20240114115640.506@kylheku.com>
<uo24di$lo8r$1@dont-email.me> <uo3ilc$vjmt$1@dont-email.me>
<uo66i4$1g9n5$1@dont-email.me> <uo6fe3$1i0eu$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 17 Jan 2024 06:07:52 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="6c05b96dd049916a493c20a1220bbe1b";
logging-data="1985742"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+1vj6OsGFIAZyw9XGACnMR"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
Cancel-Lock: sha1:pACo+qxBHmKgbkZArsdBGIdKrDo=
X-Enigmail-Draft-Status: N1110
In-Reply-To: <uo6fe3$1i0eu$1@dont-email.me>
 by: Janis Papanagnou - Wed, 17 Jan 2024 06:07 UTC

On 16.01.2024 18:46, David Brown wrote:
> On 16/01/2024 16:15, bart wrote:
>>
>> The need for assembly usually trumps whatever minor optimisation my
>> compiler might do.

The good thing is that compilers do also major optimizations.
(And the minor ones come for free.)

But the most important insight is that tackling complexity
algorithmically is what is most contributing for speed.

(This may be different for folks fiddling only on assembler
level, where _separate_ assembler projects serve better.
It's IMO more sensible for time critical stuff to just use
an assembler for such functions and embed them by a clean
function interface in any HLL than to inline assembler code.
YMMV.)

>
> Ah, there we differ. I use tools that do good optimisations. And
> perhaps 70% of the use-cases of inline assembly will be lost if the tool
> can't generate efficient code when there is inline assembly.

Janis

NO vs. SE (was Re: Effect of CPP tags)

<uo7r3e$1skfj$1@dont-email.me>

  copy mid

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

  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: janis_pa...@hotmail.com (Janis Papanagnou)
Newsgroups: comp.lang.c
Subject: NO vs. SE (was Re: Effect of CPP tags)
Date: Wed, 17 Jan 2024 07:11:58 +0100
Organization: A noiseless patient Spider
Lines: 8
Message-ID: <uo7r3e$1skfj$1@dont-email.me>
References: <umet9d$3hir9$1@dont-email.me> <unpd89$33jlu$1@dont-email.me>
<20240111133742.530@kylheku.com> <unpt44$35qn1$1@dont-email.me>
<unrfgs$3fo6l$1@dont-email.me> <unrocu$3h2ah$1@dont-email.me>
<20240112132216.285@kylheku.com> <uo0je6$e8fv$1@dont-email.me>
<20240114115640.506@kylheku.com> <uo24di$lo8r$1@dont-email.me>
<uo3ilc$vjmt$1@dont-email.me> <YYdpN.177805$c3Ea.78753@fx10.iad>
<uo44ch$12fes$1@dont-email.me> <SLgpN.41334$5Hnd.11118@fx03.iad>
<uo62le$1finu$2@dont-email.me> <xMxpN.207476$PuZ9.33416@fx11.iad>
<uo6gcp$1i5rh$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 17 Jan 2024 06:11:58 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="6c05b96dd049916a493c20a1220bbe1b";
logging-data="1987059"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+fyr3xVLOZ4slsVZ4ifcvs"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
Cancel-Lock: sha1:7GEZdNcJPDnL2cOL7jp/fkxwcpA=
In-Reply-To: <uo6gcp$1i5rh$1@dont-email.me>
 by: Janis Papanagnou - Wed, 17 Jan 2024 06:11 UTC

On 16.01.2024 19:03, David Brown wrote:
>
> [...], because they know that Norwegians are superior to Swedes in every way...

I just wanted to reply on that but then I saw your email address... :-)

Janis

Re: Effect of CPP tags

<uo7rlp$1sl5o$1@dont-email.me>

  copy mid

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

  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!.POSTED!not-for-mail
From: chris.m....@gmail.com (Chris M. Thomasson)
Newsgroups: comp.lang.c
Subject: Re: Effect of CPP tags
Date: Tue, 16 Jan 2024 22:21:44 -0800
Organization: A noiseless patient Spider
Lines: 8
Message-ID: <uo7rlp$1sl5o$1@dont-email.me>
References: <umet9d$3hir9$1@dont-email.me> <umlba2$iq0h$3@dont-email.me>
<ummhnp$rf7k$1@dont-email.me>
<pan$750c8$285261e$b7c42f65$7a0431b1@invalid.invalid>
<umq4ra$1dt87$1@dont-email.me> <umq8lh$1eaq0$2@dont-email.me>
<umqfag$1f4km$1@dont-email.me> <umqgf3$1f5qb$1@dont-email.me>
<umqj1h$1fg32$1@dont-email.me> <umsufv$1snq9$2@dont-email.me>
<umt4pk$1tg5p$1@dont-email.me> <umt6b8$1tk9o$1@dont-email.me>
<umu98h$26t0e$1@dont-email.me> <umvbc4$2b9bl$3@dont-email.me>
<umvfm8$2c0ho$1@dont-email.me> <umvgod$2c2sp$3@dont-email.me>
<umviqe$2ccb3$1@dont-email.me> <umvk15$2cdin$1@dont-email.me>
<umvo18$2cucc$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 17 Jan 2024 06:21:45 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="9d60b08ecf7f21a413a4c560ba63b788";
logging-data="1987768"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX182RzmebG1xmilL+UyCrxJsgRcbpCZGH78="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:fpdZjxAFR3tbspYB9uKeJY2ANpw=
Content-Language: en-US
In-Reply-To: <umvo18$2cucc$1@dont-email.me>
 by: Chris M. Thomasson - Wed, 17 Jan 2024 06:21 UTC

On 1/1/2024 5:14 PM, Bart wrote:
[...]

If you have a recent version of MSVC installed, give vcpkg a go. It has
a lot of packages that will be automagically build and integrated into MSVC:

https://vcpkg.io/en/packages

Re: Switch fallthrough considered harmful? (was Re: Effect of CPP tags)

<uo8b37$1v1eq$4@dont-email.me>

  copy mid

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

  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!.POSTED!not-for-mail
From: david.br...@hesbynett.no (David Brown)
Newsgroups: comp.lang.c
Subject: Re: Switch fallthrough considered harmful? (was Re: Effect of CPP
tags)
Date: Wed, 17 Jan 2024 11:44:55 +0100
Organization: A noiseless patient Spider
Lines: 28
Message-ID: <uo8b37$1v1eq$4@dont-email.me>
References: <umet9d$3hir9$1@dont-email.me> <unrocu$3h2ah$1@dont-email.me>
<unrpn1$3h8jl$1@dont-email.me> <unrro8$3hj71$1@dont-email.me>
<unruru$3i29g$1@dont-email.me> <uns9c6$3jis4$1@dont-email.me>
<20240112134536.695@kylheku.com> <unskit$3l154$1@dont-email.me>
<87zfxakqjd.fsf@nosuchdomain.example.com> <unso1g$3lb69$2@dont-email.me>
<20240112200241.728@kylheku.com> <untu7e$3u3nv$1@dont-email.me>
<87o7dolxkj.fsf@nosuchdomain.example.com> <unv3ec$48rm$1@dont-email.me>
<87jzoclss6.fsf@nosuchdomain.example.com> <86h6jfls0e.fsf@linuxsc.com>
<uo18fc$ht87$2@dont-email.me> <fYVoN.171150$c3Ea.139646@fx10.iad>
<uo1ec0$iquj$1@dont-email.me> <87o7dndln6.fsf@gmail.com>
<uo35hj$th5s$1@dont-email.me> <87h6jev9c6.fsf@gmail.com>
<uo3u9h$11i75$1@dont-email.me> <uo43r7$12f4m$1@dont-email.me>
<uo672q$1g9n5$2@dont-email.me> <uo68aq$1ge1j$3@dont-email.me>
<uo7mvp$1s1cr$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 17 Jan 2024 10:44:55 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="e5d003c4907c1c313df779ab33f575b8";
logging-data="2065882"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+BU1hVpRTS0YFXmUmB8z50IUqzoi6v/QU="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.11.0
Cancel-Lock: sha1:FX6Rw3+zwBkF6r/ILXm6HtaVhI0=
In-Reply-To: <uo7mvp$1s1cr$1@dont-email.me>
Content-Language: en-GB
 by: David Brown - Wed, 17 Jan 2024 10:44 UTC

On 17/01/2024 06:01, Janis Papanagnou wrote:
> On 16.01.2024 16:45, David Brown wrote:
>>
>> Default fallthrough switch behaviour is different in that it is
>> potentially counter-productive and dangerous. As someone who uses good
>> tools, and knows how to use them, it is not an issue for my own code -
>> but it can be a source of error in other people's code.
>
> It can also just be a useful code pattern, as in Duff's Device.
>

No.

Fallthrough switch behaviour can be useful (and not in the monstrosity
that is Duff's Device, but mostly when you have multiple switch cases
that are handled by the same code).

/Default/ fallthrough switch behaviour is not good.

If you want fallthrough, label it with "[[fallthrough]]", or a comment
or other technique recognised by your tools and by your fellow programmers.

>> I can imagine bugs in real, released code as a result of default
>> fallthrough in switches. [...]
>
> Janis
>

Re: Effect of CPP tags

<uo8cuc$1vhf8$1@dont-email.me>

  copy mid

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

  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!.POSTED!not-for-mail
From: bc...@freeuk.com (bart)
Newsgroups: comp.lang.c
Subject: Re: Effect of CPP tags
Date: Wed, 17 Jan 2024 11:16:28 +0000
Organization: A noiseless patient Spider
Lines: 47
Message-ID: <uo8cuc$1vhf8$1@dont-email.me>
References: <umet9d$3hir9$1@dont-email.me> <unmmnd$2jair$1@dont-email.me>
<87edepnich.fsf@nosuchdomain.example.com> <unmqsg$2jvva$1@dont-email.me>
<unmu6b$2kh81$1@dont-email.me> <20240110133135.834@kylheku.com>
<unn65q$2lr2i$1@dont-email.me> <20240110182957.444@kylheku.com>
<unokb1$2vmkh$1@dont-email.me> <20240111081109.274@kylheku.com>
<unpd89$33jlu$1@dont-email.me> <20240111133742.530@kylheku.com>
<unpt44$35qn1$1@dont-email.me> <unrfgs$3fo6l$1@dont-email.me>
<unrocu$3h2ah$1@dont-email.me> <65eoN.26119$9cLc.94@fx02.iad>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 17 Jan 2024 11:16:28 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="6268282b8239d0a8c360e6001c42a605";
logging-data="2082280"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/ESyIXNkOsBhQjzgk/XCAsBp1MK3uZohg="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:ANRdsJkfxweGo8KWwQUbcc8r2WE=
Content-Language: en-GB
In-Reply-To: <65eoN.26119$9cLc.94@fx02.iad>
 by: bart - Wed, 17 Jan 2024 11:16 UTC

On 12/01/2024 16:50, Scott Lurndal wrote:
> bart <bc@freeuk.com> writes:
>> On 12/01/2024 13:40, David Brown wrote:
>>> On 12/01/2024 00:20, bart wrote:
>>
>> But with 'as', it just sits there. I wonder what it's waiting for; for
>> me to type in ASM code live from the terminal?
>
> It does that so you can pipe the assembler source code in to the
> assembler.
>
> $ cat file.s | as
>
> $ cat file.c | cpp | c0 | c1 | c2 | as > file.o
>
> or, if you want, you can type in the assembler source directly.
>
> Or you can save it in a file and supply the file argument to the command.
>
> None of which your stuff supports, which makes it useless to me.

I had a spare 15 minutes so I got my scripting language to do this:

csource:=(
"#include <stdio.h>",
"int main(void) {",
" puts(""Fahrenheit 451"");",
"}")

csource -> mcc -> aa -> run

'mcc' turns a source string (or a list of strings as here) into a string
containing assembly code.

'aa' turns an assembly string into a string containing binary PE data.

'run' runs that PE data. Output is:

Fahrenheit 451

Those 3 functions are 40-50 lines. Here's another invocation:

readstrfile("/c/hello.c") -> mcc -> aa -> run

A shell seems to be a poor man's scripting language.

Re: Switch fallthrough considered harmful? (was Re: Effect of CPP tags)

<uo8d8e$1vj8l$1@dont-email.me>

  copy mid

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

  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!.POSTED!not-for-mail
From: janis_pa...@hotmail.com (Janis Papanagnou)
Newsgroups: comp.lang.c
Subject: Re: Switch fallthrough considered harmful? (was Re: Effect of CPP
tags)
Date: Wed, 17 Jan 2024 12:21:50 +0100
Organization: A noiseless patient Spider
Lines: 61
Message-ID: <uo8d8e$1vj8l$1@dont-email.me>
References: <umet9d$3hir9$1@dont-email.me> <unrocu$3h2ah$1@dont-email.me>
<unrpn1$3h8jl$1@dont-email.me> <unrro8$3hj71$1@dont-email.me>
<unruru$3i29g$1@dont-email.me> <uns9c6$3jis4$1@dont-email.me>
<20240112134536.695@kylheku.com> <unskit$3l154$1@dont-email.me>
<87zfxakqjd.fsf@nosuchdomain.example.com> <unso1g$3lb69$2@dont-email.me>
<20240112200241.728@kylheku.com> <untu7e$3u3nv$1@dont-email.me>
<87o7dolxkj.fsf@nosuchdomain.example.com> <unv3ec$48rm$1@dont-email.me>
<87jzoclss6.fsf@nosuchdomain.example.com> <86h6jfls0e.fsf@linuxsc.com>
<uo18fc$ht87$2@dont-email.me> <fYVoN.171150$c3Ea.139646@fx10.iad>
<uo1ec0$iquj$1@dont-email.me> <87o7dndln6.fsf@gmail.com>
<uo35hj$th5s$1@dont-email.me> <87h6jev9c6.fsf@gmail.com>
<uo3u9h$11i75$1@dont-email.me> <uo43r7$12f4m$1@dont-email.me>
<uo672q$1g9n5$2@dont-email.me> <uo68aq$1ge1j$3@dont-email.me>
<uo7mvp$1s1cr$1@dont-email.me> <uo8b37$1v1eq$4@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 17 Jan 2024 11:21:50 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="06e828e566a5b13877b773d3dbf6f7bf";
logging-data="2084117"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19uiNbQbvYygettUBZaplOL"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
Cancel-Lock: sha1:JmFd1bGc9K7D8vU9JMbz2Cts1K0=
In-Reply-To: <uo8b37$1v1eq$4@dont-email.me>
X-Enigmail-Draft-Status: N1110
 by: Janis Papanagnou - Wed, 17 Jan 2024 11:21 UTC

On 17.01.2024 11:44, David Brown wrote:
> On 17/01/2024 06:01, Janis Papanagnou wrote:
>> On 16.01.2024 16:45, David Brown wrote:
>>>
>>> Default fallthrough switch behaviour is different in that it is
>>> potentially counter-productive and dangerous. As someone who uses good
>>> tools, and knows how to use them, it is not an issue for my own code -
>>> but it can be a source of error in other people's code.
>>
>> It can also just be a useful code pattern, as in Duff's Device.
>>
>
> No.
>
> Fallthrough switch behaviour can be useful (and not in the monstrosity
> that is Duff's Device, but mostly when you have multiple switch cases
> that are handled by the same code).

I don't think that multiple case-labels are the interesting part;
they are just a bulky syntactic way to collect items - compare
that [syntactically] with case statements in other languages (e.g.
in Pascal). In many (most? all?) C based language, OTOH, you have
to identify every single value by a 'case' keyword, and you also
_have_ to use an explicit 'break' to not "fall through". The fall
through logic is interesting (sort of) if you want to "re-use"
code from other case labels. - Not that this feature would make
any program easier to maintain. (I would avoid that.)

The use of "code patterns" (like the mentioned Duff's Device) is
often an indication to support features that the language doesn't
natively support; I see them often (for example) in Awk. It's not
something I would strive for in cleanly written software. But it's
usable as an idiomatic expression for a subset of (specific) tasks.
YMMV.

>
> /Default/ fallthrough switch behaviour is not good.

But this is the case with C-based languages; we have to accept it,
and, again _idiomatically_, write an explicit 'break' after every
'case' statement sequence.

(But we're here in a C newsgroup and complaints make no sense.)

>
> If you want fallthrough, label it with "[[fallthrough]]", or a comment
> or other technique recognised by your tools and by your fellow programmers.

This is indeed what I do on these rare conditions where I use it.

In other languages it's even more hidden (than a missing 'break');
Kornshell for example uses ;; for a "break" logic and ;& for the
(fall-through) "continue" logic in its 'case' statements. (And
'break [N]' and 'continue [N]' have another logical context (used
only in loops).

>>> I can imagine bugs in real, released code as a result of default
>>> fallthrough in switches. [...]

Janis

Re: Effect of CPP tags

<uo8ece$1vpg1$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!rocksolid2!news.neodome.net!weretis.net!feeder8.news.weretis.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: Effect of CPP tags
Date: Wed, 17 Jan 2024 12:41:01 +0100
Organization: A noiseless patient Spider
Lines: 46
Message-ID: <uo8ece$1vpg1$1@dont-email.me>
References: <umet9d$3hir9$1@dont-email.me> <20240110133135.834@kylheku.com>
<unn65q$2lr2i$1@dont-email.me> <20240110182957.444@kylheku.com>
<unokb1$2vmkh$1@dont-email.me> <20240111081109.274@kylheku.com>
<unpd89$33jlu$1@dont-email.me> <20240111133742.530@kylheku.com>
<unpt44$35qn1$1@dont-email.me> <unrfgs$3fo6l$1@dont-email.me>
<unrocu$3h2ah$1@dont-email.me> <unrpn1$3h8jl$1@dont-email.me>
<unrro8$3hj71$1@dont-email.me> <uo35sv$tj3v$1@dont-email.me>
<uo6mb8$1j9er$1@dont-email.me> <loBpN.26873$SyNd.13811@fx33.iad>
<uo6r43$1k29c$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Wed, 17 Jan 2024 11:41:02 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="e5d003c4907c1c313df779ab33f575b8";
logging-data="2090497"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19siQa8sBP8rrGQyK5CM0c/oK0CNRgSilU="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.11.0
Cancel-Lock: sha1:Esls+kk1fYs9TMOLpo3zE+Vmzak=
In-Reply-To: <uo6r43$1k29c$1@dont-email.me>
Content-Language: en-GB
 by: David Brown - Wed, 17 Jan 2024 11:41 UTC

On 16/01/2024 22:06, bart wrote:
> On 16/01/2024 20:09, Scott Lurndal wrote:
>> bart <bc@freeuk.com> writes:
>>> On 15/01/2024 11:45, David Brown wrote:
>>>> On 12/01/2024 18:09, bart wrote:
>>
>>> (BTW that keyboard was a joy to use: it used a simple 8-bit port, with
>>> the top bit strobing when a key was ready. Compare with what's involved
>>> with using a USB keyboard today, if you didn't have a 10GB OS to take
>>> care of it.)
>>
>> If you ignore,  of course, the fact that a 64KB BIOS can easily handle
>> the entire USB stack sufficient to support both USB mass storage
>> devices, networking devices (PXE) and USB Human Interface Devices
>> (keyboards, mice).
>>
>> No 10GB OS involvement.
>>
>
> It seemed to take quite a few years before the early Linuxes I played
> around with 25+ years ago managed to support USB, among other things.

At that time, device support on Linux was very limited. But it took
off, and since perhaps 15 years ago it is rarely an issue in practice.
Out of the box support is certainly a world ahead of Windows, and new
buses (such as new USB speeds) are always supported first on Linux.

The last time I had trouble with USB and keyboards was something like 5
or 6 years ago - with Windows. It was a Dell server, where all the USB
ports were USB 3. The keyboard and mice were fine in the BIOS and Dell
setup stuff, but partway through the Windows Server installation,
Windows wanted to move to its own system and drivers - and did not have
USB 3 support out the box. It was an utterly absurd situation where the
installation process needed an extra drivers disk from Dell just to get
the keyboard working, even though it worked fine in the first part of
the installation. (And needless to say, Linux had no issues with it.)

>
> So it's only easy if you know how. Reading the current key on the Z80
> (already in ASCII) was one IN instruction.

Making support for USB keyboards (either as host or device) on modern
microcontrollers isn't bad, assuming you have basic USB libraries for
your device. It's certainly much more involved than it used to be - but
it is also more flexible.

Re: Effect of CPP tags

<uo8h5i$20910$1@dont-email.me>

  copy mid

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

  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!.POSTED!not-for-mail
From: david.br...@hesbynett.no (David Brown)
Newsgroups: comp.lang.c
Subject: Re: Effect of CPP tags
Date: Wed, 17 Jan 2024 13:28:33 +0100
Organization: A noiseless patient Spider
Lines: 64
Message-ID: <uo8h5i$20910$1@dont-email.me>
References: <umet9d$3hir9$1@dont-email.me> <unlqqa$2eqts$2@dont-email.me>
<U7ynN.143065$Wp_8.30410@fx17.iad> <unmmnd$2jair$1@dont-email.me>
<87edepnich.fsf@nosuchdomain.example.com> <unmqsg$2jvva$1@dont-email.me>
<unmu6b$2kh81$1@dont-email.me> <20240110133135.834@kylheku.com>
<unn65q$2lr2i$1@dont-email.me> <20240110182957.444@kylheku.com>
<unokb1$2vmkh$1@dont-email.me> <20240111081109.274@kylheku.com>
<unpd89$33jlu$1@dont-email.me> <20240111133742.530@kylheku.com>
<unpt44$35qn1$1@dont-email.me> <unrfgs$3fo6l$1@dont-email.me>
<unrocu$3h2ah$1@dont-email.me> <20240112132216.285@kylheku.com>
<uo0je6$e8fv$1@dont-email.me> <20240114115640.506@kylheku.com>
<uo24di$lo8r$1@dont-email.me> <20240114222417.720@kylheku.com>
<20240114231905.155@kylheku.com> <uo3l28$1010j$1@dont-email.me>
<uo3mhi$1073t$1@dont-email.me> <uo44fg$12ct8$2@dont-email.me>
<20240115152033.334@kylheku.com> <uo4p1q$15bb0$1@dont-email.me>
<uo60su$1f9o7$1@dont-email.me> <uo79at$1lvso$3@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Wed, 17 Jan 2024 12:28:34 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="e5d003c4907c1c313df779ab33f575b8";
logging-data="2106400"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/oTl5thLMK9uVkubJ78mD/48wULy00iJ0="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.11.0
Cancel-Lock: sha1:o9e7tlCiG98Mjv205I0AHBf28Zg=
In-Reply-To: <uo79at$1lvso$3@dont-email.me>
Content-Language: en-GB
 by: David Brown - Wed, 17 Jan 2024 12:28 UTC

On 17/01/2024 02:08, Chris M. Thomasson wrote:
> On 1/16/2024 5:38 AM, David Brown wrote:
>> On 16/01/2024 03:18, Chris M. Thomasson wrote:
>>> On 1/15/2024 3:24 PM, Kaz Kylheku wrote:
>>>> On 2024-01-15, Chris M. Thomasson <chris.m.thomasson.1@gmail.com>
>>>> wrote:
>>>>> On 1/15/2024 8:29 AM, David Brown wrote:
>>>>>> On 15/01/2024 17:04, David Brown wrote:
>>>>>>> On 15/01/2024 08:40, Kaz Kylheku wrote:
> [...]
>> You've mentioned this many times - do you have a reference that gives
>> the source of this function (at the time when there was an issue), and
>> a description or report of what you think gcc did wrong?  I am curious
>> as to whether it was a bug in the code or a bug in gcc (gcc is
>> certainly not bug-free).
>>
>
> I think I found it David!
>
> https://groups.google.com/g/comp.programming.threads/c/Y_Y2DZOWErM/m/nuyEoKq0onUJ
>

Looking at the start of that thread:

int trylock()
{ int res;
res = pthread_mutex_trylock(&mutex);
if (res == 0)
++acquires_count;
return res;
}

It is perfectly reasonable for a pre-C11 C compiler to change that to:

int trylock()
{ int res;
res = pthread_mutex_trylock(&mutex);
int x = acquires_count;
if (res == 0)
++x;
acquires_count = x;
return res;
}

That's the way C was defined, prior to C11 support for multithreading
environments. The compiler could assume that it alone had full control
over all data, unless it was defined as volatile. So to make this code
"correct" (according to the user's hopes) in pre-C11, "acquires_count"
must be volatile.

C11 disabled such optimisations, because they could introduce data races
that did not exist before. But C11 was not around at that time. So
having this optimisation was not a gcc bug - unless POSIX precluded such
optimisations and gcc was used in a POSIX-compatibility mode. (I don't
know the details of POSIX requirements.)

Re: Effect of CPP tags

<uo8i1h$20dpf$1@dont-email.me>

  copy mid

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

  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!.POSTED!not-for-mail
From: david.br...@hesbynett.no (David Brown)
Newsgroups: comp.lang.c
Subject: Re: Effect of CPP tags
Date: Wed, 17 Jan 2024 13:43:29 +0100
Organization: A noiseless patient Spider
Lines: 42
Message-ID: <uo8i1h$20dpf$1@dont-email.me>
References: <umet9d$3hir9$1@dont-email.me> <20240111081109.274@kylheku.com>
<unpd89$33jlu$1@dont-email.me> <20240111133742.530@kylheku.com>
<unpt44$35qn1$1@dont-email.me> <unrfgs$3fo6l$1@dont-email.me>
<unrocu$3h2ah$1@dont-email.me> <20240112132216.285@kylheku.com>
<uo0je6$e8fv$1@dont-email.me> <20240114115640.506@kylheku.com>
<uo24di$lo8r$1@dont-email.me> <20240114222417.720@kylheku.com>
<uo3eli$uv97$1@dont-email.me> <6pbpN.200172$7sbb.118143@fx16.iad>
<uo3jth$vqg9$1@dont-email.me> <B1epN.177806$c3Ea.53953@fx10.iad>
<uo3v2u$11mbu$1@dont-email.me> <20240115152928.267@kylheku.com>
<uo5pdi$1dgnv$1@dont-email.me> <uo62gj$1finu$1@dont-email.me>
<uo793d$1lvso$2@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Wed, 17 Jan 2024 12:43:29 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="e5d003c4907c1c313df779ab33f575b8";
logging-data="2111279"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+oRaXtb7h+fwHApY4kN9mDx9qAX/mC9fQ="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.11.0
Cancel-Lock: sha1:OuJN1sN+4NLrxhVxuhqSHUME6Pg=
In-Reply-To: <uo793d$1lvso$2@dont-email.me>
Content-Language: en-GB
 by: David Brown - Wed, 17 Jan 2024 12:43 UTC

On 17/01/2024 02:04, Chris M. Thomasson wrote:
> On 1/16/2024 6:06 AM, David Brown wrote:

>> Well, you don't often write inline assembly - its rare to write it.
>> It's typically the kind of thing you write once for your particular
>> instruction, then stick it away in a header somewhere.  You might use
>> it often, but you don't need to read or edit the code often.[...]
>
> As soon as you use inline assembler in a file, you sort of "need" to?

Nonsense.

How often do you use headers from the standard library, or third party
libraries, or other code? All the time, I'd assume. How often do you
read through these headers? Very rarely. How often do you edit them?
Never.

You do not need to read code of any kind, in order to use it.

Some kinds of code can be considered advanced, or ugly, or hard to
comprehend. inline assembly often falls into that category, as do
complicated macros, and some of the more cryptic corners of C++. That
code should be written by someone who knows what they are doing, tested
well, the interface described, and then the code is hidden away. Most
other people using the code never see it, and might not understand it
even if they did.

It is entirely reasonable to structure your headers like this:

// Return x + (y * z)
static inline int madd(int x, int y, int z);

...

// Implementation details
static inline int madd(int x, int y, int z) {
asm (...

Re: Switch fallthrough considered harmful? (was Re: Effect of CPP tags)

<uo8jki$20hg6$2@dont-email.me>

  copy mid

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

  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!.POSTED!not-for-mail
From: david.br...@hesbynett.no (David Brown)
Newsgroups: comp.lang.c
Subject: Re: Switch fallthrough considered harmful? (was Re: Effect of CPP
tags)
Date: Wed, 17 Jan 2024 14:10:42 +0100
Organization: A noiseless patient Spider
Lines: 76
Message-ID: <uo8jki$20hg6$2@dont-email.me>
References: <umet9d$3hir9$1@dont-email.me> <unrocu$3h2ah$1@dont-email.me>
<unrpn1$3h8jl$1@dont-email.me> <unrro8$3hj71$1@dont-email.me>
<unruru$3i29g$1@dont-email.me> <uns9c6$3jis4$1@dont-email.me>
<20240112134536.695@kylheku.com> <unskit$3l154$1@dont-email.me>
<87zfxakqjd.fsf@nosuchdomain.example.com> <unso1g$3lb69$2@dont-email.me>
<20240112200241.728@kylheku.com> <untu7e$3u3nv$1@dont-email.me>
<87o7dolxkj.fsf@nosuchdomain.example.com> <unv3ec$48rm$1@dont-email.me>
<87jzoclss6.fsf@nosuchdomain.example.com> <86h6jfls0e.fsf@linuxsc.com>
<uo18fc$ht87$2@dont-email.me> <fYVoN.171150$c3Ea.139646@fx10.iad>
<uo1ec0$iquj$1@dont-email.me> <87o7dndln6.fsf@gmail.com>
<uo35hj$th5s$1@dont-email.me> <87h6jev9c6.fsf@gmail.com>
<uo3u9h$11i75$1@dont-email.me> <uo43r7$12f4m$1@dont-email.me>
<uo672q$1g9n5$2@dont-email.me> <uo68aq$1ge1j$3@dont-email.me>
<uo7mvp$1s1cr$1@dont-email.me> <uo8b37$1v1eq$4@dont-email.me>
<uo8d8e$1vj8l$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 17 Jan 2024 13:10:42 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="e5d003c4907c1c313df779ab33f575b8";
logging-data="2115078"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18vFqJZjEh4/VI9ULL9oszCeJlSP32Lboo="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.11.0
Cancel-Lock: sha1:MT3bQiUcZSKAxPG8VQX+2efcGAE=
Content-Language: en-GB
In-Reply-To: <uo8d8e$1vj8l$1@dont-email.me>
 by: David Brown - Wed, 17 Jan 2024 13:10 UTC

On 17/01/2024 12:21, Janis Papanagnou wrote:
> On 17.01.2024 11:44, David Brown wrote:
>> On 17/01/2024 06:01, Janis Papanagnou wrote:
>>> On 16.01.2024 16:45, David Brown wrote:
>>>>
>>>> Default fallthrough switch behaviour is different in that it is
>>>> potentially counter-productive and dangerous. As someone who uses good
>>>> tools, and knows how to use them, it is not an issue for my own code -
>>>> but it can be a source of error in other people's code.
>>>
>>> It can also just be a useful code pattern, as in Duff's Device.
>>>
>>
>> No.
>>
>> Fallthrough switch behaviour can be useful (and not in the monstrosity
>> that is Duff's Device, but mostly when you have multiple switch cases
>> that are handled by the same code).
>
> I don't think that multiple case-labels are the interesting part;
> they are just a bulky syntactic way to collect items - compare
> that [syntactically] with case statements in other languages (e.g.
> in Pascal). In many (most? all?) C based language, OTOH, you have
> to identify every single value by a 'case' keyword, and you also
> _have_ to use an explicit 'break' to not "fall through". The fall
> through logic is interesting (sort of) if you want to "re-use"
> code from other case labels. - Not that this feature would make
> any program easier to maintain. (I would avoid that.)
>
> The use of "code patterns" (like the mentioned Duff's Device) is
> often an indication to support features that the language doesn't
> natively support; I see them often (for example) in Awk. It's not
> something I would strive for in cleanly written software. But it's
> usable as an idiomatic expression for a subset of (specific) tasks.
> YMMV.

Of course different people have different styles and needs. For my own
use, I vastly prefer to write the code as cleanly as possible and let
the optimiser generate code roughly like Duff's Device if that's the
most efficient. But other people have other requirements and preferences.

>
>>
>> /Default/ fallthrough switch behaviour is not good.
>
> But this is the case with C-based languages; we have to accept it,
> and, again _idiomatically_, write an explicit 'break' after every
> 'case' statement sequence.
>

I accept it, but dislike it and make sure my tools will warn me if there
is unintentional default fallthrough.

> (But we're here in a C newsgroup and complaints make no sense.)
>

Hey - without complaints, this newsgroup would be almost empty :-)

>>
>> If you want fallthrough, label it with "[[fallthrough]]", or a comment
>> or other technique recognised by your tools and by your fellow programmers.
>
> This is indeed what I do on these rare conditions where I use it.
>
> In other languages it's even more hidden (than a missing 'break');
> Kornshell for example uses ;; for a "break" logic and ;& for the
> (fall-through) "continue" logic in its 'case' statements. (And
> 'break [N]' and 'continue [N]' have another logical context (used
> only in loops).
>
>>>> I can imagine bugs in real, released code as a result of default
>>>> fallthrough in switches. [...]
>
> Janis
>

Re: NO vs. SE (was Re: Effect of CPP tags)

<uo8k11$20hg6$3@dont-email.me>

  copy mid

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

  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!.POSTED!not-for-mail
From: david.br...@hesbynett.no (David Brown)
Newsgroups: comp.lang.c
Subject: Re: NO vs. SE (was Re: Effect of CPP tags)
Date: Wed, 17 Jan 2024 14:17:21 +0100
Organization: A noiseless patient Spider
Lines: 18
Message-ID: <uo8k11$20hg6$3@dont-email.me>
References: <umet9d$3hir9$1@dont-email.me> <unpd89$33jlu$1@dont-email.me>
<20240111133742.530@kylheku.com> <unpt44$35qn1$1@dont-email.me>
<unrfgs$3fo6l$1@dont-email.me> <unrocu$3h2ah$1@dont-email.me>
<20240112132216.285@kylheku.com> <uo0je6$e8fv$1@dont-email.me>
<20240114115640.506@kylheku.com> <uo24di$lo8r$1@dont-email.me>
<uo3ilc$vjmt$1@dont-email.me> <YYdpN.177805$c3Ea.78753@fx10.iad>
<uo44ch$12fes$1@dont-email.me> <SLgpN.41334$5Hnd.11118@fx03.iad>
<uo62le$1finu$2@dont-email.me> <xMxpN.207476$PuZ9.33416@fx11.iad>
<uo6gcp$1i5rh$1@dont-email.me> <uo7r3e$1skfj$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 17 Jan 2024 13:17:21 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="e5d003c4907c1c313df779ab33f575b8";
logging-data="2115078"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+looQq4tJrgkDf84Azm0A/Mtmay+aFTcQ="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.11.0
Cancel-Lock: sha1:UyU05jmfBgngd4UTvtUTtZVTsTM=
In-Reply-To: <uo7r3e$1skfj$1@dont-email.me>
Content-Language: en-GB
 by: David Brown - Wed, 17 Jan 2024 13:17 UTC

On 17/01/2024 07:11, Janis Papanagnou wrote:
> On 16.01.2024 19:03, David Brown wrote:
>>
>> [...], because they know that Norwegians are superior to Swedes in every way...
>
> I just wanted to reply on that but then I saw your email address... :-)
>

I'm Scottish by origin, but have lived in Norway for about 30 years. So
I am a Norwegian by practice (and citizenship) rather than birth.

(Norway and Sweden view each other as "brother" countries, with very
close ties and cooperation, but also good-natured rivalry and occasional
teasing.)

Re: Effect of CPP tags

<uo8kh2$20hg6$4@dont-email.me>

  copy mid

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

  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!.POSTED!not-for-mail
From: david.br...@hesbynett.no (David Brown)
Newsgroups: comp.lang.c
Subject: Re: Effect of CPP tags
Date: Wed, 17 Jan 2024 14:25:54 +0100
Organization: A noiseless patient Spider
Lines: 52
Message-ID: <uo8kh2$20hg6$4@dont-email.me>
References: <umet9d$3hir9$1@dont-email.me> <unkkp3$26g9o$1@dont-email.me>
<87ttnmnjdb.fsf@nosuchdomain.example.com> <unkp1b$270v8$1@dont-email.me>
<ZSmnN.151217$c3Ea.70659@fx10.iad> <unkuhp$27i0v$2@dont-email.me>
<unlqqa$2eqts$2@dont-email.me> <U7ynN.143065$Wp_8.30410@fx17.iad>
<unmmnd$2jair$1@dont-email.me> <87edepnich.fsf@nosuchdomain.example.com>
<unmqsg$2jvva$1@dont-email.me> <unmu6b$2kh81$1@dont-email.me>
<20240110133135.834@kylheku.com> <unn65q$2lr2i$1@dont-email.me>
<20240110182957.444@kylheku.com> <unokb1$2vmkh$1@dont-email.me>
<20240111081109.274@kylheku.com> <unpd89$33jlu$1@dont-email.me>
<20240111133742.530@kylheku.com> <unpt44$35qn1$1@dont-email.me>
<unrfgs$3fo6l$1@dont-email.me> <unrocu$3h2ah$1@dont-email.me>
<20240112132216.285@kylheku.com> <uo0je6$e8fv$1@dont-email.me>
<20240114115640.506@kylheku.com> <uo24di$lo8r$1@dont-email.me>
<uo3ilc$vjmt$1@dont-email.me> <uo66i4$1g9n5$1@dont-email.me>
<uo6fe3$1i0eu$1@dont-email.me> <uo70pi$1l15q$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Wed, 17 Jan 2024 13:25:54 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="e5d003c4907c1c313df779ab33f575b8";
logging-data="2115078"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19BrMDppMN+9TPopfcQVyOsDCiwhP57BmU="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.11.0
Cancel-Lock: sha1:Ce1ONhMeTfphE0IRKRnA/QCfKtg=
In-Reply-To: <uo70pi$1l15q$1@dont-email.me>
Content-Language: en-GB
 by: David Brown - Wed, 17 Jan 2024 13:25 UTC

On 16/01/2024 23:42, bart wrote:
> On 16/01/2024 17:46, David Brown wrote:
>> On 16/01/2024 16:15, bart wrote:
>
>> void swap_lots(const uint32_t * restrict in, uint32_t * restrict out,
>> uint32_t n) {
>>      while (n--) {
>>          *out++ = swapEndian32(*in++);
>>          *out++ = swapEndian32(*in++);
>>          *out++ = swapEndian32(*in++);
>>          *out++ = swapEndian32(*in++);
>>      }
>> }
>
> What's 'n' here? Are 4n bytes being transformed, or 16n?

In this case, 4n 32-bit words. It's just example code to demonstrate a
point, not to be a particularly useful function in reality.

>
>>> My function would be this on x64 (although I don't support bswap):
>>>
>>>     fun swapends64(u64 x)u64 = assem mov rax, [x]; bswap rax; end
>>>
>>
>> And how efficient would your "swap_lots" function be?
>
> How do you measure efficiency? This task seems memory-bound anyway.
>

That will depend on the sizes, cache, etc., as well as the target. The
target I was using here is a Cortex M7 - with data in tightly-coupled
memory that runs at core speed, it would not be memory bound.

Efficiency is measured in clock cycles. (It can also be measured in
code size, but that's usually not as important. If it were, we would
not be doing manual loop unrolling here.)

> Using exactly that function (I now support 'bswap'), I can process a
> 100M-element u64 array (0.8GB) in .35 seconds, or 2.3GB/second.
>

On what target? Do you have an ARM Cortex-M microcontroller for testing
this?

Using a built-in bswap function kind of defeats the point of using
inline assembly. gcc has __builtin_bswap32 too, or it can be written
manually in C and optimised by the compiler to "rev" instructions. The
point is a demonstration of how gcc's inline assembly can work with the
optimiser for surrounding code, not how fast your PC can swap endianness!

Re: Effect of CPP tags

<uo8pi9$21ruo$1@dont-email.me>

  copy mid

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

  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!.POSTED!not-for-mail
From: bc...@freeuk.com (bart)
Newsgroups: comp.lang.c
Subject: Re: Effect of CPP tags
Date: Wed, 17 Jan 2024 14:51:54 +0000
Organization: A noiseless patient Spider
Lines: 97
Message-ID: <uo8pi9$21ruo$1@dont-email.me>
References: <umet9d$3hir9$1@dont-email.me>
<87ttnmnjdb.fsf@nosuchdomain.example.com> <unkp1b$270v8$1@dont-email.me>
<ZSmnN.151217$c3Ea.70659@fx10.iad> <unkuhp$27i0v$2@dont-email.me>
<unlqqa$2eqts$2@dont-email.me> <U7ynN.143065$Wp_8.30410@fx17.iad>
<unmmnd$2jair$1@dont-email.me> <87edepnich.fsf@nosuchdomain.example.com>
<unmqsg$2jvva$1@dont-email.me> <unmu6b$2kh81$1@dont-email.me>
<20240110133135.834@kylheku.com> <unn65q$2lr2i$1@dont-email.me>
<20240110182957.444@kylheku.com> <unokb1$2vmkh$1@dont-email.me>
<20240111081109.274@kylheku.com> <unpd89$33jlu$1@dont-email.me>
<20240111133742.530@kylheku.com> <unpt44$35qn1$1@dont-email.me>
<unrfgs$3fo6l$1@dont-email.me> <unrocu$3h2ah$1@dont-email.me>
<20240112132216.285@kylheku.com> <uo0je6$e8fv$1@dont-email.me>
<20240114115640.506@kylheku.com> <uo24di$lo8r$1@dont-email.me>
<uo3ilc$vjmt$1@dont-email.me> <uo66i4$1g9n5$1@dont-email.me>
<uo6fe3$1i0eu$1@dont-email.me> <uo70pi$1l15q$1@dont-email.me>
<uo8kh2$20hg6$4@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Wed, 17 Jan 2024 14:51:54 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="6268282b8239d0a8c360e6001c42a605";
logging-data="2158552"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19PEvWK5dEqwX+z7b/TZYNocK5COQ1AQQ0="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:O8A3Ioz0T7FAyhICLthEfOWy9ts=
Content-Language: en-GB
In-Reply-To: <uo8kh2$20hg6$4@dont-email.me>
 by: bart - Wed, 17 Jan 2024 14:51 UTC

On 17/01/2024 13:25, David Brown wrote:
> On 16/01/2024 23:42, bart wrote:
>> On 16/01/2024 17:46, David Brown wrote:
>>> On 16/01/2024 16:15, bart wrote:
>>
>>> void swap_lots(const uint32_t * restrict in, uint32_t * restrict out,
>>> uint32_t n) {
>>>      while (n--) {
>>>          *out++ = swapEndian32(*in++);
>>>          *out++ = swapEndian32(*in++);
>>>          *out++ = swapEndian32(*in++);
>>>          *out++ = swapEndian32(*in++);
>>>      }
>>> }
>>
>> What's 'n' here? Are 4n bytes being transformed, or 16n?
>
> In this case, 4n 32-bit words.  It's just example code to demonstrate a
> point, not to be a particularly useful function in reality.
>
>>
>>>> My function would be this on x64 (although I don't support bswap):
>>>>
>>>>     fun swapends64(u64 x)u64 = assem mov rax, [x]; bswap rax; end
>>>>
>>>
>>> And how efficient would your "swap_lots" function be?
>>
>> How do you measure efficiency? This task seems memory-bound anyway.
>>
>
> That will depend on the sizes, cache, etc., as well as the target.  The
> target I was using here is a Cortex M7 - with data in tightly-coupled
> memory that runs at core speed, it would not be memory bound.
>
> Efficiency is measured in clock cycles.  (It can also be measured in
> code size, but that's usually not as important.  If it were, we would
> not be doing manual loop unrolling here.)
>
>> Using exactly that function (I now support 'bswap'), I can process a
>> 100M-element u64 array (0.8GB) in .35 seconds, or 2.3GB/second.
>>
>
> On what target?  Do you have an ARM Cortex-M microcontroller for testing
> this?

I have an RPi4 somewhere; I only know it has a 64-bit ARM chip. ARM
processor and architecture models are mystery to me. My tests were done
on some AMD Ryzen device, probably bottom of the range.

(x64 processors are a bit of a mystery too! I just have little interest
beyond whether it's x64 or ARM64; I don't come across anything else.)

> Using a built-in bswap function kind of defeats the point of using
> inline assembly.

I didn't support 'bswap' at all. I first has to add it to my assembler,
then roll that out to the backend of my compiler.

This was necessary both to be able to use it in inline assembler, and
for the compiler backend to be able to deal with that instruction,
whatever had generated it.

So I wanted to know whether building it to the language in would be
worth doing, performance-wise (probably not). Although there are other
advantages of having it as an operator, since it could be used in-place
as 'bswap:=A[i]', and here it would be able to choose 32- and 64-bit
variations.

But it also highlighted issues with my inline assembler within macros
used to emulate inline functions, such as this:

macro byteswap(x) = assem mov rax, [x] ...

'x' can only be a simple variable at the invocation, not an arbitrary
expression like 'A[i]'. This suggested an enhancement:

assem (expr) ...

which first evaluates the expression to a known register. (I could just
do 'expr; assem ...' which /probably/ does the same, but it's risky.)

So doing the exercise helped in determining what might be a suitable
compromise. Although it would need explicit forms for 32- vs 64-bit
operations.

('assem(expr) ...' is also partway to doing what gcc asm{} does in
creating an interface, but retaining the same syntax.)

>  gcc has __builtin_bswap32 too, or it can be written
> manually in C and optimised by the compiler to "rev" instructions.  The
> point is a demonstration of how gcc's inline assembly can work with the
> optimiser for surrounding code, not how fast your PC can swap endianness!

It showed that using an actual function call, and not unrolling loops,
wasn't that slow, not on my PC.

Re: Effect of CPP tags

<K_SpN.168166$vFZa.134000@fx13.iad>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!newsfeed.endofthelinebbs.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx13.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: Effect of CPP tags
Newsgroups: comp.lang.c
References: <umet9d$3hir9$1@dont-email.me> <20240112132216.285@kylheku.com> <uo0je6$e8fv$1@dont-email.me> <20240114115640.506@kylheku.com> <uo24di$lo8r$1@dont-email.me> <20240114222417.720@kylheku.com> <uo3eli$uv97$1@dont-email.me> <6pbpN.200172$7sbb.118143@fx16.iad> <uo3jth$vqg9$1@dont-email.me> <B1epN.177806$c3Ea.53953@fx10.iad> <uo3v2u$11mbu$1@dont-email.me> <20240115152928.267@kylheku.com> <uo5pdi$1dgnv$1@dont-email.me> <20240116100845.82@kylheku.com> <uo75um$1lq3e$1@dont-email.me>
Lines: 35
Message-ID: <K_SpN.168166$vFZa.134000@fx13.iad>
X-Complaints-To: abuse@usenetserver.com
NNTP-Posting-Date: Wed, 17 Jan 2024 16:11:22 UTC
Organization: UsenetServer - www.usenetserver.com
Date: Wed, 17 Jan 2024 16:11:22 GMT
X-Received-Bytes: 2369
 by: Scott Lurndal - Wed, 17 Jan 2024 16:11 UTC

bart <bc@freeuk.com> writes:
>On 16/01/2024 18:39, Kaz Kylheku wrote:
>> On 2024-01-16, bart <bc@freeuk.com> wrote:
>
>>> gcc is a project 10s of 1000s of files. If a particular configuration
>>> targets one architecture out of 100, it can also support the ASM syntax
>>> for that architecture.
>>
>> Not reasonably so. The parser of every front end would have to have
>> a special case for that assembly language.
>>
>> The proposal does not pass a cost/benefit analysis, due to the
>> high cost and low benefit.
>>
>>> You don't need to have the ASM syntax embedded within the C grammar. Not
>>> so specifically anyway; you allow a bunch of keyword and register tokens
>>> within asm{...}.
>>
>> keywords and tokens are grammar.
>
>So how does the grammar of HTML work: does it also include the entire
>grammar of JavaScript?
>
>JS appears inside <script> ... </script> tags.

From the structured general markup language, or extensable markup
language (SGML/XML) perspective, anything between tags is completely
invisible. Semantics of any tag is Application dependent.

HTML (a non-proper subset of XML) applies semantics to
tags defined by HTML such as <script/>, <a/>, et alia.

An HTML interpreter interprets the tags and will pass the
data to the appropriate entity (in this case, a javascript
or ecmascript interpreter).


devel / comp.lang.c / Effect of CPP tags

Pages:123456789101112131415161718192021222324252627
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor