No exact or substring matches. trying for part
PICList
Thread
'[PICLIST] [PIC] F871 compilers? (thanks for PICLIT'
2000\06\17@143051
by
Marc
|
> 2) Regarding shifting of longs, I couldn't find a problem. The compiler
> generates
> 32 ;x.c: 10: c <<= 8;
> 33 03EC 0811 movf ?a_main+4,w
> 34 03ED 0092 movwf ?a_main+5
> 35 03EE 0810 movf ?a_main+3,w
> 36 03EF 0091 movwf ?a_main+4
> 37 03F0 080F movf ?a_main+2,w
> 38 03F1 0090 movwf ?a_main+3
> 39 03F2 018F clrf ?a_main+2
>
> which looks pretty good to me.
I have digged out the code snippet that caused the problems to me. It was
meant to save codespace for frequent 4-byte transfers on an SPI like bitbang
interface.
ulong ispRotate32(ulong txdata) { // send & receive 32 bits
ulong rxdata;
rxdata = ((ulong)ispRotate8((uchar)(txdata>>24)))<<24;
rxdata |= ((ulong)ispRotate8((uchar)(txdata>>16)))<<16;
rxdata |= ((ulong)ispRotate8((uchar)(txdata>> 8)))<< 8;
rxdata |= ((ulong)ispRotate8((uchar)(txdata>> 0)))<< 0;
return rxdata;
}
This is what PICLITE made with it:
461 psect text5
462 022C _ispRotate32
463 ; _rxdata assigned to ?a_ispRotate32+0
464 0000 _ispRotate32$rxdata set ?a_ispRotate32
465 ;n:\work\xxxxxxx\source\pic\isp.c: 253: ulong rx
+ data;
466 022C 0825 movf ?_ispRotate32,w
467 022D 1283 bcf 3,5
468 022E 00B6 movwf btemp
469 022F 0826 movf ?_ispRotate32+1,w
470 0230 00B7 movwf btemp+1
471 0231 0827 movf ?_ispRotate32+2,w
472 0232 00B8 movwf btemp+2
473 0233 0828 movf ?_ispRotate32+3,w
474 0234 00B9 movwf btemp+3
475 0235 3018 movlw 24
476 0236 211B fcall llslr
477 0237 0836 movf btemp,w
478 0238 1283 bcf 3,5
479 0239 217D fcall _ispRotate8
480 023A 00B6 movwf btemp
481 023B 01B7 clrf btemp+1
482 023C 01B8 clrf btemp+2
483 023D 01B9 clrf btemp+3
484 023E 3018 movlw 24
485 023F 2126 fcall llsll
486 0240 0836 movf btemp,w
487 0241 00A5 movwf ?a_ispRotate32
488 0242 0837 movf btemp+1,w
489 0243 00A6 movwf ?a_ispRotate32+1
490 0244 0838 movf btemp+2,w
491 0245 00A7 movwf ?a_ispRotate32+2
492 0246 0839 movf btemp+3,w
493 0247 00A8 movwf ?a_ispRotate32+3
494 ;n:\work\xxxxxxx\source\pic\isp.c: 256: rxdata |
+ = ((ulong)ispRotate8((uchar)(txdata>>16)))<<16;
495 0248 0827 movf ?_ispRotate32+2,w
496 0249 217D fcall _ispRotate8
497 024A 00B6 movwf btemp
HI-TECH Software PIC Macro Assembler Page 11
Sat Jun 17 19:38:33 2000
498 024B 01B7 clrf btemp+1
499 024C 01B8 clrf btemp+2
500 024D 01B9 clrf btemp+3
501 024E 3010 movlw 16
502 024F 2126 fcall llsll
503 0250 0836 movf btemp,w
504 0251 04A5 iorwf ?a_ispRotate32
505 0252 0837 movf btemp+1,w
506 0253 04A6 iorwf ?a_ispRotate32+1
507 0254 0838 movf btemp+2,w
508 0255 04A7 iorwf ?a_ispRotate32+2
509 0256 0839 movf btemp+3,w
510 0257 04A8 iorwf ?a_ispRotate32+3
511 ;n:\work\xxxxxxx\source\pic\isp.c: 257: rxdata |
+ = ((ulong)ispRotate8((uchar)(txdata>> 8)))<< 8;
512 0258 0826 movf ?_ispRotate32+1,w
513 0259 217D fcall _ispRotate8
514 025A 00B6 movwf btemp
515 025B 01B7 clrf btemp+1
516 025C 01B8 clrf btemp+2
517 025D 01B9 clrf btemp+3
518 025E 3008 movlw 8
519 025F 2126 fcall llsll
520 0260 0836 movf btemp,w
521 0261 04A5 iorwf ?a_ispRotate32
522 0262 0837 movf btemp+1,w
523 0263 04A6 iorwf ?a_ispRotate32+1
524 0264 0838 movf btemp+2,w
525 0265 04A7 iorwf ?a_ispRotate32+2
526 0266 0839 movf btemp+3,w
527 0267 04A8 iorwf ?a_ispRotate32+3
528 ;n:\work\xxxxxxx\source\pic\isp.c: 258: rxdata |
+ = ((ulong)ispRotate8((uchar)(txdata>> 0)))<< 0;
529 0268 0825 movf ?_ispRotate32,w
530 0269 217D fcall _ispRotate8
531 026A 00B6 movwf btemp
532 026B 01B7 clrf btemp+1
533 026C 01B8 clrf btemp+2
534 026D 01B9 clrf btemp+3
535 026E 04A5 iorwf ?a_ispRotate32
536 026F 0837 movf btemp+1,w
537 0270 04A6 iorwf ?a_ispRotate32+1
538 0271 0838 movf btemp+2,w
539 0272 04A7 iorwf ?a_ispRotate32+2
540 0273 0839 movf btemp+3,w
541 0274 04A8 iorwf ?a_ispRotate32+3
542 ;n:\work\xxxxxxx\source\pic\isp.c: 260: return r
+ xdata;
543 0275 0825 movf ?a_ispRotate32,w
544 0276 00B6 movwf btemp
545 0277 0826 movf ?a_ispRotate32+1,w
546 0278 00B7 movwf btemp+1
547 0279 0827 movf ?a_ispRotate32+2,w
548 027A 00B8 movwf btemp+2
549 027B 0828 movf ?a_ispRotate32+3,w
550 027C 00B9 movwf btemp+3
551 027D 0008 return
What I expected to see instead (having used IAR-C for AVR previously) was that
the the code just grabs the appropriate byte of "txdata", does the call, and
then stores the result in the approriate byte of "rxdata" (possibly
unnecessarily clearing the other 3 bytes on the first access).
Don't get me wrong, I am very satisfied with PICLITE, especially under the
fact that it is free!! It took me less than 5 minutes to avoid the "offending"
ispRotate32() function and save the code words used by it and the llsll() etc
link library.
Thanks for giving PICLITE away free!!!
PS: Just for the sake of it I ran the same C code through IAR-C for AVR, and
this is what it did:
990 ulong ispRotate32(ulong txdata) { // send & receive 32 bits
\ ispRotate32:
\ 000009FC ........ CALL ?PROLOGUE8_L09
\ 00000A00 402E MOV R4,R16
\ 00000A02 512E MOV R5,R17
\ 00000A04 622E MOV R6,R18
991 ulong rxdata;
992
993 rxdata = ((ulong)ispRotate8((uchar)(txdata>>24)))<<24;
\ 00000A06 032F MOV R16,R19
\ 00000A08 F5DF RCALL ispRotate8
\ 00000A0A B02F MOV R27,R16
994 rxdata |= ((ulong)ispRotate8((uchar)(txdata>>16)))<<16;
\ 00000A0C 062D MOV R16,R6
\ 00000A0E F2DF RCALL ispRotate8
\ 00000A10 A02F MOV R26,R16
995 rxdata |= ((ulong)ispRotate8((uchar)(txdata>> 8)))<< 8;
\ 00000A12 052D MOV R16,R5
\ 00000A14 EFDF RCALL ispRotate8
\ 00000A16 902F MOV R25,R16
996 rxdata |= ((ulong)ispRotate8((uchar)(txdata>> 0)))<< 0;
\ 00000A18 042D MOV R16,R4
\ 00000A1A ECDF RCALL ispRotate8
997
998 return rxdata;
\ 00000A1C 192F MOV R17,R25
\ 00000A1E 2A2F MOV R18,R26
\ 00000A20 3B2F MOV R19,R27
999 }
\ 00000A22 E8E0 LDI R30,8
\ 00000A24 ........ JMP ?EPILOGUE_B8_L09
\ ; rxdata R24-R27
\ ; txdata R4-R7
For non-AVR/IAR users: PROLOGUE and EPILOGUE are functions to push/pop register
contents to/from the stack, much like the movem.l instruction on 680x0. They
are used here to save the work registers at the function entry and restore them
at the exit.
2000\06\17@154108
by
Andrew Warren
|
Marc <spam_OUTPICLISTTakeThisOuT
MITVMA.MIT.EDU> wrote:
> ulong ispRotate32(ulong txdata) { // send & receive 32 bits
> ulong rxdata;
>
> rxdata = ((ulong)ispRotate8((uchar)(txdata>>24)))<<24;
> rxdata |= ((ulong)ispRotate8((uchar)(txdata>>16)))<<16;
> rxdata |= ((ulong)ispRotate8((uchar)(txdata>> 8)))<< 8;
> rxdata |= ((ulong)ispRotate8((uchar)(txdata>> 0)))<< 0;
>
> return rxdata;
> }
.... and noted that PICCLITE generated a lot of code for the
function.
Marc:
That compiler DOES support unions, doesn't it?
Wouldn't it be easier for you (and kinder to your compiler) to use
them, so you wouldn't need to go through those shifting and casting
gyrations on txdata?
I mean... Instead of needlessly forcing your one-byte-at-a-time
operations into the framework of 4-byte-wide variables, why not help
the compiler out by giving it a hint that it only needs to deal with
one byte at a time?
-Andy
=== Andrew Warren - .....fastfwdKILLspam
@spam@ix.netcom.com
=== Fast Forward Engineering - San Diego, California
=== http://www.geocities.com/SiliconValley/2499
2000\06\18@131531
by
Marc
> That compiler DOES support unions, doesn't it?
That's what I did then. And I dropped using a ulong subfunction for tx-only
messages (2/3 of all messages) in favor of doing 4 separate calls to the 8bit
tx function. That made it almost as efficient as writing it in assembler (but
much quicker to write than asm).
More... (looser matching)
- Last day of these posts
- In 2000
, 2001 only
- Today
- New search...