Sujet : Re: is Vax addressing sane today
De : kegs (at) *nospam* provalid.com (Kent Dickey)
Groupes : comp.archDate : 07. Oct 2024, 20:45:01
Autres entêtes
Organisation : provalid.com
Message-ID : <ve1a7d$1qjrq$1@dont-email.me>
References : 1 2 3 4
User-Agent : trn 4.0-test76 (Apr 2, 2001)
In article <
S9YIO.47284$xO0f.16227@fx48.iad>,
EricP <
ThatWouldBeTelling@thevillage.com> wrote:
Terje Mathisen wrote:
Kent Dickey wrote:
>
Look at:
https://godbolt.org/z/oMhW55YsK
>
Which is this code:
>
int add2(int num, int other) {
return num + other;
}
>
Compiled with these options: -O2 -ftrapv
(-ftrapv is the GCC argument for detect signed overflows and crash).
>
For x86-64 clang 19.1.0:
>
add2:
add edi, esi
jo .LBB0_1
mov eax, edi
ret
.LBB0_1:
ud1 eax, dword ptr [eax]
>
This looks OK: it does a normal add, then branches-on-overflow to
an undefined instruction.
>
But x86 has an instruction to trap on overflow directly: INTO. It's
one byte.
And it doesn't use it.
>
GCC x86-64 14.2 is even worse:
>
add2:
sub rsp, 8
call __addvsi3
add rsp, 8
ret
>
It calls a routine to do all additions which might overflow, and that
routine calls assert() if an overflow occurs.
>
The CPU has a trap-on-overflow instruction exactly for this case (to
crash
on detecting an overflow), and compilers don't even use it.
>
So even on architectures which have a trap-on-overflow instruction,
compilers don't use it.
You can only compile in INTO opcodes if you can guarantee that the INT 4
(INTO) trap vector will always be set to a proper handler, and since
that isn't part of the ABI, compilers can't depend on it?
I do agree that it would be nice if it did work, barring that clang is
doing the best possible alternative, at close to zero cost except for
the useless branch predictor table entry wastage.
Terje
>
On x64 in 64-bit mode INTO is among 21 opcodes reassigned as invalid.
One must use JO to detect signed overflow.
Others were repurposed, 1-byte INC and DEC 40..4F became the REX prefix.
Right, I forgot this. But even in 32-bit mode compiles, GCC and CLANG
both do not use INTO when using the -ftrapv flag--the compilers do the same
thing they do in 64-bit mode.
Kent
Date | Sujet | # | | Auteur |
5 Sep 24 | is Vax adressing sane today | 336 | | Brett |
5 Sep 24 | Re: is Vax adressing sane today | 324 | | John Dallman |
6 Sep 24 | Re: is Vax adressing sane today | 1 | | Lawrence D'Oliveiro |
6 Sep 24 | Re: is Vax adressing sane today | 322 | | Anton Ertl |
6 Sep 24 | Re: is Vax adressing sane today | 1 | | Lawrence D'Oliveiro |
6 Sep 24 | Re: is Vax adressing sane today | 5 | | MitchAlsup1 |
7 Sep 24 | Re: is Vax adressing sane today | 4 | | Anton Ertl |
7 Sep 24 | Re: is Vax adressing sane today | 3 | | Anton Ertl |
7 Sep 24 | Re: is Vax addressing sane today | 2 | | John Dallman |
7 Sep 24 | Re: is Vax addressing sane today | 1 | | Anton Ertl |
7 Sep 24 | Re: is Vax adressing sane today | 313 | | John Levine |
8 Sep 24 | Re: is Vax adressing sane today | 312 | | Anton Ertl |
8 Sep 24 | Re: is Vax adressing sane today | 304 | | MitchAlsup1 |
8 Sep 24 | Re: is Vax addressing sane today | 303 | | Lawrence D'Oliveiro |
9 Sep 24 | Re: is Vax addressing sane today | 231 | | MitchAlsup1 |
9 Sep 24 | Re: is Vax addressing sane today | 230 | | Brett |
9 Sep 24 | Re: is Vax addressing sane today | 7 | | MitchAlsup1 |
10 Sep 24 | Re: is Vax addressing sane today | 6 | | Niklas Holsti |
11 Sep 24 | Re: is Vax addressing sane today | 1 | | Lawrence D'Oliveiro |
25 Sep 24 | Re: is Vax addressing sane today | 4 | | Stephen Fuld |
25 Sep 24 | Re: is Vax addressing sane today | 3 | | Michael S |
25 Sep 24 | Re: is Vax addressing sane today | 2 | | MitchAlsup1 |
25 Sep 24 | Re: is Vax addressing sane today | 1 | | Niklas Holsti |
10 Sep 24 | Re: is Vax addressing sane today | 222 | | Anton Ertl |
10 Sep 24 | Re: is Vax addressing sane today | 4 | | Michael S |
10 Sep 24 | Re: is Vax addressing sane today | 3 | | Anton Ertl |
10 Sep 24 | Re: is Vax addressing sane today | 1 | | Niklas Holsti |
11 Sep 24 | Re: is Vax addressing sane today | 1 | | Michael S |
11 Sep 24 | Re: is Vax addressing sane today | 7 | | Lawrence D'Oliveiro |
11 Sep 24 | Re: is Vax addressing sane today | 6 | | Michael S |
11 Sep 24 | Re: is Vax addressing sane today | 5 | | David Brown |
11 Sep 24 | Re: is Vax addressing sane today | 2 | | Thomas Koenig |
11 Sep 24 | Re: is Vax addressing sane today | 1 | | David Brown |
11 Sep 24 | Re: is Vax addressing sane today | 2 | | David Schultz |
13 Sep 24 | Re: is Vax addressing sane today | 1 | | David Brown |
11 Sep 24 | Re: is Vax addressing sane today | 5 | | John Levine |
11 Sep 24 | Re: is Vax addressing sane today | 4 | | Thomas Koenig |
11 Sep 24 | Re: is Vax addressing sane today | 2 | | Anton Ertl |
11 Sep 24 | Re: is Vax addressing sane today | 1 | | jseigh |
11 Sep 24 | Re: is Vax addressing sane today | 1 | | John Levine |
20 Sep 24 | Re: is Vax addressing sane today | 205 | | Kent Dickey |
21 Sep 24 | Re: is Vax addressing sane today | 4 | | MitchAlsup1 |
21 Sep 24 | Re: is Vax addressing sane today | 3 | | Lawrence D'Oliveiro |
21 Sep 24 | Re: is Vax addressing sane today | 2 | | MitchAlsup1 |
21 Sep 24 | Re: is Vax addressing sane today | 1 | | Lawrence D'Oliveiro |
21 Sep 24 | Re: is Vax addressing sane today | 4 | | Lawrence D'Oliveiro |
21 Sep 24 | Re: is Vax addressing sane today | 3 | | MitchAlsup1 |
21 Sep 24 | Re: is Vax addressing sane today | 1 | | Niklas Holsti |
21 Sep 24 | Re: is Vax addressing sane today | 1 | | Lawrence D'Oliveiro |
21 Sep 24 | Re: is Vax addressing sane today | 30 | | MitchAlsup1 |
22 Sep 24 | Re: except what, is Vax addressing sane today | 18 | | John Levine |
22 Sep 24 | Re: except what, is Vax addressing sane today | 1 | | Michael S |
22 Sep 24 | Re: except what, is Vax addressing sane today | 8 | | Lawrence D'Oliveiro |
22 Sep 24 | Re: except what, is Vax addressing sane today | 7 | | Chris M. Thomasson |
22 Sep 24 | Re: except what, is Vax addressing sane today | 6 | | MitchAlsup1 |
22 Sep 24 | Re: except what, is Vax addressing sane today | 2 | | Lawrence D'Oliveiro |
22 Sep 24 | Re: except what, is Vax addressing sane today | 1 | | MitchAlsup1 |
22 Sep 24 | Re: except what, is Vax addressing sane today | 1 | | Chris M. Thomasson |
22 Sep 24 | Re: except what, is Vax addressing sane today | 2 | | John Dallman |
22 Sep 24 | Re: except what, is Vax addressing sane today | 1 | | MitchAlsup1 |
22 Sep 24 | Re: except what, is Vax addressing sane today | 5 | | Terje Mathisen |
24 Sep 24 | Re: except what, is Vax addressing sane today | 4 | | Lawrence D'Oliveiro |
24 Sep 24 | Re: except what, is Vax addressing sane today | 3 | | Chris M. Thomasson |
24 Sep 24 | Re: except what, is Vax addressing sane today | 2 | | MitchAlsup1 |
16 Oct 24 | Re: except what, is Vax addressing sane today | 1 | | Chris M. Thomasson |
22 Sep 24 | Re: except what, is Vax addressing sane today | 3 | | Lars Poulsen |
24 Sep 24 | Re: except what, is Vax addressing sane today | 2 | | Lawrence D'Oliveiro |
24 Sep 24 | Re: except what, is Vax addressing sane today | 1 | | Michael S |
22 Sep 24 | Re: is Vax addressing sane today | 7 | | Lawrence D'Oliveiro |
22 Sep 24 | Re: is Vax addressing sane today | 6 | | MitchAlsup1 |
22 Sep 24 | Re: is Vax addressing sane today | 3 | | Lawrence D'Oliveiro |
22 Sep 24 | Re: is Vax addressing sane today | 2 | | MitchAlsup1 |
22 Sep 24 | Re: is Vax addressing sane today | 1 | | Lawrence D'Oliveiro |
22 Sep 24 | Re: is Vax addressing sane today | 2 | | Anton Ertl |
24 Sep 24 | Re: is Vax addressing sane today | 1 | | MitchAlsup1 |
24 Sep 24 | Re: is Vax addressing sane today | 2 | | Stefan Monnier |
24 Sep 24 | Re: is Vax addressing sane today | 1 | | MitchAlsup1 |
25 Sep 24 | Re: is Vax addressing sane today | 1 | | MitchAlsup1 |
12 Oct 24 | Re: is Vax addressing sane today | 1 | | Anton Ertl |
22 Sep 24 | Re: is Vax addressing sane today | 4 | | Thomas Koenig |
24 Sep 24 | Re: is Vax addressing sane today | 3 | | Kent Dickey |
24 Sep 24 | Re: is Vax addressing sane today | 1 | | Bill Findlay |
24 Sep 24 | Re: is Vax addressing sane today | 1 | | Thomas Koenig |
23 Sep 24 | Re: is Vax addressing sane today | 1 | | Stefan Monnier |
23 Sep 24 | Re: is Vax addressing sane today | 161 | | Kent Dickey |
24 Sep 24 | Re: is Vax addressing sane today | 11 | | MitchAlsup1 |
24 Sep 24 | Re: is Vax addressing sane today | 1 | | Lawrence D'Oliveiro |
24 Sep 24 | Re: is Vax addressing sane today | 9 | | Terje Mathisen |
24 Sep 24 | Re: is Vax addressing sane today | 4 | | Michael S |
24 Sep 24 | Re: is Vax addressing sane today | 3 | | Terje Mathisen |
24 Sep 24 | Re: is Vax addressing sane today | 2 | | Michael S |
24 Sep 24 | Re: is Vax addressing sane today | 1 | | MitchAlsup1 |
24 Sep 24 | Re: is Vax addressing sane today | 3 | | Stephen Fuld |
24 Sep 24 | Re: is Vax addressing sane today | 2 | | MitchAlsup1 |
25 Sep 24 | Re: is Vax addressing sane today | 1 | | Stephen Fuld |
12 Oct 24 | Re: is Vax addressing sane today | 1 | | Anton Ertl |
24 Sep 24 | Re: is Vax addressing sane today | 3 | | Terje Mathisen |
29 Sep 24 | Re: is Vax addressing sane today | 1 | | Michael S |
7 Oct 24 | Re: is Vax addressing sane today | 1 | | Kent Dickey |
25 Sep 24 | Re: is Vax addressing sane today | 133 | | MitchAlsup1 |
26 Sep 24 | Re: is Vax addressing sane today | 1 | | MitchAlsup1 |
28 Sep 24 | Re: is Vax addressing sane today | 131 | | Lawrence D'Oliveiro |
28 Sep 24 | Re: is Vax addressing sane today | 3 | | George Neuner |
7 Oct 24 | Re: is Vax addressing sane today | 8 | | Kent Dickey |
12 Oct 24 | Re: is Vax addressing sane today | 2 | | Anton Ertl |
9 Sep 24 | Re: is Vax addressing sane today | 71 | | Anton Ertl |
8 Sep 24 | Re: is Vax adressing sane today | 7 | | Brett |
8 Sep 24 | Re: is Vax adressing sane today | 2 | | MitchAlsup1 |
6 Sep 24 | Re: is Vax adressing sane today | 2 | | MitchAlsup1 |
6 Sep 24 | Re: is Vax adressing sane today | 1 | | Lawrence D'Oliveiro |
6 Sep 24 | Re: is Vax adressing sane today | 8 | | Anton Ertl |