Re: is Vax addressing sane today

Liste des GroupesRevenir à c arch 
Sujet : Re: is Vax addressing sane today
De : mitchalsup (at) *nospam* aol.com (MitchAlsup1)
Groupes : comp.arch
Date : 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 today336Brett
5 Sep 24 +* Re: is Vax adressing sane today324John Dallman
6 Sep 24 i+- Re: is Vax adressing sane today1Lawrence D'Oliveiro
6 Sep 24 i`* Re: is Vax adressing sane today322Anton Ertl
6 Sep 24 i +- Re: is Vax adressing sane today1Lawrence D'Oliveiro
6 Sep 24 i +* Re: is Vax adressing sane today5MitchAlsup1
7 Sep 24 i i`* Re: is Vax adressing sane today4Anton Ertl
7 Sep 24 i i `* Re: is Vax adressing sane today3Anton Ertl
7 Sep 24 i i  `* Re: is Vax addressing sane today2John Dallman
7 Sep 24 i i   `- Re: is Vax addressing sane today1Anton Ertl
7 Sep 24 i +* Re: is Vax adressing sane today313John Levine
8 Sep 24 i i`* Re: is Vax adressing sane today312Anton Ertl
8 Sep 24 i i +* Re: is Vax adressing sane today304MitchAlsup1
8 Sep 24 i i i`* Re: is Vax addressing sane today303Lawrence D'Oliveiro
9 Sep 24 i i i +* Re: is Vax addressing sane today231MitchAlsup1
9 Sep 24 i i i i`* Re: is Vax addressing sane today230Brett
9 Sep 24 i i i i +* Re: is Vax addressing sane today7MitchAlsup1
10 Sep 24 i i i i i`* Re: is Vax addressing sane today6Niklas Holsti
11 Sep 24 i i i i i +- Re: is Vax addressing sane today1Lawrence D'Oliveiro
25 Sep 24 i i i i i `* Re: is Vax addressing sane today4Stephen Fuld
25 Sep 24 i i i i i  `* Re: is Vax addressing sane today3Michael S
25 Sep 24 i i i i i   `* Re: is Vax addressing sane today2MitchAlsup1
25 Sep 24 i i i i i    `- Re: is Vax addressing sane today1Niklas Holsti
10 Sep 24 i i i i `* Re: is Vax addressing sane today222Anton Ertl
10 Sep 24 i i i i  +* Re: is Vax addressing sane today4Michael S
10 Sep 24 i i i i  i`* Re: is Vax addressing sane today3Anton Ertl
10 Sep 24 i i i i  i +- Re: is Vax addressing sane today1Niklas Holsti
11 Sep 24 i i i i  i `- Re: is Vax addressing sane today1Michael S
11 Sep 24 i i i i  +* Re: is Vax addressing sane today7Lawrence D'Oliveiro
11 Sep 24 i i i i  i`* Re: is Vax addressing sane today6Michael S
11 Sep 24 i i i i  i `* Re: is Vax addressing sane today5David Brown
11 Sep 24 i i i i  i  +* Re: is Vax addressing sane today2Thomas Koenig
11 Sep 24 i i i i  i  i`- Re: is Vax addressing sane today1David Brown
11 Sep 24 i i i i  i  `* Re: is Vax addressing sane today2David Schultz
13 Sep 24 i i i i  i   `- Re: is Vax addressing sane today1David Brown
11 Sep 24 i i i i  +* Re: is Vax addressing sane today5John Levine
11 Sep 24 i i i i  i`* Re: is Vax addressing sane today4Thomas Koenig
11 Sep 24 i i i i  i +* Re: is Vax addressing sane today2Anton Ertl
11 Sep 24 i i i i  i i`- Re: is Vax addressing sane today1jseigh
11 Sep 24 i i i i  i `- Re: is Vax addressing sane today1John Levine
20 Sep 24 i i i i  `* Re: is Vax addressing sane today205Kent Dickey
21 Sep 24 i i i i   +* Re: is Vax addressing sane today4MitchAlsup1
21 Sep 24 i i i i   i`* Re: is Vax addressing sane today3Lawrence D'Oliveiro
21 Sep 24 i i i i   i `* Re: is Vax addressing sane today2MitchAlsup1
21 Sep 24 i i i i   i  `- Re: is Vax addressing sane today1Lawrence D'Oliveiro
21 Sep 24 i i i i   +* Re: is Vax addressing sane today4Lawrence D'Oliveiro
21 Sep 24 i i i i   i`* Re: is Vax addressing sane today3MitchAlsup1
21 Sep 24 i i i i   i +- Re: is Vax addressing sane today1Niklas Holsti
21 Sep 24 i i i i   i `- Re: is Vax addressing sane today1Lawrence D'Oliveiro
21 Sep 24 i i i i   +* Re: is Vax addressing sane today30MitchAlsup1
22 Sep 24 i i i i   i+* Re: except what, is Vax addressing sane today18John Levine
22 Sep 24 i i i i   ii+- Re: except what, is Vax addressing sane today1Michael S
22 Sep 24 i i i i   ii+* Re: except what, is Vax addressing sane today8Lawrence D'Oliveiro
22 Sep 24 i i i i   iii`* Re: except what, is Vax addressing sane today7Chris M. Thomasson
22 Sep 24 i i i i   iii `* Re: except what, is Vax addressing sane today6MitchAlsup1
22 Sep 24 i i i i   iii  +* Re: except what, is Vax addressing sane today2Lawrence D'Oliveiro
22 Sep 24 i i i i   iii  i`- Re: except what, is Vax addressing sane today1MitchAlsup1
22 Sep 24 i i i i   iii  +- Re: except what, is Vax addressing sane today1Chris M. Thomasson
22 Sep 24 i i i i   iii  `* Re: except what, is Vax addressing sane today2John Dallman
22 Sep 24 i i i i   iii   `- Re: except what, is Vax addressing sane today1MitchAlsup1
22 Sep 24 i i i i   ii+* Re: except what, is Vax addressing sane today5Terje Mathisen
24 Sep 24 i i i i   iii`* Re: except what, is Vax addressing sane today4Lawrence D'Oliveiro
24 Sep 24 i i i i   iii `* Re: except what, is Vax addressing sane today3Chris M. Thomasson
24 Sep 24 i i i i   iii  `* Re: except what, is Vax addressing sane today2MitchAlsup1
16 Oct 24 i i i i   iii   `- Re: except what, is Vax addressing sane today1Chris M. Thomasson
22 Sep 24 i i i i   ii`* Re: except what, is Vax addressing sane today3Lars Poulsen
24 Sep 24 i i i i   ii `* Re: except what, is Vax addressing sane today2Lawrence D'Oliveiro
24 Sep 24 i i i i   ii  `- Re: except what, is Vax addressing sane today1Michael S
22 Sep 24 i i i i   i+* Re: is Vax addressing sane today7Lawrence D'Oliveiro
22 Sep 24 i i i i   ii`* Re: is Vax addressing sane today6MitchAlsup1
22 Sep 24 i i i i   ii +* Re: is Vax addressing sane today3Lawrence D'Oliveiro
22 Sep 24 i i i i   ii i`* Re: is Vax addressing sane today2MitchAlsup1
22 Sep 24 i i i i   ii i `- Re: is Vax addressing sane today1Lawrence D'Oliveiro
22 Sep 24 i i i i   ii `* Re: is Vax addressing sane today2Anton Ertl
24 Sep 24 i i i i   ii  `- Re: is Vax addressing sane today1MitchAlsup1
24 Sep 24 i i i i   i+* Re: is Vax addressing sane today2Stefan Monnier
24 Sep 24 i i i i   ii`- Re: is Vax addressing sane today1MitchAlsup1
25 Sep 24 i i i i   i+- Re: is Vax addressing sane today1MitchAlsup1
12 Oct 24 i i i i   i`- Re: is Vax addressing sane today1Anton Ertl
22 Sep 24 i i i i   +* Re: is Vax addressing sane today4Thomas Koenig
24 Sep 24 i i i i   i`* Re: is Vax addressing sane today3Kent Dickey
24 Sep 24 i i i i   i +- Re: is Vax addressing sane today1Bill Findlay
24 Sep 24 i i i i   i `- Re: is Vax addressing sane today1Thomas Koenig
23 Sep 24 i i i i   +- Re: is Vax addressing sane today1Stefan Monnier
23 Sep 24 i i i i   `* Re: is Vax addressing sane today161Kent Dickey
24 Sep 24 i i i i    +* Re: is Vax addressing sane today11MitchAlsup1
24 Sep 24 i i i i    i+- Re: is Vax addressing sane today1Lawrence D'Oliveiro
24 Sep 24 i i i i    i`* Re: is Vax addressing sane today9Terje Mathisen
24 Sep 24 i i i i    i +* Re: is Vax addressing sane today4Michael S
24 Sep 24 i i i i    i i`* Re: is Vax addressing sane today3Terje Mathisen
24 Sep 24 i i i i    i i `* Re: is Vax addressing sane today2Michael S
24 Sep 24 i i i i    i i  `- Re: is Vax addressing sane today1MitchAlsup1
24 Sep 24 i i i i    i +* Re: is Vax addressing sane today3Stephen Fuld
24 Sep 24 i i i i    i i`* Re: is Vax addressing sane today2MitchAlsup1
25 Sep 24 i i i i    i i `- Re: is Vax addressing sane today1Stephen Fuld
12 Oct 24 i i i i    i `- Re: is Vax addressing sane today1Anton Ertl
24 Sep 24 i i i i    +* Re: is Vax addressing sane today3Terje Mathisen
29 Sep 24 i i i i    i+- Re: is Vax addressing sane today1Michael S
7 Oct 24 i i i i    i`- Re: is Vax addressing sane today1Kent Dickey
25 Sep 24 i i i i    +* Re: is Vax addressing sane today133MitchAlsup1
26 Sep 24 i i i i    i+- Re: is Vax addressing sane today1MitchAlsup1
28 Sep 24 i i i i    i`* Re: is Vax addressing sane today131Lawrence D'Oliveiro
28 Sep 24 i i i i    +* Re: is Vax addressing sane today3George Neuner
7 Oct 24 i i i i    +* Re: is Vax addressing sane today8Kent Dickey
12 Oct 24 i i i i    `* Re: is Vax addressing sane today2Anton Ertl
9 Sep 24 i i i `* Re: is Vax addressing sane today71Anton Ertl
8 Sep 24 i i `* Re: is Vax adressing sane today7Brett
8 Sep 24 i `* Re: is Vax adressing sane today2MitchAlsup1
6 Sep 24 +* Re: is Vax adressing sane today2MitchAlsup1
6 Sep 24 +- Re: is Vax adressing sane today1Lawrence D'Oliveiro
6 Sep 24 `* Re: is Vax adressing sane today8Anton Ertl

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal