@@ -1473,6 +1473,34 @@ term bif_erlang_bsr_2(Context *ctx, uint32_t fail_label, int live, term arg1, te
14731473 return bitshift_helper (ctx , fail_label , live , arg1 , arg2 , bsr );
14741474}
14751475
1476+ static term bnot_boxed_helper (Context * ctx , uint32_t fail_label , uint32_t live , term arg1 )
1477+ {
1478+ if (term_is_boxed_integer (arg1 )) {
1479+ switch (term_boxed_size (arg1 )) {
1480+ case 0 :
1481+ //BUG
1482+ AVM_ABORT ();
1483+
1484+ case 1 : {
1485+ avm_int_t val = term_unbox_int (arg1 );
1486+ return make_boxed_int (ctx , fail_label , live , ~val );
1487+ }
1488+
1489+ #if BOXED_TERMS_REQUIRED_FOR_INT64 == 2
1490+ case 2 : {
1491+ avm_int64_t val = term_unbox_int64 (arg1 );
1492+ return make_boxed_int64 (ctx , fail_label , live , ~val );
1493+ }
1494+ #endif
1495+ default :
1496+ RAISE_ERROR_BIF (fail_label , OVERFLOW_ATOM );
1497+ }
1498+ } else {
1499+ TRACE ("error: arg1: 0x%lx\n" , arg1 );
1500+ RAISE_ERROR_BIF (fail_label , BADARITH_ATOM );
1501+ }
1502+ }
1503+
14761504term bif_erlang_bnot_1 (Context * ctx , uint32_t fail_label , int live , term arg1 )
14771505{
14781506 UNUSED (live );
@@ -1481,7 +1509,7 @@ term bif_erlang_bnot_1(Context *ctx, uint32_t fail_label, int live, term arg1)
14811509 return ~arg1 | TERM_INTEGER_TAG ;
14821510
14831511 } else {
1484- RAISE_ERROR_BIF ( fail_label , BADARITH_ATOM );
1512+ return bnot_boxed_helper ( ctx , fail_label , live , arg1 );
14851513 }
14861514}
14871515
0 commit comments