Rats, I was hoping there was something here that would optimize $powmod. And the same kind of shortcut can benefit $biton here, as well as $bitoff. But if there's a shortcut for the other bitwisers where the numbers can have many bits set, that's above my paygrade.
The only shortcut I came up with for $xor or $and or $or was to translate both numbers to hex, then padd them so they could be lined up as equal length byte arrays, then once they're both in a &binvar the byte values can be individually $XOR'ed or $AND'ed or $OR'ed against each other.
But scripting that had too many calls to $base and $regsubex and $xor itself that the scripted method wasn't competitive. Though, if the 2 numbers can be efficiently exported from MAPM over to a uint32 array, that's 99% of the battle.
Below is the scripted $biton that borrows from the $isbit shortcut to determine whether it needs to add 2^something or not. And same with $bitoff knowing whether to subtract 2^something. Though there's got to be a better way to simulate biton/bitoff than add/subtract. This alias benchmarks to like 10% of the $biton time, with $crc just a quick check that both results match.
alias mapm_isbit_style5 { return $calc(($1 //(2^($2 -1))) % 2) }
alias mapm_biton {
var -s %fupdate $fupdate
fupdate 95
var %bits $int($1)
if (%bits !isnum 100-10000) var %bits 512
var -s %t 9
var %low.bf $calc(2^(%bits - 12)) , %hi.bf $calc(2^%bits)
var %rand.bf $rands(%low.bf,%hi.bf)
var %i %t , %ticks $ticksqpc , %check
while (%i) {
var %j %bits
while (%j) {
var %a.bf %rand.bf
var %a.bf $biton(%rand.bf,%j) , %check $crc(%check %a.bf,0)
dec %j
}
dec -s %i
}
echo -a style#1: biton time: $calc($ticksqpc - %ticks) %check
var -s %i %t , %ticks $ticksqpc , %check
while (%i) {
var %j %bits
while (%j) {
var %a.bf %rand.bf
if (!$mapm_isbit_style5(%a.bf,$calc(%j))) var %a.bf %a.bf + $calc(2^(%j -1))
var %check $crc(%check %a.bf,0)
dec %j
}
dec -s %i
}
echo -a style#2 time: $calc($ticksqpc - %ticks) %check
fupdate %fupdate
}