Skip to content

Commit

Permalink
Actually use new nqp::const::DEFCON constants
Browse files Browse the repository at this point in the history
Reduces bytecode size, and reduces runtime cost of needing to
initialize native ints each time.
  • Loading branch information
lizmat committed Mar 6, 2024
1 parent 193b3b0 commit c283942
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 24 deletions.
27 changes: 11 additions & 16 deletions src/Perl6/bootstrap.c/BOOTSTRAP.nqp
Original file line number Diff line number Diff line change
Expand Up @@ -3273,10 +3273,6 @@ BEGIN {
my int $SLURPY_ARITY := 1073741824; # 1 +< 30
my int $EDGE_REMOVAL_TODO := -1;
my int $EDGE_REMOVED := -2;
my int $DEFCON_NONE := 0;
my int $DEFCON_DEFINED := 1;
my int $DEFCON_UNDEFINED := 2;
my int $DEFCON_MASK := 3; # DEFINED +| UNDEFINED
my int $TYPE_NATIVE_INT := 4;
my int $TYPE_NATIVE_NUM := 8;
my int $TYPE_NATIVE_STR := 16;
Expand Down Expand Up @@ -3550,12 +3546,16 @@ BEGIN {

if $flags +& nqp::const::SIG_ELEM_DEFINED_ONLY {
nqp::bindpos_i(
@type_flags, $significant_param, $DEFCON_DEFINED
@type_flags,
$significant_param,
nqp::const::DEFCON_DEFINED
);
}
elsif $flags +& nqp::const::SIG_ELEM_UNDEFINED_ONLY {
nqp::bindpos_i(
@type_flags, $significant_param, $DEFCON_UNDEFINED
@type_flags,
$significant_param,
nqp::const::DEFCON_UNDEFINED
);
}

Expand Down Expand Up @@ -3739,9 +3739,6 @@ BEGIN {

Routine.HOW.add_method(Routine, 'find_best_dispatchee',
nqp::getstaticcode(sub ($self, $capture, int $many = 0) {
my int $DEFCON_DEFINED := 1;
my int $DEFCON_UNDEFINED := 2;
my int $DEFCON_MASK := $DEFCON_DEFINED +| $DEFCON_UNDEFINED;
my int $TYPE_NATIVE_INT := 4;
my int $TYPE_NATIVE_NUM := 8;
my int $TYPE_NATIVE_STR := 16;
Expand Down Expand Up @@ -3916,10 +3913,11 @@ BEGIN {
# Check for definedness if it still makes sense
if $no_mismatch {
$no_mismatch := 0
if (my int $mask := $flags +& $DEFCON_MASK)
if (my int $mask :=
$flags +& nqp::const::DEFCON_MASK)
&& ($primish || nqp::isconcrete($arg)
?? $DEFCON_DEFINED
!! $DEFCON_UNDEFINED
?? nqp::const::DEFCON_DEFINED
!! nqp::const::DEFCON_UNDEFINED
) != $mask
}
}
Expand Down Expand Up @@ -4207,9 +4205,6 @@ BEGIN {
my $MD_CT_NO_WAY := -1; # Proved it'd never manage to dispatch.

# Other constants we need.
my int $DEFCON_DEFINED := 1;
my int $DEFCON_UNDEFINED := 2;
my int $DEFCON_MASK := $DEFCON_DEFINED +| $DEFCON_UNDEFINED;
my int $TYPE_NATIVE_INT := 4;
my int $TYPE_NATIVE_NUM := 8;
my int $TYPE_NATIVE_STR := 16;
Expand Down Expand Up @@ -4344,7 +4339,7 @@ BEGIN {
last;
}
}
elsif $type_flags +& $DEFCON_MASK {
elsif $type_flags +& nqp::const::DEFCON_MASK {
$used_defcon := 1;
}
}
Expand Down
18 changes: 10 additions & 8 deletions src/vm/moar/dispatchers.nqp
Original file line number Diff line number Diff line change
Expand Up @@ -2098,9 +2098,6 @@ my class MultiDispatchNonScalar {
# mode. A resumption of a trivial dispatch will call this again, but with that
# flag not set, and then drop the first candidate from the plan, which was
# already invoked. It will then walk the candidate list as usual.
my int $DEFCON_DEFINED := 1;
my int $DEFCON_UNDEFINED := 2;
my int $DEFCON_MASK := $DEFCON_DEFINED +| $DEFCON_UNDEFINED;
my int $TYPE_NATIVE_INT := 4;
my int $TYPE_NATIVE_UINT := 32;
my int $TYPE_NATIVE_NUM := 8;
Expand Down Expand Up @@ -2266,7 +2263,8 @@ sub raku-multi-plan(
nqp::atkey($cur_candidate, 'rwness'), $i
);

my int $definedness := $type_flags +& $DEFCON_MASK;
my int $definedness :=
$type_flags +& nqp::const::DEFCON_MASK;

# Get the primitive type of the argument, and go on
# whether it's an object or primitive type
Expand All @@ -2277,8 +2275,10 @@ sub raku-multi-plan(
if $got_prim {

# Read/write and type object incompatible with natives
if $rwness # want rw, we ain't got it
|| $definedness == $DEFCON_UNDEFINED { # type object
# want rw, we ain't got it
if $rwness
# type object
|| $definedness == nqp::const::DEFCON_UNDEFINED {
$rwness_mismatch := 1;
}

Expand Down Expand Up @@ -2429,8 +2429,10 @@ sub raku-multi-plan(
my int $got := $promoted_primitive
|| nqp::isconcrete_nd($value);
$type_mismatch := 1
if ( $got && $definedness == $DEFCON_UNDEFINED)
|| (!$got && $definedness == $DEFCON_DEFINED );
if ( $got && $definedness ==
nqp::const::DEFCON_UNDEFINED)
|| (!$got && $definedness ==
nqp::const::DEFCON_DEFINED );
nqp::bindpos_i($need_conc_guard, $i, 1);
}
}
Expand Down

0 comments on commit c283942

Please sign in to comment.