Jump to content
Sign in to follow this  
PhracturedBlue

Constant Optimization

Recommended Posts

If a function's input parameter is defined as 'const' I'd think that in many cases the copy could be optimized away as in:

 

void foo(const unsigned int a)
{
...
}
void bar()
{
  unsigned int b;
  b= ...
  ...
  foo(b);
  ...
}

 

Today, boostC will generate something like:

; bar
 movlw ...
 movwf _bar_b
 movlw ...
 movwf _bar_b+1
 ...
 movf _bar_b, W
 movwf _foo_a
 movwf _bar_b+1, W
 movwf _foo_a+1
 call foo
 ...

but this should not be too hard to optimize (in many situations) to:

_foo_a equ 0x0000005f
_bar_b equ 0x0000005f
;bar
 movlw ...
 movwf _bar_b
 movlw ...
 movwf _bar_b+1
 ...
 call foo
 ...

sure it is only 4 instructions, but I have cases in my code where these types of things eat a lot of code space. I can trade RAM for code size by making the variables global, but there is no reason to do this in many cases, especially if the compiler has already determined how to overlap temporary variables to minimize RAM usage.

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.

Guest
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.

Loading...
Sign in to follow this  

×
×
  • Create New...