From: Alyssa Rosenzweig Date: Tue, 5 May 2020 22:20:08 +0000 (-0400) Subject: pan/bi: Add helper to measure clause size X-Git-Url: https://git.libre-soc.org/?p=mesa.git;a=commitdiff_plain;h=b3ae088b96d9242d7d0fabde0516ccd76279ffd5 pan/bi: Add helper to measure clause size Useful for branching. Signed-off-by: Alyssa Rosenzweig Part-of: --- diff --git a/src/panfrost/bifrost/bi_layout.c b/src/panfrost/bifrost/bi_layout.c index cc40d0398f9..1c700b13840 100644 --- a/src/panfrost/bifrost/bi_layout.c +++ b/src/panfrost/bifrost/bi_layout.c @@ -49,3 +49,43 @@ bi_can_insert_bundle(bi_clause *clause, bool constant) return (constant_count + bundle_count) <= 13; } + +/* Helper to calculate the number of quadwords in a clause. This is a function + * of the number of instructions and constants; it doesn't require actually + * packing, which is useful for branch offsets. + * + * Table of instruction count to instruction quadwords, per the packing + * algorithm, where * indicates a constant is packed for free: + * + * X | Y + * ---|--- + * 1 | 1 + * 2 | 2 + * 3 | 3* + * 4 | 3 + * 5 | 4* + * 6 | 5* + * 7 | 5 + * 8 | 6* + * + * Y = { X if X <= 3 + * { X - 1 if 4 <= X <= 6 + * { X - 2 if 7 <= X <= 8 + * + * and there is a constant for free if X is in {3, 5, 6, 8}. The remaining + * constants are packed two-by-two as constant quadwords. + */ + +unsigned +bi_clause_quadwords(bi_clause *clause) +{ + unsigned X = clause->bundle_count; + unsigned Y = X - ((X >= 7) ? 2 : (X >= 4) ? 1 : 0); + + unsigned constants = clause->constant_count; + + if ((X != 4) && (X != 7) && (X >= 3) && constants) + constants--; + + return Y + DIV_ROUND_UP(constants, 2); +} diff --git a/src/panfrost/bifrost/compiler.h b/src/panfrost/bifrost/compiler.h index eda8694079f..b1f7887e587 100644 --- a/src/panfrost/bifrost/compiler.h +++ b/src/panfrost/bifrost/compiler.h @@ -584,6 +584,7 @@ bool bi_is_live_after(bi_context *ctx, bi_block *block, bi_instruction *start, i /* Layout */ bool bi_can_insert_bundle(bi_clause *clause, bool constant); +unsigned bi_clause_quadwords(bi_clause *clause); /* Code emit */