/*1* linux/arch/unicore32/lib/findbit.S2*3* Code specific to PKUnity SoC and UniCore ISA4*5* Copyright (C) 2001-2010 GUAN Xue-tao6*7* This program is free software; you can redistribute it and/or modify8* it under the terms of the GNU General Public License version 2 as9* published by the Free Software Foundation.10*/11#include <linux/linkage.h>12#include <asm/assembler.h>13.text1415/*16* Purpose : Find a 'zero' bit17* Prototype: int find_first_zero_bit(void *addr, unsigned int maxbit);18*/19__uc32_find_first_zero_bit:20cxor.a r1, #021beq 3f22mov r2, #0231: ldb r3, [r0+], r2 >> #324xor.a r3, r3, #0xff @ invert bits25bne .L_found @ any now set - found zero bit26add r2, r2, #8 @ next bit pointer272: csub.a r2, r1 @ any more?28bub 1b293: mov r0, r1 @ no free bits30mov pc, lr3132/*33* Purpose : Find next 'zero' bit34* Prototype: int find_next_zero_bit35* (void *addr, unsigned int maxbit, int offset)36*/37ENTRY(__uc32_find_next_zero_bit)38cxor.a r1, #039beq 3b40and.a ip, r2, #741beq 1b @ If new byte, goto old routine42ldb r3, [r0+], r2 >> #343xor r3, r3, #0xff @ now looking for a 1 bit44mov.a r3, r3 >> ip @ shift off unused bits45bne .L_found46or r2, r2, #7 @ if zero, then no bits here47add r2, r2, #1 @ align bit pointer48b 2b @ loop for next bit49ENDPROC(__uc32_find_next_zero_bit)5051/*52* Purpose : Find a 'one' bit53* Prototype: int find_first_bit54* (const unsigned long *addr, unsigned int maxbit);55*/56__uc32_find_first_bit:57cxor.a r1, #058beq 3f59mov r2, #0601: ldb r3, [r0+], r2 >> #361mov.a r3, r362bne .L_found @ any now set - found zero bit63add r2, r2, #8 @ next bit pointer642: csub.a r2, r1 @ any more?65bub 1b663: mov r0, r1 @ no free bits67mov pc, lr6869/*70* Purpose : Find next 'one' bit71* Prototype: int find_next_zero_bit72* (void *addr, unsigned int maxbit, int offset)73*/74ENTRY(__uc32_find_next_bit)75cxor.a r1, #076beq 3b77and.a ip, r2, #778beq 1b @ If new byte, goto old routine79ldb r3, [r0+], r2 >> #380mov.a r3, r3 >> ip @ shift off unused bits81bne .L_found82or r2, r2, #7 @ if zero, then no bits here83add r2, r2, #1 @ align bit pointer84b 2b @ loop for next bit85ENDPROC(__uc32_find_next_bit)8687/*88* One or more bits in the LSB of r3 are assumed to be set.89*/90.L_found:91rsub r1, r3, #092and r3, r3, r193cntlz r3, r394rsub r3, r3, #3195add r0, r2, r396mov pc, lr979899100