This is the mail archive of the
ecos-discuss@sources.redhat.com
mailing list for the eCos project.
Re: arm-elf-gcc question
- To: Grant Edwards <grante at visi dot com>
- Subject: Re: [ECOS] arm-elf-gcc question
- From: Gary Thomas <gthomas at redhat dot com>
- Date: Sat, 11 Nov 2000 06:08:21 -0700 (MST)
- Cc: ecos-discuss at sources dot redhat dot com
- Organization: Red Hat, Inc.
This is definitely a C compiler issue. I'd suggest that you
take it to them (gcc@gcc.gnu.org) if you want to pursue it.
On 10-Nov-2000 Grant Edwards wrote:
> On Fri, Nov 10, 2000 at 03:47:28PM -0700, Gary Thomas wrote:
>
>> On 10-Nov-2000 Grant Edwards wrote:
>> > This is really a gcc question, but I figure this is the list
>> > with the most people using the same version I am. ;)
>> >
>> > Do other people with the arm-elf-gcc 2.95.2 with ecos patches
>> > get this sort of incredibly odd-looking code, or is mine
>> > broken?
>> >
>> > [I've only written two compilers in my life, neither of which
>> > was anything to brag about, but... yikes!]
>>
>> This basically a jump table representing your switch statement.
>> The compiler makes choices about how to implement such a statement
>> and in this case, it was decided that a table of addresses indexed
>> by the "case" selector (i.e. a jump table) was the fastest/cheapest
>> way to go.
>>
>> What did you want/expect instead?
>
> I dunno. Something more like what you get if you write it as
> an equivalent if/else. I thought it was pretty standard for
> compilers to figure out whether a switch() was better
> represented by sequential tests or by a jump table. For a
> sparsely populated "case space" compilers I've used in the past
> have generally swtiched to sequential compares to save space.
> Even with size optimization turned on (-Os), it generates the
> jumptable version which is 5X larger than sequential compares.
>
> Memory is cheap, but it's never cheap enough. ;)
>
> If the size of the case space is increased slightly (from 0x20
> to 0x28) gcc does switch to sequential compares.
>
> The threshold could probably be lower -- especially on the ARM.
> The ARM better at comparing for multiple values than many other
> CPUs. You can test for any of 8 const values in 8 instructions
> (best case):
>
> cmp r3, #1
> cmpne r3, #2
> [...]
> cmpne r3, #8
>
> While on other CPUs it takes roughly twice as many instructions.
>
> --
> Grant Edwards
> grante@visi.com