; $Id$: ; used in the ZS with number of samples > 30 fit_search_lsb: ; input : r1 - search here for the lowest non-zero bit, will be destroyed ; rstack2 - return address (r10) ; ; output: r2 - the found position from 0 to 31, if more - r1 was 0 ; ; modifies internally: r5 sll 0, r1, r5 ; copy r1 to r5 & test if zero jmp cc_zero, _fit_search_not_found ; exit, nothing found sll 8, r1, r5 ; r5 = r1 << 8 = input << 8 jmp cc_zero, _fit_search_24 ; if the result is 0, the bits 0..23 were all 0, search from 24 to 31 ; otherwise continue to search from 0 to 23 sll 8, r5, r1 ; r1 = r5 << 8 = input << 16 jmp cc_zero, _fit_search_16 ; if the result is 0, the bits 0..15 were 0, search from 16 to 23 ; otherwise continut to search from 0 to 15 sll 8, r1, r5 ; r5 = r1 << 8 = input << 24 jmp cc_zero, _fit_search_8 ; if the result is 0, the bits 0..7 were 0, search from 8 to 15 mov 0, r2 ; start from 0 ; here we know, that the first non-zero bit is from 0 to 7 ; the input bits 7..0 are now in bits 31..24 of r5! _fit_search_0: sll 4, r5, r1 ; r1 = r5 << 4 = input << 28 jmp cc_zero, _fit_search_4 ; if the result is 0, the bits 0..3 were 0, search from 4 to 7 ; now search in 0 to 3 of input or in r1 - 28 to 31! _fit_search_0_3: sll 2, r1, r5 ; r5 = r1 << 2 = input << 30 jmp cc_zero, _fit_search_2 ; if the result is 0, the bits 0..1 were 0, search from 2 to 3 ; somewhere between 0 and 1 (in r5 31..30) ! _fit_search_0_1: sll 1, r5 jmp cc_nzero, rstack2 ; was bit 30 in r5, which is bit 0 in input, return, r2 unmodified add r2, 1, r2 ; add 1 to the result, as bit 31 was 1 (bit 1 in input) jmp cc_uncond, rstack2 ; exit ; finish!!! _fit_search_4: ; here we continue in the slice 4..7 of the input add r2, 4, r2 ; add 4 to the result mov r5, r1 ; take the former bits 31..28 again jmp cc_uncond, _fit_search_0_3 ; and continue to search in 31..28 (mapped to 0..3), but the offset of 4 is already stored in the result r2 _fit_search_2: ; 30..31 in r1, 2..3 in input add r2, 2, r2 sll 1, r1 jmp cc_nzero, rstack2 ; exit, it was bit 30 = 1 add r2, 1, r2 ; add 1 to the result jmp cc_nzero, rstack2 ; and exit, it was bit 31 = 1 ; finish!!! _fit_search_8: ; here r1 = input << 16, the result is in bits 8..15 of the input mov 8, r2 mov r1, r5 jmp cc_uncond, _fit_search_0 _fit_search_16: mov 16, r2 jmp cc_uncond, _fit_search_0 _fit_search_24: mov 24, r2 mov r1, r5 jmp cc_uncond, _fit_search_0 _fit_search_not_found: mov 32, r2 jmp cc_uncond, rstack2