@@ -1429,9 +1429,13 @@ term bif_erlang_float_1(Context *ctx, uint32_t fail_label, int live, term arg1)
1429
1429
}
1430
1430
1431
1431
typedef int64_t (* bitwise_op )(int64_t a , int64_t b );
1432
+ typedef size_t (* bitwise_big_op )(
1433
+ const intn_digit_t m [], size_t m_len , intn_integer_sign_t m_sign ,
1434
+ const intn_digit_t n [], size_t n_len , intn_integer_sign_t n_sign ,
1435
+ intn_digit_t out [], intn_integer_sign_t * out_sign );
1432
1436
1433
1437
static inline term bitwise_helper (
1434
- Context * ctx , uint32_t fail_label , int live , term arg1 , term arg2 , bitwise_op op )
1438
+ Context * ctx , uint32_t fail_label , int live , term arg1 , term arg2 , bitwise_op op , bitwise_big_op big_op )
1435
1439
{
1436
1440
if (LIKELY (term_is_any_integer (arg1 ) && term_is_any_integer (arg2 ))) {
1437
1441
size_t arg1_size = term_is_integer (arg1 ) ? 0 : term_boxed_size (arg1 );
@@ -1447,7 +1451,21 @@ static inline term bitwise_helper(
1447
1451
return make_maybe_boxed_int (ctx , fail_label , live , result );
1448
1452
#endif
1449
1453
} else {
1450
- abort ();
1454
+ intn_digit_t tmp_buf1 [INTN_INT64_LEN ];
1455
+ intn_digit_t tmp_buf2 [INTN_INT64_LEN ];
1456
+ intn_digit_t * m ;
1457
+ size_t m_len ;
1458
+ intn_integer_sign_t m_sign ;
1459
+ intn_digit_t * n ;
1460
+ size_t n_len ;
1461
+ intn_integer_sign_t n_sign ;
1462
+ args_to_bigint (arg1 , arg2 , tmp_buf1 , tmp_buf2 , & m , & m_len , & m_sign , & n , & n_len , & n_sign );
1463
+
1464
+ intn_digit_t bigres [INTN_MAX_RES_LEN ];
1465
+ intn_integer_sign_t bigres_sign ;
1466
+ size_t bigres_len = big_op (m , m_len , m_sign , n , n_len , n_sign , bigres , & bigres_sign );
1467
+
1468
+ return make_bigint (ctx , fail_label , live , bigres , bigres_len , bigres_sign );
1451
1469
}
1452
1470
} else {
1453
1471
RAISE_ERROR_BIF (fail_label , BADARITH_ATOM );
@@ -1464,7 +1482,7 @@ term bif_erlang_bor_2(Context *ctx, uint32_t fail_label, int live, term arg1, te
1464
1482
if (LIKELY (term_is_integer (arg1 ) && term_is_integer (arg2 ))) {
1465
1483
return arg1 | arg2 ;
1466
1484
} else {
1467
- return bitwise_helper (ctx , fail_label , live , arg1 , arg2 , bor );
1485
+ return bitwise_helper (ctx , fail_label , live , arg1 , arg2 , bor , intn_bormn );
1468
1486
}
1469
1487
}
1470
1488
@@ -1478,7 +1496,7 @@ term bif_erlang_band_2(Context *ctx, uint32_t fail_label, int live, term arg1, t
1478
1496
if (LIKELY (term_is_integer (arg1 ) && term_is_integer (arg2 ))) {
1479
1497
return arg1 & arg2 ;
1480
1498
} else {
1481
- return bitwise_helper (ctx , fail_label , live , arg1 , arg2 , band );
1499
+ return bitwise_helper (ctx , fail_label , live , arg1 , arg2 , band , NULL );
1482
1500
}
1483
1501
}
1484
1502
@@ -1492,7 +1510,7 @@ term bif_erlang_bxor_2(Context *ctx, uint32_t fail_label, int live, term arg1, t
1492
1510
if (LIKELY (term_is_integer (arg1 ) && term_is_integer (arg2 ))) {
1493
1511
return (arg1 ^ arg2 ) | TERM_INTEGER_TAG ;
1494
1512
} else {
1495
- return bitwise_helper (ctx , fail_label , live , arg1 , arg2 , bxor );
1513
+ return bitwise_helper (ctx , fail_label , live , arg1 , arg2 , bxor , NULL );
1496
1514
}
1497
1515
}
1498
1516
0 commit comments