filled stix_bitatint() a bit

This commit is contained in:
hyunghwan.chung 2015-12-26 01:37:33 +00:00
parent 27e0186d43
commit 60b90de172
5 changed files with 21 additions and 8 deletions

View File

@ -116,7 +116,8 @@
#method bitAt: index #method bitAt: index
{ {
"## index 1 - least significant bit" "## index is 1-based"
<primitive: #_integer_bitat>
^(self bitShift: (index - 1) negated) bitAnd: 1. ^(self bitShift: (index - 1) negated) bitAnd: 1.
} }

View File

@ -378,7 +378,7 @@ PROCESS TESTING
((-2r1000000000000000000000000000100000000000000000000000000000000000000000000000 bitShift: 13) printStringRadix: 2) dump. ((-2r1000000000000000000000000000100000000000000000000000000000000000000000000000 bitShift: 13) printStringRadix: 2) dump.
((2r1000000000000000000000000000100000000000000000000000000000000000000000000000 bitShift: 13) printStringRadix: 2) dump. ((2r1000000000000000000000000000100000000000000000000000000000000000000000000000 bitShift: 13) printStringRadix: 2) dump.
((-2r1111 bitAt: 6) printStringRadix: 2) dump. ((-2r10 bitAt: 1) printStringRadix: 2) dump.
" "
FFI isNil dump. FFI isNil dump.

View File

@ -1592,6 +1592,23 @@ stix_oop_t stix_bitatint (stix_t* stix, stix_oop_t x, stix_oop_t y)
{ {
if (STIX_OOP_IS_SMOOI(x) && STIX_OOP_IS_SMOOI(y)) if (STIX_OOP_IS_SMOOI(x) && STIX_OOP_IS_SMOOI(y))
{ {
stix_ooi_t v1, v2, v3;
v1 = STIX_OOP_TO_SMOOI(x);
v2 = STIX_OOP_TO_SMOOI(y);
if (v2 <= 0) return STIX_SMOOI_TO_OOP(0);
if (v1 >= 0)
{
if (v2 >= XXXXXXXXXX) return STIX_SMOOI_TO_OOP(0);
v3 = ((stix_oow_t)v1 >> (v2 - 1)) & 1;
}
else
{
if (v2 >= XXXXXXXXXX) return STIX_SMOOI_TO_OOP(-1);
v3 = ((~(stix_oow_t)-v1 + 1) >> (v2 - 1)) & 1;
}
return STIX_SMOOI_TO_OOP(v3);
} }
else else
{ {

View File

@ -1208,7 +1208,7 @@ static int prim_integer_bitat (stix_t* stix, stix_ooi_t nargs)
{ {
stix_oop_t rcv, arg, res; stix_oop_t rcv, arg, res;
STIX_ASSERT (nargs == 2); STIX_ASSERT (nargs == 1);
rcv = ACTIVE_STACK_GET(stix, stix->sp - 1); rcv = ACTIVE_STACK_GET(stix, stix->sp - 1);
arg = ACTIVE_STACK_GET(stix, stix->sp); arg = ACTIVE_STACK_GET(stix, stix->sp);

View File

@ -58,11 +58,6 @@
#endif #endif
#if STIX_SIZEOF___INT128_T > 0
# undef STIX_SIZEOF___INT128_T
# define STIX_SIZEOF___INT128_T 0
#endif
/* ========================================================================= /* =========================================================================
* PRIMITIVE TYPE DEFINTIONS * PRIMITIVE TYPE DEFINTIONS
* ========================================================================= */ * ========================================================================= */