Article View: comp.arch
Article #782Re: Large constants in RISC
From: BGB
Date: Mon, 16 Nov 2026 19:50
Date: Mon, 16 Nov 2026 19:50
86 lines
5087 bytes
5087 bytes
On 11/15/2026 1:08 PM, MitchAlsup wrote: > anton@mips.complang.tuwien.ac.at (Anton Ertl) posted: > >> Robert Finch <robfi680@gmail.com> writes: >>> One ends up with constants in the data cache. May be slower than having >>> constants inline from the I$. One thought it to have instructions that >>> can load constants using the I$. >> >> There is no data path from the I-cache to the load unit in existing >> CPUs. I also expect that if you add such a data path, it will be >> slower, because the I-cache is not close to the LSU, but close to the >> decoder and the branch predictor. So that idea is not going to fly. > > You do NOT need said path, what you need is for the constant to show up > from the instruction stream and be parse-able from that instruction > stream easily. Given really small (1-wide) low ends, one might use a > 4-word aligned fetch--higher end machines will need correspondingly > wider Fetch and more prediction accuracy. > Yeah. I suspect on those ISA's where an "@PC+" addressing mode or similar was used to encode constant loads, this was more likely by invoking magic in the fetch and decode, than *actually* loading from and adjusting PC... Also common is for ISA's to have a special "Disp(PC)" or "(PC,Disp)" addressing mode or similar. RISC-V has neither. It is almost half-tempting though to redefine using X1 as a base register as a way to encode PC-rel loads. But, this would be non-standard and potentially controversial. Would allow the "have a small blob of constants after the current function with PC-rel loads" strategy though. While X0 might otherwise seem like an obvious choice, there are non-zero amounts of code (mostly in the RV32 microcontroller space) which use X0 to address the first and last 2K of address space (Say, 2K of ROM, and the other 2K being a mix of a small RAM area and some common MMIO ports). Granted, a lot of these sorts of devices also tend to ignore the high bits of the address, shrinking the size of the address space down to 16 or 20 bits or so (like, don't need 32 bits of address space when the RAM is measured in kB...). This would leave X1 addressing as a more obvious choice because it is "otherwise kinda useless" (or, at least, more useless than X0). Though, in my case, X0/R0 does still encode PC-rel for XG3 ops (carried over from XG1 and XG2). In this case, X1 also encoded GP, but this is in-effect redundant with using X3 (which is currently mostly what BGBCC uses). X1 encodes Zero for Abs64. Would be wonky to have X0 and X1 effectively swapped between the RV64 and XG3 encodings, but, alas... But, then again, not particularly inclined to add PC-rel Disp12 to RV as its only real use-case is something BGBCC doesn't really do. Well, contrast with PC-Rel Disp33, which can access ".rodata" and similar, or use LEA to load pointers to string literals, making these cases a little more useful. Can't currently encode these in RV space, but one can instead use AUIPC+ADDI or AUIPC+LW or similar in these cases (higher latency, but the same number of instruction words). >> The better approach is to have the data in the instructions, and >> extract it during instruction decoding, like all the immediate >> operands in all instruction sets around do. Or to have the data in >> data memory and access it with a load that works with the D-cache, >> like Alpha and others do. >> >>> ARM has shifted constant instruction too. >> >> Not in ARM A64. But ARM A64 has an interesting encoding for certain >> bit patterns. >> >> - anton
Technical Details
Message-ID:
<11dfmqe$3rp2n$1@dont-email.me>Path:
mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!news.hispagatos.org!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.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> <11dauv4$2csdn$1@dont-email.me> <2026Nov15.172809@mips.complang.tuwien.ac.at> <1794769700-5857@newsgrouper.org>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!news.hispagatos.org!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail From: BGB <cr88192@gmail.com> Newsgroups: comp.arch Subject: Re: Large constants in RISC Date: Mon, 16 Nov 2026 13:50:37 -0600 Organization: A noiseless patient Spider Lines: 86 Message-ID: <11dfmqe$3rp2n$1@dont-email.me> 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> <11dauv4$2csdn$1@dont-email.me> <2026Nov15.172809@mips.complang.tuwien.ac.at> <1794769700-5857@newsgrouper.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Mon, 16 Nov 2026 19:50:38 +0000 (UTC) Injection-Info: dont-email.me; logging-data="4056151"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18C1vVnBQWM8vcUrrt+smXr3ameRa9PULo="; posting-host="7cb72988303a6b52400f6abc3a774d75" User-Agent: Mozilla Thunderbird Cancel-Lock: sha1:MpeJlZn4EBdLhsCuOmtcJcue9gs= sha256:I1ndQ6rI89ygBIPHrNJSLjS7wZC492IhV5HxX4L2JfI= sha1:0CysYS693FWPysKyev5UoJlFIyc= sha256:kehT5wY2+r9pzXMVMJVcJUrS1Mzqfx9cU6YsTCgcb18= In-Reply-To: <1794769700-5857@newsgrouper.org> Content-Language: en-US