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

Function fxBigInt_and

xs/sources/xsBigInt.c:1061–1105  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1059}
1060
1061txBigInt *fxBigInt_and(txMachine* the, txBigInt *r, txBigInt *a, txBigInt *b)
1062{
1063 txBigInt *aa, *bb;
1064 int i;
1065 if (a->sign) {
1066 if (b->sign)
1067 goto AND_MINUS_MINUS;
1068 aa = a;
1069 a = b;
1070 b = aa;
1071 goto AND_PLUS_MINUS;
1072 }
1073 if (b->sign)
1074 goto AND_PLUS_MINUS;
1075 return fxBigInt_fit(the, fxBigInt_uand(the, r, a, b));
1076AND_PLUS_MINUS:
1077// GMP: OP1 & -OP2 == OP1 & ~(OP2 - 1)
1078 if (r == NULL)
1079 r = fxBigInt_alloc(the, a->size);
1080 bb = fxBigInt_usub(the, NULL, b, (txBigInt *)&gxBigIntOne);
1081 if (a->size > bb->size) {
1082 for (i = 0; i < bb->size; i++)
1083 r->data[i] = a->data[i] & ~bb->data[i];
1084 for (; i < a->size; i++)
1085 r->data[i] = a->data[i];
1086 }
1087 else {
1088 for (i = 0; i < a->size; i++)
1089 r->data[i] = a->data[i] & ~bb->data[i];
1090 }
1091 fxBigInt_free(the, bb);
1092 return fxBigInt_fit(the, r);
1093AND_MINUS_MINUS:
1094// GMP: -((-OP1) & (-OP2)) = -(~(OP1 - 1) & ~(OP2 - 1)) == ~(~(OP1 - 1) & ~(OP2 - 1)) + 1 == ((OP1 - 1) | (OP2 - 1)) + 1
1095 if (r == NULL)
1096 r = fxBigInt_alloc(the, MAX(a->size, b->size) + 1);
1097 aa = fxBigInt_usub(the, NULL, a, (txBigInt *)&gxBigIntOne);
1098 bb = fxBigInt_usub(the, NULL, b, (txBigInt *)&gxBigIntOne);
1099 r = fxBigInt_uor(the, r, aa, bb);
1100 r = fxBigInt_uadd(the, r, r, (txBigInt *)&gxBigIntOne);
1101 r->sign = 1;
1102 fxBigInt_free(the, bb);
1103 fxBigInt_free(the, aa);
1104 return fxBigInt_fit(the, r);
1105}
1106
1107txBigInt *fxBigInt_uand(txMachine* the, txBigInt *r, txBigInt *a, txBigInt *b)
1108{

Callers

nothing calls this directly

Calls 7

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

Tested by

no test coverage detected