View previous topic :: View next topic |
Author |
Message |
bogey n00b
Joined: 16 May 2003 Posts: 40 Location: USA
|
Posted: Wed Aug 06, 2003 4:02 pm Post subject: assembly and c |
|
|
I've been playing around with assembly under GNU/Linux. I've been looking at the assembly produced by GCC. I wrote an article (if you can call a text file on my own site an article) about some of the things I've found. I'd just like to know what some people on here think...
read it at:
http://www.geocities.com/thoolihan/loops.txt
(Forgive the old gcc and kernel version, I wrote in on a slackware box at work. But I've done the same thing at home on my gentoo boxes.)
Thanks,
-bogey |
|
Back to top |
|
|
masseya Bodhisattva
Joined: 17 Apr 2002 Posts: 2602 Location: Baltimore, MD
|
Posted: Wed Aug 06, 2003 4:13 pm Post subject: |
|
|
The article is a pretty good intro into hand optimizing assembly, but that is a very complicated thing to do on a non-trivial program. It's certainly educational, for which I applaud you, but you might be more interested in testing the assembly produced from compiled programs using different flags. _________________ if i never try anything, i never learn anything..
if i never take a risk, i stay where i am.. |
|
Back to top |
|
|
ragger n00b
Joined: 10 Feb 2003 Posts: 21
|
Posted: Wed Aug 06, 2003 4:52 pm Post subject: |
|
|
You should also check the code generated for different optimization settings.
GCC can be very clever, e.g. i compiled test3.c with -O3 -funroll-loops which resulted in the following asm code:
Code: |
main:
pushl %ebp
movl %esp, %ebp
subl $24, %esp
andl $-16, %esp
movl $10, 12(%esp) ; x = 10
movl $35, 8(%esp) ; y = 35
movl $10, 4(%esp) ; i = 10
movl $.LC0, (%esp)
call printf
movl %ebp, %esp
xorl %eax, %eax
popl %ebp
ret
|
As you can see the for loops have been optimized out and replaced with simple assignments. It doesn't get much faster than that.
About timing the code, the program probably runs not long enough to time it accurately. You may want to look into gprof to generate performance info. |
|
Back to top |
|
|
bogey n00b
Joined: 16 May 2003 Posts: 40 Location: USA
|
Posted: Wed Aug 06, 2003 6:23 pm Post subject: replies |
|
|
Thanks for the quick feedback masseya and ragger.
masseya: Quote: | but you might be more interested in testing the assembly produced from compiled programs using different flags.
| Agreed. I think the next step is to look at more real world situations.
ragger: Quote: | compiled test3.c with -O3 -funroll-loops |
As both you and masseya have suggested, I definitely will play around with the flags. As your code shows, it can have a large impact. And besides, compiler optimization is the gentoo way.
I think I should revise the article a bit though. It's seeming to read like a 'how to produce the fastest assembly code' discussion. That is interesting as well, but the original thought was 'what looking at gcc produced assembly can teach about c code'.
Also, I appreciate the gprof suggestion, I'll check it out. And I'll bump up the number of iterations to make differences more noticable.
Thanks again for the feedback and more is always welcome.
-bogey |
|
Back to top |
|
|
bogey n00b
Joined: 16 May 2003 Posts: 40 Location: USA
|
Posted: Wed Aug 06, 2003 7:44 pm Post subject: |
|
|
Alright, i've posted a slightly modified version:
[url]http://www.geocities.com/thoolihan/loops.txt [/url]
Also, per your suggestions, I'll next toy around with short programs that demonstrate effects of flags, and write up results. Maybe sometime in the next week or so.
-bogey |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|