-
-
-
-
-
-
-
-
- #ifdef __cplusplus
- extern "C" {
- #endif
-
- #define RISC_SUX
-
- #ifdef RISC_SUX
- int bsr (unsigned long int input)
- {
- asm( "bsr %%eax,%%ebx\n"
- "jnz gimskipxorek1\n"
- "xor %%eax, %%eax\n"
- "dec %%eax\n"
- "gimskipxorek1:\n"
- :"=b"(input)
- :"a"(input));
- return input;
- }
-
- int bsf (unsigned long int input)
- {
- asm( "bsf %%eax,%%ebx\n"
- "jnz gimskipxorek2\n"
- "xor %%eax, %%eax\n"
- "dec %%eax\n"
- "gimskipxorek2:\n"
- :"=b"(input)
- :"a"(input));
- return input;
- }
-
- #else
-
-
-
-
- int bsr (unsigned long int input)
- {
- long int ret=0,v=input;
-
- if (v&0xffff0000)
- v>>=16, ret=16;
- v&=0xffff;
-
- if (v&0xff00)
- v>>=8, ret+=8;
- v&=0xff;
-
- if (v&0xf0)
- v>>=4, ret+=4;
- v&=0xf;
-
- if (v&0xc)
- v>>=2, ret+=2;
- v&=0x3;
- if (v&2)
- return ret+1;
- else if (v&1)
- return ret;
- else return 0xff;
- }
-
- int bsf (unsigned long int input)
- {
- long int ret=0,v=input;
-
- if (!(v&0xffff))
- v>>=16, ret=16;
- v&=0xffff;
-
- if (!(v&0xff))
- v>>=8, ret+=8;
- v&=0xff;
-
- if (!(v&0xf))
- v>>=4, ret+=4;
- v&=0xf;
-
- if (!(v&0x3))
- v>>=2, ret+=2;
- v&=0x3;
- if (v&1)
- return ret;
- else if (v&2)
- return ret+1;
- else return 0xff;
- }
- #endif
-
- #ifdef __cplusplus
- }
- #endif
This document should validate, please check by clicking: