update datalab

This commit is contained in:
18218461270@163.com 2025-07-31 21:58:10 +08:00
parent ee78c07528
commit 94c87bf33c

View File

@ -174,11 +174,11 @@ int isTmax(int x) {
* Rating: 2 * Rating: 2
*/ */
int allOddBits(int x) { int allOddBits(int x) {
x = x & (x >> 16); x &= x >> 16;
x = x & (x >> 8); x &= x >> 8;
x = x & (x >> 4); x &= x >> 4;
x = x & (x >> 2); x &= x >> 2;
return (x >> 1) & 0x01; return (x >> 1) & 1;
} }
/* /*
* negate - return -x * negate - return -x
@ -201,7 +201,7 @@ int negate(int x) {
* Rating: 3 * Rating: 3
*/ */
int isAsciiDigit(int x) { int isAsciiDigit(int x) {
x = x ^ 0x30; x ^= 0x30;
return (!(x >> 4)) & ((~x >> 3) | ((~x >> 2) & (~x >> 1))); return (!(x >> 4)) & ((~x >> 3) | ((~x >> 2) & (~x >> 1)));
} }
/* /*
@ -212,8 +212,8 @@ int isAsciiDigit(int x) {
* Rating: 3 * Rating: 3
*/ */
int conditional(int x, int y, int z) { int conditional(int x, int y, int z) {
x = !x - 1; x = ~!x + 1;
return (x & y) | (~x & z); return (~x & y) | (x & z);
} }
/* /*
* isLessOrEqual - if x <= y then return 1, else return 0 * isLessOrEqual - if x <= y then return 1, else return 0
@ -237,11 +237,11 @@ int isLessOrEqual(int x, int y) {
* Rating: 4 * Rating: 4
*/ */
int logicalNeg(int x) { int logicalNeg(int x) {
x = x | (x >> 16); x |= x >> 16;
x = x | (x >> 8); x |= x >> 8;
x = x | (x >> 4); x |= x >> 4;
x = x | (x >> 2); x |= x >> 2;
x = x | (x >> 1); x |= x >> 1;
return ~x & 1; return ~x & 1;
} }
/* howManyBits - return the minimum number of bits required to represent x in /* howManyBits - return the minimum number of bits required to represent x in
@ -258,23 +258,23 @@ int logicalNeg(int x) {
*/ */
int howManyBits(int x) { int howManyBits(int x) {
int cnt = 1, a; int cnt = 1, a;
x = x ^ (x >> 31); x ^= x >> 31;
a = !!(x >> 16) << 4; a = !!(x >> 16) << 4;
x = x >> a; x >>= a;
cnt = cnt + a; cnt += a;
a = !!(x >> 8) << 3; a = !!(x >> 8) << 3;
x = x >> a; x >>= a;
cnt = cnt + a; cnt += a;
a = !!(x >> 4) << 2; a = !!(x >> 4) << 2;
x = x >> a; x >>= a;
cnt = cnt + a; cnt += a;
a = !!(x >> 2) << 1; a = !!(x >> 2) << 1;
x = x >> a; x >>= a;
cnt = cnt + a; cnt += a;
return cnt + !!x + !!(x >> 1); return cnt + !!x + !!(x >> 1);
} }
@ -293,22 +293,22 @@ int howManyBits(int x) {
unsigned floatScale2(unsigned uf) { unsigned floatScale2(unsigned uf) {
unsigned s = uf & 0x80000000, f = uf & 0x007FFFFF, e = (uf >> 23) & 0xFF; unsigned s = uf & 0x80000000, f = uf & 0x007FFFFF, e = (uf >> 23) & 0xFF;
if (e == 0xFFU) { if (e == 0xFF) {
return uf; return uf;
} }
if (e == 0U) { if (e == 0) {
if (f == 0U) { if (f == 0) {
return uf; return uf;
} else { } else {
e = (f >= 0x00400000U); e = f >= 0x00400000;
f = (f << 1) & 0x007FFFFFU; f = (f << 1) & 0x007FFFFF;
return s | (e << 23) | f; return s | (e << 23) | f;
} }
} }
e = e + 1; e++;
if (e == 0xFFU) { if (e == 0xFF) {
f = 0; f = 0;
} }
return s | (e << 23) | f; return s | (e << 23) | f;
@ -328,11 +328,11 @@ unsigned floatScale2(unsigned uf) {
int floatFloat2Int(unsigned uf) { int floatFloat2Int(unsigned uf) {
unsigned s = uf & 0x80000000, f = uf & 0x007FFFFF, e = (uf >> 23) & 0xFF; unsigned s = uf & 0x80000000, f = uf & 0x007FFFFF, e = (uf >> 23) & 0xFF;
if (e == 0xFFU) { if (e == 0xFF) {
return 0x80000000U; return 0x80000000;
} }
if (e == 0U) { if (e == 0) {
return 0; return 0;
} else { } else {
int E = e - 127; int E = e - 127;
@ -340,15 +340,15 @@ int floatFloat2Int(unsigned uf) {
if (E <= -1) { if (E <= -1) {
return 0; return 0;
} else if (E <= 30) { } else if (E <= 30) {
f = (f | 0x00800000); f |= 0x00800000;
if (E >= 23) { if (E >= 23) {
f = f << (E - 23); f <<= E - 23;
} else { } else {
f = f >> (23 - E); f >>= 23 - E;
} }
return s ? -f : f; return s ? -f : f;
} else { } else {
return 0x80000000U; return 0x80000000;
} }
} }
} }
@ -367,12 +367,12 @@ int floatFloat2Int(unsigned uf) {
*/ */
unsigned floatPower2(int x) { unsigned floatPower2(int x) {
if (x < -149) { if (x < -149) {
return 0U; return 0;
} else if (x <= -127) { } else if (x <= -127) {
return 1U << (x + 149); return 1 << (x + 149);
} else if (x <= 127) { } else if (x <= 127) {
return (x + 127) << 23; return (x + 127) << 23;
} else { } else {
return 0x7F800000U; return 0x7F800000;
} }
} }