Path: blob/master/arch/cris/arch-v10/lib/checksum.S
15126 views
/*1* A fast checksum routine using movem2* Copyright (c) 1998-2001 Axis Communications AB3*4* csum_partial(const unsigned char * buff, int len, unsigned int sum)5*/67.globl csum_partial8csum_partial:910;; r10 - src11;; r11 - length12;; r12 - checksum1314;; check for breakeven length between movem and normal word looping versions15;; we also do _NOT_ want to compute a checksum over more than the16;; actual length when length < 401718cmpu.w 80,$r1119blo _word_loop20nop2122;; need to save the registers we use below in the movem loop23;; this overhead is why we have a check above for breakeven length24;; only r0 - r8 have to be saved, the other ones are clobber-able25;; according to the ABI2627subq 9*4,$sp28movem $r8,[$sp]2930;; do a movem checksum3132subq 10*4,$r11 ; update length for the first loop3334_mloop: movem [$r10+],$r9 ; read 10 longwords3536;; perform dword checksumming on the 10 longwords3738add.d $r0,$r1239ax40add.d $r1,$r1241ax42add.d $r2,$r1243ax44add.d $r3,$r1245ax46add.d $r4,$r1247ax48add.d $r5,$r1249ax50add.d $r6,$r1251ax52add.d $r7,$r1253ax54add.d $r8,$r1255ax56add.d $r9,$r125758;; fold the carry into the checksum, to avoid having to loop the carry59;; back into the top6061ax62addq 0,$r126364subq 10*4,$r1165bge _mloop66nop6768addq 10*4,$r11 ; compensate for last loop underflowing length6970movem [$sp+],$r8 ; restore regs7172_word_loop:73;; only fold if there is anything to fold.7475cmpq 0,$r1276beq _no_fold7778;; fold 32-bit checksum into a 16-bit checksum, to avoid carries below.79;; r9 and r13 can be used as temporaries.8081moveq -1,$r9 ; put 0xffff in r9, faster than move.d 0xffff,r982lsrq 16,$r98384move.d $r12,$r1385lsrq 16,$r13 ; r13 = checksum >> 1686and.d $r9,$r12 ; checksum = checksum & 0xffff87add.d $r13,$r12 ; checksum += r138889_no_fold:90cmpq 2,$r1191blt _no_words92nop9394;; checksum the rest of the words9596subq 2,$r119798_wloop: subq 2,$r1199bge _wloop100addu.w [$r10+],$r12101102addq 2,$r11103104_no_words:105;; see if we have one odd byte more106cmpq 1,$r11107beq _do_byte108nop109ret110move.d $r12, $r10111112_do_byte:113;; copy and checksum the last byte114addu.b [$r10],$r12115ret116move.d $r12, $r10117118119120