Re: Cost of handling misaligned access

Liste des GroupesRevenir à c arch 
Sujet : Re: Cost of handling misaligned access
De : cr88192 (at) *nospam* gmail.com (BGB)
Groupes : comp.arch
Date : 14. Feb 2025, 22:14:11
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <voobnc$3l2dl$1@dont-email.me>
References : 1 2 3 4
User-Agent : Mozilla Thunderbird
On 2/13/2025 1:09 PM, Marcus wrote:
On 2025-02-03, Anton Ertl wrote:
BGB <cr88192@gmail.com> writes:
On 2/2/2025 10:45 AM, EricP wrote:
Digging deeper with performance counters reveals executing each unaligned
load instruction results in ~505 executed instructions. P550 almost
certainly doesn’t have hardware support for unaligned accesses.
Rather, it’s likely raising a fault and letting an operating system
handler emulate it in software."
>
>
An emulation fault, or something similarly nasty...
>
>
At that point, even turning any potentially unaligned load or store into
a runtime call is likely to be a lot cheaper.
>
There are lots of potentially unaligned loads and stores.  There are
very few actually unaligned loads and stores: On Linux-Alpha every
unaligned access is logged by default, and the number of
unaligned-access entries in the logs of our machines was relatively
small (on average a few per day).  So trapping actual unaligned
accesses was faster than replacing potential unaligned accesses with
code sequences that synthesize the unaligned access from aligned
accesses.
 If you compile regular C/C++ code that does not intentionally do any
nasty stuff, you will typically have zero unaligned loads stores.
 My machine still does not support unaligned accesses in hardware (it's
on the todo list), and it can run an awful lot of software without
problems.
 The problem arises when the programmer *deliberately* does unaligned
loads and stores in order to improve performance. Or rather, if the
programmer knows that the hardware supports unaligned loads and stores,
he/she can use that to write faster code in some special cases.
 
Pretty much.
This is partly why I am in favor of potentially adding explicit keywords for some of these cases, or to reiterate:
   __aligned:
     Inform compiler that a pointer is aligned.
     May use a faster version if appropriate.
       If a faster aligned-only variant exists of an instruction.
       On an otherwise unaligned-safe target.
   __unaligned: Inform compiler that an access is unaligned.
     May use a runtime call or similar if necessary,
       on an aligned-only target.
     May do nothing on an unaligned-safe target.
   None: Do whatever is the default.
     Presumably, assume aligned by default,
       unless target is known unaligned-safe.
And/or, an attribute, which seems to be the new style.
   __attribute__((unaligned))  //GCC-ism
   [[unaligned]]  //probably if the C standard people did it...
Most of the pointers will remain unqualified, but most will not do anything unaligned, so this is fine.
For cases where it is needed, a keyword could make sense (probably alongside volatile and the usual mess of per-target ifdefs that usually also needs to exist with this sort of code).
Meanwhile, function wrappers with manual byte-shifts or memcpy is a particularly poor solution (depends too much on compiler magic).
Would be nice if there was a "commonly accepted" or "standard" option, so that one can just use this and not have a mess of ifdefs (or to "just do it with raw bytes" and accept a potentially significant performance penalty).

 
Of course, if the cost of unaligned accesses is that high, you will
avoid them in cases like block copies where cheap unaligned accesses
would otherwise be beneficial.
>
- anton
 

Date Sujet#  Auteur
13 Feb 25 * Re: Cost of handling misaligned access48Marcus
13 Feb 25 +- Re: Cost of handling misaligned access1Thomas Koenig
14 Feb 25 +* Re: Cost of handling misaligned access41BGB
14 Feb 25 i`* Re: Cost of handling misaligned access40MitchAlsup1
18 Feb 25 i `* Re: Cost of handling misaligned access39BGB
18 Feb 25 i  +* Re: Cost of handling misaligned access33MitchAlsup1
18 Feb 25 i  i+- Re: Cost of handling misaligned access1BGB
18 Feb 25 i  i`* Re: Cost of handling misaligned access31Michael S
18 Feb 25 i  i +- Re: Cost of handling misaligned access1Thomas Koenig
18 Feb 25 i  i +* Re: Cost of handling misaligned access26MitchAlsup1
18 Feb 25 i  i i`* Re: Cost of handling misaligned access25Terje Mathisen
18 Feb 25 i  i i `* Re: Cost of handling misaligned access24MitchAlsup1
19 Feb 25 i  i i  `* Re: Cost of handling misaligned access23Terje Mathisen
19 Feb 25 i  i i   `* Re: Cost of handling misaligned access22MitchAlsup1
19 Feb 25 i  i i    `* Re: Cost of handling misaligned access21BGB
20 Feb 25 i  i i     +- Re: Cost of handling misaligned access1Robert Finch
20 Feb 25 i  i i     +* Re: Cost of handling misaligned access5MitchAlsup1
20 Feb 25 i  i i     i+* Re: Cost of handling misaligned access2BGB
20 Feb 25 i  i i     ii`- Re: Cost of handling misaligned access1BGB
21 Feb 25 i  i i     i`* Re: Cost of handling misaligned access2Robert Finch
21 Feb 25 i  i i     i `- Re: Cost of handling misaligned access1BGB
21 Feb 25 i  i i     `* Re: Cost of handling misaligned access14BGB
22 Feb 25 i  i i      +- Re: Cost of handling misaligned access1Robert Finch
22 Feb 25 i  i i      `* Re: Cost of handling misaligned access12Robert Finch
23 Feb 25 i  i i       +* Re: Cost of handling misaligned access10BGB
23 Feb 25 i  i i       i`* Re: Cost of handling misaligned access9Michael S
24 Feb 25 i  i i       i +- Re: Cost of handling misaligned access1BGB
24 Feb 25 i  i i       i `* Re: Cost of handling misaligned access7Michael S
24 Feb 25 i  i i       i  +* Re: Cost of handling misaligned access4Robert Finch
24 Feb 25 i  i i       i  i+- Re: Cost of handling misaligned access1BGB
24 Feb 25 i  i i       i  i`* Re: Cost of handling misaligned access2MitchAlsup1
25 Feb 25 i  i i       i  i `- Re: Cost of handling misaligned access1BGB
25 Feb 25 i  i i       i  `* Re: Cost of handling misaligned access2MitchAlsup1
25 Feb 25 i  i i       i   `- Re: Cost of handling misaligned access1BGB
23 Feb 25 i  i i       `- Re: Cost of handling misaligned access1Robert Finch
18 Feb 25 i  i `* Re: Cost of handling misaligned access3BGB
19 Feb 25 i  i  `* Re: Cost of handling misaligned access2MitchAlsup1
19 Feb 25 i  i   `- Re: Cost of handling misaligned access1BGB
18 Feb 25 i  `* Re: Cost of handling misaligned access5Robert Finch
18 Feb 25 i   `* Re: Cost of handling misaligned access4BGB
18 Feb 25 i    `* Re: Cost of handling misaligned access3Brett
18 Feb 25 i     `* Re: Cost of handling misaligned access2Marcus
18 Feb 25 i      `- Re: Cost of handling misaligned access1BGB
17 Feb 25 `* Re: Cost of handling misaligned access5Terje Mathisen
17 Feb 25  +- Re: Cost of handling misaligned access1Thomas Koenig
17 Feb 25  `* Re: Cost of handling misaligned access3MitchAlsup1
17 Feb 25   `* Re: Cost of handling misaligned access2Terje Mathisen
17 Feb 25    `- Re: Cost of handling misaligned access1MitchAlsup1

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal