Re: [avr-gcc-list] dev and mod may not be optimized

2007-12-12 Thread David Brown
Dmitry K. wrote: On Wednesday 12 December 2007 01:16, Albert Andras wrote: - Original Message - From: Nathan Moore [EMAIL PROTECTED] unsigned char a, b, c; c = some_input_function(); LABEL: a = c/10; b = c%10; ... * LABEL: mov r24,r18 ldi

Re: [avr-gcc-list] dev and mod may not be optimized

2007-12-12 Thread Paulo Marques
Gre7g Luterman wrote: [...] Well if size speed are getting you down, try this: http://pastie.textmate.org/127218 The calculation takes 22 bytes and executes in 40 clocks. As an assembly-language programmer, having that extra MOV in the beginning annoys me, but hey, I try not to break the asm

RE: [avr-gcc-list] dev and mod may not be optimized

2007-12-12 Thread Nathan Moore
Thank you for your explination Bjoern. I have looked at GCC internals before, but never worked on them, so I'm likely to say something stupid. I would have thought that an optimization pattern for just this type of thing would have already been in GCC, especially since on the internal helper

Re: [avr-gcc-list] dev and mod may not be optimized

2007-12-12 Thread Paulo Marques
Paulo Marques wrote: [...] a = (c * 65534) 16; b = c - (a * 10); leaving you with no divisions to perform. The main problem is that the first multiplication should be done with some hand optimized assembly to perform a 8x16 bit multiplication, leaving just the upper 8 bits of a 24 bit

RE: [avr-gcc-list] dev and mod may not be optimized

2007-12-12 Thread Weddington, Eric
-Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] org] On Behalf Of Nathan Moore Sent: Tuesday, December 11, 2007 9:26 AM To: avr-gcc-list@nongnu.org Subject: RE: [avr-gcc-list] dev and mod may not be optimized Thank you for your explination Bjoern. I

Re: [avr-gcc-list] dev and mod may not be optimized

2007-12-12 Thread Gre7g Luterman
--- Paulo Marques [EMAIL PROTECTED] wrote: Actually after a few more digging, we can do this all in plain C, by using a smaller reciprocal multiplier: snipped Wow, that's freakin' inspired! And you're right it does optimize nicely. Here's a 20 byte version that executes in 12 cycles:

Re: [avr-gcc-list] dev and mod may not be optimized

2007-12-12 Thread Paulo Marques
Gre7g Luterman wrote: --- Paulo Marques [EMAIL PROTECTED] wrote: Actually after a few more digging, we can do this all in plain C, by using a smaller reciprocal multiplier: snipped Wow, that's freakin' inspired! Thanks :) It's not really a new idea, though. Using multiply by the

Re: [avr-gcc-list] dev and mod may not be optimized

2007-12-11 Thread Eric Pasquier
Just a correction : div() take 2 parameters : div_t t; t=div(c, 10); a=t.quot; b=t.rem; Eric. - Original Message - From: Albert Andras To: avr-gcc-list@nongnu.org Sent: Tuesday, December 11, 2007 4:16 PM Subject: Re: [avr-gcc-list] dev and mod may

Re: [avr-gcc-list] dev and mod may not be optimized

2007-12-11 Thread Dmitry K.
On Wednesday 12 December 2007 01:16, Albert Andras wrote: - Original Message - From: Nathan Moore [EMAIL PROTECTED] unsigned char a, b, c; c = some_input_function(); LABEL: a = c/10; b = c%10; ... * LABEL: mov r24,r18 ldi

RE: [avr-gcc-list] dev and mod may not be optimized

2007-12-11 Thread Weddington, Eric
-Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] org] On Behalf Of Dmitry K. Sent: Tuesday, December 11, 2007 3:44 PM To: avr-gcc-list@nongnu.org Cc: Nathan Moore Subject: Re: [avr-gcc-list] dev and mod may not be optimized Alas, the usage of div

Re: [avr-gcc-list] dev and mod may not be optimized

2007-12-11 Thread Gre7g Luterman
--- Dmitry K. [EMAIL PROTECTED] wrote: Alas, the usage of div() function is more space and more time expansive. The reason is that div() uses an another function: __divmodhi4(), i.e. 16-bits. Compare two programs: prog1: 150 bytes, 238 clocks prog2: 212 bytes, 316 clocks Well if

Re: [avr-gcc-list] dev and mod may not be optimized

2007-12-11 Thread Dmitry K.
On Wednesday 12 December 2007 09:29, Weddington, Eric wrote: Should we implement 2 (or 3) div functions then in avr-libc? 8, 16, and 32 bit? Possible, yes. Today the libgcc labrary contains 6 division functions (8, 16, 32 bits, signed and unsigned), but Avr-libc includes only 2 links (div,

RE: [avr-gcc-list] dev and mod may not be optimized

2007-12-11 Thread Weddington, Eric
-Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] org] On Behalf Of Dmitry K. Sent: Tuesday, December 11, 2007 5:37 PM To: avr-gcc-list@nongnu.org Subject: Re: [avr-gcc-list] dev and mod may not be optimized On Wednesday 12 December 2007 09:29, Weddington