MCPcopy Create free account
hub / github.com/Moddable-OpenSource/moddable / fxBigInt_or

Function fxBigInt_or

xs/sources/xsBigInt.c:1124–1172  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1122}
1123
1124txBigInt *fxBigInt_or(txMachine* the, txBigInt *r, txBigInt *a, txBigInt *b)
1125{
1126 txBigInt *aa, *bb;
1127 int i;
1128 mxBigInt_meter(MAX(a->size, b->size));
1129 if (a->sign) {
1130 if (b->sign)
1131 goto OR_MINUS_MINUS;
1132 aa = a;
1133 a = b;
1134 b = aa;
1135 goto OR_PLUS_MINUS;
1136 }
1137 if (b->sign)
1138 goto OR_PLUS_MINUS;
1139 return fxBigInt_fit(the, fxBigInt_uor(the, r, a, b));
1140OR_PLUS_MINUS:
1141// GMP: -(OP1 | (-OP2)) = -(OP1 | ~(OP2 - 1)) == ~(OP1 | ~(OP2 - 1)) + 1 == (~OP1 & (OP2 - 1)) + 1
1142 if (r == NULL)
1143 r = fxBigInt_alloc(the, b->size + 1);
1144 bb = fxBigInt_usub(the, NULL, b, (txBigInt *)&gxBigIntOne);
1145 if (a->size < bb->size) {
1146 for (i = 0; i < a->size; i++)
1147 r->data[i] = ~a->data[i] & bb->data[i];
1148 for (; i < bb->size; i++)
1149 r->data[i] = bb->data[i];
1150 }
1151 else {
1152 for (i = 0; i < bb->size; i++)
1153 r->data[i] = ~a->data[i] & bb->data[i];
1154 }
1155 r->size = bb->size;
1156 r = fxBigInt_uadd(the, r, r, (txBigInt *)&gxBigIntOne);
1157 r->sign = 1;
1158 fxBigInt_free(the, bb);
1159 return fxBigInt_fit(the, r);
1160OR_MINUS_MINUS:
1161// GMP: -((-OP1) | (-OP2)) = -(~(OP1 - 1) | ~(OP2 - 1)) == ~(~(OP1 - 1) | ~(OP2 - 1)) + 1 = = ((OP1 - 1) & (OP2 - 1)) + 1
1162 if (r == NULL)
1163 r = fxBigInt_alloc(the, MIN(a->size, b->size) + 1);
1164 aa = fxBigInt_usub(the, NULL, a, (txBigInt *)&gxBigIntOne);
1165 bb = fxBigInt_usub(the, NULL, b, (txBigInt *)&gxBigIntOne);
1166 r = fxBigInt_uand(the, r, aa, bb);
1167 r = fxBigInt_uadd(the, r, r, (txBigInt *)&gxBigIntOne);
1168 r->sign = 1;
1169 fxBigInt_free(the, bb);
1170 fxBigInt_free(the, aa);
1171 return fxBigInt_fit(the, r);
1172}
1173
1174txBigInt *fxBigInt_uor(txMachine* the, txBigInt *r, txBigInt *a, txBigInt *b)
1175{

Callers

nothing calls this directly

Calls 7

fxBigInt_fitFunction · 0.85
fxBigInt_uorFunction · 0.85
fxBigInt_allocFunction · 0.85
fxBigInt_usubFunction · 0.85
fxBigInt_uaddFunction · 0.85
fxBigInt_freeFunction · 0.85
fxBigInt_uandFunction · 0.85

Tested by

no test coverage detected