|
| 1 | +@bit(x: int): int { |
| 2 | + two: int = const 2; |
| 3 | + div2: int = div x two; |
| 4 | + mul2: int = mul div2 two; |
| 5 | + bit: int = sub x mul2; |
| 6 | + ret bit; |
| 7 | +} |
| 8 | +@bitand(a: int, b: int): int { |
| 9 | + zero: int = const 0; |
| 10 | + one: int = const 1; |
| 11 | + two: int = const 2; |
| 12 | + result: int = const 0; |
| 13 | + pow: int = const 1; |
| 14 | +.loop.cond: |
| 15 | + acond: bool = gt a zero; |
| 16 | + bcond: bool = gt b zero; |
| 17 | + cond: bool = or acond bcond; |
| 18 | + br cond .loop.body .loop.end; |
| 19 | +.loop.body: |
| 20 | + abit: int = call @bit a; |
| 21 | + bbit: int = call @bit b; |
| 22 | + abit1: bool = eq abit one; |
| 23 | + bbit1: bool = eq bbit one; |
| 24 | + rbitb: bool = and abit1 bbit1; |
| 25 | + rbit: int = const 0; |
| 26 | + br rbitb .setone .skip; |
| 27 | +.setone: |
| 28 | + rbit: int = const 1; |
| 29 | +.skip: |
| 30 | + term: int = mul rbit pow; |
| 31 | + result: int = add result term; |
| 32 | + a: int = div a two; |
| 33 | + b: int = div b two; |
| 34 | + pow: int = mul pow two; |
| 35 | + jmp .loop.cond; |
| 36 | +.loop.end: |
| 37 | + ret result; |
| 38 | +} |
| 39 | +@bitor(a: int, b: int): int { |
| 40 | + zero: int = const 0; |
| 41 | + one: int = const 1; |
| 42 | + two: int = const 2; |
| 43 | + result: int = const 0; |
| 44 | + pow: int = const 1; |
| 45 | +.loop.cond.or: |
| 46 | + acond: bool = gt a zero; |
| 47 | + bcond: bool = gt b zero; |
| 48 | + cond: bool = or acond bcond; |
| 49 | + br cond .loop.body.or .loop.end.or; |
| 50 | +.loop.body.or: |
| 51 | + abit: int = call @bit a; |
| 52 | + bbit: int = call @bit b; |
| 53 | + abit1: bool = eq abit one; |
| 54 | + bbit1: bool = eq bbit one; |
| 55 | + rbitb: bool = or abit1 bbit1; |
| 56 | + rbit: int = const 0; |
| 57 | + br rbitb .setone.or .skip.or; |
| 58 | +.setone.or: |
| 59 | + rbit: int = const 1; |
| 60 | +.skip.or: |
| 61 | + term: int = mul rbit pow; |
| 62 | + result: int = add result term; |
| 63 | + a: int = div a two; |
| 64 | + b: int = div b two; |
| 65 | + pow: int = mul pow two; |
| 66 | + jmp .loop.cond.or; |
| 67 | +.loop.end.or: |
| 68 | + ret result; |
| 69 | +} |
| 70 | +@bitxor(a: int, b: int): int { |
| 71 | + zero: int = const 0; |
| 72 | + one: int = const 1; |
| 73 | + two: int = const 2; |
| 74 | + result: int = const 0; |
| 75 | + pow: int = const 1; |
| 76 | +.loop.cond.xor: |
| 77 | + acond: bool = gt a zero; |
| 78 | + bcond: bool = gt b zero; |
| 79 | + cond: bool = or acond bcond; |
| 80 | + br cond .loop.body.xor .loop.end.xor; |
| 81 | +.loop.body.xor: |
| 82 | + abit: int = call @bit a; |
| 83 | + bbit: int = call @bit b; |
| 84 | + abit1: bool = eq abit one; |
| 85 | + bbit1: bool = eq bbit one; |
| 86 | + nb: bool = not bbit1; |
| 87 | + na: bool = not abit1; |
| 88 | + t1: bool = and abit1 nb; |
| 89 | + t2: bool = and na bbit1; |
| 90 | + rbitb: bool = or t1 t2; |
| 91 | + rbit: int = const 0; |
| 92 | + br rbitb .setone.xor .skip.xor; |
| 93 | +.setone.xor: |
| 94 | + rbit: int = const 1; |
| 95 | +.skip.xor: |
| 96 | + term: int = mul rbit pow; |
| 97 | + result: int = add result term; |
| 98 | + a: int = div a two; |
| 99 | + b: int = div b two; |
| 100 | + pow: int = mul pow two; |
| 101 | + jmp .loop.cond.xor; |
| 102 | +.loop.end.xor: |
| 103 | + ret result; |
| 104 | +} |
| 105 | +@ashr(x: int, n: int): int { |
| 106 | + zero: int = const 0; |
| 107 | + one: int = const 1; |
| 108 | + two: int = const 2; |
| 109 | +.loop.cond.shr: |
| 110 | + npos: bool = gt n zero; |
| 111 | + br npos .loop.body.shr .loop.end.shr; |
| 112 | +.loop.body.shr: |
| 113 | + q: int = div x two; |
| 114 | + q2: int = mul q two; |
| 115 | + r: int = sub x q2; |
| 116 | + neg: bool = lt x zero; |
| 117 | + rzero: bool = eq r zero; |
| 118 | + odd: bool = not rzero; |
| 119 | + fix: bool = and neg odd; |
| 120 | + br fix .adjust .no_adjust; |
| 121 | +.adjust: |
| 122 | + q: int = sub q one; |
| 123 | + jmp .after; |
| 124 | +.no_adjust: |
| 125 | + jmp .after; |
| 126 | +.after: |
| 127 | + x: int = id q; |
| 128 | + n: int = sub n one; |
| 129 | + jmp .loop.cond.shr; |
| 130 | +.loop.end.shr: |
| 131 | + ret x; |
| 132 | +} |
| 133 | +@L.ack.1(m.1: any, n.2: any): any { |
| 134 | + tmp.25: any = const 0; |
| 135 | + tmp.26: any = call @L.eq.p.2 m.1 tmp.25; |
| 136 | + tmp.19: any = id tmp.26; |
| 137 | + tmp.28: any = const 6; |
| 138 | + tmp.27: any = eq tmp.19 tmp.28; |
| 139 | + tmp.29: any = not tmp.27; |
| 140 | + br tmp.29 .L.then.5 .L.else.6; |
| 141 | +.L.then.5: |
| 142 | + tmp.30: any = const 8; |
| 143 | + tmp.31: any = call @L.+.3 n.2 tmp.30; |
| 144 | + ret tmp.31; |
| 145 | +.L.else.6: |
| 146 | + tmp.32: any = const 0; |
| 147 | + tmp.33: any = call @L.eq.p.2 n.2 tmp.32; |
| 148 | + tmp.20: any = id tmp.33; |
| 149 | + tmp.35: any = const 6; |
| 150 | + tmp.34: any = eq tmp.20 tmp.35; |
| 151 | + tmp.36: any = not tmp.34; |
| 152 | + br tmp.36 .L.then.7 .L.else.8; |
| 153 | +.L.then.7: |
| 154 | + tmp.37: any = const 8; |
| 155 | + tmp.38: any = call @L._.4 m.1 tmp.37; |
| 156 | + tmp.21: any = id tmp.38; |
| 157 | + tmp.39: any = const 8; |
| 158 | + tmp.40: any = call @L.ack.1 tmp.21 tmp.39; |
| 159 | + ret tmp.40; |
| 160 | +.L.else.8: |
| 161 | + tmp.41: any = const 8; |
| 162 | + tmp.42: any = call @L._.4 m.1 tmp.41; |
| 163 | + tmp.22: any = id tmp.42; |
| 164 | + tmp.43: any = const 8; |
| 165 | + tmp.44: any = call @L._.4 n.2 tmp.43; |
| 166 | + tmp.24: any = id tmp.44; |
| 167 | + tmp.45: any = call @L.ack.1 m.1 tmp.24; |
| 168 | + tmp.23: any = id tmp.45; |
| 169 | + tmp.46: any = call @L.ack.1 tmp.22 tmp.23; |
| 170 | + ret tmp.46; |
| 171 | +} |
| 172 | +@L._.4(tmp.9: any, tmp.10: any): any { |
| 173 | + tmp.47: any = const 7; |
| 174 | + tmp.48: any = call @bitand tmp.10 tmp.47; |
| 175 | + tmp.16: any = id tmp.48; |
| 176 | + tmp.50: any = const 0; |
| 177 | + tmp.49: any = eq tmp.16 tmp.50; |
| 178 | + br tmp.49 .L.then.11 .L.else.12; |
| 179 | +.L.then.11: |
| 180 | + tmp.51: any = const 14; |
| 181 | + tmp.15: any = id tmp.51; |
| 182 | + jmp .L.endif.13; |
| 183 | +.L.else.12: |
| 184 | + tmp.52: any = const 6; |
| 185 | + tmp.15: any = id tmp.52; |
| 186 | +.L.endif.13: |
| 187 | + tmp.54: any = const 6; |
| 188 | + tmp.53: any = eq tmp.15 tmp.54; |
| 189 | + tmp.55: any = not tmp.53; |
| 190 | + br tmp.55 .L.then.9 .L.else.10; |
| 191 | +.L.then.9: |
| 192 | + tmp.56: any = const 7; |
| 193 | + tmp.57: any = call @bitand tmp.9 tmp.56; |
| 194 | + tmp.18: any = id tmp.57; |
| 195 | + tmp.59: any = const 0; |
| 196 | + tmp.58: any = eq tmp.18 tmp.59; |
| 197 | + br tmp.58 .L.then.16 .L.else.17; |
| 198 | +.L.then.16: |
| 199 | + tmp.60: any = const 14; |
| 200 | + tmp.17: any = id tmp.60; |
| 201 | + jmp .L.endif.18; |
| 202 | +.L.else.17: |
| 203 | + tmp.61: any = const 6; |
| 204 | + tmp.17: any = id tmp.61; |
| 205 | +.L.endif.18: |
| 206 | + tmp.63: any = const 6; |
| 207 | + tmp.62: any = eq tmp.17 tmp.63; |
| 208 | + tmp.64: any = not tmp.62; |
| 209 | + br tmp.64 .L.then.14 .L.else.15; |
| 210 | +.L.then.14: |
| 211 | + tmp.65: any = sub tmp.9 tmp.10; |
| 212 | + ret tmp.65; |
| 213 | +.L.else.15: |
| 214 | + tmp.66: any = const 830; |
| 215 | + ret tmp.66; |
| 216 | +.L.else.10: |
| 217 | + tmp.67: any = const 830; |
| 218 | + ret tmp.67; |
| 219 | +} |
| 220 | +@L.+.3(tmp.7: any, tmp.8: any): any { |
| 221 | + tmp.68: any = const 7; |
| 222 | + tmp.69: any = call @bitand tmp.8 tmp.68; |
| 223 | + tmp.12: any = id tmp.69; |
| 224 | + tmp.71: any = const 0; |
| 225 | + tmp.70: any = eq tmp.12 tmp.71; |
| 226 | + br tmp.70 .L.then.21 .L.else.22; |
| 227 | +.L.then.21: |
| 228 | + tmp.72: any = const 14; |
| 229 | + tmp.11: any = id tmp.72; |
| 230 | + jmp .L.endif.23; |
| 231 | +.L.else.22: |
| 232 | + tmp.73: any = const 6; |
| 233 | + tmp.11: any = id tmp.73; |
| 234 | +.L.endif.23: |
| 235 | + tmp.75: any = const 6; |
| 236 | + tmp.74: any = eq tmp.11 tmp.75; |
| 237 | + tmp.76: any = not tmp.74; |
| 238 | + br tmp.76 .L.then.19 .L.else.20; |
| 239 | +.L.then.19: |
| 240 | + tmp.77: any = const 7; |
| 241 | + tmp.78: any = call @bitand tmp.7 tmp.77; |
| 242 | + tmp.14: any = id tmp.78; |
| 243 | + tmp.80: any = const 0; |
| 244 | + tmp.79: any = eq tmp.14 tmp.80; |
| 245 | + br tmp.79 .L.then.26 .L.else.27; |
| 246 | +.L.then.26: |
| 247 | + tmp.81: any = const 14; |
| 248 | + tmp.13: any = id tmp.81; |
| 249 | + jmp .L.endif.28; |
| 250 | +.L.else.27: |
| 251 | + tmp.82: any = const 6; |
| 252 | + tmp.13: any = id tmp.82; |
| 253 | +.L.endif.28: |
| 254 | + tmp.84: any = const 6; |
| 255 | + tmp.83: any = eq tmp.13 tmp.84; |
| 256 | + tmp.85: any = not tmp.83; |
| 257 | + br tmp.85 .L.then.24 .L.else.25; |
| 258 | +.L.then.24: |
| 259 | + tmp.86: any = add tmp.7 tmp.8; |
| 260 | + ret tmp.86; |
| 261 | +.L.else.25: |
| 262 | + tmp.87: any = const 574; |
| 263 | + ret tmp.87; |
| 264 | +.L.else.20: |
| 265 | + tmp.88: any = const 574; |
| 266 | + ret tmp.88; |
| 267 | +} |
| 268 | +@L.eq.p.2(tmp.5: any, tmp.6: any): any { |
| 269 | + tmp.89: any = eq tmp.5 tmp.6; |
| 270 | + br tmp.89 .L.then.29 .L.else.30; |
| 271 | +.L.then.29: |
| 272 | + tmp.90: any = const 14; |
| 273 | + ret tmp.90; |
| 274 | +.L.else.30: |
| 275 | + tmp.91: any = const 6; |
| 276 | + ret tmp.91; |
| 277 | +} |
| 278 | +@main: any { |
| 279 | + tmp.92: any = const 24; |
| 280 | + arg.x.3: any = id tmp.92; |
| 281 | + tmp.93: any = const 48; |
| 282 | + arg.y.4: any = id tmp.93; |
| 283 | + tmp.94: any = call @L.ack.1 arg.x.3 arg.y.4; |
| 284 | + tmp.95: any = const 8; |
| 285 | + tmp.94: any = div tmp.94 tmp.95; |
| 286 | + print tmp.94; |
| 287 | +} |
0 commit comments