Some MIPS cores have an instruction to count leading zeros. This patch
allows MIPS variants and platforms to substitute their own methods to
compute bit indexes.
The attached file, mips_arch.patch, patches MIPS architecture files to
allow the HAL_LSBIT_INDEX and HAL_MSBIT_INDEX macros to be substituted
out. The current architecture macros will continue to be used if they
are not overridden.
The attached file, mips_mips32.patch, patches MIPS32 variant files to
override the HAL_LSBIT_INDEX and HAL_MSBIT_INDEX macros to use a more
efficient method to compute bit indexes.
Note: The MIPS64 variant, at least, should be patched in a similar
manner as the MIPS32 variant because it also has a 'CLZ' instruction.
--
+---------------------------------------------
| Daniel Helgason <[EMAIL PROTECTED]>
Index: packages/hal/mips/arch/current/include/hal_arch.h
===================================================================
RCS file: /cvs/ecos/ecos/packages/hal/mips/arch/current/include/hal_arch.h,v
retrieving revision 1.18
diff -r1.18 hal_arch.h
128a129,130
> #ifndef CYGHWR_HAL_BIT_INDEXES_DEFINED
>
135a138,139
> #endif
>
Index: packages/hal/mips/arch/current/src/hal_misc.c
===================================================================
RCS file: /cvs/ecos/ecos/packages/hal/mips/arch/current/src/hal_misc.c,v
retrieving revision 1.30
diff -r1.30 hal_misc.c
301a302,304
>
> #ifndef CYGHWR_HAL_BIT_INDEXES_DEFINED
>
347a351,353
> #endif
>
>
Index: packages/hal/mips/mips32/current/include/var_arch.h
===================================================================
RCS file: /cvs/ecos/ecos/packages/hal/mips/mips32/current/include/var_arch.h,v
retrieving revision 1.5
diff -r1.5 var_arch.h
88a89,125
> // Bit manipulation macros
>
> #ifndef CYGHWR_HAL_BIT_INDEXES_DEFINED
>
> //--------------------------------------------------------
> // Determine the index of the ls bit of the supplied mask.
>
> #define HAL_LSBIT_INDEX(_index_, _mask_) \
> CYG_MACRO_START \
> unsigned _reg_; \
> \
> _reg_ = (_mask_); \
> _reg_ &= -_reg_; \
> asm volatile ("clz %0, %1\n" \
> : "=r" (_reg_) \
> : "r" (_reg_) ); \
> (_index_) = 31 - _reg_; \
> CYG_MACRO_END
>
> //--------------------------------------------------------
> // Determine the index of the ms bit of the supplied mask.
>
> #define HAL_MSBIT_INDEX(_index_, _mask_) \
> CYG_MACRO_START \
> unsigned _reg_; \
> \
> _reg_ = (_mask_); \
> asm volatile ("clz %0, %1\n" \
> : "=r" (_reg_) \
> : "r" (_reg_) ); \
> (_index_) = 31 - _reg_; \
> CYG_MACRO_END
>
> #define CYGHWR_HAL_BIT_INDEXES_DEFINED
> #endif
>
> //--------------------------------------------------------------------------