RE: Questions on the stack for IA64

From: Rahul Chaturvedi <justanotheraliasforrahul_at_yahoo.com>
Date: 2004-04-14 15:05:56
> >c.) How exactly is the data stored in the bspstore
> >locations?
> 
> The processor writes out stacked registers to the
> bspstore
> area "in the background" while other execution is
> happening.

Does the compiler ever touch this backing store?
I believe it is used during a stack unwind?


> >b.) There is something called $GP and $TP that the
> >compiler defines as r1 and r13 respectively. Anyone
> >got any idea what they are?
> 
> r1 is used for simple access to some of the data,
> without
> it you would need to use "movl reg=<64-bit value>"
> to get
> the address of a global.  Using it, many data
> objects can
> be accessed using relative addressing from the $GP,
> a.k.a.
> __gp address.  $TP is used in the same way for
> thread local
> storage.

Thanks, the code makes a lot more sense now :)

> Can you provide a sample of C-code that results in
> this
> excessive storing to memory?

(I hope this e-mail is still readable after all this
code pasted in here =\)

+++------------------------------+++
int func(char* pszTest, int iTest, long lTest)
{
        int a, b, c, d, e, f, g, h, i, j, k, l, m, n,
o, p, q, r, s, t, u, v, w, x, y, z;

        a = 1; b = 2; c = 3; d = 4; e = 5; f = 6; g =
7; h = 8; i = 9; j = 10; k = 11; l = 12; m = 13;
	n = 14; o = 15; p = 16; q = 17; r = 18; s = 19; t =
20; u = 21; v = 22; w = 23; x = 24; y = 25; z = 26;

        printf("", a, b, c, d, e, f, g, h, i, j, k, l,
m, n, o, p, q, r, s, t, u, v, w, x, y, z, aa, bb, cc,
dd, ee, ff, gg);

        c = temp(a, b);
        return 0;
}
+++------------------------------+++
 
This code when compiled with gcc -g -O2 gives me this
assembly,

+++------------------------------+++
(From objdump) The function starts with,

int func(char* pszTest, int iTest, long lTest)
{
4000000000000680:       00 08 2d 06 80 05       [MII] 
     alloc r33=ar.pfs,11,3,0

Then corresponding to these lines,


        int a, b, c, d, e, f, g, h, i, j, k, l, m, n,
o, p, q, r, s, t, u, v, w, x, y, z;

        a = 1; b = 2; c = 3; d = 4; e = 5; f = 6; g =
7; h = 8; i = 9; j = 10; k = 11; l = 12; m = 13;
	n = 14; o = 15; p = 16; q = 17; r = 18; s = 19; t =
20; u = 21; v = 22; w = 23; x = 24; y = 25; z = 26;

        printf("", a, b, c, d, e, f, g, h, i, j, k, l,
m, n, o, p, q, r, s, t, u, v, w, x, y, z, aa, bb, cc,
dd, ee, ff, gg);


This is the assembly code,
4000000000000686:       c0 00 33 7c 46 c0             
     adds r12=-160,r12
400000000000068c:       81 00 00 90                   
     mov r14=8
4000000000000690:       09 28 09 00 00 24       [MMI] 
     mov r37=2
4000000000000696:       60 1a 00 00 48 e0             
     mov r38=3
400000000000069c:       44 00 00 90                   
     mov r39=4;;
40000000000006a0:       00 78 40 18 00 21       [MII] 
     adds r15=16,r12
40000000000006a6:       00 c1 30 00 42 20             
     adds r16=24,r12
40000000000006ac:       02 62 00 84                   
     adds r17=32,r12
40000000000006b0:       00 90 a0 18 00 21       [MII] 
     adds r18=40,r12
40000000000006b6:       30 81 31 00 42 80             
     adds r19=48,r12
40000000000006bc:       82 63 00 84                   
     adds r20=56,r12
40000000000006c0:       09 a8 00 19 00 21       [MMI] 
     adds r21=64,r12
40000000000006c6:       60 41 32 00 42 00             
     adds r22=72,r12
40000000000006cc:       00 00 04 00                   
     nop.i 0x0;;
40000000000006d0:       00 00 38 1e 90 11       [MII] 
     st4 [r15]=r14
40000000000006d6:       e0 48 00 00 48 e0             
     mov r14=9
40000000000006dc:       02 65 00 84                   
     adds r23=80,r12
40000000000006e0:       0a c0 60 19 00 21       [MMI] 
     adds r24=88,r12;;
40000000000006e6:       00 70 40 20 23 c0             
     st4 [r16]=r14
40000000000006ec:       a1 00 00 90                   
     mov r14=10
40000000000006f0:       02 c8 80 19 00 21       [MII] 
     adds r25=96,r12
40000000000006f6:       a0 41 33 00 42 60             
     adds r26=104,r12;;
40000000000006fc:       03 67 00 84                   
     adds r27=112,r12
4000000000000700:       09 00 38 22 90 11       [MMI] 
     st4 [r17]=r14
4000000000000706:       e0 58 00 00 48 80             
     mov r14=11
400000000000070c:       83 67 00 84                   
     adds r28=120,r12;;
4000000000000710:       00 00 38 24 90 11       [MII] 
     st4 [r18]=r14
4000000000000716:       e0 60 00 00 48 a0             
     mov r14=12
400000000000071c:       03 60 04 84                   
     adds r29=128,r12
4000000000000720:       0a f0 20 18 01 21       [MMI] 
     adds r30=136,r12;;
4000000000000726:       00 70 4c 20 23 c0             
     st4 [r19]=r14
400000000000072c:       d1 00 00 90                   
     mov r14=13
4000000000000730:       02 f8 40 18 01 21       [MII] 
     adds r31=144,r12
4000000000000736:       80 c0 30 02 42 20             
     adds r8=152,r12;;
400000000000073c:       01 62 04 84                   
     adds r9=160,r12
4000000000000740:       09 00 38 28 90 11       [MMI] 
     st4 [r20]=r14
4000000000000746:       e0 70 00 00 48 60             
     mov r14=14
400000000000074c:       04 0d 00 90                   
     addl r35=80,r1;;
4000000000000750:       00 00 38 2a 90 11       [MII] 
     st4 [r21]=r14
4000000000000756:       e0 78 00 00 48 40             
     mov r14=15
400000000000075c:       04 08 00 84                   
     mov r34=r1
4000000000000760:       0a 40 15 00 00 24       [MMI] 
     mov r40=5;;
4000000000000766:       00 70 58 20 23 c0             
     st4 [r22]=r14
400000000000076c:       01 01 00 90                   
     mov r14=16
4000000000000770:       02 48 19 00 00 24       [MII] 
     mov r41=6
4000000000000776:       a0 3a 00 00 48 00             
     mov r42=7;;
400000000000077c:       04 00 c4 00                   
     mov r32=b0
4000000000000780:       09 00 38 2e 90 11       [MMI] 
     st4 [r23]=r14
4000000000000786:       e0 88 00 00 48 80             
     mov r14=17
400000000000078c:       14 00 00 90                   
     mov r36=1;;
4000000000000790:       00 00 38 30 90 11       [MII] 
     st4 [r24]=r14
4000000000000796:       e0 90 00 00 48 00             
     mov r14=18
400000000000079c:       00 00 04 00                   
     nop.i 0x0
40000000000007a0:       0b 18 01 46 18 10       [MMI] 
     ld8 r35=[r35];;
40000000000007a6:       00 70 64 20 23 c0             
     st4 [r25]=r14
40000000000007ac:       31 01 00 90                   
     mov r14=19;;
40000000000007b0:       02 00 38 34 90 11       [MII] 
     st4 [r26]=r14
40000000000007b6:       e0 a0 00 00 48 00             
     mov r14=20;;
40000000000007bc:       00 00 04 00                   
     nop.i 0x0
40000000000007c0:       02 00 38 36 90 11       [MII] 
     st4 [r27]=r14
40000000000007c6:       e0 a8 00 00 48 00             
     mov r14=21;;
40000000000007cc:       00 00 04 00                   
     nop.i 0x0
40000000000007d0:       02 00 38 38 90 11       [MII] 
     st4 [r28]=r14
40000000000007d6:       e0 b0 00 00 48 00             
     mov r14=22;;
40000000000007dc:       00 00 04 00                   
     nop.i 0x0
40000000000007e0:       02 00 38 3a 90 11       [MII] 
     st4 [r29]=r14
40000000000007e6:       e0 b8 00 00 48 00             
     mov r14=23;;
40000000000007ec:       00 00 04 00                   
     nop.i 0x0
40000000000007f0:       02 00 38 3c 90 11       [MII] 
     st4 [r30]=r14
40000000000007f6:       e0 c0 00 00 48 00             
     mov r14=24;;
40000000000007fc:       00 00 04 00                   
     nop.i 0x0
4000000000000800:       02 00 38 3e 90 11       [MII] 
     st4 [r31]=r14
4000000000000806:       e0 c8 00 00 48 00             
     mov r14=25;;
400000000000080c:       00 00 04 00                   
     nop.i 0x0
4000000000000810:       02 00 38 10 90 11       [MII] 
     st4 [r8]=r14
4000000000000816:       e0 d0 00 00 48 00             
     mov r14=26;;
400000000000081c:       00 00 04 00                   
     nop.i 0x0
4000000000000820:       11 00 38 12 90 11       [MIB] 
     st4 [r9]=r14
4000000000000826:       00 00 00 02 00 00             
     nop.i 0x0
400000000000082c:       28 fc ff 58                   
     br.call.sptk.many b0=4000000000000440
<_init+0x150>;;
4000000000000830:       00 08 00 44 00 21       [MII] 
     mov r1=r34
+++------------------------------+++


As you can see, almost all the parameters are being
"st4'd" to memory. From the architecture
specification, shouldn't all these be moved into
registers? I have a total of much lesser than 96
parameters?


Code with lesser parameters (around 2-3) seems to use
registers fine though.

In the same code, corresponding to,

        c = temp(a, b);

The corresponding assembly is,

4000000000000836:       30 0a 00 00 48 80             
     mov r35=1
400000000000083c:       24 00 00 90                   
     mov r36=2
4000000000000840:       1d 00 00 00 01 00       [MFB] 
     nop.m 0x0
4000000000000846:       00 00 00 02 00 00             
     nop.f 0x0
400000000000084c:       e8 fd ff 58                   
     br.call.sptk.many b0=4000000000000620 <temp>;;



The register stack has more than enough registers to
handle 26 input's, 26 outputs and 26 local variables,
so why would it not put all the locals into registers
and pass them onto printf?


>>>>> Luck, Tony wrote on Tuesday, April 13, 2004 9:26
AM

> >Rahul Chaturvedi wrote on Monday, April 12, 2004
10:17 PM
> >d.) The pfs register seems to point to a location
in
> >0xcxxxxxxxxxxxxxxx. Shouldn't this point to some
> >accessible memory location (from usermode)?
>
> someone else can take this one?

ar.pfs is not a memory address pointer. See section
3.1.8.10 of
ia64 software developer's manual, volume 1 for proper
way to
decode that register (FYI, bit [63-62] is previous
privilege
level, which is 3 in the above case).

- Ken

Alright, okay, that also makes more sense now :)
I didn't look for the format for the pfs, I assumed it
was just a memory address.


	
		
__________________________________
Do you Yahoo!?
Yahoo! Tax Center - File online by April 15th
http://taxes.yahoo.com/filing.html
-
To unsubscribe from this list: send the line "unsubscribe linux-ia64" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Received on Wed Apr 14 01:11:44 2004

This archive was generated by hypermail 2.1.8 : 2005-08-02 09:20:25 EST