How to change library functions: add, sub, mul, div?

OP #1839176
Rate this post
• ▲ useful
▼ not useful
I would like to know how many times I use
math (double) functions: add, sub, mul, div inside a complex prog.

My first idea was to get the gcc sources and replace the
functions in libc library. If I'm not mistaken, this
is the double ADD function:

DFtype __adddf3(DFtype a, DFtype b)
{
  FP_DECL_EX;
  FP_DECL_D(A); FP_DECL_D(B); FP_DECL_D(R);
  DFtype r;

  FP_INIT_ROUNDMODE;
  FP_UNPACK_SEMIRAW_D(A, a);
  FP_UNPACK_SEMIRAW_D(B, b);
  FP_ADD_D(R, A, B);
  FP_PACK_SEMIRAW_D(r, R);
  FP_HANDLE_EXCEPTIONS;

  return r;
}

First of all, this one takes more time to execute than the
one in libc, which means that the code generated isn't the same.

Second, is there a simpler way?

Something like:

int ADDcount = 0;

set alias of "__adddf3" to "myADD"

double myADD (double n1, double n2)
{
        ADDcount++;

clear alias of "myADD" to original
        // call original function
        return (n1 + n2);
}

set alias of "__adddf3" to "myADD"

Thanks

Reply

Note: the original post is older than 6 months. Please don't ask any new questions in this thread, but start a new one.

Formatting
  • [c]C-Code[/c]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]
  • [[Title]] – link to an article
  • Link to another post: right-click its post ID (#8078628), copy the address, paste it into the text

More about formatting

Post long source code as an attachment, not in the text.

Already registered? Log in

Not shown to anyone. We send you a link; your post appears once you confirm it there.

By submitting you create a free account and accept the terms of use.