Skip to content

Commit

Permalink
[core] part 2 of labs GH #1111
Browse files Browse the repository at this point in the history
only use labs() on 64-bit.
also use it with Integer.absolute
  • Loading branch information
Reini Urban committed Nov 6, 2014
1 parent fad80cf commit a986981
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/ops/core_ops.c
Expand Up @@ -17242,7 +17242,7 @@ Parrot_getstderr_p(opcode_t *cur_opcode, PARROT_INTERP) {

opcode_t *
Parrot_abs_i(opcode_t *cur_opcode, PARROT_INTERP) {
#if defined(PARROT_HAS_LABS)
#if defined(PARROT_HAS_LABS) && (INTVAL_SIZE == 8)
IREG(1) = labs(IREG(1));

#else
Expand All @@ -17261,7 +17261,7 @@ Parrot_abs_n(opcode_t *cur_opcode, PARROT_INTERP) {

opcode_t *
Parrot_abs_i_i(opcode_t *cur_opcode, PARROT_INTERP) {
#if defined(PARROT_HAS_LABS)
#if defined(PARROT_HAS_LABS) && (INTVAL_SIZE == 8)
IREG(1) = labs(IREG(2));

#else
Expand Down
4 changes: 2 additions & 2 deletions src/ops/math.ops
Expand Up @@ -46,7 +46,7 @@ Set $1 to absolute value of $2.
=cut

inline op abs(inout INT) {
#ifdef PARROT_HAS_LABS
#if defined(PARROT_HAS_LABS) && (INTVAL_SIZE == 8)
$1 = labs($1);
#else
$1 = abs($1);
Expand All @@ -58,7 +58,7 @@ inline op abs(inout NUM) {
}

inline op abs(out INT, in INT) {
#ifdef PARROT_HAS_LABS
#if defined(PARROT_HAS_LABS) && (INTVAL_SIZE == 8)
$1 = labs($2);
#else
$1 = abs($2);
Expand Down
21 changes: 16 additions & 5 deletions src/pmc/integer.pmc
Expand Up @@ -1226,9 +1226,14 @@ is the minimum integer, a BigInt is created.
VTABLE PMC *absolute(PMC *dest) :no_wb {
const INTVAL a = SELF.get_integer();

if (a != PARROT_INTVAL_MIN)
return Parrot_pmc_new_init_int(INTERP, VTABLE_type(INTERP, SELF),
abs(a));
if (a != PARROT_INTVAL_MIN) {
#if defined(PARROT_HAS_LABS) && (INTVAL_SIZE == 8)
UINTVAL ua = labs(a);
#else
UINTVAL ua = abs(a);
#endif
return Parrot_pmc_new_init_int(INTERP, VTABLE_type(INTERP, SELF), ua);
}
else {
PMC *promoted;
maybe_throw_overflow_error(INTERP);
Expand All @@ -1241,8 +1246,14 @@ is the minimum integer, a BigInt is created.
VTABLE void i_absolute() :manual_wb {
const INTVAL a = SELF.get_integer();

if (a != PARROT_INTVAL_MIN)
VTABLE_set_integer_native(INTERP, SELF, abs(a));
if (a != PARROT_INTVAL_MIN) {
#if defined(PARROT_HAS_LABS) && (INTVAL_SIZE == 8)
UINTVAL ua = labs(a);
#else
UINTVAL ua = abs(a);
#endif
VTABLE_set_integer_native(INTERP, SELF, ua);
}
else {
maybe_throw_overflow_error(INTERP);
SELF = upgrade_self_to_bignum(INTERP, SELF);
Expand Down

0 comments on commit a986981

Please sign in to comment.