date and time created 81/10/15 13:47:05 by peter
authorPeter B. Kessler <peter@ucbvax.Berkeley.EDU>
Fri, 16 Oct 1981 05:47:05 +0000 (21:47 -0800)
committerPeter B. Kessler <peter@ucbvax.Berkeley.EDU>
Fri, 16 Oct 1981 05:47:05 +0000 (21:47 -0800)
SCCS-vsn: usr.bin/gprof/lookup.c 1.1

usr/src/usr.bin/gprof/lookup.c [new file with mode: 0644]

diff --git a/usr/src/usr.bin/gprof/lookup.c b/usr/src/usr.bin/gprof/lookup.c
new file mode 100644 (file)
index 0000000..e4831d1
--- /dev/null
@@ -0,0 +1,77 @@
+#ifndef lint
+    static     char *sccsid = "@(#)lookup.c    1.1 (Berkeley) %G%";
+#endif lint
+
+#include "dprof.h"
+
+    /*
+     * 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( address )
+    unsigned long      address;
+{
+    register long      low;
+    register long      middle;
+    register long      high;
+#   ifdef DEBUG
+       register int    probes;
+
+       probes = 0;
+#   endif DEBUG
+    for ( low = 0 , high = nname - 1 ; low != high ; ) {
+#      ifdef DEBUG
+           probes += 1;
+#      endif DEBUG
+       middle = ( high + low ) >> 1;
+       if ( nl[ middle ].value <= address && nl[ middle+1 ].value > address ) {
+#          ifdef DEBUG
+               if ( debug & TALLYDEBUG ) {
+                   printf( "[nllookup] %d (%d) probes\n" , probes , nname-1 );
+               }
+#          endif DEBUG
+           return &nl[ middle ];
+       }
+       if ( nl[ middle ].value > address ) {
+           high = middle;
+       } else {
+           low = middle + 1;
+       }
+    }
+    fprintf( stderr , "[nllookup] binary search fails???\n" );
+    return 0;
+}
+
+arctype *
+arclookup( parentp , childp )
+    nltype     *parentp;
+    nltype     *childp;
+{
+    arctype    *arcp;
+
+    if ( parentp == 0 || childp == 0 ) {
+       fprintf( "[arclookup] parentp == 0 || childp == 0\n" );
+       return 0;
+    }
+#   ifdef DEBUG
+       if ( debug & TALLYDEBUG ) {
+           printf( "[arclookup] parent %s child %s\n" ,
+                   parentp -> name , childp -> name );
+       }
+#   endif DEBUG
+    for ( arcp = parentp -> children ; arcp ; arcp = arcp -> arc_childlist ) {
+#      ifdef DEBUG
+           if ( debug & TALLYDEBUG ) {
+               printf( "[arclookup]\t arc_parent %s arc_child %s\n" ,
+                       arcp -> arc_parentp -> name ,
+                       arcp -> arc_childp -> name );
+           }
+#      endif DEBUG
+       if ( arcp -> arc_childp == childp ) {
+           return arcp;
+       }
+    }
+    return 0;
+}