SFBMath.h
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef SFBMATH_H
00024 #define SFBMATH_H
00025
00026 #include "SFBTypes.h"
00027
00028 #ifdef __cplusplus
00029 extern "C" {
00030 #endif
00031
00032 #if defined(HOST_MODE) || defined(__thumb__)
00033
00037 #define COUNT_LEADING_ZEROS(u32InputVal, u32OutputCount) \
00038 do { \
00039 (u32InputVal) |= (u32InputVal)>>1; \
00040 (u32InputVal) |= (u32InputVal)>>2; \
00041 (u32InputVal) |= (u32InputVal)>>2; \
00042 (u32InputVal) |= (u32InputVal)>>4; \
00043 (u32InputVal) |= (u32InputVal)>>8; \
00044 (u32InputVal) |= (u32InputVal)>>16; \
00045 (u32OutputCount) = 32-countOnes(u32InputVal); \
00046 } while (0)
00047
00048 #else
00049
00054 #define COUNT_LEADING_ZEROS(u32InputVal, u32OutputCount) \
00055 \
00056 __asm__ __volatile__ ("movs %[count],%[val],lsr #16\n\t" \
00057 "mov %[count],#0\n\t" \
00058 "addeq %[count],%[count],#16\n\t" \
00059 "moveqs %[val],%[val],lsl #16\n\t" \
00060 "addeq %[count],%[count],#1\n\t" \
00061 "tst %[val],#0xff000000\n\t" \
00062 "addeq %[count],%[count],#8\n\t" \
00063 "moveq %[val],%[val],lsl #8\n\t" \
00064 "tst %[val],#0xf0000000\n\t" \
00065 "addeq %[count],%[count],#4\n\t" \
00066 "moveq %[val],%[val],lsl #4\n\t" \
00067 "tst %[val],#0xc0000000\n\t" \
00068 "addeq %[count],%[count],#2\n\t" \
00069 "moveq %[val],%[val],lsl #2\n\t" \
00070 "tst %[val],#0x80000000\n\t" \
00071 "addeq %[count],%[count],#1" \
00072 : [count] "=r" (u32OutputCount), \
00073 [val] "+r" (u32InputVal) \
00074 : )
00075 #endif
00076
00077 extern int countLeadingZeros(u32 x) ;
00078
00079 extern int countOnes(u32 x) ;
00080
00081 extern int countTrailingZeros(int x) ;
00082
00083 #ifdef __cplusplus
00084 }
00085 #endif
00086
00087
00088 #endif
00089