Sujet : Re: is Vax addressing sane today
De : mitchalsup (at) *nospam* aol.com (MitchAlsup1)
Groupes : comp.archDate : 25. Sep 2024, 20:11:32
Autres entêtes
Organisation : Rocksolid Light
Message-ID : <8f031f2b5082d97582b1231a060f2b9f@www.novabbs.org>
References : 1 2 3 4 5 6
User-Agent : Rocksolid Light
On Wed, 25 Sep 2024 16:54:18 +0000, EricP wrote:
Kent Dickey wrote:
In article <O2DHO.184073$kxD8.113118@fx11.iad>,
EricP <ThatWouldBeTelling@thevillage.com> wrote:
Well, there is a bunch of things to unpack here.
>
First, INTO is a 32-bit x86 instruction. On 64-bit x64 AMD reassigned
that opcode to be for other instructions. On x64 the JO (jump overflow)
instruction does overflow detection.
>
The reason AMD could reassign INTO was because it wasn't being used by
C/C++.
But this is a side effect of C's widespread use, not the cause.
Programmers write in C because it is widely used and supported,
Free compilers
and as a consequence of that choice they get unchecked arithmetic.
But they are not choosing C to get unchecked arithmetic.
Had this same usage tests been done on other languages the results
would likely be quite different.
>
Second, on x86 the INTO and on x64 a JO offset32 take up 1 and 5 bytes
respectively. In JO case it has to branch to a ThrowOverflow () call
so thats 5 more bytes per ADD or SUB if you want error traceability.
With overflow trapping instructions there is NO runtime or code size
cost.
>
Third, on many risc ISA like RISC-V there are no flags so no JO
instruction
even possible. Either they must use the branchless overflow idiom or the
branching version, adding more to the cost of error detection.
>
*OR*its has an Add Fault Overflow instruction which has NO RUNTIME COST
ADDFO rd = rs1 + rs2
*OR"its ??? can you translate than into comp.arch language.
Fourth, it sounds like what you want is a risc (no flags) ADD
instruction
that returns both a result and an overflow flag so you can do the
equivalent of the x64 JO branch test.
ADDO (ro,rd) = rs1 + rs2
where rd is dest and ro is a register to receive a 0/1 overflow flag.
Once one allows multiple dest registers ADDO is trivial to support.
>
But that does not invalidate the usefulness of ADDFO.
I would also have ADDFC Add Fault Carry for unsigned overflow,
Which will be used two orders of magnitude less than ADDFO. First
because unsigned is used less often than signed, secondly much/most
unsigned arithmetic is specified to wrap rather than check.
plus other instructions for checking signed overflow and unsigned carry.
>
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.
>
Yes, this is all for x64 which has no INTO instruction.
s/x64/x86-64/g
It is still an x86 with all the benefits and detriments.
<snip>
>
So why should any hardware include an instruction to trap-on-overflow?
>
Because ALL the negative speed and code size consequences do not occur.
No because an EFFICIENT trap-on-overflow has no performance consequences
when no overflow is created. Efficient means 10-20 cycles to arrive at
exception handler--already in a reentrant state with exceptions and
interrupts still enabled. Just because x86 is so horrible in this regard
does not mean every architecture has to be at least that bad.
Trap-on-overflow instruction have a hardware cost, of varying severity.
If the ISA isn't already trapping on ALU instructions (such as
divide-by-0), it adds a new class of operations which can take
exceptions. An ALU functional unit that cannot take exceptions doesn't
have to save "unwinding" info (at minimum, info to recover the PC, and
possibly rollback state), and not needing this can be a nice
simplification. Branches and LD/ST always needs this info, but not
needing it on ALU ops can be a nice simplification of logic, and makes
it
easier to have multiple ALU functional units. Note that x86 INTO can
be treated as a branch, so it doesn't have the cost of an instruction
like "ADDTO r1,r2,r3" which is a normal ADD but where the ADD itself
traps if it overflows. ADDTO is particularly what I am arguing
against--
it is just a bad idea for the ISA to have ALU instructions take
exceptions.
>
Not really. Its a flag in the uOp indicating HasException and a union
of fields to hold exception status and RIP, all of which needs to be
there for other instructions like load/store.
Agreed, the overhead of recording "Overflow" and whether to do something
about it is so small that other considerations sway the argumetns.
Instruction sets which make detecting overflow difficult (say, RISC-V),
would do well to make branch-on-overflow efficient and easy. But adding
trap-on-overflow instructions is a waste of effort.
No they are a very useful tool for those who need such a tool
because the manual alternative is significantly more expensive
for both size and performance.
>
"I have one example where overflow exceptions would be a poor
implementation
choice" does not imply "therefore no one should have them as an option".
>
Can you share what language, compiler, and hardware you are using which
implements overflow checks using a trap-on-overflow instruction?
>
Kent
>
On DEC VAX the Overflow Enable flag was in the Program Status Word.
On My 66000 Overflow enable bit is part of the thread-status-line.
IIRC it was enabled by default in all DEC languages, Fortran77, Pascal,
Ada, Cobol, and disabled by default for C. But it could be toggled with
a runtime library call.
Similar--but library call does not have to "gain privilege" to flip the
bit's state.
For a variety of reasons having Overflow Enable in the status register
is A Bad Idea.
Can you expand. It seems to me if the unprivileged application using
the instructions at hand (Header Register instruction) can access
and write those exception control bits without needing privilege--
that most of the "A Bad Idea™" disappear. At the same time there
are significant amounts of state that do require privilege to
access in thread-status-line, and HR obeys such a distinction.
On Alpha it was a compile switch which selects different
instructions ADD vs ADDV, and also controlled by pragmas.
If you wanted to manually test for overflow then you used
one of the idioms, whatever language you worked in.
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 |