Skip to content

Commit

Permalink
shorten generated code with broadcastloop start/end macros
Browse files Browse the repository at this point in the history
  • Loading branch information
mohawk2 committed Mar 19, 2023
1 parent 4464903 commit e3718fa
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions Basic/Gen/PP/PDLCode.pm
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,14 @@ sub new {
'PDL_COMMENT("dims here are how many steps along those dims")',
(map "register PDL_Indx __tinc0_$parnames->[$_] = PDL_BRC_INC(\$PRIV(broadcast).incs,__tnpdls,$_,0);", 0..$#$parnames),
(map "register PDL_Indx __tinc1_$parnames->[$_] = PDL_BRC_INC(\$PRIV(broadcast).incs,__tnpdls,$_,1);", 0..$#$parnames),
eol_protect(
"#define ".$this->broadcastloop_macroname($backcode, 'START') . " " .
$this->broadcastloop_start($this->func_name($backcode))
)."\n",
eol_protect(
"#define ".$this->broadcastloop_macroname($backcode, 'END') . " " .
$this->broadcastloop_end
)."\n",
).
$this->params_declare.
join('',map $_->get_incregisters, @$pobjs{sort keys %$pobjs}).
Expand All @@ -169,6 +177,11 @@ sub new {

} # new()

sub eol_protect {
my ($text) = @_;
join " \\\n", split /\n/, $text;
}

sub params_declare {
my ($this) = @_;
my ($ord,$pdls) = $this->get_pdls;
Expand All @@ -185,6 +198,11 @@ EOF

sub func_name { $_[1] ? "writebackdata" : "readdata" }

sub broadcastloop_macroname {
my ($this, $backcode, $which) = @_;
"PDL_BROADCASTLOOP_${which}_$this->{Name}_".$this->func_name($backcode);
}

sub broadcastloop_start {
my ($this, $funcname) = @_;
my ($ord,$pdls) = $this->get_pdls;
Expand Down Expand Up @@ -547,11 +565,11 @@ sub new {
sub myoffs { return 0; }
sub myprelude {
my($this,$parent,$context,$backcode) = @_;
$parent->broadcastloop_start($parent->func_name($backcode));
$parent->broadcastloop_macroname($backcode, 'START') . "\n";
}

sub mypostlude {my($this,$parent,$context,$backcode) = @_;
$parent->broadcastloop_end;
$parent->broadcastloop_macroname($backcode, 'END') . "\n";
}

# Simple subclass of BroadcastLoop to implement writeback code
Expand Down

0 comments on commit e3718fa

Please sign in to comment.