Skip to content

Commit 99e48e6

Browse files
committed
Merge pull request #1952 from bettio/remove-useless-optimization
Remove useless optimization 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 f7676a8 + bdcfbe0 commit 99e48e6

File tree

3 files changed

+4
-88
lines changed

3 files changed

+4
-88
lines changed

src/libAtomVM/externalterm.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,13 +222,12 @@ static int serialize_term(uint8_t *buf, term t, GlobalContext *glb)
222222
}
223223
return INTEGER_EXT_SIZE;
224224
} else {
225-
bool is_negative;
226-
avm_uint64_t unsigned_val = int64_safe_unsigned_abs_set_flag(val, &is_negative);
225+
avm_uint64_t unsigned_val = int64_safe_unsigned_abs(val);
227226
uint8_t num_bytes = get_num_bytes(unsigned_val);
228227
if (buf != NULL) {
229228
buf[0] = SMALL_BIG_EXT;
230229
buf[1] = num_bytes;
231-
buf[2] = is_negative ? 0x01 : 0x00;
230+
buf[2] = val < 0 ? 0x01 : 0x00;
232231
write_bytes(buf + 3, unsigned_val);
233232
}
234233
return SMALL_BIG_EXT_BASE_SIZE + num_bytes;

src/libAtomVM/intn.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -917,9 +917,8 @@ static inline void intn_from_uint64(uint64_t absu64, intn_digit_t out[])
917917
*/
918918
static inline void intn_from_int64(int64_t i64, intn_digit_t out[], intn_integer_sign_t *out_sign)
919919
{
920-
bool is_negative;
921-
uint64_t absu64 = int64_safe_unsigned_abs_set_flag(i64, &is_negative);
922-
*out_sign = is_negative ? IntNNegativeInteger : IntNPositiveInteger;
920+
uint64_t absu64 = int64_safe_unsigned_abs(i64);
921+
*out_sign = i64 < 0 ? IntNNegativeInteger : IntNPositiveInteger;
923922
intn_from_uint64(absu64, out);
924923
}
925924

src/libAtomVM/utils.h

Lines changed: 0 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -621,88 +621,6 @@ static inline uint64_t int64_safe_unsigned_abs(int64_t i64)
621621
return (i64 < 0) ? ((uint64_t) - (i64 + 1)) + 1 : (uint64_t) i64;
622622
}
623623

624-
/**
625-
* @brief Check if 32-bit signed integer (\c int32_t) is negative
626-
*
627-
* Efficient predicate to test if a 32-bit signed integer is negative,
628-
* equivalent to \c (i32 < 0).
629-
*
630-
* @param i32 Signed 32-bit integer to test
631-
* @return true if negative, false if zero or positive
632-
*/
633-
static inline bool int32_is_negative(int32_t i32)
634-
{
635-
return ((uint32_t) i32) >> 31;
636-
}
637-
638-
/**
639-
* @brief Check if 64-bit signed integer (\c int64_t) is negative
640-
*
641-
* Efficient predicate to test if a 64-bit signed integer is negative,
642-
* equivalent to (i64 < 0).
643-
*
644-
* @param i64 Signed 64-bit integer to test
645-
* @return true if negative, false if zero or positive
646-
*/
647-
static inline bool int64_is_negative(int64_t i64)
648-
{
649-
return ((uint64_t) i64) >> 63;
650-
}
651-
652-
/**
653-
* @brief Get absolute value as uint32_t and sign of 32-bit integer
654-
*
655-
* Computes the absolute value of a signed 32-bit integer (\c int32_t) as
656-
* unsigned (\c uint32_t) and sets a flag indicating whether the original
657-
* value was negative. Combines sign extraction and absolute value computation
658-
* for efficiency. Commonly used when serializing integers where the sign is
659-
* stored separately from the magnitude.
660-
*
661-
* @param i32 Signed integer to process
662-
* @param[out] is_negative Set to true if i32 is negative, false otherwise
663-
* @return Absolute value as unsigned 32-bit integer (\c uint32_t)
664-
*
665-
* @pre is_negative != NULL
666-
*
667-
* @note Useful for integer formatting and parsing operations
668-
* @note Handles \c INT32_MIN correctly
669-
*
670-
* @see int32_safe_unsigned_abs() for absolute value without sign flag
671-
* @see int32_is_negative() for sign checking only
672-
*/
673-
static inline uint32_t int32_safe_unsigned_abs_set_flag(int32_t i32, bool *is_negative)
674-
{
675-
*is_negative = int32_is_negative(i32);
676-
return int32_safe_unsigned_abs(i32);
677-
}
678-
679-
/**
680-
* @brief Get absolute value as uint64_t and sign of 64-bit integer
681-
*
682-
* Computes the absolute value of a signed 64-bit integer (\c int64_t) as
683-
* unsigned (\c uint64_t) and sets a flag indicating whether the original
684-
* value was negative. Combines sign extraction and absolute value computation
685-
* for efficiency. Commonly used when serializing integers where the sign is
686-
* stored separately from the magnitude.
687-
*
688-
* @param i64 Signed integer to process
689-
* @param[out] is_negative Set to true if i64 is negative, false otherwise
690-
* @return Absolute value as unsigned 64-bit integer (\c uint64_t)
691-
*
692-
* @pre is_negative != NULL
693-
*
694-
* @note Useful for integer formatting and parsing operations
695-
* @note Handles \c INT64_MIN correctly
696-
*
697-
* @see int64_safe_unsigned_abs() for absolute value without sign flag
698-
* @see int64_is_negative() for sign checking only
699-
*/
700-
static inline uint64_t int64_safe_unsigned_abs_set_flag(int64_t i64, bool *is_negative)
701-
{
702-
*is_negative = int64_is_negative(i64);
703-
return int64_safe_unsigned_abs(i64);
704-
}
705-
706624
/**
707625
* @brief Perform arithmetic right shift on 32-bit signed integer (\c int32_t)
708626
*

0 commit comments

Comments
 (0)