1 /* 2 * Copyright (c) 1983 Regents of the University of California. 3 * All rights reserved. 4 * 5 * %sccs.include.redist.c% 6 */ 7 8 #ifndef lint 9 static char sccsid[] = "@(#)lookup.c 5.4 (Berkeley) 06/01/90"; 10 #endif /* not lint */ 11 12 #include "gprof.h" 13 14 /* 15 * look up an address in a sorted-by-address namelist 16 * this deals with misses by mapping them to the next lower 17 * entry point. 18 */ 19 nltype * 20 nllookup( address ) 21 unsigned long address; 22 { 23 register long low; 24 register long middle; 25 register long high; 26 # ifdef DEBUG 27 register int probes; 28 29 probes = 0; 30 # endif DEBUG 31 for ( low = 0 , high = nname - 1 ; low != high ; ) { 32 # ifdef DEBUG 33 probes += 1; 34 # endif DEBUG 35 middle = ( high + low ) >> 1; 36 if ( nl[ middle ].value <= address && nl[ middle+1 ].value > address ) { 37 # ifdef DEBUG 38 if ( debug & LOOKUPDEBUG ) { 39 printf( "[nllookup] %d (%d) probes\n" , probes , nname-1 ); 40 } 41 # endif DEBUG 42 return &nl[ middle ]; 43 } 44 if ( nl[ middle ].value > address ) { 45 high = middle; 46 } else { 47 low = middle + 1; 48 } 49 } 50 fprintf( stderr , "[nllookup] binary search fails???\n" ); 51 return 0; 52 } 53 54 arctype * 55 arclookup( parentp , childp ) 56 nltype *parentp; 57 nltype *childp; 58 { 59 arctype *arcp; 60 61 if ( parentp == 0 || childp == 0 ) { 62 fprintf( "[arclookup] parentp == 0 || childp == 0\n" ); 63 return 0; 64 } 65 # ifdef DEBUG 66 if ( debug & LOOKUPDEBUG ) { 67 printf( "[arclookup] parent %s child %s\n" , 68 parentp -> name , childp -> name ); 69 } 70 # endif DEBUG 71 for ( arcp = parentp -> children ; arcp ; arcp = arcp -> arc_childlist ) { 72 # ifdef DEBUG 73 if ( debug & LOOKUPDEBUG ) { 74 printf( "[arclookup]\t arc_parent %s arc_child %s\n" , 75 arcp -> arc_parentp -> name , 76 arcp -> arc_childp -> name ); 77 } 78 # endif DEBUG 79 if ( arcp -> arc_childp == childp ) { 80 return arcp; 81 } 82 } 83 return 0; 84 } 85