[prev in list] [next in list] [prev in thread] [next in thread] 

List:       opensolaris-mdb-discuss
Subject:    Re: [mdb-discuss] making sense of branching instructions
From:       Calum Mackay <Calum.Mackay () Sun ! COM>
Date:       2009-05-27 14:14:08
Message-ID: 4A1D4AB0.5010708 () sun ! com
[Download RAW message or body]

Mike Gerdts wrote:
> I'm trying to understand how to interpret SPARC branching instructions
> presented by mdb and am having some troubles.
>
> On snv_111a I see:
>
>> libc.so.1`fclose::dis
> libc.so.1`fclose:               save      %sp, -0x60, %sp
> libc.so.1`fclose+4:             orcc      %g0, %i0, %i1
> libc.so.1`fclose+8:             bne,pn    %icc, +0x10<libc.so.1`fclose+0x18>
> libc.so.1`fclose+0xc:           nop
> libc.so.1`fclose+0x10:          ret
> libc.so.1`fclose+0x14:          restore   %g0, -0x1, %o0
> libc.so.1`fclose+0x18:          call      +0x8<libc.so.1`fclose+0x20>
> ...
>
> At fclose+8, the instruction is saying to "branch to fclose+0x18" if
> thingA is not equal to thingB.  Presumably thingA is %icc (which
> itself is still a mystery to me) but I have no idea what thingB is.

to put it another way:

thingA is %g0 [i.e. zero], and thingB is %i0 [the first (and only) arg 
to fclose()]

bne uses %icc (explicitly) to see the result of the orcc, to decide 
whether they're equal.

something has predicted that this branch is not normally taken


fclose() returns early if its first arg is zero (i.e. a NULL pointer).

It returns -1, as part of the branch/ret

 > libc.so.1`fclose+0x14:          restore   %g0, -0x1, %o0

which is EOF. See the source here:

http://src.opensolaris.org/source/xref/onnv/onnv-gate/usr/src/lib/libc/port/stdio/flush.c#689

     694 	if (iop == NULL) {
     695 		return (EOF);		/* avoid passing zero to FLOCKFILE */
     696 	}



One might suggest that the prediction is probably wrong, here :)


cheers,
c.
_______________________________________________
mdb-discuss mailing list
mdb-discuss@opensolaris.org
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic