mirror of
https://github.com/gbdev/rgbds.git
synced 2026-10-06 04:05:38 +00:00
Add POPCOUNT function (#2166)
This commit is contained in:
1 parent
ff6f1699e9
commit
d95e9260e4
13 files changed
+45
-3
No files matched your search
@@ -173,6 +173,7 @@ static UpperMap<int> const keywords{
|
||||
{"ISCONST", T_(OP_ISCONST) },
|
||||
|
||||
{"BITWIDTH", T_(OP_BITWIDTH) },
|
||||
{"POPCOUNT", T_(OP_POPCOUNT) },
|
||||
{"TZCOUNT", T_(OP_TZCOUNT) },
|
||||
|
||||
{"BYTELEN", T_(OP_BYTELEN) },
|
||||
|
||||
@@ -286,6 +286,7 @@
|
||||
%token OP_ISCONST "ISCONST"
|
||||
%token OP_LOG "LOG"
|
||||
%token OP_LOW "LOW"
|
||||
%token OP_POPCOUNT "POPCOUNT"
|
||||
%token OP_POW "POW"
|
||||
%token OP_READFILE "READFILE"
|
||||
%token OP_REVCHAR "REVCHAR"
|
||||
@@ -1396,6 +1397,9 @@ relocexpr_no_str:
|
||||
| OP_BITWIDTH LPAREN relocexpr RPAREN {
|
||||
$$.makeUnaryOp(RPN_BITWIDTH, std::move($3));
|
||||
}
|
||||
| OP_POPCOUNT LPAREN relocexpr RPAREN {
|
||||
$$.makeUnaryOp(RPN_POPCOUNT, std::move($3));
|
||||
}
|
||||
| OP_TZCOUNT LPAREN relocexpr RPAREN {
|
||||
$$.makeUnaryOp(RPN_TZCOUNT, std::move($3));
|
||||
}
|
||||
|
||||
@@ -279,6 +279,9 @@ void Expression::makeUnaryOp(RPNCommand op, Expression &&src) {
|
||||
case RPN_TZCOUNT:
|
||||
data = op_tzcount(val);
|
||||
break;
|
||||
case RPN_POPCOUNT:
|
||||
data = op_popcount(val);
|
||||
break;
|
||||
// LCOV_EXCL_START
|
||||
default:
|
||||
// `makeUnaryOp` should never be called with a non-unary operator!
|
||||
|
||||
@@ -182,6 +182,9 @@ static int32_t computeRPNExpr(Patch const &patch, std::vector<Symbol> const &fil
|
||||
case RPN_TZCOUNT:
|
||||
value = op_tzcount(popRPN(patch));
|
||||
break;
|
||||
case RPN_POPCOUNT:
|
||||
value = op_popcount(popRPN(patch));
|
||||
break;
|
||||
|
||||
case RPN_OR:
|
||||
value = popRPN(patch) | popRPN(patch);
|
||||
|
||||
@@ -141,3 +141,7 @@ int32_t op_bitwidth(int32_t value) {
|
||||
int32_t op_tzcount(int32_t value) {
|
||||
return value != 0 ? ctz(static_cast<uint32_t>(value)) : 32;
|
||||
}
|
||||
|
||||
int32_t op_popcount(int32_t value) {
|
||||
return popcount(static_cast<uint32_t>(value));
|
||||
}
|
||||
Reference in new issue
Block a user