In trying to implement a fast rotate with carry on the avr platform, it should be possible to do a left shift on a register, and then add-with-carry that register and __zero_reg__. i.e.:
asm volatile("lsl %0; adc %0, __zero_reg__" : "+r"(x) : "0"(x)); however, gcc doesn't seem to understand that the carry bit is set, and thus it only emits the lsl instruction. The workaround is to split it into 2 statements: asm volatile("lsl %0" : "+r"(x) : "0"(x)); asm volatile("adc %0, __zero_reg__" : "+r"(x) : "0"(x)); That generates the expected (correct) output. -- Summary: GCC incorrectly optimizes inline assembly, resulting in incorrect code Product: gcc Version: 4.3.4 Status: UNCONFIRMED Severity: critical Priority: P3 Component: target AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: dgrnbrg at mit dot edu GCC build triplet: --target=avr --program-prefx=avr --enable-languages=c -- disable- GCC host triplet: i688-linux GCC target triplet: avr http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39628