flat assembler
Message board for the users of flat assembler.
![]() |
Author |
|
revolution 31 May 2010, 06:28
Get a disassembly listing of the C generated code. I expect you will find that the loop is completely eliminated from the code since it produces no output.
Try using something like this: Code: for ( i=0 ; i<1000000000 ; i++) { area+=pi*r*r; } printf ("area=%f",area) } |
|||
![]() |
|
LocoDelAssembly 31 May 2010, 07:42
Still, I'm quite sure the C compiler is very likely to do better job than the assembly version, I don't think that, for instance, "area" won't gonna be registered, pi will be reloaded always and pi*r*r will be recalculated in each iteration instead of moving it at for "prolog". At least one of those inefficiencies GCC will optimize out.
PS: What I've said above is only valid for the case of consuming the for-loop output, using volatile variables could indeed make the compiler be beaten by the Assembly version (for instance, GCC may be forced to access R twice from before when multiplying instead of once as the Assembly code) PS2: (last I hope) The Assembly version is using two fp registers per iteration but releasing only one. After enough iterations, the result will be just a NaN and the processor probably will take more time executing the FPU instructions because of that (besides the before mentioned inefficiencies). Note that you have to fix this for correctness sake as you are not producing a valid result. |
|||
![]() |
|
Endre 31 May 2010, 08:45
I don't know how you've compiled your c-file with gcc, but depending whether you use any optimization switches or not the result can be very different. For instance if you apply -O2 then nothing will be computed in run-time since "pi" and "r" are assumed to be constants (they don't change), thus the compiler eliminates the whole loop and the computation.
If you want to see what gcc generates then just use objdump -S my_file | less On the other hand if you don't apply any optimization switch then it shan't be quicker than your assembly program. If you really want to demonstrate how faster your assembly program is then try writing a c-code which makes the compiler believe that it is really a sane c-program and cannot be optimized to zero (as the compiler did with your current c-program). |
|||
![]() |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.