Skip to content

Instantly share code, notes, and snippets.

@cygx
Created October 8, 2016 18:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cygx/fec5e5aa03df84483e81fb5c25a74131 to your computer and use it in GitHub Desktop.
Save cygx/fec5e5aa03df84483e81fb5c25a74131 to your computer and use it in GitHub Desktop.
sub round-up-to-multi($i, $m) {
(($i + $m - 1) div $m) * $m
}
sub compute-sa(+@_) {
my $size = 0;
my $align = 0;
for @_ -> ($s, $a) {
$size = round-up-to-multi($size, $a) + $s;
$align = $a if $a > $align;
}
$size = round-up-to-multi($size, $align);
($size, $align);
}
say compute-sa <4 4>, <3 1>, <2 2>;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment