EmbDev.net

Forum: ARM programming with GCC/GNU tools How to change library functions: add, sub, mul, div?


Author: A. S. (aleksazr)
Posted on:

Rate this post
0 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

Entering an e-mail address is optional. If you want to receive reply notifications by e-mail, please log in.

Rules — please read before posting

  • Post long source code as attachment, not in the text
  • Posting advertisements is forbidden.

Formatting options

  • [c]C code[/c]
  • [avrasm]AVR assembler code[/avrasm]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]




Bild automatisch verkleinern, falls nötig
Note: the original post is older than 6 months. Please don't ask any new questions in this thread, but start a new one.