bpo-36957: Add _PyLong_Rshift() and _PyLong_Lshift(). (GH-13416)

diff --git a/Modules/mathmodule.c b/Modules/mathmodule.c
index 8213092..7a0044a 100644
--- a/Modules/mathmodule.c
+++ b/Modules/mathmodule.c
@@ -1671,18 +1671,13 @@
     }
     d = 0;
     while (--s >= 0) {
-        PyObject *q, *shift;
+        PyObject *q;
         size_t e = d;
 
         d = c >> s;
 
         /* q = (n >> 2*c - e - d + 1) // a */
-        shift = PyLong_FromSize_t(2U*c - d - e + 1U);
-        if (shift == NULL) {
-            goto error;
-        }
-        q = PyNumber_Rshift(n, shift);
-        Py_DECREF(shift);
+        q = _PyLong_Rshift(n, 2U*c - d - e + 1U);
         if (q == NULL) {
             goto error;
         }
@@ -1692,13 +1687,7 @@
         }
 
         /* a = (a << d - 1 - e) + q */
-        shift = PyLong_FromSize_t(d - 1U - e);
-        if (shift == NULL) {
-            Py_DECREF(q);
-            goto error;
-        }
-        Py_SETREF(a, PyNumber_Lshift(a, shift));
-        Py_DECREF(shift);
+        Py_SETREF(a, _PyLong_Lshift(a, d - 1U - e));
         if (a == NULL) {
             Py_DECREF(q);
             goto error;
@@ -1939,9 +1928,9 @@
 math_factorial(PyObject *module, PyObject *arg)
 /*[clinic end generated code: output=6686f26fae00e9ca input=6d1c8105c0d91fb4]*/
 {
-    long x;
+    long x, two_valuation;
     int overflow;
-    PyObject *result, *odd_part, *two_valuation, *pyint_form;
+    PyObject *result, *odd_part, *pyint_form;
 
     if (PyFloat_Check(arg)) {
         PyObject *lx;
@@ -1990,13 +1979,8 @@
     odd_part = factorial_odd_part(x);
     if (odd_part == NULL)
         return NULL;
-    two_valuation = PyLong_FromLong(x - count_set_bits(x));
-    if (two_valuation == NULL) {
-        Py_DECREF(odd_part);
-        return NULL;
-    }
-    result = PyNumber_Lshift(odd_part, two_valuation);
-    Py_DECREF(two_valuation);
+    two_valuation = x - count_set_bits(x);
+    result = _PyLong_Lshift(odd_part, two_valuation);
     Py_DECREF(odd_part);
     return result;
 }