public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug inline-asm/37895] AVR inline assembly clobbers input value
       [not found] <bug-37895-4@http.gcc.gnu.org/bugzilla/>
@ 2010-11-06 12:20 ` avr at gjlay dot de
  2011-03-12 13:01 ` avr at gjlay dot de
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 4+ messages in thread
From: avr at gjlay dot de @ 2010-11-06 12:20 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37895

Georg Lay <avr at gjlay dot de> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |avr at gjlay dot de,
                   |                            |Rudolf.Leitgeb at gmx dot
                   |                            |at

--- Comment #1 from Georg Lay <avr at gjlay dot de> 2010-11-06 12:20:27 UTC ---
(In reply to comment #0)
> I carefully followed the instructions how to write proper inline assembly for

Please not that no one will be able to reproduce this without a compileable
testcase and compiler options.

> Here's sample code, I tried to write a fast routine for multiplying a 16-bit
> number with an 8 bit number, the result would be written to a 32 bit number:

The snippet itself looks ok. However, the clobber are good for nothing except
confusing you or potential readers. R0 and R1 are fixed as per avr ABI so
clobbering them is useless. That's the reason why you have to write the final
CLR 

> I get incorrect results. I believe this is the case because the "left" variable
> is assigned to the same registers as "result", and "left" is overwritten during
> the multiplication. According to several web pages the  "=&r" (result)
> directive should prevent exactly this ....

Correct.

> Since the bug reporting guide explicitly discourages from posting assembly code
> generated by the compiler, I refrain from posting it here, although it might
> help clarify this issue. I will post it upon request, though :)

asm might be helpful here to explain, but exev more helpful would be the
source.

> Some extra information:
> 
> I don't use plain vanilla avr gcc, but the win avr version: WinAVR 20071221,
> which is 4.2.2 plus some AVR specific patches (some bug fixes, extra device
> support). Please let me know, if gcc-bugzilla is the wrong address for these
> bugs!

Probably. There might be bugs that are introduced by some patches that are
incorporated in WinAVR but not in mainline avr-gcc, so claritying where a bug
originates is tedious and the first place to consult might be a place like
avrfreaks.net or mikrocontroller.net which are much more busy than this page.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug inline-asm/37895] AVR inline assembly clobbers input value
       [not found] <bug-37895-4@http.gcc.gnu.org/bugzilla/>
  2010-11-06 12:20 ` [Bug inline-asm/37895] AVR inline assembly clobbers input value avr at gjlay dot de
@ 2011-03-12 13:01 ` avr at gjlay dot de
  2011-03-14 13:52 ` Rudolf.Leitgeb at gmx dot at
  2011-03-14 14:14 ` eric.weddington at atmel dot com
  3 siblings, 0 replies; 4+ messages in thread
From: avr at gjlay dot de @ 2011-03-12 13:01 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37895

Georg-Johann Lay <avr at gjlay dot de> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |eric.weddington at atmel
                   |                            |dot com

--- Comment #2 from Georg-Johann Lay <avr at gjlay dot de> 2011-03-12 13:01:13 UTC ---
I can not confirm the problems for WinAVR-20071221 (gcc 4.2.2)

With the following function

int32_t test_mul (void)
{
    int32_t res = mul_16_8(0x1234, 0x56);
    return res;
}

Both the generated code and the result of the computation (400760 in that
specific case) are as expected.

Presumably there is an error in your code outside the snippet (which we aren't
allowed to see), maybe some signed/undigned clashes, promotion problems,
overflows, etc.

The code compiles with 
  -S -Os -mmcu=atmega88 -fverbose-asm
to

<asm>
test_mul:
/* prologue: frame size=0 */
/* prologue end (size=0) */
    ldi r24,lo8(4660)     ;  tmp43,
    ldi r25,hi8(4660)     ;  tmp43,
    ldi r18,lo8(86)     ;  tmp44,
    movw r20,r24     ; , tmp43
/* #APP */
    clr r24;     ;  res
    clr r25;     ;  res
    mul r20, r18;     ; , tmp44
    movw r22, r0;     ;  res
    mul r21, r18;     ; , tmp44
    add r23, r0;     ;  res
    adc r24, r1;     ;  res
    clr __zero_reg__

/* #NOAPP */
/* epilogue: frame size=0 */
    ret
</asm>
which is correct. gcc respects the early-clobber, i.e. the output operand
(r22-r25) does not overlap an input operand (r20-r21 and r18).

IMO this bug is invalid and can be closed.

Johann


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug inline-asm/37895] AVR inline assembly clobbers input value
       [not found] <bug-37895-4@http.gcc.gnu.org/bugzilla/>
  2010-11-06 12:20 ` [Bug inline-asm/37895] AVR inline assembly clobbers input value avr at gjlay dot de
  2011-03-12 13:01 ` avr at gjlay dot de
@ 2011-03-14 13:52 ` Rudolf.Leitgeb at gmx dot at
  2011-03-14 14:14 ` eric.weddington at atmel dot com
  3 siblings, 0 replies; 4+ messages in thread
From: Rudolf.Leitgeb at gmx dot at @ 2011-03-14 13:52 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37895

--- Comment #3 from Rudolf Leitgeb <Rudolf.Leitgeb at gmx dot at> 2011-03-14 13:52:15 UTC ---
Wow, it's a while since I reported this issue... and the problem seems to have
gone away with newer versions of avr-gcc, I just tried version 4.3.5 which
comes with Ubuntu 10.10.

So, please go ahead and close it.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug inline-asm/37895] AVR inline assembly clobbers input value
       [not found] <bug-37895-4@http.gcc.gnu.org/bugzilla/>
                   ` (2 preceding siblings ...)
  2011-03-14 13:52 ` Rudolf.Leitgeb at gmx dot at
@ 2011-03-14 14:14 ` eric.weddington at atmel dot com
  3 siblings, 0 replies; 4+ messages in thread
From: eric.weddington at atmel dot com @ 2011-03-14 14:14 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37895

Eric Weddington <eric.weddington at atmel dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |WORKSFORME

--- Comment #4 from Eric Weddington <eric.weddington at atmel dot com> 2011-03-14 14:13:35 UTC ---
(In reply to comment #3)
> So, please go ahead and close it.

Ok. Closing as WORKSFORME.


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2011-03-14 14:14 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <bug-37895-4@http.gcc.gnu.org/bugzilla/>
2010-11-06 12:20 ` [Bug inline-asm/37895] AVR inline assembly clobbers input value avr at gjlay dot de
2011-03-12 13:01 ` avr at gjlay dot de
2011-03-14 13:52 ` Rudolf.Leitgeb at gmx dot at
2011-03-14 14:14 ` eric.weddington at atmel dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).