I have some rather complex and highly templated code (C++, but this may not be very relevant) of which I'd like to know the number of adds, subs, muls, divs, and sqrts at execution. Is there an automatic way to get this information (the compiler could work it out easily)? I tried to count it myself in the assembler code generated, but got confused with jp
, jmp
, and call
s.
Automatic way to obtain the floating-point operation count for some piece of code
966 views Asked by Walter At
2
There are 2 answers
2
On
Yes you can, but the way is a bit complex:
Try to change your "add", "sub", "mul", "div", "sqrt" in the binary to some invalid opcode. Dont forget to define an invalid opcode error handler to restore the opcode. When you program runs, the cpu will trigger the invalid opcode error at those changed "add", "sub", "mul", "div", "sqrt". By counting the times invalid opcode error being triggered, you can get the exactly what you want.
I would suggest to override
+
,-
,*
,/
operators andsqrt
function for some float-like type, in which you can count their use.Something like this: