🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.arch
Article #781

Re: Large constants in RISC

#781
From: MitchAlsup
Date: Mon, 16 Nov 2026 19:08
166 lines
7152 bytes
anton@mips.complang.tuwien.ac.at (Anton Ertl) posted:

> Thomas Koenig <tkoenig@netcologne.de> writes:
> >Anton Ertl <anton@mips.complang.tuwien.ac.at> schrieb:
> >> Thomas Koenig <tkoenig@netcologne.de> writes:
---------------------
> <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;
> }

main:
       ENTER   R0,R0,#0
       CALX    [IP,,#GOT[foo]]
       LDD     R1,[IP,,#y]
       CALL    lgamma
       LDSW    R2,[ip,,#signam]
       LDSW    R3,[ip,,#a]
       ADD     R2,R2,R3
       LDSW    R3,[IP,,#b]
       ADD     R2,R2,R3
       STW     R2,[ip,,#a]
       MOV     R1,#0
       EXIT    R0,R0,#0

> anton@cfarm121:~/bigconstants$ cat foo.c
> int a, b;
> double x, y;
> void foo(void)
> {
> }

foo:
       RET

> 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
Technical Details
Message-ID: <1794856095-5857@newsgrouper.org>
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!newsgrouper.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> <2026Nov16.104152@mips.complang.tuwien.ac.at>

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!newsgrouper.org!.POSTED!not-for-mail
From: MitchAlsup <user5857@newsgrouper.org.invalid>
Newsgroups: comp.arch
Subject: Re: Large constants in RISC
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> <2026Nov16.104152@mips.complang.tuwien.ac.at>
Date: Mon, 16 Nov 2026 19:08:15 GMT
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Message-ID: <1794856095-5857@newsgrouper.org>
Injection-Info: newsgrouper.org; mail-complaints-to="newsgrouper@yahoo.com"; posting-account=user5857
Injection-Date: Mon, 16 Nov 2026 19:08:15 GMT
User-Agent: Newsgrouper/0.9.0