Article View: comp.arch
Article #766Re: Large constants in RISC
From: EricP
Date: Sun, 15 Nov 2026 19:12
Date: Sun, 15 Nov 2026 19:12
76 lines
4107 bytes
4107 bytes
On 2026-Nov-15 11:08, Anton Ertl wrote: > BGB <cr88192@gmail.com> writes: >> However, if counting clock-cycles, a prefix is a win: >> Prefix + Op: Zero cycle overhead for the missed constant; >> Load + Op: May add 3 or 4 clock cycles. >> >> So, would need to speculatively load the immediate values several >> instructions in advance, and hope that there are no extra cache misses. > > The nice thing about the load is that its address is usually available > right away. So the load operation is typically performed as soon as > possible, and for a sequence > > load r1, d(rct) > add r3=r1+r2 > > where rct is the register pointing to the constant table, the result > may be ready in r1 before r2 is ready. > > The bottom line is that this load typically does not cost latency. If I was using the constant table approach I would: - define for LD and ST instructions that if the base register was the zero register (R0 or R31) then it means use the 64-bit RIP. - add scaled index LD and ST instructions with the following format: opcode 6b Rs1_base 5b Rs2_index 5b Rd/Rs3 5b data_type 3b scale 3b offset 5b Data types are signed integer: B, H, W, L float: S, D This can access anywhere in 64b address space in 2 instructions: - use a small RIPrel offset to load the 64b RIPrel offset from the table = use the scaled index LD/ST with scale = 0, index = offset, and base RIP to address all of memory. For RIP-relative 64b addressing: LD.L r1 = [RIP + table_offset] LD.dt r2 = [RIP + r1<<0] For absolute 64b addressing, set the base register to the constant and the index register to the zero register (which equals 0 NOT the RIP): LD.L r1 = [RIP + table_offset] LD.dt r2 = [r1 + r0<<0] > Concerning cache misses: If the code is executed often, the constant > will be in the (L1) D-Cache. If there is a cache miss, the code has > not been executed recently. Bottom line: Cache misses are rare, > because caches work. > >> This sort of thing can be a bigger saving though for things like >> accessing global variables (where the existing options "generally >> suck"). Typically, an unscaled Disp12 falls short of being able to >> directly address all of the commonly-used global variables in a typical >> program. > > How many globals does your program have. > > In order to be able to address the globals of a program with a single > global pointer, the linker needs to do quite a bit of work. Maybe the > RISC-V linker does. For the Alpha every compilation unit has its own > constant and global table as far as I remember (and I think the same > register is used for both on the Alpha). > > - anton Alpha put the constant table just above the entry to the routine running backwards and aligned the routine on a cache line. On entry it would do a BR rd,+0 to copy the PC into rd then they use that as a base to access the constant table. However neither Alpha or RV have Its 16b offset field should be enough
Technical Details
Message-ID:
<JunKS.106396$Cm3.49782@fx47.iad>Path:
mbox-mo1.pugleaf.net!news-lax.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer04.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx47.iad.POSTED!not-for-mailReferences:
<11d76uq$11cdc$1@paganini.bofh.team> <11d9d0d$1rsce$1@dont-email.me> <11d9tq8$1b9c1$2@paganini.bofh.team> <11dabct$26fdl$1@dont-email.me> <11dahac$2t74$1@gal.iecc.com> <11dakku$29j9n$1@dont-email.me> <2026Nov15.170804@mips.complang.tuwien.ac.at>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer04.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx47.iad.POSTED!not-for-mail MIME-Version: 1.0 User-Agent: Mozilla Thunderbird From: EricP <ThatWouldBeTelling@thevillage.com> Subject: Re: Large constants in RISC Newsgroups: comp.arch References: <11d76uq$11cdc$1@paganini.bofh.team> <11d9d0d$1rsce$1@dont-email.me> <11d9tq8$1b9c1$2@paganini.bofh.team> <11dabct$26fdl$1@dont-email.me> <11dahac$2t74$1@gal.iecc.com> <11dakku$29j9n$1@dont-email.me> <2026Nov15.170804@mips.complang.tuwien.ac.at> Content-Language: en-CA In-Reply-To: <2026Nov15.170804@mips.complang.tuwien.ac.at> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Lines: 76 Message-ID: <JunKS.106396$Cm3.49782@fx47.iad> X-Complaints-To: abuse@UsenetServer.com NNTP-Posting-Date: Sun, 15 Nov 2026 19:12:41 UTC Date: Sun, 15 Nov 2026 14:12:38 -0500 X-Received-Bytes: 3886