Skip to content

Commit 81e387d

Browse files
committed
Revert "DEBUG /wo gmp issues"
This reverts commit 959d07d.
1 parent 959d07d commit 81e387d

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

ext/gmp/gmp.c

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,40 @@ static void shift_operator_helper(gmp_binary_ui_op_t op, zval *return_value, zva
368368

369369
static int gmp_do_operation_ex(zend_uchar opcode, zval *result, zval *op1, zval *op2) /* {{{ */
370370
{
371+
switch (opcode) {
372+
case ZEND_ADD:
373+
gmp_zval_binary_ui_op(result, op1, op2, mpz_add, mpz_add_ui, false, true);
374+
if (UNEXPECTED(EG(exception))) { return FAILURE; }
375+
return SUCCESS;
376+
case ZEND_SUB:
377+
DO_BINARY_UI_OP(mpz_sub);
378+
case ZEND_MUL:
379+
DO_BINARY_UI_OP(mpz_mul);
380+
case ZEND_POW:
381+
shift_operator_helper(mpz_pow_ui, result, op1, op2, opcode);
382+
return SUCCESS;
383+
case ZEND_DIV:
384+
DO_BINARY_UI_OP_EX(mpz_tdiv_q, gmp_mpz_tdiv_q_ui, 1);
385+
case ZEND_MOD:
386+
DO_BINARY_UI_OP_EX(mpz_mod, gmp_mpz_mod_ui, 1);
387+
case ZEND_SL:
388+
shift_operator_helper(mpz_mul_2exp, result, op1, op2, opcode);
389+
return SUCCESS;
390+
case ZEND_SR:
391+
shift_operator_helper(mpz_fdiv_q_2exp, result, op1, op2, opcode);
392+
return SUCCESS;
393+
case ZEND_BW_OR:
394+
DO_BINARY_OP(mpz_ior);
395+
case ZEND_BW_AND:
396+
DO_BINARY_OP(mpz_and);
397+
case ZEND_BW_XOR:
398+
DO_BINARY_OP(mpz_xor);
399+
case ZEND_BW_NOT:
400+
DO_UNARY_OP(mpz_com);
401+
402+
default:
371403
return FAILURE;
404+
}
372405
}
373406
/* }}} */
374407

@@ -1012,18 +1045,21 @@ ZEND_FUNCTION(gmp_strval)
10121045
/* {{{ Add a and b */
10131046
ZEND_FUNCTION(gmp_add)
10141047
{
1048+
gmp_binary_ui_op(mpz_add, mpz_add_ui);
10151049
}
10161050
/* }}} */
10171051

10181052
/* {{{ Subtract b from a */
10191053
ZEND_FUNCTION(gmp_sub)
10201054
{
1055+
gmp_binary_ui_op(mpz_sub, mpz_sub_ui);
10211056
}
10221057
/* }}} */
10231058

10241059
/* {{{ Multiply a and b */
10251060
ZEND_FUNCTION(gmp_mul)
10261061
{
1062+
gmp_binary_ui_op(mpz_mul, mpz_mul_ui);
10271063
}
10281064
/* }}} */
10291065

@@ -1477,12 +1513,14 @@ ZEND_FUNCTION(gmp_prob_prime)
14771513
/* {{{ Computes greatest common denominator (gcd) of a and b */
14781514
ZEND_FUNCTION(gmp_gcd)
14791515
{
1516+
gmp_binary_ui_op(mpz_gcd, gmp_mpz_gcd_ui);
14801517
}
14811518
/* }}} */
14821519

14831520
/* {{{ Computes least common multiple (lcm) of a and b */
14841521
ZEND_FUNCTION(gmp_lcm)
14851522
{
1523+
gmp_binary_ui_op(mpz_lcm, mpz_lcm_ui);
14861524
}
14871525
/* }}} */
14881526

0 commit comments

Comments
 (0)