AVR GCC Cyclomatic Complexity Limitation

Go To Last Post
13 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Dear forum,

I am developing my application with AVR Studio. I am using a lot of linked lists and the code cyclomatic complexity is really high(ifs inside ifs inside ifs, inside whiles inside switch-cases...).

I have been developing with Eclipse and compiled with gcc for PC and everything worked fine. Now I want to port it to AVR and surprise.. some parts of the code are not generated (some parts of the machine code).

I was surprised to see this when I looked with AVRStudio's disassembler.

My question is this : what is the maximum amount of complexity AVR GCC can support? I am currently manually optimising code, but I can't really do anything in cases where I need to iterate the linked list and do nesed ifs or switch-cases on the current element :(

Cheers,
Mihai

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

My guess is that GCC is optimizing some of your code away, because the result appear to be unused. Try turning all optimization off(if that's an option).

Four legs good, two legs bad, three legs stable.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

you could at least turn off the optimisation to see if the 'gone' code has returned

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks for your replies. I already did that, even with the -O0 some parts are not generated. The code is just too complex :(

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

mihaigalos wrote:
Thanks for your replies. I already did that, even with the -O0 some parts are not generated. The code is just too complex :(

I seriously doubt that - I've been a member of this forum for a few years, and I've never heard of anyone writing code that is "too complex" for GCC.
In fact, I will wager you fifty shiny pence that the problem lies elsewhere.

Four legs good, two legs bad, three legs stable.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Dear John,

I am not rulling out that possibility :)

it's not GCC, it's AVR-GCC. It does run correctly on the PC when compiled with GCC.
Specific parts of machine code are not generated by avr-gcc, I have really long ifs and the level of nesting is over 20 in parts of the code.

I'm kind of abusing the compiler, if you wish. I just want to know how much I can abuse it until it cracks.

Look at this, for example; All of this is inside an even bigger if which is in a switch branch which is in a while loop..

while(NULL != symIterator)
	{
	
		if(
			(0 == strcmp(symIterator->st->name,stp->name)) &&
			(
				(
					( symIterator->st->type_add_info == stp->type_add_info )&&
					( 
						(
							(NULL != symIterator->st->parent_type)&&
							(NULL != stp->parent_type) &&
							(0 == strcmp(symIterator->st->parent_type,stp->parent_type))&&
							( PARAM_F!= stp->type_add_info)
						) ||
						(
							( symIterator->st->parent_type[0] >= '0') &&
							( symIterator->st->parent_type[0] <= '9')
							
						)
					)
				)||
				(	
					(
						( PARAM_I  == symIterator->st->type_add_info) ||
						( PARAM_P == symIterator->st->type_add_info)
					) &&
					(
						( PARAM_F_I != stp->type_add_info) &&
						( PARAM_F_C   != stp->type_add_info) &&
						( PARAM_F_P!= stp->type_add_info)
					)
				)||
				(
					( PARAN_S_M == symIterator->st->type_add_info ) &&
					( 
						(NULL != symIterator->st->parent_type)&&
						(NULL != stp->parent_type) &&
						(0 == strcmp(symIterator->st->parent_type,stp->parent_type))
					)
				)||
				(
					(PARAM_N_I == stp->type) &&
					(PARAN_N_I == stp->type_add_info) &&
					(0 == strcmp(stp->parent_type,"None"))&&
					(0 == strcmp(stp->scope,symIterator->st->scope))
				)
			)
		  )
		{
...
}

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Well I'm no expert in C compilers, but as far as I know, GCC is GCC. OK, the assembly code generation will differ between targets, but the level of complexity/nesting levels etc. I would expect to be pretty much the same. I haven't the patience to try and work out what your code is trying to achieve, but that's where a C compiler performs way better than I do, having a much higher threshold of boredom. How many levels of nested ifs switch cases and so on do you estimate that you are using? I believe there minimum levels defined for C compilers according to the ANSI spec(if not, then certainly for the C99 spec).

Four legs good, two legs bad, three legs stable.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

it's not GCC, it's AVR-GCC

As John says, they are the same thing. avr-gcc is simply a port of GCC to an AVR cross compilation target.

One of the key differences between what you call "GCC" (I take that to be x86 GCC?) and avr-gcc is the size of the types. "int" is 32bit on ARM and x86 targets but just 16 bit on AVR so it's quite possible to write C on one that "breaks" on the other. Use of types will help this situation a LOT!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

thank you all.
It makes a lot of sense what you are saying, I'm not sure why chunks of code are not being generated.

I will do a repost when/if I find anything.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

One little thing from my own limited experience.
I too had problems when going up in complexity.
I use a Makefile and the command "make".
Worked fine on simple projects.
Things were missed out as the projects expanded.
The solution is "make clean" "make all".
If you dont use make or knew that anyway just ignor this.

John

If all else fails, read the instructions.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

Things were missed out as the projects expanded.
The solution is "make clean" "make all".

Then you hadn't got your dependency rules written correctly. A well written makefile will always recompile all the dependencies.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Doing a clean before is definetely helping. It seems to be working now.. Strange thing I haven't done it before- I thought Build All and Run does it anyhow.

I am using AVR Studio's auto-generated Makefile, and you can bet there is no clean in the make all rule.

Well.. all's well that ends well.. Thank you all.
And as for John-A-Brown, send me a message if you're ever in Lyon,France. I'll buy you a beer for the 50 pence I owe you :D

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
Well.. all's well that ends well.. Thank you all.
And as for John-A-Brown, send me a message if you're ever in Lyon,France. I'll buy you a beer for the 50 pence I owe you

Forget about it. I'll have a shot of pastis instead.

Four legs good, two legs bad, three legs stable.