Skip to content

Commit 70519ec

Browse files
committed
Merge pull request #1916 from bettio/utils-cleanup-and-doc
- Add doxygen documentation to `utils.h` functions that have been introduced with feature/bigint branch. - Move bitshift utilities to `utils.h`. - Fix issue with 60-bits `b` operand in `a bsr b` and `a bsl b` These changes are made under both the "Apache 2.0" and the "GNU Lesser General Public License 2.1 or later" license terms (dual license). SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later
2 parents 3a6309e + b0db34a commit 70519ec

File tree

4 files changed

+581
-26
lines changed

4 files changed

+581
-26
lines changed

src/libAtomVM/bif.c

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1691,32 +1691,6 @@ term bif_erlang_bxor_2(Context *ctx, uint32_t fail_label, int live, term arg1, t
16911691
}
16921692
}
16931693

1694-
static inline int64_t int64_bsr(int64_t n, unsigned int rshift)
1695-
{
1696-
return (int64_t) ((n < 0) ? ~(~((uint64_t) n) >> rshift) : (((uint64_t) n) >> rshift));
1697-
}
1698-
1699-
static inline bool int64_bsl_overflow(int64_t n, unsigned int lshift, int64_t *out)
1700-
{
1701-
if (lshift >= 64) {
1702-
*out = 0;
1703-
return (n != 0);
1704-
}
1705-
1706-
int64_t res = (int64_t) (((uint64_t) n) << lshift);
1707-
*out = res;
1708-
int64_t check = int64_bsr(res, lshift);
1709-
return check != n;
1710-
}
1711-
1712-
static inline int64_t int64_bsr_safe(int64_t n, unsigned int rshift)
1713-
{
1714-
if (rshift >= 64) {
1715-
return n < 0 ? -1 : 0;
1716-
}
1717-
return int64_bsr(n, rshift);
1718-
}
1719-
17201694
term bif_erlang_bsl_2(Context *ctx, uint32_t fail_label, int live, term arg1, term arg2)
17211695
{
17221696
if (LIKELY(term_is_any_integer(arg1) && term_is_non_neg_int(arg2))) {

src/libAtomVM/term_typedef.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ typedef uint64_t avm_uint64_t;
8686
#error "term size must be either 32 bit or 64 bit."
8787
#endif
8888

89+
_Static_assert(SIZE_MAX >= AVM_INT_MAX, "SIZE_MAX < AVM_INT_MAX is an unsupported configuration.");
90+
8991
#define UNICODE_CHAR_MAX 0x10FFFF
9092

9193
#define MIN_NOT_BOXED_INT (AVM_INT_MIN >> 4)

0 commit comments

Comments
 (0)