Charles,
I was trying to convert the caching hack version of the Ackermann example using your shifts() function. If I can get this to work I'll use the C extension module version of shifts() you wrote.
' Script BASIC Ackermann
function shifts(v,p,ar)
  local bp,ba,co,cq,bi,x,y,d
  bp=1
  x=0xffffffff and v
  for co=0 to 31
    ba[co]=0
  next
  for co=0 to 31
    bi=x and bp
    cq=co+p
    if (bi<>0) then
      if ((cq>=0)and(cq<32)) then
        ba[cq]=1
      end if
    end if
    bp = bp + bp
  next
  bp=1
  y=0
  '
  ' SUPPORT FOR ARITHMETIC RIGHT SHIFTS
  '
  d=100
  if (ar) then
    if (x and 0x80000000) then  
      d=31+p
    end if
  end if
  '
  for co=0 to 31
   if ((ba[co]<>0)or(co>=d)) then
      y=y or bp
    end if
    bp = bp + bp
  next
  shifts=y
end function
' PRINT shifts(0x80000000,2),"\n"
' PRINT shifts(-32,-2,1),"\n"
' PRINT shifts(8,-2),"\n"
FUNCTION ackermann(m, n)
  IF NOT m THEN ackermann = n + 1
  IF n >= shifts(1, -n_bits) THEN
    idx = 0
  ELSE
    idx = shifts(m, n_bits) + n
    IF cache[idx] THEN ackermann = cache[idx]
  END IF
  IF NOT n THEN
    res = ackermann(m - 1, 1)
  ELSE
    res = ackermann(m - 1, ackermann(m, n - 1))
  END IF
  IF cache[idx] = res THEN ackermann = res
END FUNCTION
m_bits = 3
n_bits = 20
SPLITA STRING(1048576,"") BY "" TO cache
FOR m = 0 TO 1
  FOR n = 0 TO 3 - m
    PRINT "A(",m," , ",n,") = ", ackermann(m, n),"\n"
  NEXT
NEXT