1
0
mirror of https://github.com/adtools/clib2.git synced 2025-12-08 14:59:05 +00:00
Files
amiga-clib2/library/profile__mcount.c
Olaf Barthel 91bcdea2a2 Initial import into SourceForge CVS
git-svn-id: file:///Users/olsen/Code/migration-svn-zu-git/logical-line-staging/clib2/trunk@14685 87f5fb63-7c3d-0410-a384-fd976d0f7a62
2004-07-26 16:36:55 +00:00

104 lines
1.8 KiB
C

#include "profile_gmon.h"
#include <exec/exec.h>
#include <proto/exec.h>
#include <stddef.h>
void
__mcount(uint32 frompc, uint32 selfpc)
{
uint16 *frompcindex;
struct tostruct *top, *prevtop;
struct gmonparam *p;
int32 toindex;
p = &_gmonparam;
if (p->state != kGmonProfOn) return;
p->state = kGmonProfBusy;
/*
* Check if the PC is inside our text segment.
* Really should be...
*/
frompc -= p->lowpc;
selfpc -= p->lowpc;
if (frompc > p->textsize) goto done;
#if (HASHFRACTION & (HASHFRACTION-1)) == 0
if (p->hashfraction == HASHFRACTION)
{
frompcindex = &p->froms[(size_t)(frompc / (HASHFRACTION *
sizeof(*p->froms)))];
}
else
#endif
{
frompcindex = &p->froms[(size_t)(frompc / (p->hashfraction *
sizeof(*p->froms)))];
}
toindex = *frompcindex;
if (toindex == 0)
{
/* first time down this arc */
toindex = ++p->tos[0].link;
if (toindex >= p->tolimit)
/* Ouch! Overflow */
goto overflow;
*frompcindex = (uint16)toindex;
top = &p->tos[toindex];
top->selfpc = selfpc;
top->count = 1;
top->link = 0;
goto done;
}
top = &p->tos[toindex];
if (top->selfpc == selfpc)
{
/* arc at front of chain */
top->count++;
goto done;
}
for (;;)
{
if (top->link == 0)
{
toindex = ++p->tos[0].link;
if (toindex >= p->tolimit)
goto overflow;
top = &p->tos[toindex];
top->selfpc = selfpc;
top->count = 1;
top->link = *frompcindex;
*frompcindex = (uint16)toindex;
goto done;
}
prevtop = top;
top = &p->tos[top->link];
if (top->selfpc == selfpc)
{
top->count++;
toindex = prevtop->link;
prevtop->link = top->link;
top->link = *frompcindex;
*frompcindex = (uint16)toindex;
goto done;
}
}
done:
p->state = kGmonProfOn;
return;
overflow:
p->state = kGmonProfError;
return;
}