FreeBSD/usr.bin/gprof/lookup.c
/*
     *	look up an address in a sorted-by-address namelist
     *	    this deals with misses by mapping them to the next lower
     *	    entry point.
     */
look up an address in a sorted-by-address namelist
this deals with misses by mapping them to the next lower
entry point.
look up an address in a sorted - by - address namelist this deals with misses by mapping them to the next lower entry point .
nltype *
nllookup(unsigned long address)
{
    register long	low;
    register long	middle;
    register long	high;
#   ifdef DEBUG
	register int	probes;
	probes = 0;
#   endif 
    for ( low = 0 , high = nname - 1 ; low != high ; ) {
#	ifdef DEBUG
	    probes += 1;
#	endif 
	middle = ( high + low ) >> 1;
	if ( nl[ middle ].value <= address && nl[ middle+1 ].value > address ) {
#	    ifdef DEBUG
		if ( debug & LOOKUPDEBUG ) {
		    printf( "[nllookup] %d (%d) probes\n" , probes , nname-1 );
		}
#	    endif 
#if defined(__arm__)
	if (nl[middle].name[0] == '$' &&
	    nl[middle-1].value == nl[middle].value)
		middle--;
#endif
	    return &nl[ middle ];
	}
	if ( nl[ middle ].value > address ) {
	    high = middle;
	} else {
	    low = middle + 1;
	}
    }
#   ifdef DEBUG
	if ( debug & LOOKUPDEBUG ) {
	    fprintf( stderr , "[nllookup] (%d) binary search fails\n" ,
		nname-1 );
	}
#   endif 
    return 0;
}
nltype * nllookup ( unsigned long address ) { register long low ; register long middle ; register long high ; #   ifdef DEBUG register int probes ; probes = 0 ; #   endif for ( low = 0 , high = nname - 1 ; low != high ; ) { #	ifdef DEBUG probes += 1 ; #	endif middle = ( high + low ) >> 1 ; if ( nl [ middle ] . value <= address && nl [ middle + 1 ] . value > address ) { #	    ifdef DEBUG if ( debug & LOOKUPDEBUG ) { printf ( " \n " , probes , nname - 1 ) ; } #	    endif #if defined ( __arm__ ) if ( nl [ middle ] . name [ 0 ] == ' ' && nl [ middle - 1 ] . value == nl [ middle ] . value ) middle -- ; #endif return & nl [ middle ] ; } if ( nl [ middle ] . value > address ) { high = middle ; } else { low = middle + 1 ; } } #   ifdef DEBUG if ( debug & LOOKUPDEBUG ) { fprintf ( stderr , " \n " , nname - 1 ) ; } #   endif return 0 ; }
look up an address in a sorted-by-address namelist
      this deals with misses by mapping them to the next lower
      entry point.
look up an address in a sorted - by - address namelist this deals with misses by mapping them to the next lower entry point .
/* DEBUG */ /* DEBUG */ /* DEBUG */ /* DEBUG */