🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

38 total messages Started by makendo Tue, 27 Oct 2026 06:17
Re: interrupt handling latency and weird register use (was Re: OT: Epic RISC-V rant)
#375
Author: makendo
Date: Tue, 27 Oct 2026 06:17
11 lines
2033 bytes
> Grinberg actually mentioned it, but got it wrong.  He claimed that
> multiplication and division are indepenently optional, while in the
> RISC-V specification, you get none or both.

RISC-V allows only implementing multiplication without implementing
division, with "Zmmul" being the official name for this partial
implementation of M. The case where division is implemented but
multiplication is not does not have a name assigned -- it is pretty
well known that hardware designers, compiler writers and low-level
programmers hate division far more than multiplication, so I doubt
if divison-only hardware is even out in the wild for any ISA...
Re: interrupt handling latency and weird register use (was Re: OT: Epic RISC-V rant)
#378
Author: Anton Ertl
Date: Tue, 27 Oct 2026 16:14
26 lines
2554 bytes
makendo <makendo@makendo.invalid> writes:
>The case where division is implemented but
>multiplication is not does not have a name assigned -- it is pretty
>well known that hardware designers, compiler writers and low-level
>programmers hate division far more than multiplication, so I doubt
>if divison-only hardware is even out in the wild for any ISA...

I don't think that "hate" is the right concept.  Division is costly:
Costly to implement and it tends to run slowly (although ARM tries
hard to disprove that part, even on low-end cores like the
Cortex-A53).  And it's not that frequent, which means that if you
throw lots of hardware at making it fast, the payoff will be small.
And because it is slow, various potential use cases avoid it and
prefer to use shifts or multiplication by the inverse, making it even
less frequent.

Even relatively recent architectures like Alpha (1992) and IA-64
(2001) do not include integer division instructions.

So I found the inclusion of division in the RISC-V M extension
surprising.  They then separated them again by defining Zmmul.

- anton
-- 
'Anyone trying for "industrial quality" ISA should avoid undefined behavior.'
  Mitch Alsup, <c17fcd89-f024-40e7-a594-88a85ac10d20o@googlegroups.com>
Re: interrupt handling latency and weird register use (was Re: OT: Epic RISC-V rant)
#385
Author: MitchAlsup
Date: Tue, 27 Oct 2026 17:06
52 lines
3182 bytes
anton@mips.complang.tuwien.ac.at (Anton Ertl) posted:

> makendo <makendo@makendo.invalid> writes:
> >The case where division is implemented but
> >multiplication is not does not have a name assigned -- it is pretty
> >well known that hardware designers, compiler writers and low-level
> >programmers hate division far more than multiplication, so I doubt
> >if divison-only hardware is even out in the wild for any ISA...
> 
> I don't think that "hate" is the right concept.  Division is costly:

But "lack of division" is also costly !! especially if some future
implementation will have division {which it will} and then you have
no direct means to make the dusty decks fast.

Note to µArchitects, put the instruction in even if you are going to
TRAP to SW emulation. Later on when DIV is implemented it just runs
faster and you had to do nothing (but put it in).

> Costly to implement and it tends to run slowly (although ARM tries
> hard to disprove that part, even on low-end cores like the
> Cortex-A53).

Let me assert that adding IDIV/UDIV is WAY LESS COSTLY than adding 1300
SIMD instructions.

>               And it's not that frequent, which means that if you
> throw lots of hardware at making it fast, the payoff will be small.

Having it perfectly defined is the critical part {bit patterns in,
bit patterns out} then each implementation can choose for itself
whether to put it in or leave it out.

> And because it is slow, various potential use cases avoid it and
> prefer to use shifts or multiplication by the inverse, making it even
> less frequent.

I have considered a x / (2^n) instruction--only a few gates worse than
SRA.
 
> Even relatively recent architectures like Alpha (1992) and IA-64
> (2001) do not include integer division instructions.

And look at where they are now.
 
> So I found the inclusion of division in the RISC-V M extension
> surprising.  They then separated them again by defining Zmmul.

RISC-V is like a shotgun with a short barrel and no choke--it just
needs to hit something for its backers to say they hit something.
> 
> - anton
Re: interrupt handling latency and weird register use (was Re: OT: Epic RISC-V rant)
#387
Author: Michael S
Date: Tue, 27 Oct 2026 17:17
15 lines
1963 bytes
On Tue, 27 Oct 2026 17:06:29 GMT
MitchAlsup <user5857@newsgrouper.org.invalid> wrote:

> 
> Having it perfectly defined is the critical part {bit patterns in,
> bit patterns out} then each implementation can choose for itself
> whether to put it in or leave it out.
> 

An interesting question here is "Do one has to include 128b / 64b
division in the ISA or it's better to leave it off?".
AMD decided that it was needed, but it seems that nobody else followed
the suit.

Re: interrupt handling latency and weird register use (was Re: OT: Epic RISC-V rant)
#386
Author: Terje Mathisen
Date: Tue, 27 Oct 2026 18:20
38 lines
3258 bytes
MitchAlsup wrote:
> anton@mips.complang.tuwien.ac.at (Anton Ertl) posted:
> 
>> makendo <makendo@makendo.invalid> writes:
>>> The case where division is implemented but
>>> multiplication is not does not have a name assigned -- it is pretty
>>> well known that hardware designers, compiler writers and low-level
>>> programmers hate division far more than multiplication, so I doubt
>>> if divison-only hardware is even out in the wild for any ISA...
>>
>> I don't think that "hate" is the right concept.  Division is costly:
> 
> But "lack of division" is also costly !! especially if some future
> implementation will have division {which it will} and then you have
> no direct means to make the dusty decks fast.

Intel actually did this correctly back in 1978/79 when they designed the 
8087: If you did not have the FPU, then the main 8088 CPU would trap to 
an emulation layer which did what was required. The only real problem 
was that this was significantly slower than a direct call to a SW 
function which did the same operation.

What we ended up with on most applications was a hybrid, where the 
compiler would generate calls to a shim, said shim would inspect the 
available HW (FPU/No FPU) and patch the call:

Either just modify the call target to go directly to the emuation 
function, or replace the CALL FDIV_EMULATION machine code with the 
actual 8087 FDIV opcode.

Since FPU ops could be both larger and shorter than a 16-bit CALL, the 
compiler also had to pad each instance to whatever was larger.

Terje

-- 
- <Terje.Mathisen at tmsw.no>
"almost all programming can be viewed as an exercise in caching"
Re: interrupt handling latency and weird register use (was Re: OT: Epic RISC-V rant)
#390
Author: John Savard
Date: Tue, 27 Oct 2026 18:45
15 lines
1881 bytes
On Tue, 27 Oct 2026 16:14:14 GMT, anton@mips.complang.tuwien.ac.at
(Anton Ertl) wrote:

>Even relatively recent architectures like Alpha (1992) and IA-64
>(2001) do not include integer division instructions.
>
>So I found the inclusion of division in the RISC-V M extension
>surprising.

I certainly don't. Doing anything by software is excruciatingly slow,
especially if the program includes any branch instructions. Divisions
are needed less often than multiplies, yes, but if they're slow they
will still impact performance severely.

John Savard
Re: interrupt handling latency and weird register use (was Re: OT: Epic RISC-V rant)
#425
Author: John Savard
Date: Tue, 27 Oct 2026 18:46
14 lines
1863 bytes
On Tue, 27 Oct 2026 17:06:29 GMT, MitchAlsup
<user5857@newsgrouper.org.invalid> wrote:

>But "lack of division" is also costly !! especially if some future
>implementation will have division {which it will} and then you have
>no direct means to make the dusty decks fast.
>
>Note to µArchitects, put the instruction in even if you are going to
>TRAP to SW emulation. Later on when DIV is implemented it just runs
>faster and you had to do nothing (but put it in).

An excellent point!

John Savard
Re: interrupt handling latency and weird register use (was Re: OT: Epic RISC-V rant)
#391
Author: John Savard
Date: Tue, 27 Oct 2026 18:49
12 lines
1767 bytes
On Tue, 27 Oct 2026 19:20:04 +0100, Terje Mathisen
<terje.mathisen@tmsw.no> wrote:

>The only real problem 
>was that this was significantly slower than a direct call to a SW 
>function which did the same operation.

Hence, SANE on the early Macintosh. Which was insane because it
rejected Mitch's approach, and forced subroutine calls even if you had
an FPU.

John Savard
Re: interrupt handling latency and weird register use (was Re: OT: Epic RISC-V rant)
#392
Author: BGB
Date: Tue, 27 Oct 2026 18:56
151 lines
7167 bytes
On 10/27/2026 11:14 AM, Anton Ertl wrote:
> makendo <makendo@makendo.invalid> writes:
>> The case where division is implemented but
>> multiplication is not does not have a name assigned -- it is pretty
>> well known that hardware designers, compiler writers and low-level
>> programmers hate division far more than multiplication, so I doubt
>> if divison-only hardware is even out in the wild for any ISA...
> 
> I don't think that "hate" is the right concept.  Division is costly:
> Costly to implement and it tends to run slowly (although ARM tries
> hard to disprove that part, even on low-end cores like the
> Cortex-A53).  And it's not that frequent, which means that if you
> throw lots of hardware at making it fast, the payoff will be small.
> And because it is slow, various potential use cases avoid it and
> prefer to use shifts or multiplication by the inverse, making it even
> less frequent.
> 

Yes.

General purpose division is infrequent enough that even slow hardware 
support is debatable, vs implementing it in software as a runtime function.

And, since generally everyone knows division is often slow, there is a 
tendency for programmers to avoid it whenever possible, which ironically 
lessens the incentive for faster division in the general case.


Then, there are niche cases where one wants it to be fast.
But, then often in these cases a usable strategy is to use a lookup 
table of reciprocals, which is often also a usable strategy to speed up 
runtime-library division.


In the naive case, one can have a table of reciprocals and only divide 
via the table when in range of the lookup table. However, this scales 
poorly. With care, there are tricks to push it further with a smaller 
lookup table, but more care is needed to avoid cases that would result 
in inexact results (in cases where it is necessary to have an exact result).

One trick is, say:
You have a table of root reciprocals;
You have a table of derived reciprocals, holding an index to the root 
reciprocal, and a right shift value (say, both packed into a 16-bit number);
This can be used as the main division table.

If outside of the naive range of the table:
   Is the current divisor a power-of-2 multiple of an index in the table?
     reuse that index, but add the scale to the final right-shift.
   Maybe try some factorization tricks.
   Else, fall back to a generic-but-slow strategy.
     Such as a shift-and-subtract loop.

For something like a 3D renderer, typically exact results are not needed 
so it is possible to behave as-if the power-of-2 case is always true.

Another option is doing a trick of trying the power-of-2 case, then 
back-multiplying the result.
   q_apx = div_apx(dividend, divisor);
   dvi_apx = q_apx * divisor;
   rem_apx = dividend - dvi_apx;
   if(rem_apx < divisor)
     return(q_apx);   //exact
   if(rem_apx < (divisor*2))
     return(q_apx+1);   //off by 1
   //rare path, fall back to slow strategy.


Though, this approach mostly only makes sense if one assumes that the 
multiplier is reasonably fast compared to the divider slow-path.

If using a shift-add multiplier, this approach does not make sense.


For 3D rendering, there is often a need for fast approximate 
floating-point division, but then a reasonable strategy is:
   Generate a reciprocal:
     Do a magic integer subtract;
     Patch it up with a few N-R stages.
   Do division via multiplication by reciprocal.

Likewise for square-root, and reciprocal-square-root.


Though, another option is to do approximate floating-point reciprocal by 
extracting the mantissa and then using an approximate integer reciprocal 
of the HOBs as the starting point (with the shift-factors added to the 
computed new exponent).

This is more complicated than the "subtract and N-R" trick, but can work 
out being potentially faster if the FPU isn't particularly fast (or if 
doing FPU emulation).


> Even relatively recent architectures like Alpha (1992) and IA-64
> (2001) do not include integer division instructions.
> 
> So I found the inclusion of division in the RISC-V M extension
> surprising.  They then separated them again by defining Zmmul.
> 

If one assumes that multiplication is done with a Shift-and-Add unit, 
then division comes cheaply as a very modest logic tweak.

Doesn't work if one uses a different strategy to implement multiply though.

In my case, I used shift-and-add for 64-bit multiply, and for 32 and 64 
bit division.

64-bit multiply:
A little slower than the "decompose and use 32-bit multiply in software" 
strategy, but less inconvenient.

32-bit divide:
A little faster than the software-side lookup-table trickery.

64-bit divide:
Notably faster than the shift-subtract loop.

However...
In most cases division is infrequent enough that it doesn't make a big 
difference either way.



A cheaper strategy would be to only provide for 32-bit narrow and 
widening multiply in a 64-bit machine.

Then argue that everything else be faked using 32-bit widening multiply.

But... annoyingly... RV64 doesn't provide a 32-bit widening multiply 
instruction.


Though, did recently get around to adding a special case to BGBCC that 
things like:
   int x, y, z;
   ...
   z=(((long long)x)*((long long)y))>>24;

Will now use a widening multiply (when available) rather than a full 
64-bit multiply. Previously, was mostly often using an intrinsic for 
this sort of thing, but this kinda sucked.


For RISC-V, can fake the full version of M with trap-and-emulate, but 
this is the slowest option.

...

Re: floating point, interrupt handling latency and weird register use (was Re: OT: Epic RISC-V rant)
#395
Author: John Levine
Date: Tue, 27 Oct 2026 20:08
24 lines
2446 bytes
According to Terje Mathisen  <terje.mathisen@tmsw.no>:
>Intel actually did this correctly back in 1978/79 when they designed the 
>8087: If you did not have the FPU, then the main 8088 CPU would trap to 
>an emulation layer which did what was required. The only real problem 
>was that this was significantly slower than a direct call to a SW 
>function which did the same operation.

Sadly, no.  Without an 8087 the 8088 just ignored the ESC opcode used
by floating instructions, but ...

>What we ended up with on most applications was a hybrid, where the 
>compiler would generate calls to a shim, said shim would inspect the 
>available HW (FPU/No FPU) and patch the call:

The Wizard C compiler, the predecessor of Turbo C, had a hack where it
emitted floating point instructions but with the first byte replaced
by a trap opcode.  Then it was roughly as you described, patch it
to a real float instruction if there was an 8087, or call the software
version.

-- 
Regards,
John Levine, johnl@taugh.com, Primary Perpetrator of "The Internet for Dummies",
Please consider the environment before reading this e-mail. https://jl.ly
Re: interrupt handling latency and weird register use (was Re: OT: Epic RISC-V rant)
#398
Author: MitchAlsup
Date: Tue, 27 Oct 2026 20:59
24 lines
2035 bytes
Michael S <already5chosen@yahoo.com> posted:

> On Tue, 27 Oct 2026 17:06:29 GMT
> MitchAlsup <user5857@newsgrouper.org.invalid> wrote:
> 
> > 
> > Having it perfectly defined is the critical part {bit patterns in,
> > bit patterns out} then each implementation can choose for itself
> > whether to put it in or leave it out.
> > 
> 
> An interesting question here is "Do one has to include 128b / 64b
> division in the ISA or it's better to leave it off?".
> AMD decided that it was needed, but it seems that nobody else followed
> the suit.

My 66000 provides 128/64 by means of the CARRY instruction-modifier.

Few architectures have what CARRY provides en-the-large--everything from
ADC-SUBC to double wide shifts, double wide inserts, exact FP arithmetics
...

And on the exact FP arithmetics, the inexact bit does not get set (when
it is not providing useful information).
Re: floating point, interrupt handling latency and weird register use (was Re: OT: Epic RISC-V rant)
#404
Author: Brian G. Lucas
Date: Tue, 27 Oct 2026 21:44
25 lines
2548 bytes
On 10/27/26 3:08 PM, John Levine wrote:
> According to Terje Mathisen  <terje.mathisen@tmsw.no>:
>> Intel actually did this correctly back in 1978/79 when they designed the
>> 8087: If you did not have the FPU, then the main 8088 CPU would trap to
>> an emulation layer which did what was required. The only real problem
>> was that this was significantly slower than a direct call to a SW
>> function which did the same operation.
> 
> Sadly, no.  Without an 8087 the 8088 just ignored the ESC opcode used
> by floating instructions, but ...
> 
>> What we ended up with on most applications was a hybrid, where the
>> compiler would generate calls to a shim, said shim would inspect the
>> available HW (FPU/No FPU) and patch the call:
> 
> The Wizard C compiler, the predecessor of Turbo C, had a hack where it
> emitted floating point instructions but with the first byte replaced
> by a trap opcode.  Then it was roughly as you described, patch it
> to a real float instruction if there was an 8087, or call the software
> version.
> 
We also did that in the PC/IX kernel.

Brian
128/64 division (was: interrupt handling latency and weird register use)
#406
Author: Anton Ertl
Date: Wed, 28 Oct 2026 08:34
44 lines
3369 bytes
Michael S <already5chosen@yahoo.com> writes:
>An interesting question here is "Do one has to include 128b / 64b
>division in the ISA or it's better to leave it off?".
>AMD decided that it was needed, but it seems that nobody else followed
>the suit.

The same can be seen already in the 32-bit relatives.  Most (all?)
RISCs just have 32/32 division, if they have division at all, IA-32
has 64/32.  So they continue that in 64-bit RISCs and AMD64.

Given the existing programming languages, the need for 128/64 bit
division is rare (Forth has UM/MOD and SM/REM, which correspond to
AMD64 DIV and IDIV instructions, respectively), and three source
registers does not fit in usual instruction encodings, so most
architectures leave 128/64 to software.

About software implementations: Implementing 128/64 when you only have
64/64 is messy, however.  And general long division is messy in any
case (but I expect that 128/64 helps in that case; certainly n/64 for
arbitrary n is easy with 128/64 and messy with 64/64).

Let's see how expensive they are on a Ryzen 8700G (Zen4, with 128/64
support) and Power8 (without):

Invocations:

# 64/64
time ./gforth-fast -e ': foo #1_000_000_000_000 {: addend :} 1_000_000_000 {: divisor :} addend 100000000 0 do divisor /mod + addend + loop . ; foo bye'
# 128/64
time ./gforth-fast -e ': foo #1_000_000_000_000_000_000_000_000. 1_000_000_000 {: divisor :} divisor 2/ 1- {: dmax :} 100000000 0 do divisor sm/rem swap dmax min loop d. ; foo bye'

64/64  128/64
0.385s 0.424s Ryzen 8700G
1.176s 2.115s Power8

Given the rarity of 128/64, a factor of 2 looks acceptable.  But if
the division was as fast as on Power8 as on the Ryzen 8700G, the
overhead of 128/64 might be a larger factor (that would probably still
be considered acceptable).

- anton
-- 
'Anyone trying for "industrial quality" ISA should avoid undefined behavior.'
  Mitch Alsup, <c17fcd89-f024-40e7-a594-88a85ac10d20o@googlegroups.com>
Re: 128/64 division (was: interrupt handling latency and weird register use)
#409
Author: John Savard
Date: Wed, 28 Oct 2026 11:10
14 lines
2060 bytes
On Wed, 28 Oct 2026 08:34:27 GMT, anton@mips.complang.tuwien.ac.at
(Anton Ertl) wrote:

>The same can be seen already in the 32-bit relatives.  Most (all?)
>RISCs just have 32/32 division, if they have division at all, IA-32
>has 64/32.  So they continue that in 64-bit RISCs and AMD64.

Since System/360 had 64/32 division, quite automatically I included
128/64 division in Concertina II as the DIVIDE EXTENSIBLY instruction,
while having simple 32/32 and 64/64 instructions also as the plain
DIVIDE instruction (the System/360 only had the former) on the grounds
that this is what compilers will usually use.

John Savard
Re: floating point, interrupt handling latency and weird register use (was Re: OT: Epic RISC-V rant)
#410
Author: Waldek Hebisch
Date: Wed, 28 Oct 2026 12:10
15 lines
1754 bytes
John Levine <johnl@taugh.com> wrote:
> According to Terje Mathisen  <terje.mathisen@tmsw.no>:
>>Intel actually did this correctly back in 1978/79 when they designed the 
>>8087: If you did not have the FPU, then the main 8088 CPU would trap to 
>>an emulation layer which did what was required. The only real problem 
>>was that this was significantly slower than a direct call to a SW 
>>function which did the same operation.
> 
> Sadly, no.  Without an 8087 the 8088 just ignored the ESC opcode used
> by floating instructions, but ...

I did not look at 8088, but 80386 trapped when requested.

-- 
                              Waldek Hebisch
Re: interrupt handling latency and weird register use (was Re: OT: Epic RISC-V rant)
#411
Author: Waldek Hebisch
Date: Wed, 28 Oct 2026 12:17
36 lines
2946 bytes
Terje Mathisen <terje.mathisen@tmsw.no> wrote:
> MitchAlsup wrote:
>> anton@mips.complang.tuwien.ac.at (Anton Ertl) posted:
>> 
>>> makendo <makendo@makendo.invalid> writes:
>>>> The case where division is implemented but
>>>> multiplication is not does not have a name assigned -- it is pretty
>>>> well known that hardware designers, compiler writers and low-level
>>>> programmers hate division far more than multiplication, so I doubt
>>>> if divison-only hardware is even out in the wild for any ISA...
>>>
>>> I don't think that "hate" is the right concept.  Division is costly:
>> 
>> But "lack of division" is also costly !! especially if some future
>> implementation will have division {which it will} and then you have
>> no direct means to make the dusty decks fast.
> 
> Intel actually did this correctly back in 1978/79 when they designed the 
> 8087: If you did not have the FPU, then the main 8088 CPU would trap to 
> an emulation layer which did what was required. The only real problem 
> was that this was significantly slower than a direct call to a SW 
> function which did the same operation.

I used TeX on 386.  It did relatively small number of floating
point operations.  On 386 with 387 FPU operation almost vanished
in noise.  On 386 without FPU TeX on one of my inputs had 3 times
longer execution time, that is about 66% time was spent in FPU
emulator.  IIRC emulation was at least hundreds (if not thousends)
times slower than FPU (which was also not that fast).

That partially could be due to specific emulation, but when
program needed to run fast on machines without FPU one basically
wanted to eradicate all uses of FPU in that program.

-- 
                              Waldek Hebisch
Re: interrupt handling latency and weird register use (was Re: OT: Epic RISC-V rant)
#413
Author: Waldek Hebisch
Date: Wed, 28 Oct 2026 12:33
36 lines
2979 bytes
MitchAlsup <user5857@newsgrouper.org.invalid> wrote:
> anton@mips.complang.tuwien.ac.at (Anton Ertl) posted:
> 
>> makendo <makendo@makendo.invalid> writes:
>> >The case where division is implemented but
>> >multiplication is not does not have a name assigned -- it is pretty
>> >well known that hardware designers, compiler writers and low-level
>> >programmers hate division far more than multiplication, so I doubt
>> >if divison-only hardware is even out in the wild for any ISA...
>> 
>> I don't think that "hate" is the right concept.  Division is costly:
> 
> But "lack of division" is also costly !! especially if some future
> implementation will have division {which it will} and then you have
> no direct means to make the dusty decks fast.

You assume binaries or assembler code.  In microcontroller world
programs are frequently compiled for one specific CPU model.
And in case of microcontrollers savings due to ommision of
divide circuit can be significant.  I know you do not like
Risc-V, but one small model (CH32V003) even skips multiplication.
IIUC even smallest Arm-s have multiplication (which theoretically
can be slow, but on all small models that I know it 32 bit
multiplication executes in 1 cycle).

> Note to µArchitects, put the instruction in even if you are going to
> TRAP to SW emulation. Later on when DIV is implemented it just runs
> faster and you had to do nothing (but put it in).

You need to make it fast enough so that compilers are not tempted
to call software emulation.  Also beware of interrput latency,
if division is slow microcontroller probably should allow
interrupts in the middle of division.

-- 
                              Waldek Hebisch
Re: interrupt handling latency and weird register use (was Re: OT: Epic RISC-V rant)
#414
Author: Anton Ertl
Date: Wed, 28 Oct 2026 12:41
14 lines
2014 bytes
antispam@fricas.org (Waldek Hebisch) writes:
>I used TeX on 386.  It did relatively small number of floating
>point operations.

AFAIK TeX does not do FP, or at least the versions from those times
did not.  That's because TeX was intended to create reproducible
results across machines, and FP was not useful for that when TeX was
written, because FP operations behaved differently on different
machines.

- anton
-- 
'Anyone trying for "industrial quality" ISA should avoid undefined behavior.'
  Mitch Alsup, <c17fcd89-f024-40e7-a594-88a85ac10d20o@googlegroups.com>
Re: interrupt handling latency and weird register use (was Re: OT: Epic RISC-V rant)
#415
Author: John Savard
Date: Wed, 28 Oct 2026 15:20
19 lines
2216 bytes
On Wed, 28 Oct 2026 12:33:44 -0000 (UTC), antispam@fricas.org (Waldek
Hebisch) wrote:
>MitchAlsup <user5857@newsgrouper.org.invalid> wrote:

>> But "lack of division" is also costly !! especially if some future
>> implementation will have division {which it will} and then you have
>> no direct means to make the dusty decks fast.

>You assume binaries or assembler code.  In microcontroller world
>programs are frequently compiled for one specific CPU model.

This may be, but his advice is still eminently sound for the Windows
desktop PC world. Which is the one in which billions of helpless
consumers face the industry almost completely on their own.
Corporations implementing devices containing microcontrollers, on the
other hand, are much more likely to be able to take care of
themselves.

John Savard
Re: interrupt handling latency and weird register use (was Re: OT: Epic RISC-V rant)
#418
Author: MitchAlsup
Date: Wed, 28 Oct 2026 15:47
47 lines
3293 bytes
antispam@fricas.org (Waldek Hebisch) posted:

> MitchAlsup <user5857@newsgrouper.org.invalid> wrote:
> > anton@mips.complang.tuwien.ac.at (Anton Ertl) posted:
> > 
> >> makendo <makendo@makendo.invalid> writes:
> >> >The case where division is implemented but
> >> >multiplication is not does not have a name assigned -- it is pretty
> >> >well known that hardware designers, compiler writers and low-level
> >> >programmers hate division far more than multiplication, so I doubt
> >> >if divison-only hardware is even out in the wild for any ISA...
> >> 
> >> I don't think that "hate" is the right concept.  Division is costly:
> > 
> > But "lack of division" is also costly !! especially if some future
> > implementation will have division {which it will} and then you have
> > no direct means to make the dusty decks fast.
> 
> You assume binaries or assembler code.  In microcontroller world
> programs are frequently compiled for one specific CPU model.
> And in case of microcontrollers savings due to ommision of
> divide circuit can be significant.

This gets at my point: my point is the opposite of RISC-V--that is
one defines all the OpCodes and if an implementation does not deal
with OpCode X, that implementation takes an OPERATION fault. RISC-V
leaves that OpCode slot undefined (potentially available for other
uses).

>                                     I know you do not like
> Risc-V, but one small model (CH32V003) even skips multiplication.
> IIUC even smallest Arm-s have multiplication (which theoretically
> can be slow, but on all small models that I know it 32 bit
> multiplication executes in 1 cycle).
> 
> > Note to µArchitects, put the instruction in even if you are going to
> > TRAP to SW emulation. Later on when DIV is implemented it just runs
> > faster and you had to do nothing (but put it in).
> 
> You need to make it fast enough so that compilers are not tempted
> to call software emulation.  Also beware of interrput latency,

I am shooting at 10 cycles there and 10 cycles back.

> if division is slow microcontroller probably should allow
> interrupts in the middle of division.
> 
Re: floating point, interrupt handling latency and weird register use (was Re: OT: Epic RISC-V rant)
#419
Author: John Levine
Date: Wed, 28 Oct 2026 16:46
18 lines
1973 bytes
According to Waldek Hebisch <antispam@fricas.org>:
>> Sadly, no.  Without an 8087 the 8088 just ignored the ESC opcode used
>> by floating instructions, but ...
>
>I did not look at 8088, but 80386 trapped when requested.

The 8087 and 80287 were separate chips that sat on the bus
and snooped to see what to do.  No x87, no snooping, no
action.

The 386 had a much more complicated coprocessor interface which could
work with either a 16 bit 287 or a 32 bit 387.  As you note, it added
an option to trap if you had neither.

-- 
Regards,
John Levine, johnl@taugh.com, Primary Perpetrator of "The Internet for Dummies",
Please consider the environment before reading this e-mail. https://jl.ly
Re: interrupt handling latency and weird register use (was Re: OT: Epic RISC-V rant)
#426
Author: Waldek Hebisch
Date: Wed, 28 Oct 2026 19:06
25 lines
2367 bytes
Anton Ertl <anton@mips.complang.tuwien.ac.at> wrote:
> antispam@fricas.org (Waldek Hebisch) writes:
>>I used TeX on 386.  It did relatively small number of floating
>>point operations.
> 
> AFAIK TeX does not do FP, or at least the versions from those times
> did not.  That's because TeX was intended to create reproducible
> results across machines, and FP was not useful for that when TeX was
> written, because FP operations behaved differently on different
> machines.

Wrong.  Main computations like line and page breaking were integer
only.  But some positioning decisions that could only lead to
tiny error were done in floating point.  Knuth claimed that each
implementation would do line and page breaks in "the same" place
and AFAIK this was true.  But he did not claim bit-for-bit indentical
results, the claim was that differences were smaller that human
can see.

IIRC Knuth allowed use of fixed point for those computations, but
WEB to C system (and probably also other implementations) used
floating point.

-- 
                              Waldek Hebisch
Re: interrupt handling latency and weird register use (was Re: OT: Epic RISC-V rant)
#431
Author: BGB
Date: Wed, 28 Oct 2026 20:52
109 lines
5972 bytes
On 10/28/2026 7:33 AM, Waldek Hebisch wrote:
> MitchAlsup <user5857@newsgrouper.org.invalid> wrote:
>> anton@mips.complang.tuwien.ac.at (Anton Ertl) posted:
>>
>>> makendo <makendo@makendo.invalid> writes:
>>>> The case where division is implemented but
>>>> multiplication is not does not have a name assigned -- it is pretty
>>>> well known that hardware designers, compiler writers and low-level
>>>> programmers hate division far more than multiplication, so I doubt
>>>> if divison-only hardware is even out in the wild for any ISA...
>>>
>>> I don't think that "hate" is the right concept.  Division is costly:
>>
>> But "lack of division" is also costly !! especially if some future
>> implementation will have division {which it will} and then you have
>> no direct means to make the dusty decks fast.
> 
> You assume binaries or assembler code.  In microcontroller world
> programs are frequently compiled for one specific CPU model.
> And in case of microcontrollers savings due to ommision of
> divide circuit can be significant.  I know you do not like
> Risc-V, but one small model (CH32V003) even skips multiplication.
> IIUC even smallest Arm-s have multiplication (which theoretically
> can be slow, but on all small models that I know it 32 bit
> multiplication executes in 1 cycle).
> 

Yeah.

Ironically, the smallest microcontroller style core I did was using a 
very limited subset of the SuperH ISA.

But, in this case, can note:
   16-bit instructions;
   No multiply or divide;
   No general-purpose shift;
     Would use "shift slides".
   No auto-increment (was present in normal SH);
   Not pipelined and would do an I$ miss every 8 instrs;
     Also no real D$ either, would miss nearly every access;
     And memory access was not pipelined.
   ...

This whole thing kind of died off, ironically, because I didn't have 
much particular use for cheap-but-slow cores.

A small RISC-V core would cost more, but be a little more useful.
For a microcontroller use-case, RV32I is actually pretty sane; though 
RV32IMC or RV32IC is more industry-standard here.

There is RV32E (with 16 registers), but it seems relatively few people 
want to limit the register space that bad.

Main "cheapening" would be to only allow X0 and X1 as destinations for 
JAL and JALR, and requiring that Rs2 for Bcc ops is X0.


>> Note to µArchitects, put the instruction in even if you are going to
>> TRAP to SW emulation. Later on when DIV is implemented it just runs
>> faster and you had to do nothing (but put it in).
> 
> You need to make it fast enough so that compilers are not tempted
> to call software emulation.  Also beware of interrput latency,
> if division is slow microcontroller probably should allow
> interrupts in the middle of division.
> 

Yeah.


Fast interrupt handling is always a long standing issue.

Seemingly, there is a multi-way split:
   Require ISR to spill/reload registers manually;
     Looks bad on paper, but often cheaper/faster in practice.
   Register Banks:
     Looks fast, but there are a lot of "hidden gotchas" here.
   Automatic spill/reload to/from memory contexts:
     Seems clever, but likewise comes with a lot of "gotchas".


Half tempting is to provide some way to allow the ISRs to patch 
instructions directly to a handler sequence.
This makes a problem though mostly for things like addressing.

Say, in many cases, something like a RISC-V JAL doesn't reach far enough 
to be able to put a patched-in handler in-range.

So, one almost needs something like a hidden architectural jump table, 
say and special instructions to jump via this jump table.


For BGBCC, I had taken a different option:
The PE/PEL loading is handled by the kernel;
The PE read-only sections, data/bss, and stack, are unrelated;
The compiler counts up how many "potentially trapping" instructions are 
used and explicitly leaves space for basic patch handling (enough pad 
space for encode an Abs64 branch).

For RV64, this pad space would need to be within 1MB of the offending 
instruction, but for XG3 can be within 16MB.


There is still a little more complexity if dealing with Linux ELF-PIE 
binaries (and dealing with glibc's "ld.so" behavior), but there are 
possible options that could be tried (to maybe provision for providing 
free space near the ".text" sections).

Re: interrupt handling latency and weird register use (was Re: OT: Epic RISC-V rant)
#428
Author: BGB
Date: Wed, 28 Oct 2026 21:39
60 lines
4000 bytes
On 10/28/2026 7:41 AM, Anton Ertl wrote:
> antispam@fricas.org (Waldek Hebisch) writes:
>> I used TeX on 386.  It did relatively small number of floating
>> point operations.
> 
> AFAIK TeX does not do FP, or at least the versions from those times
> did not.  That's because TeX was intended to create reproducible
> results across machines, and FP was not useful for that when TeX was
> written, because FP operations behaved differently on different
> machines.
> 

Still sort of an issue IME:

Different compilers, different optimization settings, whether it is 
using x87 or SSE, ..., may subtly change the results of FP calculations.


Well, or sometimes it may be CPU dependent:
I had encountered some code that failed when compiled for 64-bit and run 
on an Intel CPU, but still worked fine on an AMD CPU;
I eventually figured out it was because the code in question was doing 
something unorthodox (using "float*" and "double*" operations to copy 
memory) and the Intel CPU's MOVSS and MOVSD instructions were apparently 
stomping the value if it was a NaN (changing the NaN bit pattern to a 
different NaN bit pattern).

Whereas, on the AMD CPU, "MOVSS/MOVSD xmm, [mem]" behaved the same as 
"MOVD/MOVQ xmm, [mem]", leaving the NaN's alone.



Though, that said, did at one point have a CPU that seemingly had 
non-deterministic floating-point math, where one could run the same 
calculation multiple times and get slightly different results each time.

I think I eventually realized that this particular CPU (an AMD Athlon64 
/ Clawhammer) had floating-point math that was sensitive to CPU 
temperature (CPU got hot, and FPU math got noisy).

Nothing drastic, mostly it was like it would start adding random noise 
into the low-order bits of FPU calculations. Mostly didn't effect much.

Not exactly the worst issue this computer had (actually, it was horribly 
unstable and crash-prone in general).


Well, I suspect it was maybe a case of CPUs were often clocked at a 
point where they were on the knife edge of being able to work at all. I 
lot of my follow-on computers, I ended up needing to explicitly underclock.

Actually, my current Xen+ PC is the first I ended up not needing to 
underclock, as it appears to run pretty stable and reliable at its stock 
CPU speed.

...


> - anton
Re: interrupt handling latency and weird register use (was Re: OT: Epic RISC-V rant)
#442
Author: Anton Ertl
Date: Thu, 29 Oct 2026 16:57
17 lines
2114 bytes
MitchAlsup <user5857@newsgrouper.org.invalid> writes:
>especially if some future
>implementation will have division {which it will} and then you have
>no direct means to make the dusty decks fast.
>
>Note to µArchitects, put the instruction in even if you are going to
>TRAP to SW emulation. Later on when DIV is implemented it just runs
>faster and you had to do nothing (but put it in).

Microarchitects will not implement an instruction that's not in the
instruction set designed by the architects.  But for architects, your
advice is good and not just for division.

- anton
-- 
'Anyone trying for "industrial quality" ISA should avoid undefined behavior.'
  Mitch Alsup, <c17fcd89-f024-40e7-a594-88a85ac10d20o@googlegroups.com>
Re: interrupt handling latency and weird register use (was Re: OT: Epic RISC-V rant)
#450
Author: Josh Vanderhoof
Date: Thu, 29 Oct 2026 23:25
24 lines
2353 bytes
MitchAlsup <user5857@newsgrouper.org.invalid> writes:

>> > Note to µArchitects, put the instruction in even if you are 
>> > going to TRAP to SW emulation. Later on when DIV is 
>> > implemented it just runs faster and you had to do nothing 
>> > (but put it in). 
>>  You need to make it fast enough so that compilers are not 
>> tempted to call software emulation.  Also beware of interrput 
>> latency, 
> 
> I am shooting at 10 cycles there and 10 cycles back. 

Would it be possible to have a hardware version of polyfill?  The 
basic idea would be that instead of emulation via trapping, the 
software calls a standardized divide routine.  On hardware with a 
divide instruction it checks the routine and if it sees it's the 
standard divide routine it just uses its divide instruction 
instead.  If it doesn't have hardware division it just runs the 
divide routine.

I think I'd be more likely to use new instructions if they worked 
this way, providing the standard polyfill routine in the 
documentation for the new instruction.  The way things work now I 
only use them after they've been around for a decade.
Re: interrupt handling latency and weird register use (was Re: OT: Epic RISC-V rant)
#452
Author: MitchAlsup
Date: Fri, 30 Oct 2026 00:30
40 lines
2979 bytes
Josh Vanderhoof <x@y.z> posted:

> MitchAlsup <user5857@newsgrouper.org.invalid> writes:
> 
> >> > Note to µArchitects, put the instruction in even if you are 
> >> > going to TRAP to SW emulation. Later on when DIV is 
> >> > implemented it just runs faster and you had to do nothing 
> >> > (but put it in). 
> >>  You need to make it fast enough so that compilers are not 
> >> tempted to call software emulation.  Also beware of interrput 
> >> latency, 
> > 
> > I am shooting at 10 cycles there and 10 cycles back. 
> 
> Would it be possible to have a hardware version of polyfill?  The 
> basic idea would be that instead of emulation via trapping, the 
> software calls a standardized divide routine.  On hardware with a 
> divide instruction it checks the routine and if it sees it's the 
> standard divide routine it just uses its divide instruction 
> instead.  If it doesn't have hardware division it just runs the 
> divide routine.

I do not see any justification of NOT having DIV as an instruction
and in HW (by means of some king of sequencer). In the same way
we can put 16 GBOoO cores on a single die with 256-bit wide SIMD, 
the amount of area saved not doing DIV is invisible when seen at 
the die-level.

In the smallest conceivable implementations, DIV is a multiplexer in
the feedback-loop around the integer ADDer and a 5-state sequencer.

For me, I can't see building a core that does not have a 64×64
multiplier, either. 
 
> I think I'd be more likely to use new instructions if they worked 
> this way, providing the standard polyfill routine in the 
> documentation for the new instruction.  The way things work now I 
> only use them after they've been around for a decade.

I have no idea what you mean by polyfill.
Re: interrupt handling latency and weird register use (was Re: OT: Epic RISC-V
#461
Author: John Dallman
Date: Fri, 30 Oct 2026 11:50
26 lines
2039 bytes
In article <ygnwlr084yt.fsf@y.z>, x@y.z (Josh Vanderhoof) wrote:

> Would it be possible to have a hardware version of polyfill?  The 
> basic idea would be that instead of emulation via trapping, the 
> software calls a standardized divide routine.  On hardware with a 
> divide instruction it checks the routine and if it sees it's the 
> standard divide routine it just uses its divide instruction 
> instead.  If it doesn't have hardware division it just runs the 
> divide routine.

Older 32-bit versions of AIX had a version of this IIRC that IBM called
"millicode." The problem was that POWER1 and POWER2 didn't have quite the
same ISA as 32-bit PowerPC. IBM produced lots of material about how they
were /mostly/ the same, but the differences were a real pain for
compilers. 

You could do the same things on the variant ISAs, but some of them needed
more than one instruction. So the compiler would generate enough space
for the longest of the alternative instruction sequences and the loader,
which knows what hardware it's running on, would fill in the correct
sequences, and no-ops in any spare space. 

None of this was necessary on 64-bit AIX, where the core ISA was
standardised from the beginning. 

John 
Re: interrupt handling latency and weird register use (was Re: OT: Epic RISC-V rant)
#467
Author: BGB
Date: Fri, 30 Oct 2026 19:01
231 lines
10371 bytes
On 10/29/2026 7:30 PM, MitchAlsup wrote:
> Josh Vanderhoof <x@y.z> posted:
> 
>> MitchAlsup <user5857@newsgrouper.org.invalid> writes:
>>
>>>>> Note to µArchitects, put the instruction in even if you are
>>>>> going to TRAP to SW emulation. Later on when DIV is
>>>>> implemented it just runs faster and you had to do nothing
>>>>> (but put it in).
>>>>   You need to make it fast enough so that compilers are not
>>>> tempted to call software emulation.  Also beware of interrput
>>>> latency,
>>>
>>> I am shooting at 10 cycles there and 10 cycles back.
>>
>> Would it be possible to have a hardware version of polyfill?  The
>> basic idea would be that instead of emulation via trapping, the
>> software calls a standardized divide routine.  On hardware with a
>> divide instruction it checks the routine and if it sees it's the
>> standard divide routine it just uses its divide instruction
>> instead.  If it doesn't have hardware division it just runs the
>> divide routine.
> 
> I do not see any justification of NOT having DIV as an instruction
> and in HW (by means of some king of sequencer). In the same way
> we can put 16 GBOoO cores on a single die with 256-bit wide SIMD,
> the amount of area saved not doing DIV is invisible when seen at
> the die-level.
> 
> In the smallest conceivable implementations, DIV is a multiplexer in
> the feedback-loop around the integer ADDer and a 5-state sequencer.
> 
> For me, I can't see building a core that does not have a 64×64
> multiplier, either.
>   


I did such a thing in an FPGA (for 64-bit MUL/DIV):
   Shift 1-bit left;
   Do an ADD/SUB;
   Maybe use carry status as a comparison;
   ~ 36 or 68 clock cycles for 32 or 64 bit DIV;
   ...
And it still managed to burn through around 1000 LUTs.

Granted, not particularly large if compared with some things (the L1 D$ 
is far larger, etc), but still not exactly negligible either.
   Well:
     L1 D$, I$, regfile/forwarding, and instruction decoder
   Being the "big eaters".
     Followed by, say:
       Main FPU
       SIMD Unit (Binary16/Binary32)
       Int64 MUL/DIV
       Integer ALUs (3 of them);
       ...
     Shift was more than plain ALU,
       but limited to the first 2 lanes.
       Third lane only does plain ALU ops.


There was an investigated option to allow speculatively running the 
32-bit DIV through the 32-bit multiplier by using a small lookup table 
for reciprocals, and using this result (skipping the main divider) if it 
hit (32-bit value being divided by a divisor in the range of 1 to 63 or 
similar).

This was actually effective, but the relative impact of making 
common-case divides faster was small enough to be negligible for overall 
performance; for a non-zero cost.


Still probably worth having a DIV instruction in any "application class" 
core though.
Where, if a core is intended for general purpose application software, 
probably should have a divide instruction. If intended for embedded 
systems or microcontrollers (where typically cost optimization is the 
dominant concern and code is typically compiled for a specific CPU 
model), maybe a good idea to leave it out.

I originally was more opposed to having instructions for things which 
couldn't be guaranteed to be affordably viable or cost effective in 
hardware; but have since softened more to the idea of using 
trap-and-emulate in these cases.

There is an option of trap and emulate, or hot-patch, but does require 
that the kernel has some space within JAL/BSR distance to patch into.


Can note that a lot of the mainline/dominant cores (in the ARM space) 
are in-order dual-issue.


This is arguably cheaper than the 3-wide approach I had used:
   Lane 1: ALU, Shift, BRA, CMP, MEM, FPU, ...
   Lane 2: ALU, Shift, CMP (3R), FPU-ALT, ...
   Lane 3: ALU

The main merit of 3 wide here is that:
   A 3-input instruction can co-execute with another instruction;
   Can dual issue 3-input ops;
   Can support 128-bit 3-input ops;
   ...

Whereas a strictly dual-lane core couldn't do any 128-bit 3-input ops, 
various edge-case instructions, ... And couldn't dual-issue instructions 
whenever doing something like an indexed store.

That said, 4R2W is still cheaper than 6R3W.
And, 6R2W dual-issue doesn't save enough to be worthwhile, vs having a 
3rd ALU; even if the 3rd lane ALU is relatively low traffic (but does 
occasionally pay off in dense integer-math heavy code).

In this case, the ALU does:
   ADD/SUB/AND/OR/XOR (in both 3R and 3RI variants).
   Also MOV(2R/2RI) / MV / LI, ...


But, despite the ARM cores being dual-issue, they tend to have NEON, 
which looks like a more expensive approach to SIMD than what I had been 
using (needs its own register file, etc).

Whereas my core had been using the GPR regfile for everything, and just 
pretending to have a GPR and FPR regfile for sake of the RISC-V mode.

Not seen a particularly strong case for having a split between GPRs and 
FPRs other than "FPU ops are higher latency than ALU ops, so need their 
own regfile and pipeline for 'reasons'...".


Though, in my case, that I went for having typically higher latency for 
ALU ops:
   The MV / LI cases are 1-cycle;
   Other ALU / Shift / etc: 2 cycle.
   Load: 3 or 4 cycles.
     3 cycles: Basic memory load;
     4 cycles: Load with a converter step
       Eg: Binary32->Binary64 or texture loads.

A lot of the other RV cores it seems had aimed for:
   1 cycle: All basic instructions;
   2 cycle: Memory Load;
   ...

Did experiment with some fast-path cases for ALU and Load, but had noted 
that while they helped the basic/pure RV64G base, they didn't help 
notably with other cases, and most of the difference for RV64G was tied 
fairly specifically to the need for multi-op sequences for index 
calculations. If you have LEA/SHnADD, and indexed-load, the relative 
performance gain of 1-cycle latency on Shift and ADD instructions and 
similar mostly goes away; except maybe when spinning in tight loops 
(which is seemingly a poor case on my CPU design).

Well, say "while(*ct++==*cs++);" is something preferably avoided.


Seemingly ran into a bit of an issue in this space:
Can't really move to higher clock speeds without sacrifices that hurt 
more than they gain;
Can't really do that much more per-cycle without needing to drop lower 
in terms of clock speed (which also hurts);
...

Like, it seems like I had found a local optimum in the current 50 MHz 
target range (at least for the current Artix-7 chips).


Like, can make a core that runs at 75 MHz on an FPGA, but the only thing 
it can really gain is "slightly faster at Doom, slower on everything else".

Or, maybe go for RV32IM at 100 MHz, which runs Doom and similar well, 
but is pretty limited for other tasks.


More recently, stuff has gotten a lot slower as this search space seems 
to be pretty much explored; and practical usefulness is more debatable 
(vs, say, the cheaper option of maybe using an ARM SBC maybe paired with 
a separate 8/16 microcontroller chip for any RT stuff).


And, all I really achieved with my own CPU design was seemingly just 
using it for running ports of games and similar, rather than for 
anything "actually useful".

Well, and even then, "Make framerates in Quake not suck" still being a 
difficult problem.


>> I think I'd be more likely to use new instructions if they worked
>> this way, providing the standard polyfill routine in the
>> documentation for the new instruction.  The way things work now I
>> only use them after they've been around for a decade.
> 
> I have no idea what you mean by polyfill.


My understanding of it is, say:
You call a function for something as the default path (possibly with an 
indirect call via a function pointer);
If there is a faster version, it patches over to that after detecting 
that it exists;
If an instruction exists, one could maybe go further and patch out the 
original function call itself.

Say:
   JAL X1, __divsi   //Default case
Then, say:
   __divsi:
     LD  X5, __divsi_fptr  //decomposes into AUIPC+LD or similar
     JALR X0, X5, 0

   .section .data
   __divsi_fptr .quad __divsi_initial

Where __divsi_initial checks if a faster divide exists and if so 
replaces itself with that, or replaces the call with a call to the 
generic version.

Say:
   __divsi_fast:
     DIVW X10, X10, X11   //if we have the DIVW instruction...
     RTS

   __divsi_slow:
     ... //ye olde shift-subtract loop


Or, basically the inverse of the "have instruction, but trap and 
emulate" case.

Re: interrupt handling latency and weird register use (was Re: OT: Epic RISC-V rant)
#475
Author: Josh Vanderhoof
Date: Sat, 31 Oct 2026 05:02
68 lines
4472 bytes
MitchAlsup <user5857@newsgrouper.org.invalid> writes:

> Josh Vanderhoof <x@y.z> posted: 
> 
>> MitchAlsup <user5857@newsgrouper.org.invalid> writes:  
>> >> > Note to µArchitects, put the instruction in even if you 
>> >> > are  going to TRAP to SW emulation. Later on when DIV is 
>> >> > implemented it just runs faster and you had to do nothing 
>> >> > (but put it in).  
>> >>  You need to make it fast enough so that compilers are not  
>> >> tempted to call software emulation.  Also beware of 
>> >> interrput  latency,  
>> >  I am shooting at 10 cycles there and 10 cycles back.  
>>  Would it be possible to have a hardware version of polyfill? 
>> The  basic idea would be that instead of emulation via 
>> trapping, the  software calls a standardized divide routine. 
>> On hardware with a  divide instruction it checks the routine 
>> and if it sees it's the  standard divide routine it just uses 
>> its divide instruction  instead.  If it doesn't have hardware 
>> division it just runs the  divide routine. 
> 
> I do not see any justification of NOT having DIV as an 
> instruction and in HW (by means of some king of sequencer). In 
> the same way we can put 16 GBOoO cores on a single die with 
> 256-bit wide SIMD,  the amount of area saved not doing DIV is 
> invisible when seen at  the die-level. 
> 
> In the smallest conceivable implementations, DIV is a 
> multiplexer in the feedback-loop around the integer ADDer and a 
> 5-state sequencer. 
> 
> For me, I can't see building a core that does not have a 64×64 
> multiplier, either.  

I get that, but I'm not really talking about the necessity of 
divide instructions.  I'm talking about dealing with processors 
with different sets of features.

Say instead it's for something called featurex and some processors 
want it in hardware and some don't.  It'd be much easier for 
someone writing the software if a standard sequence of 
instructions for doing featurex was defined and new processors 
that do featurex in hardware automatically checked call targets 
and recognize when the instruction sequence matches featurex. 
Then when the routine is called later uses the dedicated 
instruction instead doing the call.

It's be really nice because the code would be identical for 
everything and also run about as fast as possible on everything. 
I have no idea how hard it would be to keep the track of which 
subroutines are actually new instructions though.

I'd much rather have something like this than have to write 
multiple versions of things depending on whether or not some CPUID 
bit is set.
 
>> I think I'd be more likely to use new instructions if they 
>> worked  this way, providing the standard polyfill routine in 
>> the  documentation for the new instruction.  The way things 
>> work now I  only use them after they've been around for a 
>> decade. 
> 
> I have no idea what you mean by polyfill. 

When they add new stuff to Javascript they provide equivalent code 
that works in older versions that's called "polyfill".  It's 
convenient because it lets you use the new API without needing 
alternate versions for older interpreters.
Re: interrupt handling latency and weird register use (was Re: OT: Epic RISC-V rant)
#529
Author: Terje Mathisen
Date: Sat, 31 Oct 2026 07:44
108 lines
6186 bytes
Josh Vanderhoof wrote:
> MitchAlsup <user5857@newsgrouper.org.invalid> writes:
> 
>> Josh Vanderhoof <x@y.z> posted:
>>> MitchAlsup <user5857@newsgrouper.org.invalid> writes: >> > Note to 
>>> µArchitects, put the instruction in even if you >> > are  going to 
>>> TRAP to SW emulation. Later on when DIV is >> > implemented it just 
>>> runs faster and you had to do nothing >> > (but put it in). >>  You 
>>> need to make it fast enough so that compilers are not >> tempted to 
>>> call software emulation.  Also beware of >> interrput  latency, >  I 
>>> am shooting at 10 cycles there and 10 cycles back.  Would it be 
>>> possible to have a hardware version of polyfill? The  basic idea 
>>> would be that instead of emulation via trapping, the  software calls 
>>> a standardized divide routine. On hardware with a  divide instruction 
>>> it checks the routine and if it sees it's the  standard divide 
>>> routine it just uses its divide instruction  instead.  If it doesn't 
>>> have hardware division it just runs the  divide routine. 
>>
>> I do not see any justification of NOT having DIV as an instruction and 
>> in HW (by means of some king of sequencer). In the same way we can put 
>> 16 GBOoO cores on a single die with 256-bit wide SIMD,  the amount of 
>> area saved not doing DIV is invisible when seen at  the die-level.
>> In the smallest conceivable implementations, DIV is a multiplexer in 
>> the feedback-loop around the integer ADDer and a 5-state sequencer.
>> For me, I can't see building a core that does not have a 64×64 
>> multiplier, either. 
> 
> I get that, but I'm not really talking about the necessity of divide 
> instructions.  I'm talking about dealing with processors with different 
> sets of features.
> 
> Say instead it's for something called featurex and some processors want 
> it in hardware and some don't.  It'd be much easier for someone writing 
> the software if a standard sequence of instructions for doing featurex 
> was defined and new processors that do featurex in hardware 
> automatically checked call targets and recognize when the instruction 
> sequence matches featurex. Then when the routine is called later uses 
> the dedicated instruction instead doing the call.

There is simply no way to do that for individual instructions intended 
to be used in a tight loop. The AES opcodes are a typical example:

You can write two different functions, one using AES opcodes and one 
doing it with regular integer instructions, but if you try to replace 
each AES opcode with a sequence that can be back-patched into the actual 
instructions, then you will probably end up with far slower results.

The correct way here is to have a function pointer that initially points 
at a thunk which checks (CPUID) the local cpu and then updates the 
pointer to go directly to the optimized version.

Terje
> 
> It's be really nice because the code would be identical for everything 
> and also run about as fast as possible on everything. I have no idea how 
> hard it would be to keep the track of which subroutines are actually new 
> instructions though.
> 
> I'd much rather have something like this than have to write multiple 
> versions of things depending on whether or not some CPUID bit is set.
> 
>>> I think I'd be more likely to use new instructions if they worked  
>>> this way, providing the standard polyfill routine in the  
>>> documentation for the new instruction.  The way things work now I  
>>> only use them after they've been around for a decade. 
>>
>> I have no idea what you mean by polyfill. 
> 
> When they add new stuff to Javascript they provide equivalent code that 
> works in older versions that's called "polyfill".  It's convenient 
> because it lets you use the new API without needing alternate versions 
> for older interpreters.

They have the luxury of JIT everywhere so they can still run at 
near-hardware speed after first finding the opcodes are available.

Terje

-- 
- <Terje.Mathisen at tmsw.no>
"almost all programming can be viewed as an exercise in caching"
Unimplemented opcodes via jump tables (was: interrupt handling latency and weird register use)
#480
Author: Thomas Koenig
Date: Sat, 31 Oct 2026 09:45
31 lines
2919 bytes
Josh Vanderhoof <x@y.z> schrieb:

> Say instead it's for something called featurex and some processors 
> want it in hardware and some don't.  It'd be much easier for 
> someone writing the software if a standard sequence of 
> instructions for doing featurex was defined and new processors 
> that do featurex in hardware automatically checked call targets 
> and recognize when the instruction sequence matches featurex. 
> Then when the routine is called later uses the dedicated 
> instruction instead doing the call.

You could have instructions that either do things in hardware or
jump to a subroutine at a defined address from a jump table
index by opcode.  That would solve the problem, I think, and

> It's be really nice because the code would be identical for 
> everything and also run about as fast as possible on everything. 
> I have no idea how hard it would be to keep the track of which 
> subroutines are actually new instructions though.

this would be OK.

Has anybody actually done this?  Seems obvious, but maybe only
in hindsight, and could save the RISC-V compiler writers a
lot of grief, at least as far as compatibility is concerned, but
cost would be another matter.

-- 
This USENET posting was made without artificial intelligence,
artificial impertinence, artificial arrogance, artificial stupidity,
artificial flavorings or artificial colorants.
Re: interrupt handling latency and weird register use (was Re: OT: Epic RISC-V rant)
#484
Author: Thomas Koenig
Date: Sat, 31 Oct 2026 15:15
13 lines
2067 bytes
Terje Mathisen <terje.mathisen@tmsw.no> schrieb:

> The correct way here is to have a function pointer that initially points 
> at a thunk which checks (CPUID) the local cpu and then updates the 
> pointer to go directly to the optimized version.

gfortran does that for calling different versions of matmul
compiled with different flags.

-- 
This USENET posting was made without artificial intelligence,
artificial impertinence, artificial arrogance, artificial stupidity,
artificial flavorings or artificial colorants.
Re: Unimplemented opcodes via jump tables (was: interrupt handling latency and weird register use)
#491
Author: MitchAlsup
Date: Sat, 31 Oct 2026 18:27
36 lines
2837 bytes
Thomas Koenig <tkoenig@netcologne.de> posted:

> Josh Vanderhoof <x@y.z> schrieb:
> 
> > Say instead it's for something called featurex and some processors 
> > want it in hardware and some don't.  It'd be much easier for 
> > someone writing the software if a standard sequence of 
> > instructions for doing featurex was defined and new processors 
> > that do featurex in hardware automatically checked call targets 
> > and recognize when the instruction sequence matches featurex. 
> > Then when the routine is called later uses the dedicated 
> > instruction instead doing the call.
> 
> You could have instructions that either do things in hardware or
> jump to a subroutine at a defined address from a jump table
> index by opcode.  That would solve the problem, I think, and

That would add LDD-latency plus JUMP-latency to instruction-latency--
even if the index was extracted by HW. Probably around 5-6 cycles.
 
> > It's be really nice because the code would be identical for 
> > everything and also run about as fast as possible on everything. 
> > I have no idea how hard it would be to keep the track of which 
> > subroutines are actually new instructions though.
> 
> this would be OK.
> 
> Has anybody actually done this?

How do you think microCode works ??

>                                  Seems obvious, but maybe only
> in hindsight, and could save the RISC-V compiler writers a
> lot of grief, at least as far as compatibility is concerned, but
> cost would be another matter.
> 
Re: Unimplemented opcodes via jump tables (was: interrupt handling latency and weird register use)
#494
Author: Thomas Koenig
Date: Sat, 31 Oct 2026 19:10
47 lines
3610 bytes
MitchAlsup <user5857@newsgrouper.org.invalid> schrieb:
> Thomas Koenig <tkoenig@netcologne.de> posted:
>
>> Josh Vanderhoof <x@y.z> schrieb:
>> 
>> > Say instead it's for something called featurex and some processors 
>> > want it in hardware and some don't.  It'd be much easier for 
>> > someone writing the software if a standard sequence of 
>> > instructions for doing featurex was defined and new processors 
>> > that do featurex in hardware automatically checked call targets 
>> > and recognize when the instruction sequence matches featurex. 
>> > Then when the routine is called later uses the dedicated 
>> > instruction instead doing the call.
>> 
>> You could have instructions that either do things in hardware or
>> jump to a subroutine at a defined address from a jump table
>> index by opcode.  That would solve the problem, I think, and
>
> That would add LDD-latency plus JUMP-latency to instruction-latency--
> even if the index was extracted by HW. Probably around 5-6 cycles.

Sounds reasonable.  Much faster than trap+emulate, fixup at runtime
would probably need lots of NOPs, and branching to different
versions multiplies code size by the number of versions you have.

It would simply be just another compromise, I guess.

>  
>> > It's be really nice because the code would be identical for 
>> > everything and also run about as fast as possible on everything. 
>> > I have no idea how hard it would be to keep the track of which 
>> > subroutines are actually new instructions though.
>> 
>> this would be OK.
>> 
>> Has anybody actually done this?
>
> How do you think microCode works ??

What I was thinking of was to expose this in the ISA, so people
could use multiplication etc without having to switch on CPU
type, which is a pain.  Call it poor man's millicode.

-- 
This USENET posting was made without artificial intelligence,
artificial impertinence, artificial arrogance, artificial stupidity,
artificial flavorings or artificial colorants.
Re: interrupt handling latency and weird register use (was Re: OT: Epic RISC-V rant)
#502
Author: Terje Mathisen
Date: Sun, 01 Nov 2026 08:02
20 lines
2553 bytes
Thomas Koenig wrote:
> Terje Mathisen <terje.mathisen@tmsw.no> schrieb:
> 
>> The correct way here is to have a function pointer that initially points
>> at a thunk which checks (CPUID) the local cpu and then updates the
>> pointer to go directly to the optimized version.
> 
> gfortran does that for calling different versions of matmul
> compiled with different flags.
> 
I re-invented this technique for my final (?) word count version, it has 
4-5 different kernels plus a benchmarking startup: Measure the speed for 
a 4KB block of input, testing every kernel, then patch the pointer to go 
directly to the fastest.

Terje

-- 
- <Terje.Mathisen at tmsw.no>
"almost all programming can be viewed as an exercise in caching"
Re: Unimplemented opcodes via jump tables (was: interrupt handling latency and weird register use)
#503
Author: Anton Ertl
Date: Sun, 01 Nov 2026 16:11
40 lines
3420 bytes
Thomas Koenig <tkoenig@netcologne.de> writes:
>MitchAlsup <user5857@newsgrouper.org.invalid> schrieb:
>> Thomas Koenig <tkoenig@netcologne.de> posted:
>>> You could have instructions that either do things in hardware or
>>> jump to a subroutine at a defined address from a jump table
>>> index by opcode.  That would solve the problem, I think, and
>>
>> That would add LDD-latency plus JUMP-latency to instruction-latency--
>> even if the index was extracted by HW. Probably around 5-6 cycles.

Just treat it like a call, and predict it very accurately after the
first execution.  The major cost is the extraction of the various
fields and the access to the registers; alternatively, have 32K
variants of each software-defined three-address instruction (assuming
32 registers) where the registers are hard-coded in the variant.

>What I was thinking of was to expose this in the ISA, so people
>could use multiplication etc without having to switch on CPU
>type, which is a pain.

Ideally the CPU exposes the defined instruction, and leaves the
implementation details to some deeper level in the implementation, and
for this kind of implementation maybe in the firmware.  If the
implementations are visible in the user-level and system-level address
space, we cannot avoid making it somewhat visible.

An alternative would be to put these implementations in a separate
address space, but:

1) That implies additional hardware costs which are not necessarily
worth the benefit.

2) When the implemented instruction performs memory accesses or
control flow, extra capabilities are needed to do that in the
usr/system address space.

- anton
-- 
'Anyone trying for "industrial quality" ISA should avoid undefined behavior.'
  Mitch Alsup, <c17fcd89-f024-40e7-a594-88a85ac10d20o@googlegroups.com>
Re: interrupt handling latency and weird register use (was Re: OT: Epic RISC-V rant)
#558
Author: Paul Clayton
Date: Thu, 05 Nov 2026 04:53
90 lines
6273 bytes
On 10/31/26 3:44 AM, Terje Mathisen wrote:
> Josh Vanderhoof wrote:
[snip]
>> Say instead it's for something called featurex and some 
>> processors want it in hardware and some don't.  It'd be much 
>> easier for someone writing the software if a standard sequence 
>> of instructions for doing featurex was defined and new 
>> processors that do featurex in hardware automatically checked 
>> call targets and recognize when the instruction sequence 
>> matches featurex. Then when the routine is called later uses 
>> the dedicated instruction instead doing the call.
> 
> There is simply no way to do that for individual instructions 
> intended to be used in a tight loop. The AES opcodes are a 
> typical example:
> 
> You can write two different functions, one using AES opcodes and 
> one doing it with regular integer instructions, but if you try 
> to replace each AES opcode with a sequence that can be 
> back-patched into the actual instructions, then you will 
> probably end up with far slower results.

Besides the slowness factor (though still faster than trap-and-
emulate), there is the problem that one would need either to use
fixed registers for the inputs and outputs or provide something
like the Mill's conform operation to select the arguments and
define the destination. If the number of operands was limited to
the number in general instructions (say four register operands),
a prefix instruction (similar to My 66000's DOUBLE) could
provide the explicit operands (with implicit operands also
being possible).

If the function call used a table index rather than an offset
from the instruction address, one index could be available for
each new instruction so hardware could quickly determine the
instruction.

This would seem to double the size of the "instruction" — e.g.,
a 32-bit operand-defining prefix and a 32-bit operation-
designating instruction. (One might have implicit operands
defined when the prefix is not used.) It is not clear if
such is a good tradeoff.

Intel at least also seems to be eager to exclude functionality,
so an automated handling faster than trap-and-emulate might not
be attractive to Intel even if the performance was slow.

(Some functionality would also be difficult to emulate in
software. While x86 transactional memory required having a
fallback path (so it was more hint-like), the performance
benefit of the extra hardware support was the main motivation.)

For AES there are probably also advantages for emulation
software not using per-instruction "translation". Software might
also choose to use a different operation that is good enough for
its use case and have easier software implementation. There may
also be I/O devices which provide acceleration for some
operations, a processor core might not be able to decide between
software emulation and handoff to an accelerator.

> The correct way here is to have a function pointer that 
> initially points at a thunk which checks (CPUID) the local cpu 
> and then updates the pointer to go directly to the optimized 
> version.

I feel that the _correct_ way is to use an intermediate software
distribution format that is translated to the specific machine
code. (This would still have code duplication issues when
supporting multiple architectures within a family if the special
code was required to be supported on all cores.) This even
allows new intermediate format software to run on old hardware
by updating the translator. (Old hardware might not cache the
function addresses near the instruction cache for much later
added instructions. Caching the actual functions would also have
storage limitations compared to ROM microcode.)

(The Stanford MIPS design used a code reorganizer to support an
intermediate format that was agnostic of pipeline
characteristics. If commercial MIPS had used an intermediate
software distribution format, delayed branches could have been
eliminated even with a very simple translation mechanism. With a
more complex intermediate format, multiplication and division
could have been changed to use GPRs.)

Sadly, using an intermediate format can cause problems when
there are bugs in the final translator or when the software has
bugs that are only manifested in a later implementation. Formal
methods might eliminate the former, but "it works on my system"
seems a common attitude and even with good intentions bugs can
be released where an intermediate layer makes debugging harder.
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads