Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Mon 22 Sep 2014, 04:25
All times are UTC - 4
 Forum index » Off-Topic Area » Programming
Reduced compiled size by eliminating redundant assembly
Post_new_topic   Reply_to_topic View_previous_topic :: View_next_topic
Page 1 of 1 Posts_count  
Author Message
technosaurus


Joined: 18 May 2008
Posts: 4351

PostPosted: Tue 29 Oct 2013, 12:12    Post_subject:  Reduced compiled size by eliminating redundant assembly  

The topic is covered with better formatting at:
http://stackoverflow.com/questions/19663795/automatic-code-deduplication-of-assembly-language

but I am interested in puppy-like solutions too, maybe someone can figure out a novel way to do this in 10 lines of awk Smile

I've been going through some Assembly Programming Videos to get a better understanding of how to manually optimize the *.s files left after compiling with gcc/g++ -S ... One of the topics covered was Refactoring Redundant Code that demonstrates how to move redundant code to its own labeled block ending with a ret and replacing it with a call.

Out of curiosity, trying to reduce compiled size, I compiled some C and C++ projects with -S and various optimizations including -Os,-O2,-O3,-pipe,-combine and -fwhole-program and analyzed the resulting *.s files for redundancy using a lightly patched (for .s files) version of duplo. Only -fwhole-program (now deprecated IIRC) had a significant effect toward eliminating duplicate code across files (I assume its replacement(s) -flto would behave similarly during link time - roughly equivalent to compiling with -ffunction-sections -fdata-sections and linking with --gc-sections) but still misses significantly large blocks of code.

The example given in the video is 2 blocks containing:
Code:
mov eax,power
mul ebx
mov power,eax
inc count
which it replaces with call CalculateNextPower and CalculateNextPower looks like:
Code:
CalculateNextPower:
mov eax,power
mul ebx
mov power,eax
inc count
ret
Am I missing a compiler option (or even a standalone tool) that does this automatically when compiling for size (including other compilers: clang, icc, etc..) or is this functionality absent (for a reason?).

If it doesn't exist, it could be possible to modify duplo to ignore lines starting with a '.' or ';' (and others?) and replace duplicate code blocks with calls to functions with the duplicate code, but I am open to other suggestions that would work directly with the compiler's internal representations.

_________________
Web Programming - Pet Packaging 100 & 101
Back to top
View user's profile Send_private_message 
technosaurus


Joined: 18 May 2008
Posts: 4351

PostPosted: Tue 29 Oct 2013, 15:42    Post_subject:  

Ok, I patched duplo for assembly files:

basic howto:
Code:
compile your c/cpp files with
gcc -S <options_here> *.c
gcc -S <options_here> *.cpp
for x in *.s; do;
echo $x
done > files.txt
duplo -ml 5 -ip files.txt out.txt


If you downloaded this version, try the one in the next post.

_________________
Web Programming - Pet Packaging 100 & 101

Edited_time_total
Back to top
View user's profile Send_private_message 
technosaurus


Joined: 18 May 2008
Posts: 4351

PostPosted: Tue 29 Oct 2013, 20:47    Post_subject:  

repatched duplo, need to keep labels in place (I thought it ended the string but it actually just removed the labels)
duplo-asm.patch.gz
Description 
gz

 Download 
Filename  duplo-asm.patch.gz 
Filesize  1.11 KB 
Downloaded  62 Time(s) 
duplo.tar.gz
Description 
gz

 Download 
Filename  duplo.tar.gz 
Filesize  14.44 KB 
Downloaded  63 Time(s) 

_________________
Web Programming - Pet Packaging 100 & 101
Back to top
View user's profile Send_private_message 
Display_posts:   Sort by:   
Page 1 of 1 Posts_count  
Post_new_topic   Reply_to_topic View_previous_topic :: View_next_topic
 Forum index » Off-Topic Area » Programming
Jump to:  

Rules_post_cannot
Rules_reply_cannot
Rules_edit_cannot
Rules_delete_cannot
Rules_vote_cannot
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.0585s ][ Queries: 13 (0.0142s) ][ GZIP on ]