From: SourceForge.net <no...@so...> - 2004-12-26 19:31:27
|
Bugs item #1086921, was opened at 2004-12-17 08:04 Message generated for change (Comment added) made by tecodev You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=100599&aid=1086921&group_id=599 Category: pic16 target Group: fixed Status: Closed Resolution: Fixed Priority: 5 Submitted By: ccsporters (tecodev) Assigned to: Vangelis Rokas (vrokas) Summary: Several bugs concerning the stack Initial Comment: PIC16's gen.c contains several bugs concerning values on the stack. (1) values are accessed via FSR2 The current implementation is off by one (FSR2 points to highest address available for local variables on the stack but offset 0 seems never to be used; instead we overwrite the first saved register...) fixed in aopForSym() and pic16_freeAsmop() (2) stack space for locals on the stack is allocated incorrectly In genFunction() fsr1h in decremented unless fsr0l has underflowed (Carry bit is set iff SUBWF returns a value >= 0). (3) result values in WREG aer overwritten In genEndFunction() functions using the stack for locals and returning a value via WREG the result value in WREG is overwritten by the MOVLW (sym->stack) instruction used to pop the locals from the stack. My fix is rather a workaround as it ignores functions not returning a value (producing unneccessary slow (but still correct) code. (4) addresses on symbols on the stack In genAddrOf() the addresses are calculated using ADDWF and a conditional INCF on FSR2. As FSR2 contains the largest address used for locals this has to be a conditional decrement on FSR2H. For "clarity" I changed it to SUBWF, conditional DECF. I also meddled in stdbool.h telling the system to use chars for booleans on the PIC16 port (as bits aer not yet too wel supported). A last change (rather cosmetic) has been applied to frexpf.c using the constant EXCESS instead of the literal value 0x7e for exponent calculations (this would impact no all ports so double check!). Although floating point still doesn't really work (sqrtf, sinf etc. still return rather random values) these fixes help on getting them done. Most bugs from above can be pinpointed by compiling sqrtf.c and frexpf.c from device/lib for pic16, so I do not attach another demo file. I do upload another implementation on sqrt using the "slow" fixpoint iteration, which actually works in the curent state of the port! Regards, Raphael Neider ---------------------------------------------------------------------- >Comment By: ccsporters (tecodev) Date: 2004-12-26 19:31 Message: Logged In: YES user_id=1115835 I have to correct my patch: in (1) and (4) we have to consider two cases: (a) arguments are refenreced via FSR2 + sym->stack with sym->stack >= 2 (this was broken by my patch) (b) local variable on the stack are accessed via FSR2+sym->stack+1 with sym->stack < 0 (sym->stack == 0 is never used thus I add 1) Fixed in aopForSym(), freeAsmOp() and genAddrOf(). genEndFunction() has another problem: on entry we save FSR2, create the local frame and save registers (in this order). On exit we first removed the local frame (thus throwing away saved registers), restored registers and FSR2. This lead to uncontrolled behaviour after function calls (as the caller variables were overwritten). Fixed in genEndFunction(). The attached patch is against the current CVS version! Regards, Raphael ---------------------------------------------------------------------- Comment By: ccsporters (tecodev) Date: 2004-12-17 08:09 Message: Logged In: YES user_id=1115835 Being a it, here's my device/lib/Makefile which (hopefully) builds the pic16.lib library containing nearly all functions from the standard SDCC lib! Yes, it works! Regards, Raphael Neider ---------------------------------------------------------------------- Comment By: ccsporters (tecodev) Date: 2004-12-17 08:07 Message: Logged In: YES user_id=1115835 float.c proposes the slow but working iterative sqrt calculation. Compile with -DIN_VALUE=xxx and link against the neccessary .rel files from device/lib/build/pic16 (after having build them, which requires modifications to device/lib/Makefile). ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=100599&aid=1086921&group_id=599 |