|
47 | 47 | extern "C" {
|
48 | 48 | #endif
|
49 | 49 |
|
| 50 | +#define TERM_BOXED_INTEGER_SIGN_BIT_POS 2 // 3rd bit |
| 51 | +#define TERM_BOXED_INTEGER_SIGN_BIT (1 << TERM_BOXED_INTEGER_SIGN_BIT_POS) |
50 | 52 | #define TERM_BOXED_VALUE_TAG 0x2
|
51 | 53 | #define TERM_INTEGER_TAG 0xF
|
52 | 54 | #define TERM_CATCH_TAG 0x1B
|
53 | 55 |
|
54 | 56 | #define TERM_BOXED_TAG_MASK 0x3F
|
55 | 57 | #define TERM_BOXED_TUPLE 0x0
|
56 | 58 | #define TERM_BOXED_BIN_MATCH_STATE 0x4
|
57 |
| -#define TERM_BOXED_POSITIVE_INTEGER 0x8 |
| 59 | +#define TERM_BOXED_POSITIVE_INTEGER 0x8 // b1000 (b1s00) |
| 60 | +#define TERM_BOXED_NEGATIVE_INTEGER (TERM_BOXED_POSITIVE_INTEGER | TERM_BOXED_INTEGER_SIGN_BIT) |
58 | 61 | #define TERM_BOXED_REF 0x10
|
59 | 62 | #define TERM_BOXED_FUN 0x14
|
60 | 63 | #define TERM_BOXED_FLOAT 0x18
|
@@ -443,7 +446,8 @@ static inline bool term_is_boxed_integer(term t)
|
443 | 446 | {
|
444 | 447 | if (term_is_boxed(t)) {
|
445 | 448 | const term *boxed_value = term_to_const_term_ptr(t);
|
446 |
| - if ((boxed_value[0] & TERM_BOXED_TAG_MASK) == TERM_BOXED_POSITIVE_INTEGER) { |
| 449 | + if (((boxed_value[0] & TERM_BOXED_TAG_MASK) | TERM_BOXED_INTEGER_SIGN_BIT) |
| 450 | + == TERM_BOXED_NEGATIVE_INTEGER) { |
447 | 451 | return true;
|
448 | 452 | }
|
449 | 453 | }
|
@@ -819,16 +823,18 @@ static inline avm_int64_t term_maybe_unbox_int64(term maybe_boxed_int)
|
819 | 823 |
|
820 | 824 | static inline term term_make_boxed_int(avm_int_t value, Heap *heap)
|
821 | 825 | {
|
| 826 | + avm_uint_t sign = (((avm_uint_t) value) >> (TERM_BITS - 1)) << TERM_BOXED_INTEGER_SIGN_BIT_POS; |
822 | 827 | term *boxed_int = memory_heap_alloc(heap, 1 + BOXED_TERMS_REQUIRED_FOR_INT);
|
823 |
| - boxed_int[0] = (BOXED_TERMS_REQUIRED_FOR_INT << 6) | TERM_BOXED_POSITIVE_INTEGER; // OR sign bit |
| 828 | + boxed_int[0] = (BOXED_TERMS_REQUIRED_FOR_INT << 6) | TERM_BOXED_POSITIVE_INTEGER | sign; |
824 | 829 | boxed_int[1] = value;
|
825 | 830 | return ((term) boxed_int) | TERM_BOXED_VALUE_TAG;
|
826 | 831 | }
|
827 | 832 |
|
828 | 833 | static inline term term_make_boxed_int64(avm_int64_t large_int64, Heap *heap)
|
829 | 834 | {
|
| 835 | + avm_uint64_t sign = (((avm_uint64_t) large_int64) >> 63) << TERM_BOXED_INTEGER_SIGN_BIT_POS; |
830 | 836 | term *boxed_int = memory_heap_alloc(heap, 1 + BOXED_TERMS_REQUIRED_FOR_INT64);
|
831 |
| - boxed_int[0] = (BOXED_TERMS_REQUIRED_FOR_INT64 << 6) | TERM_BOXED_POSITIVE_INTEGER; // OR sign bit |
| 837 | + boxed_int[0] = (BOXED_TERMS_REQUIRED_FOR_INT64 << 6) | TERM_BOXED_POSITIVE_INTEGER | sign; |
832 | 838 | #if BOXED_TERMS_REQUIRED_FOR_INT64 == 1
|
833 | 839 | boxed_int[1] = large_int64;
|
834 | 840 | #elif BOXED_TERMS_REQUIRED_FOR_INT64 == 2
|
|
0 commit comments