3 ms·
I had a completely irrational dislike for the division. You could use a loop, but then you were wasting >3/4ths of your cycles on shifting and branching. If you
by AlotOfReading 5y ago
I had a completely irrational dislike for the division. You could use a loop, but then you were wasting >3/4ths of your cycles on shifting and branching. If you had the misfortune to have the compiler generate division code, it'd usually fill the branch delay slot with a NOP as well. The solution was simply to stick 8/16/32 division instructions in a row, but that felt inelegant. I spent a day writing some silly routine that averaged ~22 cycles over 32 bit integers just because it annoyed me so much.
- freemint 5y agoDo you still have access to this?
- AlotOfReading 5y agoSadly not. I was pretty terrible about version control and saving things from that early in my career. The concept was pretty simple though: division was 1-bit so you could simply do fewer divisions if you had smaller numbers. The first version was something like a BSR -> jump into the divide table. That probably would have been the place to stop, but I was clearly terrible at profiling because I remember adding all sorts of special case logic on top to handle things like powers of two, which likely ended up being slower in practice because cycle times aren't everything.
- girvo 5y ago> I was pretty terrible about version control and saving things from that early in my career. You and everyone else, I feel. I tried to find some of my early projects from two decades back, and despite having backups floating around on various hard-drives, I could not find them to save my life. I wish I'd accepted the good word of CVS/SVN back then!
- exikyut 5y agoThis is not an answer to your question as asked, but the direction it goes may prove interesting: https://lab.whitequark.org/notes/2020-04-06/synthesizing-optimal-8051-code/ https://lab.whitequark.org/notes/2020-04-06/synthesizing-opt... (Found this a while back, mild impostor syndrome moment much)
- freemint 5y agowhitequark is pretty genius. I think i saw that on her twitter previously but thanks for the trip down memory lane.