|
楼主 |
发表于 2010-8-5 11:37:18
|
显示全部楼层
RENMA请看下10L
这里再附上汇编对比
===========================
优化前
6433 ; 98 void CRC16_Update(u8 data)
6433 ; 99 {
6435 .text: section .text,new
6436 0000 _CRC16_Update:
6438 00000000 OFST: set 0
6441 ; 101 tmp = (u8)(crc>>8);
6443 0000 450100 mov L7064_tmp,_CRC16
6444 0003 88 push a
6445 ; 102 tmp ^= data;
6447 0004 b800 xor a,L7064_tmp
6448 ; 103 tmp >>= 4;
6450 0006 4e swap a
6451 0007 a40f and a,#15
6452 0009 b700 ld L7064_tmp,a
6453 ; 104 crc <<= 4;
6455 000b a604 ld a,#4
6456 000d L6:
6457 000d 3802 sll _CRC16+1
6458 000f 3901 rlc _CRC16
6459 0011 4a dec a
6460 0012 26f9 jrne L6
6461 ; 105 crc ^= table[tmp];
6463 0014 b600 ld a,L7064_tmp
6464 0016 5f clrw x
6465 0017 97 ld xl,a
6466 0018 58 sllw x
6467 0019 de0000 ldw x,(L5064_table,x)
6468 001c 01 rrwa x,a
6469 001d b802 xor a,_CRC16+1
6470 001f 01 rrwa x,a
6471 0020 b801 xor a,_CRC16
6472 0022 01 rrwa x,a
6473 0023 bf01 ldw _CRC16,x
6474 ; 107 tmp = (u8)(crc>>8);
6476 0025 b601 ld a,_CRC16
6477 ; 108 tmp >>=4;
6479 0027 4e swap a
6480 ; 109 tmp ^= data;
6482 0028 1801 xor a,(OFST+1,sp)
6483 ; 110 tmp &= 0x0f;
6485 002a a40f and a,#15
6486 002c b700 ld L7064_tmp,a
6487 ; 111 crc <<= 4;
6489 002e a604 ld a,#4
6490 0030 L01:
6491 0030 3802 sll _CRC16+1
6492 0032 3901 rlc _CRC16
6493 0034 4a dec a
6494 0035 26f9 jrne L01
6495 ; 112 crc ^= table[tmp];
6497 0037 b600 ld a,L7064_tmp
6498 0039 5f clrw x
6499 003a 97 ld xl,a
6500 003b 58 sllw x
6501 003c de0000 ldw x,(L5064_table,x)
6502 003f 01 rrwa x,a
6503 0040 b802 xor a,_CRC16+1
6504 0042 01 rrwa x,a
6505 0043 b801 xor a,_CRC16
6506 0045 01 rrwa x,a
6507 0046 bf01 ldw _CRC16,x
6508 ; 113 }
6511 0048 84 pop a
6512 0049 81 ret
===========================
优化后
6462 ; 105 void CRC16_Update(u8 data)
6462 ; 106 {
6464 .text: section .text,new
6465 0000 _CRC16_Update:
6469 ; 108 tmp2 = (u8)(data^H8BIT(crc));
6471 0000 b802 xor a,_CRC16
6472 0002 b700 ld L3164_tmp2,a
6473 ; 109 tmp1 = (u8)(tmp2>>4);
6475 0004 4e swap a
6476 0005 a40f and a,#15
6477 0007 b701 ld L1164_tmp1,a
6478 ; 110 tmp2^= tmp1;
6480 0009 b800 xor a,L3164_tmp2
6481 ; 111 tmp2&= 0x0f;
6483 000b a40f and a,#15
6484 000d b700 ld L3164_tmp2,a
6485 ; 113 PTR_BYTE(crc)[BYTE_H] = (u8)(table1_H(tmp1)^table2_H[tmp2]^L8BIT(crc));
6487 000f 5f clrw x
6488 0010 97 ld xl,a
6489 0011 b601 ld a,L1164_tmp1
6490 0013 48 sll a
6491 0014 d80000 xor a,(L5064_table2_H,x)
6492 0017 b803 xor a,_CRC16+1
6493 0019 b702 ld _CRC16,a
6494 ; 114 PTR_BYTE(crc)[BYTE_L] = (u8)(table1_L(tmp1)^table2_L[tmp2]);
6496 001b 5f clrw x
6497 001c b600 ld a,L3164_tmp2
6498 001e 97 ld xl,a
6499 001f b601 ld a,L1164_tmp1
6500 0021 4e swap a
6501 0022 a4f0 and a,#240
6502 0024 d80010 xor a,(L7064_table2_L,x)
6503 0027 b703 ld _CRC16+1,a
6504 ; 115 }
6507 0029 81 ret |
|