Mesa (master): nir: Add bit_count to lower_int64 pass
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Thu Aug 27 17:32:04 UTC 2020
Module: Mesa
Branch: master
Commit: a54695ddcb26b4437c361d7df8c93f6b8a990e27
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=a54695ddcb26b4437c361d7df8c93f6b8a990e27
Author: Jesse Natalie <jenatali at microsoft.com>
Date: Tue Jun 23 05:47:20 2020 -0700
nir: Add bit_count to lower_int64 pass
Reviewed-by: Boris Brezillon <boris.brezillon at collabora.com>
Reviewed-by: Jason Ekstrand <jason at jlekstrand.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6313>
---
src/compiler/nir/nir.h | 1 +
src/compiler/nir/nir_lower_int64.c | 15 +++++++++++++++
2 files changed, 16 insertions(+)
diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h
index 3bfc2d1333b..e72b01b7158 100644
--- a/src/compiler/nir/nir.h
+++ b/src/compiler/nir/nir.h
@@ -2998,6 +2998,7 @@ typedef enum {
nir_lower_imul_2x32_64 = (1 << 12),
nir_lower_extract64 = (1 << 13),
nir_lower_ufind_msb64 = (1 << 14),
+ nir_lower_bit_count64 = (1 << 15),
} nir_lower_int64_options;
typedef enum {
diff --git a/src/compiler/nir/nir_lower_int64.c b/src/compiler/nir/nir_lower_int64.c
index e780948c37d..07b307ea461 100644
--- a/src/compiler/nir/nir_lower_int64.c
+++ b/src/compiler/nir/nir_lower_int64.c
@@ -785,6 +785,16 @@ lower_f2(nir_builder *b, nir_ssa_def *x, bool dst_is_signed)
return res;
}
+static nir_ssa_def *
+lower_bit_count64(nir_builder *b, nir_ssa_def *x)
+{
+ nir_ssa_def *x_lo = nir_unpack_64_2x32_split_x(b, x);
+ nir_ssa_def *x_hi = nir_unpack_64_2x32_split_y(b, x);
+ nir_ssa_def *lo_count = nir_bit_count(b, x_lo);
+ nir_ssa_def *hi_count = nir_bit_count(b, x_hi);
+ return nir_iadd(b, lo_count, hi_count);
+}
+
nir_lower_int64_options
nir_lower_int64_op_to_options_mask(nir_op opcode)
{
@@ -859,6 +869,8 @@ nir_lower_int64_op_to_options_mask(nir_op opcode)
return nir_lower_extract64;
case nir_op_ufind_msb:
return nir_lower_ufind_msb64;
+ case nir_op_bit_count:
+ return nir_lower_bit_count64;
default:
return 0;
}
@@ -963,6 +975,8 @@ lower_int64_alu_instr(nir_builder *b, nir_instr *instr, void *_state)
return lower_extract(b, alu->op, src[0], src[1]);
case nir_op_ufind_msb:
return lower_ufind_msb64(b, src[0]);
+ case nir_op_bit_count:
+ return lower_bit_count64(b, src[0]);
case nir_op_i2f64:
case nir_op_i2f32:
case nir_op_i2f16:
@@ -1028,6 +1042,7 @@ should_lower_int64_alu_instr(const nir_instr *instr, const void *_data)
return false;
break;
case nir_op_ufind_msb:
+ case nir_op_bit_count:
assert(alu->src[0].src.is_ssa);
if (alu->src[0].src.ssa->bit_size != 64)
return false;
More information about the mesa-commit
mailing list