本文最后更新于 2025-11-16 22:14:46
首先声明datalab本人未完成,有4道题目没有做出来。本文博客记录下自己的解析,以便以后回忆。如果能帮助到你就更好了,如果觉得本文没啥技术含量,也望多多包涵。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246
|
int bitAnd(int x, int y) { return ~(~x | ~y); }
int getByte(int x, int n) { int offsetValue = 0xff; int offsetIndex = n << 3; int value = (x & (offsetValue << offsetIndex)) >> offsetIndex; return value & offsetValue; }
int logicalShift(int x, int n) { int offset = 0x1 << 31; int offsetValue = ~(offset >> n << 1); return (x >> n) & offsetValue; }
int bitCount(int x) { return 2; }
int bang(int x) { return 2; }
int tmin(void) { return (0x1 << 31); }
int fitsBits(int x, int n) { int offsetValue = 0x1 << n; int addValue = (offsetValue >> 1) & (~offsetValue); int value1 = x + addValue; int value2 = addValue + (~x); int maxValue = 0x1 << 31; return (n >> 5) | ((!(value1 & maxValue)) & (!(value2 & maxValue))); }
int divpwr2(int x, int n) { int maxValue = 0x1 << 31; int offsetValue = ~(0x1 << 31 >> (32 + ~n)); int andValue = offsetValue & x; return (x >> n) + ((!!(x & maxValue)) & (!!(andValue))); }
int negate(int x) { return ~x + 1; }
int isPositive(int x) { return (!(x >> 31)) ^ (!x); }
int isLessOrEqual(int x, int y) { int offsetValue = 0x1; int offsetIndex = 31; int offsetSign = offsetValue << offsetIndex; int signX = !(x & offsetSign); int signY = !(y & offsetSign); int value1 = ((!signX) & signY )^ 0x0; int value2 = (signX & (!signY)) ^ 0x1; int value3 = (!((y + ~x + 1) & offsetSign)) ^ 0x0; return value1 | (value2 & value3); }
int ilog2(int x) { return 2; }
unsigned float_neg(unsigned uf) { int offsetValue = 0x1; int offsetIndex = 0; int andValue = 0; int signValue; while (offsetIndex < 31) { signValue = (uf & offsetValue) >> offsetIndex; if (offsetIndex < 23) { andValue = andValue | signValue; } else { andValue = andValue & signValue; } offsetIndex += 1; offsetValue <<= 1; } if (andValue) { return uf; } return uf ^ offsetValue; }
unsigned float_i2f(int x) { return 2; }
unsigned float_twice(unsigned uf) { int signIndex = 31; int expIndex = 23; int offsetValue = 0x1; int offsetSign = offsetValue << signIndex; int andValue = 1; int orValue = 0; int signValue; int offsetIndex = expIndex; while (offsetIndex < signIndex) { signValue = (uf & (offsetValue << offsetIndex)) >> offsetIndex; andValue = andValue & signValue; orValue = orValue | signValue; offsetIndex += 1; } if (andValue == 1) { return uf; } else if (orValue == 0) { signValue = !!(uf & offsetSign); uf <<= 1; if (signValue == 0) { return uf & (~offsetSign); } return uf | offsetSign; } else { signValue = ((uf >> expIndex) + 1) << expIndex; offsetIndex = expIndex; while (offsetIndex < signIndex) { uf &= ~(offsetValue << offsetIndex); offsetIndex += 1; } return uf | signValue; } }
|

datalab笔记
https://njit-77.github.io/2018/09/21/datalab/