avr-gcc-list
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [avr-gcc-list] multiply by constant always expands to int


From: Paulo Marques
Subject: Re: [avr-gcc-list] multiply by constant always expands to int
Date: Tue, 06 Dec 2005 19:33:51 +0000
User-agent: Mozilla Thunderbird 1.0.6 (X11/20050716)

Eric Weddington wrote:
Paulo Marques wrote:
[...]
(modulo the register moves) but promotes "a" and "b" to 2-byte integers under gcc 4.0.2, generating a bunch of mul's and add's.

Could you provide a complete testcase, and not just a snippet? I'm having a hard time reproducing what you are describing with 4.0.2.

So did I!

I thought this would just happen with any multiply operation, and tried to build a simple test case, and to my surprise everything was just fine.

I tried to make the simple case more and more like my real program, to no avail. I finally gave up and started the other way around, peeling of code from my real program until I could get the simplest possible program that also showed the problem.

After a lot of peeling, this is it:

void test(void)
{
        unsigned short data;
        unsigned char a, b;

        a = PORTD;
        b = PORTC;
        
        data = b * a;

        OCR1A = data;

        b = PORTC;
        
        data = b * a;

        OCR1B = data;
}

I read/write values to ports just to make sure the compiler doesn't optimize the values away.

The weird thing is that, if you comment out the _second_ multiply, the _first_ one becomes properly compiled as a single "mul" instruction. If you leave it in, then _both_ become 2 byte wide!

I compiled this with today's gcc from subversion and the result is the same. This was compiled with -Os, but I believe it happens with other otpimization levels too.

Is there any documentation (good or bad) about the gcc internals that I could use as a starting point? Or is this a "use the source, Luke" kind of scenario? :)

That's a question for the gcc mailing list.

Oops, sorry.

The best thing to do is to start looking around on the GCC website and looking at all of the available documentation.

Will do.

Yes, they have an internals document. However, from what I've heard from others, it's not exactly easy to get through; it takes a lot of perserverance to learn GCC internals.

Ok, thanks for all the help :)

--
Paulo Marques
Software Development Department - Grupo PIE, S.A.
Phone: +351 252 290600, Fax: +351 252 290601
Web: www.grupopie.com

Pointy-Haired Boss: I don't see anything that could stand in our way.
           Dilbert: Sanity? Reality? The laws of physics?




reply via email to

[Prev in Thread] Current Thread [Next in Thread]