calling the directory…
netmeeting ils
pinging…
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.Interesting. I would have expected that most AArch64 code is position
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
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).
As both absolute and PC-rel methods are possible on all cpu's,
On 2026-Nov-22 12:23, EricP wrote:
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.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
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
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).
The above examination shows where the weaknesses are in each ISA.
This is towards considering what modifications would improve each in different scenarios.
Eg. as I noted earlier, defining rBase == R0 => RIP and adding
LD & ST instructions with scaled-index address mode then
it gives access to the full 64b address space, absolute or RIP-rel addressing, in two instructions.
Does it need a similar optimization for branch, call, jump, or
case/switches to ranges larger than an ISA supports?
How big are the native relative branch/call offsets?
If it is just a 12 or 13 bit offset, what is the sequence for a
larger range? Does that need to be optimized too?
I use the term "branch" and its variations like "branch and link"
or "branch subroutine" to mean the destination is relative to the
branching instruction, and "jump" and its variations to mean the
destination is independent of the jumping instruction.
In my terminology RV's Jump And Link JAL instruction would be
BAL because it is relative, whereas its Jump and Link Register
would remain JALR as it calculates its destination independent
of the jumping instruction. RVs conditional branches remain Bcc
as they are relative to the branching instruction.
RV has a two instruction sequence to unconditional branch relative
to any address within 32b, +-2GB, AUIPC and JALR plus a temp register.
To branch relative to any address in 64b space requires AUIPC,
a LD to load a 64b constant offset from the constant table,
ADD to the PC base to get an absolute address, and JALR.
If the destination is relocatable, as it would be with a destination
in a shared library, then the 64b offset constant would need a
relocation table entry so it is patched by the loader
(aka an imported DLL library routine trampoline).
However that relocation patch could make this code unsharable
(depending on how the OS handles shared code and data in EXE and DLL's)
so a longer code sequence might be necessary to extract a
dynamic address from the GOT table,
which is itself located
at an absolute address.
The above becomes simpler if a new JALR instruction incorporates
the same rBase == R0 => RIP definition plus an offset register,
which may be R0 the zero register.
A general 64 branch relative is
LD.L r1 = [RIP + table_offset] // load 64b offset
JALR r0, [RIP + r1] // add offset to rip and jump
and a general absolute jump is
LD.L r1 = [RIP + table_offset] // load absolute address
JALR r0, [r1 + r0] // jump there
EricP <ThatWouldBeTelling@thevillage.com> schrieb:
As both absolute and PC-rel methods are possible on all cpu's,
It is possible in principle for Power previous to version 3.1, but
it was painful. The system has a TOC pointer in r2, which points
to local data and the GOT, restricted to 64k. If you really wanted
to do pc-relative, you had to get the PC via a branch and link
instruction into the link register, then transfer it from there to
a general register. Power version 3.0 added a add PC immediate
+ shifted instruction. V3.1 finally allows for pc-relative with
34-bit offset, in a 64-bit instruction.
On 2026-Nov-23 05:47, Thomas Koenig wrote:
EricP <ThatWouldBeTelling@thevillage.com> schrieb:
As both absolute and PC-rel methods are possible on all cpu's,
It is possible in principle for Power previous to version 3.1, but
it was painful. The system has a TOC pointer in r2, which points
to local data and the GOT, restricted to 64k. If you really wanted
to do pc-relative, you had to get the PC via a branch and link
instruction into the link register, then transfer it from there to
a general register. Power version 3.0 added a add PC immediate
+ shifted instruction. V3.1 finally allows for pc-relative with
34-bit offset, in a 64-bit instruction.
The 32b x86 also does not have native PC-rel addressing,
just absolute, register relative, with optional scaled-index.
To get the PC into a register one calls a two instruction routine,
which pushes the incremented PC on the stack, loads the bottom
of stack dword into a register and returns.
This routine could be positioned after a basic block near by.
To make that perform well the core needs store-to-load forwarding
so it can pull the PC from the store queue and not wait for the
value to hit memory, and a branch predictor so the call does not
cause a stall. A "MOVPC Rd" instruction would have been simpler.
An OS could support shared DLLs without PC-rel position independent code
but the OS image loader's job is more complicated as it must decide
whether to reuse an existing image already located at an absolute address,
or make a new relocated version of that image file. It gets complicated because each loaded DLL can depend on many other DLLs loaded at their currently assigned absolute address. Doing that optimally sounds like
a bin packing problem which are NP-hard, and since sharing isn't
strictly required then probably a "best effort" at reuse would do.
Hmm... didn't think of that. Indeed this could lead to actual
addresses embedded in the code. Then again, I'd expect most such JIT
setups to want to keep most of those addresses in data rather than in
the code so the GC can more easily trace through them.
So, we now have 3 suggested circumstances, but it's not clear if these
occur enough to explain Andrew's experience.
Andrew, do you know what causes all those large constant addresses
you're seeing?
Stefan Monnier <monnier@iro.umontreal.ca> wrote:
Hmm... didn't think of that. Indeed this could lead to actualGCs have not the slightest difficulty tracing through embedded
addresses embedded in the code. Then again, I'd expect most such JIT
setups to want to keep most of those addresses in data rather than in
the code so the GC can more easily trace through them.
addresses. We use whatever form of address constants is fastest.
Andrew, do you know what causes all those large constant addresses
you're seeing?
Very common constants are classes used in expressions, such as
new File("filename")
or casts between types
File x = (File)anObject;
Casts are more common than is immediately apparent, because the
compiler inserts them when it can't prove the type of an object.
The other important case is metadata. We gather a lot of information
about running code: branch frequency, type frequency, and so on. Every metadata address is a constant in the generated code. After a while,
code is recompiled and we use all the gathered informtion to drive
inlining and other optimizations.
On 2026-Nov-23 05:47, Thomas Koenig wrote:We asm programmers didn't use that function call, we just did
EricP <ThatWouldBeTelling@thevillage.com> schrieb:
As both absolute and PC-rel methods are possible on all cpu's,
It is possible in principle for Power previous to version 3.1, but
it was painful. The system has a TOC pointer in r2, which points>> to local data and the GOT, restricted to 64k. If you really wanted
to do pc-relative, you had to get the PC via a branch and link
instruction into the link register, then transfer it from there to
a general register. Power version 3.0 added a add PC immediate
+ shifted instruction. V3.1 finally allows for pc-relative with
34-bit offset, in a 64-bit instruction.
The 32b x86 also does not have native PC-rel addressing,
just absolute, register relative, with optional scaled-index.
To get the PC into a register one calls a two instruction routine,
which pushes the incremented PC on the stack, loads the bottom
of stack dword into a register and returns.
This routine could be positioned after a basic block near by.
To make that perform well the core needs store-to-load forwarding
so it can pull the PC from the store queue and not wait for the
value to hit memory, and a branch predictor so the call does not
cause a stall. A "MOVPC Rd" instruction would have been simpler.
aph@littlepinkcloud.invalid [2026-11-24 13:46:24] wrote:
Stefan Monnier <monnier@iro.umontreal.ca> wrote:
Hmm... didn't think of that. Indeed this could lead to actualGCs have not the slightest difficulty tracing through embedded
addresses embedded in the code. Then again, I'd expect most such JIT
setups to want to keep most of those addresses in data rather than in
the code so the GC can more easily trace through them.
addresses. We use whatever form of address constants is fastest.
Maybe it's not "hard" compared to the rest of what it takes to write
a high performance GC, but it's still a fair bit more work to have to
tell the GC where to find the few bitfields that need to be stitched
together to make up the actual pointer (it definitely makes tracing
through such references slower), and if you have a moving GC it also
makes moves harder, because of the need to both retrofit the new address
into the corresponding bitfields (which also means you can't use an instruction sequence special-tailored to the original address) and take
care of updating/flushing the I-cache.
Andrew, do you know what causes all those large constant addresses
you're seeing?
Very common constants are classes used in expressions, such as
new File("filename")
or casts between types
File x = (File)anObject;
Casts are more common than is immediately apparent, because the
compiler inserts them when it can't prove the type of an object.
Interesting, thanks. So it is indeed the JIT case suggested by Anton!
The other important case is metadata. We gather a lot of information
about running code: branch frequency, type frequency, and so on. Every
metadata address is a constant in the generated code. After a while,
code is recompiled and we use all the gathered informtion to drive
inlining and other optimizations.
Hmm... even more interesting: since the metadata-gathering is part of
the code that's generated cheaply,
I'd have expected that code to use a simple approach that always
loads the large constants from some data section rather than "use
whatever form of address constants is fastest" (which I would have
expected is used only for the high-performance version of the code).
EricP wrote:
On 2026-Nov-23 05:47, Thomas Koenig wrote:
EricP <ThatWouldBeTelling@thevillage.com> schrieb:
As both absolute and PC-rel methods are possible on all cpu's,
It is possible in principle for Power previous to version 3.1, but
it was painful. The system has a TOC pointer in r2, which points
to local data and the GOT, restricted to 64k. If you really wanted
to do pc-relative, you had to get the PC via a branch and link
instruction into the link register, then transfer it from there to
a general register. Power version 3.0 added a add PC immediate
+ shifted instruction. V3.1 finally allows for pc-relative with
34-bit offset, in a 64-bit instruction.
The 32b x86 also does not have native PC-rel addressing,
just absolute, register relative, with optional scaled-index.
To get the PC into a register one calls a two instruction routine,
which pushes the incremented PC on the stack, loads the bottom
of stack dword into a register and returns.
This routine could be positioned after a basic block near by.
To make that perform well the core needs store-to-load forwarding
so it can pull the PC from the store queue and not wait for the
value to hit memory, and a branch predictor so the call does not
cause a stall. A "MOVPC Rd" instruction would have been simpler.
We asm programmers didn't use that function call, we just did
call next
next:
pop bx
Two instructions, 4 bytes
but when return predictors turned up having a CALL without the expected
RET caused mispredicts.
Terje
data: api.nasa.gov (APOD, NeoWs)
| Sysop: | cequra |
|---|---|
| Location: | Grimsby United Kingdom |
| Users: | 4 |
| Nodes: | 4 (0 / 4) |
| Uptime: | 498852:57:44 |
| Calls: | 197 |
| Files: | 8,821 |
| D/L today: |
29 files (9,432K bytes) |
| Messages: | 39,038 |