7#include "nuitka/prelude.h"
15 CHECK_NILONG_OBJECT(operand1);
16 CHECK_NILONG_OBJECT(operand2);
18 bool left_c_usable = IS_NILONG_C_VALUE_VALID(operand1);
19 bool right_c_usable = IS_NILONG_C_VALUE_VALID(operand2);
21 if (left_c_usable && right_c_usable) {
25#pragma warning(disable : 4101)
27 NUITKA_MAY_BE_UNUSED
bool cbool_result;
28 NUITKA_MAY_BE_UNUSED PyObject *obj_result;
29 NUITKA_MAY_BE_UNUSED
long clong_result;
30 NUITKA_MAY_BE_UNUSED
double cfloat_result;
35 CHECK_NILONG_OBJECT(operand1);
36 CHECK_NILONG_OBJECT(operand2);
38 const long a = GET_NILONG_C_VALUE(operand1);
39 const long b = GET_NILONG_C_VALUE(operand2);
41 const long x = (long)((
unsigned long)a + b);
42 bool no_overflow = ((x ^ a) >= 0 || (x ^ b) >= 0);
43 if (likely(no_overflow)) {
45 goto exit_result_ok_clong;
48 ENFORCE_NILONG_OBJECT_VALUE(operand1);
49 obj_result = BINARY_OPERATION_ADD_OBJECT_LONG_CLONG(operand1->python_value, operand2->c_value);
51 if (unlikely(result == NULL)) {
55 SET_NILONG_OBJECT_VALUE(result, obj_result);
59 SET_NILONG_C_VALUE(result, clong_result);
62 }
else if (left_c_usable ==
false && right_c_usable) {
63 PyObject *python_result = BINARY_OPERATION_ADD_OBJECT_LONG_CLONG(operand1->python_value, operand2->c_value);
65 if (unlikely(python_result == NULL)) {
69 SET_NILONG_OBJECT_VALUE(result, python_result);
71 }
else if (left_c_usable && right_c_usable ==
false) {
72 PyObject *python_result = BINARY_OPERATION_ADD_OBJECT_LONG_CLONG(operand2->python_value, operand1->c_value);
74 if (unlikely(python_result == NULL)) {
78 SET_NILONG_OBJECT_VALUE(result, python_result);
82 PyObject *python_result = BINARY_OPERATION_ADD_OBJECT_LONG_LONG(operand1->python_value, operand1->python_value);
84 if (unlikely(python_result == NULL)) {
88 SET_NILONG_OBJECT_VALUE(result, python_result);
97 CHECK_NILONG_OBJECT(operand1);
98 assert(Py_ABS(operand2) < (1 << PyLong_SHIFT));
100 bool left_c_usable = IS_NILONG_C_VALUE_VALID(operand1);
101 bool right_c_usable =
true;
103 if (left_c_usable && right_c_usable) {
107#pragma warning(disable : 4101)
109 NUITKA_MAY_BE_UNUSED
bool cbool_result;
110 NUITKA_MAY_BE_UNUSED PyObject *obj_result;
111 NUITKA_MAY_BE_UNUSED
long clong_result;
112 NUITKA_MAY_BE_UNUSED
double cfloat_result;
117 CHECK_NILONG_OBJECT(operand1);
118 assert(Py_ABS(operand2) < (1 << PyLong_SHIFT));
120 const long a = GET_NILONG_C_VALUE(operand1);
121 const long b = (long)(operand2);
123 const long x = (long)((
unsigned long)a + b);
124 bool no_overflow = ((x ^ a) >= 0 || (x ^ b) >= 0);
125 if (likely(no_overflow)) {
127 goto exit_result_ok_clong;
130 ENFORCE_NILONG_OBJECT_VALUE(operand1);
131 obj_result = BINARY_OPERATION_ADD_OBJECT_LONG_DIGIT(operand1->python_value, operand2);
133 if (unlikely(result == NULL)) {
137 SET_NILONG_OBJECT_VALUE(result, obj_result);
140 exit_result_ok_clong:
141 SET_NILONG_C_VALUE(result, clong_result);
144 }
else if (left_c_usable ==
false && right_c_usable) {
145 PyObject *python_result = BINARY_OPERATION_ADD_OBJECT_LONG_DIGIT(operand1->python_value, operand2);
147 if (unlikely(python_result == NULL)) {
151 SET_NILONG_OBJECT_VALUE(result, python_result);
154 NUITKA_CANNOT_GET_HERE(
"cannot happen with types NILONG DIGIT");