Article View: comp.arch
Article #890Re: Large constants in RISC
From: EricP
Date: Sun, 22 Nov 2026 17:23
Date: Sun, 22 Nov 2026 17:23
50 lines
3707 bytes
3707 bytes
On 2026-Nov-20 22:23, Stefan Monnier wrote: > On 2026-Nov-19 08:59, Stefan Monnier wrote: >> aph@littlepinkcloud.invalid [2026-11-19 09:42:51] wrote: >>> In a way, it does. Most large constants I see are addresses. >>> AArch64 (almost) always has a 48-bit user space, so except for >>> floating-point doubles and the very occasional large integer, constant >>> loads look like >>> mov x0, 42857; movk x0, 0x60b8, lsl 16; movk x0, 0xaaaa, lsl 32 >> Interesting. I would have expected that most AArch64 code is position >> independent (e.g. for address space randomization purposes), so I wonder >> in which circumstances we end up with such instruction sequences to >> build hardcoded addresses. > > EricP [2026-11-20 15:47:57] wrote: >> An application or OS can require that certain data structures >> are mapped at predefined virtual addresses. > > I find it hard to believe that these thingies would account for a large > portion of large constants. In many ISAs code can be optimized to smaller a smaller memory model than the full 64b address space because most applications and libraries reside in the first 2GB and access small objects. As both absolute and PC-rel methods are possible on all cpu's, the comparison is a matter of how efficient each is in an ISA, in a compiled memory model. Compiled memory model matters because if one knows that only the lower and upper 2GB will be accessed then compiler can use sign extended 32b values as both relative offsets or absolute addresses. I'm interested is what happens when one tries to use an ISA in its full 64b address space as that is where many inefficiencies show up. Eg. RV requires 2 instructions to calculate a constant in a 32b memory model but 5 instructions in the full 64b memory model. Eg. RV's LD instruction contains a 12b immediate offset but if the offset is larger you must load the immediate, 2 or 5 instructions, add it to a base, then LD using it, 7 instructions. One needs to consider scenarios for: - each ISA, x64, A64, RV, - various memory models: - tiny memory model smaller than 32b, - small memory model using 32b subset inside a 64b address space, - full 64b address space, - absolute and PC-rel addressing, - various address sequences - first access vs subsequent access. - various usage scenarios - unshared vs shared exe or dll (and this brings different OS behaviour into consideration).
Technical Details
Message-ID:
<5yFMS.36883$gOr4.31829@fx08.iad>Path:
mbox-mo1.pugleaf.net!srv.newsdeef.eu!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx08.iad.POSTED!not-for-mailReferences:
<11d76uq$11cdc$1@paganini.bofh.team> <11d7ct8$17akn$1@dont-email.me> <11d7ih2$11orr$1@paganini.bofh.team> <11d9d0d$1rsce$1@dont-email.me> <11d9tq8$1b9c1$2@paganini.bofh.team> <2026Nov14.201017@mips.complang.tuwien.ac.at> <6af911ea.18530156@news.eternal-september.org> <SYScnWsR3rgGWWP3nZ2dnZfqn_WdnZ2d@supernews.com> <jwv1p8hhqmy.fsf-monnier+comp.arch@gnu.org> <4m2MS.132607$Lt64.106487@fx41.iad> <jwvo6bidgit.fsf-monnier+comp.arch@gnu.org>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx08.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> <11d7ct8$17akn$1@dont-email.me> <11d7ih2$11orr$1@paganini.bofh.team> <11d9d0d$1rsce$1@dont-email.me> <11d9tq8$1b9c1$2@paganini.bofh.team> <2026Nov14.201017@mips.complang.tuwien.ac.at> <6af911ea.18530156@news.eternal-september.org> <SYScnWsR3rgGWWP3nZ2dnZfqn_WdnZ2d@supernews.com> <jwv1p8hhqmy.fsf-monnier+comp.arch@gnu.org> <4m2MS.132607$Lt64.106487@fx41.iad> <jwvo6bidgit.fsf-monnier+comp.arch@gnu.org> Content-Language: en-CA In-Reply-To: <jwvo6bidgit.fsf-monnier+comp.arch@gnu.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Lines: 50 Message-ID: <5yFMS.36883$gOr4.31829@fx08.iad> X-Complaints-To: abuse@UsenetServer.com NNTP-Posting-Date: Sun, 22 Nov 2026 17:23:13 UTC Date: Sun, 22 Nov 2026 12:23:09 -0500 X-Received-Bytes: 3497