🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.arch
Article #529

Re: interrupt handling latency and weird register use (was Re: OT: Epic RISC-V rant)

#529
From: 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"
Technical Details
Message-ID: <11c469p$u1at$1@dont-email.me>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail
References: <87qzk0nejz.fsf@nightsong.com> <116d89d$27baf$1@paganini.bofh.team> <87ecfcagiw.fsf_-_@debian> <2026Sep1.225146@mips.complang.tuwien.ac.at> <11bpfm8$190ap$1@dont-email.me> <2026Oct27.171414@mips.complang.tuwien.ac.at> <1793120789-5857@newsgrouper.org> <11bsq36$36q1t$3@paganini.bofh.team> <1793202439-5857@newsgrouper.org> <ygnwlr084yt.fsf@y.z> <1793320218-5857@newsgrouper.org> <ygnjymy5uo2.fsf@y.z>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail
From: Terje Mathisen <terje.mathisen@tmsw.no>
Newsgroups: comp.arch
Subject: Re: interrupt handling latency and weird register use (was Re: OT:
 Epic RISC-V rant)
Date: Sat, 31 Oct 2026 08:44:59 +0100
Organization: A noiseless patient Spider
Lines: 108
Message-ID: <11c469p$u1at$1@dont-email.me>
References: <87qzk0nejz.fsf@nightsong.com>
 <116d89d$27baf$1@paganini.bofh.team> <87ecfcagiw.fsf_-_@debian>
 <2026Sep1.225146@mips.complang.tuwien.ac.at> <11bpfm8$190ap$1@dont-email.me>
 <2026Oct27.171414@mips.complang.tuwien.ac.at>
 <1793120789-5857@newsgrouper.org> <11bsq36$36q1t$3@paganini.bofh.team>
 <1793202439-5857@newsgrouper.org> <ygnwlr084yt.fsf@y.z>
 <1793320218-5857@newsgrouper.org> <ygnjymy5uo2.fsf@y.z>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: quoted-printable
Injection-Date: Sat, 31 Oct 2026 07:44:58 +0000 (UTC)
Injection-Info: dont-email.me;
	logging-data="984413"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX19mOtzW1W53tVrmotn/JIcZaFPidDRoupzrhIXdkcB1Qg=="; posting-host="e5ac42ce6e6f6161a2e381c55edeef36"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:140.0) Gecko/20100101
 Firefox/140.0 SeaMonkey/2.53.24
Cancel-Lock: sha1:qU9rZ+FzTf7D6X9hGpX+LJnnW9A= sha256:D4ZTwMpKrO2kl5rRiepRH8bkXG/fyVJv/DpjCUIoGxs=
	sha1:nxHwtjcH/mckHF05lodtbnw3yoQ= sha256:brUzKekTiOUdmLv5Ml3Zl2emOf21dOCQ3kUIrkjN6X0=
In-Reply-To: <ygnjymy5uo2.fsf@y.z>