4 ms·
Compiling a subset of Python syntax to x86-64 assembly for fun and zero profit
- denfromufa 9y agoalso worth mentioning here llvmlite & numba, peachpy: http://llvmlite.pydata.org/en/latest http://llvmlite.pydata.org/en/latest http://numba.pydata.org http://numba.pydata.org https://github.com/Maratyszcza/PeachPy https://github.com/Maratyszcza/PeachPy
- rajathagasthya 9y agoInformative article as always from you. Thanks!
- senorsmile 9y agoThis was a very fun read. Makes me want to get back into assembly, figure out 64 bit assembly and make this more than a toy... almost.
- MichailP 9y agoThere was a whole course (notes for which are here [1]) dedicated to this topic, by prof. Jeremy Siek. [1] ecee.colorado.edu/ecen4553/fall09/notes.pdf
- benhoyt 9y agoWow, that looks really good -- thanks for sharing the link. Yeah, it's definitely similar to what I'm doing but in a more formal and non-toyish way.
- deleted 9y ago[deleted]
- mtanski 9y ago> pyast64 with peephole 0.24 29.7 > C version (gcc -O0) 0.22 31.8 Modern x86_64 processors are really good at ruing "bad" asm pretty efficiently.
- alephnil 9y agoAbsolutely. The amount of tricks used to achieve that is amazing, including things register renaming, branch prediction, virtual registers, instruction reordering etc. That is not really what demonstrated here though, as gcc was run with optimizations turned off, since otherwise the program would have been optimized to printing a constant.
- soravux 9y agoInteresting topic. We did something similar in the past using the bytecode instead of the AST tree to accelerate genetic algorithm evolution: http://multigrad.blogspot.com/2014/07/low-level-frenzy.html http://multigrad.blogspot.com/2014/07/low-level-frenzy.html http://multigrad.blogspot.com/2014/06/fun-with-python-bytecode.html http://multigrad.blogspot.com/2014/06/fun-with-python-byteco... I'm curious, what was the original use case for pyast64? Feels like we could apply it to genetic programming fairly straightforwardly.
- benhoyt 9y agoSorry, I didn't have a use case -- I did it purely for fun. However, I got the idea when I was trying to optimize some Python bytecode.
- john_moscow 9y agoLooks cool. But why asm? Generating C or C++ code and letting the GCC optimizer do the heavy lifting for you could probably get you a massive perf boost.
- ianai 9y agoBecause the people who talk down python for not being c/c++ "would win".
- john_moscow 9y agoWhy? Both C/C++ and Python are just tools and they have different strong/weak sides. I can't see much harm in combining the strong sides of 2 worlds. That said, isn't PyPy (https://pypy.org/ https://pypy.org/) already doing the same thing?
- ianai 9y agoI wasnt being serious - in line with the headline "for fun and no profit". Optimizing python with calls out to optimized c/c++ code has always been a thing. I think a large part of the interest here is novelty.
- viraptor 9y agoCython already does this. Including using type hints.
- ponytech 9y agoUsing the same technique, would it be possible to generate WebAssembly ?