The listing provided (math.lst) does not indicate any bugs. The code performs ( as I can see) properly.
jl performs a jump upon compare on signed numbers. So,if (char)temp1 less than zero then it jumps. Starus register in your case being updated upon add.b #0x30, &temp1 Appropriate jump insn is: ; (jump_insn 13 12 24 (set (pc) ; (if_then_else (lt:QI (mem:QI (symbol_ref:HI ("temp1"))) ; (const_int 0 [0x0])) ; (label_ref 22) ; (pc))) 7 {*cbranchqi} BTW, In your example V bit cannot be set. cheers, ~d On Tuesday 15 July 2003 03:51, Takahashi, Chris wrote: > I have discovered code which optimizes improperly. Attached are multiple > versions of the code. The code is incorrect if any level of optimization > is on (-O1 -O2 -O3 or -Os). test.c is compileable under gcc and > msp430-gcc. When targeted at i386 the source generates valid code with both > -D_WORK_ (the _WORK_ define switches from a valid to invalid version when > compiled) and with out (in fact it creates the same code). Also attached > is math.c which contains the problematic code with minimal support code so > that a minimal object can be created. math.c also is the same as the > preprocessed code of math.c. > > When compiled for the MSP target it uses msp430 simulator to assess the > validity of the code. When the dysfunctional code is compiled it creates a > jl instruction in place of a jn instruction after the if statement (see > attached math.lst). > > I have included a make file to make viewing the bug easier. All you need > is the simulator in your path and it will make the code and run the test > cases. > > About the code: > The attached code (in math.c) increments the upper nibble of temp1 by 3 > then > > examines the upper nibble of temp1 to see if it is >= 8. If it is then > do nothing, otherwise > undo the increment by decrementing the upper nibble by 3. > > The assembly generated performs the inc by 3 then checks the n and v flags > with the jl instruction to determine when to jump. because only the last > bit is being checked it is only appropriate to check the n flag -- as the > result of the last arithmetic instr is inconsequential (aside from the > content of bit 7). > > If any more info is needed please mail me or the list. And I'll send it > ASAP. > > -Chris Takahashi -- /***************************************************************** ("`-''-/").___..--''"`-._ (\ Dimmy the Wild UA1ACZ `6_ 6 ) `-. ( ).`-.__.`) State Polytechnical Univ. (_Y_.)' ._ ) `._ `. ``-..-' Radio-Physics Departament _..`--'_..-_/ /--'_.' ,' Saint Petersburg, Russia (il),-'' (li),' ((!.-' +7 (812) 5403923, 5585314 *****************************************************************/