(
analysis: Analysis, outfile: TextIO, lines: bool
)
| 215 | return (-stack.base_offset).to_c() |
| 216 | |
| 217 | def generate_tier1_cases( |
| 218 | analysis: Analysis, outfile: TextIO, lines: bool |
| 219 | ) -> None: |
| 220 | out = CWriter(outfile, 2, lines) |
| 221 | emitter = Emitter(out, analysis.labels) |
| 222 | out.emit("\n") |
| 223 | for name, inst in sorted(analysis.instructions.items()): |
| 224 | out.emit("\n") |
| 225 | out.emit(f"TARGET({name}) {{\n") |
| 226 | popped = get_popped(inst, analysis) |
| 227 | # We need to ifdef it because this breaks platforms |
| 228 | # without computed gotos/tail calling. |
| 229 | out.emit(f"#if _Py_TAIL_CALL_INTERP\n") |
| 230 | out.emit(f"int opcode = {name};\n") |
| 231 | out.emit(f"(void)(opcode);\n") |
| 232 | out.emit(f"#endif\n") |
| 233 | needs_this = uses_this(inst) |
| 234 | unused_guard = "(void)this_instr;\n" |
| 235 | if inst.properties.needs_prev: |
| 236 | out.emit(f"_Py_CODEUNIT* const prev_instr = frame->instr_ptr;\n") |
| 237 | |
| 238 | if needs_this and not inst.is_target: |
| 239 | out.emit(f"_Py_CODEUNIT* const this_instr = next_instr;\n") |
| 240 | out.emit(unused_guard) |
| 241 | if not inst.properties.no_save_ip: |
| 242 | out.emit(f"frame->instr_ptr = next_instr;\n") |
| 243 | |
| 244 | out.emit(f"next_instr += {inst.size};\n") |
| 245 | out.emit(f"INSTRUCTION_STATS({name});\n") |
| 246 | if inst.is_target: |
| 247 | out.emit(f"PREDICTED_{name}:;\n") |
| 248 | if needs_this: |
| 249 | out.emit(f"_Py_CODEUNIT* const this_instr = next_instr - {inst.size};\n") |
| 250 | out.emit(unused_guard) |
| 251 | if inst.properties.uses_opcode: |
| 252 | out.emit(f"opcode = {name};\n") |
| 253 | if inst.family is not None: |
| 254 | out.emit( |
| 255 | f"static_assert({inst.family.size} == {inst.size-1}" |
| 256 | ', "incorrect cache size");\n' |
| 257 | ) |
| 258 | declare_variables(inst, out) |
| 259 | offset = 1 # The instruction itself |
| 260 | stack = Stack() |
| 261 | for part in inst.parts: |
| 262 | if part.properties.records_value: |
| 263 | continue |
| 264 | # Only emit braces if more than one uop |
| 265 | insert_braces = len([p for p in inst.parts if isinstance(p, Uop)]) > 1 |
| 266 | reachable, offset, stack = write_uop(part, emitter, offset, stack, inst, insert_braces) |
| 267 | out.start_line() |
| 268 | if reachable: # type: ignore[possibly-undefined] |
| 269 | stack.flush(out) |
| 270 | out.emit("DISPATCH();\n") |
| 271 | out.start_line() |
| 272 | out.emit("}") |
| 273 | out.emit("\n") |
| 274 |
no test coverage detected
searching dependent graphs…