Jump to content
Sign in to follow this  
Guest Pavel

Optimization issues

Recommended Posts

Guest Pavel

Sometimes compiler doesn't generate optimal code for a given expression. Optimizing such assembly will be beneficial for all compiler users and every such case worths an enhancement reques. An optimization request should consist of three parts:


1. C code that generates unoptimized assemby pattern

2. Unoptimized assembly code

3. Proposed optimized assembly code


For example an item can look like:


Double AND optimization proposal:

1. char a, b, c, d, e;
   a = b ^ (c & 0xf0) ^ (d << 5) ^ e;

2.;;;;;;;; a = b ^ (c & 0xf0) ^ (d << 5) ^ e;
movf _c_main, W
andlw D'240'
xorwf _b_main, W
movwf _code_tmp_0000
movf _d_main, W
movwf _code_tmp_0001
rlf _code_tmp_0001 , F
swapf _code_tmp_0001, W
andlw 0xF0                           ;<<<<<<<<<<<<<<<<
andlw D'224'                        ;<<<<<<<<<<<<<<<<
xorwf _code_tmp_0000 , W
xorwf _e_main, W
movwf _a_main

3. Replace 2 marked instructions with:
andlw 0xF0
where instruction operand (0xF0) = operand_from instruction_1  (0xF0) | operand_from instruction_2 (D'224')




Share this post

Link to post
Share on other sites

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

  • Create New...