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.