I found a size optimization to the routine on this page and I've changed it. This is what it used to be: (for A (mod M))
This is what it is now:
I've tried conducting speed tests, but I'm having difficulty. If someone could help me with this, I'd appreciate it. If in fact, the old routine is faster, we should probably put both up and give the pros and cons of each.