Created
November 30, 2012 21:31
-
-
Save skids/4178797 to your computer and use it in GitHub Desktop.
A fix for tomath repr right shifts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Cargo-culted fix for right shift issues in nqp_bigint.ops. */ | |
/* This could be done better in a way that doesn't dirty so much write cache | |
for huge shifts/values, since the results are calculatable without actually | |
performing additions across the whole number. */ | |
inline op nqp_bigint_shr(out PMC, invar PMC, in INT, invar PMC) :base_core { | |
mp_int b; | |
mp_int *a = get_bigint(interp, $2); | |
mp_init((&b)); | |
mp_copy(a,(&b)); | |
if (MP_NEG == SIGN(a)) { | |
/* deal with two's complement one-offness */ | |
mp_add_d((&b),1,(&b)); | |
} | |
$1 = REPR($4)->allocate(interp, STABLE($4)); | |
REPR($1)->initialize(interp, STABLE($1), OBJECT_BODY($1)); | |
mp_div_2d((&b), $3, (&b), NULL); | |
if (MP_NEG == SIGN(a)) { | |
mp_sub_d((&b),1,(&b)); | |
} | |
mp_copy((&b),get_bigint(interp, $1)); | |
mp_clear((&b)); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment