🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.arch
Article #776

Re: Large constants in RISC

#776
From: Anton Ertl
Date: Mon, 16 Nov 2026 09:41
169 lines
7791 bytes
Thomas Koenig <tkoenig@netcologne.de> writes:
>Anton Ertl <anton@mips.complang.tuwien.ac.at> schrieb:
>> Thomas Koenig <tkoenig@netcologne.de> writes:
>>>If you want data, you can look at a RISC architecture which has
>>>adopted 34-bit constants.
>>
>> Which one?  And does it have faster implementations than ARM A64 which
>> does not have such a feature last I looked.
>
>Power ISA v3.1 (aka Power 10).

The data I have about that is that code on it runs slower than on the
fastest ARM A64 implementations, at least for single-threaded loads.
The per-core performance with all 8 threads exceeds that of AMD and
Intel CPUs, and probably also that of the fastest ARM A64
implementations, but I would need access to those ARM A64 CPUs to
confirm this.

>Table of contents, for accessing global data.  Their ABI has
>a special register for that, r2, which is no longer needed
>for pc-relative code (also introduced with v3.1).  Plus, size
>restrictions were lifted.

I looked at functions with references to global variables, large
constants, and separately linked functions in
<2025Jul1.180809@mips.complang.tuwien.ac.at>.

anton@cfarm121:~/bigconstants$ cat main.c 
#include <math.h>
extern int a, b;
extern double x, y;
extern void foo(void);

int main()
{
  foo();
  x = lgamma(y);
  a += signgam;
  a += b;
  return 0;
}
anton@cfarm121:~/bigconstants$ cat foo.c
int a, b;
double x, y;
void foo(void)
{
}
anton@cfarm121:~/bigconstants$ gcc -Wall -O -FPIC main.c foo.c -lm
anton@cfarm121:~/bigconstants$ objdump -d a.out
...
00000000000009f4 <.main>:
 9f4:   7c 08 02 a6     mflr    r0
 9f8:   f8 01 00 10     std     r0,16(r1)
 9fc:   f8 21 ff 91     stdu    r1,-112(r1)
 a00:   48 00 00 79     bl      a78 <.foo>
 a04:   60 00 00 00     nop
 a08:   60 00 00 00     nop
 a0c:   39 22 81 90     addi    r9,r2,-32368
 a10:   c8 29 00 00     lfd     f1,0(r9)
 a14:   4b ff fe 0d     bl      820 <0000001a.plt_call.lgamma@@GLIBC_2.23>
 a18:   e8 41 00 28     ld      r2,40(r1)
 a1c:   60 00 00 00     nop
 a20:   39 22 81 98     addi    r9,r2,-32360
 a24:   d8 29 00 00     stfd    f1,0(r9)
 a28:   60 00 00 00     nop
 a2c:   39 42 81 a4     addi    r10,r2,-32348
 a30:   81 2a 00 00     lwz     r9,0(r10)
 a34:   60 00 00 00     nop
 a38:   e9 02 80 28     ld      r8,-32728(r2)
 a3c:   81 08 00 00     lwz     r8,0(r8)
 a40:   7d 29 42 14     add     r9,r9,r8
 a44:   60 00 00 00     nop
 a48:   39 02 81 a0     addi    r8,r2,-32352
 a4c:   81 08 00 00     lwz     r8,0(r8)
 a50:   7d 29 42 14     add     r9,r9,r8
 a54:   91 2a 00 00     stw     r9,0(r10)
 a58:   38 60 00 00     li      r3,0
 a5c:   38 21 00 70     addi    r1,r1,112
 a60:   e8 01 00 10     ld      r0,16(r1)
 a64:   7c 08 03 a6     mtlr    r0
 a68:   4e 80 00 20     blr
 a6c:   00 00 00 00     .long 0x0
 a70:   00 00 00 01     .long 0x1
 a74:   80 00 00 00     lwz     r0,0(0)

0000000000000a78 <.foo>:
 a78:   4e 80 00 20     blr

anton@cfarm121:~/bigconstants$ gcc -Wall -O -FPIC -mcpu=power10 main.c foo.c -lm
anton@cfarm121:~/bigconstants$ objdump -d a.out
0000000000000a40 <.main>:
 a40:   7c 08 02 a6     mflr    r0
 a44:   f8 01 00 10     std     r0,16(r1)
 a48:   f8 21 ff 91     stdu    r1,-112(r1)
 a4c:   48 00 00 79     bl      ac4 <.foo>
 a50:   60 00 00 00     nop
 a54:   06 10 00 01     pla     r9,128572       # 20090 <y>
 a58:   39 20 f6 3c 
 a5c:   c8 29 00 00     lfd     f1,0(r9)
 a60:   4b ff fd e1     bl      840 <0000001a.plt_call.lgamma@@GLIBC_2.23>
 a64:   e8 41 00 28     ld      r2,40(r1)
 a68:   06 10 00 01     pla     r9,128560       # 20098 <x>
 a6c:   39 20 f6 30 
 a70:   d8 29 00 00     stfd    f1,0(r9)
 a74:   06 10 00 01     pla     r9,128560       # 200a4 <a>
 a78:   39 20 f6 30 
 a7c:   80 c9 00 00     lwz     r6,0(r9)
 a80:   04 10 00 01     pld     r10,128168      # 1ff28 [signgam@got]
 a84:   e5 40 f4 a8 
 a88:   80 ea 00 00     lwz     r7,0(r10)
 a8c:   06 10 00 01     pla     r10,128532      # 200a0 <b>
 a90:   39 40 f6 14 
 a94:   81 0a 00 00     lwz     r8,0(r10)
 a98:   7d 47 32 14     add     r10,r7,r6
 a9c:   7d 4a 42 14     add     r10,r10,r8
 aa0:   91 49 00 00     stw     r10,0(r9)
 aa4:   38 60 00 00     li      r3,0
 aa8:   38 21 00 70     addi    r1,r1,112
 aac:   e8 01 00 10     ld      r0,16(r1)
 ab0:   7c 08 03 a6     mtlr    r0
 ab4:   4e 80 00 20     blr
 ab8:   00 00 00 00     .long 0x0
 abc:   00 00 00 01     .long 0x1
 ac0:   80 00 00 00     lwz     r0,0(0)

0000000000000ac4 <.foo>:
 ac4:   4e 80 00 20     blr

In this case the difference does not impress me.  But of course this
is not a case that would benefit from the availability of r2 for other
purposes.

For comparison, here's what I get on ARM A64:

0000000000000864 <main>:
 864:   a9bf7bfd        stp     x29, x30, [sp, #-16]!
 868:   910003fd        mov     x29, sp
 86c:   94000017        bl      8c8 <foo>
 870:   90000080        adrp    x0, 10000 <__FRAME_END__+0xf550>
 874:   f947e400        ldr     x0, [x0, #4040]
 878:   fd400000        ldr     d0, [x0]
 87c:   97ffffad        bl      730 <lgamma@plt>
 880:   90000080        adrp    x0, 10000 <__FRAME_END__+0xf550>
 884:   f947d400        ldr     x0, [x0, #4008]
 888:   fd000000        str     d0, [x0]
 88c:   90000081        adrp    x1, 10000 <__FRAME_END__+0xf550>
 890:   f947e021        ldr     x1, [x1, #4032]
 894:   b9400020        ldr     w0, [x1]
 898:   90000082        adrp    x2, 10000 <__FRAME_END__+0xf550>
 89c:   f947ec42        ldr     x2, [x2, #4056]
 8a0:   b9400042        ldr     w2, [x2]
 8a4:   0b020000        add     w0, w0, w2
 8a8:   90000082        adrp    x2, 10000 <__FRAME_END__+0xf550>
 8ac:   f947d042        ldr     x2, [x2, #4000]
 8b0:   b9400042        ldr     w2, [x2]
 8b4:   0b020000        add     w0, w0, w2
 8b8:   b9000020        str     w0, [x1]
 8bc:   52800000        mov     w0, #0x0                        // #0
 8c0:   a8c17bfd        ldp     x29, x30, [sp], #16
 8c4:   d65f03c0        ret

00000000000008c8 <foo>:
 8c8:   d65f03c0        ret
 8cc:   d503201f        nop

- anton
-- 
'Anyone trying for "industrial quality" ISA should avoid undefined behavior.'
  Mitch Alsup, <c17fcd89-f024-40e7-a594-88a85ac10d20o@googlegroups.com>
Technical Details
Message-ID: <2026Nov16.104152@mips.complang.tuwien.ac.at>
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!news.mb-net.net!open-news-network.org!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail
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> <2026Nov15.173606@mips.complang.tuwien.ac.at> <11ddbps$34jn8$1@dont-email.me> <2026Nov16.082231@mips.complang.tuwien.ac.at> <11deh16$3dssn$1@dont-email.me>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!news.mb-net.net!open-news-network.org!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail
From: anton@mips.complang.tuwien.ac.at (Anton Ertl)
Newsgroups: comp.arch
Subject: Re: Large constants in RISC
Date: Mon, 16 Nov 2026 09:41:52 GMT
Organization: Institut fuer Computersprachen, Technische Universitaet Wien
Lines: 169
Message-ID: <2026Nov16.104152@mips.complang.tuwien.ac.at>
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> <2026Nov15.173606@mips.complang.tuwien.ac.at> <11ddbps$34jn8$1@dont-email.me> <2026Nov16.082231@mips.complang.tuwien.ac.at> <11deh16$3dssn$1@dont-email.me>
Injection-Date: Mon, 16 Nov 2026 10:12:22 +0000 (UTC)
Injection-Info: dont-email.me;
	logging-data="3647480"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX19z3W1Kt1ev0QecAsuoROXT"; posting-host="162378f659f64fe0e343a03d3521a08a"
Cancel-Lock: sha1:dlBU6swS7EnU/NFTa3FHmEOTuwA= sha256:ZiqvSHPh/VxZ5B8fBumR+NSTyChMUz6gryGI9oiF578=
	sha1:nD+9umd/bEE3OVwuxGRN2zvDplI= sha256:htgTdYNFt+obvYTVNosoG5ae8HejWd8qlJ2Q8lNRmRc=
X-newsreader: xrn 10.11