Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

...Unix, MS-DOS, and Windows NT (also known as the Good, the Bad, and the Ugly). -- Matt Welsh


devel / comp.arch / Re: Dense machine code from C++ code (compiler optimizations)

SubjectAuthor
* Dense machine code from C++ code (compiler optimizations)Marcus
+* Re: Dense machine code from C++ code (compiler optimizations)Terje Mathisen
|`- Re: Dense machine code from C++ code (compiler optimizations)Marcus
+* Re: Dense machine code from C++ code (compiler optimizations)BGB
|+* Re: Dense machine code from C++ code (compiler optimizations)robf...@gmail.com
||`* Re: Dense machine code from C++ code (compiler optimizations)MitchAlsup
|| `* Re: Dense machine code from C++ code (compiler optimizations)BGB
||  +- Re: Dense machine code from C++ code (compiler optimizations)Ivan Godard
||  `* Re: Dense machine code from C++ code (compiler optimizations)MitchAlsup
||   +* Re: Dense machine code from C++ code (compiler optimizations)Ivan Godard
||   |`- Re: Dense machine code from C++ code (compiler optimizations)MitchAlsup
||   `* Re: Dense machine code from C++ code (compiler optimizations)BGB
||    `* Re: Dense machine code from C++ code (compiler optimizations)MitchAlsup
||     `* Re: Dense machine code from C++ code (compiler optimizations)BGB
||      +* Re: Dense machine code from C++ code (compiler optimizations)robf...@gmail.com
||      |+- Re: Dense machine code from C++ code (compiler optimizations)BGB
||      |`* Re: Thor (was: Dense machine code...)Marcus
||      | `* Re: Thor (was: Dense machine code...)robf...@gmail.com
||      |  +- Re: ThorEricP
||      |  `* Re: Thor (was: Dense machine code...)Marcus
||      |   `- Re: Thor (was: Dense machine code...)robf...@gmail.com
||      `* Re: Dense machine code from C++ code (compiler optimizations)MitchAlsup
||       `* Re: Dense machine code from C++ code (compiler optimizations)BGB
||        `* Re: Dense machine code from C++ code (compiler optimizations)MitchAlsup
||         `* Re: Dense machine code from C++ code (compiler optimizations)BGB
||          `* Re: Dense machine code from C++ code (compiler optimizations)BGB
||           `* Re: Testing with open source games (was Dense machine code ...)Marcus
||            +* Re: Testing with open source games (was Dense machine code ...)Terje Mathisen
||            |`* Re: Testing with open source games (was Dense machine code ...)Marcus
||            | +- Re: Testing with open source games (was Dense machine code ...)Terje Mathisen
||            | `* Re: Testing with open source games (was Dense machine code ...)James Van Buskirk
||            |  `- Re: Testing with open source games (was Dense machine code ...)Marcus
||            `- Re: Testing with open source games (was Dense machine code ...)BGB
|`* Re: Dense machine code from C++ code (compiler optimizations)Marcus
| +* Re: Dense machine code from C++ code (compiler optimizations)Ivan Godard
| |+- Re: Dense machine code from C++ code (compiler optimizations)Thomas Koenig
| |`* Re: Dense machine code from C++ code (compiler optimizations)BGB
| | `* Re: Dense machine code from C++ code (compiler optimizations)Ivan Godard
| |  +- Re: Dense machine code from C++ code (compiler optimizations)MitchAlsup
| |  `- Re: Dense machine code from C++ code (compiler optimizations)BGB
| +* Re: Dense machine code from C++ code (compiler optimizations)BGB
| |`- Re: Dense machine code from C++ code (compiler optimizations)Paul A. Clayton
| `* Re: Dense machine code from C++ code (compiler optimizations)Thomas Koenig
|  `* Re: Dense machine code from C++ code (compiler optimizations)Marcus
|   +* Re: Dense machine code from C++ code (compiler optimizations)Thomas Koenig
|   |`* Re: Dense machine code from C++ code (compiler optimizations)Marcus
|   | `- Re: Dense machine code from C++ code (compiler optimizations)Thomas Koenig
|   `* Re: Dense machine code from C++ code (compiler optimizations)BGB
|    +* Re: Dense machine code from C++ code (compiler optimizations)Marcus
|    |`- Re: Dense machine code from C++ code (compiler optimizations)George Neuner
|    `* Re: Dense machine code from C++ code (compiler optimizations)David Brown
|     `* Re: Dense machine code from C++ code (compiler optimizations)Marcus
|      `* Re: Dense machine code from C++ code (compiler optimizations)Terje Mathisen
|       +* Re: Dense machine code from C++ code (compiler optimizations)MitchAlsup
|       |`- Re: Dense machine code from C++ code (compiler optimizations)Terje Mathisen
|       +- Re: Dense machine code from C++ code (compiler optimizations)BGB
|       `- Re: Dense machine code from C++ code (compiler optimizations)Marcus
`* Re: Dense machine code from C++ code (compiler optimizations)Ir. Hj. Othman bin Hj. Ahmad
 +- Re: Dense machine code from C++ code (compiler optimizations)MitchAlsup
 `* Re: Dense machine code from C++ code (compiler optimizations)Thomas Koenig
  +* Re: Dense machine code from C++ code (compiler optimizations)chris
  |`* Re: Dense machine code from C++ code (compiler optimizations)David Brown
  | `* Re: Dense machine code from C++ code (compiler optimizations)chris
  |  +* Re: Dense machine code from C++ code (compiler optimizations)David Brown
  |  |`- Re: Dense machine code from C++ code (compiler optimizations)chris
  |  `* Re: Dense machine code from C++ code (compiler optimizations)Terje Mathisen
  |   `* Re: Dense machine code from C++ code (compiler optimizations)MitchAlsup
  |    +- Re: Dense machine code from C++ code (compiler optimizations)MitchAlsup
  |    `* Re: Dense machine code from C++ code (compiler optimizations)Terje Mathisen
  |     `- Re: Dense machine code from C++ code (compiler optimizations)MitchAlsup
  +* Re: Dense machine code from C++ code (compiler optimizations)David Brown
  |`* Re: Dense machine code from C++ code (compiler optimizations)BGB
  | `* Re: Dense machine code from C++ code (compiler optimizations)David Brown
  |  `* Re: Dense machine code from C++ code (compiler optimizations)BGB
  |   +* Re: Dense machine code from C++ code (compiler optimizations)MitchAlsup
  |   |`* Re: Dense machine code from C++ code (compiler optimizations)BGB
  |   | `- Re: Dense machine code from C++ code (compiler optimizations)MitchAlsup
  |   `* Re: Dense machine code from C++ code (compiler optimizations)David Brown
  |    `- Re: Dense machine code from C++ code (compiler optimizations)BGB
  `* Re: Dense machine code from C++ code (compiler optimizations)Stephen Fuld
   +* Re: Dense machine code from C++ code (compiler optimizations)MitchAlsup
   |`- Re: Dense machine code from C++ code (compiler optimizations)Stephen Fuld
   +* Re: Dense machine code from C++ code (compiler optimizations)James Van Buskirk
   |`* Re: Dense machine code from C++ code (compiler optimizations)Stephen Fuld
   | +* Re: Dense machine code from C++ code (compiler optimizations)MitchAlsup
   | |+- Re: Dense machine code from C++ code (compiler optimizations)Marcus
   | |`* Re: Dense machine code from C++ code (compiler optimizations)Terje Mathisen
   | | `* Re: Dense machine code from C++ code (compiler optimizations)Stephen Fuld
   | |  `* Re: Dense machine code from C++ code (compiler optimizations)EricP
   | |   `* Re: Dense machine code from C++ code (compiler optimizations)MitchAlsup
   | |    `* Re: Dense machine code from C++ code (compiler optimizations)EricP
   | |     `* Re: Dense machine code from C++ code (compiler optimizations)MitchAlsup
   | |      `- Re: Dense machine code from C++ code (compiler optimizations)EricP
   | `* Re: Dense machine code from C++ code (compiler optimizations)Tim Rentsch
   |  +* Re: Dense machine code from C++ code (compiler optimizations)Stephen Fuld
   |  |+* Re: Dense machine code from C++ code (compiler optimizations)Guillaume
   |  ||+* Re: Dense machine code from C++ code (compiler optimizations)MitchAlsup
   |  |||+- Re: Dense machine code from C++ code (compiler optimizations)Thomas Koenig
   |  |||`* Re: Dense machine code from C++ code (compiler optimizations)Guillaume
   |  ||| +* Re: Dense machine code from C++ code (compiler optimizations)MitchAlsup
   |  ||| |`* Re: Dense machine code from C++ code (compiler optimizations)Andreas Eder
   |  ||| `- Re: Dense machine code from C++ code (compiler optimizations)Tim Rentsch
   |  ||`- Re: Dense machine code from C++ code (compiler optimizations)Tim Rentsch
   |  |`* Re: Dense machine code from C++ code (compiler optimizations)Tim Rentsch
   |  `* Re: Dense machine code from C++ code (compiler optimizations)Ivan Godard
   `- Re: Dense machine code from C++ code (compiler optimizations)Andreas Eder

Pages:12345678
Re: Dense machine code from C++ code (compiler optimizations)

<spn9sv$9cm$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=22342&group=comp.arch#22342

  copy link   Newsgroups: comp.arch
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: david.br...@hesbynett.no (David Brown)
Newsgroups: comp.arch
Subject: Re: Dense machine code from C++ code (compiler optimizations)
Date: Sun, 19 Dec 2021 13:51:42 +0100
Organization: A noiseless patient Spider
Lines: 77
Message-ID: <spn9sv$9cm$1@dont-email.me>
References: <sndun6$q07$1@dont-email.me>
<dc10dfff-b48e-40ec-8c24-0a6c2e1790d2n@googlegroups.com>
<sphe6s$5a3$1@newsreader4.netcologne.de> <spi4l7$sdj$1@dont-email.me>
<spjmcf$hhs$1@dont-email.me> <spl5kc$mja$1@dont-email.me>
<splek0$j57$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
Injection-Date: Sun, 19 Dec 2021 12:51:43 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="753ede66e0e7aca579d9b44103d22a83";
logging-data="9622"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX197nfyqMlnjcoFoMRLfNYQEAKSxYO4Ey5U="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.11.0
Cancel-Lock: sha1:7y4EXrma1SYt5yq/4u/fTGI28jk=
In-Reply-To: <splek0$j57$1@dont-email.me>
Content-Language: en-GB
 by: David Brown - Sun, 19 Dec 2021 12:51 UTC

On 18/12/2021 20:59, BGB wrote:
> On 12/18/2021 11:26 AM, David Brown wrote:

>> Compilers are free to change load and store orders on the assumption
>> that the current thread of execution is the only thing that ever sees
>> the accesses, unless you specifically say otherwise (with "volatile",
>> atomics, or other methods).  More extreme movements are usually only
>> done at higher levels of optimisation.  But if the code does not work
>> correctly at -O2, you can be pretty confident that your code is wrong.
>> Compiler bugs are not unheard of, of course, but user-code bugs are a
>> /lot/ more common!
>>
>
> This code is single threaded.
>
> The code in question depends on the use of misaligned and overlapping
> loads and stores. As a result, changing the relative load/store order
> will change the visible results.
>

Compilers assume you follow the rules for alignments - and then
overlapping cannot possibly occur (for types smaller than the maximum
alignment sizes). I don't think there is any way to construct objects
that overlap while remaining within the strict rules of C (by which I
mean, without invoking behaviour that is not defined by the standards.
Particular compilers might support it, however).

>
> I was trying to use pointers declared as:
>   __attribute__((__may_alias__)) __attribute__((aligned(1)))
>
> But, this did not work in GCC.

No, it will not. "may_alias" does not change alignment rules or allow
overlapping. And the "aligned" attribute is for /increasing/ alignment,
not reducing it. You might have better luck using a struct with the
"packed" attribute - that's the only way in gcc to work with unaligned
data in a fully defined way, I believe.

>
> However, 'volatile' did give the expected behavior.

"volatile" tells the compiler to make the access you gave, regardless of
anything else, and can be used to force unaligned reads and writes
(amongst other things).

>
> The above did work in Clang, however as far as I can tell it is behaving
> the same in this case as it did for volatile.
>
>
> One can also use a bunch of 8 and 16 byte memcpy operations, but as
> noted, this is slower than using 'volatile'.
>

>
>
> For the "generic" fallback, "getu32_le()" and friends can fall back to
> something like:
>   ((ptr)[0]|((ptr)[1]<<8)|((ptr)[2]<<16)|((ptr)[3]<<24))
>
> But, this results in a fairly massive drop in performance with MSVC.
>
> However, interestingly, GCC sees much less of a performance impact with
> this case.
>
>

I recommend playing in <https://godbolt.org> and trying different
combinations here - you can quickly compare the generated results for
different compilers, flags, and code.

>
> This sort of hackery may make a pretty big difference in the speed of an
> LZ decoder...
>

Re: Dense machine code from C++ code (compiler optimizations)

<spo1m1$1d60$1@gioia.aioe.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=22344&group=comp.arch#22344

  copy link   Newsgroups: comp.arch
Path: i2pn2.org!i2pn.org!aioe.org!rd9pRsUZyxkRLAEK7e/Uzw.user.46.165.242.91.POSTED!not-for-mail
From: terje.ma...@tmsw.no (Terje Mathisen)
Newsgroups: comp.arch
Subject: Re: Dense machine code from C++ code (compiler optimizations)
Date: Sun, 19 Dec 2021 20:37:38 +0100
Organization: Aioe.org NNTP Server
Message-ID: <spo1m1$1d60$1@gioia.aioe.org>
References: <sndun6$q07$1@dont-email.me>
<dc10dfff-b48e-40ec-8c24-0a6c2e1790d2n@googlegroups.com>
<sphe6s$5a3$1@newsreader4.netcologne.de> <sphs92$8lg$1@gioia.aioe.org>
<spi43n$h7h$1@dont-email.me> <spif98$1lkm$1@gioia.aioe.org>
<spisnd$dq2$1@gioia.aioe.org>
<555424d7-7e86-4d10-ad66-398c2035797dn@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Info: gioia.aioe.org; logging-data="46272"; posting-host="rd9pRsUZyxkRLAEK7e/Uzw.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:68.0) Gecko/20100101
Firefox/68.0 SeaMonkey/2.53.10.1
X-Notice: Filtered by postfilter v. 0.9.2
 by: Terje Mathisen - Sun, 19 Dec 2021 19:37 UTC

MitchAlsup wrote:
> On Friday, December 17, 2021 at 2:42:25 PM UTC-6, Terje Mathisen wrote:
>> I'll typically load 32 or 64 bits surrounding the target are, swap the
>> bytes if there's an endian change, then use regular shift & mask ops to
>> get at what I need.
> <
> We teach compilers to recognize << followed by >> and convert it into
> EXT instructions.
> We teach compilers to recognize & followed by << followed by &~
> followed by | and convert it into INS instructions (when appropriate).

I love those compiler micro-optimizations, they remove the need for
inline asm to handle these things.

Terje

--
- <Terje.Mathisen at tmsw.no>
"almost all programming can be viewed as an exercise in caching"

Re: Dense machine code from C++ code (compiler optimizations)

<33b5f3c0-8661-4a58-a5b9-5f256dc50632n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=22345&group=comp.arch#22345

  copy link   Newsgroups: comp.arch
X-Received: by 2002:ac8:5b01:: with SMTP id m1mr9950121qtw.313.1639945748758;
Sun, 19 Dec 2021 12:29:08 -0800 (PST)
X-Received: by 2002:a05:6808:211c:: with SMTP id r28mr16506881oiw.155.1639945748633;
Sun, 19 Dec 2021 12:29:08 -0800 (PST)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.arch
Date: Sun, 19 Dec 2021 12:29:08 -0800 (PST)
In-Reply-To: <spo1m1$1d60$1@gioia.aioe.org>
Injection-Info: google-groups.googlegroups.com; posting-host=2600:1700:291:29f0:dd48:b07a:c9e5:e58e;
posting-account=H_G_JQkAAADS6onOMb-dqvUozKse7mcM
NNTP-Posting-Host: 2600:1700:291:29f0:dd48:b07a:c9e5:e58e
References: <sndun6$q07$1@dont-email.me> <dc10dfff-b48e-40ec-8c24-0a6c2e1790d2n@googlegroups.com>
<sphe6s$5a3$1@newsreader4.netcologne.de> <sphs92$8lg$1@gioia.aioe.org>
<spi43n$h7h$1@dont-email.me> <spif98$1lkm$1@gioia.aioe.org>
<spisnd$dq2$1@gioia.aioe.org> <555424d7-7e86-4d10-ad66-398c2035797dn@googlegroups.com>
<spo1m1$1d60$1@gioia.aioe.org>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <33b5f3c0-8661-4a58-a5b9-5f256dc50632n@googlegroups.com>
Subject: Re: Dense machine code from C++ code (compiler optimizations)
From: MitchAl...@aol.com (MitchAlsup)
Injection-Date: Sun, 19 Dec 2021 20:29:08 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 26
 by: MitchAlsup - Sun, 19 Dec 2021 20:29 UTC

On Sunday, December 19, 2021 at 1:37:41 PM UTC-6, Terje Mathisen wrote:
> MitchAlsup wrote:
> > On Friday, December 17, 2021 at 2:42:25 PM UTC-6, Terje Mathisen wrote:
> >> I'll typically load 32 or 64 bits surrounding the target are, swap the
> >> bytes if there's an endian change, then use regular shift & mask ops to
> >> get at what I need.
> > <
> > We teach compilers to recognize << followed by >> and convert it into
> > EXT instructions.
> > We teach compilers to recognize & followed by << followed by &~
> > followed by | and convert it into INS instructions (when appropriate).
<
> I love those compiler micro-optimizations, they remove the need for
> inline asm to handle these things.
<
No reason to change the language or library interfaces to access easy
to identify idioms. I modified the M88K compiler to do these in 1984.
All it takes it recognizing a slightly more complicated pattern when
selecting code to be emitted. They typically, also, take a minor amount
of pressure off the register allocator.
<
> Terje
>
>
> --
> - <Terje.Mathisen at tmsw.no>
> "almost all programming can be viewed as an exercise in caching"

Re: Dense machine code from C++ code (compiler optimizations)

<spo6d4$ao7$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=22346&group=comp.arch#22346

  copy link   Newsgroups: comp.arch
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: cr88...@gmail.com (BGB)
Newsgroups: comp.arch
Subject: Re: Dense machine code from C++ code (compiler optimizations)
Date: Sun, 19 Dec 2021 14:58:11 -0600
Organization: A noiseless patient Spider
Lines: 165
Message-ID: <spo6d4$ao7$1@dont-email.me>
References: <sndun6$q07$1@dont-email.me>
<dc10dfff-b48e-40ec-8c24-0a6c2e1790d2n@googlegroups.com>
<sphe6s$5a3$1@newsreader4.netcologne.de> <spi4l7$sdj$1@dont-email.me>
<spjmcf$hhs$1@dont-email.me> <spl5kc$mja$1@dont-email.me>
<splek0$j57$1@dont-email.me> <spn9sv$9cm$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Sun, 19 Dec 2021 20:58:12 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="75b42e13be0f9ec744f65a9d2140a83f";
logging-data="11015"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18qFBFs6wrBFQN0CRyd/Dkq"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.4.0
Cancel-Lock: sha1:WQH58zbvW5sAWVUFnMzKNdFaSY8=
In-Reply-To: <spn9sv$9cm$1@dont-email.me>
Content-Language: en-US
 by: BGB - Sun, 19 Dec 2021 20:58 UTC

On 12/19/2021 6:51 AM, David Brown wrote:
> On 18/12/2021 20:59, BGB wrote:
>> On 12/18/2021 11:26 AM, David Brown wrote:
>
>>> Compilers are free to change load and store orders on the assumption
>>> that the current thread of execution is the only thing that ever sees
>>> the accesses, unless you specifically say otherwise (with "volatile",
>>> atomics, or other methods).  More extreme movements are usually only
>>> done at higher levels of optimisation.  But if the code does not work
>>> correctly at -O2, you can be pretty confident that your code is wrong.
>>> Compiler bugs are not unheard of, of course, but user-code bugs are a
>>> /lot/ more common!
>>>
>>
>> This code is single threaded.
>>
>> The code in question depends on the use of misaligned and overlapping
>> loads and stores. As a result, changing the relative load/store order
>> will change the visible results.
>>
>
> Compilers assume you follow the rules for alignments - and then
> overlapping cannot possibly occur (for types smaller than the maximum
> alignment sizes). I don't think there is any way to construct objects
> that overlap while remaining within the strict rules of C (by which I
> mean, without invoking behaviour that is not defined by the standards.
> Particular compilers might support it, however).
>

The goal in this case was seeing what would work in the various compilers.

>>
>> I was trying to use pointers declared as:
>>   __attribute__((__may_alias__)) __attribute__((aligned(1)))
>>
>> But, this did not work in GCC.
>
> No, it will not. "may_alias" does not change alignment rules or allow
> overlapping. And the "aligned" attribute is for /increasing/ alignment,
> not reducing it. You might have better luck using a struct with the
> "packed" attribute - that's the only way in gcc to work with unaligned
> data in a fully defined way, I believe.
>

There is also the "memcpy" option, say:
inline uint32_t getu32_le(void *ptr)
{ uint32_t v;
memcpy(&v, ptr, 4);
return(v);
}

However, despite memcpy and inline being (often) essentially free in
GCC, the end result still ended up roughly 20% slower.

I guess maybe one could use a packed struct like, say:
typedef struct ui32ps_s __attribute__((packed)) {
uint32_t v;
}ui32ps_t;

#define getu32_le(ptr) (((ui32ps_t *)(ptr))->v)

Haven't tried this yet.

The attempt to use 'aligned(1)' was to see if it would behave like
'__unaligned' in some other compilers, but GCC has neither '__unaligned'
nor '__packed', ...

In BGBCC, I followed a rule similar to MSVC, in that either __unaligned
or __packed may allow for unaligned pointers (they are treated as
equivalent in this case); otherwise pointers are assumed to be natively
aligned.
This mostly effects things like whether the compiler is allowed to use
'MOV.X' operations in BJX2, since (unlike other loads/stores) MOV.X
imposes an 8B alignment restriction (*).

*: Mostly because allowing a freely aligned 128-bit load/store would
have a significant adverse effect on the cost of the L1 D$.

Namely one can imagine that each 128-bit L1 line is effectively divided
in half, and one uses a pair of these half-lines to implement an
unaligned load/store (selecting/inserting 64 bits from anywhere within
the 128-bit pair). In this case, the MOV.X operation simply skips this
select/insert stage and operates more directly on the pair of half-lines.

Loads will sign or zero extend the value as requested. Stores will copy
the high-order bits (for insert) from the 'select' results. A new pair
of half-lines will be generated by "reinserting" this 64-bit value back
in at the target pair (which retain any unchanged bits from the select
pair).

In cases where an unaligned 128b load/store is needed, it can be
implemented using a pair of MOV.Q instructions.

By extension, alignment is imposed in a few other areas (Reg: HW, ABI):
SP: 8, 16
PC: 2/4*, 2/4*, (*: 4 is required for inter-ISA branches with RVX)
GBR: 8, 16
TBR: 8, 16

>>
>> However, 'volatile' did give the expected behavior.
>
> "volatile" tells the compiler to make the access you gave, regardless of
> anything else, and can be used to force unaligned reads and writes
> (amongst other things).
>

Yeah.

Volatile seemed to be the winner in these tests.

>>
>> The above did work in Clang, however as far as I can tell it is behaving
>> the same in this case as it did for volatile.
>>
>>
>> One can also use a bunch of 8 and 16 byte memcpy operations, but as
>> noted, this is slower than using 'volatile'.
>>
>
>>
>>
>> For the "generic" fallback, "getu32_le()" and friends can fall back to
>> something like:
>>   ((ptr)[0]|((ptr)[1]<<8)|((ptr)[2]<<16)|((ptr)[3]<<24))
>>
>> But, this results in a fairly massive drop in performance with MSVC.
>>
>> However, interestingly, GCC sees much less of a performance impact with
>> this case.
>>
>>
>
> I recommend playing in <https://godbolt.org> and trying different
> combinations here - you can quickly compare the generated results for
> different compilers, flags, and code.
>

When I looked at it before, GCC was able to transform this pattern into
a plain memory load. MSVC does not seem to do this.

Still leaves an open mystery though of why it would be slower (in GCC)
than the use of 'volatile' or 'memcpy', since it should otherwise be
expected to be the same in this case.

But, in any case, the hit is a lot smaller than the one MSVC takes here.

>>
>> This sort of hackery may make a pretty big difference in the speed of an
>> LZ decoder...
>>
>

Re: Dense machine code from C++ code (compiler optimizations)

<spqc1d$oio$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=22352&group=comp.arch#22352

  copy link   Newsgroups: comp.arch
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: sfu...@alumni.cmu.edu.invalid (Stephen Fuld)
Newsgroups: comp.arch
Subject: Re: Dense machine code from C++ code (compiler optimizations)
Date: Mon, 20 Dec 2021 08:46:37 -0800
Organization: A noiseless patient Spider
Lines: 38
Message-ID: <spqc1d$oio$1@dont-email.me>
References: <sndun6$q07$1@dont-email.me>
<dc10dfff-b48e-40ec-8c24-0a6c2e1790d2n@googlegroups.com>
<sphe6s$5a3$1@newsreader4.netcologne.de>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 20 Dec 2021 16:46:37 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="b1f42bd3c3915fb259be10ded43720f8";
logging-data="25176"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/Mwl7ngWZxHBhtAoQ6EtCgEk3IbE7tc3o="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.4.0
Cancel-Lock: sha1:pccncc6/bvd6n1DdVe8ndPjSgUI=
In-Reply-To: <sphe6s$5a3$1@newsreader4.netcologne.de>
Content-Language: en-US
 by: Stephen Fuld - Mon, 20 Dec 2021 16:46 UTC

On 12/16/2021 11:28 PM, Thomas Koenig wrote:
> Ir. Hj. Othman bin Hj. Ahmad <othmana@gmail.com> schrieb:
>
>> HLL is very poor in bit manipulations. Better use a library for
>> these bit manipulations, so less need for optimization.
>
> Not really - calling a library function has a _lot_ of overhead,
> and what goes on in the library is hidden from the compiler. It is
> usually preferred for the compiler to emit highly optimized code.
>
> These days, compilers will might even recognize some standard
> idioms for certain bit manipulations and use a corresponding
> machine instruction, if available.

A compiler I used to use (it was for Fortran, but this functionality is
not Fortran specific) had a pseudo function named "Bits". It looked
like a function that accepted three arguments, a variable name and a
starting bit number and number of bits, both of which could be a
constant or an integer variable. One of its unique properties is that
it could also be used on the left hand side of an assignment statement.

This feature led to very clear, concise code, that the compiler didn't
have to go through a complex algorithms to recognize, and would generate
optimal, inline code. There was sort of a pragma that could optionally
generate checking code for out of range combinations of length and
starting bit number.

So, for example, the source code to move two bits starting at bit 3 of
variable B to starting at bit 4 of variable A would be

Bits (A, 2, 4) = Bits (B, 2, 3)

I always liked this feature, and used it a fair amount.

--
- Stephen Fuld
(e-mail address disguised to prevent spam)

Re: Dense machine code from C++ code (compiler optimizations)

<69bd3679-e03e-46ac-a93a-443e45bb743an@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=22353&group=comp.arch#22353

  copy link   Newsgroups: comp.arch
X-Received: by 2002:a05:6214:2423:: with SMTP id gy3mr9398889qvb.44.1640021129272;
Mon, 20 Dec 2021 09:25:29 -0800 (PST)
X-Received: by 2002:a9d:7443:: with SMTP id p3mr12012973otk.331.1640021128984;
Mon, 20 Dec 2021 09:25:28 -0800 (PST)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.arch
Date: Mon, 20 Dec 2021 09:25:28 -0800 (PST)
In-Reply-To: <spqc1d$oio$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=2600:1700:291:29f0:e1a7:8791:699c:c121;
posting-account=H_G_JQkAAADS6onOMb-dqvUozKse7mcM
NNTP-Posting-Host: 2600:1700:291:29f0:e1a7:8791:699c:c121
References: <sndun6$q07$1@dont-email.me> <dc10dfff-b48e-40ec-8c24-0a6c2e1790d2n@googlegroups.com>
<sphe6s$5a3$1@newsreader4.netcologne.de> <spqc1d$oio$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <69bd3679-e03e-46ac-a93a-443e45bb743an@googlegroups.com>
Subject: Re: Dense machine code from C++ code (compiler optimizations)
From: MitchAl...@aol.com (MitchAlsup)
Injection-Date: Mon, 20 Dec 2021 17:25:29 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 41
 by: MitchAlsup - Mon, 20 Dec 2021 17:25 UTC

On Monday, December 20, 2021 at 10:46:40 AM UTC-6, Stephen Fuld wrote:
> On 12/16/2021 11:28 PM, Thomas Koenig wrote:
> > Ir. Hj. Othman bin Hj. Ahmad <oth...@gmail.com> schrieb:
> >
> >> HLL is very poor in bit manipulations. Better use a library for
> >> these bit manipulations, so less need for optimization.
> >
> > Not really - calling a library function has a _lot_ of overhead,
> > and what goes on in the library is hidden from the compiler. It is
> > usually preferred for the compiler to emit highly optimized code.
> >
> > These days, compilers will might even recognize some standard
> > idioms for certain bit manipulations and use a corresponding
> > machine instruction, if available.
> A compiler I used to use (it was for Fortran, but this functionality is
> not Fortran specific) had a pseudo function named "Bits". It looked
> like a function that accepted three arguments, a variable name and a
> starting bit number and number of bits, both of which could be a
> constant or an integer variable. One of its unique properties is that
> it could also be used on the left hand side of an assignment statement.
>
> This feature led to very clear, concise code, that the compiler didn't
> have to go through a complex algorithms to recognize, and would generate
> optimal, inline code. There was sort of a pragma that could optionally
> generate checking code for out of range combinations of length and
> starting bit number.
>
> So, for example, the source code to move two bits starting at bit 3 of
> variable B to starting at bit 4 of variable A would be
>
> Bits (A, 2, 4) = Bits (B, 2, 3)
<
A more livable syntax might be:
<
A<2:4> = B<2:3>
>
> I always liked this feature, and used it a fair amount.
>
>
> --
> - Stephen Fuld
> (e-mail address disguised to prevent spam)

Re: Dense machine code from C++ code (compiler optimizations)

<spqhj2$gdf$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=22354&group=comp.arch#22354

  copy link   Newsgroups: comp.arch
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: not_va...@comcast.net (James Van Buskirk)
Newsgroups: comp.arch
Subject: Re: Dense machine code from C++ code (compiler optimizations)
Date: Mon, 20 Dec 2021 11:21:19 -0700
Organization: A noiseless patient Spider
Lines: 1
Message-ID: <spqhj2$gdf$1@dont-email.me>
References: <sndun6$q07$1@dont-email.me> <dc10dfff-b48e-40ec-8c24-0a6c2e1790d2n@googlegroups.com> <sphe6s$5a3$1@newsreader4.netcologne.de> <spqc1d$oio$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain;
format=flowed;
charset="UTF-8";
reply-type=response
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 20 Dec 2021 18:21:22 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="3120cd3a22001495c1b8e6140f8c63f1";
logging-data="16815"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/Phwc7/2PEMNfH2PXc7JAihkK2pq/yySU="
Cancel-Lock: sha1:iPQIwTNEgDc4VYpkX1Jc1KELiAo=
X-MimeOLE: Produced By Microsoft MimeOLE V16.4.3528.331
In-Reply-To: <spqc1d$oio$1@dont-email.me>
X-Newsreader: Microsoft Windows Live Mail 16.4.3528.331
Importance: Normal
X-Priority: 3
X-MSMail-Priority: Normal
 by: James Van Buskirk - Mon, 20 Dec 2021 18:21 UTC

"Stephen Fuld" wrote in message news:spqc1d$oio$1@dont-email.me...

> A compiler I used to use (it was for Fortran, but this functionality is
> not Fortran specific) had a pseudo function named "Bits". It looked
> like a function that accepted three arguments, a variable name and a
> starting bit number and number of bits, both of which could be a
> constant or an integer variable. One of its unique properties is that
> it could also be used on the left hand side of an assignment statement.

> This feature led to very clear, concise code, that the compiler didn't
> have to go through a complex algorithms to recognize, and would generate
> optimal, inline code. There was sort of a pragma that could optionally
> generate checking code for out of range combinations of length and
> starting bit number.

> So, for example, the source code to move two bits starting at bit 3 of
> variable B to starting at bit 4 of variable A would be

> Bits (A, 2, 4) = Bits (B, 2, 3)

> I always liked this feature, and used it a fair amount.

Compare
https://gcc.gnu.org/onlinedocs/gfortran/IBITS.html#IBITS
https://gcc.gnu.org/onlinedocs/gfortran/MVBITS.html#MVBITS
which are both elemental.

Re: Dense machine code from C++ code (compiler optimizations)

<spqk4n$4e9$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=22357&group=comp.arch#22357

  copy link   Newsgroups: comp.arch
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: sfu...@alumni.cmu.edu.invalid (Stephen Fuld)
Newsgroups: comp.arch
Subject: Re: Dense machine code from C++ code (compiler optimizations)
Date: Mon, 20 Dec 2021 11:04:53 -0800
Organization: A noiseless patient Spider
Lines: 45
Message-ID: <spqk4n$4e9$1@dont-email.me>
References: <sndun6$q07$1@dont-email.me>
<dc10dfff-b48e-40ec-8c24-0a6c2e1790d2n@googlegroups.com>
<sphe6s$5a3$1@newsreader4.netcologne.de> <spqc1d$oio$1@dont-email.me>
<69bd3679-e03e-46ac-a93a-443e45bb743an@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 20 Dec 2021 19:04:55 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="b1f42bd3c3915fb259be10ded43720f8";
logging-data="4553"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX198ZgPfGJ+N8xldNWc1of4Kh/LtlicgvPk="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.4.0
Cancel-Lock: sha1:b0ztA8QcLQI2R32IsUTIWfxwzDw=
In-Reply-To: <69bd3679-e03e-46ac-a93a-443e45bb743an@googlegroups.com>
Content-Language: en-US
 by: Stephen Fuld - Mon, 20 Dec 2021 19:04 UTC

On 12/20/2021 9:25 AM, MitchAlsup wrote:
> On Monday, December 20, 2021 at 10:46:40 AM UTC-6, Stephen Fuld wrote:
>> On 12/16/2021 11:28 PM, Thomas Koenig wrote:
>>> Ir. Hj. Othman bin Hj. Ahmad <oth...@gmail.com> schrieb:
>>>
>>>> HLL is very poor in bit manipulations. Better use a library for
>>>> these bit manipulations, so less need for optimization.
>>>
>>> Not really - calling a library function has a _lot_ of overhead,
>>> and what goes on in the library is hidden from the compiler. It is
>>> usually preferred for the compiler to emit highly optimized code.
>>>
>>> These days, compilers will might even recognize some standard
>>> idioms for certain bit manipulations and use a corresponding
>>> machine instruction, if available.
>> A compiler I used to use (it was for Fortran, but this functionality is
>> not Fortran specific) had a pseudo function named "Bits". It looked
>> like a function that accepted three arguments, a variable name and a
>> starting bit number and number of bits, both of which could be a
>> constant or an integer variable. One of its unique properties is that
>> it could also be used on the left hand side of an assignment statement.
>>
>> This feature led to very clear, concise code, that the compiler didn't
>> have to go through a complex algorithms to recognize, and would generate
>> optimal, inline code. There was sort of a pragma that could optionally
>> generate checking code for out of range combinations of length and
>> starting bit number.
>>
>> So, for example, the source code to move two bits starting at bit 3 of
>> variable B to starting at bit 4 of variable A would be
>>
>> Bits (A, 2, 4) = Bits (B, 2, 3)
> <
> A more livable syntax might be:
> <
> A<2:4> = B<2:3>

I have no problem with that. The main point is to eliminate the need
for specifying some sequence of several shift and mask operations in the
source code. Both your suggestion and mine are clearer and less error
prone for the programmer.

--
- Stephen Fuld
(e-mail address disguised to prevent spam)

Re: Dense machine code from C++ code (compiler optimizations)

<spqkjk$7ug$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=22358&group=comp.arch#22358

  copy link   Newsgroups: comp.arch
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: sfu...@alumni.cmu.edu.invalid (Stephen Fuld)
Newsgroups: comp.arch
Subject: Re: Dense machine code from C++ code (compiler optimizations)
Date: Mon, 20 Dec 2021 11:12:50 -0800
Organization: A noiseless patient Spider
Lines: 40
Message-ID: <spqkjk$7ug$1@dont-email.me>
References: <sndun6$q07$1@dont-email.me>
<dc10dfff-b48e-40ec-8c24-0a6c2e1790d2n@googlegroups.com>
<sphe6s$5a3$1@newsreader4.netcologne.de> <spqc1d$oio$1@dont-email.me>
<spqhj2$gdf$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Mon, 20 Dec 2021 19:12:52 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="b1f42bd3c3915fb259be10ded43720f8";
logging-data="8144"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+8P0w+DhSF/WwjB5q/5F3PVipprz3ThnI="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.4.0
Cancel-Lock: sha1:VkK3eiyMJclvTOhP9WFUObMWx3M=
In-Reply-To: <spqhj2$gdf$1@dont-email.me>
Content-Language: en-US
 by: Stephen Fuld - Mon, 20 Dec 2021 19:12 UTC

On 12/20/2021 10:21 AM, James Van Buskirk wrote:
> "Stephen Fuld"  wrote in message news:spqc1d$oio$1@dont-email.me...
>> A compiler I used to use (it was for Fortran, but this functionality
>> is not Fortran specific) had a pseudo function named "Bits".  It
>> looked like a function that accepted three arguments, a variable name
>> and a starting bit number and number of bits, both of which could be a
>> constant or an integer variable.  One of its unique properties is that
>> it could also be used on the left hand side of an assignment statement.
>
>> This feature led to very clear, concise code, that the compiler didn't
>> have to go through a complex algorithms to recognize, and would
>> generate optimal, inline code.  There was sort of a pragma that could
>> optionally generate checking code for out of range combinations of
>> length and starting bit number.
>
>> So, for example, the source code to move two bits starting at bit 3 of
>> variable B to starting at bit 4 of variable A would be
>
>> Bits (A, 2, 4) = Bits (B, 2, 3)
>
>> I always liked this feature, and used it a fair amount.
>
> Compare
> https://gcc.gnu.org/onlinedocs/gfortran/IBITS.html#IBITS
> https://gcc.gnu.org/onlinedocs/gfortran/MVBITS.html#MVBITS
> which are both elemental.

They seem essentially equivalent. It says that these came in with
Fortran 90. The compiler I was referring to had its roots in a
predecessor with a different name that dated back to at least the early
1970s. I am glad the idea became standardized.

I guess I should ask the question that given that C is probably used for
bit manipulation stuff at least as much as Fortran, how come the C
standard didn't pick up some equivalent?

--
- Stephen Fuld
(e-mail address disguised to prevent spam)

Re: Dense machine code from C++ code (compiler optimizations)

<a650f1a3-976f-41a4-8196-83b3ffe8095dn@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=22359&group=comp.arch#22359

  copy link   Newsgroups: comp.arch
X-Received: by 2002:ac8:5e4d:: with SMTP id i13mr5594038qtx.232.1640030812855;
Mon, 20 Dec 2021 12:06:52 -0800 (PST)
X-Received: by 2002:a9d:f45:: with SMTP id 63mr12544737ott.350.1640030812560;
Mon, 20 Dec 2021 12:06:52 -0800 (PST)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.arch
Date: Mon, 20 Dec 2021 12:06:52 -0800 (PST)
In-Reply-To: <spqkjk$7ug$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=2600:1700:291:29f0:e1a7:8791:699c:c121;
posting-account=H_G_JQkAAADS6onOMb-dqvUozKse7mcM
NNTP-Posting-Host: 2600:1700:291:29f0:e1a7:8791:699c:c121
References: <sndun6$q07$1@dont-email.me> <dc10dfff-b48e-40ec-8c24-0a6c2e1790d2n@googlegroups.com>
<sphe6s$5a3$1@newsreader4.netcologne.de> <spqc1d$oio$1@dont-email.me>
<spqhj2$gdf$1@dont-email.me> <spqkjk$7ug$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <a650f1a3-976f-41a4-8196-83b3ffe8095dn@googlegroups.com>
Subject: Re: Dense machine code from C++ code (compiler optimizations)
From: MitchAl...@aol.com (MitchAlsup)
Injection-Date: Mon, 20 Dec 2021 20:06:52 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 44
 by: MitchAlsup - Mon, 20 Dec 2021 20:06 UTC

On Monday, December 20, 2021 at 1:12:54 PM UTC-6, Stephen Fuld wrote:
> On 12/20/2021 10:21 AM, James Van Buskirk wrote:
> > "Stephen Fuld" wrote in message news:spqc1d$oio$1...@dont-email.me...
> >> A compiler I used to use (it was for Fortran, but this functionality
> >> is not Fortran specific) had a pseudo function named "Bits". It
> >> looked like a function that accepted three arguments, a variable name
> >> and a starting bit number and number of bits, both of which could be a
> >> constant or an integer variable. One of its unique properties is that
> >> it could also be used on the left hand side of an assignment statement.
> >
> >> This feature led to very clear, concise code, that the compiler didn't
> >> have to go through a complex algorithms to recognize, and would
> >> generate optimal, inline code. There was sort of a pragma that could
> >> optionally generate checking code for out of range combinations of
> >> length and starting bit number.
> >
> >> So, for example, the source code to move two bits starting at bit 3 of
> >> variable B to starting at bit 4 of variable A would be
> >
> >> Bits (A, 2, 4) = Bits (B, 2, 3)
> >
> >> I always liked this feature, and used it a fair amount.
> >
> > Compare
> > https://gcc.gnu.org/onlinedocs/gfortran/IBITS.html#IBITS
> > https://gcc.gnu.org/onlinedocs/gfortran/MVBITS.html#MVBITS
> > which are both elemental.
> They seem essentially equivalent. It says that these came in with
> Fortran 90. The compiler I was referring to had its roots in a
> predecessor with a different name that dated back to at least the early
> 1970s. I am glad the idea became standardized.
>
> I guess I should ask the question that given that C is probably used for
> bit manipulation stuff at least as much as Fortran, how come the C
> standard didn't pick up some equivalent?
<
{Sarcasm mode=on}
<
Having a straightforward way to succinctly express the requirement is
<ahem> Not 'C'.
<
{Sarcasm mode=stays on}........
> --
> - Stephen Fuld
> (e-mail address disguised to prevent spam)

Re: Dense machine code from C++ code (compiler optimizations)

<sprrq4$3a4$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=22360&group=comp.arch#22360

  copy link   Newsgroups: comp.arch
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: m.del...@this.bitsnbites.eu (Marcus)
Newsgroups: comp.arch
Subject: Re: Dense machine code from C++ code (compiler optimizations)
Date: Tue, 21 Dec 2021 07:21:55 +0100
Organization: A noiseless patient Spider
Lines: 73
Message-ID: <sprrq4$3a4$1@dont-email.me>
References: <sndun6$q07$1@dont-email.me>
<dc10dfff-b48e-40ec-8c24-0a6c2e1790d2n@googlegroups.com>
<sphe6s$5a3$1@newsreader4.netcologne.de> <spqc1d$oio$1@dont-email.me>
<spqhj2$gdf$1@dont-email.me> <spqkjk$7ug$1@dont-email.me>
<a650f1a3-976f-41a4-8196-83b3ffe8095dn@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 21 Dec 2021 06:21:56 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="6e26408f2fd69c57717e7470eb8bf98b";
logging-data="3396"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19bLnocWB89Akrb9+EqIwtr0sg8Fo77seA="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.14.0
Cancel-Lock: sha1:CisbTjIEJaBjvZPhcHBKOOEWIPQ=
In-Reply-To: <a650f1a3-976f-41a4-8196-83b3ffe8095dn@googlegroups.com>
Content-Language: en-US
 by: Marcus - Tue, 21 Dec 2021 06:21 UTC

On 2021-12-20, MitchAlsup wrote:
> On Monday, December 20, 2021 at 1:12:54 PM UTC-6, Stephen Fuld wrote:
>> On 12/20/2021 10:21 AM, James Van Buskirk wrote:
>>> "Stephen Fuld" wrote in message news:spqc1d$oio$1...@dont-email.me...
>>>> A compiler I used to use (it was for Fortran, but this functionality
>>>> is not Fortran specific) had a pseudo function named "Bits". It
>>>> looked like a function that accepted three arguments, a variable name
>>>> and a starting bit number and number of bits, both of which could be a
>>>> constant or an integer variable. One of its unique properties is that
>>>> it could also be used on the left hand side of an assignment statement.
>>>
>>>> This feature led to very clear, concise code, that the compiler didn't
>>>> have to go through a complex algorithms to recognize, and would
>>>> generate optimal, inline code. There was sort of a pragma that could
>>>> optionally generate checking code for out of range combinations of
>>>> length and starting bit number.
>>>
>>>> So, for example, the source code to move two bits starting at bit 3 of
>>>> variable B to starting at bit 4 of variable A would be
>>>
>>>> Bits (A, 2, 4) = Bits (B, 2, 3)
>>>
>>>> I always liked this feature, and used it a fair amount.
>>>
>>> Compare
>>> https://gcc.gnu.org/onlinedocs/gfortran/IBITS.html#IBITS
>>> https://gcc.gnu.org/onlinedocs/gfortran/MVBITS.html#MVBITS
>>> which are both elemental.
>> They seem essentially equivalent. It says that these came in with
>> Fortran 90. The compiler I was referring to had its roots in a
>> predecessor with a different name that dated back to at least the early
>> 1970s. I am glad the idea became standardized.
>>
>> I guess I should ask the question that given that C is probably used for
>> bit manipulation stuff at least as much as Fortran, how come the C
>> standard didn't pick up some equivalent?
> <
> {Sarcasm mode=on}
> <
> Having a straightforward way to succinctly express the requirement is
> <ahem> Not 'C'.
> <
> {Sarcasm mode=stays on}........

How about this quick hack in C++... ;-)

It compiles to bit field instructions on ARM:
https://godbolt.org/z/78K3s1cs1

#include <cstring>

// Helper struct.
template <unsigned POS, unsigned LEN, typename T>
struct ipos_helper {
T _1 : POS;
T x : LEN;
};

// Extract bit field.
template <unsigned POS, unsigned LEN, typename T>
T ipos(T x) {
ipos_helper<POS, LEN, T> helper;
static_assert(sizeof(helper) >= sizeof(T));
std::memcpy(&helper, &x, sizeof(T));
return helper.x;
}

unsigned test(unsigned num) {
return ipos<4, 9>(num);
}

/Marcus

Re: Dense machine code from C++ code (compiler optimizations)

<spsc75$an1$1@gioia.aioe.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=22361&group=comp.arch#22361

  copy link   Newsgroups: comp.arch
Path: i2pn2.org!i2pn.org!aioe.org!rd9pRsUZyxkRLAEK7e/Uzw.user.46.165.242.91.POSTED!not-for-mail
From: terje.ma...@tmsw.no (Terje Mathisen)
Newsgroups: comp.arch
Subject: Re: Dense machine code from C++ code (compiler optimizations)
Date: Tue, 21 Dec 2021 12:01:59 +0100
Organization: Aioe.org NNTP Server
Message-ID: <spsc75$an1$1@gioia.aioe.org>
References: <sndun6$q07$1@dont-email.me>
<dc10dfff-b48e-40ec-8c24-0a6c2e1790d2n@googlegroups.com>
<sphe6s$5a3$1@newsreader4.netcologne.de> <spqc1d$oio$1@dont-email.me>
<spqhj2$gdf$1@dont-email.me> <spqkjk$7ug$1@dont-email.me>
<a650f1a3-976f-41a4-8196-83b3ffe8095dn@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Info: gioia.aioe.org; logging-data="10977"; posting-host="rd9pRsUZyxkRLAEK7e/Uzw.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:68.0) Gecko/20100101
Firefox/68.0 SeaMonkey/2.53.10.1
X-Notice: Filtered by postfilter v. 0.9.2
 by: Terje Mathisen - Tue, 21 Dec 2021 11:01 UTC

MitchAlsup wrote:
> On Monday, December 20, 2021 at 1:12:54 PM UTC-6, Stephen Fuld wrote:
>> On 12/20/2021 10:21 AM, James Van Buskirk wrote:
>>> Compare
>>> https://gcc.gnu.org/onlinedocs/gfortran/IBITS.html#IBITS
>>> https://gcc.gnu.org/onlinedocs/gfortran/MVBITS.html#MVBITS
>>> which are both elemental.
>> They seem essentially equivalent. It says that these came in with
>> Fortran 90. The compiler I was referring to had its roots in a
>> predecessor with a different name that dated back to at least the early
>> 1970s. I am glad the idea became standardized.
>>
>> I guess I should ask the question that given that C is probably used for
>> bit manipulation stuff at least as much as Fortran, how come the C
>> standard didn't pick up some equivalent?
> <
> {Sarcasm mode=on}
> <
> Having a straightforward way to succinctly express the requirement is
> <ahem> Not 'C'.
> <
> {Sarcasm mode=stays on}........

My guess would be that since this effectively requires a fixed bit
ordering within bytes/words, and we already had cpus numbering the bits
from the top as well as up from the bottom, this one was a non-starter
since it would penalize at least one of the alternatives?

Terje

--
- <Terje.Mathisen at tmsw.no>
"almost all programming can be viewed as an exercise in caching"

Re: Dense machine code from C++ code (compiler optimizations)

<874k72qjre.fsf@eder.anydns.info>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=22362&group=comp.arch#22362

  copy link   Newsgroups: comp.arch
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: a_eder_...@web.de (Andreas Eder)
Newsgroups: comp.arch
Subject: Re: Dense machine code from C++ code (compiler optimizations)
Date: Tue, 21 Dec 2021 12:28:53 +0100
Organization: A noiseless patient Spider
Lines: 27
Message-ID: <874k72qjre.fsf@eder.anydns.info>
References: <sndun6$q07$1@dont-email.me>
<dc10dfff-b48e-40ec-8c24-0a6c2e1790d2n@googlegroups.com>
<sphe6s$5a3$1@newsreader4.netcologne.de> <spqc1d$oio$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: reader02.eternal-september.org; posting-host="b21e6749fa93f4088676c9b7ba4e6f70";
logging-data="15087"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19jBihYyhuaNnXXn1brjSRg"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux)
Cancel-Lock: sha1:E/0OD2+zooU6tKRYXElM72HkRe8=
sha1:+i2Qqcz2nPFedsVpkgBR5zhVaiY=
 by: Andreas Eder - Tue, 21 Dec 2021 11:28 UTC

On Mo 20 Dez 2021 at 08:46, Stephen Fuld <sfuld@alumni.cmu.edu.invalid> wrote:

> A compiler I used to use (it was for Fortran, but this functionality is
> not Fortran specific) had a pseudo function named "Bits". It looked
> like a function that accepted three arguments, a variable name and a
> starting bit number and number of bits, both of which could be a
> constant or an integer variable. One of its unique properties is that
> it could also be used on the left hand side of an assignment statement.
>
> This feature led to very clear, concise code, that the compiler didn't
> have to go through a complex algorithms to recognize, and would generate
> optimal, inline code. There was sort of a pragma that could optionally
> generate checking code for out of range combinations of length and
> starting bit number.
>
> So, for example, the source code to move two bits starting at bit 3 of
> variable B to starting at bit 4 of variable A would be
>
> Bits (A, 2, 4) = Bits (B, 2, 3)
>
> I always liked this feature, and used it a fair amount.

This reminds me of the ldb and dpb functions in Common Lisp:
(http://www.lispworks.com/documentation/HyperSpec/Body/f_dpb.htm
http://www.lispworks.com/documentation/HyperSpec/Body/f_ldb.htm)

'Andreas

Re: Dense machine code from C++ code (compiler optimizations)

<spsv1b$b37$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=22364&group=comp.arch#22364

  copy link   Newsgroups: comp.arch
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: sfu...@alumni.cmu.edu.invalid (Stephen Fuld)
Newsgroups: comp.arch
Subject: Re: Dense machine code from C++ code (compiler optimizations)
Date: Tue, 21 Dec 2021 08:23:05 -0800
Organization: A noiseless patient Spider
Lines: 46
Message-ID: <spsv1b$b37$1@dont-email.me>
References: <sndun6$q07$1@dont-email.me>
<dc10dfff-b48e-40ec-8c24-0a6c2e1790d2n@googlegroups.com>
<sphe6s$5a3$1@newsreader4.netcologne.de> <spqc1d$oio$1@dont-email.me>
<spqhj2$gdf$1@dont-email.me> <spqkjk$7ug$1@dont-email.me>
<a650f1a3-976f-41a4-8196-83b3ffe8095dn@googlegroups.com>
<spsc75$an1$1@gioia.aioe.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 21 Dec 2021 16:23:07 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="0affbe66f6740e5efd5f149a2fed0e01";
logging-data="11367"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18RuM4cBQgmf8J/mn1bQht+KYgVSZlPWOk="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.4.0
Cancel-Lock: sha1:jJoaNcPzDvl1s2N700F45hWwz0M=
In-Reply-To: <spsc75$an1$1@gioia.aioe.org>
Content-Language: en-US
 by: Stephen Fuld - Tue, 21 Dec 2021 16:23 UTC

On 12/21/2021 3:01 AM, Terje Mathisen wrote:
> MitchAlsup wrote:
>> On Monday, December 20, 2021 at 1:12:54 PM UTC-6, Stephen Fuld wrote:
>>> On 12/20/2021 10:21 AM, James Van Buskirk wrote:
>>>> Compare
>>>> https://gcc.gnu.org/onlinedocs/gfortran/IBITS.html#IBITS
>>>> https://gcc.gnu.org/onlinedocs/gfortran/MVBITS.html#MVBITS
>>>> which are both elemental.
>>> They seem essentially equivalent. It says that these came in with
>>> Fortran 90. The compiler I was referring to had its roots in a
>>> predecessor with a different name that dated back to at least the early
>>> 1970s. I am glad the idea became standardized.
>>>
>>> I guess I should ask the question that given that C is probably used for
>>> bit manipulation stuff at least as much as Fortran, how come the C
>>> standard didn't pick up some equivalent?
>> <
>> {Sarcasm mode=on}
>> <
>> Having a straightforward way to succinctly express the requirement is
>> <ahem> Not 'C'.
>> <
>> {Sarcasm mode=stays on}........
>
> My guess would be that since this effectively requires a fixed bit
> ordering within bytes/words, and we already had cpus numbering the bits
> from the top as well as up from the bottom, this one was a non-starter
> since it would penalize at least one of the alternatives?

Could be. I think there are two issues here. Big/little where the
actual order in memory is different, and numbering conventions, where
only the names change. Coding a sequence of shifts and masks is also
not portable to big/little endian designs, etc. so this is no different.

As for the numbering conventions, one could have the compiler be
sensitive to different ordering conventions and change the meaning of
the arguments appropriately depending upon target architecture. This
would make coding for any particular architecture consistent with that
architecture's conventions, but probably doesn't help portability, and I
am not sure it is a good idea. But I am not sure that "hiding" the
differences under a sequence of shifts and masks is any better.

--
- Stephen Fuld
(e-mail address disguised to prevent spam)

Re: Dense machine code from C++ code (compiler optimizations)

<lvnwJ.64876$cW6.20831@fx08.iad>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=22366&group=comp.arch#22366

  copy link   Newsgroups: comp.arch
Path: i2pn2.org!i2pn.org!paganini.bofh.team!news.dns-netz.com!news.freedyn.de!newsreader4.netcologne.de!news.netcologne.de!peer01.ams1!peer.ams1.xlned.com!news.xlned.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx08.iad.POSTED!not-for-mail
From: ThatWoul...@thevillage.com (EricP)
User-Agent: Thunderbird 2.0.0.24 (Windows/20100228)
MIME-Version: 1.0
Newsgroups: comp.arch
Subject: Re: Dense machine code from C++ code (compiler optimizations)
References: <sndun6$q07$1@dont-email.me> <dc10dfff-b48e-40ec-8c24-0a6c2e1790d2n@googlegroups.com> <sphe6s$5a3$1@newsreader4.netcologne.de> <spqc1d$oio$1@dont-email.me> <spqhj2$gdf$1@dont-email.me> <spqkjk$7ug$1@dont-email.me> <a650f1a3-976f-41a4-8196-83b3ffe8095dn@googlegroups.com> <spsc75$an1$1@gioia.aioe.org> <spsv1b$b37$1@dont-email.me>
In-Reply-To: <spsv1b$b37$1@dont-email.me>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Lines: 52
Message-ID: <lvnwJ.64876$cW6.20831@fx08.iad>
X-Complaints-To: abuse@UsenetServer.com
NNTP-Posting-Date: Tue, 21 Dec 2021 16:44:01 UTC
Date: Tue, 21 Dec 2021 11:44:04 -0500
X-Received-Bytes: 3575
 by: EricP - Tue, 21 Dec 2021 16:44 UTC

Stephen Fuld wrote:
> On 12/21/2021 3:01 AM, Terje Mathisen wrote:
>> MitchAlsup wrote:
>>> On Monday, December 20, 2021 at 1:12:54 PM UTC-6, Stephen Fuld wrote:
>>>> On 12/20/2021 10:21 AM, James Van Buskirk wrote:
>>>>> Compare
>>>>> https://gcc.gnu.org/onlinedocs/gfortran/IBITS.html#IBITS
>>>>> https://gcc.gnu.org/onlinedocs/gfortran/MVBITS.html#MVBITS
>>>>> which are both elemental.
>>>> They seem essentially equivalent. It says that these came in with
>>>> Fortran 90. The compiler I was referring to had its roots in a
>>>> predecessor with a different name that dated back to at least the early
>>>> 1970s. I am glad the idea became standardized.
>>>>
>>>> I guess I should ask the question that given that C is probably used
>>>> for
>>>> bit manipulation stuff at least as much as Fortran, how come the C
>>>> standard didn't pick up some equivalent?
>>> <
>>> {Sarcasm mode=on}
>>> <
>>> Having a straightforward way to succinctly express the requirement is
>>> <ahem> Not 'C'.
>>> <
>>> {Sarcasm mode=stays on}........
>>
>> My guess would be that since this effectively requires a fixed bit
>> ordering within bytes/words, and we already had cpus numbering the
>> bits from the top as well as up from the bottom, this one was a
>> non-starter since it would penalize at least one of the alternatives?
>
> Could be. I think there are two issues here. Big/little where the
> actual order in memory is different, and numbering conventions, where
> only the names change. Coding a sequence of shifts and masks is also
> not portable to big/little endian designs, etc. so this is no different.
>
> As for the numbering conventions, one could have the compiler be
> sensitive to different ordering conventions and change the meaning of
> the arguments appropriately depending upon target architecture. This
> would make coding for any particular architecture consistent with that
> architecture's conventions, but probably doesn't help portability, and I
> am not sure it is a good idea. But I am not sure that "hiding" the
> differences under a sequence of shifts and masks is any better.

In C the order in which bit fields in a struct are concatenated
is implementation dependent. It matters for unions.

In Verilog I think almost everything is little endian except,
strangely, the order of bit fields in a struct which is big endian.
(I find it strange because it is such a glaring wart that you'd think
someone would have noticed it during the language design phase.)

Re: Dense machine code from C++ code (compiler optimizations)

<8f03eabb-37b8-4723-bc94-f4c3a3f1e7a7n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=22367&group=comp.arch#22367

  copy link   Newsgroups: comp.arch
X-Received: by 2002:a05:620a:25ca:: with SMTP id y10mr2750461qko.526.1640107865288;
Tue, 21 Dec 2021 09:31:05 -0800 (PST)
X-Received: by 2002:a05:6830:2b20:: with SMTP id l32mr2962136otv.333.1640107865031;
Tue, 21 Dec 2021 09:31:05 -0800 (PST)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.arch
Date: Tue, 21 Dec 2021 09:31:04 -0800 (PST)
In-Reply-To: <lvnwJ.64876$cW6.20831@fx08.iad>
Injection-Info: google-groups.googlegroups.com; posting-host=2600:1700:291:29f0:acc6:5615:3a25:3fe7;
posting-account=H_G_JQkAAADS6onOMb-dqvUozKse7mcM
NNTP-Posting-Host: 2600:1700:291:29f0:acc6:5615:3a25:3fe7
References: <sndun6$q07$1@dont-email.me> <dc10dfff-b48e-40ec-8c24-0a6c2e1790d2n@googlegroups.com>
<sphe6s$5a3$1@newsreader4.netcologne.de> <spqc1d$oio$1@dont-email.me>
<spqhj2$gdf$1@dont-email.me> <spqkjk$7ug$1@dont-email.me> <a650f1a3-976f-41a4-8196-83b3ffe8095dn@googlegroups.com>
<spsc75$an1$1@gioia.aioe.org> <spsv1b$b37$1@dont-email.me> <lvnwJ.64876$cW6.20831@fx08.iad>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <8f03eabb-37b8-4723-bc94-f4c3a3f1e7a7n@googlegroups.com>
Subject: Re: Dense machine code from C++ code (compiler optimizations)
From: MitchAl...@aol.com (MitchAlsup)
Injection-Date: Tue, 21 Dec 2021 17:31:05 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 65
 by: MitchAlsup - Tue, 21 Dec 2021 17:31 UTC

On Tuesday, December 21, 2021 at 10:44:04 AM UTC-6, EricP wrote:
> Stephen Fuld wrote:
> > On 12/21/2021 3:01 AM, Terje Mathisen wrote:
> >> MitchAlsup wrote:
> >>> On Monday, December 20, 2021 at 1:12:54 PM UTC-6, Stephen Fuld wrote:
> >>>> On 12/20/2021 10:21 AM, James Van Buskirk wrote:
> >>>>> Compare
> >>>>> https://gcc.gnu.org/onlinedocs/gfortran/IBITS.html#IBITS
> >>>>> https://gcc.gnu.org/onlinedocs/gfortran/MVBITS.html#MVBITS
> >>>>> which are both elemental.
> >>>> They seem essentially equivalent. It says that these came in with
> >>>> Fortran 90. The compiler I was referring to had its roots in a
> >>>> predecessor with a different name that dated back to at least the early
> >>>> 1970s. I am glad the idea became standardized.
> >>>>
> >>>> I guess I should ask the question that given that C is probably used
> >>>> for
> >>>> bit manipulation stuff at least as much as Fortran, how come the C
> >>>> standard didn't pick up some equivalent?
> >>> <
> >>> {Sarcasm mode=on}
> >>> <
> >>> Having a straightforward way to succinctly express the requirement is
> >>> <ahem> Not 'C'.
> >>> <
> >>> {Sarcasm mode=stays on}........
> >>
> >> My guess would be that since this effectively requires a fixed bit
> >> ordering within bytes/words, and we already had cpus numbering the
> >> bits from the top as well as up from the bottom, this one was a
> >> non-starter since it would penalize at least one of the alternatives?
> >
> > Could be. I think there are two issues here. Big/little where the
> > actual order in memory is different, and numbering conventions, where
> > only the names change. Coding a sequence of shifts and masks is also
> > not portable to big/little endian designs, etc. so this is no different.
> >
> > As for the numbering conventions, one could have the compiler be
> > sensitive to different ordering conventions and change the meaning of
> > the arguments appropriately depending upon target architecture. This
> > would make coding for any particular architecture consistent with that
> > architecture's conventions, but probably doesn't help portability, and I
> > am not sure it is a good idea. But I am not sure that "hiding" the
> > differences under a sequence of shifts and masks is any better.
> In C the order in which bit fields in a struct are concatenated
> is implementation dependent. It matters for unions.
>
> In Verilog I think almost everything is little endian except,
> strangely, the order of bit fields in a struct which is big endian.
> (I find it strange because it is such a glaring wart that you'd think
> someone would have noticed it during the language design phase.)
<
Verilog is biEndian (or Endian Free).
<
One can write:
<
a[3:5] = b[5:3];
<
And the bits are reversed !
<
In Verilog bits are just wires (most of the time), wires can be taken in any order:
<
a[3:12] = (b[5:3],b[6:12]);
<
Which reverses 3 bits and copies 6 more. It really helps just to think of them as wires
and assignment as a wiring order.

Re: Dense machine code from C++ code (compiler optimizations)

<CiqwJ.142768$Wkjc.45146@fx35.iad>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=22368&group=comp.arch#22368

  copy link   Newsgroups: comp.arch
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!newsreader4.netcologne.de!news.netcologne.de!peer02.ams1!peer.ams1.xlned.com!news.xlned.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx35.iad.POSTED!not-for-mail
From: ThatWoul...@thevillage.com (EricP)
User-Agent: Thunderbird 2.0.0.24 (Windows/20100228)
MIME-Version: 1.0
Newsgroups: comp.arch
Subject: Re: Dense machine code from C++ code (compiler optimizations)
References: <sndun6$q07$1@dont-email.me> <dc10dfff-b48e-40ec-8c24-0a6c2e1790d2n@googlegroups.com> <sphe6s$5a3$1@newsreader4.netcologne.de> <spqc1d$oio$1@dont-email.me> <spqhj2$gdf$1@dont-email.me> <spqkjk$7ug$1@dont-email.me> <a650f1a3-976f-41a4-8196-83b3ffe8095dn@googlegroups.com> <spsc75$an1$1@gioia.aioe.org> <spsv1b$b37$1@dont-email.me> <lvnwJ.64876$cW6.20831@fx08.iad> <8f03eabb-37b8-4723-bc94-f4c3a3f1e7a7n@googlegroups.com>
In-Reply-To: <8f03eabb-37b8-4723-bc94-f4c3a3f1e7a7n@googlegroups.com>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Lines: 55
Message-ID: <CiqwJ.142768$Wkjc.45146@fx35.iad>
X-Complaints-To: abuse@UsenetServer.com
NNTP-Posting-Date: Tue, 21 Dec 2021 19:55:14 UTC
Date: Tue, 21 Dec 2021 14:54:28 -0500
X-Received-Bytes: 3131
 by: EricP - Tue, 21 Dec 2021 19:54 UTC

MitchAlsup wrote:
> On Tuesday, December 21, 2021 at 10:44:04 AM UTC-6, EricP wrote:
>>
>> In Verilog I think almost everything is little endian except,
>> strangely, the order of bit fields in a struct which is big endian.
>> (I find it strange because it is such a glaring wart that you'd think
>> someone would have noticed it during the language design phase.)
> <
> Verilog is biEndian (or Endian Free).
> <
> One can write:
> <
> a[3:5] = b[5:3];
> <
> And the bits are reversed !
> <
> In Verilog bits are just wires (most of the time), wires can be taken in any order:
> <
> a[3:12] = (b[5:3],b[6:12]);
> <
> Which reverses 3 bits and copies 6 more. It really helps just to think of them as wires
> and assignment as a wiring order.

Certain things are hardwired to behave little endian.

Yes for a single field you can declare that the bits are named
from left-low to right-high, or left-high to right-low,
which is endian neutral.

However I got the impression that if you actually tried to use
big endian ordering that certain things would behave anomalously.
e.g. while bits may be named in big endian high to low order,
array elements are always numbered in little endian low to high order.
A unioned array the lowest index always accesses the lsb of an overlay,
irrespective of naming of element bits.

For example

typedef union packed
{
bit [0:7] vecA[10:1]; // 10 big endian bytes
bit vecB[80]; // 80 bits numbered [79:0]
} MyUnion;

that the lsb of vecA[1][7:7] would overlay the lsb of vecB[0].

Also while the fields of a struct are packed in left to right or
big endian order, the whole of a struct or union can be accessed
as a bit field with range [n-1:0] which is little endian order.

It looks to me that since the language shows a preference for
little endian that one should stick to it to avoid gotcha's.
And just watch out for the order of struct field packing.

Re: Dense machine code from C++ code (compiler optimizations)

<e956f13d-4e49-418d-99a4-29bd663a30c4n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=22369&group=comp.arch#22369

  copy link   Newsgroups: comp.arch
X-Received: by 2002:a05:6214:5286:: with SMTP id kj6mr565495qvb.74.1640129883128;
Tue, 21 Dec 2021 15:38:03 -0800 (PST)
X-Received: by 2002:a05:6808:11c5:: with SMTP id p5mr505508oiv.51.1640129882835;
Tue, 21 Dec 2021 15:38:02 -0800 (PST)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.arch
Date: Tue, 21 Dec 2021 15:38:02 -0800 (PST)
In-Reply-To: <CiqwJ.142768$Wkjc.45146@fx35.iad>
Injection-Info: google-groups.googlegroups.com; posting-host=2600:1700:291:29f0:d468:a7b5:b2de:657;
posting-account=H_G_JQkAAADS6onOMb-dqvUozKse7mcM
NNTP-Posting-Host: 2600:1700:291:29f0:d468:a7b5:b2de:657
References: <sndun6$q07$1@dont-email.me> <dc10dfff-b48e-40ec-8c24-0a6c2e1790d2n@googlegroups.com>
<sphe6s$5a3$1@newsreader4.netcologne.de> <spqc1d$oio$1@dont-email.me>
<spqhj2$gdf$1@dont-email.me> <spqkjk$7ug$1@dont-email.me> <a650f1a3-976f-41a4-8196-83b3ffe8095dn@googlegroups.com>
<spsc75$an1$1@gioia.aioe.org> <spsv1b$b37$1@dont-email.me>
<lvnwJ.64876$cW6.20831@fx08.iad> <8f03eabb-37b8-4723-bc94-f4c3a3f1e7a7n@googlegroups.com>
<CiqwJ.142768$Wkjc.45146@fx35.iad>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <e956f13d-4e49-418d-99a4-29bd663a30c4n@googlegroups.com>
Subject: Re: Dense machine code from C++ code (compiler optimizations)
From: MitchAl...@aol.com (MitchAlsup)
Injection-Date: Tue, 21 Dec 2021 23:38:03 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 55
 by: MitchAlsup - Tue, 21 Dec 2021 23:38 UTC

On Tuesday, December 21, 2021 at 1:55:17 PM UTC-6, EricP wrote:
> MitchAlsup wrote:
> > On Tuesday, December 21, 2021 at 10:44:04 AM UTC-6, EricP wrote:
> >>
> >> In Verilog I think almost everything is little endian except,
> >> strangely, the order of bit fields in a struct which is big endian.
> >> (I find it strange because it is such a glaring wart that you'd think
> >> someone would have noticed it during the language design phase.)
> > <
> > Verilog is biEndian (or Endian Free).
> > <
> > One can write:
> > <
> > a[3:5] = b[5:3];
> > <
> > And the bits are reversed !
> > <
> > In Verilog bits are just wires (most of the time), wires can be taken in any order:
> > <
> > a[3:12] = (b[5:3],b[6:12]);
> > <
> > Which reverses 3 bits and copies 6 more. It really helps just to think of them as wires
> > and assignment as a wiring order.
> Certain things are hardwired to behave little endian.
>
> Yes for a single field you can declare that the bits are named
> from left-low to right-high, or left-high to right-low,
> which is endian neutral.
>
> However I got the impression that if you actually tried to use
> big endian ordering that certain things would behave anomalously.
> e.g. while bits may be named in big endian high to low order,
> array elements are always numbered in little endian low to high order.
> A unioned array the lowest index always accesses the lsb of an overlay,
> irrespective of naming of element bits.
>
> For example
>
> typedef union packed
> {
> bit [0:7] vecA[10:1]; // 10 big endian bytes
> bit vecB[80]; // 80 bits numbered [79:0]
> } MyUnion;
>
> that the lsb of vecA[1][7:7] would overlay the lsb of vecB[0].
>
> Also while the fields of a struct are packed in left to right or
> big endian order, the whole of a struct or union can be accessed
> as a bit field with range [n-1:0] which is little endian order.
>
> It looks to me that since the language shows a preference for
> little endian that one should stick to it to avoid gotcha's.
> And just watch out for the order of struct field packing.
<
Perhaps it is best said that Verilog is Endian neutral,
and that some things are more naturally expressed in Little Endian.

Re: Dense machine code from C++ code (compiler optimizations)

<BQJwJ.246048$I%1.202866@fx36.iad>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=22378&group=comp.arch#22378

  copy link   Newsgroups: comp.arch
Path: i2pn2.org!i2pn.org!paganini.bofh.team!news.dns-netz.com!news.freedyn.de!newsfeed.xs4all.nl!newsfeed7.news.xs4all.nl!news.uzoreto.com!news-out.netnews.com!news.alt.net!fdc2.netnews.com!peer01.ams1!peer.ams1.xlned.com!news.xlned.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx36.iad.POSTED!not-for-mail
From: ThatWoul...@thevillage.com (EricP)
User-Agent: Thunderbird 2.0.0.24 (Windows/20100228)
MIME-Version: 1.0
Newsgroups: comp.arch
Subject: Re: Dense machine code from C++ code (compiler optimizations)
References: <sndun6$q07$1@dont-email.me> <dc10dfff-b48e-40ec-8c24-0a6c2e1790d2n@googlegroups.com> <sphe6s$5a3$1@newsreader4.netcologne.de> <spqc1d$oio$1@dont-email.me> <spqhj2$gdf$1@dont-email.me> <spqkjk$7ug$1@dont-email.me> <a650f1a3-976f-41a4-8196-83b3ffe8095dn@googlegroups.com> <spsc75$an1$1@gioia.aioe.org> <spsv1b$b37$1@dont-email.me> <lvnwJ.64876$cW6.20831@fx08.iad> <8f03eabb-37b8-4723-bc94-f4c3a3f1e7a7n@googlegroups.com> <CiqwJ.142768$Wkjc.45146@fx35.iad> <e956f13d-4e49-418d-99a4-29bd663a30c4n@googlegroups.com>
In-Reply-To: <e956f13d-4e49-418d-99a4-29bd663a30c4n@googlegroups.com>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Lines: 69
Message-ID: <BQJwJ.246048$I%1.202866@fx36.iad>
X-Complaints-To: abuse@UsenetServer.com
NNTP-Posting-Date: Wed, 22 Dec 2021 18:08:33 UTC
Date: Wed, 22 Dec 2021 13:08:06 -0500
X-Received-Bytes: 4106
 by: EricP - Wed, 22 Dec 2021 18:08 UTC

MitchAlsup wrote:
> On Tuesday, December 21, 2021 at 1:55:17 PM UTC-6, EricP wrote:
>> MitchAlsup wrote:
>>> On Tuesday, December 21, 2021 at 10:44:04 AM UTC-6, EricP wrote:
>>>> In Verilog I think almost everything is little endian except,
>>>> strangely, the order of bit fields in a struct which is big endian.
>>>> (I find it strange because it is such a glaring wart that you'd think
>>>> someone would have noticed it during the language design phase.)
>>> <
>>> Verilog is biEndian (or Endian Free).
>>> <
>>> One can write:
>>> <
>>> a[3:5] = b[5:3];
>>> <
>>> And the bits are reversed !
>>> <
>>> In Verilog bits are just wires (most of the time), wires can be taken in any order:
>>> <
>>> a[3:12] = (b[5:3],b[6:12]);
>>> <
>>> Which reverses 3 bits and copies 6 more. It really helps just to think of them as wires
>>> and assignment as a wiring order.
>> Certain things are hardwired to behave little endian.
>>
>> Yes for a single field you can declare that the bits are named
>> from left-low to right-high, or left-high to right-low,
>> which is endian neutral.
>>
>> However I got the impression that if you actually tried to use
>> big endian ordering that certain things would behave anomalously.
>> e.g. while bits may be named in big endian high to low order,
>> array elements are always numbered in little endian low to high order.
>> A unioned array the lowest index always accesses the lsb of an overlay,
>> irrespective of naming of element bits.
>>
>> For example
>>
>> typedef union packed
>> {
>> bit [0:7] vecA[10:1]; // 10 big endian bytes
>> bit vecB[80]; // 80 bits numbered [79:0]
>> } MyUnion;
>>
>> that the lsb of vecA[1][7:7] would overlay the lsb of vecB[0].
>>
>> Also while the fields of a struct are packed in left to right or
>> big endian order, the whole of a struct or union can be accessed
>> as a bit field with range [n-1:0] which is little endian order.
>>
>> It looks to me that since the language shows a preference for
>> little endian that one should stick to it to avoid gotcha's.
>> And just watch out for the order of struct field packing.
> <
> Perhaps it is best said that Verilog is Endian neutral,
> and that some things are more naturally expressed in Little Endian.

A more straight forward example:
a 16 bit halfword unioned onto a 2 byte array.
In Verilog array[0] overlays the least significant byte of the word as it
does on a little endian machine, irrespective of how the bits are numbered.

With LE bit numbering a bit address trivially chops into a
byte/halfword/word array index and bit offsett, to denote the same bit.
With BE bit numbering a bit address selects different bits
depending on whether it is a byte or half or word array index.
That is where the potential gotcha's creep in.

Re: Dense machine code from C++ code (compiler optimizations)

<86mtks1j79.fsf@linuxsc.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=22380&group=comp.arch#22380

  copy link   Newsgroups: comp.arch
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: tr.17...@z991.linuxsc.com (Tim Rentsch)
Newsgroups: comp.arch
Subject: Re: Dense machine code from C++ code (compiler optimizations)
Date: Wed, 22 Dec 2021 12:24:42 -0800
Organization: A noiseless patient Spider
Lines: 47
Message-ID: <86mtks1j79.fsf@linuxsc.com>
References: <sndun6$q07$1@dont-email.me> <dc10dfff-b48e-40ec-8c24-0a6c2e1790d2n@googlegroups.com> <sphe6s$5a3$1@newsreader4.netcologne.de> <spqc1d$oio$1@dont-email.me> <spqhj2$gdf$1@dont-email.me> <spqkjk$7ug$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: reader02.eternal-september.org; posting-host="87d859bbdbd04ca6adc497ba3d90e845";
logging-data="5957"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19/OvKqHa1PmGMd2ZBfrBiUjdKlOgaCV9s="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:mD0zJruEIrPQCvUMjcR/qpe5UrU=
sha1:hPitkMVm0MGKexM18SdQlgktZvE=
 by: Tim Rentsch - Wed, 22 Dec 2021 20:24 UTC

Stephen Fuld <sfuld@alumni.cmu.edu.invalid> writes:

> On 12/20/2021 10:21 AM, James Van Buskirk wrote:
>
>> "Stephen Fuld" wrote in message news:spqc1d$oio$1@dont-email.me...
>>
>>> A compiler I used to use (it was for Fortran, but this
>>> functionality is not Fortran specific) had a pseudo function named
>>> "Bits". It looked like a function that accepted three arguments,
>>> a variable name and a starting bit number and number of bits, both
>>> of which could be a constant or an integer variable. One of its
>>> unique properties is that it could also be used on the left hand
>>> side of an assignment statement.
>>>
>>> This feature led to very clear, concise code, that the compiler
>>> didn't have to go through a complex algorithms to recognize, and
>>> would generate optimal, inline code. There was sort of a pragma
>>> that could optionally generate checking code for out of range
>>> combinations of length and starting bit number.
>>>
>>> So, for example, the source code to move two bits starting at bit
>>> 3 of variable B to starting at bit 4 of variable A would be
>>>
>>> Bits (A, 2, 4) = Bits (B, 2, 3)
>>>
>>> I always liked this feature, and used it a fair amount.
>>
>> Compare
>> https://gcc.gnu.org/onlinedocs/gfortran/IBITS.html#IBITS
>> https://gcc.gnu.org/onlinedocs/gfortran/MVBITS.html#MVBITS
>> which are both elemental.
>
> They seem essentially equivalent. It says that these came in with
> Fortran 90. The compiler I was referring to had its roots in a
> predecessor with a different name that dated back to at least the
> early 1970s. I am glad the idea became standardized.
>
> I guess I should ask the question that given that C is probably used
> for bit manipulation stuff at least as much as Fortran, how come the
> C standard didn't pick up some equivalent?

Not necessarily an answer but an observation: in C no new language
feature is needed, because C has the C preprocessor. It isn't hard
to write a macro that does the necessary shifting and masking (and
these days compilers are mostly smart enough to recognize the common
patterns and translate them efficiently and in machine-specific
ways).

Re: Dense machine code from C++ code (compiler optimizations)

<sq2acu$hg3$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=22384&group=comp.arch#22384

  copy link   Newsgroups: comp.arch
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: sfu...@alumni.cmu.edu.invalid (Stephen Fuld)
Newsgroups: comp.arch
Subject: Re: Dense machine code from C++ code (compiler optimizations)
Date: Thu, 23 Dec 2021 09:07:40 -0800
Organization: A noiseless patient Spider
Lines: 74
Message-ID: <sq2acu$hg3$1@dont-email.me>
References: <sndun6$q07$1@dont-email.me>
<dc10dfff-b48e-40ec-8c24-0a6c2e1790d2n@googlegroups.com>
<sphe6s$5a3$1@newsreader4.netcologne.de> <spqc1d$oio$1@dont-email.me>
<spqhj2$gdf$1@dont-email.me> <spqkjk$7ug$1@dont-email.me>
<86mtks1j79.fsf@linuxsc.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 23 Dec 2021 17:07:42 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="a1cbc4ff726890647a88cb892a4ab8bb";
logging-data="17923"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18P7QcDpfZ0r2nDJ4wQx4/hNFQCGSOnia4="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.4.1
Cancel-Lock: sha1:CicykdQIhqcnUFponXdpYY9ffkc=
In-Reply-To: <86mtks1j79.fsf@linuxsc.com>
Content-Language: en-US
 by: Stephen Fuld - Thu, 23 Dec 2021 17:07 UTC

On 12/22/2021 12:24 PM, Tim Rentsch wrote:
> Stephen Fuld <sfuld@alumni.cmu.edu.invalid> writes:
>
>> On 12/20/2021 10:21 AM, James Van Buskirk wrote:
>>
>>> "Stephen Fuld" wrote in message news:spqc1d$oio$1@dont-email.me...
>>>
>>>> A compiler I used to use (it was for Fortran, but this
>>>> functionality is not Fortran specific) had a pseudo function named
>>>> "Bits". It looked like a function that accepted three arguments,
>>>> a variable name and a starting bit number and number of bits, both
>>>> of which could be a constant or an integer variable. One of its
>>>> unique properties is that it could also be used on the left hand
>>>> side of an assignment statement.
>>>>
>>>> This feature led to very clear, concise code, that the compiler
>>>> didn't have to go through a complex algorithms to recognize, and
>>>> would generate optimal, inline code. There was sort of a pragma
>>>> that could optionally generate checking code for out of range
>>>> combinations of length and starting bit number.
>>>>
>>>> So, for example, the source code to move two bits starting at bit
>>>> 3 of variable B to starting at bit 4 of variable A would be
>>>>
>>>> Bits (A, 2, 4) = Bits (B, 2, 3)
>>>>
>>>> I always liked this feature, and used it a fair amount.
>>>
>>> Compare
>>> https://gcc.gnu.org/onlinedocs/gfortran/IBITS.html#IBITS
>>> https://gcc.gnu.org/onlinedocs/gfortran/MVBITS.html#MVBITS
>>> which are both elemental.
>>
>> They seem essentially equivalent. It says that these came in with
>> Fortran 90. The compiler I was referring to had its roots in a
>> predecessor with a different name that dated back to at least the
>> early 1970s. I am glad the idea became standardized.
>>
>> I guess I should ask the question that given that C is probably used
>> for bit manipulation stuff at least as much as Fortran, how come the
>> C standard didn't pick up some equivalent?
>
> Not necessarily an answer but an observation: in C no new language
> feature is needed, because C has the C preprocessor. It isn't hard
> to write a macro that does the necessary shifting and masking (and
> these days compilers are mostly smart enough to recognize the common
> patterns and translate them efficiently and in machine-specific
> ways).

While you are right, of course, about the preprocessor, I guess it comes
down to me having a different philosophy of language design, than what
Mitch expressed in his (sarcastic) comment.

> Having a straightforward way to succinctly express the requirement is
> <ahem> Not 'C'.

The problem with the preprocessor approach is that everyone will code
their own macro, possibly with different syntax, so I have to learn what
you did, then if I move to a different project, what they did etc. That
is the beauty of a standard. (Unless you are talking about having the
preprocessor macro standardized.)

Compare with, for example, integer division. It is part of the
standard, even though fairly rarely used. If bit field extraction and
insertion are reasonably well used (and I am guessing they are - at
least as much as they are used in Fortran, though probably less than
division), then I feel they should be standardized to ease the
programmer's job.

--
- Stephen Fuld
(e-mail address disguised to prevent spam)

Re: Dense machine code from C++ code (compiler optimizations)

<sq2hfi$lah$1@gioia.aioe.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=22385&group=comp.arch#22385

  copy link   Newsgroups: comp.arch
Path: i2pn2.org!i2pn.org!aioe.org!UgLt14+w9tVHe1BtIa3HDQ.user.46.165.242.75.POSTED!not-for-mail
From: mess...@bottle.org (Guillaume)
Newsgroups: comp.arch
Subject: Re: Dense machine code from C++ code (compiler optimizations)
Date: Thu, 23 Dec 2021 20:08:32 +0100
Organization: Aioe.org NNTP Server
Message-ID: <sq2hfi$lah$1@gioia.aioe.org>
References: <sndun6$q07$1@dont-email.me>
<dc10dfff-b48e-40ec-8c24-0a6c2e1790d2n@googlegroups.com>
<sphe6s$5a3$1@newsreader4.netcologne.de> <spqc1d$oio$1@dont-email.me>
<spqhj2$gdf$1@dont-email.me> <spqkjk$7ug$1@dont-email.me>
<86mtks1j79.fsf@linuxsc.com> <sq2acu$hg3$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Info: gioia.aioe.org; logging-data="21841"; posting-host="UgLt14+w9tVHe1BtIa3HDQ.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.4.1
X-Notice: Filtered by postfilter v. 0.9.2
Content-Language: fr
 by: Guillaume - Thu, 23 Dec 2021 19:08 UTC

Le 23/12/2021 à 18:07, Stephen Fuld a écrit :
> Compare with, for example, integer division.  It is part of the
> standard, even though fairly rarely used.

Sorry, I'm not sure I got it? Integer division is rarely used in C? Can
you elaborate?

> If bit field extraction and
> insertion are reasonably well used (and I am guessing they are - at
> least as much as they are used in Fortran, though probably less than
> division), then I feel they should be standardized to ease the
> programmer's job.

It's probably up for debate, of course, like any new "feature" that
could be added to C. For instance, stdint was added to C99... but this
was a bit different: integer widths were mostly implementation-defined
before that. Standardizing things that are commonly used and rely on
implementation-defined stuff makes sense.

But "bit manipulation" in general is something that can be implemented,
off the top of my head, in a portable way, using existing operators,
without risking incorrect behavior if you use them properly. So adding
bit manipulation functions to the standard would not add tremendous
value. Sure it would marginally help developers, but as far as I've
seen, the process of adding a new feature in the C standard usually
implies that it can't be done portably otherwise. Again, extracting bits
can be done portably as far as I see it. (Don't hesitate to prove me
wrong with an example!)

Re: Dense machine code from C++ code (compiler optimizations)

<cc7b7735-d386-4b43-ac97-035c647d7f05n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=22386&group=comp.arch#22386

  copy link   Newsgroups: comp.arch
X-Received: by 2002:a37:a5d1:: with SMTP id o200mr935487qke.525.1640288260348;
Thu, 23 Dec 2021 11:37:40 -0800 (PST)
X-Received: by 2002:a05:6808:2396:: with SMTP id bp22mr2847461oib.78.1640288259997;
Thu, 23 Dec 2021 11:37:39 -0800 (PST)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!border1.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.arch
Date: Thu, 23 Dec 2021 11:37:39 -0800 (PST)
In-Reply-To: <sq2hfi$lah$1@gioia.aioe.org>
Injection-Info: google-groups.googlegroups.com; posting-host=2600:1700:291:29f0:3dec:141b:f9b8:299;
posting-account=H_G_JQkAAADS6onOMb-dqvUozKse7mcM
NNTP-Posting-Host: 2600:1700:291:29f0:3dec:141b:f9b8:299
References: <sndun6$q07$1@dont-email.me> <dc10dfff-b48e-40ec-8c24-0a6c2e1790d2n@googlegroups.com>
<sphe6s$5a3$1@newsreader4.netcologne.de> <spqc1d$oio$1@dont-email.me>
<spqhj2$gdf$1@dont-email.me> <spqkjk$7ug$1@dont-email.me> <86mtks1j79.fsf@linuxsc.com>
<sq2acu$hg3$1@dont-email.me> <sq2hfi$lah$1@gioia.aioe.org>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <cc7b7735-d386-4b43-ac97-035c647d7f05n@googlegroups.com>
Subject: Re: Dense machine code from C++ code (compiler optimizations)
From: MitchAl...@aol.com (MitchAlsup)
Injection-Date: Thu, 23 Dec 2021 19:37:40 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Lines: 47
 by: MitchAlsup - Thu, 23 Dec 2021 19:37 UTC

On Thursday, December 23, 2021 at 1:08:39 PM UTC-6, Guillaume wrote:
> Le 23/12/2021 à 18:07, Stephen Fuld a écrit :
> > Compare with, for example, integer division. It is part of the
> > standard, even though fairly rarely used.
> Sorry, I'm not sure I got it? Integer division is rarely used in C? Can
> you elaborate?
> > If bit field extraction and
> > insertion are reasonably well used (and I am guessing they are - at
> > least as much as they are used in Fortran, though probably less than
> > division), then I feel they should be standardized to ease the
> > programmer's job.
> It's probably up for debate, of course, like any new "feature" that
> could be added to C. For instance, stdint was added to C99... but this
> was a bit different: integer widths were mostly implementation-defined
> before that. Standardizing things that are commonly used and rely on
> implementation-defined stuff makes sense.
>
> But "bit manipulation" in general is something that can be implemented,
> off the top of my head, in a portable way, using existing operators,
> without risking incorrect behavior if you use them properly. So adding
> bit manipulation functions to the standard would not add tremendous
> value. Sure it would marginally help developers, but as far as I've
> seen, the process of adding a new feature in the C standard usually
> implies that it can't be done portably otherwise. Again, extracting bits
> can be done portably as far as I see it. (Don't hesitate to prove me
> wrong with an example!)
<
We have to separate this into two (2) categories: static bit fields which
C already has, and dynamic bit fields which C does not have.
<
Thus, we have already taught the compilers how to recognize these patterns
and generate bit field codes. Static pattern recognition is easier than dynamic;
but if you can recognize the dynamic cases, you automatically recognize the
static. I first did this in 1983 for DENELCORE and I believe that others got there
before I did.
<
The only benefit to developers would be some kind of syntactic sugar to make
bit fields easier to specify::
<
a<3:17> = b<9:23>;
<
Macros seem to fail in that they cannot do syntactic sugar things.

Re: Dense machine code from C++ code (compiler optimizations)

<sq2n99$pqe$1@newsreader4.netcologne.de>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=22387&group=comp.arch#22387

  copy link   Newsgroups: comp.arch
Path: i2pn2.org!i2pn.org!news.uzoreto.com!newsreader4.netcologne.de!news.netcologne.de!.POSTED.2001-4dd4-c1ea-0-7285-c2ff-fe6c-992d.ipv6dyn.netcologne.de!not-for-mail
From: tkoe...@netcologne.de (Thomas Koenig)
Newsgroups: comp.arch
Subject: Re: Dense machine code from C++ code (compiler optimizations)
Date: Thu, 23 Dec 2021 20:47:37 -0000 (UTC)
Organization: news.netcologne.de
Distribution: world
Message-ID: <sq2n99$pqe$1@newsreader4.netcologne.de>
References: <sndun6$q07$1@dont-email.me>
<dc10dfff-b48e-40ec-8c24-0a6c2e1790d2n@googlegroups.com>
<sphe6s$5a3$1@newsreader4.netcologne.de> <spqc1d$oio$1@dont-email.me>
<spqhj2$gdf$1@dont-email.me> <spqkjk$7ug$1@dont-email.me>
<86mtks1j79.fsf@linuxsc.com> <sq2acu$hg3$1@dont-email.me>
<sq2hfi$lah$1@gioia.aioe.org>
<cc7b7735-d386-4b43-ac97-035c647d7f05n@googlegroups.com>
Injection-Date: Thu, 23 Dec 2021 20:47:37 -0000 (UTC)
Injection-Info: newsreader4.netcologne.de; posting-host="2001-4dd4-c1ea-0-7285-c2ff-fe6c-992d.ipv6dyn.netcologne.de:2001:4dd4:c1ea:0:7285:c2ff:fe6c:992d";
logging-data="26446"; mail-complaints-to="abuse@netcologne.de"
User-Agent: slrn/1.0.3 (Linux)
 by: Thomas Koenig - Thu, 23 Dec 2021 20:47 UTC

MitchAlsup <MitchAlsup@aol.com> schrieb:

> The only benefit to developers would be some kind of syntactic sugar to make
> bit fields easier to specify::
><
> a<3:17> = b<9:23>;
><
> Macros seem to fail in that they cannot do syntactic sugar things.

Macros in C can be used either for syntactic sugar or for syntactic
cyanide.

The original Bourne shell is an example. I'll leave it up to
the reader to decide if the C source code

IF wdval==NL
THEN IF flg&NLFLG
THEN wdval=';'; chkpr(NL);
FI
ELIF i==0 ANDF (flg&MTFLG)==0
THEN synbad();
FI

is the former or the latter.

Re: Dense machine code from C++ code (compiler optimizations)

<sq2vkc$qp3$1@gioia.aioe.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=22388&group=comp.arch#22388

  copy link   Newsgroups: comp.arch
Path: i2pn2.org!i2pn.org!aioe.org!UgLt14+w9tVHe1BtIa3HDQ.user.46.165.242.75.POSTED!not-for-mail
From: mess...@bottle.org (Guillaume)
Newsgroups: comp.arch
Subject: Re: Dense machine code from C++ code (compiler optimizations)
Date: Fri, 24 Dec 2021 00:10:02 +0100
Organization: Aioe.org NNTP Server
Message-ID: <sq2vkc$qp3$1@gioia.aioe.org>
References: <sndun6$q07$1@dont-email.me>
<dc10dfff-b48e-40ec-8c24-0a6c2e1790d2n@googlegroups.com>
<sphe6s$5a3$1@newsreader4.netcologne.de> <spqc1d$oio$1@dont-email.me>
<spqhj2$gdf$1@dont-email.me> <spqkjk$7ug$1@dont-email.me>
<86mtks1j79.fsf@linuxsc.com> <sq2acu$hg3$1@dont-email.me>
<sq2hfi$lah$1@gioia.aioe.org>
<cc7b7735-d386-4b43-ac97-035c647d7f05n@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Info: gioia.aioe.org; logging-data="27427"; posting-host="UgLt14+w9tVHe1BtIa3HDQ.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.4.1
X-Notice: Filtered by postfilter v. 0.9.2
Content-Language: fr
 by: Guillaume - Thu, 23 Dec 2021 23:10 UTC

Le 23/12/2021 à 20:37, MitchAlsup a écrit :
> The only benefit to developers would be some kind of syntactic sugar to make
> bit fields easier to specify::
> <
> a<3:17> = b<9:23>;

Oh, I perfectly get that, and I agree this notation would be quite nice.

> Macros seem to fail in that they cannot do syntactic sugar things.

Not this kind, indeed. But the whole question regarding the standard is,
is it really worth it to make additions to it just for some syntactic
sugar? This is not the spirit of C.

But in that same vein, I would have a number of other notations I would
like to have in C. A lot more than just this. Thing is, who knows where
that would lead the language.

Pages:12345678
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor