Jump to content
Sign in to follow this  
RJS

Is There Is Way To Remove The Bloat From C++ Calls?

Recommended Posts

I just upgraded to the C++ version of the compiler and while the compiler does not affect the size of my existing code when I recompile it, it does seem to create bloated code when using classes. For example in the non C++ version the function call func( a ); generates the following assembler code:

 

0012 5002 MOVF main_1_a, W

0014 6E03 MOVWF func_00001_arg_a

0016 EC02F000 CALL func_00001

 

However using a C++ version of the function, foo.func( a ); the following code is generated

 

0012 0E00 MOVLW HIGH(gbl_foo+D'0')

0014 6E04 MOVWF func_00000_arg_this+D'1'

0016 0E01 MOVLW LOW(gbl_foo+D'0')

0018 6E03 MOVWF func_00000_arg_this

001A 5002 MOVF main_1_a, W

001C 6E05 MOVWF func_00000_arg_a

001E EC02F000 CALL func_00000

 

I could understand this if I was using indirection or virtual functions but since the location of the function in my case is always deterministic I do not understand why the additional code is necessary. I have tried using the static keyword and it creates asm similar to the non C++ code in this simple example but a class with multiple functions is causes duplicate references and other errors and I could find any other way to use the static keyword or to otherwise reduce the code size.

 

Here is the example of a multi function class where I tried to use static but does not compile:

 

// test.cpp 
#include <system.h> 

#pragma CLOCK_FREQ 8000000 

#include "foo.h" 

FOO foo; 

void main( void ) 
{ 

char a; 

for( a = 0; a < 100; ++a ) 
foo.func( a ); 

} 

// foo.h 

class FOO 
{ 
public: 
static void func( char a ); 
static void anotherfunc( char a ); 
}; 

// foo.cpp 
#include "foo.h" 

void FOO::func( char a ) 
{ 
char b; 

b = a; 

anotherfunc( b ); 
} 

void FOO::anotherfunc( char a ) 
{ 
char b; 

b = a; 
}

 

 

Please let me know if there is any way to better optimize this while still using c++

 

Thanks,

 

RJS

Share this post


Link to post
Share on other sites

The "bloated" code is initialisation of this argument that is part of all class methods except static ones. Static class methods do not have this argument. Please try SourceBoost release candidate 6.91 that will be available within next couple of days. It has this issue sorted out.

 

Regards,

Pavel

Share this post


Link to post
Share on other sites
The "bloated" code is initialisation of this argument that is part of all class methods except static ones. Static class methods do not have this argument. Please try SourceBoost release candidate 6.91 that will be available within next couple of days. It has this issue sorted out.

 

Regards,

Pavel

 

I tried 6.91 RC2 and the static keyword now works for all functions and reduced my program size by 2K ;)

 

Thanks for the quick fix, you guys are are the best!!!!

 

RJS

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