2

I want to compare two pieces of low-level code, each in its own file. The format is AT&T-Assembly-style: For me, it's two CUDA PTX files, but this question applies also for the output of gcc -S or clang -S. For the sake of discussion assume that they're two implementations of the same function.

Now, I can of course diff the files textually. The problem is that the register assignments are different. The programs could be completely the same, just with different register names; or a small difference in one line may change the register assignments everywhere (e.g. reduce everything by 1 since an extra register is not used).

I don't mind extra instructions or comments etc. - those are handled just fine by textual diff tools.

My question: What can I do in order to hide those register differences everywhere, for a more "structural" comparison? Should I try some "canonicalization" with a pre-diff'ing parsing script (and if so, which/how)? Can I maybe avail myself of an assembler which takes my code, or a compiler which produces my code, to help me with this?

einpoklum
  • 118,144
  • 57
  • 340
  • 684
  • Working on GCC/nvptx myself, I sympathize, this is annoying. However, for me, not yet to such a degree that I'd have done something about it... ;-P – tschwinge Aug 03 '23 at 18:27
  • 1
    @tschwinge: If we at least had a PTX parsing library, we could perhaps feed the AST into some kind of tree-diff'ing tool. – einpoklum Aug 03 '23 at 18:28
  • 1
    There are PTX simulators (, , , for example), which maybe could help (assuming they contain suitable PTX parsers, of course) for building such a PTX "canonicalization" tool. Or, if applicable, do it in the respective compiler back end. – tschwinge Aug 03 '23 at 18:38
  • @tschwinge: It seems gpgpu-sim does indeed have a PTX parser: I see YACC and LEX files in there. However: 1. It's not easy to separate and 2. It is outdated by several yea (e.g. no half-precision types|). But it's a start. – einpoklum Aug 04 '23 at 09:53

0 Answers0