摘要:1 #!/bin/sh 2 module="device-mapper"3 major=`sed -n -e "/$module\$/p" /proc/devices | awk '{print $1}'`4 echo $major
阅读全文
摘要:1 int isqrt(unsigned x) 2 { 3 unsigned m, y, b; 4 5 m = 0x40000000; 6 y = 0; 7 while(m != 0) 8 { 9 b = y | m; 10 y = y >> 1; 11 if(x >= b) 12 { 13 x = x - b; 14 y = y | m; 15 } 16 m = m >> 2; 17 } 18 return y; 19 }
阅读全文
摘要:对于两个寄存器x和y以及掩码m,当第i位的掩码m(i)=1时,交换x和y的第i位内容,而当第i位的掩码m(i)=0时,保留x和y的第i位内容不变x = x ^ y;y = y ^ (x & m);x = x ^ y;
阅读全文
摘要:写了大概一下午,本以为很easy的,写了才知道“边界+细节”,尤其“(ones >> 2) >> ntz”,如果写成了“ones>>(2+ntz)"就会报错,边界部分自己调了。关于bitcount部分,做了修改,基本只用一个大的常数,以及一些小的数字。 4 int bitcount(unsigned int n) 5 { 6 unsigned int tmp; 7 tmp = n & 0x33333333; 8 n = n - tmp; 9 n = (n >> 2) & 0x33333333; 10 tmp = tmp
阅读全文
摘要:3 int bit_pos(unsigned int n) 4 { 5 n = n & (-n); 6 n = n - 1; 7 n = n - ((n>>1)&0x77777777) - ((n>>2)&0x33333333)-((n>>3)&0x11111111); 8 n = (n + (n>>4))&0xf0f0f0f; 9 n = n + ((n >> 8)& 0xf) + ((n >> 16)& 0xf) + ((n >> 24)& 0
阅读全文
摘要:4 int clp2(unsigned int n) 5 { 6 --n; 7 n = n | (n >> 1); 8 n = n | (n >> 2); 9 n = n | (n >> 4); 10 n = n | (n >> 8); 11 n = n | (n >> 16); 12 return n + 1; 13 }unsigned flp2 (unsigned x){ x = x | (x >> 1) x = x | (x >> 2) x = x | (x >> 4); x = x | (x
阅读全文
摘要:4 int bitcount(unsigned int n) 5 { 6 n = n - ((n>>1)&033333333333) - ((n>>2)&011111111111); 7 n = (n + (n>>3))&030707070707; 8 n = n % 0x3f; 9 return n; 10 } 17 int bitcount(unsigned int n) 18 { 19 n = n - ((n>>1)&0x77777777) - ((n>>2)&0x33333333)-((
阅读全文