2018-01-23 09:48:43 +08:00
|
|
|
/*
|
|
|
|
|
* Copyright © 2018 Intel Corporation
|
|
|
|
|
*
|
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
|
|
|
*
|
|
|
|
|
* The above copyright notice and this permission notice (including the next
|
|
|
|
|
* paragraph) shall be included in all copies or substantial portions of the
|
|
|
|
|
* Software.
|
|
|
|
|
*
|
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
|
|
|
|
* IN THE SOFTWARE.
|
|
|
|
|
*/
|
2025-08-13 10:56:51 +01:00
|
|
|
#include "nir.h"
|
2018-01-23 09:48:43 +08:00
|
|
|
#include "nir_range_analysis.h"
|
2023-08-08 12:00:35 -05:00
|
|
|
#include <float.h>
|
|
|
|
|
#include <math.h>
|
2018-01-23 09:48:43 +08:00
|
|
|
#include "util/hash_table.h"
|
2023-02-14 21:42:22 +00:00
|
|
|
#include "util/u_dynarray.h"
|
2023-08-08 12:00:35 -05:00
|
|
|
#include "util/u_math.h"
|
2023-03-27 16:29:32 -04:00
|
|
|
#include "c99_alloca.h"
|
2018-01-23 09:48:43 +08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Analyzes a sequence of operations to determine some aspects of the range of
|
|
|
|
|
* the result.
|
|
|
|
|
*/
|
|
|
|
|
|
2023-02-14 21:42:22 +00:00
|
|
|
struct analysis_query {
|
|
|
|
|
uint32_t pushed_queries;
|
|
|
|
|
uint32_t result_index;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct analysis_state {
|
|
|
|
|
nir_shader *shader;
|
2026-03-02 16:20:26 +00:00
|
|
|
void *range_ht;
|
2023-02-14 21:42:22 +00:00
|
|
|
|
|
|
|
|
struct util_dynarray query_stack;
|
|
|
|
|
struct util_dynarray result_stack;
|
|
|
|
|
|
|
|
|
|
size_t query_size;
|
2026-03-02 16:20:26 +00:00
|
|
|
uint32_t (*get_key)(struct analysis_query *q);
|
|
|
|
|
bool (*lookup)(void *table, uint32_t key, uint32_t *value);
|
|
|
|
|
void (*insert)(void *table, uint32_t key, uint32_t value);
|
2023-02-14 21:42:22 +00:00
|
|
|
void (*process_query)(struct analysis_state *state, struct analysis_query *q,
|
|
|
|
|
uint32_t *result, const uint32_t *src);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static void *
|
|
|
|
|
push_analysis_query(struct analysis_state *state, size_t size)
|
|
|
|
|
{
|
|
|
|
|
struct analysis_query *q = util_dynarray_grow_bytes(&state->query_stack, 1, size);
|
|
|
|
|
q->pushed_queries = 0;
|
|
|
|
|
q->result_index = util_dynarray_num_elements(&state->result_stack, uint32_t);
|
|
|
|
|
|
util/dynarray: infer type in append
Most of the time, we can infer the type to append in
util_dynarray_append using __typeof__, which is standardized in C23 and
support in Jesse's MSMSVCV. This patch drops the type argument most of
the time, making util_dynarray a little more ergonomic to use.
This is done in four steps.
First, rename util_dynarray_append -> util_dynarray_append_typed
bash -c "find . -type f -exec sed -i -e 's/util_dynarray_append(/util_dynarray_append_typed(/g' \{} \;"
Then, add a new append that infers the type. This is much more ergonomic
for what you want most of the time.
Next, use type-inferred append as much as possible, via Coccinelle
patch (plus manual fixup):
@@
expression dynarray, element;
type type;
@@
-util_dynarray_append_typed(dynarray, type, element);
+util_dynarray_append(dynarray, element);
Finally, hand fixup cases that Coccinelle missed or incorrectly
translated, of which there were several because we can't used the
untyped append with a literal (since the sizeof won't do what you want).
All four steps are squashed to produce a single patch changing every
util_dynarray_append call site in tree to either drop a type parameter
(if possible) or insert a _typed suffix (if we can't infer). As such,
the final patch is best reviewed by hand even though it was
tool-assisted.
No Long Linguine Meals were involved in the making of this patch.
Signed-off-by: Alyssa Rosenzweig <alyssa.rosenzweig@intel.com>
Acked-by: Faith Ekstrand <faith.ekstrand@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/38038>
2025-10-23 15:36:13 -04:00
|
|
|
util_dynarray_append_typed(&state->result_stack, uint32_t, 0);
|
2023-02-14 21:42:22 +00:00
|
|
|
|
|
|
|
|
return q;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Helper for performing range analysis without recursion. */
|
|
|
|
|
static uint32_t
|
|
|
|
|
perform_analysis(struct analysis_state *state)
|
|
|
|
|
{
|
|
|
|
|
while (state->query_stack.size) {
|
|
|
|
|
struct analysis_query *cur =
|
2023-08-08 12:00:35 -05:00
|
|
|
(struct analysis_query *)((char *)util_dynarray_end(&state->query_stack) - state->query_size);
|
2023-02-14 21:42:22 +00:00
|
|
|
uint32_t *result = util_dynarray_element(&state->result_stack, uint32_t, cur->result_index);
|
|
|
|
|
|
2026-03-02 16:20:26 +00:00
|
|
|
uint32_t key = state->get_key(cur);
|
2023-02-14 21:42:22 +00:00
|
|
|
/* There might be a cycle-resolving entry for loop header phis. Ignore this when finishing
|
|
|
|
|
* them by testing pushed_queries.
|
|
|
|
|
*/
|
2026-03-02 16:20:26 +00:00
|
|
|
if (cur->pushed_queries == 0 && key != UINT32_MAX &&
|
|
|
|
|
state->lookup(state->range_ht, key, result)) {
|
2023-02-14 21:42:22 +00:00
|
|
|
state->query_stack.size -= state->query_size;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-08 12:00:35 -05:00
|
|
|
uint32_t *src = (uint32_t *)util_dynarray_end(&state->result_stack) - cur->pushed_queries;
|
2023-02-14 21:42:22 +00:00
|
|
|
state->result_stack.size -= sizeof(uint32_t) * cur->pushed_queries;
|
|
|
|
|
|
|
|
|
|
uint32_t prev_num_queries = state->query_stack.size;
|
|
|
|
|
state->process_query(state, cur, result, src);
|
|
|
|
|
|
|
|
|
|
uint32_t num_queries = state->query_stack.size;
|
|
|
|
|
if (num_queries > prev_num_queries) {
|
|
|
|
|
cur = (struct analysis_query *)util_dynarray_element(&state->query_stack, char,
|
|
|
|
|
prev_num_queries - state->query_size);
|
|
|
|
|
cur->pushed_queries = (num_queries - prev_num_queries) / state->query_size;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-02 16:20:26 +00:00
|
|
|
if (key != UINT32_MAX)
|
|
|
|
|
state->insert(state->range_ht, key, *result);
|
2023-02-14 21:42:22 +00:00
|
|
|
|
|
|
|
|
state->query_stack.size -= state->query_size;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
assert(state->result_stack.size == sizeof(uint32_t));
|
|
|
|
|
|
|
|
|
|
uint32_t res = util_dynarray_top(&state->result_stack, uint32_t);
|
|
|
|
|
util_dynarray_fini(&state->query_stack);
|
|
|
|
|
util_dynarray_fini(&state->result_stack);
|
|
|
|
|
|
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
nir: rewrite fp range analysis as a fp class analysis
Knowing if a value is not larger than one helps proving finite
results of fmul/fadd and will allow skipping/creating more fsat.
Knowing that a value is larger than one helps proving non zero
results of fmul.
Separating positive and negative zero also has advantages when
signed zero correctness is required.
Foz-DB Navi48:
Totals from 1344 (1.63% of 82636) affected shaders:
Instrs: 5319389 -> 5312280 (-0.13%); split: -0.14%, +0.01%
CodeSize: 29702516 -> 29665684 (-0.12%); split: -0.13%, +0.01%
Latency: 40694344 -> 40694545 (+0.00%); split: -0.01%, +0.02%
InvThroughput: 7481192 -> 7480403 (-0.01%); split: -0.02%, +0.01%
VClause: 121947 -> 121946 (-0.00%); split: -0.00%, +0.00%
SClause: 104972 -> 104923 (-0.05%); split: -0.05%, +0.00%
Copies: 371098 -> 371092 (-0.00%); split: -0.02%, +0.02%
Branches: 122929 -> 122919 (-0.01%); split: -0.01%, +0.00%
PreSGPRs: 82506 -> 82510 (+0.00%); split: -0.00%, +0.01%
PreVGPRs: 79175 -> 79168 (-0.01%)
VALU: 2906718 -> 2904777 (-0.07%); split: -0.07%, +0.00%
SALU: 726256 -> 723454 (-0.39%); split: -0.39%, +0.00%
VMEM: 205021 -> 205016 (-0.00%)
SMEM: 163972 -> 163916 (-0.03%)
VOPD: 303354 -> 303298 (-0.02%); split: +0.02%, -0.04%
Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/39987>
2026-02-08 23:03:16 +01:00
|
|
|
static fp_class_mask
|
2026-02-07 22:36:25 +01:00
|
|
|
analyze_fp_constant(const nir_load_const_instr *const load)
|
2018-01-23 09:48:43 +08:00
|
|
|
{
|
nir: rewrite fp range analysis as a fp class analysis
Knowing if a value is not larger than one helps proving finite
results of fmul/fadd and will allow skipping/creating more fsat.
Knowing that a value is larger than one helps proving non zero
results of fmul.
Separating positive and negative zero also has advantages when
signed zero correctness is required.
Foz-DB Navi48:
Totals from 1344 (1.63% of 82636) affected shaders:
Instrs: 5319389 -> 5312280 (-0.13%); split: -0.14%, +0.01%
CodeSize: 29702516 -> 29665684 (-0.12%); split: -0.13%, +0.01%
Latency: 40694344 -> 40694545 (+0.00%); split: -0.01%, +0.02%
InvThroughput: 7481192 -> 7480403 (-0.01%); split: -0.02%, +0.01%
VClause: 121947 -> 121946 (-0.00%); split: -0.00%, +0.00%
SClause: 104972 -> 104923 (-0.05%); split: -0.05%, +0.00%
Copies: 371098 -> 371092 (-0.00%); split: -0.02%, +0.02%
Branches: 122929 -> 122919 (-0.01%); split: -0.01%, +0.00%
PreSGPRs: 82506 -> 82510 (+0.00%); split: -0.00%, +0.01%
PreVGPRs: 79175 -> 79168 (-0.01%)
VALU: 2906718 -> 2904777 (-0.07%); split: -0.07%, +0.00%
SALU: 726256 -> 723454 (-0.39%); split: -0.39%, +0.00%
VMEM: 205021 -> 205016 (-0.00%)
SMEM: 163972 -> 163916 (-0.03%)
VOPD: 303354 -> 303298 (-0.02%); split: +0.02%, -0.04%
Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/39987>
2026-02-08 23:03:16 +01:00
|
|
|
fp_class_mask result = 0;
|
2018-01-23 09:48:43 +08:00
|
|
|
|
2026-02-07 22:36:25 +01:00
|
|
|
for (unsigned i = 0; i < load->def.num_components; ++i) {
|
|
|
|
|
const double v = nir_const_value_as_float(load->value[i],
|
2026-02-07 22:15:42 +01:00
|
|
|
load->def.bit_size);
|
2018-01-23 09:48:43 +08:00
|
|
|
|
nir: rewrite fp range analysis as a fp class analysis
Knowing if a value is not larger than one helps proving finite
results of fmul/fadd and will allow skipping/creating more fsat.
Knowing that a value is larger than one helps proving non zero
results of fmul.
Separating positive and negative zero also has advantages when
signed zero correctness is required.
Foz-DB Navi48:
Totals from 1344 (1.63% of 82636) affected shaders:
Instrs: 5319389 -> 5312280 (-0.13%); split: -0.14%, +0.01%
CodeSize: 29702516 -> 29665684 (-0.12%); split: -0.13%, +0.01%
Latency: 40694344 -> 40694545 (+0.00%); split: -0.01%, +0.02%
InvThroughput: 7481192 -> 7480403 (-0.01%); split: -0.02%, +0.01%
VClause: 121947 -> 121946 (-0.00%); split: -0.00%, +0.00%
SClause: 104972 -> 104923 (-0.05%); split: -0.05%, +0.00%
Copies: 371098 -> 371092 (-0.00%); split: -0.02%, +0.02%
Branches: 122929 -> 122919 (-0.01%); split: -0.01%, +0.00%
PreSGPRs: 82506 -> 82510 (+0.00%); split: -0.00%, +0.01%
PreVGPRs: 79175 -> 79168 (-0.01%)
VALU: 2906718 -> 2904777 (-0.07%); split: -0.07%, +0.00%
SALU: 726256 -> 723454 (-0.39%); split: -0.39%, +0.00%
VMEM: 205021 -> 205016 (-0.00%)
SMEM: 163972 -> 163916 (-0.03%)
VOPD: 303354 -> 303298 (-0.02%); split: +0.02%, -0.04%
Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/39987>
2026-02-08 23:03:16 +01:00
|
|
|
if (!isnan(v) && floor(v) != v)
|
|
|
|
|
result |= FP_CLASS_NON_INTEGRAL;
|
2018-01-23 09:48:43 +08:00
|
|
|
|
2026-02-07 22:15:42 +01:00
|
|
|
if (isnan(v))
|
nir: rewrite fp range analysis as a fp class analysis
Knowing if a value is not larger than one helps proving finite
results of fmul/fadd and will allow skipping/creating more fsat.
Knowing that a value is larger than one helps proving non zero
results of fmul.
Separating positive and negative zero also has advantages when
signed zero correctness is required.
Foz-DB Navi48:
Totals from 1344 (1.63% of 82636) affected shaders:
Instrs: 5319389 -> 5312280 (-0.13%); split: -0.14%, +0.01%
CodeSize: 29702516 -> 29665684 (-0.12%); split: -0.13%, +0.01%
Latency: 40694344 -> 40694545 (+0.00%); split: -0.01%, +0.02%
InvThroughput: 7481192 -> 7480403 (-0.01%); split: -0.02%, +0.01%
VClause: 121947 -> 121946 (-0.00%); split: -0.00%, +0.00%
SClause: 104972 -> 104923 (-0.05%); split: -0.05%, +0.00%
Copies: 371098 -> 371092 (-0.00%); split: -0.02%, +0.02%
Branches: 122929 -> 122919 (-0.01%); split: -0.01%, +0.00%
PreSGPRs: 82506 -> 82510 (+0.00%); split: -0.00%, +0.01%
PreVGPRs: 79175 -> 79168 (-0.01%)
VALU: 2906718 -> 2904777 (-0.07%); split: -0.07%, +0.00%
SALU: 726256 -> 723454 (-0.39%); split: -0.39%, +0.00%
VMEM: 205021 -> 205016 (-0.00%)
SMEM: 163972 -> 163916 (-0.03%)
VOPD: 303354 -> 303298 (-0.02%); split: +0.02%, -0.04%
Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/39987>
2026-02-08 23:03:16 +01:00
|
|
|
result |= FP_CLASS_NAN;
|
|
|
|
|
else if (v == -INFINITY)
|
|
|
|
|
result |= FP_CLASS_NEG_INF;
|
|
|
|
|
else if (v < -1.0)
|
|
|
|
|
result |= FP_CLASS_LT_NEG_ONE;
|
|
|
|
|
else if (v == -1.0)
|
|
|
|
|
result |= FP_CLASS_NEG_ONE;
|
|
|
|
|
else if (v < 0.0)
|
|
|
|
|
result |= FP_CLASS_LT_ZERO_GT_NEG_ONE;
|
|
|
|
|
else if (dui(v) == 0)
|
|
|
|
|
result |= FP_CLASS_POS_ZERO;
|
|
|
|
|
else if (v == 0.0)
|
|
|
|
|
result |= FP_CLASS_NEG_ZERO;
|
|
|
|
|
else if (v < 1.0)
|
|
|
|
|
result |= FP_CLASS_GT_ZERO_LT_POS_ONE;
|
|
|
|
|
else if (v == 1.0)
|
|
|
|
|
result |= FP_CLASS_POS_ONE;
|
|
|
|
|
else if (v < INFINITY)
|
|
|
|
|
result |= FP_CLASS_GT_POS_ONE;
|
|
|
|
|
else
|
|
|
|
|
result |= FP_CLASS_POS_INF;
|
|
|
|
|
|
|
|
|
|
if (v != 0) {
|
|
|
|
|
/* handle potential denorm flushing. */
|
|
|
|
|
bool is_denorm = false;
|
|
|
|
|
switch (load->def.bit_size) {
|
|
|
|
|
case 64:
|
|
|
|
|
is_denorm = fabs(v) < DBL_MIN;
|
|
|
|
|
break;
|
|
|
|
|
case 32:
|
|
|
|
|
is_denorm = fabs(v) < FLT_MIN;
|
|
|
|
|
break;
|
|
|
|
|
case 16:
|
|
|
|
|
is_denorm = fabs(v) < ldexp(1.0, -14);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
UNREACHABLE("unsupported float size");
|
|
|
|
|
}
|
|
|
|
|
if (is_denorm)
|
|
|
|
|
result |= v < 0.0 ? FP_CLASS_NEG_ZERO : FP_CLASS_POS_ZERO;
|
|
|
|
|
}
|
2018-01-23 09:48:43 +08:00
|
|
|
}
|
|
|
|
|
|
nir: rewrite fp range analysis as a fp class analysis
Knowing if a value is not larger than one helps proving finite
results of fmul/fadd and will allow skipping/creating more fsat.
Knowing that a value is larger than one helps proving non zero
results of fmul.
Separating positive and negative zero also has advantages when
signed zero correctness is required.
Foz-DB Navi48:
Totals from 1344 (1.63% of 82636) affected shaders:
Instrs: 5319389 -> 5312280 (-0.13%); split: -0.14%, +0.01%
CodeSize: 29702516 -> 29665684 (-0.12%); split: -0.13%, +0.01%
Latency: 40694344 -> 40694545 (+0.00%); split: -0.01%, +0.02%
InvThroughput: 7481192 -> 7480403 (-0.01%); split: -0.02%, +0.01%
VClause: 121947 -> 121946 (-0.00%); split: -0.00%, +0.00%
SClause: 104972 -> 104923 (-0.05%); split: -0.05%, +0.00%
Copies: 371098 -> 371092 (-0.00%); split: -0.02%, +0.02%
Branches: 122929 -> 122919 (-0.01%); split: -0.01%, +0.00%
PreSGPRs: 82506 -> 82510 (+0.00%); split: -0.00%, +0.01%
PreVGPRs: 79175 -> 79168 (-0.01%)
VALU: 2906718 -> 2904777 (-0.07%); split: -0.07%, +0.00%
SALU: 726256 -> 723454 (-0.39%); split: -0.39%, +0.00%
VMEM: 205021 -> 205016 (-0.00%)
SMEM: 163972 -> 163916 (-0.03%)
VOPD: 303354 -> 303298 (-0.02%); split: +0.02%, -0.04%
Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/39987>
2026-02-08 23:03:16 +01:00
|
|
|
return result;
|
2019-08-12 15:40:20 -07:00
|
|
|
}
|
|
|
|
|
|
2023-02-14 21:38:41 +00:00
|
|
|
struct fp_query {
|
|
|
|
|
struct analysis_query head;
|
2026-02-07 22:36:25 +01:00
|
|
|
const nir_def *def;
|
2023-02-14 21:38:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static void
|
2026-02-07 22:36:25 +01:00
|
|
|
push_fp_query(struct analysis_state *state, const nir_def *def)
|
2023-02-14 21:38:41 +00:00
|
|
|
{
|
|
|
|
|
struct fp_query *pushed_q = push_analysis_query(state, sizeof(struct fp_query));
|
2026-02-07 22:36:25 +01:00
|
|
|
pushed_q->def = def;
|
2023-02-14 21:38:41 +00:00
|
|
|
}
|
|
|
|
|
|
2026-03-02 16:20:26 +00:00
|
|
|
static uint32_t
|
2023-02-14 21:38:41 +00:00
|
|
|
get_fp_key(struct analysis_query *q)
|
|
|
|
|
{
|
|
|
|
|
struct fp_query *fp_q = (struct fp_query *)q;
|
|
|
|
|
|
2026-02-07 22:36:25 +01:00
|
|
|
if (!nir_def_is_alu(fp_q->def))
|
2026-03-02 16:20:26 +00:00
|
|
|
return UINT32_MAX;
|
2023-02-14 21:38:41 +00:00
|
|
|
|
2026-03-02 15:44:38 +00:00
|
|
|
return fp_q->def->index;
|
2023-02-14 21:38:41 +00:00
|
|
|
}
|
|
|
|
|
|
2026-03-02 15:44:38 +00:00
|
|
|
static bool
|
|
|
|
|
fp_lookup(void *table, uint32_t key, uint32_t *value)
|
|
|
|
|
{
|
|
|
|
|
nir_fp_analysis_state *state = table;
|
|
|
|
|
if (BITSET_TEST(state->bitset, key)) {
|
|
|
|
|
*value = *(uint32_t *)util_sparse_array_get(&state->arr, key);
|
|
|
|
|
return true;
|
|
|
|
|
} else {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
fp_insert(void *table, uint32_t key, uint32_t value)
|
|
|
|
|
{
|
|
|
|
|
nir_fp_analysis_state *state = table;
|
|
|
|
|
BITSET_SET(state->bitset, key);
|
|
|
|
|
state->max = MAX2(state->max, (int)key);
|
|
|
|
|
*(uint32_t *)util_sparse_array_get(&state->arr, key) = value;
|
|
|
|
|
}
|
2026-03-02 16:20:26 +00:00
|
|
|
|
nir: rewrite fp range analysis as a fp class analysis
Knowing if a value is not larger than one helps proving finite
results of fmul/fadd and will allow skipping/creating more fsat.
Knowing that a value is larger than one helps proving non zero
results of fmul.
Separating positive and negative zero also has advantages when
signed zero correctness is required.
Foz-DB Navi48:
Totals from 1344 (1.63% of 82636) affected shaders:
Instrs: 5319389 -> 5312280 (-0.13%); split: -0.14%, +0.01%
CodeSize: 29702516 -> 29665684 (-0.12%); split: -0.13%, +0.01%
Latency: 40694344 -> 40694545 (+0.00%); split: -0.01%, +0.02%
InvThroughput: 7481192 -> 7480403 (-0.01%); split: -0.02%, +0.01%
VClause: 121947 -> 121946 (-0.00%); split: -0.00%, +0.00%
SClause: 104972 -> 104923 (-0.05%); split: -0.05%, +0.00%
Copies: 371098 -> 371092 (-0.00%); split: -0.02%, +0.02%
Branches: 122929 -> 122919 (-0.01%); split: -0.01%, +0.00%
PreSGPRs: 82506 -> 82510 (+0.00%); split: -0.00%, +0.01%
PreVGPRs: 79175 -> 79168 (-0.01%)
VALU: 2906718 -> 2904777 (-0.07%); split: -0.07%, +0.00%
SALU: 726256 -> 723454 (-0.39%); split: -0.39%, +0.00%
VMEM: 205021 -> 205016 (-0.00%)
SMEM: 163972 -> 163916 (-0.03%)
VOPD: 303354 -> 303298 (-0.02%); split: +0.02%, -0.04%
Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/39987>
2026-02-08 23:03:16 +01:00
|
|
|
static fp_class_mask
|
|
|
|
|
fneg_fp_class(fp_class_mask src)
|
2025-03-22 15:58:52 +01:00
|
|
|
{
|
nir: rewrite fp range analysis as a fp class analysis
Knowing if a value is not larger than one helps proving finite
results of fmul/fadd and will allow skipping/creating more fsat.
Knowing that a value is larger than one helps proving non zero
results of fmul.
Separating positive and negative zero also has advantages when
signed zero correctness is required.
Foz-DB Navi48:
Totals from 1344 (1.63% of 82636) affected shaders:
Instrs: 5319389 -> 5312280 (-0.13%); split: -0.14%, +0.01%
CodeSize: 29702516 -> 29665684 (-0.12%); split: -0.13%, +0.01%
Latency: 40694344 -> 40694545 (+0.00%); split: -0.01%, +0.02%
InvThroughput: 7481192 -> 7480403 (-0.01%); split: -0.02%, +0.01%
VClause: 121947 -> 121946 (-0.00%); split: -0.00%, +0.00%
SClause: 104972 -> 104923 (-0.05%); split: -0.05%, +0.00%
Copies: 371098 -> 371092 (-0.00%); split: -0.02%, +0.02%
Branches: 122929 -> 122919 (-0.01%); split: -0.01%, +0.00%
PreSGPRs: 82506 -> 82510 (+0.00%); split: -0.00%, +0.01%
PreVGPRs: 79175 -> 79168 (-0.01%)
VALU: 2906718 -> 2904777 (-0.07%); split: -0.07%, +0.00%
SALU: 726256 -> 723454 (-0.39%); split: -0.39%, +0.00%
VMEM: 205021 -> 205016 (-0.00%)
SMEM: 163972 -> 163916 (-0.03%)
VOPD: 303354 -> 303298 (-0.02%); split: +0.02%, -0.04%
Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/39987>
2026-02-08 23:03:16 +01:00
|
|
|
fp_class_mask result = src & (FP_CLASS_NAN | FP_CLASS_NON_INTEGRAL);
|
|
|
|
|
|
|
|
|
|
#define NEG_BIT(neg, pos) \
|
|
|
|
|
if (src & FP_CLASS_##pos) \
|
|
|
|
|
result |= FP_CLASS_##neg; \
|
|
|
|
|
if (src & FP_CLASS_##neg) \
|
|
|
|
|
result |= FP_CLASS_##pos;
|
|
|
|
|
|
|
|
|
|
NEG_BIT(NEG_INF, POS_INF);
|
|
|
|
|
NEG_BIT(LT_NEG_ONE, GT_POS_ONE);
|
|
|
|
|
NEG_BIT(NEG_ONE, POS_ONE);
|
|
|
|
|
NEG_BIT(LT_ZERO_GT_NEG_ONE, GT_ZERO_LT_POS_ONE);
|
|
|
|
|
NEG_BIT(NEG_ZERO, POS_ZERO);
|
|
|
|
|
|
|
|
|
|
#undef NEG_BIT
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static fp_class_mask
|
|
|
|
|
fmul_fp_class(fp_class_mask left, fp_class_mask right, bool mulz, bool src_eq, bool src_neg_eq)
|
|
|
|
|
{
|
|
|
|
|
/* For runtime performance, shortcut the common completely unknown case. */
|
|
|
|
|
if (left == FP_CLASS_UNKNOWN && right == FP_CLASS_UNKNOWN && !src_eq && !src_neg_eq)
|
|
|
|
|
return FP_CLASS_UNKNOWN;
|
|
|
|
|
|
|
|
|
|
fp_class_mask result = 0;
|
|
|
|
|
|
|
|
|
|
if (left & FP_CLASS_NAN) {
|
|
|
|
|
if (right & FP_CLASS_ANY_ZERO)
|
|
|
|
|
result |= mulz ? FP_CLASS_POS_ZERO : FP_CLASS_NAN;
|
|
|
|
|
|
|
|
|
|
if (right & (FP_CLASS_ANY_NEG | FP_CLASS_ANY_POS | FP_CLASS_NAN))
|
|
|
|
|
result |= FP_CLASS_NAN;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (left & FP_CLASS_NEG_INF) {
|
|
|
|
|
if (right & FP_CLASS_ANY_ZERO)
|
|
|
|
|
result |= mulz ? FP_CLASS_POS_ZERO : FP_CLASS_NAN;
|
|
|
|
|
|
|
|
|
|
if (right & FP_CLASS_ANY_NEG)
|
|
|
|
|
result |= FP_CLASS_POS_INF;
|
|
|
|
|
|
|
|
|
|
if (right & FP_CLASS_ANY_POS)
|
|
|
|
|
result |= FP_CLASS_NEG_INF;
|
|
|
|
|
|
|
|
|
|
if (right & FP_CLASS_NAN)
|
|
|
|
|
result |= FP_CLASS_NAN;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (left & FP_CLASS_POS_INF) {
|
|
|
|
|
if (right & FP_CLASS_ANY_ZERO)
|
|
|
|
|
result |= mulz ? FP_CLASS_POS_ZERO : FP_CLASS_NAN;
|
|
|
|
|
|
|
|
|
|
if (right & FP_CLASS_ANY_POS)
|
|
|
|
|
result |= FP_CLASS_POS_INF;
|
|
|
|
|
|
|
|
|
|
if (right & FP_CLASS_ANY_NEG)
|
|
|
|
|
result |= FP_CLASS_NEG_INF;
|
|
|
|
|
|
|
|
|
|
if (right & FP_CLASS_NAN)
|
|
|
|
|
result |= FP_CLASS_NAN;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (left & FP_CLASS_ANY_NEG_FINITE) {
|
|
|
|
|
if (right & FP_CLASS_POS_ZERO)
|
|
|
|
|
result |= mulz ? FP_CLASS_POS_ZERO : FP_CLASS_NEG_ZERO;
|
|
|
|
|
|
|
|
|
|
result |= fneg_fp_class(right & (FP_CLASS_NEG_ZERO | FP_CLASS_POS_INF | FP_CLASS_NEG_INF | FP_CLASS_NAN));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (left & FP_CLASS_ANY_POS_FINITE) {
|
|
|
|
|
if (right & FP_CLASS_NEG_ZERO)
|
|
|
|
|
result |= mulz ? FP_CLASS_POS_ZERO : FP_CLASS_NEG_ZERO;
|
|
|
|
|
|
|
|
|
|
result |= right & (FP_CLASS_POS_ZERO | FP_CLASS_POS_INF | FP_CLASS_NEG_INF | FP_CLASS_NAN);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (left & FP_CLASS_LT_NEG_ONE) {
|
|
|
|
|
if (right & FP_CLASS_LT_NEG_ONE)
|
|
|
|
|
result |= FP_CLASS_POS_INF | FP_CLASS_GT_POS_ONE;
|
|
|
|
|
|
|
|
|
|
if (right & FP_CLASS_NEG_ONE)
|
|
|
|
|
result |= FP_CLASS_GT_POS_ONE;
|
|
|
|
|
|
|
|
|
|
if (right & FP_CLASS_LT_ZERO_GT_NEG_ONE)
|
|
|
|
|
result |= FP_CLASS_GT_ZERO_LT_POS_ONE | FP_CLASS_POS_ONE | FP_CLASS_GT_POS_ONE;
|
|
|
|
|
|
|
|
|
|
if (right & FP_CLASS_GT_POS_ONE)
|
|
|
|
|
result |= FP_CLASS_NEG_INF | FP_CLASS_LT_NEG_ONE;
|
|
|
|
|
|
|
|
|
|
if (right & FP_CLASS_POS_ONE)
|
|
|
|
|
result |= FP_CLASS_LT_NEG_ONE;
|
|
|
|
|
|
|
|
|
|
if (right & FP_CLASS_GT_ZERO_LT_POS_ONE)
|
|
|
|
|
result |= FP_CLASS_LT_ZERO_GT_NEG_ONE | FP_CLASS_NEG_ONE | FP_CLASS_LT_NEG_ONE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (left & FP_CLASS_GT_POS_ONE) {
|
|
|
|
|
if (right & FP_CLASS_GT_POS_ONE)
|
|
|
|
|
result |= FP_CLASS_POS_INF | FP_CLASS_GT_POS_ONE;
|
|
|
|
|
|
|
|
|
|
if (right & FP_CLASS_POS_ONE)
|
|
|
|
|
result |= FP_CLASS_GT_POS_ONE;
|
|
|
|
|
|
|
|
|
|
if (right & FP_CLASS_GT_ZERO_LT_POS_ONE)
|
|
|
|
|
result |= FP_CLASS_GT_ZERO_LT_POS_ONE | FP_CLASS_POS_ONE | FP_CLASS_GT_POS_ONE;
|
|
|
|
|
|
|
|
|
|
if (right & FP_CLASS_LT_NEG_ONE)
|
|
|
|
|
result |= FP_CLASS_NEG_INF | FP_CLASS_LT_NEG_ONE;
|
|
|
|
|
|
|
|
|
|
if (right & FP_CLASS_NEG_ONE)
|
|
|
|
|
result |= FP_CLASS_LT_NEG_ONE;
|
|
|
|
|
|
|
|
|
|
if (right & FP_CLASS_LT_ZERO_GT_NEG_ONE)
|
|
|
|
|
result |= FP_CLASS_LT_ZERO_GT_NEG_ONE | FP_CLASS_NEG_ONE | FP_CLASS_LT_NEG_ONE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (left & FP_CLASS_NEG_ONE)
|
|
|
|
|
result |= fneg_fp_class(right & ~FP_CLASS_ANY_ZERO);
|
|
|
|
|
|
|
|
|
|
if (left & FP_CLASS_POS_ONE)
|
|
|
|
|
result |= right & ~FP_CLASS_ANY_ZERO;
|
|
|
|
|
|
|
|
|
|
if (left & FP_CLASS_LT_ZERO_GT_NEG_ONE) {
|
|
|
|
|
if (right & FP_CLASS_LT_NEG_ONE)
|
|
|
|
|
result |= FP_CLASS_GT_ZERO_LT_POS_ONE | FP_CLASS_POS_ONE | FP_CLASS_GT_POS_ONE;
|
|
|
|
|
|
|
|
|
|
if (right & FP_CLASS_NEG_ONE)
|
|
|
|
|
result |= FP_CLASS_GT_ZERO_LT_POS_ONE;
|
|
|
|
|
|
|
|
|
|
if (right & FP_CLASS_LT_ZERO_GT_NEG_ONE)
|
|
|
|
|
result |= FP_CLASS_POS_ZERO | FP_CLASS_GT_ZERO_LT_POS_ONE;
|
|
|
|
|
|
|
|
|
|
if (right & FP_CLASS_GT_POS_ONE)
|
|
|
|
|
result |= FP_CLASS_LT_ZERO_GT_NEG_ONE | FP_CLASS_NEG_ONE | FP_CLASS_LT_NEG_ONE;
|
|
|
|
|
|
|
|
|
|
if (right & FP_CLASS_POS_ONE)
|
|
|
|
|
result |= FP_CLASS_LT_ZERO_GT_NEG_ONE;
|
|
|
|
|
|
|
|
|
|
if (right & FP_CLASS_GT_ZERO_LT_POS_ONE)
|
|
|
|
|
result |= FP_CLASS_NEG_ZERO | FP_CLASS_LT_ZERO_GT_NEG_ONE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (left & FP_CLASS_GT_ZERO_LT_POS_ONE) {
|
|
|
|
|
if (right & FP_CLASS_GT_POS_ONE)
|
|
|
|
|
result |= FP_CLASS_GT_ZERO_LT_POS_ONE | FP_CLASS_POS_ONE | FP_CLASS_GT_POS_ONE;
|
|
|
|
|
|
|
|
|
|
if (right & FP_CLASS_POS_ONE)
|
|
|
|
|
result |= FP_CLASS_GT_ZERO_LT_POS_ONE;
|
|
|
|
|
|
|
|
|
|
if (right & FP_CLASS_GT_ZERO_LT_POS_ONE)
|
|
|
|
|
result |= FP_CLASS_POS_ZERO | FP_CLASS_GT_ZERO_LT_POS_ONE;
|
|
|
|
|
|
|
|
|
|
if (right & FP_CLASS_LT_NEG_ONE)
|
|
|
|
|
result |= FP_CLASS_LT_ZERO_GT_NEG_ONE | FP_CLASS_NEG_ONE | FP_CLASS_LT_NEG_ONE;
|
|
|
|
|
|
|
|
|
|
if (right & FP_CLASS_NEG_ONE)
|
|
|
|
|
result |= FP_CLASS_LT_ZERO_GT_NEG_ONE;
|
|
|
|
|
|
|
|
|
|
if (right & FP_CLASS_LT_ZERO_GT_NEG_ONE)
|
|
|
|
|
result |= FP_CLASS_NEG_ZERO | FP_CLASS_LT_ZERO_GT_NEG_ONE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (left & FP_CLASS_NEG_ZERO) {
|
|
|
|
|
if (mulz) {
|
|
|
|
|
result |= FP_CLASS_POS_ZERO;
|
|
|
|
|
} else {
|
|
|
|
|
if (right & (FP_CLASS_ANY_INF | FP_CLASS_NAN))
|
|
|
|
|
result |= FP_CLASS_NAN;
|
|
|
|
|
|
|
|
|
|
if (right & (FP_CLASS_ANY_NEG_FINITE | FP_CLASS_NEG_ZERO))
|
|
|
|
|
result |= FP_CLASS_POS_ZERO;
|
|
|
|
|
|
|
|
|
|
if (right & (FP_CLASS_ANY_POS_FINITE | FP_CLASS_POS_ZERO))
|
|
|
|
|
result |= FP_CLASS_NEG_ZERO;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (left & FP_CLASS_POS_ZERO) {
|
|
|
|
|
if (mulz) {
|
|
|
|
|
result |= FP_CLASS_POS_ZERO;
|
|
|
|
|
} else {
|
|
|
|
|
if (right & (FP_CLASS_ANY_INF | FP_CLASS_NAN))
|
|
|
|
|
result |= FP_CLASS_NAN;
|
|
|
|
|
|
|
|
|
|
if (right & (FP_CLASS_ANY_POS_FINITE | FP_CLASS_POS_ZERO))
|
|
|
|
|
result |= FP_CLASS_POS_ZERO;
|
|
|
|
|
|
|
|
|
|
if (right & (FP_CLASS_ANY_NEG_FINITE | FP_CLASS_NEG_ZERO))
|
|
|
|
|
result |= FP_CLASS_NEG_ZERO;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (src_eq || src_neg_eq) {
|
|
|
|
|
/* This case can't create new ones. */
|
|
|
|
|
if (!(left & (FP_CLASS_POS_ONE | FP_CLASS_NEG_ONE)))
|
|
|
|
|
result &= ~(FP_CLASS_POS_ONE | FP_CLASS_NEG_ONE);
|
|
|
|
|
|
|
|
|
|
if (src_eq)
|
|
|
|
|
result &= ~(FP_CLASS_ANY_NEG | FP_CLASS_NEG_ZERO);
|
|
|
|
|
else if (src_neg_eq && mulz)
|
|
|
|
|
result &= ~FP_CLASS_ANY_POS;
|
|
|
|
|
else if (src_neg_eq)
|
|
|
|
|
result &= ~(FP_CLASS_ANY_POS | FP_CLASS_POS_ZERO);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ((left | right) & FP_CLASS_NON_INTEGRAL) {
|
|
|
|
|
if (result & (FP_CLASS_LT_NEG_ONE | FP_CLASS_LT_ZERO_GT_NEG_ONE |
|
|
|
|
|
FP_CLASS_GT_ZERO_LT_POS_ONE | FP_CLASS_GT_POS_ONE))
|
|
|
|
|
result |= FP_CLASS_NON_INTEGRAL;
|
2025-03-22 15:58:52 +01:00
|
|
|
} else {
|
nir: rewrite fp range analysis as a fp class analysis
Knowing if a value is not larger than one helps proving finite
results of fmul/fadd and will allow skipping/creating more fsat.
Knowing that a value is larger than one helps proving non zero
results of fmul.
Separating positive and negative zero also has advantages when
signed zero correctness is required.
Foz-DB Navi48:
Totals from 1344 (1.63% of 82636) affected shaders:
Instrs: 5319389 -> 5312280 (-0.13%); split: -0.14%, +0.01%
CodeSize: 29702516 -> 29665684 (-0.12%); split: -0.13%, +0.01%
Latency: 40694344 -> 40694545 (+0.00%); split: -0.01%, +0.02%
InvThroughput: 7481192 -> 7480403 (-0.01%); split: -0.02%, +0.01%
VClause: 121947 -> 121946 (-0.00%); split: -0.00%, +0.00%
SClause: 104972 -> 104923 (-0.05%); split: -0.05%, +0.00%
Copies: 371098 -> 371092 (-0.00%); split: -0.02%, +0.02%
Branches: 122929 -> 122919 (-0.01%); split: -0.01%, +0.00%
PreSGPRs: 82506 -> 82510 (+0.00%); split: -0.00%, +0.01%
PreVGPRs: 79175 -> 79168 (-0.01%)
VALU: 2906718 -> 2904777 (-0.07%); split: -0.07%, +0.00%
SALU: 726256 -> 723454 (-0.39%); split: -0.39%, +0.00%
VMEM: 205021 -> 205016 (-0.00%)
SMEM: 163972 -> 163916 (-0.03%)
VOPD: 303354 -> 303298 (-0.02%); split: +0.02%, -0.04%
Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/39987>
2026-02-08 23:03:16 +01:00
|
|
|
result &= ~(FP_CLASS_LT_ZERO_GT_NEG_ONE | FP_CLASS_GT_ZERO_LT_POS_ONE);
|
2025-03-22 15:58:52 +01:00
|
|
|
}
|
nir: rewrite fp range analysis as a fp class analysis
Knowing if a value is not larger than one helps proving finite
results of fmul/fadd and will allow skipping/creating more fsat.
Knowing that a value is larger than one helps proving non zero
results of fmul.
Separating positive and negative zero also has advantages when
signed zero correctness is required.
Foz-DB Navi48:
Totals from 1344 (1.63% of 82636) affected shaders:
Instrs: 5319389 -> 5312280 (-0.13%); split: -0.14%, +0.01%
CodeSize: 29702516 -> 29665684 (-0.12%); split: -0.13%, +0.01%
Latency: 40694344 -> 40694545 (+0.00%); split: -0.01%, +0.02%
InvThroughput: 7481192 -> 7480403 (-0.01%); split: -0.02%, +0.01%
VClause: 121947 -> 121946 (-0.00%); split: -0.00%, +0.00%
SClause: 104972 -> 104923 (-0.05%); split: -0.05%, +0.00%
Copies: 371098 -> 371092 (-0.00%); split: -0.02%, +0.02%
Branches: 122929 -> 122919 (-0.01%); split: -0.01%, +0.00%
PreSGPRs: 82506 -> 82510 (+0.00%); split: -0.00%, +0.01%
PreVGPRs: 79175 -> 79168 (-0.01%)
VALU: 2906718 -> 2904777 (-0.07%); split: -0.07%, +0.00%
SALU: 726256 -> 723454 (-0.39%); split: -0.39%, +0.00%
VMEM: 205021 -> 205016 (-0.00%)
SMEM: 163972 -> 163916 (-0.03%)
VOPD: 303354 -> 303298 (-0.02%); split: +0.02%, -0.04%
Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/39987>
2026-02-08 23:03:16 +01:00
|
|
|
|
|
|
|
|
return result;
|
2025-03-22 15:58:52 +01:00
|
|
|
}
|
|
|
|
|
|
nir: rewrite fp range analysis as a fp class analysis
Knowing if a value is not larger than one helps proving finite
results of fmul/fadd and will allow skipping/creating more fsat.
Knowing that a value is larger than one helps proving non zero
results of fmul.
Separating positive and negative zero also has advantages when
signed zero correctness is required.
Foz-DB Navi48:
Totals from 1344 (1.63% of 82636) affected shaders:
Instrs: 5319389 -> 5312280 (-0.13%); split: -0.14%, +0.01%
CodeSize: 29702516 -> 29665684 (-0.12%); split: -0.13%, +0.01%
Latency: 40694344 -> 40694545 (+0.00%); split: -0.01%, +0.02%
InvThroughput: 7481192 -> 7480403 (-0.01%); split: -0.02%, +0.01%
VClause: 121947 -> 121946 (-0.00%); split: -0.00%, +0.00%
SClause: 104972 -> 104923 (-0.05%); split: -0.05%, +0.00%
Copies: 371098 -> 371092 (-0.00%); split: -0.02%, +0.02%
Branches: 122929 -> 122919 (-0.01%); split: -0.01%, +0.00%
PreSGPRs: 82506 -> 82510 (+0.00%); split: -0.00%, +0.01%
PreVGPRs: 79175 -> 79168 (-0.01%)
VALU: 2906718 -> 2904777 (-0.07%); split: -0.07%, +0.00%
SALU: 726256 -> 723454 (-0.39%); split: -0.39%, +0.00%
VMEM: 205021 -> 205016 (-0.00%)
SMEM: 163972 -> 163916 (-0.03%)
VOPD: 303354 -> 303298 (-0.02%); split: +0.02%, -0.04%
Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/39987>
2026-02-08 23:03:16 +01:00
|
|
|
static fp_class_mask
|
|
|
|
|
fadd_fp_class(fp_class_mask left, fp_class_mask right)
|
2025-03-22 15:58:52 +01:00
|
|
|
{
|
nir: rewrite fp range analysis as a fp class analysis
Knowing if a value is not larger than one helps proving finite
results of fmul/fadd and will allow skipping/creating more fsat.
Knowing that a value is larger than one helps proving non zero
results of fmul.
Separating positive and negative zero also has advantages when
signed zero correctness is required.
Foz-DB Navi48:
Totals from 1344 (1.63% of 82636) affected shaders:
Instrs: 5319389 -> 5312280 (-0.13%); split: -0.14%, +0.01%
CodeSize: 29702516 -> 29665684 (-0.12%); split: -0.13%, +0.01%
Latency: 40694344 -> 40694545 (+0.00%); split: -0.01%, +0.02%
InvThroughput: 7481192 -> 7480403 (-0.01%); split: -0.02%, +0.01%
VClause: 121947 -> 121946 (-0.00%); split: -0.00%, +0.00%
SClause: 104972 -> 104923 (-0.05%); split: -0.05%, +0.00%
Copies: 371098 -> 371092 (-0.00%); split: -0.02%, +0.02%
Branches: 122929 -> 122919 (-0.01%); split: -0.01%, +0.00%
PreSGPRs: 82506 -> 82510 (+0.00%); split: -0.00%, +0.01%
PreVGPRs: 79175 -> 79168 (-0.01%)
VALU: 2906718 -> 2904777 (-0.07%); split: -0.07%, +0.00%
SALU: 726256 -> 723454 (-0.39%); split: -0.39%, +0.00%
VMEM: 205021 -> 205016 (-0.00%)
SMEM: 163972 -> 163916 (-0.03%)
VOPD: 303354 -> 303298 (-0.02%); split: +0.02%, -0.04%
Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/39987>
2026-02-08 23:03:16 +01:00
|
|
|
/* For runtime performance, shortcut the common completely unknown case. */
|
|
|
|
|
if (left == FP_CLASS_UNKNOWN && right == FP_CLASS_UNKNOWN)
|
|
|
|
|
return FP_CLASS_UNKNOWN;
|
|
|
|
|
|
|
|
|
|
fp_class_mask result = (left | right) & FP_CLASS_NAN;
|
2025-03-22 15:58:52 +01:00
|
|
|
/* X + Y is NaN if either operand is NaN or if one operand is +Inf and
|
nir: rewrite fp range analysis as a fp class analysis
Knowing if a value is not larger than one helps proving finite
results of fmul/fadd and will allow skipping/creating more fsat.
Knowing that a value is larger than one helps proving non zero
results of fmul.
Separating positive and negative zero also has advantages when
signed zero correctness is required.
Foz-DB Navi48:
Totals from 1344 (1.63% of 82636) affected shaders:
Instrs: 5319389 -> 5312280 (-0.13%); split: -0.14%, +0.01%
CodeSize: 29702516 -> 29665684 (-0.12%); split: -0.13%, +0.01%
Latency: 40694344 -> 40694545 (+0.00%); split: -0.01%, +0.02%
InvThroughput: 7481192 -> 7480403 (-0.01%); split: -0.02%, +0.01%
VClause: 121947 -> 121946 (-0.00%); split: -0.00%, +0.00%
SClause: 104972 -> 104923 (-0.05%); split: -0.05%, +0.00%
Copies: 371098 -> 371092 (-0.00%); split: -0.02%, +0.02%
Branches: 122929 -> 122919 (-0.01%); split: -0.01%, +0.00%
PreSGPRs: 82506 -> 82510 (+0.00%); split: -0.00%, +0.01%
PreVGPRs: 79175 -> 79168 (-0.01%)
VALU: 2906718 -> 2904777 (-0.07%); split: -0.07%, +0.00%
SALU: 726256 -> 723454 (-0.39%); split: -0.39%, +0.00%
VMEM: 205021 -> 205016 (-0.00%)
SMEM: 163972 -> 163916 (-0.03%)
VOPD: 303354 -> 303298 (-0.02%); split: +0.02%, -0.04%
Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/39987>
2026-02-08 23:03:16 +01:00
|
|
|
* the other is -Inf.
|
2025-03-22 15:58:52 +01:00
|
|
|
*/
|
nir: rewrite fp range analysis as a fp class analysis
Knowing if a value is not larger than one helps proving finite
results of fmul/fadd and will allow skipping/creating more fsat.
Knowing that a value is larger than one helps proving non zero
results of fmul.
Separating positive and negative zero also has advantages when
signed zero correctness is required.
Foz-DB Navi48:
Totals from 1344 (1.63% of 82636) affected shaders:
Instrs: 5319389 -> 5312280 (-0.13%); split: -0.14%, +0.01%
CodeSize: 29702516 -> 29665684 (-0.12%); split: -0.13%, +0.01%
Latency: 40694344 -> 40694545 (+0.00%); split: -0.01%, +0.02%
InvThroughput: 7481192 -> 7480403 (-0.01%); split: -0.02%, +0.01%
VClause: 121947 -> 121946 (-0.00%); split: -0.00%, +0.00%
SClause: 104972 -> 104923 (-0.05%); split: -0.05%, +0.00%
Copies: 371098 -> 371092 (-0.00%); split: -0.02%, +0.02%
Branches: 122929 -> 122919 (-0.01%); split: -0.01%, +0.00%
PreSGPRs: 82506 -> 82510 (+0.00%); split: -0.00%, +0.01%
PreVGPRs: 79175 -> 79168 (-0.01%)
VALU: 2906718 -> 2904777 (-0.07%); split: -0.07%, +0.00%
SALU: 726256 -> 723454 (-0.39%); split: -0.39%, +0.00%
VMEM: 205021 -> 205016 (-0.00%)
SMEM: 163972 -> 163916 (-0.03%)
VOPD: 303354 -> 303298 (-0.02%); split: +0.02%, -0.04%
Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/39987>
2026-02-08 23:03:16 +01:00
|
|
|
if (left & FP_CLASS_NEG_INF) {
|
|
|
|
|
if (right & FP_CLASS_POS_INF)
|
|
|
|
|
result |= FP_CLASS_NAN;
|
|
|
|
|
if (right & (FP_CLASS_ANY_FINITE | FP_CLASS_NEG_INF))
|
|
|
|
|
result |= FP_CLASS_NEG_INF;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (left & FP_CLASS_POS_INF) {
|
|
|
|
|
if (right & FP_CLASS_NEG_INF)
|
|
|
|
|
result |= FP_CLASS_NAN;
|
|
|
|
|
if (right & (FP_CLASS_ANY_FINITE | FP_CLASS_POS_INF))
|
|
|
|
|
result |= FP_CLASS_POS_INF;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (left & FP_CLASS_LT_NEG_ONE) {
|
|
|
|
|
result |= (right & FP_CLASS_ANY_INF);
|
|
|
|
|
|
|
|
|
|
if (right & FP_CLASS_LT_NEG_ONE)
|
|
|
|
|
result |= FP_CLASS_NEG_INF | FP_CLASS_LT_NEG_ONE;
|
|
|
|
|
|
|
|
|
|
if (right & (FP_CLASS_NEG_ONE | FP_CLASS_LT_ZERO_GT_NEG_ONE | FP_CLASS_ANY_ZERO))
|
|
|
|
|
result |= FP_CLASS_LT_NEG_ONE;
|
|
|
|
|
|
|
|
|
|
if (right & (FP_CLASS_GT_ZERO_LT_POS_ONE | FP_CLASS_POS_ONE))
|
|
|
|
|
result |= FP_CLASS_LT_NEG_ONE | FP_CLASS_NEG_ONE | FP_CLASS_LT_ZERO_GT_NEG_ONE;
|
|
|
|
|
|
|
|
|
|
if (right & FP_CLASS_GT_POS_ONE)
|
|
|
|
|
result |= FP_CLASS_ANY_FINITE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (left & FP_CLASS_GT_POS_ONE) {
|
|
|
|
|
result |= (right & FP_CLASS_ANY_INF);
|
|
|
|
|
|
|
|
|
|
if (right & FP_CLASS_GT_POS_ONE)
|
|
|
|
|
result |= FP_CLASS_POS_INF | FP_CLASS_GT_POS_ONE;
|
|
|
|
|
|
|
|
|
|
if (right & (FP_CLASS_POS_ONE | FP_CLASS_GT_ZERO_LT_POS_ONE | FP_CLASS_ANY_ZERO))
|
|
|
|
|
result |= FP_CLASS_GT_POS_ONE;
|
|
|
|
|
|
|
|
|
|
if (right & (FP_CLASS_LT_ZERO_GT_NEG_ONE | FP_CLASS_NEG_ONE))
|
|
|
|
|
result |= FP_CLASS_GT_POS_ONE | FP_CLASS_POS_ONE | FP_CLASS_GT_ZERO_LT_POS_ONE;
|
|
|
|
|
|
|
|
|
|
if (right & FP_CLASS_LT_NEG_ONE)
|
|
|
|
|
result |= FP_CLASS_ANY_FINITE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (left & FP_CLASS_NEG_ONE) {
|
|
|
|
|
result |= (right & FP_CLASS_ANY_INF);
|
|
|
|
|
|
|
|
|
|
if (right & (FP_CLASS_LT_NEG_ONE | FP_CLASS_NEG_ONE | FP_CLASS_LT_ZERO_GT_NEG_ONE))
|
|
|
|
|
result |= FP_CLASS_LT_NEG_ONE;
|
|
|
|
|
|
|
|
|
|
if (right & (FP_CLASS_LT_ZERO_GT_NEG_ONE | FP_CLASS_ANY_ZERO | FP_CLASS_GT_ZERO_LT_POS_ONE))
|
|
|
|
|
result |= FP_CLASS_NEG_ONE;
|
|
|
|
|
|
|
|
|
|
if (right & FP_CLASS_GT_ZERO_LT_POS_ONE)
|
|
|
|
|
result |= FP_CLASS_LT_ZERO_GT_NEG_ONE;
|
|
|
|
|
|
|
|
|
|
if (right & FP_CLASS_POS_ONE)
|
|
|
|
|
result |= FP_CLASS_POS_ZERO;
|
|
|
|
|
|
|
|
|
|
if (right & FP_CLASS_GT_POS_ONE)
|
|
|
|
|
result |= FP_CLASS_GT_ZERO_LT_POS_ONE | FP_CLASS_POS_ONE | FP_CLASS_GT_POS_ONE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (left & FP_CLASS_POS_ONE) {
|
|
|
|
|
result |= (right & FP_CLASS_ANY_INF);
|
|
|
|
|
|
|
|
|
|
if (right & (FP_CLASS_GT_POS_ONE | FP_CLASS_POS_ONE | FP_CLASS_GT_ZERO_LT_POS_ONE))
|
|
|
|
|
result |= FP_CLASS_GT_POS_ONE;
|
|
|
|
|
|
|
|
|
|
if (right & (FP_CLASS_GT_ZERO_LT_POS_ONE | FP_CLASS_ANY_ZERO | FP_CLASS_LT_ZERO_GT_NEG_ONE))
|
|
|
|
|
result |= FP_CLASS_POS_ONE;
|
|
|
|
|
|
|
|
|
|
if (right & FP_CLASS_LT_ZERO_GT_NEG_ONE)
|
|
|
|
|
result |= FP_CLASS_GT_ZERO_LT_POS_ONE;
|
|
|
|
|
|
|
|
|
|
if (right & FP_CLASS_NEG_ONE)
|
|
|
|
|
result |= FP_CLASS_POS_ZERO;
|
|
|
|
|
|
|
|
|
|
if (right & FP_CLASS_LT_NEG_ONE)
|
|
|
|
|
result |= FP_CLASS_LT_ZERO_GT_NEG_ONE | FP_CLASS_NEG_ONE | FP_CLASS_LT_NEG_ONE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (left & FP_CLASS_LT_ZERO_GT_NEG_ONE) {
|
|
|
|
|
result |= (right & FP_CLASS_ANY_INF);
|
|
|
|
|
|
|
|
|
|
if (right & FP_CLASS_LT_NEG_ONE)
|
|
|
|
|
result |= FP_CLASS_LT_NEG_ONE;
|
|
|
|
|
|
|
|
|
|
if (right & FP_CLASS_NEG_ONE)
|
|
|
|
|
result |= FP_CLASS_LT_NEG_ONE | FP_CLASS_NEG_ONE;
|
|
|
|
|
|
|
|
|
|
if (right & FP_CLASS_LT_ZERO_GT_NEG_ONE)
|
|
|
|
|
result |= FP_CLASS_LT_NEG_ONE | FP_CLASS_NEG_ONE | FP_CLASS_LT_ZERO_GT_NEG_ONE;
|
|
|
|
|
|
|
|
|
|
if (right & FP_CLASS_ANY_ZERO)
|
|
|
|
|
result |= FP_CLASS_LT_ZERO_GT_NEG_ONE;
|
|
|
|
|
|
|
|
|
|
if (right & FP_CLASS_GT_ZERO_LT_POS_ONE)
|
|
|
|
|
result |= FP_CLASS_LT_ZERO_GT_NEG_ONE | FP_CLASS_ANY_ZERO | FP_CLASS_GT_ZERO_LT_POS_ONE;
|
|
|
|
|
|
|
|
|
|
if (right & FP_CLASS_POS_ONE)
|
|
|
|
|
result |= FP_CLASS_GT_ZERO_LT_POS_ONE | FP_CLASS_POS_ONE;
|
|
|
|
|
|
|
|
|
|
if (right & FP_CLASS_GT_POS_ONE)
|
|
|
|
|
result |= FP_CLASS_GT_ZERO_LT_POS_ONE | FP_CLASS_POS_ONE | FP_CLASS_GT_POS_ONE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (left & FP_CLASS_GT_ZERO_LT_POS_ONE) {
|
|
|
|
|
result |= (right & FP_CLASS_ANY_INF);
|
|
|
|
|
|
|
|
|
|
if (right & FP_CLASS_GT_POS_ONE)
|
|
|
|
|
result |= FP_CLASS_GT_POS_ONE;
|
|
|
|
|
|
|
|
|
|
if (right & FP_CLASS_POS_ONE)
|
|
|
|
|
result |= FP_CLASS_GT_POS_ONE | FP_CLASS_POS_ONE;
|
|
|
|
|
|
|
|
|
|
if (right & FP_CLASS_GT_ZERO_LT_POS_ONE)
|
|
|
|
|
result |= FP_CLASS_GT_POS_ONE | FP_CLASS_POS_ONE | FP_CLASS_GT_ZERO_LT_POS_ONE;
|
|
|
|
|
|
|
|
|
|
if (right & FP_CLASS_ANY_ZERO)
|
|
|
|
|
result |= FP_CLASS_GT_ZERO_LT_POS_ONE;
|
|
|
|
|
|
|
|
|
|
if (right & FP_CLASS_LT_ZERO_GT_NEG_ONE)
|
|
|
|
|
result |= FP_CLASS_GT_ZERO_LT_POS_ONE | FP_CLASS_ANY_ZERO | FP_CLASS_LT_ZERO_GT_NEG_ONE;
|
|
|
|
|
|
|
|
|
|
if (right & FP_CLASS_NEG_ONE)
|
|
|
|
|
result |= FP_CLASS_LT_ZERO_GT_NEG_ONE | FP_CLASS_NEG_ONE;
|
|
|
|
|
|
|
|
|
|
if (right & FP_CLASS_LT_NEG_ONE)
|
|
|
|
|
result |= FP_CLASS_LT_ZERO_GT_NEG_ONE | FP_CLASS_NEG_ONE | FP_CLASS_LT_NEG_ONE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (left & FP_CLASS_NEG_ZERO) {
|
|
|
|
|
result |= right;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (left & FP_CLASS_POS_ZERO) {
|
|
|
|
|
result |= right & ~FP_CLASS_NEG_ZERO;
|
|
|
|
|
if (right & FP_CLASS_NEG_ZERO)
|
|
|
|
|
result |= FP_CLASS_POS_ZERO;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ((left | right) & FP_CLASS_NON_INTEGRAL) {
|
|
|
|
|
if (result & (FP_CLASS_LT_NEG_ONE | FP_CLASS_LT_ZERO_GT_NEG_ONE |
|
|
|
|
|
FP_CLASS_GT_ZERO_LT_POS_ONE | FP_CLASS_GT_POS_ONE))
|
|
|
|
|
result |= FP_CLASS_NON_INTEGRAL;
|
|
|
|
|
} else {
|
|
|
|
|
result &= ~(FP_CLASS_LT_ZERO_GT_NEG_ONE | FP_CLASS_GT_ZERO_LT_POS_ONE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static fp_class_mask
|
|
|
|
|
frcp_fp_class(fp_class_mask src)
|
|
|
|
|
{
|
|
|
|
|
fp_class_mask result = src & FP_CLASS_NAN;
|
|
|
|
|
|
|
|
|
|
/* Inf/Zero result in Zero/Inf.*/
|
|
|
|
|
if (src & FP_CLASS_NEG_INF)
|
|
|
|
|
result |= FP_CLASS_NEG_ZERO;
|
|
|
|
|
if (src & FP_CLASS_POS_INF)
|
|
|
|
|
result |= FP_CLASS_POS_ZERO;
|
|
|
|
|
if (src & FP_CLASS_NEG_ZERO)
|
|
|
|
|
result |= FP_CLASS_NEG_INF;
|
|
|
|
|
if (src & FP_CLASS_POS_ZERO)
|
|
|
|
|
result |= FP_CLASS_POS_INF;
|
|
|
|
|
|
|
|
|
|
/* One results in one. */
|
|
|
|
|
if (src & FP_CLASS_NEG_ONE)
|
|
|
|
|
result |= FP_CLASS_NEG_ONE;
|
|
|
|
|
if (src & FP_CLASS_POS_ONE)
|
|
|
|
|
result |= FP_CLASS_POS_ONE;
|
|
|
|
|
|
|
|
|
|
if (src & FP_CLASS_LT_NEG_ONE)
|
|
|
|
|
result |= FP_CLASS_LT_ZERO_GT_NEG_ONE | FP_CLASS_NEG_ZERO | FP_CLASS_NON_INTEGRAL;
|
|
|
|
|
if (src & FP_CLASS_GT_POS_ONE)
|
|
|
|
|
result |= FP_CLASS_GT_ZERO_LT_POS_ONE | FP_CLASS_POS_ZERO | FP_CLASS_NON_INTEGRAL;
|
|
|
|
|
|
|
|
|
|
if (src & FP_CLASS_LT_ZERO_GT_NEG_ONE)
|
|
|
|
|
result |= FP_CLASS_LT_NEG_ONE | FP_CLASS_NEG_INF | FP_CLASS_NON_INTEGRAL;
|
|
|
|
|
if (src & FP_CLASS_GT_ZERO_LT_POS_ONE)
|
|
|
|
|
result |= FP_CLASS_GT_POS_ONE | FP_CLASS_POS_INF | FP_CLASS_NON_INTEGRAL;
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static fp_class_mask
|
|
|
|
|
fsqrt_fp_class(fp_class_mask src)
|
|
|
|
|
{
|
|
|
|
|
fp_class_mask result = src & (FP_CLASS_NAN | FP_CLASS_ANY_ZERO);
|
|
|
|
|
|
|
|
|
|
if (src & FP_CLASS_ANY_NEG)
|
|
|
|
|
result |= FP_CLASS_NAN;
|
|
|
|
|
|
|
|
|
|
if (src & FP_CLASS_GT_ZERO_LT_POS_ONE)
|
|
|
|
|
result |= FP_CLASS_GT_ZERO_LT_POS_ONE | FP_CLASS_NON_INTEGRAL;
|
|
|
|
|
if (src & FP_CLASS_POS_ONE)
|
|
|
|
|
result |= FP_CLASS_POS_ONE;
|
|
|
|
|
if (src & FP_CLASS_GT_POS_ONE)
|
|
|
|
|
result |= FP_CLASS_GT_POS_ONE | FP_CLASS_POS_ONE | FP_CLASS_NON_INTEGRAL;
|
|
|
|
|
if (src & FP_CLASS_POS_INF)
|
|
|
|
|
result |= FP_CLASS_POS_INF;
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static fp_class_mask
|
|
|
|
|
fmin_part(fp_class_mask upper_bound, fp_class_mask value)
|
|
|
|
|
{
|
|
|
|
|
/* Find the highest value in upper_bound, and return all
|
|
|
|
|
* smaller or equal values from value.
|
|
|
|
|
*/
|
|
|
|
|
upper_bound &= FP_CLASS_ANY_NEG | FP_CLASS_ANY_ZERO | FP_CLASS_ANY_POS;
|
|
|
|
|
value &= FP_CLASS_ANY_NEG | FP_CLASS_ANY_ZERO | FP_CLASS_ANY_POS;
|
|
|
|
|
|
|
|
|
|
/* This works even in the case where upper_bound is 0 */
|
|
|
|
|
return value & BITFIELD_MASK(util_last_bit(upper_bound));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static fp_class_mask
|
|
|
|
|
fmin_fp_class(fp_class_mask left, fp_class_mask right)
|
|
|
|
|
{
|
|
|
|
|
fp_class_mask result = 0;
|
|
|
|
|
|
|
|
|
|
/* If one source is NaN, we have to include the whole range of the other source. */
|
|
|
|
|
if (left & FP_CLASS_NAN)
|
|
|
|
|
result |= right;
|
|
|
|
|
if (right & FP_CLASS_NAN)
|
|
|
|
|
result |= left;
|
|
|
|
|
|
|
|
|
|
result |= fmin_part(left, right);
|
|
|
|
|
result |= fmin_part(right, left);
|
|
|
|
|
|
|
|
|
|
/* Could probably do better, but meh. */
|
|
|
|
|
if ((left | right) & FP_CLASS_NON_INTEGRAL) {
|
|
|
|
|
if (result & (FP_CLASS_LT_NEG_ONE | FP_CLASS_LT_ZERO_GT_NEG_ONE |
|
|
|
|
|
FP_CLASS_GT_ZERO_LT_POS_ONE | FP_CLASS_GT_POS_ONE))
|
|
|
|
|
result |= FP_CLASS_NON_INTEGRAL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static fp_class_mask
|
|
|
|
|
handle_sz(const nir_alu_instr *alu, fp_class_mask src)
|
|
|
|
|
{
|
|
|
|
|
if (nir_alu_instr_is_signed_zero_preserve(alu) || !(src & FP_CLASS_ANY_ZERO))
|
|
|
|
|
return src;
|
|
|
|
|
|
|
|
|
|
return src | FP_CLASS_ANY_ZERO;
|
2025-03-22 15:58:52 +01:00
|
|
|
}
|
|
|
|
|
|
2018-01-23 09:48:43 +08:00
|
|
|
/**
|
nir: rewrite fp range analysis as a fp class analysis
Knowing if a value is not larger than one helps proving finite
results of fmul/fadd and will allow skipping/creating more fsat.
Knowing that a value is larger than one helps proving non zero
results of fmul.
Separating positive and negative zero also has advantages when
signed zero correctness is required.
Foz-DB Navi48:
Totals from 1344 (1.63% of 82636) affected shaders:
Instrs: 5319389 -> 5312280 (-0.13%); split: -0.14%, +0.01%
CodeSize: 29702516 -> 29665684 (-0.12%); split: -0.13%, +0.01%
Latency: 40694344 -> 40694545 (+0.00%); split: -0.01%, +0.02%
InvThroughput: 7481192 -> 7480403 (-0.01%); split: -0.02%, +0.01%
VClause: 121947 -> 121946 (-0.00%); split: -0.00%, +0.00%
SClause: 104972 -> 104923 (-0.05%); split: -0.05%, +0.00%
Copies: 371098 -> 371092 (-0.00%); split: -0.02%, +0.02%
Branches: 122929 -> 122919 (-0.01%); split: -0.01%, +0.00%
PreSGPRs: 82506 -> 82510 (+0.00%); split: -0.00%, +0.01%
PreVGPRs: 79175 -> 79168 (-0.01%)
VALU: 2906718 -> 2904777 (-0.07%); split: -0.07%, +0.00%
SALU: 726256 -> 723454 (-0.39%); split: -0.39%, +0.00%
VMEM: 205021 -> 205016 (-0.00%)
SMEM: 163972 -> 163916 (-0.03%)
VOPD: 303354 -> 303298 (-0.02%); split: +0.02%, -0.04%
Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/39987>
2026-02-08 23:03:16 +01:00
|
|
|
* Analyze an expression to determine the possible fp classes of its result
|
2018-01-23 09:48:43 +08:00
|
|
|
*/
|
2023-02-14 21:38:41 +00:00
|
|
|
static void
|
|
|
|
|
process_fp_query(struct analysis_state *state, struct analysis_query *aq, uint32_t *result,
|
|
|
|
|
const uint32_t *src_res)
|
2018-01-23 09:48:43 +08:00
|
|
|
{
|
2023-02-14 21:38:41 +00:00
|
|
|
struct fp_query q = *(struct fp_query *)aq;
|
2026-02-07 22:36:25 +01:00
|
|
|
const nir_def *def = q.def;
|
2023-02-14 21:38:41 +00:00
|
|
|
|
2026-02-07 22:36:25 +01:00
|
|
|
if (nir_def_is_const(def)) {
|
nir: rewrite fp range analysis as a fp class analysis
Knowing if a value is not larger than one helps proving finite
results of fmul/fadd and will allow skipping/creating more fsat.
Knowing that a value is larger than one helps proving non zero
results of fmul.
Separating positive and negative zero also has advantages when
signed zero correctness is required.
Foz-DB Navi48:
Totals from 1344 (1.63% of 82636) affected shaders:
Instrs: 5319389 -> 5312280 (-0.13%); split: -0.14%, +0.01%
CodeSize: 29702516 -> 29665684 (-0.12%); split: -0.13%, +0.01%
Latency: 40694344 -> 40694545 (+0.00%); split: -0.01%, +0.02%
InvThroughput: 7481192 -> 7480403 (-0.01%); split: -0.02%, +0.01%
VClause: 121947 -> 121946 (-0.00%); split: -0.00%, +0.00%
SClause: 104972 -> 104923 (-0.05%); split: -0.05%, +0.00%
Copies: 371098 -> 371092 (-0.00%); split: -0.02%, +0.02%
Branches: 122929 -> 122919 (-0.01%); split: -0.01%, +0.00%
PreSGPRs: 82506 -> 82510 (+0.00%); split: -0.00%, +0.01%
PreVGPRs: 79175 -> 79168 (-0.01%)
VALU: 2906718 -> 2904777 (-0.07%); split: -0.07%, +0.00%
SALU: 726256 -> 723454 (-0.39%); split: -0.39%, +0.00%
VMEM: 205021 -> 205016 (-0.00%)
SMEM: 163972 -> 163916 (-0.03%)
VOPD: 303354 -> 303298 (-0.02%); split: +0.02%, -0.04%
Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/39987>
2026-02-08 23:03:16 +01:00
|
|
|
*result = analyze_fp_constant(nir_def_as_load_const(def));
|
2023-02-14 21:38:41 +00:00
|
|
|
return;
|
|
|
|
|
}
|
2018-01-23 09:48:43 +08:00
|
|
|
|
2026-02-07 22:36:25 +01:00
|
|
|
if (!nir_def_is_alu(def)) {
|
nir: rewrite fp range analysis as a fp class analysis
Knowing if a value is not larger than one helps proving finite
results of fmul/fadd and will allow skipping/creating more fsat.
Knowing that a value is larger than one helps proving non zero
results of fmul.
Separating positive and negative zero also has advantages when
signed zero correctness is required.
Foz-DB Navi48:
Totals from 1344 (1.63% of 82636) affected shaders:
Instrs: 5319389 -> 5312280 (-0.13%); split: -0.14%, +0.01%
CodeSize: 29702516 -> 29665684 (-0.12%); split: -0.13%, +0.01%
Latency: 40694344 -> 40694545 (+0.00%); split: -0.01%, +0.02%
InvThroughput: 7481192 -> 7480403 (-0.01%); split: -0.02%, +0.01%
VClause: 121947 -> 121946 (-0.00%); split: -0.00%, +0.00%
SClause: 104972 -> 104923 (-0.05%); split: -0.05%, +0.00%
Copies: 371098 -> 371092 (-0.00%); split: -0.02%, +0.02%
Branches: 122929 -> 122919 (-0.01%); split: -0.01%, +0.00%
PreSGPRs: 82506 -> 82510 (+0.00%); split: -0.00%, +0.01%
PreVGPRs: 79175 -> 79168 (-0.01%)
VALU: 2906718 -> 2904777 (-0.07%); split: -0.07%, +0.00%
SALU: 726256 -> 723454 (-0.39%); split: -0.39%, +0.00%
VMEM: 205021 -> 205016 (-0.00%)
SMEM: 163972 -> 163916 (-0.03%)
VOPD: 303354 -> 303298 (-0.02%); split: +0.02%, -0.04%
Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/39987>
2026-02-08 23:03:16 +01:00
|
|
|
*result = FP_CLASS_UNKNOWN;
|
2023-02-14 21:38:41 +00:00
|
|
|
return;
|
|
|
|
|
}
|
2018-01-23 09:48:43 +08:00
|
|
|
|
2026-02-07 22:36:25 +01:00
|
|
|
const nir_alu_instr *const alu = nir_def_as_alu(def);
|
2018-01-23 09:48:43 +08:00
|
|
|
|
2023-02-14 21:38:41 +00:00
|
|
|
if (!aq->pushed_queries) {
|
|
|
|
|
switch (alu->op) {
|
|
|
|
|
case nir_op_bcsel:
|
2026-02-07 22:36:25 +01:00
|
|
|
push_fp_query(state, alu->src[1].src.ssa);
|
|
|
|
|
push_fp_query(state, alu->src[2].src.ssa);
|
2023-02-14 21:38:41 +00:00
|
|
|
return;
|
|
|
|
|
case nir_op_mov:
|
|
|
|
|
case nir_op_fabs:
|
|
|
|
|
case nir_op_fexp2:
|
2026-02-11 19:58:41 +01:00
|
|
|
case nir_op_flog2:
|
2023-02-14 21:38:41 +00:00
|
|
|
case nir_op_frcp:
|
2025-02-14 20:13:58 +01:00
|
|
|
case nir_op_fsqrt:
|
2025-02-14 20:05:54 +01:00
|
|
|
case nir_op_frsq:
|
2023-02-14 21:38:41 +00:00
|
|
|
case nir_op_fneg:
|
|
|
|
|
case nir_op_fsat:
|
|
|
|
|
case nir_op_fsign:
|
|
|
|
|
case nir_op_ffloor:
|
|
|
|
|
case nir_op_fceil:
|
|
|
|
|
case nir_op_ftrunc:
|
2025-02-14 18:54:09 +01:00
|
|
|
case nir_op_ffract:
|
2026-02-11 19:53:46 +01:00
|
|
|
case nir_op_fsin:
|
|
|
|
|
case nir_op_fcos:
|
|
|
|
|
case nir_op_fsin_amd:
|
|
|
|
|
case nir_op_fcos_amd:
|
2025-07-30 15:04:06 +02:00
|
|
|
case nir_op_f2f16:
|
|
|
|
|
case nir_op_f2f16_rtz:
|
|
|
|
|
case nir_op_f2f16_rtne:
|
|
|
|
|
case nir_op_f2f32:
|
|
|
|
|
case nir_op_f2f64:
|
2023-02-14 21:38:41 +00:00
|
|
|
case nir_op_fdot2:
|
|
|
|
|
case nir_op_fdot3:
|
|
|
|
|
case nir_op_fdot4:
|
|
|
|
|
case nir_op_fdot8:
|
|
|
|
|
case nir_op_fdot16:
|
|
|
|
|
case nir_op_fdot2_replicated:
|
|
|
|
|
case nir_op_fdot3_replicated:
|
|
|
|
|
case nir_op_fdot4_replicated:
|
|
|
|
|
case nir_op_fdot8_replicated:
|
|
|
|
|
case nir_op_fdot16_replicated:
|
2026-02-07 22:36:25 +01:00
|
|
|
push_fp_query(state, alu->src[0].src.ssa);
|
2023-02-14 21:38:41 +00:00
|
|
|
return;
|
|
|
|
|
case nir_op_fadd:
|
|
|
|
|
case nir_op_fmax:
|
|
|
|
|
case nir_op_fmin:
|
|
|
|
|
case nir_op_fmul:
|
|
|
|
|
case nir_op_fmulz:
|
|
|
|
|
case nir_op_fpow:
|
2026-02-07 22:36:25 +01:00
|
|
|
case nir_op_vec2:
|
|
|
|
|
push_fp_query(state, alu->src[0].src.ssa);
|
|
|
|
|
push_fp_query(state, alu->src[1].src.ssa);
|
2023-02-14 21:38:41 +00:00
|
|
|
return;
|
|
|
|
|
case nir_op_ffma:
|
2025-03-24 08:20:46 +01:00
|
|
|
case nir_op_ffmaz:
|
2023-02-14 21:38:41 +00:00
|
|
|
case nir_op_flrp:
|
2026-02-07 22:36:25 +01:00
|
|
|
push_fp_query(state, alu->src[0].src.ssa);
|
|
|
|
|
push_fp_query(state, alu->src[1].src.ssa);
|
|
|
|
|
push_fp_query(state, alu->src[2].src.ssa);
|
2023-02-14 21:38:41 +00:00
|
|
|
return;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-01-23 09:48:43 +08:00
|
|
|
|
nir: rewrite fp range analysis as a fp class analysis
Knowing if a value is not larger than one helps proving finite
results of fmul/fadd and will allow skipping/creating more fsat.
Knowing that a value is larger than one helps proving non zero
results of fmul.
Separating positive and negative zero also has advantages when
signed zero correctness is required.
Foz-DB Navi48:
Totals from 1344 (1.63% of 82636) affected shaders:
Instrs: 5319389 -> 5312280 (-0.13%); split: -0.14%, +0.01%
CodeSize: 29702516 -> 29665684 (-0.12%); split: -0.13%, +0.01%
Latency: 40694344 -> 40694545 (+0.00%); split: -0.01%, +0.02%
InvThroughput: 7481192 -> 7480403 (-0.01%); split: -0.02%, +0.01%
VClause: 121947 -> 121946 (-0.00%); split: -0.00%, +0.00%
SClause: 104972 -> 104923 (-0.05%); split: -0.05%, +0.00%
Copies: 371098 -> 371092 (-0.00%); split: -0.02%, +0.02%
Branches: 122929 -> 122919 (-0.01%); split: -0.01%, +0.00%
PreSGPRs: 82506 -> 82510 (+0.00%); split: -0.00%, +0.01%
PreVGPRs: 79175 -> 79168 (-0.01%)
VALU: 2906718 -> 2904777 (-0.07%); split: -0.07%, +0.00%
SALU: 726256 -> 723454 (-0.39%); split: -0.39%, +0.00%
VMEM: 205021 -> 205016 (-0.00%)
SMEM: 163972 -> 163916 (-0.03%)
VOPD: 303354 -> 303298 (-0.02%); split: +0.02%, -0.04%
Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/39987>
2026-02-08 23:03:16 +01:00
|
|
|
fp_class_mask r = FP_CLASS_UNKNOWN;
|
2019-08-12 15:40:20 -07:00
|
|
|
|
2018-01-23 09:48:43 +08:00
|
|
|
switch (alu->op) {
|
nir: rewrite fp range analysis as a fp class analysis
Knowing if a value is not larger than one helps proving finite
results of fmul/fadd and will allow skipping/creating more fsat.
Knowing that a value is larger than one helps proving non zero
results of fmul.
Separating positive and negative zero also has advantages when
signed zero correctness is required.
Foz-DB Navi48:
Totals from 1344 (1.63% of 82636) affected shaders:
Instrs: 5319389 -> 5312280 (-0.13%); split: -0.14%, +0.01%
CodeSize: 29702516 -> 29665684 (-0.12%); split: -0.13%, +0.01%
Latency: 40694344 -> 40694545 (+0.00%); split: -0.01%, +0.02%
InvThroughput: 7481192 -> 7480403 (-0.01%); split: -0.02%, +0.01%
VClause: 121947 -> 121946 (-0.00%); split: -0.00%, +0.00%
SClause: 104972 -> 104923 (-0.05%); split: -0.05%, +0.00%
Copies: 371098 -> 371092 (-0.00%); split: -0.02%, +0.02%
Branches: 122929 -> 122919 (-0.01%); split: -0.01%, +0.00%
PreSGPRs: 82506 -> 82510 (+0.00%); split: -0.00%, +0.01%
PreVGPRs: 79175 -> 79168 (-0.01%)
VALU: 2906718 -> 2904777 (-0.07%); split: -0.07%, +0.00%
SALU: 726256 -> 723454 (-0.39%); split: -0.39%, +0.00%
VMEM: 205021 -> 205016 (-0.00%)
SMEM: 163972 -> 163916 (-0.03%)
VOPD: 303354 -> 303298 (-0.02%); split: +0.02%, -0.04%
Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/39987>
2026-02-08 23:03:16 +01:00
|
|
|
case nir_op_b2i16:
|
2018-01-23 09:48:43 +08:00
|
|
|
case nir_op_b2i32:
|
nir: rewrite fp range analysis as a fp class analysis
Knowing if a value is not larger than one helps proving finite
results of fmul/fadd and will allow skipping/creating more fsat.
Knowing that a value is larger than one helps proving non zero
results of fmul.
Separating positive and negative zero also has advantages when
signed zero correctness is required.
Foz-DB Navi48:
Totals from 1344 (1.63% of 82636) affected shaders:
Instrs: 5319389 -> 5312280 (-0.13%); split: -0.14%, +0.01%
CodeSize: 29702516 -> 29665684 (-0.12%); split: -0.13%, +0.01%
Latency: 40694344 -> 40694545 (+0.00%); split: -0.01%, +0.02%
InvThroughput: 7481192 -> 7480403 (-0.01%); split: -0.02%, +0.01%
VClause: 121947 -> 121946 (-0.00%); split: -0.00%, +0.00%
SClause: 104972 -> 104923 (-0.05%); split: -0.05%, +0.00%
Copies: 371098 -> 371092 (-0.00%); split: -0.02%, +0.02%
Branches: 122929 -> 122919 (-0.01%); split: -0.01%, +0.00%
PreSGPRs: 82506 -> 82510 (+0.00%); split: -0.00%, +0.01%
PreVGPRs: 79175 -> 79168 (-0.01%)
VALU: 2906718 -> 2904777 (-0.07%); split: -0.07%, +0.00%
SALU: 726256 -> 723454 (-0.39%); split: -0.39%, +0.00%
VMEM: 205021 -> 205016 (-0.00%)
SMEM: 163972 -> 163916 (-0.03%)
VOPD: 303354 -> 303298 (-0.02%); split: +0.02%, -0.04%
Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/39987>
2026-02-08 23:03:16 +01:00
|
|
|
case nir_op_b2i64:
|
|
|
|
|
/* b2i32 will generate either 0x00000000 or 0x00000001. When those bit
|
2020-08-17 15:56:24 -07:00
|
|
|
* patterns are interpreted as floating point, they are 0.0 and
|
nir: rewrite fp range analysis as a fp class analysis
Knowing if a value is not larger than one helps proving finite
results of fmul/fadd and will allow skipping/creating more fsat.
Knowing that a value is larger than one helps proving non zero
results of fmul.
Separating positive and negative zero also has advantages when
signed zero correctness is required.
Foz-DB Navi48:
Totals from 1344 (1.63% of 82636) affected shaders:
Instrs: 5319389 -> 5312280 (-0.13%); split: -0.14%, +0.01%
CodeSize: 29702516 -> 29665684 (-0.12%); split: -0.13%, +0.01%
Latency: 40694344 -> 40694545 (+0.00%); split: -0.01%, +0.02%
InvThroughput: 7481192 -> 7480403 (-0.01%); split: -0.02%, +0.01%
VClause: 121947 -> 121946 (-0.00%); split: -0.00%, +0.00%
SClause: 104972 -> 104923 (-0.05%); split: -0.05%, +0.00%
Copies: 371098 -> 371092 (-0.00%); split: -0.02%, +0.02%
Branches: 122929 -> 122919 (-0.01%); split: -0.01%, +0.00%
PreSGPRs: 82506 -> 82510 (+0.00%); split: -0.00%, +0.01%
PreVGPRs: 79175 -> 79168 (-0.01%)
VALU: 2906718 -> 2904777 (-0.07%); split: -0.07%, +0.00%
SALU: 726256 -> 723454 (-0.39%); split: -0.39%, +0.00%
VMEM: 205021 -> 205016 (-0.00%)
SMEM: 163972 -> 163916 (-0.03%)
VOPD: 303354 -> 303298 (-0.02%); split: +0.02%, -0.04%
Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/39987>
2026-02-08 23:03:16 +01:00
|
|
|
* 1.401298464324817e-45. The latter is subnormal.
|
2020-08-17 15:56:24 -07:00
|
|
|
*/
|
nir: rewrite fp range analysis as a fp class analysis
Knowing if a value is not larger than one helps proving finite
results of fmul/fadd and will allow skipping/creating more fsat.
Knowing that a value is larger than one helps proving non zero
results of fmul.
Separating positive and negative zero also has advantages when
signed zero correctness is required.
Foz-DB Navi48:
Totals from 1344 (1.63% of 82636) affected shaders:
Instrs: 5319389 -> 5312280 (-0.13%); split: -0.14%, +0.01%
CodeSize: 29702516 -> 29665684 (-0.12%); split: -0.13%, +0.01%
Latency: 40694344 -> 40694545 (+0.00%); split: -0.01%, +0.02%
InvThroughput: 7481192 -> 7480403 (-0.01%); split: -0.02%, +0.01%
VClause: 121947 -> 121946 (-0.00%); split: -0.00%, +0.00%
SClause: 104972 -> 104923 (-0.05%); split: -0.05%, +0.00%
Copies: 371098 -> 371092 (-0.00%); split: -0.02%, +0.02%
Branches: 122929 -> 122919 (-0.01%); split: -0.01%, +0.00%
PreSGPRs: 82506 -> 82510 (+0.00%); split: -0.00%, +0.01%
PreVGPRs: 79175 -> 79168 (-0.01%)
VALU: 2906718 -> 2904777 (-0.07%); split: -0.07%, +0.00%
SALU: 726256 -> 723454 (-0.39%); split: -0.39%, +0.00%
VMEM: 205021 -> 205016 (-0.00%)
SMEM: 163972 -> 163916 (-0.03%)
VOPD: 303354 -> 303298 (-0.02%); split: +0.02%, -0.04%
Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/39987>
2026-02-08 23:03:16 +01:00
|
|
|
r = FP_CLASS_POS_ZERO | FP_CLASS_GT_ZERO_LT_POS_ONE;
|
2018-01-23 09:48:43 +08:00
|
|
|
break;
|
|
|
|
|
|
nir: rewrite fp range analysis as a fp class analysis
Knowing if a value is not larger than one helps proving finite
results of fmul/fadd and will allow skipping/creating more fsat.
Knowing that a value is larger than one helps proving non zero
results of fmul.
Separating positive and negative zero also has advantages when
signed zero correctness is required.
Foz-DB Navi48:
Totals from 1344 (1.63% of 82636) affected shaders:
Instrs: 5319389 -> 5312280 (-0.13%); split: -0.14%, +0.01%
CodeSize: 29702516 -> 29665684 (-0.12%); split: -0.13%, +0.01%
Latency: 40694344 -> 40694545 (+0.00%); split: -0.01%, +0.02%
InvThroughput: 7481192 -> 7480403 (-0.01%); split: -0.02%, +0.01%
VClause: 121947 -> 121946 (-0.00%); split: -0.00%, +0.00%
SClause: 104972 -> 104923 (-0.05%); split: -0.05%, +0.00%
Copies: 371098 -> 371092 (-0.00%); split: -0.02%, +0.02%
Branches: 122929 -> 122919 (-0.01%); split: -0.01%, +0.00%
PreSGPRs: 82506 -> 82510 (+0.00%); split: -0.00%, +0.01%
PreVGPRs: 79175 -> 79168 (-0.01%)
VALU: 2906718 -> 2904777 (-0.07%); split: -0.07%, +0.00%
SALU: 726256 -> 723454 (-0.39%); split: -0.39%, +0.00%
VMEM: 205021 -> 205016 (-0.00%)
SMEM: 163972 -> 163916 (-0.03%)
VOPD: 303354 -> 303298 (-0.02%); split: +0.02%, -0.04%
Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/39987>
2026-02-08 23:03:16 +01:00
|
|
|
case nir_op_b2f16:
|
|
|
|
|
case nir_op_b2f32:
|
|
|
|
|
case nir_op_b2f64:
|
|
|
|
|
r = FP_CLASS_POS_ZERO | FP_CLASS_POS_ONE;
|
|
|
|
|
break;
|
2018-01-24 20:23:15 +08:00
|
|
|
|
nir: rewrite fp range analysis as a fp class analysis
Knowing if a value is not larger than one helps proving finite
results of fmul/fadd and will allow skipping/creating more fsat.
Knowing that a value is larger than one helps proving non zero
results of fmul.
Separating positive and negative zero also has advantages when
signed zero correctness is required.
Foz-DB Navi48:
Totals from 1344 (1.63% of 82636) affected shaders:
Instrs: 5319389 -> 5312280 (-0.13%); split: -0.14%, +0.01%
CodeSize: 29702516 -> 29665684 (-0.12%); split: -0.13%, +0.01%
Latency: 40694344 -> 40694545 (+0.00%); split: -0.01%, +0.02%
InvThroughput: 7481192 -> 7480403 (-0.01%); split: -0.02%, +0.01%
VClause: 121947 -> 121946 (-0.00%); split: -0.00%, +0.00%
SClause: 104972 -> 104923 (-0.05%); split: -0.05%, +0.00%
Copies: 371098 -> 371092 (-0.00%); split: -0.02%, +0.02%
Branches: 122929 -> 122919 (-0.01%); split: -0.01%, +0.00%
PreSGPRs: 82506 -> 82510 (+0.00%); split: -0.00%, +0.01%
PreVGPRs: 79175 -> 79168 (-0.01%)
VALU: 2906718 -> 2904777 (-0.07%); split: -0.07%, +0.00%
SALU: 726256 -> 723454 (-0.39%); split: -0.39%, +0.00%
VMEM: 205021 -> 205016 (-0.00%)
SMEM: 163972 -> 163916 (-0.03%)
VOPD: 303354 -> 303298 (-0.02%); split: +0.02%, -0.04%
Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/39987>
2026-02-08 23:03:16 +01:00
|
|
|
case nir_op_vec2:
|
|
|
|
|
case nir_op_bcsel:
|
|
|
|
|
r = src_res[0] | src_res[1];
|
2018-01-24 20:23:15 +08:00
|
|
|
break;
|
|
|
|
|
|
nir: rewrite fp range analysis as a fp class analysis
Knowing if a value is not larger than one helps proving finite
results of fmul/fadd and will allow skipping/creating more fsat.
Knowing that a value is larger than one helps proving non zero
results of fmul.
Separating positive and negative zero also has advantages when
signed zero correctness is required.
Foz-DB Navi48:
Totals from 1344 (1.63% of 82636) affected shaders:
Instrs: 5319389 -> 5312280 (-0.13%); split: -0.14%, +0.01%
CodeSize: 29702516 -> 29665684 (-0.12%); split: -0.13%, +0.01%
Latency: 40694344 -> 40694545 (+0.00%); split: -0.01%, +0.02%
InvThroughput: 7481192 -> 7480403 (-0.01%); split: -0.02%, +0.01%
VClause: 121947 -> 121946 (-0.00%); split: -0.00%, +0.00%
SClause: 104972 -> 104923 (-0.05%); split: -0.05%, +0.00%
Copies: 371098 -> 371092 (-0.00%); split: -0.02%, +0.02%
Branches: 122929 -> 122919 (-0.01%); split: -0.01%, +0.00%
PreSGPRs: 82506 -> 82510 (+0.00%); split: -0.00%, +0.01%
PreVGPRs: 79175 -> 79168 (-0.01%)
VALU: 2906718 -> 2904777 (-0.07%); split: -0.07%, +0.00%
SALU: 726256 -> 723454 (-0.39%); split: -0.39%, +0.00%
VMEM: 205021 -> 205016 (-0.00%)
SMEM: 163972 -> 163916 (-0.03%)
VOPD: 303354 -> 303298 (-0.02%); split: +0.02%, -0.04%
Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/39987>
2026-02-08 23:03:16 +01:00
|
|
|
case nir_op_i2f16:
|
2018-01-23 09:48:43 +08:00
|
|
|
case nir_op_i2f32:
|
nir: rewrite fp range analysis as a fp class analysis
Knowing if a value is not larger than one helps proving finite
results of fmul/fadd and will allow skipping/creating more fsat.
Knowing that a value is larger than one helps proving non zero
results of fmul.
Separating positive and negative zero also has advantages when
signed zero correctness is required.
Foz-DB Navi48:
Totals from 1344 (1.63% of 82636) affected shaders:
Instrs: 5319389 -> 5312280 (-0.13%); split: -0.14%, +0.01%
CodeSize: 29702516 -> 29665684 (-0.12%); split: -0.13%, +0.01%
Latency: 40694344 -> 40694545 (+0.00%); split: -0.01%, +0.02%
InvThroughput: 7481192 -> 7480403 (-0.01%); split: -0.02%, +0.01%
VClause: 121947 -> 121946 (-0.00%); split: -0.00%, +0.00%
SClause: 104972 -> 104923 (-0.05%); split: -0.05%, +0.00%
Copies: 371098 -> 371092 (-0.00%); split: -0.02%, +0.02%
Branches: 122929 -> 122919 (-0.01%); split: -0.01%, +0.00%
PreSGPRs: 82506 -> 82510 (+0.00%); split: -0.00%, +0.01%
PreVGPRs: 79175 -> 79168 (-0.01%)
VALU: 2906718 -> 2904777 (-0.07%); split: -0.07%, +0.00%
SALU: 726256 -> 723454 (-0.39%); split: -0.39%, +0.00%
VMEM: 205021 -> 205016 (-0.00%)
SMEM: 163972 -> 163916 (-0.03%)
VOPD: 303354 -> 303298 (-0.02%); split: +0.02%, -0.04%
Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/39987>
2026-02-08 23:03:16 +01:00
|
|
|
case nir_op_i2f64:
|
|
|
|
|
r &= ~FP_CLASS_NAN;
|
|
|
|
|
r &= ~FP_CLASS_NON_INTEGRAL;
|
|
|
|
|
r &= ~FP_CLASS_GT_ZERO_LT_POS_ONE;
|
|
|
|
|
r &= ~FP_CLASS_LT_ZERO_GT_NEG_ONE;
|
|
|
|
|
r &= ~FP_CLASS_NEG_ZERO;
|
|
|
|
|
if (alu->def.bit_size > 16 || alu->src[0].src.ssa->bit_size <= 16)
|
|
|
|
|
r &= ~FP_CLASS_ANY_INF;
|
|
|
|
|
break;
|
2018-01-23 09:48:43 +08:00
|
|
|
|
nir: rewrite fp range analysis as a fp class analysis
Knowing if a value is not larger than one helps proving finite
results of fmul/fadd and will allow skipping/creating more fsat.
Knowing that a value is larger than one helps proving non zero
results of fmul.
Separating positive and negative zero also has advantages when
signed zero correctness is required.
Foz-DB Navi48:
Totals from 1344 (1.63% of 82636) affected shaders:
Instrs: 5319389 -> 5312280 (-0.13%); split: -0.14%, +0.01%
CodeSize: 29702516 -> 29665684 (-0.12%); split: -0.13%, +0.01%
Latency: 40694344 -> 40694545 (+0.00%); split: -0.01%, +0.02%
InvThroughput: 7481192 -> 7480403 (-0.01%); split: -0.02%, +0.01%
VClause: 121947 -> 121946 (-0.00%); split: -0.00%, +0.00%
SClause: 104972 -> 104923 (-0.05%); split: -0.05%, +0.00%
Copies: 371098 -> 371092 (-0.00%); split: -0.02%, +0.02%
Branches: 122929 -> 122919 (-0.01%); split: -0.01%, +0.00%
PreSGPRs: 82506 -> 82510 (+0.00%); split: -0.00%, +0.01%
PreVGPRs: 79175 -> 79168 (-0.01%)
VALU: 2906718 -> 2904777 (-0.07%); split: -0.07%, +0.00%
SALU: 726256 -> 723454 (-0.39%); split: -0.39%, +0.00%
VMEM: 205021 -> 205016 (-0.00%)
SMEM: 163972 -> 163916 (-0.03%)
VOPD: 303354 -> 303298 (-0.02%); split: +0.02%, -0.04%
Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/39987>
2026-02-08 23:03:16 +01:00
|
|
|
case nir_op_u2f16:
|
|
|
|
|
case nir_op_u2f32:
|
|
|
|
|
case nir_op_u2f64:
|
|
|
|
|
r &= ~FP_CLASS_NAN;
|
|
|
|
|
r &= ~FP_CLASS_NON_INTEGRAL;
|
|
|
|
|
r &= ~FP_CLASS_GT_ZERO_LT_POS_ONE;
|
|
|
|
|
r &= ~FP_CLASS_NEG_ZERO;
|
|
|
|
|
r &= ~FP_CLASS_ANY_NEG;
|
|
|
|
|
if (alu->def.bit_size > 16 || alu->src[0].src.ssa->bit_size < 16)
|
|
|
|
|
r &= ~FP_CLASS_ANY_INF;
|
2018-01-23 09:48:43 +08:00
|
|
|
break;
|
|
|
|
|
|
2025-07-30 15:04:06 +02:00
|
|
|
case nir_op_f2f16:
|
|
|
|
|
case nir_op_f2f16_rtz:
|
|
|
|
|
case nir_op_f2f16_rtne:
|
|
|
|
|
case nir_op_f2f32:
|
|
|
|
|
case nir_op_f2f64: {
|
nir: rewrite fp range analysis as a fp class analysis
Knowing if a value is not larger than one helps proving finite
results of fmul/fadd and will allow skipping/creating more fsat.
Knowing that a value is larger than one helps proving non zero
results of fmul.
Separating positive and negative zero also has advantages when
signed zero correctness is required.
Foz-DB Navi48:
Totals from 1344 (1.63% of 82636) affected shaders:
Instrs: 5319389 -> 5312280 (-0.13%); split: -0.14%, +0.01%
CodeSize: 29702516 -> 29665684 (-0.12%); split: -0.13%, +0.01%
Latency: 40694344 -> 40694545 (+0.00%); split: -0.01%, +0.02%
InvThroughput: 7481192 -> 7480403 (-0.01%); split: -0.02%, +0.01%
VClause: 121947 -> 121946 (-0.00%); split: -0.00%, +0.00%
SClause: 104972 -> 104923 (-0.05%); split: -0.05%, +0.00%
Copies: 371098 -> 371092 (-0.00%); split: -0.02%, +0.02%
Branches: 122929 -> 122919 (-0.01%); split: -0.01%, +0.00%
PreSGPRs: 82506 -> 82510 (+0.00%); split: -0.00%, +0.01%
PreVGPRs: 79175 -> 79168 (-0.01%)
VALU: 2906718 -> 2904777 (-0.07%); split: -0.07%, +0.00%
SALU: 726256 -> 723454 (-0.39%); split: -0.39%, +0.00%
VMEM: 205021 -> 205016 (-0.00%)
SMEM: 163972 -> 163916 (-0.03%)
VOPD: 303354 -> 303298 (-0.02%); split: +0.02%, -0.04%
Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/39987>
2026-02-08 23:03:16 +01:00
|
|
|
r = handle_sz(alu, src_res[0]);
|
2025-07-30 15:04:06 +02:00
|
|
|
|
|
|
|
|
if (alu->src[0].src.ssa->bit_size > alu->def.bit_size) {
|
nir: rewrite fp range analysis as a fp class analysis
Knowing if a value is not larger than one helps proving finite
results of fmul/fadd and will allow skipping/creating more fsat.
Knowing that a value is larger than one helps proving non zero
results of fmul.
Separating positive and negative zero also has advantages when
signed zero correctness is required.
Foz-DB Navi48:
Totals from 1344 (1.63% of 82636) affected shaders:
Instrs: 5319389 -> 5312280 (-0.13%); split: -0.14%, +0.01%
CodeSize: 29702516 -> 29665684 (-0.12%); split: -0.13%, +0.01%
Latency: 40694344 -> 40694545 (+0.00%); split: -0.01%, +0.02%
InvThroughput: 7481192 -> 7480403 (-0.01%); split: -0.02%, +0.01%
VClause: 121947 -> 121946 (-0.00%); split: -0.00%, +0.00%
SClause: 104972 -> 104923 (-0.05%); split: -0.05%, +0.00%
Copies: 371098 -> 371092 (-0.00%); split: -0.02%, +0.02%
Branches: 122929 -> 122919 (-0.01%); split: -0.01%, +0.00%
PreSGPRs: 82506 -> 82510 (+0.00%); split: -0.00%, +0.01%
PreVGPRs: 79175 -> 79168 (-0.01%)
VALU: 2906718 -> 2904777 (-0.07%); split: -0.07%, +0.00%
SALU: 726256 -> 723454 (-0.39%); split: -0.39%, +0.00%
VMEM: 205021 -> 205016 (-0.00%)
SMEM: 163972 -> 163916 (-0.03%)
VOPD: 303354 -> 303298 (-0.02%); split: +0.02%, -0.04%
Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/39987>
2026-02-08 23:03:16 +01:00
|
|
|
bool rtz = alu->op == nir_op_f2f16_rtz;
|
|
|
|
|
if (alu->op != nir_op_f2f16_rtne && alu->op != nir_op_f2f16_rtz) {
|
|
|
|
|
nir_shader *shader = nir_cf_node_get_function(&alu->instr.block->cf_node)->function->shader;
|
|
|
|
|
unsigned execution_mode = shader->info.float_controls_execution_mode;
|
|
|
|
|
rtz = nir_is_rounding_mode_rtz(execution_mode, alu->def.bit_size);
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-30 15:04:06 +02:00
|
|
|
/* Unless we are rounding towards zero, large values can create Inf. */
|
nir: rewrite fp range analysis as a fp class analysis
Knowing if a value is not larger than one helps proving finite
results of fmul/fadd and will allow skipping/creating more fsat.
Knowing that a value is larger than one helps proving non zero
results of fmul.
Separating positive and negative zero also has advantages when
signed zero correctness is required.
Foz-DB Navi48:
Totals from 1344 (1.63% of 82636) affected shaders:
Instrs: 5319389 -> 5312280 (-0.13%); split: -0.14%, +0.01%
CodeSize: 29702516 -> 29665684 (-0.12%); split: -0.13%, +0.01%
Latency: 40694344 -> 40694545 (+0.00%); split: -0.01%, +0.02%
InvThroughput: 7481192 -> 7480403 (-0.01%); split: -0.02%, +0.01%
VClause: 121947 -> 121946 (-0.00%); split: -0.00%, +0.00%
SClause: 104972 -> 104923 (-0.05%); split: -0.05%, +0.00%
Copies: 371098 -> 371092 (-0.00%); split: -0.02%, +0.02%
Branches: 122929 -> 122919 (-0.01%); split: -0.01%, +0.00%
PreSGPRs: 82506 -> 82510 (+0.00%); split: -0.00%, +0.01%
PreVGPRs: 79175 -> 79168 (-0.01%)
VALU: 2906718 -> 2904777 (-0.07%); split: -0.07%, +0.00%
SALU: 726256 -> 723454 (-0.39%); split: -0.39%, +0.00%
VMEM: 205021 -> 205016 (-0.00%)
SMEM: 163972 -> 163916 (-0.03%)
VOPD: 303354 -> 303298 (-0.02%); split: +0.02%, -0.04%
Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/39987>
2026-02-08 23:03:16 +01:00
|
|
|
if (r & FP_CLASS_LT_NEG_ONE) {
|
|
|
|
|
if (!rtz)
|
|
|
|
|
r |= FP_CLASS_NEG_INF;
|
|
|
|
|
r |= FP_CLASS_NEG_ONE;
|
|
|
|
|
}
|
|
|
|
|
if (r & FP_CLASS_GT_POS_ONE) {
|
|
|
|
|
if (!rtz)
|
|
|
|
|
r |= FP_CLASS_POS_INF;
|
|
|
|
|
r |= FP_CLASS_POS_ONE;
|
|
|
|
|
}
|
2025-07-30 15:04:06 +02:00
|
|
|
|
|
|
|
|
/* Underflow can create new zeros. */
|
nir: rewrite fp range analysis as a fp class analysis
Knowing if a value is not larger than one helps proving finite
results of fmul/fadd and will allow skipping/creating more fsat.
Knowing that a value is larger than one helps proving non zero
results of fmul.
Separating positive and negative zero also has advantages when
signed zero correctness is required.
Foz-DB Navi48:
Totals from 1344 (1.63% of 82636) affected shaders:
Instrs: 5319389 -> 5312280 (-0.13%); split: -0.14%, +0.01%
CodeSize: 29702516 -> 29665684 (-0.12%); split: -0.13%, +0.01%
Latency: 40694344 -> 40694545 (+0.00%); split: -0.01%, +0.02%
InvThroughput: 7481192 -> 7480403 (-0.01%); split: -0.02%, +0.01%
VClause: 121947 -> 121946 (-0.00%); split: -0.00%, +0.00%
SClause: 104972 -> 104923 (-0.05%); split: -0.05%, +0.00%
Copies: 371098 -> 371092 (-0.00%); split: -0.02%, +0.02%
Branches: 122929 -> 122919 (-0.01%); split: -0.01%, +0.00%
PreSGPRs: 82506 -> 82510 (+0.00%); split: -0.00%, +0.01%
PreVGPRs: 79175 -> 79168 (-0.01%)
VALU: 2906718 -> 2904777 (-0.07%); split: -0.07%, +0.00%
SALU: 726256 -> 723454 (-0.39%); split: -0.39%, +0.00%
VMEM: 205021 -> 205016 (-0.00%)
SMEM: 163972 -> 163916 (-0.03%)
VOPD: 303354 -> 303298 (-0.02%); split: +0.02%, -0.04%
Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/39987>
2026-02-08 23:03:16 +01:00
|
|
|
if (r & FP_CLASS_LT_ZERO_GT_NEG_ONE) {
|
|
|
|
|
if (!rtz)
|
|
|
|
|
r |= FP_CLASS_NEG_ONE;
|
|
|
|
|
r |= FP_CLASS_NEG_ZERO;
|
|
|
|
|
}
|
|
|
|
|
if (r & FP_CLASS_GT_ZERO_LT_POS_ONE) {
|
|
|
|
|
if (!rtz)
|
|
|
|
|
r |= FP_CLASS_POS_ONE;
|
|
|
|
|
r |= FP_CLASS_POS_ZERO;
|
|
|
|
|
}
|
2025-07-30 15:04:06 +02:00
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
nir: rewrite fp range analysis as a fp class analysis
Knowing if a value is not larger than one helps proving finite
results of fmul/fadd and will allow skipping/creating more fsat.
Knowing that a value is larger than one helps proving non zero
results of fmul.
Separating positive and negative zero also has advantages when
signed zero correctness is required.
Foz-DB Navi48:
Totals from 1344 (1.63% of 82636) affected shaders:
Instrs: 5319389 -> 5312280 (-0.13%); split: -0.14%, +0.01%
CodeSize: 29702516 -> 29665684 (-0.12%); split: -0.13%, +0.01%
Latency: 40694344 -> 40694545 (+0.00%); split: -0.01%, +0.02%
InvThroughput: 7481192 -> 7480403 (-0.01%); split: -0.02%, +0.01%
VClause: 121947 -> 121946 (-0.00%); split: -0.00%, +0.00%
SClause: 104972 -> 104923 (-0.05%); split: -0.05%, +0.00%
Copies: 371098 -> 371092 (-0.00%); split: -0.02%, +0.02%
Branches: 122929 -> 122919 (-0.01%); split: -0.01%, +0.00%
PreSGPRs: 82506 -> 82510 (+0.00%); split: -0.00%, +0.01%
PreVGPRs: 79175 -> 79168 (-0.01%)
VALU: 2906718 -> 2904777 (-0.07%); split: -0.07%, +0.00%
SALU: 726256 -> 723454 (-0.39%); split: -0.39%, +0.00%
VMEM: 205021 -> 205016 (-0.00%)
SMEM: 163972 -> 163916 (-0.03%)
VOPD: 303354 -> 303298 (-0.02%); split: +0.02%, -0.04%
Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/39987>
2026-02-08 23:03:16 +01:00
|
|
|
case nir_op_fneg:
|
|
|
|
|
r = fneg_fp_class(src_res[0]);
|
|
|
|
|
break;
|
2018-01-23 09:48:43 +08:00
|
|
|
|
nir: rewrite fp range analysis as a fp class analysis
Knowing if a value is not larger than one helps proving finite
results of fmul/fadd and will allow skipping/creating more fsat.
Knowing that a value is larger than one helps proving non zero
results of fmul.
Separating positive and negative zero also has advantages when
signed zero correctness is required.
Foz-DB Navi48:
Totals from 1344 (1.63% of 82636) affected shaders:
Instrs: 5319389 -> 5312280 (-0.13%); split: -0.14%, +0.01%
CodeSize: 29702516 -> 29665684 (-0.12%); split: -0.13%, +0.01%
Latency: 40694344 -> 40694545 (+0.00%); split: -0.01%, +0.02%
InvThroughput: 7481192 -> 7480403 (-0.01%); split: -0.02%, +0.01%
VClause: 121947 -> 121946 (-0.00%); split: -0.00%, +0.00%
SClause: 104972 -> 104923 (-0.05%); split: -0.05%, +0.00%
Copies: 371098 -> 371092 (-0.00%); split: -0.02%, +0.02%
Branches: 122929 -> 122919 (-0.01%); split: -0.01%, +0.00%
PreSGPRs: 82506 -> 82510 (+0.00%); split: -0.00%, +0.01%
PreVGPRs: 79175 -> 79168 (-0.01%)
VALU: 2906718 -> 2904777 (-0.07%); split: -0.07%, +0.00%
SALU: 726256 -> 723454 (-0.39%); split: -0.39%, +0.00%
VMEM: 205021 -> 205016 (-0.00%)
SMEM: 163972 -> 163916 (-0.03%)
VOPD: 303354 -> 303298 (-0.02%); split: +0.02%, -0.04%
Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/39987>
2026-02-08 23:03:16 +01:00
|
|
|
case nir_op_fabs:
|
|
|
|
|
r = src_res[0];
|
2018-01-23 09:48:43 +08:00
|
|
|
|
nir: rewrite fp range analysis as a fp class analysis
Knowing if a value is not larger than one helps proving finite
results of fmul/fadd and will allow skipping/creating more fsat.
Knowing that a value is larger than one helps proving non zero
results of fmul.
Separating positive and negative zero also has advantages when
signed zero correctness is required.
Foz-DB Navi48:
Totals from 1344 (1.63% of 82636) affected shaders:
Instrs: 5319389 -> 5312280 (-0.13%); split: -0.14%, +0.01%
CodeSize: 29702516 -> 29665684 (-0.12%); split: -0.13%, +0.01%
Latency: 40694344 -> 40694545 (+0.00%); split: -0.01%, +0.02%
InvThroughput: 7481192 -> 7480403 (-0.01%); split: -0.02%, +0.01%
VClause: 121947 -> 121946 (-0.00%); split: -0.00%, +0.00%
SClause: 104972 -> 104923 (-0.05%); split: -0.05%, +0.00%
Copies: 371098 -> 371092 (-0.00%); split: -0.02%, +0.02%
Branches: 122929 -> 122919 (-0.01%); split: -0.01%, +0.00%
PreSGPRs: 82506 -> 82510 (+0.00%); split: -0.00%, +0.01%
PreVGPRs: 79175 -> 79168 (-0.01%)
VALU: 2906718 -> 2904777 (-0.07%); split: -0.07%, +0.00%
SALU: 726256 -> 723454 (-0.39%); split: -0.39%, +0.00%
VMEM: 205021 -> 205016 (-0.00%)
SMEM: 163972 -> 163916 (-0.03%)
VOPD: 303354 -> 303298 (-0.02%); split: +0.02%, -0.04%
Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/39987>
2026-02-08 23:03:16 +01:00
|
|
|
r |= fneg_fp_class(r & (FP_CLASS_ANY_NEG | FP_CLASS_NEG_ZERO));
|
|
|
|
|
r &= ~(FP_CLASS_ANY_NEG | FP_CLASS_NEG_ZERO);
|
2018-01-23 09:48:43 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case nir_op_fadd: {
|
nir: rewrite fp range analysis as a fp class analysis
Knowing if a value is not larger than one helps proving finite
results of fmul/fadd and will allow skipping/creating more fsat.
Knowing that a value is larger than one helps proving non zero
results of fmul.
Separating positive and negative zero also has advantages when
signed zero correctness is required.
Foz-DB Navi48:
Totals from 1344 (1.63% of 82636) affected shaders:
Instrs: 5319389 -> 5312280 (-0.13%); split: -0.14%, +0.01%
CodeSize: 29702516 -> 29665684 (-0.12%); split: -0.13%, +0.01%
Latency: 40694344 -> 40694545 (+0.00%); split: -0.01%, +0.02%
InvThroughput: 7481192 -> 7480403 (-0.01%); split: -0.02%, +0.01%
VClause: 121947 -> 121946 (-0.00%); split: -0.00%, +0.00%
SClause: 104972 -> 104923 (-0.05%); split: -0.05%, +0.00%
Copies: 371098 -> 371092 (-0.00%); split: -0.02%, +0.02%
Branches: 122929 -> 122919 (-0.01%); split: -0.01%, +0.00%
PreSGPRs: 82506 -> 82510 (+0.00%); split: -0.00%, +0.01%
PreVGPRs: 79175 -> 79168 (-0.01%)
VALU: 2906718 -> 2904777 (-0.07%); split: -0.07%, +0.00%
SALU: 726256 -> 723454 (-0.39%); split: -0.39%, +0.00%
VMEM: 205021 -> 205016 (-0.00%)
SMEM: 163972 -> 163916 (-0.03%)
VOPD: 303354 -> 303298 (-0.02%); split: +0.02%, -0.04%
Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/39987>
2026-02-08 23:03:16 +01:00
|
|
|
r = fadd_fp_class(src_res[0], src_res[1]);
|
2018-01-23 09:48:43 +08:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-07 08:56:22 -07:00
|
|
|
case nir_op_fexp2: {
|
nir: rewrite fp range analysis as a fp class analysis
Knowing if a value is not larger than one helps proving finite
results of fmul/fadd and will allow skipping/creating more fsat.
Knowing that a value is larger than one helps proving non zero
results of fmul.
Separating positive and negative zero also has advantages when
signed zero correctness is required.
Foz-DB Navi48:
Totals from 1344 (1.63% of 82636) affected shaders:
Instrs: 5319389 -> 5312280 (-0.13%); split: -0.14%, +0.01%
CodeSize: 29702516 -> 29665684 (-0.12%); split: -0.13%, +0.01%
Latency: 40694344 -> 40694545 (+0.00%); split: -0.01%, +0.02%
InvThroughput: 7481192 -> 7480403 (-0.01%); split: -0.02%, +0.01%
VClause: 121947 -> 121946 (-0.00%); split: -0.00%, +0.00%
SClause: 104972 -> 104923 (-0.05%); split: -0.05%, +0.00%
Copies: 371098 -> 371092 (-0.00%); split: -0.02%, +0.02%
Branches: 122929 -> 122919 (-0.01%); split: -0.01%, +0.00%
PreSGPRs: 82506 -> 82510 (+0.00%); split: -0.00%, +0.01%
PreVGPRs: 79175 -> 79168 (-0.01%)
VALU: 2906718 -> 2904777 (-0.07%); split: -0.07%, +0.00%
SALU: 726256 -> 723454 (-0.39%); split: -0.39%, +0.00%
VMEM: 205021 -> 205016 (-0.00%)
SMEM: 163972 -> 163916 (-0.03%)
VOPD: 303354 -> 303298 (-0.02%); split: +0.02%, -0.04%
Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/39987>
2026-02-08 23:03:16 +01:00
|
|
|
fp_class_mask src = src_res[0];
|
|
|
|
|
r = 0;
|
|
|
|
|
|
2019-08-07 08:56:22 -07:00
|
|
|
/* If the parameter might be less than zero, the mathematically result
|
|
|
|
|
* will be on (0, 1). For sufficiently large magnitude negative
|
|
|
|
|
* parameters, the result will flush to zero.
|
|
|
|
|
*/
|
nir: rewrite fp range analysis as a fp class analysis
Knowing if a value is not larger than one helps proving finite
results of fmul/fadd and will allow skipping/creating more fsat.
Knowing that a value is larger than one helps proving non zero
results of fmul.
Separating positive and negative zero also has advantages when
signed zero correctness is required.
Foz-DB Navi48:
Totals from 1344 (1.63% of 82636) affected shaders:
Instrs: 5319389 -> 5312280 (-0.13%); split: -0.14%, +0.01%
CodeSize: 29702516 -> 29665684 (-0.12%); split: -0.13%, +0.01%
Latency: 40694344 -> 40694545 (+0.00%); split: -0.01%, +0.02%
InvThroughput: 7481192 -> 7480403 (-0.01%); split: -0.02%, +0.01%
VClause: 121947 -> 121946 (-0.00%); split: -0.00%, +0.00%
SClause: 104972 -> 104923 (-0.05%); split: -0.05%, +0.00%
Copies: 371098 -> 371092 (-0.00%); split: -0.02%, +0.02%
Branches: 122929 -> 122919 (-0.01%); split: -0.01%, +0.00%
PreSGPRs: 82506 -> 82510 (+0.00%); split: -0.00%, +0.01%
PreVGPRs: 79175 -> 79168 (-0.01%)
VALU: 2906718 -> 2904777 (-0.07%); split: -0.07%, +0.00%
SALU: 726256 -> 723454 (-0.39%); split: -0.39%, +0.00%
VMEM: 205021 -> 205016 (-0.00%)
SMEM: 163972 -> 163916 (-0.03%)
VOPD: 303354 -> 303298 (-0.02%); split: +0.02%, -0.04%
Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/39987>
2026-02-08 23:03:16 +01:00
|
|
|
if (src & FP_CLASS_NEG_INF)
|
|
|
|
|
r |= FP_CLASS_POS_ZERO;
|
2019-08-07 08:56:22 -07:00
|
|
|
|
nir: rewrite fp range analysis as a fp class analysis
Knowing if a value is not larger than one helps proving finite
results of fmul/fadd and will allow skipping/creating more fsat.
Knowing that a value is larger than one helps proving non zero
results of fmul.
Separating positive and negative zero also has advantages when
signed zero correctness is required.
Foz-DB Navi48:
Totals from 1344 (1.63% of 82636) affected shaders:
Instrs: 5319389 -> 5312280 (-0.13%); split: -0.14%, +0.01%
CodeSize: 29702516 -> 29665684 (-0.12%); split: -0.13%, +0.01%
Latency: 40694344 -> 40694545 (+0.00%); split: -0.01%, +0.02%
InvThroughput: 7481192 -> 7480403 (-0.01%); split: -0.02%, +0.01%
VClause: 121947 -> 121946 (-0.00%); split: -0.00%, +0.00%
SClause: 104972 -> 104923 (-0.05%); split: -0.05%, +0.00%
Copies: 371098 -> 371092 (-0.00%); split: -0.02%, +0.02%
Branches: 122929 -> 122919 (-0.01%); split: -0.01%, +0.00%
PreSGPRs: 82506 -> 82510 (+0.00%); split: -0.00%, +0.01%
PreVGPRs: 79175 -> 79168 (-0.01%)
VALU: 2906718 -> 2904777 (-0.07%); split: -0.07%, +0.00%
SALU: 726256 -> 723454 (-0.39%); split: -0.39%, +0.00%
VMEM: 205021 -> 205016 (-0.00%)
SMEM: 163972 -> 163916 (-0.03%)
VOPD: 303354 -> 303298 (-0.02%); split: +0.02%, -0.04%
Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/39987>
2026-02-08 23:03:16 +01:00
|
|
|
if (src & FP_CLASS_LT_NEG_ONE)
|
|
|
|
|
r |= FP_CLASS_POS_ZERO | FP_CLASS_GT_ZERO_LT_POS_ONE | FP_CLASS_NON_INTEGRAL;
|
2019-08-07 08:56:22 -07:00
|
|
|
|
nir: rewrite fp range analysis as a fp class analysis
Knowing if a value is not larger than one helps proving finite
results of fmul/fadd and will allow skipping/creating more fsat.
Knowing that a value is larger than one helps proving non zero
results of fmul.
Separating positive and negative zero also has advantages when
signed zero correctness is required.
Foz-DB Navi48:
Totals from 1344 (1.63% of 82636) affected shaders:
Instrs: 5319389 -> 5312280 (-0.13%); split: -0.14%, +0.01%
CodeSize: 29702516 -> 29665684 (-0.12%); split: -0.13%, +0.01%
Latency: 40694344 -> 40694545 (+0.00%); split: -0.01%, +0.02%
InvThroughput: 7481192 -> 7480403 (-0.01%); split: -0.02%, +0.01%
VClause: 121947 -> 121946 (-0.00%); split: -0.00%, +0.00%
SClause: 104972 -> 104923 (-0.05%); split: -0.05%, +0.00%
Copies: 371098 -> 371092 (-0.00%); split: -0.02%, +0.02%
Branches: 122929 -> 122919 (-0.01%); split: -0.01%, +0.00%
PreSGPRs: 82506 -> 82510 (+0.00%); split: -0.00%, +0.01%
PreVGPRs: 79175 -> 79168 (-0.01%)
VALU: 2906718 -> 2904777 (-0.07%); split: -0.07%, +0.00%
SALU: 726256 -> 723454 (-0.39%); split: -0.39%, +0.00%
VMEM: 205021 -> 205016 (-0.00%)
SMEM: 163972 -> 163916 (-0.03%)
VOPD: 303354 -> 303298 (-0.02%); split: +0.02%, -0.04%
Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/39987>
2026-02-08 23:03:16 +01:00
|
|
|
if (src & (FP_CLASS_NEG_ONE | FP_CLASS_LT_ZERO_GT_NEG_ONE))
|
|
|
|
|
r |= FP_CLASS_GT_ZERO_LT_POS_ONE | FP_CLASS_NON_INTEGRAL;
|
2019-08-12 15:40:20 -07:00
|
|
|
|
nir: rewrite fp range analysis as a fp class analysis
Knowing if a value is not larger than one helps proving finite
results of fmul/fadd and will allow skipping/creating more fsat.
Knowing that a value is larger than one helps proving non zero
results of fmul.
Separating positive and negative zero also has advantages when
signed zero correctness is required.
Foz-DB Navi48:
Totals from 1344 (1.63% of 82636) affected shaders:
Instrs: 5319389 -> 5312280 (-0.13%); split: -0.14%, +0.01%
CodeSize: 29702516 -> 29665684 (-0.12%); split: -0.13%, +0.01%
Latency: 40694344 -> 40694545 (+0.00%); split: -0.01%, +0.02%
InvThroughput: 7481192 -> 7480403 (-0.01%); split: -0.02%, +0.01%
VClause: 121947 -> 121946 (-0.00%); split: -0.00%, +0.00%
SClause: 104972 -> 104923 (-0.05%); split: -0.05%, +0.00%
Copies: 371098 -> 371092 (-0.00%); split: -0.02%, +0.02%
Branches: 122929 -> 122919 (-0.01%); split: -0.01%, +0.00%
PreSGPRs: 82506 -> 82510 (+0.00%); split: -0.00%, +0.01%
PreVGPRs: 79175 -> 79168 (-0.01%)
VALU: 2906718 -> 2904777 (-0.07%); split: -0.07%, +0.00%
SALU: 726256 -> 723454 (-0.39%); split: -0.39%, +0.00%
VMEM: 205021 -> 205016 (-0.00%)
SMEM: 163972 -> 163916 (-0.03%)
VOPD: 303354 -> 303298 (-0.02%); split: +0.02%, -0.04%
Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/39987>
2026-02-08 23:03:16 +01:00
|
|
|
if (src & (FP_CLASS_LT_ZERO_GT_NEG_ONE | FP_CLASS_ANY_ZERO | FP_CLASS_GT_ZERO_LT_POS_ONE))
|
|
|
|
|
r |= FP_CLASS_POS_ONE;
|
2020-08-17 15:56:24 -07:00
|
|
|
|
nir: rewrite fp range analysis as a fp class analysis
Knowing if a value is not larger than one helps proving finite
results of fmul/fadd and will allow skipping/creating more fsat.
Knowing that a value is larger than one helps proving non zero
results of fmul.
Separating positive and negative zero also has advantages when
signed zero correctness is required.
Foz-DB Navi48:
Totals from 1344 (1.63% of 82636) affected shaders:
Instrs: 5319389 -> 5312280 (-0.13%); split: -0.14%, +0.01%
CodeSize: 29702516 -> 29665684 (-0.12%); split: -0.13%, +0.01%
Latency: 40694344 -> 40694545 (+0.00%); split: -0.01%, +0.02%
InvThroughput: 7481192 -> 7480403 (-0.01%); split: -0.02%, +0.01%
VClause: 121947 -> 121946 (-0.00%); split: -0.00%, +0.00%
SClause: 104972 -> 104923 (-0.05%); split: -0.05%, +0.00%
Copies: 371098 -> 371092 (-0.00%); split: -0.02%, +0.02%
Branches: 122929 -> 122919 (-0.01%); split: -0.01%, +0.00%
PreSGPRs: 82506 -> 82510 (+0.00%); split: -0.00%, +0.01%
PreVGPRs: 79175 -> 79168 (-0.01%)
VALU: 2906718 -> 2904777 (-0.07%); split: -0.07%, +0.00%
SALU: 726256 -> 723454 (-0.39%); split: -0.39%, +0.00%
VMEM: 205021 -> 205016 (-0.00%)
SMEM: 163972 -> 163916 (-0.03%)
VOPD: 303354 -> 303298 (-0.02%); split: +0.02%, -0.04%
Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/39987>
2026-02-08 23:03:16 +01:00
|
|
|
if (src & (FP_CLASS_GT_ZERO_LT_POS_ONE | FP_CLASS_POS_ONE))
|
|
|
|
|
r |= FP_CLASS_GT_POS_ONE;
|
2018-01-23 09:48:43 +08:00
|
|
|
|
nir: rewrite fp range analysis as a fp class analysis
Knowing if a value is not larger than one helps proving finite
results of fmul/fadd and will allow skipping/creating more fsat.
Knowing that a value is larger than one helps proving non zero
results of fmul.
Separating positive and negative zero also has advantages when
signed zero correctness is required.
Foz-DB Navi48:
Totals from 1344 (1.63% of 82636) affected shaders:
Instrs: 5319389 -> 5312280 (-0.13%); split: -0.14%, +0.01%
CodeSize: 29702516 -> 29665684 (-0.12%); split: -0.13%, +0.01%
Latency: 40694344 -> 40694545 (+0.00%); split: -0.01%, +0.02%
InvThroughput: 7481192 -> 7480403 (-0.01%); split: -0.02%, +0.01%
VClause: 121947 -> 121946 (-0.00%); split: -0.00%, +0.00%
SClause: 104972 -> 104923 (-0.05%); split: -0.05%, +0.00%
Copies: 371098 -> 371092 (-0.00%); split: -0.02%, +0.02%
Branches: 122929 -> 122919 (-0.01%); split: -0.01%, +0.00%
PreSGPRs: 82506 -> 82510 (+0.00%); split: -0.00%, +0.01%
PreVGPRs: 79175 -> 79168 (-0.01%)
VALU: 2906718 -> 2904777 (-0.07%); split: -0.07%, +0.00%
SALU: 726256 -> 723454 (-0.39%); split: -0.39%, +0.00%
VMEM: 205021 -> 205016 (-0.00%)
SMEM: 163972 -> 163916 (-0.03%)
VOPD: 303354 -> 303298 (-0.02%); split: +0.02%, -0.04%
Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/39987>
2026-02-08 23:03:16 +01:00
|
|
|
if (src & (FP_CLASS_GT_POS_ONE))
|
|
|
|
|
r |= FP_CLASS_GT_POS_ONE | FP_CLASS_POS_INF;
|
2018-01-23 09:48:43 +08:00
|
|
|
|
nir: rewrite fp range analysis as a fp class analysis
Knowing if a value is not larger than one helps proving finite
results of fmul/fadd and will allow skipping/creating more fsat.
Knowing that a value is larger than one helps proving non zero
results of fmul.
Separating positive and negative zero also has advantages when
signed zero correctness is required.
Foz-DB Navi48:
Totals from 1344 (1.63% of 82636) affected shaders:
Instrs: 5319389 -> 5312280 (-0.13%); split: -0.14%, +0.01%
CodeSize: 29702516 -> 29665684 (-0.12%); split: -0.13%, +0.01%
Latency: 40694344 -> 40694545 (+0.00%); split: -0.01%, +0.02%
InvThroughput: 7481192 -> 7480403 (-0.01%); split: -0.02%, +0.01%
VClause: 121947 -> 121946 (-0.00%); split: -0.00%, +0.00%
SClause: 104972 -> 104923 (-0.05%); split: -0.05%, +0.00%
Copies: 371098 -> 371092 (-0.00%); split: -0.02%, +0.02%
Branches: 122929 -> 122919 (-0.01%); split: -0.01%, +0.00%
PreSGPRs: 82506 -> 82510 (+0.00%); split: -0.00%, +0.01%
PreVGPRs: 79175 -> 79168 (-0.01%)
VALU: 2906718 -> 2904777 (-0.07%); split: -0.07%, +0.00%
SALU: 726256 -> 723454 (-0.39%); split: -0.39%, +0.00%
VMEM: 205021 -> 205016 (-0.00%)
SMEM: 163972 -> 163916 (-0.03%)
VOPD: 303354 -> 303298 (-0.02%); split: +0.02%, -0.04%
Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/39987>
2026-02-08 23:03:16 +01:00
|
|
|
if (src & FP_CLASS_POS_INF)
|
|
|
|
|
r |= FP_CLASS_POS_INF;
|
2020-08-17 15:56:24 -07:00
|
|
|
|
nir: rewrite fp range analysis as a fp class analysis
Knowing if a value is not larger than one helps proving finite
results of fmul/fadd and will allow skipping/creating more fsat.
Knowing that a value is larger than one helps proving non zero
results of fmul.
Separating positive and negative zero also has advantages when
signed zero correctness is required.
Foz-DB Navi48:
Totals from 1344 (1.63% of 82636) affected shaders:
Instrs: 5319389 -> 5312280 (-0.13%); split: -0.14%, +0.01%
CodeSize: 29702516 -> 29665684 (-0.12%); split: -0.13%, +0.01%
Latency: 40694344 -> 40694545 (+0.00%); split: -0.01%, +0.02%
InvThroughput: 7481192 -> 7480403 (-0.01%); split: -0.02%, +0.01%
VClause: 121947 -> 121946 (-0.00%); split: -0.00%, +0.00%
SClause: 104972 -> 104923 (-0.05%); split: -0.05%, +0.00%
Copies: 371098 -> 371092 (-0.00%); split: -0.02%, +0.02%
Branches: 122929 -> 122919 (-0.01%); split: -0.01%, +0.00%
PreSGPRs: 82506 -> 82510 (+0.00%); split: -0.00%, +0.01%
PreVGPRs: 79175 -> 79168 (-0.01%)
VALU: 2906718 -> 2904777 (-0.07%); split: -0.07%, +0.00%
SALU: 726256 -> 723454 (-0.39%); split: -0.39%, +0.00%
VMEM: 205021 -> 205016 (-0.00%)
SMEM: 163972 -> 163916 (-0.03%)
VOPD: 303354 -> 303298 (-0.02%); split: +0.02%, -0.04%
Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/39987>
2026-02-08 23:03:16 +01:00
|
|
|
if (src & FP_CLASS_NON_INTEGRAL)
|
|
|
|
|
r |= FP_CLASS_NON_INTEGRAL;
|
nir/range_analysis: Fix analysis of fmin, fmax, or fsat with NaN source
Recall that when either value is NaN, fmax will pick the other value.
This means the result range of the fmax will either be the "ideal"
result range (calculated above) or the range of the non-NaN value.
Previously, something like fmax({gt_zero}, {lt_zero, is_a_number}) would
return a range of gt_zero. However, if the "gt_zero" parameter is NaN,
the actual result will be the "lt_zero" parameter.
This analysis depends on the is_a_number analysis also added in this MR.
Assuming this doesn't cause any unforeseen problems, I believe we should
wait a bit, then nominate a subset of the series for the stable
branches.
This fixes the piglit tests
tests/spec/glsl-1.30/execution/range_analysis_fmax_of_nan.shader_test
tests/spec/glsl-1.30/execution/range_analysis_fmin_of_nan.shader_test
from https://gitlab.freedesktop.org/mesa/piglit/-/merge_requests/463.
Even with the added fsat fixes, range_analysis_fsat_of_nan.shader_test
still fails. There are some other issues there that will be addressed
in later commits (in another MR).
v2: Add fsat fixes. Suggested by Rhys.
Fixes: 405de7ccb6c ("nir/range-analysis: Rudimentary value range analysis pass")
Reviewed-by: Rhys Perry <pendingchaos02@gmail.com>
Shader-db results:
All Intel platforms had similar results. (Tiger Lake shown)
total instructions in shared programs: 21049290 -> 21049314 (<.01%)
instructions in affected programs: 3175 -> 3199 (0.76%)
helped: 0
HURT: 17
HURT stats (abs) min: 1 max: 3 x̄: 1.41 x̃: 1
HURT stats (rel) min: 0.20% max: 1.89% x̄: 0.97% x̃: 0.92%
95% mean confidence interval for instructions value: 1.09 1.73
95% mean confidence interval for instructions %-change: 0.75% 1.19%
Instructions are HURT.
total cycles in shared programs: 855136176 -> 855136406 (<.01%)
cycles in affected programs: 37579 -> 37809 (0.61%)
helped: 0
HURT: 17
HURT stats (abs) min: 12 max: 20 x̄: 13.53 x̃: 14
HURT stats (rel) min: 0.17% max: 1.13% x̄: 0.79% x̃: 0.91%
95% mean confidence interval for cycles value: 12.53 14.53
95% mean confidence interval for cycles %-change: 0.63% 0.94%
Cycles are HURT.
Fossil-db results:
Tiger Lake
Instructions in all programs: 160901033 -> 160902591 (+0.0%)
SENDs in all programs: 6812270 -> 6812270 (+0.0%)
Loops in all programs: 38225 -> 38225 (+0.0%)
Cycles in all programs: 7430016795 -> 7429003266 (-0.0%)
Spills in all programs: 192582 -> 192582 (+0.0%)
Fills in all programs: 304539 -> 304539 (+0.0%)
Ice Lake
Instructions in all programs: 145299102 -> 145301634 (+0.0%)
SENDs in all programs: 6863890 -> 6863890 (+0.0%)
Loops in all programs: 38219 -> 38219 (+0.0%)
Cycles in all programs: 8798390846 -> 8798589772 (+0.0%)
Spills in all programs: 216880 -> 216880 (+0.0%)
Fills in all programs: 334250 -> 334250 (+0.0%)
Skylake
Instructions in all programs: 135889478 -> 135892010 (+0.0%)
SENDs in all programs: 6802916 -> 6802916 (+0.0%)
Loops in all programs: 38216 -> 38216 (+0.0%)
Cycles in all programs: 8442624166 -> 8442597324 (-0.0%)
Spills in all programs: 194839 -> 194839 (+0.0%)
Fills in all programs: 301116 -> 301116 (+0.0%)
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9108>
2021-01-27 19:42:44 -08:00
|
|
|
|
nir: rewrite fp range analysis as a fp class analysis
Knowing if a value is not larger than one helps proving finite
results of fmul/fadd and will allow skipping/creating more fsat.
Knowing that a value is larger than one helps proving non zero
results of fmul.
Separating positive and negative zero also has advantages when
signed zero correctness is required.
Foz-DB Navi48:
Totals from 1344 (1.63% of 82636) affected shaders:
Instrs: 5319389 -> 5312280 (-0.13%); split: -0.14%, +0.01%
CodeSize: 29702516 -> 29665684 (-0.12%); split: -0.13%, +0.01%
Latency: 40694344 -> 40694545 (+0.00%); split: -0.01%, +0.02%
InvThroughput: 7481192 -> 7480403 (-0.01%); split: -0.02%, +0.01%
VClause: 121947 -> 121946 (-0.00%); split: -0.00%, +0.00%
SClause: 104972 -> 104923 (-0.05%); split: -0.05%, +0.00%
Copies: 371098 -> 371092 (-0.00%); split: -0.02%, +0.02%
Branches: 122929 -> 122919 (-0.01%); split: -0.01%, +0.00%
PreSGPRs: 82506 -> 82510 (+0.00%); split: -0.00%, +0.01%
PreVGPRs: 79175 -> 79168 (-0.01%)
VALU: 2906718 -> 2904777 (-0.07%); split: -0.07%, +0.00%
SALU: 726256 -> 723454 (-0.39%); split: -0.39%, +0.00%
VMEM: 205021 -> 205016 (-0.00%)
SMEM: 163972 -> 163916 (-0.03%)
VOPD: 303354 -> 303298 (-0.02%); split: +0.02%, -0.04%
Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/39987>
2026-02-08 23:03:16 +01:00
|
|
|
if (src & FP_CLASS_NAN)
|
|
|
|
|
r |= FP_CLASS_NAN;
|
2018-01-23 09:48:43 +08:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-11 19:58:41 +01:00
|
|
|
case nir_op_flog2: {
|
|
|
|
|
r = 0;
|
|
|
|
|
|
|
|
|
|
if (src_res[0] & (FP_CLASS_ANY_NEG | FP_CLASS_NAN))
|
|
|
|
|
r |= FP_CLASS_NAN;
|
|
|
|
|
|
|
|
|
|
if (src_res[0] & FP_CLASS_ANY_ZERO)
|
|
|
|
|
r |= FP_CLASS_NEG_INF;
|
|
|
|
|
|
|
|
|
|
if (src_res[0] & FP_CLASS_GT_ZERO_LT_POS_ONE)
|
|
|
|
|
r |= FP_CLASS_ANY_NEG | FP_CLASS_NON_INTEGRAL;
|
|
|
|
|
|
|
|
|
|
if (src_res[0] & FP_CLASS_POS_ONE)
|
|
|
|
|
r |= FP_CLASS_POS_ZERO;
|
|
|
|
|
|
|
|
|
|
if (src_res[0] & FP_CLASS_GT_POS_ONE)
|
|
|
|
|
r |= FP_CLASS_GT_ZERO_LT_POS_ONE | FP_CLASS_POS_ONE | FP_CLASS_GT_POS_ONE | FP_CLASS_NON_INTEGRAL;
|
|
|
|
|
|
|
|
|
|
if (src_res[0] & FP_CLASS_POS_INF)
|
|
|
|
|
r |= FP_CLASS_POS_INF;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
nir: rewrite fp range analysis as a fp class analysis
Knowing if a value is not larger than one helps proving finite
results of fmul/fadd and will allow skipping/creating more fsat.
Knowing that a value is larger than one helps proving non zero
results of fmul.
Separating positive and negative zero also has advantages when
signed zero correctness is required.
Foz-DB Navi48:
Totals from 1344 (1.63% of 82636) affected shaders:
Instrs: 5319389 -> 5312280 (-0.13%); split: -0.14%, +0.01%
CodeSize: 29702516 -> 29665684 (-0.12%); split: -0.13%, +0.01%
Latency: 40694344 -> 40694545 (+0.00%); split: -0.01%, +0.02%
InvThroughput: 7481192 -> 7480403 (-0.01%); split: -0.02%, +0.01%
VClause: 121947 -> 121946 (-0.00%); split: -0.00%, +0.00%
SClause: 104972 -> 104923 (-0.05%); split: -0.05%, +0.00%
Copies: 371098 -> 371092 (-0.00%); split: -0.02%, +0.02%
Branches: 122929 -> 122919 (-0.01%); split: -0.01%, +0.00%
PreSGPRs: 82506 -> 82510 (+0.00%); split: -0.00%, +0.01%
PreVGPRs: 79175 -> 79168 (-0.01%)
VALU: 2906718 -> 2904777 (-0.07%); split: -0.07%, +0.00%
SALU: 726256 -> 723454 (-0.39%); split: -0.39%, +0.00%
VMEM: 205021 -> 205016 (-0.00%)
SMEM: 163972 -> 163916 (-0.03%)
VOPD: 303354 -> 303298 (-0.02%); split: +0.02%, -0.04%
Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/39987>
2026-02-08 23:03:16 +01:00
|
|
|
case nir_op_fmax: {
|
|
|
|
|
fp_class_mask left = fneg_fp_class(src_res[0]);
|
|
|
|
|
fp_class_mask right = fneg_fp_class(src_res[1]);
|
|
|
|
|
r = fneg_fp_class(fmin_fp_class(left, right));
|
2018-01-23 09:48:43 +08:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
nir: rewrite fp range analysis as a fp class analysis
Knowing if a value is not larger than one helps proving finite
results of fmul/fadd and will allow skipping/creating more fsat.
Knowing that a value is larger than one helps proving non zero
results of fmul.
Separating positive and negative zero also has advantages when
signed zero correctness is required.
Foz-DB Navi48:
Totals from 1344 (1.63% of 82636) affected shaders:
Instrs: 5319389 -> 5312280 (-0.13%); split: -0.14%, +0.01%
CodeSize: 29702516 -> 29665684 (-0.12%); split: -0.13%, +0.01%
Latency: 40694344 -> 40694545 (+0.00%); split: -0.01%, +0.02%
InvThroughput: 7481192 -> 7480403 (-0.01%); split: -0.02%, +0.01%
VClause: 121947 -> 121946 (-0.00%); split: -0.00%, +0.00%
SClause: 104972 -> 104923 (-0.05%); split: -0.05%, +0.00%
Copies: 371098 -> 371092 (-0.00%); split: -0.02%, +0.02%
Branches: 122929 -> 122919 (-0.01%); split: -0.01%, +0.00%
PreSGPRs: 82506 -> 82510 (+0.00%); split: -0.00%, +0.01%
PreVGPRs: 79175 -> 79168 (-0.01%)
VALU: 2906718 -> 2904777 (-0.07%); split: -0.07%, +0.00%
SALU: 726256 -> 723454 (-0.39%); split: -0.39%, +0.00%
VMEM: 205021 -> 205016 (-0.00%)
SMEM: 163972 -> 163916 (-0.03%)
VOPD: 303354 -> 303298 (-0.02%); split: +0.02%, -0.04%
Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/39987>
2026-02-08 23:03:16 +01:00
|
|
|
case nir_op_fmin:
|
|
|
|
|
r = fmin_fp_class(src_res[0], src_res[1]);
|
|
|
|
|
break;
|
|
|
|
|
|
2021-09-14 18:02:01 +01:00
|
|
|
case nir_op_fmul:
|
|
|
|
|
case nir_op_fmulz: {
|
nir: rewrite fp range analysis as a fp class analysis
Knowing if a value is not larger than one helps proving finite
results of fmul/fadd and will allow skipping/creating more fsat.
Knowing that a value is larger than one helps proving non zero
results of fmul.
Separating positive and negative zero also has advantages when
signed zero correctness is required.
Foz-DB Navi48:
Totals from 1344 (1.63% of 82636) affected shaders:
Instrs: 5319389 -> 5312280 (-0.13%); split: -0.14%, +0.01%
CodeSize: 29702516 -> 29665684 (-0.12%); split: -0.13%, +0.01%
Latency: 40694344 -> 40694545 (+0.00%); split: -0.01%, +0.02%
InvThroughput: 7481192 -> 7480403 (-0.01%); split: -0.02%, +0.01%
VClause: 121947 -> 121946 (-0.00%); split: -0.00%, +0.00%
SClause: 104972 -> 104923 (-0.05%); split: -0.05%, +0.00%
Copies: 371098 -> 371092 (-0.00%); split: -0.02%, +0.02%
Branches: 122929 -> 122919 (-0.01%); split: -0.01%, +0.00%
PreSGPRs: 82506 -> 82510 (+0.00%); split: -0.00%, +0.01%
PreVGPRs: 79175 -> 79168 (-0.01%)
VALU: 2906718 -> 2904777 (-0.07%); split: -0.07%, +0.00%
SALU: 726256 -> 723454 (-0.39%); split: -0.39%, +0.00%
VMEM: 205021 -> 205016 (-0.00%)
SMEM: 163972 -> 163916 (-0.03%)
VOPD: 303354 -> 303298 (-0.02%); split: +0.02%, -0.04%
Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/39987>
2026-02-08 23:03:16 +01:00
|
|
|
bool mulz = alu->op == nir_op_fmulz;
|
|
|
|
|
bool src_eq = nir_alu_srcs_equal(alu, alu, 0, 1);
|
|
|
|
|
bool src_neg_eq = !nir_src_is_const(alu->src[0].src) && nir_alu_srcs_negative_equal(alu, alu, 0, 1);
|
|
|
|
|
r = fmul_fp_class(src_res[0], src_res[1], mulz, src_eq, src_neg_eq);
|
2018-01-23 09:48:43 +08:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
nir: rewrite fp range analysis as a fp class analysis
Knowing if a value is not larger than one helps proving finite
results of fmul/fadd and will allow skipping/creating more fsat.
Knowing that a value is larger than one helps proving non zero
results of fmul.
Separating positive and negative zero also has advantages when
signed zero correctness is required.
Foz-DB Navi48:
Totals from 1344 (1.63% of 82636) affected shaders:
Instrs: 5319389 -> 5312280 (-0.13%); split: -0.14%, +0.01%
CodeSize: 29702516 -> 29665684 (-0.12%); split: -0.13%, +0.01%
Latency: 40694344 -> 40694545 (+0.00%); split: -0.01%, +0.02%
InvThroughput: 7481192 -> 7480403 (-0.01%); split: -0.02%, +0.01%
VClause: 121947 -> 121946 (-0.00%); split: -0.00%, +0.00%
SClause: 104972 -> 104923 (-0.05%); split: -0.05%, +0.00%
Copies: 371098 -> 371092 (-0.00%); split: -0.02%, +0.02%
Branches: 122929 -> 122919 (-0.01%); split: -0.01%, +0.00%
PreSGPRs: 82506 -> 82510 (+0.00%); split: -0.00%, +0.01%
PreVGPRs: 79175 -> 79168 (-0.01%)
VALU: 2906718 -> 2904777 (-0.07%); split: -0.07%, +0.00%
SALU: 726256 -> 723454 (-0.39%); split: -0.39%, +0.00%
VMEM: 205021 -> 205016 (-0.00%)
SMEM: 163972 -> 163916 (-0.03%)
VOPD: 303354 -> 303298 (-0.02%); split: +0.02%, -0.04%
Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/39987>
2026-02-08 23:03:16 +01:00
|
|
|
case nir_op_frcp:
|
|
|
|
|
r = frcp_fp_class(handle_sz(alu, src_res[0]));
|
2018-01-23 09:48:43 +08:00
|
|
|
break;
|
|
|
|
|
|
2019-08-12 17:28:35 -07:00
|
|
|
case nir_op_mov:
|
nir: rewrite fp range analysis as a fp class analysis
Knowing if a value is not larger than one helps proving finite
results of fmul/fadd and will allow skipping/creating more fsat.
Knowing that a value is larger than one helps proving non zero
results of fmul.
Separating positive and negative zero also has advantages when
signed zero correctness is required.
Foz-DB Navi48:
Totals from 1344 (1.63% of 82636) affected shaders:
Instrs: 5319389 -> 5312280 (-0.13%); split: -0.14%, +0.01%
CodeSize: 29702516 -> 29665684 (-0.12%); split: -0.13%, +0.01%
Latency: 40694344 -> 40694545 (+0.00%); split: -0.01%, +0.02%
InvThroughput: 7481192 -> 7480403 (-0.01%); split: -0.02%, +0.01%
VClause: 121947 -> 121946 (-0.00%); split: -0.00%, +0.00%
SClause: 104972 -> 104923 (-0.05%); split: -0.05%, +0.00%
Copies: 371098 -> 371092 (-0.00%); split: -0.02%, +0.02%
Branches: 122929 -> 122919 (-0.01%); split: -0.01%, +0.00%
PreSGPRs: 82506 -> 82510 (+0.00%); split: -0.00%, +0.01%
PreVGPRs: 79175 -> 79168 (-0.01%)
VALU: 2906718 -> 2904777 (-0.07%); split: -0.07%, +0.00%
SALU: 726256 -> 723454 (-0.39%); split: -0.39%, +0.00%
VMEM: 205021 -> 205016 (-0.00%)
SMEM: 163972 -> 163916 (-0.03%)
VOPD: 303354 -> 303298 (-0.02%); split: +0.02%, -0.04%
Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/39987>
2026-02-08 23:03:16 +01:00
|
|
|
r = src_res[0];
|
2018-01-23 09:48:43 +08:00
|
|
|
break;
|
|
|
|
|
|
2021-03-08 14:30:00 -08:00
|
|
|
case nir_op_fsat: {
|
nir: rewrite fp range analysis as a fp class analysis
Knowing if a value is not larger than one helps proving finite
results of fmul/fadd and will allow skipping/creating more fsat.
Knowing that a value is larger than one helps proving non zero
results of fmul.
Separating positive and negative zero also has advantages when
signed zero correctness is required.
Foz-DB Navi48:
Totals from 1344 (1.63% of 82636) affected shaders:
Instrs: 5319389 -> 5312280 (-0.13%); split: -0.14%, +0.01%
CodeSize: 29702516 -> 29665684 (-0.12%); split: -0.13%, +0.01%
Latency: 40694344 -> 40694545 (+0.00%); split: -0.01%, +0.02%
InvThroughput: 7481192 -> 7480403 (-0.01%); split: -0.02%, +0.01%
VClause: 121947 -> 121946 (-0.00%); split: -0.00%, +0.00%
SClause: 104972 -> 104923 (-0.05%); split: -0.05%, +0.00%
Copies: 371098 -> 371092 (-0.00%); split: -0.02%, +0.02%
Branches: 122929 -> 122919 (-0.01%); split: -0.01%, +0.00%
PreSGPRs: 82506 -> 82510 (+0.00%); split: -0.00%, +0.01%
PreVGPRs: 79175 -> 79168 (-0.01%)
VALU: 2906718 -> 2904777 (-0.07%); split: -0.07%, +0.00%
SALU: 726256 -> 723454 (-0.39%); split: -0.39%, +0.00%
VMEM: 205021 -> 205016 (-0.00%)
SMEM: 163972 -> 163916 (-0.03%)
VOPD: 303354 -> 303298 (-0.02%); split: +0.02%, -0.04%
Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/39987>
2026-02-08 23:03:16 +01:00
|
|
|
r = src_res[0];
|
2018-06-01 18:54:49 -07:00
|
|
|
|
nir: rewrite fp range analysis as a fp class analysis
Knowing if a value is not larger than one helps proving finite
results of fmul/fadd and will allow skipping/creating more fsat.
Knowing that a value is larger than one helps proving non zero
results of fmul.
Separating positive and negative zero also has advantages when
signed zero correctness is required.
Foz-DB Navi48:
Totals from 1344 (1.63% of 82636) affected shaders:
Instrs: 5319389 -> 5312280 (-0.13%); split: -0.14%, +0.01%
CodeSize: 29702516 -> 29665684 (-0.12%); split: -0.13%, +0.01%
Latency: 40694344 -> 40694545 (+0.00%); split: -0.01%, +0.02%
InvThroughput: 7481192 -> 7480403 (-0.01%); split: -0.02%, +0.01%
VClause: 121947 -> 121946 (-0.00%); split: -0.00%, +0.00%
SClause: 104972 -> 104923 (-0.05%); split: -0.05%, +0.00%
Copies: 371098 -> 371092 (-0.00%); split: -0.02%, +0.02%
Branches: 122929 -> 122919 (-0.01%); split: -0.01%, +0.00%
PreSGPRs: 82506 -> 82510 (+0.00%); split: -0.00%, +0.01%
PreVGPRs: 79175 -> 79168 (-0.01%)
VALU: 2906718 -> 2904777 (-0.07%); split: -0.07%, +0.00%
SALU: 726256 -> 723454 (-0.39%); split: -0.39%, +0.00%
VMEM: 205021 -> 205016 (-0.00%)
SMEM: 163972 -> 163916 (-0.03%)
VOPD: 303354 -> 303298 (-0.02%); split: +0.02%, -0.04%
Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/39987>
2026-02-08 23:03:16 +01:00
|
|
|
/* max(+0.0, x) */
|
|
|
|
|
if (r & (FP_CLASS_ANY_NEG | FP_CLASS_NEG_ZERO | FP_CLASS_NAN)) {
|
|
|
|
|
r &= ~(FP_CLASS_ANY_NEG | FP_CLASS_NEG_ZERO | FP_CLASS_NAN);
|
|
|
|
|
r |= FP_CLASS_POS_ZERO;
|
|
|
|
|
}
|
2018-06-01 18:54:49 -07:00
|
|
|
|
nir: rewrite fp range analysis as a fp class analysis
Knowing if a value is not larger than one helps proving finite
results of fmul/fadd and will allow skipping/creating more fsat.
Knowing that a value is larger than one helps proving non zero
results of fmul.
Separating positive and negative zero also has advantages when
signed zero correctness is required.
Foz-DB Navi48:
Totals from 1344 (1.63% of 82636) affected shaders:
Instrs: 5319389 -> 5312280 (-0.13%); split: -0.14%, +0.01%
CodeSize: 29702516 -> 29665684 (-0.12%); split: -0.13%, +0.01%
Latency: 40694344 -> 40694545 (+0.00%); split: -0.01%, +0.02%
InvThroughput: 7481192 -> 7480403 (-0.01%); split: -0.02%, +0.01%
VClause: 121947 -> 121946 (-0.00%); split: -0.00%, +0.00%
SClause: 104972 -> 104923 (-0.05%); split: -0.05%, +0.00%
Copies: 371098 -> 371092 (-0.00%); split: -0.02%, +0.02%
Branches: 122929 -> 122919 (-0.01%); split: -0.01%, +0.00%
PreSGPRs: 82506 -> 82510 (+0.00%); split: -0.00%, +0.01%
PreVGPRs: 79175 -> 79168 (-0.01%)
VALU: 2906718 -> 2904777 (-0.07%); split: -0.07%, +0.00%
SALU: 726256 -> 723454 (-0.39%); split: -0.39%, +0.00%
VMEM: 205021 -> 205016 (-0.00%)
SMEM: 163972 -> 163916 (-0.03%)
VOPD: 303354 -> 303298 (-0.02%); split: +0.02%, -0.04%
Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/39987>
2026-02-08 23:03:16 +01:00
|
|
|
/* min(+1.0, x) */
|
|
|
|
|
if (r & (FP_CLASS_GT_POS_ONE | FP_CLASS_POS_INF)) {
|
|
|
|
|
r &= ~(FP_CLASS_GT_POS_ONE | FP_CLASS_POS_INF);
|
|
|
|
|
r |= FP_CLASS_POS_ONE;
|
2018-06-01 18:54:49 -07:00
|
|
|
}
|
nir: rewrite fp range analysis as a fp class analysis
Knowing if a value is not larger than one helps proving finite
results of fmul/fadd and will allow skipping/creating more fsat.
Knowing that a value is larger than one helps proving non zero
results of fmul.
Separating positive and negative zero also has advantages when
signed zero correctness is required.
Foz-DB Navi48:
Totals from 1344 (1.63% of 82636) affected shaders:
Instrs: 5319389 -> 5312280 (-0.13%); split: -0.14%, +0.01%
CodeSize: 29702516 -> 29665684 (-0.12%); split: -0.13%, +0.01%
Latency: 40694344 -> 40694545 (+0.00%); split: -0.01%, +0.02%
InvThroughput: 7481192 -> 7480403 (-0.01%); split: -0.02%, +0.01%
VClause: 121947 -> 121946 (-0.00%); split: -0.00%, +0.00%
SClause: 104972 -> 104923 (-0.05%); split: -0.05%, +0.00%
Copies: 371098 -> 371092 (-0.00%); split: -0.02%, +0.02%
Branches: 122929 -> 122919 (-0.01%); split: -0.01%, +0.00%
PreSGPRs: 82506 -> 82510 (+0.00%); split: -0.00%, +0.01%
PreVGPRs: 79175 -> 79168 (-0.01%)
VALU: 2906718 -> 2904777 (-0.07%); split: -0.07%, +0.00%
SALU: 726256 -> 723454 (-0.39%); split: -0.39%, +0.00%
VMEM: 205021 -> 205016 (-0.00%)
SMEM: 163972 -> 163916 (-0.03%)
VOPD: 303354 -> 303298 (-0.02%); split: +0.02%, -0.04%
Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/39987>
2026-02-08 23:03:16 +01:00
|
|
|
|
|
|
|
|
if (!(r & FP_CLASS_GT_ZERO_LT_POS_ONE))
|
|
|
|
|
r &= ~FP_CLASS_NON_INTEGRAL;
|
|
|
|
|
|
2018-01-23 09:48:43 +08:00
|
|
|
break;
|
2021-03-08 14:30:00 -08:00
|
|
|
}
|
2018-01-23 09:48:43 +08:00
|
|
|
|
|
|
|
|
case nir_op_fsign:
|
nir: rewrite fp range analysis as a fp class analysis
Knowing if a value is not larger than one helps proving finite
results of fmul/fadd and will allow skipping/creating more fsat.
Knowing that a value is larger than one helps proving non zero
results of fmul.
Separating positive and negative zero also has advantages when
signed zero correctness is required.
Foz-DB Navi48:
Totals from 1344 (1.63% of 82636) affected shaders:
Instrs: 5319389 -> 5312280 (-0.13%); split: -0.14%, +0.01%
CodeSize: 29702516 -> 29665684 (-0.12%); split: -0.13%, +0.01%
Latency: 40694344 -> 40694545 (+0.00%); split: -0.01%, +0.02%
InvThroughput: 7481192 -> 7480403 (-0.01%); split: -0.02%, +0.01%
VClause: 121947 -> 121946 (-0.00%); split: -0.00%, +0.00%
SClause: 104972 -> 104923 (-0.05%); split: -0.05%, +0.00%
Copies: 371098 -> 371092 (-0.00%); split: -0.02%, +0.02%
Branches: 122929 -> 122919 (-0.01%); split: -0.01%, +0.00%
PreSGPRs: 82506 -> 82510 (+0.00%); split: -0.00%, +0.01%
PreVGPRs: 79175 -> 79168 (-0.01%)
VALU: 2906718 -> 2904777 (-0.07%); split: -0.07%, +0.00%
SALU: 726256 -> 723454 (-0.39%); split: -0.39%, +0.00%
VMEM: 205021 -> 205016 (-0.00%)
SMEM: 163972 -> 163916 (-0.03%)
VOPD: 303354 -> 303298 (-0.02%); split: +0.02%, -0.04%
Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/39987>
2026-02-08 23:03:16 +01:00
|
|
|
r = 0;
|
2018-01-23 09:48:43 +08:00
|
|
|
|
nir: rewrite fp range analysis as a fp class analysis
Knowing if a value is not larger than one helps proving finite
results of fmul/fadd and will allow skipping/creating more fsat.
Knowing that a value is larger than one helps proving non zero
results of fmul.
Separating positive and negative zero also has advantages when
signed zero correctness is required.
Foz-DB Navi48:
Totals from 1344 (1.63% of 82636) affected shaders:
Instrs: 5319389 -> 5312280 (-0.13%); split: -0.14%, +0.01%
CodeSize: 29702516 -> 29665684 (-0.12%); split: -0.13%, +0.01%
Latency: 40694344 -> 40694545 (+0.00%); split: -0.01%, +0.02%
InvThroughput: 7481192 -> 7480403 (-0.01%); split: -0.02%, +0.01%
VClause: 121947 -> 121946 (-0.00%); split: -0.00%, +0.00%
SClause: 104972 -> 104923 (-0.05%); split: -0.05%, +0.00%
Copies: 371098 -> 371092 (-0.00%); split: -0.02%, +0.02%
Branches: 122929 -> 122919 (-0.01%); split: -0.01%, +0.00%
PreSGPRs: 82506 -> 82510 (+0.00%); split: -0.00%, +0.01%
PreVGPRs: 79175 -> 79168 (-0.01%)
VALU: 2906718 -> 2904777 (-0.07%); split: -0.07%, +0.00%
SALU: 726256 -> 723454 (-0.39%); split: -0.39%, +0.00%
VMEM: 205021 -> 205016 (-0.00%)
SMEM: 163972 -> 163916 (-0.03%)
VOPD: 303354 -> 303298 (-0.02%); split: +0.02%, -0.04%
Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/39987>
2026-02-08 23:03:16 +01:00
|
|
|
if (src_res[0] & FP_CLASS_ANY_NEG)
|
|
|
|
|
r |= FP_CLASS_NEG_ONE;
|
2025-02-14 20:13:58 +01:00
|
|
|
|
nir: rewrite fp range analysis as a fp class analysis
Knowing if a value is not larger than one helps proving finite
results of fmul/fadd and will allow skipping/creating more fsat.
Knowing that a value is larger than one helps proving non zero
results of fmul.
Separating positive and negative zero also has advantages when
signed zero correctness is required.
Foz-DB Navi48:
Totals from 1344 (1.63% of 82636) affected shaders:
Instrs: 5319389 -> 5312280 (-0.13%); split: -0.14%, +0.01%
CodeSize: 29702516 -> 29665684 (-0.12%); split: -0.13%, +0.01%
Latency: 40694344 -> 40694545 (+0.00%); split: -0.01%, +0.02%
InvThroughput: 7481192 -> 7480403 (-0.01%); split: -0.02%, +0.01%
VClause: 121947 -> 121946 (-0.00%); split: -0.00%, +0.00%
SClause: 104972 -> 104923 (-0.05%); split: -0.05%, +0.00%
Copies: 371098 -> 371092 (-0.00%); split: -0.02%, +0.02%
Branches: 122929 -> 122919 (-0.01%); split: -0.01%, +0.00%
PreSGPRs: 82506 -> 82510 (+0.00%); split: -0.00%, +0.01%
PreVGPRs: 79175 -> 79168 (-0.01%)
VALU: 2906718 -> 2904777 (-0.07%); split: -0.07%, +0.00%
SALU: 726256 -> 723454 (-0.39%); split: -0.39%, +0.00%
VMEM: 205021 -> 205016 (-0.00%)
SMEM: 163972 -> 163916 (-0.03%)
VOPD: 303354 -> 303298 (-0.02%); split: +0.02%, -0.04%
Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/39987>
2026-02-08 23:03:16 +01:00
|
|
|
if (src_res[0] & FP_CLASS_ANY_ZERO)
|
|
|
|
|
r |= FP_CLASS_ANY_ZERO;
|
2025-02-14 20:13:58 +01:00
|
|
|
|
nir: rewrite fp range analysis as a fp class analysis
Knowing if a value is not larger than one helps proving finite
results of fmul/fadd and will allow skipping/creating more fsat.
Knowing that a value is larger than one helps proving non zero
results of fmul.
Separating positive and negative zero also has advantages when
signed zero correctness is required.
Foz-DB Navi48:
Totals from 1344 (1.63% of 82636) affected shaders:
Instrs: 5319389 -> 5312280 (-0.13%); split: -0.14%, +0.01%
CodeSize: 29702516 -> 29665684 (-0.12%); split: -0.13%, +0.01%
Latency: 40694344 -> 40694545 (+0.00%); split: -0.01%, +0.02%
InvThroughput: 7481192 -> 7480403 (-0.01%); split: -0.02%, +0.01%
VClause: 121947 -> 121946 (-0.00%); split: -0.00%, +0.00%
SClause: 104972 -> 104923 (-0.05%); split: -0.05%, +0.00%
Copies: 371098 -> 371092 (-0.00%); split: -0.02%, +0.02%
Branches: 122929 -> 122919 (-0.01%); split: -0.01%, +0.00%
PreSGPRs: 82506 -> 82510 (+0.00%); split: -0.00%, +0.01%
PreVGPRs: 79175 -> 79168 (-0.01%)
VALU: 2906718 -> 2904777 (-0.07%); split: -0.07%, +0.00%
SALU: 726256 -> 723454 (-0.39%); split: -0.39%, +0.00%
VMEM: 205021 -> 205016 (-0.00%)
SMEM: 163972 -> 163916 (-0.03%)
VOPD: 303354 -> 303298 (-0.02%); split: +0.02%, -0.04%
Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/39987>
2026-02-08 23:03:16 +01:00
|
|
|
if (src_res[0] & FP_CLASS_ANY_POS)
|
|
|
|
|
r |= FP_CLASS_POS_ONE;
|
2025-02-14 20:13:58 +01:00
|
|
|
|
nir: rewrite fp range analysis as a fp class analysis
Knowing if a value is not larger than one helps proving finite
results of fmul/fadd and will allow skipping/creating more fsat.
Knowing that a value is larger than one helps proving non zero
results of fmul.
Separating positive and negative zero also has advantages when
signed zero correctness is required.
Foz-DB Navi48:
Totals from 1344 (1.63% of 82636) affected shaders:
Instrs: 5319389 -> 5312280 (-0.13%); split: -0.14%, +0.01%
CodeSize: 29702516 -> 29665684 (-0.12%); split: -0.13%, +0.01%
Latency: 40694344 -> 40694545 (+0.00%); split: -0.01%, +0.02%
InvThroughput: 7481192 -> 7480403 (-0.01%); split: -0.02%, +0.01%
VClause: 121947 -> 121946 (-0.00%); split: -0.00%, +0.00%
SClause: 104972 -> 104923 (-0.05%); split: -0.05%, +0.00%
Copies: 371098 -> 371092 (-0.00%); split: -0.02%, +0.02%
Branches: 122929 -> 122919 (-0.01%); split: -0.01%, +0.00%
PreSGPRs: 82506 -> 82510 (+0.00%); split: -0.00%, +0.01%
PreVGPRs: 79175 -> 79168 (-0.01%)
VALU: 2906718 -> 2904777 (-0.07%); split: -0.07%, +0.00%
SALU: 726256 -> 723454 (-0.39%); split: -0.39%, +0.00%
VMEM: 205021 -> 205016 (-0.00%)
SMEM: 163972 -> 163916 (-0.03%)
VOPD: 303354 -> 303298 (-0.02%); split: +0.02%, -0.04%
Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/39987>
2026-02-08 23:03:16 +01:00
|
|
|
/* fsign is -1, 0, or 1, even for NaN */
|
|
|
|
|
if (src_res[0] & FP_CLASS_NAN)
|
|
|
|
|
r |= FP_CLASS_NEG_ONE | FP_CLASS_ANY_ZERO | FP_CLASS_POS_ONE;
|
2018-01-23 09:48:43 +08:00
|
|
|
break;
|
2025-02-14 20:05:54 +01:00
|
|
|
|
nir: rewrite fp range analysis as a fp class analysis
Knowing if a value is not larger than one helps proving finite
results of fmul/fadd and will allow skipping/creating more fsat.
Knowing that a value is larger than one helps proving non zero
results of fmul.
Separating positive and negative zero also has advantages when
signed zero correctness is required.
Foz-DB Navi48:
Totals from 1344 (1.63% of 82636) affected shaders:
Instrs: 5319389 -> 5312280 (-0.13%); split: -0.14%, +0.01%
CodeSize: 29702516 -> 29665684 (-0.12%); split: -0.13%, +0.01%
Latency: 40694344 -> 40694545 (+0.00%); split: -0.01%, +0.02%
InvThroughput: 7481192 -> 7480403 (-0.01%); split: -0.02%, +0.01%
VClause: 121947 -> 121946 (-0.00%); split: -0.00%, +0.00%
SClause: 104972 -> 104923 (-0.05%); split: -0.05%, +0.00%
Copies: 371098 -> 371092 (-0.00%); split: -0.02%, +0.02%
Branches: 122929 -> 122919 (-0.01%); split: -0.01%, +0.00%
PreSGPRs: 82506 -> 82510 (+0.00%); split: -0.00%, +0.01%
PreVGPRs: 79175 -> 79168 (-0.01%)
VALU: 2906718 -> 2904777 (-0.07%); split: -0.07%, +0.00%
SALU: 726256 -> 723454 (-0.39%); split: -0.39%, +0.00%
VMEM: 205021 -> 205016 (-0.00%)
SMEM: 163972 -> 163916 (-0.03%)
VOPD: 303354 -> 303298 (-0.02%); split: +0.02%, -0.04%
Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/39987>
2026-02-08 23:03:16 +01:00
|
|
|
case nir_op_fsqrt:
|
|
|
|
|
r = fsqrt_fp_class(src_res[0]);
|
|
|
|
|
break;
|
2025-02-14 20:05:54 +01:00
|
|
|
|
nir: rewrite fp range analysis as a fp class analysis
Knowing if a value is not larger than one helps proving finite
results of fmul/fadd and will allow skipping/creating more fsat.
Knowing that a value is larger than one helps proving non zero
results of fmul.
Separating positive and negative zero also has advantages when
signed zero correctness is required.
Foz-DB Navi48:
Totals from 1344 (1.63% of 82636) affected shaders:
Instrs: 5319389 -> 5312280 (-0.13%); split: -0.14%, +0.01%
CodeSize: 29702516 -> 29665684 (-0.12%); split: -0.13%, +0.01%
Latency: 40694344 -> 40694545 (+0.00%); split: -0.01%, +0.02%
InvThroughput: 7481192 -> 7480403 (-0.01%); split: -0.02%, +0.01%
VClause: 121947 -> 121946 (-0.00%); split: -0.00%, +0.00%
SClause: 104972 -> 104923 (-0.05%); split: -0.05%, +0.00%
Copies: 371098 -> 371092 (-0.00%); split: -0.02%, +0.02%
Branches: 122929 -> 122919 (-0.01%); split: -0.01%, +0.00%
PreSGPRs: 82506 -> 82510 (+0.00%); split: -0.00%, +0.01%
PreVGPRs: 79175 -> 79168 (-0.01%)
VALU: 2906718 -> 2904777 (-0.07%); split: -0.07%, +0.00%
SALU: 726256 -> 723454 (-0.39%); split: -0.39%, +0.00%
VMEM: 205021 -> 205016 (-0.00%)
SMEM: 163972 -> 163916 (-0.03%)
VOPD: 303354 -> 303298 (-0.02%); split: +0.02%, -0.04%
Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/39987>
2026-02-08 23:03:16 +01:00
|
|
|
case nir_op_frsq:
|
|
|
|
|
r = frcp_fp_class(fsqrt_fp_class(handle_sz(alu, src_res[0])));
|
2025-02-14 20:05:54 +01:00
|
|
|
break;
|
|
|
|
|
|
2018-01-23 09:48:43 +08:00
|
|
|
case nir_op_ffloor: {
|
2020-08-17 15:56:24 -07:00
|
|
|
/* In IEEE 754, floor(NaN) is NaN, and floor(±Inf) is ±Inf. See
|
|
|
|
|
* https://pubs.opengroup.org/onlinepubs/9699919799.2016edition/functions/floor.html
|
|
|
|
|
*/
|
nir: rewrite fp range analysis as a fp class analysis
Knowing if a value is not larger than one helps proving finite
results of fmul/fadd and will allow skipping/creating more fsat.
Knowing that a value is larger than one helps proving non zero
results of fmul.
Separating positive and negative zero also has advantages when
signed zero correctness is required.
Foz-DB Navi48:
Totals from 1344 (1.63% of 82636) affected shaders:
Instrs: 5319389 -> 5312280 (-0.13%); split: -0.14%, +0.01%
CodeSize: 29702516 -> 29665684 (-0.12%); split: -0.13%, +0.01%
Latency: 40694344 -> 40694545 (+0.00%); split: -0.01%, +0.02%
InvThroughput: 7481192 -> 7480403 (-0.01%); split: -0.02%, +0.01%
VClause: 121947 -> 121946 (-0.00%); split: -0.00%, +0.00%
SClause: 104972 -> 104923 (-0.05%); split: -0.05%, +0.00%
Copies: 371098 -> 371092 (-0.00%); split: -0.02%, +0.02%
Branches: 122929 -> 122919 (-0.01%); split: -0.01%, +0.00%
PreSGPRs: 82506 -> 82510 (+0.00%); split: -0.00%, +0.01%
PreVGPRs: 79175 -> 79168 (-0.01%)
VALU: 2906718 -> 2904777 (-0.07%); split: -0.07%, +0.00%
SALU: 726256 -> 723454 (-0.39%); split: -0.39%, +0.00%
VMEM: 205021 -> 205016 (-0.00%)
SMEM: 163972 -> 163916 (-0.03%)
VOPD: 303354 -> 303298 (-0.02%); split: +0.02%, -0.04%
Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/39987>
2026-02-08 23:03:16 +01:00
|
|
|
r = src_res[0];
|
2020-08-17 15:56:24 -07:00
|
|
|
|
nir: rewrite fp range analysis as a fp class analysis
Knowing if a value is not larger than one helps proving finite
results of fmul/fadd and will allow skipping/creating more fsat.
Knowing that a value is larger than one helps proving non zero
results of fmul.
Separating positive and negative zero also has advantages when
signed zero correctness is required.
Foz-DB Navi48:
Totals from 1344 (1.63% of 82636) affected shaders:
Instrs: 5319389 -> 5312280 (-0.13%); split: -0.14%, +0.01%
CodeSize: 29702516 -> 29665684 (-0.12%); split: -0.13%, +0.01%
Latency: 40694344 -> 40694545 (+0.00%); split: -0.01%, +0.02%
InvThroughput: 7481192 -> 7480403 (-0.01%); split: -0.02%, +0.01%
VClause: 121947 -> 121946 (-0.00%); split: -0.00%, +0.00%
SClause: 104972 -> 104923 (-0.05%); split: -0.05%, +0.00%
Copies: 371098 -> 371092 (-0.00%); split: -0.02%, +0.02%
Branches: 122929 -> 122919 (-0.01%); split: -0.01%, +0.00%
PreSGPRs: 82506 -> 82510 (+0.00%); split: -0.00%, +0.01%
PreVGPRs: 79175 -> 79168 (-0.01%)
VALU: 2906718 -> 2904777 (-0.07%); split: -0.07%, +0.00%
SALU: 726256 -> 723454 (-0.39%); split: -0.39%, +0.00%
VMEM: 205021 -> 205016 (-0.00%)
SMEM: 163972 -> 163916 (-0.03%)
VOPD: 303354 -> 303298 (-0.02%); split: +0.02%, -0.04%
Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/39987>
2026-02-08 23:03:16 +01:00
|
|
|
if (r & FP_CLASS_NON_INTEGRAL) {
|
|
|
|
|
if (r & FP_CLASS_LT_ZERO_GT_NEG_ONE)
|
|
|
|
|
r |= FP_CLASS_NEG_ONE;
|
2018-01-23 09:48:43 +08:00
|
|
|
|
nir: rewrite fp range analysis as a fp class analysis
Knowing if a value is not larger than one helps proving finite
results of fmul/fadd and will allow skipping/creating more fsat.
Knowing that a value is larger than one helps proving non zero
results of fmul.
Separating positive and negative zero also has advantages when
signed zero correctness is required.
Foz-DB Navi48:
Totals from 1344 (1.63% of 82636) affected shaders:
Instrs: 5319389 -> 5312280 (-0.13%); split: -0.14%, +0.01%
CodeSize: 29702516 -> 29665684 (-0.12%); split: -0.13%, +0.01%
Latency: 40694344 -> 40694545 (+0.00%); split: -0.01%, +0.02%
InvThroughput: 7481192 -> 7480403 (-0.01%); split: -0.02%, +0.01%
VClause: 121947 -> 121946 (-0.00%); split: -0.00%, +0.00%
SClause: 104972 -> 104923 (-0.05%); split: -0.05%, +0.00%
Copies: 371098 -> 371092 (-0.00%); split: -0.02%, +0.02%
Branches: 122929 -> 122919 (-0.01%); split: -0.01%, +0.00%
PreSGPRs: 82506 -> 82510 (+0.00%); split: -0.00%, +0.01%
PreVGPRs: 79175 -> 79168 (-0.01%)
VALU: 2906718 -> 2904777 (-0.07%); split: -0.07%, +0.00%
SALU: 726256 -> 723454 (-0.39%); split: -0.39%, +0.00%
VMEM: 205021 -> 205016 (-0.00%)
SMEM: 163972 -> 163916 (-0.03%)
VOPD: 303354 -> 303298 (-0.02%); split: +0.02%, -0.04%
Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/39987>
2026-02-08 23:03:16 +01:00
|
|
|
if (r & FP_CLASS_GT_ZERO_LT_POS_ONE)
|
|
|
|
|
r |= FP_CLASS_POS_ZERO;
|
|
|
|
|
|
|
|
|
|
if (r & FP_CLASS_GT_POS_ONE)
|
|
|
|
|
r |= FP_CLASS_POS_ONE;
|
|
|
|
|
|
|
|
|
|
r &= ~(FP_CLASS_NON_INTEGRAL | FP_CLASS_LT_ZERO_GT_NEG_ONE | FP_CLASS_GT_ZERO_LT_POS_ONE);
|
|
|
|
|
}
|
2018-01-23 09:48:43 +08:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case nir_op_fceil: {
|
2020-08-17 15:56:24 -07:00
|
|
|
/* In IEEE 754, ceil(NaN) is NaN, and ceil(±Inf) is ±Inf. See
|
|
|
|
|
* https://pubs.opengroup.org/onlinepubs/9699919799.2016edition/functions/ceil.html
|
|
|
|
|
*/
|
nir: rewrite fp range analysis as a fp class analysis
Knowing if a value is not larger than one helps proving finite
results of fmul/fadd and will allow skipping/creating more fsat.
Knowing that a value is larger than one helps proving non zero
results of fmul.
Separating positive and negative zero also has advantages when
signed zero correctness is required.
Foz-DB Navi48:
Totals from 1344 (1.63% of 82636) affected shaders:
Instrs: 5319389 -> 5312280 (-0.13%); split: -0.14%, +0.01%
CodeSize: 29702516 -> 29665684 (-0.12%); split: -0.13%, +0.01%
Latency: 40694344 -> 40694545 (+0.00%); split: -0.01%, +0.02%
InvThroughput: 7481192 -> 7480403 (-0.01%); split: -0.02%, +0.01%
VClause: 121947 -> 121946 (-0.00%); split: -0.00%, +0.00%
SClause: 104972 -> 104923 (-0.05%); split: -0.05%, +0.00%
Copies: 371098 -> 371092 (-0.00%); split: -0.02%, +0.02%
Branches: 122929 -> 122919 (-0.01%); split: -0.01%, +0.00%
PreSGPRs: 82506 -> 82510 (+0.00%); split: -0.00%, +0.01%
PreVGPRs: 79175 -> 79168 (-0.01%)
VALU: 2906718 -> 2904777 (-0.07%); split: -0.07%, +0.00%
SALU: 726256 -> 723454 (-0.39%); split: -0.39%, +0.00%
VMEM: 205021 -> 205016 (-0.00%)
SMEM: 163972 -> 163916 (-0.03%)
VOPD: 303354 -> 303298 (-0.02%); split: +0.02%, -0.04%
Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/39987>
2026-02-08 23:03:16 +01:00
|
|
|
r = src_res[0];
|
|
|
|
|
|
|
|
|
|
if (r & FP_CLASS_NON_INTEGRAL) {
|
|
|
|
|
if (r & FP_CLASS_LT_NEG_ONE)
|
|
|
|
|
r |= FP_CLASS_NEG_ONE;
|
2020-08-17 15:56:24 -07:00
|
|
|
|
nir: rewrite fp range analysis as a fp class analysis
Knowing if a value is not larger than one helps proving finite
results of fmul/fadd and will allow skipping/creating more fsat.
Knowing that a value is larger than one helps proving non zero
results of fmul.
Separating positive and negative zero also has advantages when
signed zero correctness is required.
Foz-DB Navi48:
Totals from 1344 (1.63% of 82636) affected shaders:
Instrs: 5319389 -> 5312280 (-0.13%); split: -0.14%, +0.01%
CodeSize: 29702516 -> 29665684 (-0.12%); split: -0.13%, +0.01%
Latency: 40694344 -> 40694545 (+0.00%); split: -0.01%, +0.02%
InvThroughput: 7481192 -> 7480403 (-0.01%); split: -0.02%, +0.01%
VClause: 121947 -> 121946 (-0.00%); split: -0.00%, +0.00%
SClause: 104972 -> 104923 (-0.05%); split: -0.05%, +0.00%
Copies: 371098 -> 371092 (-0.00%); split: -0.02%, +0.02%
Branches: 122929 -> 122919 (-0.01%); split: -0.01%, +0.00%
PreSGPRs: 82506 -> 82510 (+0.00%); split: -0.00%, +0.01%
PreVGPRs: 79175 -> 79168 (-0.01%)
VALU: 2906718 -> 2904777 (-0.07%); split: -0.07%, +0.00%
SALU: 726256 -> 723454 (-0.39%); split: -0.39%, +0.00%
VMEM: 205021 -> 205016 (-0.00%)
SMEM: 163972 -> 163916 (-0.03%)
VOPD: 303354 -> 303298 (-0.02%); split: +0.02%, -0.04%
Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/39987>
2026-02-08 23:03:16 +01:00
|
|
|
if (r & FP_CLASS_LT_ZERO_GT_NEG_ONE)
|
|
|
|
|
r |= FP_CLASS_NEG_ZERO;
|
2018-01-23 09:48:43 +08:00
|
|
|
|
nir: rewrite fp range analysis as a fp class analysis
Knowing if a value is not larger than one helps proving finite
results of fmul/fadd and will allow skipping/creating more fsat.
Knowing that a value is larger than one helps proving non zero
results of fmul.
Separating positive and negative zero also has advantages when
signed zero correctness is required.
Foz-DB Navi48:
Totals from 1344 (1.63% of 82636) affected shaders:
Instrs: 5319389 -> 5312280 (-0.13%); split: -0.14%, +0.01%
CodeSize: 29702516 -> 29665684 (-0.12%); split: -0.13%, +0.01%
Latency: 40694344 -> 40694545 (+0.00%); split: -0.01%, +0.02%
InvThroughput: 7481192 -> 7480403 (-0.01%); split: -0.02%, +0.01%
VClause: 121947 -> 121946 (-0.00%); split: -0.00%, +0.00%
SClause: 104972 -> 104923 (-0.05%); split: -0.05%, +0.00%
Copies: 371098 -> 371092 (-0.00%); split: -0.02%, +0.02%
Branches: 122929 -> 122919 (-0.01%); split: -0.01%, +0.00%
PreSGPRs: 82506 -> 82510 (+0.00%); split: -0.00%, +0.01%
PreVGPRs: 79175 -> 79168 (-0.01%)
VALU: 2906718 -> 2904777 (-0.07%); split: -0.07%, +0.00%
SALU: 726256 -> 723454 (-0.39%); split: -0.39%, +0.00%
VMEM: 205021 -> 205016 (-0.00%)
SMEM: 163972 -> 163916 (-0.03%)
VOPD: 303354 -> 303298 (-0.02%); split: +0.02%, -0.04%
Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/39987>
2026-02-08 23:03:16 +01:00
|
|
|
if (r & FP_CLASS_GT_ZERO_LT_POS_ONE)
|
|
|
|
|
r |= FP_CLASS_POS_ONE;
|
|
|
|
|
|
|
|
|
|
r &= ~(FP_CLASS_NON_INTEGRAL | FP_CLASS_LT_ZERO_GT_NEG_ONE | FP_CLASS_GT_ZERO_LT_POS_ONE);
|
|
|
|
|
}
|
2018-01-23 09:48:43 +08:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case nir_op_ftrunc: {
|
2020-08-17 15:56:24 -07:00
|
|
|
/* In IEEE 754, trunc(NaN) is NaN, and trunc(±Inf) is ±Inf. See
|
|
|
|
|
* https://pubs.opengroup.org/onlinepubs/9699919799.2016edition/functions/trunc.html
|
|
|
|
|
*/
|
nir: rewrite fp range analysis as a fp class analysis
Knowing if a value is not larger than one helps proving finite
results of fmul/fadd and will allow skipping/creating more fsat.
Knowing that a value is larger than one helps proving non zero
results of fmul.
Separating positive and negative zero also has advantages when
signed zero correctness is required.
Foz-DB Navi48:
Totals from 1344 (1.63% of 82636) affected shaders:
Instrs: 5319389 -> 5312280 (-0.13%); split: -0.14%, +0.01%
CodeSize: 29702516 -> 29665684 (-0.12%); split: -0.13%, +0.01%
Latency: 40694344 -> 40694545 (+0.00%); split: -0.01%, +0.02%
InvThroughput: 7481192 -> 7480403 (-0.01%); split: -0.02%, +0.01%
VClause: 121947 -> 121946 (-0.00%); split: -0.00%, +0.00%
SClause: 104972 -> 104923 (-0.05%); split: -0.05%, +0.00%
Copies: 371098 -> 371092 (-0.00%); split: -0.02%, +0.02%
Branches: 122929 -> 122919 (-0.01%); split: -0.01%, +0.00%
PreSGPRs: 82506 -> 82510 (+0.00%); split: -0.00%, +0.01%
PreVGPRs: 79175 -> 79168 (-0.01%)
VALU: 2906718 -> 2904777 (-0.07%); split: -0.07%, +0.00%
SALU: 726256 -> 723454 (-0.39%); split: -0.39%, +0.00%
VMEM: 205021 -> 205016 (-0.00%)
SMEM: 163972 -> 163916 (-0.03%)
VOPD: 303354 -> 303298 (-0.02%); split: +0.02%, -0.04%
Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/39987>
2026-02-08 23:03:16 +01:00
|
|
|
r = src_res[0];
|
|
|
|
|
|
|
|
|
|
if (r & FP_CLASS_NON_INTEGRAL) {
|
|
|
|
|
if (r & FP_CLASS_LT_NEG_ONE)
|
|
|
|
|
r |= FP_CLASS_NEG_ONE;
|
|
|
|
|
|
|
|
|
|
if (r & FP_CLASS_LT_ZERO_GT_NEG_ONE)
|
|
|
|
|
r |= FP_CLASS_NEG_ZERO;
|
2018-01-23 09:48:43 +08:00
|
|
|
|
nir: rewrite fp range analysis as a fp class analysis
Knowing if a value is not larger than one helps proving finite
results of fmul/fadd and will allow skipping/creating more fsat.
Knowing that a value is larger than one helps proving non zero
results of fmul.
Separating positive and negative zero also has advantages when
signed zero correctness is required.
Foz-DB Navi48:
Totals from 1344 (1.63% of 82636) affected shaders:
Instrs: 5319389 -> 5312280 (-0.13%); split: -0.14%, +0.01%
CodeSize: 29702516 -> 29665684 (-0.12%); split: -0.13%, +0.01%
Latency: 40694344 -> 40694545 (+0.00%); split: -0.01%, +0.02%
InvThroughput: 7481192 -> 7480403 (-0.01%); split: -0.02%, +0.01%
VClause: 121947 -> 121946 (-0.00%); split: -0.00%, +0.00%
SClause: 104972 -> 104923 (-0.05%); split: -0.05%, +0.00%
Copies: 371098 -> 371092 (-0.00%); split: -0.02%, +0.02%
Branches: 122929 -> 122919 (-0.01%); split: -0.01%, +0.00%
PreSGPRs: 82506 -> 82510 (+0.00%); split: -0.00%, +0.01%
PreVGPRs: 79175 -> 79168 (-0.01%)
VALU: 2906718 -> 2904777 (-0.07%); split: -0.07%, +0.00%
SALU: 726256 -> 723454 (-0.39%); split: -0.39%, +0.00%
VMEM: 205021 -> 205016 (-0.00%)
SMEM: 163972 -> 163916 (-0.03%)
VOPD: 303354 -> 303298 (-0.02%); split: +0.02%, -0.04%
Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/39987>
2026-02-08 23:03:16 +01:00
|
|
|
if (r & FP_CLASS_GT_ZERO_LT_POS_ONE)
|
|
|
|
|
r |= FP_CLASS_POS_ZERO;
|
|
|
|
|
|
|
|
|
|
if (r & FP_CLASS_GT_POS_ONE)
|
|
|
|
|
r |= FP_CLASS_POS_ONE;
|
|
|
|
|
|
|
|
|
|
r &= ~(FP_CLASS_NON_INTEGRAL | FP_CLASS_LT_ZERO_GT_NEG_ONE | FP_CLASS_GT_ZERO_LT_POS_ONE);
|
|
|
|
|
}
|
2018-01-23 09:48:43 +08:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-14 18:54:09 +01:00
|
|
|
case nir_op_ffract: {
|
nir: rewrite fp range analysis as a fp class analysis
Knowing if a value is not larger than one helps proving finite
results of fmul/fadd and will allow skipping/creating more fsat.
Knowing that a value is larger than one helps proving non zero
results of fmul.
Separating positive and negative zero also has advantages when
signed zero correctness is required.
Foz-DB Navi48:
Totals from 1344 (1.63% of 82636) affected shaders:
Instrs: 5319389 -> 5312280 (-0.13%); split: -0.14%, +0.01%
CodeSize: 29702516 -> 29665684 (-0.12%); split: -0.13%, +0.01%
Latency: 40694344 -> 40694545 (+0.00%); split: -0.01%, +0.02%
InvThroughput: 7481192 -> 7480403 (-0.01%); split: -0.02%, +0.01%
VClause: 121947 -> 121946 (-0.00%); split: -0.00%, +0.00%
SClause: 104972 -> 104923 (-0.05%); split: -0.05%, +0.00%
Copies: 371098 -> 371092 (-0.00%); split: -0.02%, +0.02%
Branches: 122929 -> 122919 (-0.01%); split: -0.01%, +0.00%
PreSGPRs: 82506 -> 82510 (+0.00%); split: -0.00%, +0.01%
PreVGPRs: 79175 -> 79168 (-0.01%)
VALU: 2906718 -> 2904777 (-0.07%); split: -0.07%, +0.00%
SALU: 726256 -> 723454 (-0.39%); split: -0.39%, +0.00%
VMEM: 205021 -> 205016 (-0.00%)
SMEM: 163972 -> 163916 (-0.03%)
VOPD: 303354 -> 303298 (-0.02%); split: +0.02%, -0.04%
Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/39987>
2026-02-08 23:03:16 +01:00
|
|
|
r = 0;
|
2025-02-14 18:54:09 +01:00
|
|
|
|
nir: rewrite fp range analysis as a fp class analysis
Knowing if a value is not larger than one helps proving finite
results of fmul/fadd and will allow skipping/creating more fsat.
Knowing that a value is larger than one helps proving non zero
results of fmul.
Separating positive and negative zero also has advantages when
signed zero correctness is required.
Foz-DB Navi48:
Totals from 1344 (1.63% of 82636) affected shaders:
Instrs: 5319389 -> 5312280 (-0.13%); split: -0.14%, +0.01%
CodeSize: 29702516 -> 29665684 (-0.12%); split: -0.13%, +0.01%
Latency: 40694344 -> 40694545 (+0.00%); split: -0.01%, +0.02%
InvThroughput: 7481192 -> 7480403 (-0.01%); split: -0.02%, +0.01%
VClause: 121947 -> 121946 (-0.00%); split: -0.00%, +0.00%
SClause: 104972 -> 104923 (-0.05%); split: -0.05%, +0.00%
Copies: 371098 -> 371092 (-0.00%); split: -0.02%, +0.02%
Branches: 122929 -> 122919 (-0.01%); split: -0.01%, +0.00%
PreSGPRs: 82506 -> 82510 (+0.00%); split: -0.00%, +0.01%
PreVGPRs: 79175 -> 79168 (-0.01%)
VALU: 2906718 -> 2904777 (-0.07%); split: -0.07%, +0.00%
SALU: 726256 -> 723454 (-0.39%); split: -0.39%, +0.00%
VMEM: 205021 -> 205016 (-0.00%)
SMEM: 163972 -> 163916 (-0.03%)
VOPD: 303354 -> 303298 (-0.02%); split: +0.02%, -0.04%
Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/39987>
2026-02-08 23:03:16 +01:00
|
|
|
/* fract(±Inf) is NaN. */
|
|
|
|
|
if (src_res[0] & (FP_CLASS_ANY_INF | FP_CLASS_NAN))
|
|
|
|
|
r |= FP_CLASS_NAN;
|
2025-02-14 18:54:09 +01:00
|
|
|
|
nir: rewrite fp range analysis as a fp class analysis
Knowing if a value is not larger than one helps proving finite
results of fmul/fadd and will allow skipping/creating more fsat.
Knowing that a value is larger than one helps proving non zero
results of fmul.
Separating positive and negative zero also has advantages when
signed zero correctness is required.
Foz-DB Navi48:
Totals from 1344 (1.63% of 82636) affected shaders:
Instrs: 5319389 -> 5312280 (-0.13%); split: -0.14%, +0.01%
CodeSize: 29702516 -> 29665684 (-0.12%); split: -0.13%, +0.01%
Latency: 40694344 -> 40694545 (+0.00%); split: -0.01%, +0.02%
InvThroughput: 7481192 -> 7480403 (-0.01%); split: -0.02%, +0.01%
VClause: 121947 -> 121946 (-0.00%); split: -0.00%, +0.00%
SClause: 104972 -> 104923 (-0.05%); split: -0.05%, +0.00%
Copies: 371098 -> 371092 (-0.00%); split: -0.02%, +0.02%
Branches: 122929 -> 122919 (-0.01%); split: -0.01%, +0.00%
PreSGPRs: 82506 -> 82510 (+0.00%); split: -0.00%, +0.01%
PreVGPRs: 79175 -> 79168 (-0.01%)
VALU: 2906718 -> 2904777 (-0.07%); split: -0.07%, +0.00%
SALU: 726256 -> 723454 (-0.39%); split: -0.39%, +0.00%
VMEM: 205021 -> 205016 (-0.00%)
SMEM: 163972 -> 163916 (-0.03%)
VOPD: 303354 -> 303298 (-0.02%); split: +0.02%, -0.04%
Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/39987>
2026-02-08 23:03:16 +01:00
|
|
|
/* fract(non_integral) is in (0, 1). */
|
|
|
|
|
if (src_res[0] & FP_CLASS_NON_INTEGRAL)
|
|
|
|
|
r |= FP_CLASS_GT_ZERO_LT_POS_ONE | FP_CLASS_NON_INTEGRAL;
|
|
|
|
|
|
|
|
|
|
/* fract(small, negative) can be 1.0. */
|
|
|
|
|
if (src_res[0] & FP_CLASS_LT_ZERO_GT_NEG_ONE)
|
|
|
|
|
r |= FP_CLASS_POS_ONE;
|
|
|
|
|
|
|
|
|
|
/* fract(integral) is +0.0. */
|
|
|
|
|
if (src_res[0] & (FP_CLASS_LT_NEG_ONE | FP_CLASS_NEG_ONE | FP_CLASS_ANY_ZERO | FP_CLASS_POS_ONE | FP_CLASS_GT_POS_ONE))
|
|
|
|
|
r |= FP_CLASS_POS_ZERO;
|
2025-02-14 18:54:09 +01:00
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-11 19:53:46 +01:00
|
|
|
case nir_op_fsin:
|
|
|
|
|
case nir_op_fcos:
|
|
|
|
|
case nir_op_fsin_amd:
|
|
|
|
|
case nir_op_fcos_amd: {
|
|
|
|
|
/* [-1, +1], and sin/cos(Inf) is NaN */
|
|
|
|
|
r = FP_CLASS_NEG_ONE | FP_CLASS_LT_ZERO_GT_NEG_ONE | FP_CLASS_ANY_ZERO |
|
|
|
|
|
FP_CLASS_GT_ZERO_LT_POS_ONE | FP_CLASS_POS_ONE | FP_CLASS_NON_INTEGRAL;
|
|
|
|
|
|
|
|
|
|
if (src_res[0] & (FP_CLASS_NAN | FP_CLASS_ANY_INF))
|
|
|
|
|
r |= FP_CLASS_NAN;
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-21 16:47:31 -07:00
|
|
|
case nir_op_fdot2:
|
|
|
|
|
case nir_op_fdot3:
|
|
|
|
|
case nir_op_fdot4:
|
|
|
|
|
case nir_op_fdot8:
|
|
|
|
|
case nir_op_fdot16:
|
|
|
|
|
case nir_op_fdot2_replicated:
|
|
|
|
|
case nir_op_fdot3_replicated:
|
|
|
|
|
case nir_op_fdot4_replicated:
|
|
|
|
|
case nir_op_fdot8_replicated:
|
|
|
|
|
case nir_op_fdot16_replicated: {
|
|
|
|
|
/* If the two sources are the same SSA value, then the result is either
|
|
|
|
|
* NaN or some number >= 0. If one source is the negation of the other,
|
|
|
|
|
* the result is either NaN or some number <= 0.
|
|
|
|
|
*
|
|
|
|
|
* In either of these two cases, if one source is a number, then the
|
|
|
|
|
* other must also be a number. Since it should not be possible to get
|
|
|
|
|
* Inf-Inf in the dot-product, the result must also be a number.
|
|
|
|
|
*/
|
|
|
|
|
if (nir_alu_srcs_equal(alu, alu, 0, 1)) {
|
nir: rewrite fp range analysis as a fp class analysis
Knowing if a value is not larger than one helps proving finite
results of fmul/fadd and will allow skipping/creating more fsat.
Knowing that a value is larger than one helps proving non zero
results of fmul.
Separating positive and negative zero also has advantages when
signed zero correctness is required.
Foz-DB Navi48:
Totals from 1344 (1.63% of 82636) affected shaders:
Instrs: 5319389 -> 5312280 (-0.13%); split: -0.14%, +0.01%
CodeSize: 29702516 -> 29665684 (-0.12%); split: -0.13%, +0.01%
Latency: 40694344 -> 40694545 (+0.00%); split: -0.01%, +0.02%
InvThroughput: 7481192 -> 7480403 (-0.01%); split: -0.02%, +0.01%
VClause: 121947 -> 121946 (-0.00%); split: -0.00%, +0.00%
SClause: 104972 -> 104923 (-0.05%); split: -0.05%, +0.00%
Copies: 371098 -> 371092 (-0.00%); split: -0.02%, +0.02%
Branches: 122929 -> 122919 (-0.01%); split: -0.01%, +0.00%
PreSGPRs: 82506 -> 82510 (+0.00%); split: -0.00%, +0.01%
PreVGPRs: 79175 -> 79168 (-0.01%)
VALU: 2906718 -> 2904777 (-0.07%); split: -0.07%, +0.00%
SALU: 726256 -> 723454 (-0.39%); split: -0.39%, +0.00%
VMEM: 205021 -> 205016 (-0.00%)
SMEM: 163972 -> 163916 (-0.03%)
VOPD: 303354 -> 303298 (-0.02%); split: +0.02%, -0.04%
Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/39987>
2026-02-08 23:03:16 +01:00
|
|
|
r = FP_CLASS_ANY_POS | FP_CLASS_POS_ZERO;
|
2022-06-21 16:47:31 -07:00
|
|
|
} else if (nir_alu_srcs_negative_equal(alu, alu, 0, 1)) {
|
nir: rewrite fp range analysis as a fp class analysis
Knowing if a value is not larger than one helps proving finite
results of fmul/fadd and will allow skipping/creating more fsat.
Knowing that a value is larger than one helps proving non zero
results of fmul.
Separating positive and negative zero also has advantages when
signed zero correctness is required.
Foz-DB Navi48:
Totals from 1344 (1.63% of 82636) affected shaders:
Instrs: 5319389 -> 5312280 (-0.13%); split: -0.14%, +0.01%
CodeSize: 29702516 -> 29665684 (-0.12%); split: -0.13%, +0.01%
Latency: 40694344 -> 40694545 (+0.00%); split: -0.01%, +0.02%
InvThroughput: 7481192 -> 7480403 (-0.01%); split: -0.02%, +0.01%
VClause: 121947 -> 121946 (-0.00%); split: -0.00%, +0.00%
SClause: 104972 -> 104923 (-0.05%); split: -0.05%, +0.00%
Copies: 371098 -> 371092 (-0.00%); split: -0.02%, +0.02%
Branches: 122929 -> 122919 (-0.01%); split: -0.01%, +0.00%
PreSGPRs: 82506 -> 82510 (+0.00%); split: -0.00%, +0.01%
PreVGPRs: 79175 -> 79168 (-0.01%)
VALU: 2906718 -> 2904777 (-0.07%); split: -0.07%, +0.00%
SALU: 726256 -> 723454 (-0.39%); split: -0.39%, +0.00%
VMEM: 205021 -> 205016 (-0.00%)
SMEM: 163972 -> 163916 (-0.03%)
VOPD: 303354 -> 303298 (-0.02%); split: +0.02%, -0.04%
Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/39987>
2026-02-08 23:03:16 +01:00
|
|
|
r = FP_CLASS_ANY_NEG | FP_CLASS_NEG_ZERO;
|
2022-06-21 16:47:31 -07:00
|
|
|
} else {
|
nir: rewrite fp range analysis as a fp class analysis
Knowing if a value is not larger than one helps proving finite
results of fmul/fadd and will allow skipping/creating more fsat.
Knowing that a value is larger than one helps proving non zero
results of fmul.
Separating positive and negative zero also has advantages when
signed zero correctness is required.
Foz-DB Navi48:
Totals from 1344 (1.63% of 82636) affected shaders:
Instrs: 5319389 -> 5312280 (-0.13%); split: -0.14%, +0.01%
CodeSize: 29702516 -> 29665684 (-0.12%); split: -0.13%, +0.01%
Latency: 40694344 -> 40694545 (+0.00%); split: -0.01%, +0.02%
InvThroughput: 7481192 -> 7480403 (-0.01%); split: -0.02%, +0.01%
VClause: 121947 -> 121946 (-0.00%); split: -0.00%, +0.00%
SClause: 104972 -> 104923 (-0.05%); split: -0.05%, +0.00%
Copies: 371098 -> 371092 (-0.00%); split: -0.02%, +0.02%
Branches: 122929 -> 122919 (-0.01%); split: -0.01%, +0.00%
PreSGPRs: 82506 -> 82510 (+0.00%); split: -0.00%, +0.01%
PreVGPRs: 79175 -> 79168 (-0.01%)
VALU: 2906718 -> 2904777 (-0.07%); split: -0.07%, +0.00%
SALU: 726256 -> 723454 (-0.39%); split: -0.39%, +0.00%
VMEM: 205021 -> 205016 (-0.00%)
SMEM: 163972 -> 163916 (-0.03%)
VOPD: 303354 -> 303298 (-0.02%); split: +0.02%, -0.04%
Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/39987>
2026-02-08 23:03:16 +01:00
|
|
|
r = FP_CLASS_UNKNOWN;
|
2022-06-21 16:47:31 -07:00
|
|
|
}
|
nir: rewrite fp range analysis as a fp class analysis
Knowing if a value is not larger than one helps proving finite
results of fmul/fadd and will allow skipping/creating more fsat.
Knowing that a value is larger than one helps proving non zero
results of fmul.
Separating positive and negative zero also has advantages when
signed zero correctness is required.
Foz-DB Navi48:
Totals from 1344 (1.63% of 82636) affected shaders:
Instrs: 5319389 -> 5312280 (-0.13%); split: -0.14%, +0.01%
CodeSize: 29702516 -> 29665684 (-0.12%); split: -0.13%, +0.01%
Latency: 40694344 -> 40694545 (+0.00%); split: -0.01%, +0.02%
InvThroughput: 7481192 -> 7480403 (-0.01%); split: -0.02%, +0.01%
VClause: 121947 -> 121946 (-0.00%); split: -0.00%, +0.00%
SClause: 104972 -> 104923 (-0.05%); split: -0.05%, +0.00%
Copies: 371098 -> 371092 (-0.00%); split: -0.02%, +0.02%
Branches: 122929 -> 122919 (-0.01%); split: -0.01%, +0.00%
PreSGPRs: 82506 -> 82510 (+0.00%); split: -0.00%, +0.01%
PreVGPRs: 79175 -> 79168 (-0.01%)
VALU: 2906718 -> 2904777 (-0.07%); split: -0.07%, +0.00%
SALU: 726256 -> 723454 (-0.39%); split: -0.39%, +0.00%
VMEM: 205021 -> 205016 (-0.00%)
SMEM: 163972 -> 163916 (-0.03%)
VOPD: 303354 -> 303298 (-0.02%); split: +0.02%, -0.04%
Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/39987>
2026-02-08 23:03:16 +01:00
|
|
|
|
|
|
|
|
if (src_res[0] & FP_CLASS_NAN)
|
|
|
|
|
r |= FP_CLASS_NAN;
|
|
|
|
|
|
|
|
|
|
if (src_res[0] & FP_CLASS_NON_INTEGRAL)
|
|
|
|
|
r |= FP_CLASS_NON_INTEGRAL;
|
|
|
|
|
|
2022-06-21 16:47:31 -07:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-09 12:48:27 -07:00
|
|
|
case nir_op_fpow: {
|
nir: rewrite fp range analysis as a fp class analysis
Knowing if a value is not larger than one helps proving finite
results of fmul/fadd and will allow skipping/creating more fsat.
Knowing that a value is larger than one helps proving non zero
results of fmul.
Separating positive and negative zero also has advantages when
signed zero correctness is required.
Foz-DB Navi48:
Totals from 1344 (1.63% of 82636) affected shaders:
Instrs: 5319389 -> 5312280 (-0.13%); split: -0.14%, +0.01%
CodeSize: 29702516 -> 29665684 (-0.12%); split: -0.13%, +0.01%
Latency: 40694344 -> 40694545 (+0.00%); split: -0.01%, +0.02%
InvThroughput: 7481192 -> 7480403 (-0.01%); split: -0.02%, +0.01%
VClause: 121947 -> 121946 (-0.00%); split: -0.00%, +0.00%
SClause: 104972 -> 104923 (-0.05%); split: -0.05%, +0.00%
Copies: 371098 -> 371092 (-0.00%); split: -0.02%, +0.02%
Branches: 122929 -> 122919 (-0.01%); split: -0.01%, +0.00%
PreSGPRs: 82506 -> 82510 (+0.00%); split: -0.00%, +0.01%
PreVGPRs: 79175 -> 79168 (-0.01%)
VALU: 2906718 -> 2904777 (-0.07%); split: -0.07%, +0.00%
SALU: 726256 -> 723454 (-0.39%); split: -0.39%, +0.00%
VMEM: 205021 -> 205016 (-0.00%)
SMEM: 163972 -> 163916 (-0.03%)
VOPD: 303354 -> 303298 (-0.02%); split: +0.02%, -0.04%
Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/39987>
2026-02-08 23:03:16 +01:00
|
|
|
/* This is a basic port of the old range analysis, the opcode is very
|
|
|
|
|
* underdefined. But improvements are likely possible.
|
|
|
|
|
* Due to flush-to-zero semanatics of floating-point numbers with very
|
2019-08-09 12:48:27 -07:00
|
|
|
* small mangnitudes, we can never really be sure a result will be
|
|
|
|
|
* non-zero.
|
|
|
|
|
*
|
|
|
|
|
* NIR uses pow() and powf() to constant evaluate nir_op_fpow. The man
|
|
|
|
|
* page for that function says:
|
|
|
|
|
*
|
|
|
|
|
* If y is 0, the result is 1.0 (even if x is a NaN).
|
|
|
|
|
*
|
|
|
|
|
* gt_zero: pow(*, eq_zero)
|
|
|
|
|
* | pow(eq_zero, lt_zero) # 0^-y = +inf
|
|
|
|
|
* | pow(eq_zero, le_zero) # 0^-y = +inf or 0^0 = 1.0
|
|
|
|
|
* ;
|
|
|
|
|
*
|
|
|
|
|
* eq_zero: pow(eq_zero, gt_zero)
|
|
|
|
|
* ;
|
|
|
|
|
*
|
|
|
|
|
* ge_zero: pow(gt_zero, gt_zero)
|
|
|
|
|
* | pow(gt_zero, ge_zero)
|
|
|
|
|
* | pow(gt_zero, lt_zero)
|
|
|
|
|
* | pow(gt_zero, le_zero)
|
|
|
|
|
* | pow(gt_zero, ne_zero)
|
|
|
|
|
* | pow(gt_zero, unknown)
|
|
|
|
|
* | pow(ge_zero, gt_zero)
|
|
|
|
|
* | pow(ge_zero, ge_zero)
|
|
|
|
|
* | pow(ge_zero, lt_zero)
|
|
|
|
|
* | pow(ge_zero, le_zero)
|
|
|
|
|
* | pow(ge_zero, ne_zero)
|
|
|
|
|
* | pow(ge_zero, unknown)
|
|
|
|
|
* | pow(eq_zero, ge_zero) # 0^0 = 1.0 or 0^+y = 0.0
|
|
|
|
|
* | pow(eq_zero, ne_zero) # 0^-y = +inf or 0^+y = 0.0
|
|
|
|
|
* | pow(eq_zero, unknown) # union of all other y cases
|
|
|
|
|
* ;
|
|
|
|
|
*
|
|
|
|
|
* All other cases are unknown.
|
|
|
|
|
*
|
|
|
|
|
* We could do better if the right operand is a constant, integral
|
|
|
|
|
* value.
|
|
|
|
|
*/
|
nir: rewrite fp range analysis as a fp class analysis
Knowing if a value is not larger than one helps proving finite
results of fmul/fadd and will allow skipping/creating more fsat.
Knowing that a value is larger than one helps proving non zero
results of fmul.
Separating positive and negative zero also has advantages when
signed zero correctness is required.
Foz-DB Navi48:
Totals from 1344 (1.63% of 82636) affected shaders:
Instrs: 5319389 -> 5312280 (-0.13%); split: -0.14%, +0.01%
CodeSize: 29702516 -> 29665684 (-0.12%); split: -0.13%, +0.01%
Latency: 40694344 -> 40694545 (+0.00%); split: -0.01%, +0.02%
InvThroughput: 7481192 -> 7480403 (-0.01%); split: -0.02%, +0.01%
VClause: 121947 -> 121946 (-0.00%); split: -0.00%, +0.00%
SClause: 104972 -> 104923 (-0.05%); split: -0.05%, +0.00%
Copies: 371098 -> 371092 (-0.00%); split: -0.02%, +0.02%
Branches: 122929 -> 122919 (-0.01%); split: -0.01%, +0.00%
PreSGPRs: 82506 -> 82510 (+0.00%); split: -0.00%, +0.01%
PreVGPRs: 79175 -> 79168 (-0.01%)
VALU: 2906718 -> 2904777 (-0.07%); split: -0.07%, +0.00%
SALU: 726256 -> 723454 (-0.39%); split: -0.39%, +0.00%
VMEM: 205021 -> 205016 (-0.00%)
SMEM: 163972 -> 163916 (-0.03%)
VOPD: 303354 -> 303298 (-0.02%); split: +0.02%, -0.04%
Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/39987>
2026-02-08 23:03:16 +01:00
|
|
|
|
|
|
|
|
fp_class_mask left = src_res[0];
|
|
|
|
|
fp_class_mask right = src_res[1];
|
|
|
|
|
|
|
|
|
|
if (!(right & (FP_CLASS_ANY_NEG | FP_CLASS_ANY_POS))) {
|
|
|
|
|
r = FP_CLASS_ANY_POS;
|
|
|
|
|
} else if (left & (FP_CLASS_ANY_NEG | FP_CLASS_NEG_ZERO)) {
|
|
|
|
|
r = FP_CLASS_UNKNOWN;
|
|
|
|
|
} else {
|
|
|
|
|
r = FP_CLASS_ANY_POS | FP_CLASS_ANY_ZERO;
|
|
|
|
|
if ((right & (FP_CLASS_ANY_NEG | FP_CLASS_NON_INTEGRAL)) || (left & FP_CLASS_NON_INTEGRAL))
|
|
|
|
|
r |= FP_CLASS_NON_INTEGRAL;
|
|
|
|
|
}
|
2020-07-02 18:18:09 -07:00
|
|
|
|
|
|
|
|
/* Various cases can result in NaN, so assume the worst. */
|
nir: rewrite fp range analysis as a fp class analysis
Knowing if a value is not larger than one helps proving finite
results of fmul/fadd and will allow skipping/creating more fsat.
Knowing that a value is larger than one helps proving non zero
results of fmul.
Separating positive and negative zero also has advantages when
signed zero correctness is required.
Foz-DB Navi48:
Totals from 1344 (1.63% of 82636) affected shaders:
Instrs: 5319389 -> 5312280 (-0.13%); split: -0.14%, +0.01%
CodeSize: 29702516 -> 29665684 (-0.12%); split: -0.13%, +0.01%
Latency: 40694344 -> 40694545 (+0.00%); split: -0.01%, +0.02%
InvThroughput: 7481192 -> 7480403 (-0.01%); split: -0.02%, +0.01%
VClause: 121947 -> 121946 (-0.00%); split: -0.00%, +0.00%
SClause: 104972 -> 104923 (-0.05%); split: -0.05%, +0.00%
Copies: 371098 -> 371092 (-0.00%); split: -0.02%, +0.02%
Branches: 122929 -> 122919 (-0.01%); split: -0.01%, +0.00%
PreSGPRs: 82506 -> 82510 (+0.00%); split: -0.00%, +0.01%
PreVGPRs: 79175 -> 79168 (-0.01%)
VALU: 2906718 -> 2904777 (-0.07%); split: -0.07%, +0.00%
SALU: 726256 -> 723454 (-0.39%); split: -0.39%, +0.00%
VMEM: 205021 -> 205016 (-0.00%)
SMEM: 163972 -> 163916 (-0.03%)
VOPD: 303354 -> 303298 (-0.02%); split: +0.02%, -0.04%
Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/39987>
2026-02-08 23:03:16 +01:00
|
|
|
r |= FP_CLASS_NAN;
|
2020-07-02 18:18:09 -07:00
|
|
|
|
2019-08-09 12:48:27 -07:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-24 08:20:46 +01:00
|
|
|
case nir_op_ffma:
|
|
|
|
|
case nir_op_ffmaz: {
|
nir: rewrite fp range analysis as a fp class analysis
Knowing if a value is not larger than one helps proving finite
results of fmul/fadd and will allow skipping/creating more fsat.
Knowing that a value is larger than one helps proving non zero
results of fmul.
Separating positive and negative zero also has advantages when
signed zero correctness is required.
Foz-DB Navi48:
Totals from 1344 (1.63% of 82636) affected shaders:
Instrs: 5319389 -> 5312280 (-0.13%); split: -0.14%, +0.01%
CodeSize: 29702516 -> 29665684 (-0.12%); split: -0.13%, +0.01%
Latency: 40694344 -> 40694545 (+0.00%); split: -0.01%, +0.02%
InvThroughput: 7481192 -> 7480403 (-0.01%); split: -0.02%, +0.01%
VClause: 121947 -> 121946 (-0.00%); split: -0.00%, +0.00%
SClause: 104972 -> 104923 (-0.05%); split: -0.05%, +0.00%
Copies: 371098 -> 371092 (-0.00%); split: -0.02%, +0.02%
Branches: 122929 -> 122919 (-0.01%); split: -0.01%, +0.00%
PreSGPRs: 82506 -> 82510 (+0.00%); split: -0.00%, +0.01%
PreVGPRs: 79175 -> 79168 (-0.01%)
VALU: 2906718 -> 2904777 (-0.07%); split: -0.07%, +0.00%
SALU: 726256 -> 723454 (-0.39%); split: -0.39%, +0.00%
VMEM: 205021 -> 205016 (-0.00%)
SMEM: 163972 -> 163916 (-0.03%)
VOPD: 303354 -> 303298 (-0.02%); split: +0.02%, -0.04%
Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/39987>
2026-02-08 23:03:16 +01:00
|
|
|
bool mulz = alu->op == nir_op_ffmaz;
|
|
|
|
|
bool src_eq = nir_alu_srcs_equal(alu, alu, 0, 1);
|
|
|
|
|
bool src_neg_eq = !nir_src_is_const(alu->src[0].src) && nir_alu_srcs_negative_equal(alu, alu, 0, 1);
|
|
|
|
|
fp_class_mask r_mul = fmul_fp_class(src_res[0], src_res[1], mulz, src_eq, src_neg_eq);
|
|
|
|
|
r = fadd_fp_class(r_mul, src_res[2]);
|
|
|
|
|
|
|
|
|
|
/* fma(a, b, +0.0) can be -0.0 if a * b underflows.
|
|
|
|
|
* When fused, the underflow is not flushed before the addition.
|
|
|
|
|
*/
|
|
|
|
|
bool mul_underflow = (((src_res[0] & FP_CLASS_LT_ZERO_GT_NEG_ONE) && (src_res[1] & FP_CLASS_GT_ZERO_LT_POS_ONE)) ||
|
|
|
|
|
((src_res[1] & FP_CLASS_LT_ZERO_GT_NEG_ONE) && (src_res[0] & FP_CLASS_GT_ZERO_LT_POS_ONE)));
|
|
|
|
|
if (!src_eq && mul_underflow && (src_res[2] & FP_CLASS_POS_ZERO))
|
|
|
|
|
r |= FP_CLASS_NEG_ZERO;
|
|
|
|
|
|
2019-08-01 11:51:36 -07:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case nir_op_flrp: {
|
|
|
|
|
/* Decompose the flrp to first + third * (second + -first) */
|
nir: rewrite fp range analysis as a fp class analysis
Knowing if a value is not larger than one helps proving finite
results of fmul/fadd and will allow skipping/creating more fsat.
Knowing that a value is larger than one helps proving non zero
results of fmul.
Separating positive and negative zero also has advantages when
signed zero correctness is required.
Foz-DB Navi48:
Totals from 1344 (1.63% of 82636) affected shaders:
Instrs: 5319389 -> 5312280 (-0.13%); split: -0.14%, +0.01%
CodeSize: 29702516 -> 29665684 (-0.12%); split: -0.13%, +0.01%
Latency: 40694344 -> 40694545 (+0.00%); split: -0.01%, +0.02%
InvThroughput: 7481192 -> 7480403 (-0.01%); split: -0.02%, +0.01%
VClause: 121947 -> 121946 (-0.00%); split: -0.00%, +0.00%
SClause: 104972 -> 104923 (-0.05%); split: -0.05%, +0.00%
Copies: 371098 -> 371092 (-0.00%); split: -0.02%, +0.02%
Branches: 122929 -> 122919 (-0.01%); split: -0.01%, +0.00%
PreSGPRs: 82506 -> 82510 (+0.00%); split: -0.00%, +0.01%
PreVGPRs: 79175 -> 79168 (-0.01%)
VALU: 2906718 -> 2904777 (-0.07%); split: -0.07%, +0.00%
SALU: 726256 -> 723454 (-0.39%); split: -0.39%, +0.00%
VMEM: 205021 -> 205016 (-0.00%)
SMEM: 163972 -> 163916 (-0.03%)
VOPD: 303354 -> 303298 (-0.02%); split: +0.02%, -0.04%
Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/39987>
2026-02-08 23:03:16 +01:00
|
|
|
fp_class_mask inner_fadd_class =
|
|
|
|
|
fadd_fp_class(src_res[1], fneg_fp_class(src_res[0]));
|
2019-08-01 11:51:36 -07:00
|
|
|
|
nir: rewrite fp range analysis as a fp class analysis
Knowing if a value is not larger than one helps proving finite
results of fmul/fadd and will allow skipping/creating more fsat.
Knowing that a value is larger than one helps proving non zero
results of fmul.
Separating positive and negative zero also has advantages when
signed zero correctness is required.
Foz-DB Navi48:
Totals from 1344 (1.63% of 82636) affected shaders:
Instrs: 5319389 -> 5312280 (-0.13%); split: -0.14%, +0.01%
CodeSize: 29702516 -> 29665684 (-0.12%); split: -0.13%, +0.01%
Latency: 40694344 -> 40694545 (+0.00%); split: -0.01%, +0.02%
InvThroughput: 7481192 -> 7480403 (-0.01%); split: -0.02%, +0.01%
VClause: 121947 -> 121946 (-0.00%); split: -0.00%, +0.00%
SClause: 104972 -> 104923 (-0.05%); split: -0.05%, +0.00%
Copies: 371098 -> 371092 (-0.00%); split: -0.02%, +0.02%
Branches: 122929 -> 122919 (-0.01%); split: -0.01%, +0.00%
PreSGPRs: 82506 -> 82510 (+0.00%); split: -0.00%, +0.01%
PreVGPRs: 79175 -> 79168 (-0.01%)
VALU: 2906718 -> 2904777 (-0.07%); split: -0.07%, +0.00%
SALU: 726256 -> 723454 (-0.39%); split: -0.39%, +0.00%
VMEM: 205021 -> 205016 (-0.00%)
SMEM: 163972 -> 163916 (-0.03%)
VOPD: 303354 -> 303298 (-0.02%); split: +0.02%, -0.04%
Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/39987>
2026-02-08 23:03:16 +01:00
|
|
|
fp_class_mask fmul_class =
|
|
|
|
|
fmul_fp_class(src_res[2], inner_fadd_class, false, false, false);
|
2019-08-01 11:51:36 -07:00
|
|
|
|
nir: rewrite fp range analysis as a fp class analysis
Knowing if a value is not larger than one helps proving finite
results of fmul/fadd and will allow skipping/creating more fsat.
Knowing that a value is larger than one helps proving non zero
results of fmul.
Separating positive and negative zero also has advantages when
signed zero correctness is required.
Foz-DB Navi48:
Totals from 1344 (1.63% of 82636) affected shaders:
Instrs: 5319389 -> 5312280 (-0.13%); split: -0.14%, +0.01%
CodeSize: 29702516 -> 29665684 (-0.12%); split: -0.13%, +0.01%
Latency: 40694344 -> 40694545 (+0.00%); split: -0.01%, +0.02%
InvThroughput: 7481192 -> 7480403 (-0.01%); split: -0.02%, +0.01%
VClause: 121947 -> 121946 (-0.00%); split: -0.00%, +0.00%
SClause: 104972 -> 104923 (-0.05%); split: -0.05%, +0.00%
Copies: 371098 -> 371092 (-0.00%); split: -0.02%, +0.02%
Branches: 122929 -> 122919 (-0.01%); split: -0.01%, +0.00%
PreSGPRs: 82506 -> 82510 (+0.00%); split: -0.00%, +0.01%
PreVGPRs: 79175 -> 79168 (-0.01%)
VALU: 2906718 -> 2904777 (-0.07%); split: -0.07%, +0.00%
SALU: 726256 -> 723454 (-0.39%); split: -0.39%, +0.00%
VMEM: 205021 -> 205016 (-0.00%)
SMEM: 163972 -> 163916 (-0.03%)
VOPD: 303354 -> 303298 (-0.02%); split: +0.02%, -0.04%
Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/39987>
2026-02-08 23:03:16 +01:00
|
|
|
r = fadd_fp_class(src_res[0], fmul_class);
|
|
|
|
|
|
|
|
|
|
/* Various cases can result in NaN, so assume the worst. */
|
|
|
|
|
r |= FP_CLASS_NAN;
|
2019-08-01 11:51:36 -07:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-23 09:48:43 +08:00
|
|
|
default:
|
nir: rewrite fp range analysis as a fp class analysis
Knowing if a value is not larger than one helps proving finite
results of fmul/fadd and will allow skipping/creating more fsat.
Knowing that a value is larger than one helps proving non zero
results of fmul.
Separating positive and negative zero also has advantages when
signed zero correctness is required.
Foz-DB Navi48:
Totals from 1344 (1.63% of 82636) affected shaders:
Instrs: 5319389 -> 5312280 (-0.13%); split: -0.14%, +0.01%
CodeSize: 29702516 -> 29665684 (-0.12%); split: -0.13%, +0.01%
Latency: 40694344 -> 40694545 (+0.00%); split: -0.01%, +0.02%
InvThroughput: 7481192 -> 7480403 (-0.01%); split: -0.02%, +0.01%
VClause: 121947 -> 121946 (-0.00%); split: -0.00%, +0.00%
SClause: 104972 -> 104923 (-0.05%); split: -0.05%, +0.00%
Copies: 371098 -> 371092 (-0.00%); split: -0.02%, +0.02%
Branches: 122929 -> 122919 (-0.01%); split: -0.01%, +0.00%
PreSGPRs: 82506 -> 82510 (+0.00%); split: -0.00%, +0.01%
PreVGPRs: 79175 -> 79168 (-0.01%)
VALU: 2906718 -> 2904777 (-0.07%); split: -0.07%, +0.00%
SALU: 726256 -> 723454 (-0.39%); split: -0.39%, +0.00%
VMEM: 205021 -> 205016 (-0.00%)
SMEM: 163972 -> 163916 (-0.03%)
VOPD: 303354 -> 303298 (-0.02%); split: +0.02%, -0.04%
Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/39987>
2026-02-08 23:03:16 +01:00
|
|
|
r = FP_CLASS_UNKNOWN;
|
2018-01-23 09:48:43 +08:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
nir: rewrite fp range analysis as a fp class analysis
Knowing if a value is not larger than one helps proving finite
results of fmul/fadd and will allow skipping/creating more fsat.
Knowing that a value is larger than one helps proving non zero
results of fmul.
Separating positive and negative zero also has advantages when
signed zero correctness is required.
Foz-DB Navi48:
Totals from 1344 (1.63% of 82636) affected shaders:
Instrs: 5319389 -> 5312280 (-0.13%); split: -0.14%, +0.01%
CodeSize: 29702516 -> 29665684 (-0.12%); split: -0.13%, +0.01%
Latency: 40694344 -> 40694545 (+0.00%); split: -0.01%, +0.02%
InvThroughput: 7481192 -> 7480403 (-0.01%); split: -0.02%, +0.01%
VClause: 121947 -> 121946 (-0.00%); split: -0.00%, +0.00%
SClause: 104972 -> 104923 (-0.05%); split: -0.05%, +0.00%
Copies: 371098 -> 371092 (-0.00%); split: -0.02%, +0.02%
Branches: 122929 -> 122919 (-0.01%); split: -0.01%, +0.00%
PreSGPRs: 82506 -> 82510 (+0.00%); split: -0.00%, +0.01%
PreVGPRs: 79175 -> 79168 (-0.01%)
VALU: 2906718 -> 2904777 (-0.07%); split: -0.07%, +0.00%
SALU: 726256 -> 723454 (-0.39%); split: -0.39%, +0.00%
VMEM: 205021 -> 205016 (-0.00%)
SMEM: 163972 -> 163916 (-0.03%)
VOPD: 303354 -> 303298 (-0.02%); split: +0.02%, -0.04%
Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/39987>
2026-02-08 23:03:16 +01:00
|
|
|
if (nir_alu_type_get_base_type(nir_op_infos[alu->op].output_type) == nir_type_float)
|
|
|
|
|
r = handle_sz(alu, r);
|
2018-01-23 09:48:43 +08:00
|
|
|
|
nir: rewrite fp range analysis as a fp class analysis
Knowing if a value is not larger than one helps proving finite
results of fmul/fadd and will allow skipping/creating more fsat.
Knowing that a value is larger than one helps proving non zero
results of fmul.
Separating positive and negative zero also has advantages when
signed zero correctness is required.
Foz-DB Navi48:
Totals from 1344 (1.63% of 82636) affected shaders:
Instrs: 5319389 -> 5312280 (-0.13%); split: -0.14%, +0.01%
CodeSize: 29702516 -> 29665684 (-0.12%); split: -0.13%, +0.01%
Latency: 40694344 -> 40694545 (+0.00%); split: -0.01%, +0.02%
InvThroughput: 7481192 -> 7480403 (-0.01%); split: -0.02%, +0.01%
VClause: 121947 -> 121946 (-0.00%); split: -0.00%, +0.00%
SClause: 104972 -> 104923 (-0.05%); split: -0.05%, +0.00%
Copies: 371098 -> 371092 (-0.00%); split: -0.02%, +0.02%
Branches: 122929 -> 122919 (-0.01%); split: -0.01%, +0.00%
PreSGPRs: 82506 -> 82510 (+0.00%); split: -0.00%, +0.01%
PreVGPRs: 79175 -> 79168 (-0.01%)
VALU: 2906718 -> 2904777 (-0.07%); split: -0.07%, +0.00%
SALU: 726256 -> 723454 (-0.39%); split: -0.39%, +0.00%
VMEM: 205021 -> 205016 (-0.00%)
SMEM: 163972 -> 163916 (-0.03%)
VOPD: 303354 -> 303298 (-0.02%); split: +0.02%, -0.04%
Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/39987>
2026-02-08 23:03:16 +01:00
|
|
|
assert((r & FP_CLASS_UNKNOWN) == r);
|
|
|
|
|
assert((r & ~FP_CLASS_NON_INTEGRAL) != 0);
|
|
|
|
|
assert(!(r & FP_CLASS_NON_INTEGRAL) || (r & (FP_CLASS_LT_NEG_ONE | FP_CLASS_LT_ZERO_GT_NEG_ONE |
|
|
|
|
|
FP_CLASS_GT_POS_ONE | FP_CLASS_GT_ZERO_LT_POS_ONE)));
|
2020-07-02 18:18:09 -07:00
|
|
|
|
nir: rewrite fp range analysis as a fp class analysis
Knowing if a value is not larger than one helps proving finite
results of fmul/fadd and will allow skipping/creating more fsat.
Knowing that a value is larger than one helps proving non zero
results of fmul.
Separating positive and negative zero also has advantages when
signed zero correctness is required.
Foz-DB Navi48:
Totals from 1344 (1.63% of 82636) affected shaders:
Instrs: 5319389 -> 5312280 (-0.13%); split: -0.14%, +0.01%
CodeSize: 29702516 -> 29665684 (-0.12%); split: -0.13%, +0.01%
Latency: 40694344 -> 40694545 (+0.00%); split: -0.01%, +0.02%
InvThroughput: 7481192 -> 7480403 (-0.01%); split: -0.02%, +0.01%
VClause: 121947 -> 121946 (-0.00%); split: -0.00%, +0.00%
SClause: 104972 -> 104923 (-0.05%); split: -0.05%, +0.00%
Copies: 371098 -> 371092 (-0.00%); split: -0.02%, +0.02%
Branches: 122929 -> 122919 (-0.01%); split: -0.01%, +0.00%
PreSGPRs: 82506 -> 82510 (+0.00%); split: -0.00%, +0.01%
PreVGPRs: 79175 -> 79168 (-0.01%)
VALU: 2906718 -> 2904777 (-0.07%); split: -0.07%, +0.00%
SALU: 726256 -> 723454 (-0.39%); split: -0.39%, +0.00%
VMEM: 205021 -> 205016 (-0.00%)
SMEM: 163972 -> 163916 (-0.03%)
VOPD: 303354 -> 303298 (-0.02%); split: +0.02%, -0.04%
Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/39987>
2026-02-08 23:03:16 +01:00
|
|
|
*result = r;
|
2018-01-23 09:48:43 +08:00
|
|
|
}
|
|
|
|
|
|
nir: rewrite fp range analysis as a fp class analysis
Knowing if a value is not larger than one helps proving finite
results of fmul/fadd and will allow skipping/creating more fsat.
Knowing that a value is larger than one helps proving non zero
results of fmul.
Separating positive and negative zero also has advantages when
signed zero correctness is required.
Foz-DB Navi48:
Totals from 1344 (1.63% of 82636) affected shaders:
Instrs: 5319389 -> 5312280 (-0.13%); split: -0.14%, +0.01%
CodeSize: 29702516 -> 29665684 (-0.12%); split: -0.13%, +0.01%
Latency: 40694344 -> 40694545 (+0.00%); split: -0.01%, +0.02%
InvThroughput: 7481192 -> 7480403 (-0.01%); split: -0.02%, +0.01%
VClause: 121947 -> 121946 (-0.00%); split: -0.00%, +0.00%
SClause: 104972 -> 104923 (-0.05%); split: -0.05%, +0.00%
Copies: 371098 -> 371092 (-0.00%); split: -0.02%, +0.02%
Branches: 122929 -> 122919 (-0.01%); split: -0.01%, +0.00%
PreSGPRs: 82506 -> 82510 (+0.00%); split: -0.00%, +0.01%
PreVGPRs: 79175 -> 79168 (-0.01%)
VALU: 2906718 -> 2904777 (-0.07%); split: -0.07%, +0.00%
SALU: 726256 -> 723454 (-0.39%); split: -0.39%, +0.00%
VMEM: 205021 -> 205016 (-0.00%)
SMEM: 163972 -> 163916 (-0.03%)
VOPD: 303354 -> 303298 (-0.02%); split: +0.02%, -0.04%
Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/39987>
2026-02-08 23:03:16 +01:00
|
|
|
fp_class_mask
|
|
|
|
|
nir_analyze_fp_class(nir_fp_analysis_state *fp_state, const nir_def *def)
|
2018-01-23 09:48:43 +08:00
|
|
|
{
|
2023-02-14 21:38:41 +00:00
|
|
|
struct fp_query query_alloc[64];
|
|
|
|
|
uint32_t result_alloc[64];
|
|
|
|
|
|
|
|
|
|
struct analysis_state state;
|
2026-03-02 15:44:38 +00:00
|
|
|
state.range_ht = fp_state;
|
2023-02-14 21:38:41 +00:00
|
|
|
util_dynarray_init_from_stack(&state.query_stack, query_alloc, sizeof(query_alloc));
|
|
|
|
|
util_dynarray_init_from_stack(&state.result_stack, result_alloc, sizeof(result_alloc));
|
|
|
|
|
state.query_size = sizeof(struct fp_query);
|
|
|
|
|
state.get_key = &get_fp_key;
|
2026-03-02 15:44:38 +00:00
|
|
|
state.lookup = &fp_lookup;
|
|
|
|
|
state.insert = &fp_insert;
|
2023-02-14 21:38:41 +00:00
|
|
|
state.process_query = &process_fp_query;
|
|
|
|
|
|
2026-02-07 22:36:25 +01:00
|
|
|
push_fp_query(&state, def);
|
2023-02-14 21:38:41 +00:00
|
|
|
|
nir: rewrite fp range analysis as a fp class analysis
Knowing if a value is not larger than one helps proving finite
results of fmul/fadd and will allow skipping/creating more fsat.
Knowing that a value is larger than one helps proving non zero
results of fmul.
Separating positive and negative zero also has advantages when
signed zero correctness is required.
Foz-DB Navi48:
Totals from 1344 (1.63% of 82636) affected shaders:
Instrs: 5319389 -> 5312280 (-0.13%); split: -0.14%, +0.01%
CodeSize: 29702516 -> 29665684 (-0.12%); split: -0.13%, +0.01%
Latency: 40694344 -> 40694545 (+0.00%); split: -0.01%, +0.02%
InvThroughput: 7481192 -> 7480403 (-0.01%); split: -0.02%, +0.01%
VClause: 121947 -> 121946 (-0.00%); split: -0.00%, +0.00%
SClause: 104972 -> 104923 (-0.05%); split: -0.05%, +0.00%
Copies: 371098 -> 371092 (-0.00%); split: -0.02%, +0.02%
Branches: 122929 -> 122919 (-0.01%); split: -0.01%, +0.00%
PreSGPRs: 82506 -> 82510 (+0.00%); split: -0.00%, +0.01%
PreVGPRs: 79175 -> 79168 (-0.01%)
VALU: 2906718 -> 2904777 (-0.07%); split: -0.07%, +0.00%
SALU: 726256 -> 723454 (-0.39%); split: -0.39%, +0.00%
VMEM: 205021 -> 205016 (-0.00%)
SMEM: 163972 -> 163916 (-0.03%)
VOPD: 303354 -> 303298 (-0.02%); split: +0.02%, -0.04%
Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/39987>
2026-02-08 23:03:16 +01:00
|
|
|
return perform_analysis(&state);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct fp_result_range
|
|
|
|
|
nir_analyze_fp_range(nir_fp_analysis_state *fp_state, const nir_def *def)
|
|
|
|
|
{
|
|
|
|
|
fp_class_mask fp_class = nir_analyze_fp_class(fp_state, def);
|
|
|
|
|
|
|
|
|
|
struct fp_result_range result = {
|
|
|
|
|
unknown,
|
|
|
|
|
!(fp_class & FP_CLASS_NON_INTEGRAL),
|
|
|
|
|
!(fp_class & FP_CLASS_NAN),
|
|
|
|
|
!(fp_class & (FP_CLASS_NAN | FP_CLASS_ANY_INF)),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (!(fp_class & (FP_CLASS_ANY_NEG | FP_CLASS_ANY_POS)))
|
|
|
|
|
result.range = eq_zero;
|
|
|
|
|
else if (!(fp_class & (FP_CLASS_ANY_POS | FP_CLASS_ANY_ZERO)))
|
|
|
|
|
result.range = lt_zero;
|
|
|
|
|
else if (!(fp_class & FP_CLASS_ANY_POS))
|
|
|
|
|
result.range = le_zero;
|
|
|
|
|
else if (!(fp_class & (FP_CLASS_ANY_NEG | FP_CLASS_ANY_ZERO)))
|
|
|
|
|
result.range = gt_zero;
|
|
|
|
|
else if (!(fp_class & FP_CLASS_ANY_NEG))
|
|
|
|
|
result.range = ge_zero;
|
|
|
|
|
else if (!(fp_class & FP_CLASS_ANY_ZERO))
|
|
|
|
|
result.range = ne_zero;
|
|
|
|
|
|
|
|
|
|
return result;
|
2018-01-23 09:48:43 +08:00
|
|
|
}
|
2019-11-12 17:51:19 +00:00
|
|
|
|
2026-03-02 15:32:41 +00:00
|
|
|
nir_fp_analysis_state
|
|
|
|
|
nir_create_fp_analysis_state(nir_function_impl *impl)
|
|
|
|
|
{
|
2026-03-02 15:44:38 +00:00
|
|
|
nir_fp_analysis_state state;
|
|
|
|
|
state.impl = impl;
|
|
|
|
|
/* Over-allocate the bitset, so that we can keep using the allocated table memory
|
|
|
|
|
* even when new SSA values are added. */
|
|
|
|
|
state.size = BITSET_BYTES(impl->ssa_alloc + impl->ssa_alloc / 4u);
|
|
|
|
|
state.max = -1;
|
|
|
|
|
state.bitset = calloc(state.size, 1);
|
|
|
|
|
util_sparse_array_init(&state.arr, 4, 256);
|
|
|
|
|
return state;
|
2026-03-02 15:32:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
nir_invalidate_fp_analysis_state(nir_fp_analysis_state *state)
|
|
|
|
|
{
|
2026-03-02 15:44:38 +00:00
|
|
|
if (BITSET_BYTES(state->impl->ssa_alloc) > state->size) {
|
|
|
|
|
state->size = BITSET_BYTES(state->impl->ssa_alloc + state->impl->ssa_alloc / 4u);
|
|
|
|
|
free(state->bitset);
|
|
|
|
|
state->bitset = calloc(state->size, 1);
|
|
|
|
|
} else if (state->max >= 0) {
|
|
|
|
|
memset(state->bitset, 0, BITSET_BYTES(state->max + 1));
|
|
|
|
|
}
|
|
|
|
|
state->max = -1;
|
2026-03-02 15:32:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
nir_free_fp_analysis_state(nir_fp_analysis_state *state)
|
|
|
|
|
{
|
2026-03-02 15:44:38 +00:00
|
|
|
util_sparse_array_finish(&state->arr);
|
|
|
|
|
free(state->bitset);
|
2026-03-02 15:32:41 +00:00
|
|
|
}
|
|
|
|
|
|
2023-08-08 12:00:35 -05:00
|
|
|
static uint32_t
|
|
|
|
|
bitmask(uint32_t size)
|
|
|
|
|
{
|
2019-11-12 17:51:19 +00:00
|
|
|
return size >= 32 ? 0xffffffffu : ((uint32_t)1 << size) - 1u;
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-08 12:00:35 -05:00
|
|
|
static uint64_t
|
|
|
|
|
mul_clamp(uint32_t a, uint32_t b)
|
2019-11-12 17:51:19 +00:00
|
|
|
{
|
|
|
|
|
if (a != 0 && (a * b) / a != b)
|
|
|
|
|
return (uint64_t)UINT32_MAX + 1;
|
|
|
|
|
else
|
|
|
|
|
return a * b;
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-24 10:52:56 +00:00
|
|
|
/* recursively gather at most "buf_size" phi/bcsel sources */
|
2019-11-12 17:51:19 +00:00
|
|
|
static unsigned
|
2023-08-12 16:17:15 -04:00
|
|
|
search_phi_bcsel(nir_scalar scalar, nir_scalar *buf, unsigned buf_size, struct set *visited)
|
2019-11-12 17:51:19 +00:00
|
|
|
{
|
|
|
|
|
if (_mesa_set_search(visited, scalar.def))
|
|
|
|
|
return 0;
|
|
|
|
|
_mesa_set_add(visited, scalar.def);
|
|
|
|
|
|
2025-11-07 21:38:36 +08:00
|
|
|
if (nir_def_instr_type(scalar.def) == nir_instr_type_phi) {
|
2025-07-31 09:49:36 -04:00
|
|
|
nir_phi_instr *phi = nir_def_as_phi(scalar.def);
|
2019-11-12 17:51:19 +00:00
|
|
|
unsigned num_sources_left = exec_list_length(&phi->srcs);
|
2020-11-24 10:52:56 +00:00
|
|
|
if (buf_size >= num_sources_left) {
|
|
|
|
|
unsigned total_added = 0;
|
|
|
|
|
nir_foreach_phi_src(src, phi) {
|
2020-11-24 14:53:04 +00:00
|
|
|
num_sources_left--;
|
2023-08-15 10:07:24 -05:00
|
|
|
unsigned added = search_phi_bcsel(nir_get_scalar(src->src.ssa, scalar.comp),
|
2023-08-08 12:00:35 -05:00
|
|
|
buf + total_added, buf_size - num_sources_left, visited);
|
2020-11-24 14:53:04 +00:00
|
|
|
assert(added <= buf_size);
|
2020-11-24 10:52:56 +00:00
|
|
|
buf_size -= added;
|
|
|
|
|
total_added += added;
|
|
|
|
|
}
|
|
|
|
|
return total_added;
|
2019-11-12 17:51:19 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-12 16:17:15 -04:00
|
|
|
if (nir_scalar_is_alu(scalar)) {
|
|
|
|
|
nir_op op = nir_scalar_alu_op(scalar);
|
2019-11-12 17:51:19 +00:00
|
|
|
|
|
|
|
|
if ((op == nir_op_bcsel || op == nir_op_b32csel) && buf_size >= 2) {
|
2023-08-12 16:17:15 -04:00
|
|
|
nir_scalar src1 = nir_scalar_chase_alu_src(scalar, 1);
|
|
|
|
|
nir_scalar src2 = nir_scalar_chase_alu_src(scalar, 2);
|
2019-11-12 17:51:19 +00:00
|
|
|
|
2023-07-03 18:36:28 +01:00
|
|
|
unsigned added = search_phi_bcsel(src1, buf, buf_size - 1, visited);
|
2019-11-12 17:51:19 +00:00
|
|
|
buf_size -= added;
|
2023-07-03 18:36:28 +01:00
|
|
|
added += search_phi_bcsel(src2, buf + added, buf_size, visited);
|
2019-11-12 17:51:19 +00:00
|
|
|
return added;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
buf[0] = scalar;
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-14 17:43:57 +02:00
|
|
|
static uint32_t
|
|
|
|
|
get_max_workgroup_invocations(nir_shader *nir)
|
|
|
|
|
{
|
|
|
|
|
if (!nir->options || !nir->options->max_workgroup_invocations)
|
|
|
|
|
return UINT16_MAX;
|
2022-11-17 12:47:59 -08:00
|
|
|
|
2025-09-14 17:43:57 +02:00
|
|
|
return nir->options->max_workgroup_invocations;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static uint32_t
|
|
|
|
|
get_max_workgroup_count(nir_shader *nir, unsigned dim)
|
|
|
|
|
{
|
2022-11-17 12:47:59 -08:00
|
|
|
/* max_workgroup_count represents the maximum compute shader / kernel
|
|
|
|
|
* dispatchable work size. On most hardware, this is essentially
|
|
|
|
|
* unbounded. On some hardware max_workgroup_count[1] and
|
|
|
|
|
* max_workgroup_count[2] may be smaller.
|
|
|
|
|
*/
|
2025-09-14 17:43:57 +02:00
|
|
|
if (!nir->options || !nir->options->max_workgroup_count[dim])
|
|
|
|
|
return UINT32_MAX;
|
|
|
|
|
|
|
|
|
|
return nir->options->max_workgroup_count[dim];
|
|
|
|
|
}
|
2021-03-11 12:43:56 +01:00
|
|
|
|
2025-08-13 10:56:51 +01:00
|
|
|
struct scalar_query {
|
2023-02-10 16:24:39 +00:00
|
|
|
struct analysis_query head;
|
2023-08-12 16:17:15 -04:00
|
|
|
nir_scalar scalar;
|
2023-02-10 16:24:39 +00:00
|
|
|
};
|
2019-11-12 17:51:19 +00:00
|
|
|
|
2023-02-10 16:24:39 +00:00
|
|
|
static void
|
2025-08-13 10:56:51 +01:00
|
|
|
push_scalar_query(struct analysis_state *state, nir_scalar scalar)
|
2023-02-10 16:24:39 +00:00
|
|
|
{
|
2025-08-13 10:56:51 +01:00
|
|
|
struct scalar_query *pushed_q = push_analysis_query(state, sizeof(struct scalar_query));
|
2023-02-10 16:24:39 +00:00
|
|
|
pushed_q->scalar = scalar;
|
|
|
|
|
}
|
2019-11-12 17:51:19 +00:00
|
|
|
|
2026-03-02 16:20:26 +00:00
|
|
|
static uint32_t
|
2025-08-13 10:56:51 +01:00
|
|
|
get_scalar_key(struct analysis_query *q)
|
2023-02-10 16:24:39 +00:00
|
|
|
{
|
2025-08-13 10:56:51 +01:00
|
|
|
nir_scalar scalar = ((struct scalar_query *)q)->scalar;
|
2019-11-12 17:51:19 +00:00
|
|
|
/* keys can't be 0, so we have to add 1 to the index */
|
2023-02-10 16:24:39 +00:00
|
|
|
unsigned shift_amount = ffs(NIR_MAX_VEC_COMPONENTS) - 1;
|
2023-08-12 16:17:15 -04:00
|
|
|
return nir_scalar_is_const(scalar)
|
2026-03-02 16:20:26 +00:00
|
|
|
? UINT32_MAX
|
|
|
|
|
: ((scalar.def->index + 1) << shift_amount) | scalar.comp;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static bool
|
|
|
|
|
scalar_lookup(void *table, uint32_t key, uint32_t *value)
|
|
|
|
|
{
|
|
|
|
|
struct hash_table *ht = table;
|
|
|
|
|
struct hash_entry *he = _mesa_hash_table_search(ht, (void *)(uintptr_t)key);
|
|
|
|
|
if (he)
|
|
|
|
|
*value = (uintptr_t)he->data;
|
|
|
|
|
return he != NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
scalar_insert(void *table, uint32_t key, uint32_t value)
|
|
|
|
|
{
|
|
|
|
|
struct hash_table *ht = table;
|
|
|
|
|
_mesa_hash_table_insert(ht, (void *)(uintptr_t)key, (void *)(uintptr_t)value);
|
2023-02-10 16:24:39 +00:00
|
|
|
}
|
2021-06-09 11:00:22 +02:00
|
|
|
|
2023-02-10 16:24:39 +00:00
|
|
|
static void
|
2025-08-13 10:56:51 +01:00
|
|
|
get_intrinsic_uub(struct analysis_state *state, struct scalar_query q, uint32_t *result,
|
2023-02-10 16:24:39 +00:00
|
|
|
const uint32_t *src)
|
|
|
|
|
{
|
|
|
|
|
nir_shader *shader = state->shader;
|
|
|
|
|
|
2025-07-31 09:49:36 -04:00
|
|
|
nir_intrinsic_instr *intrin = nir_def_as_intrinsic(q.scalar.def);
|
2023-02-10 16:24:39 +00:00
|
|
|
switch (intrin->intrinsic) {
|
|
|
|
|
case nir_intrinsic_load_local_invocation_index:
|
|
|
|
|
/* The local invocation index is used under the hood by RADV for
|
|
|
|
|
* some non-compute-like shaders (eg. LS and NGG). These technically
|
|
|
|
|
* run in workgroups on the HW, even though this fact is not exposed
|
|
|
|
|
* by the API.
|
|
|
|
|
* They can safely use the same code path here as variable sized
|
|
|
|
|
* compute-like shader stages.
|
|
|
|
|
*/
|
2025-08-05 16:50:43 +08:00
|
|
|
if (!mesa_shader_stage_uses_workgroup(shader->info.stage) ||
|
2023-02-10 16:24:39 +00:00
|
|
|
shader->info.workgroup_size_variable) {
|
2025-09-14 17:43:57 +02:00
|
|
|
*result = get_max_workgroup_invocations(shader) - 1;
|
2023-02-10 16:24:39 +00:00
|
|
|
} else {
|
|
|
|
|
*result = (shader->info.workgroup_size[0] *
|
|
|
|
|
shader->info.workgroup_size[1] *
|
2023-08-08 12:00:35 -05:00
|
|
|
shader->info.workgroup_size[2]) -
|
|
|
|
|
1u;
|
2021-06-09 11:00:22 +02:00
|
|
|
}
|
2023-02-10 16:24:39 +00:00
|
|
|
break;
|
|
|
|
|
case nir_intrinsic_load_local_invocation_id:
|
|
|
|
|
if (shader->info.workgroup_size_variable)
|
2025-09-14 17:43:57 +02:00
|
|
|
*result = get_max_workgroup_invocations(shader) - 1u;
|
2023-02-10 16:24:39 +00:00
|
|
|
else
|
|
|
|
|
*result = shader->info.workgroup_size[q.scalar.comp] - 1u;
|
|
|
|
|
break;
|
|
|
|
|
case nir_intrinsic_load_workgroup_id:
|
2025-09-14 17:43:57 +02:00
|
|
|
*result = get_max_workgroup_count(shader, q.scalar.comp) - 1u;
|
2023-02-10 16:24:39 +00:00
|
|
|
break;
|
|
|
|
|
case nir_intrinsic_load_num_workgroups:
|
2025-09-14 17:43:57 +02:00
|
|
|
*result = get_max_workgroup_count(shader, q.scalar.comp);
|
2023-02-10 16:24:39 +00:00
|
|
|
break;
|
|
|
|
|
case nir_intrinsic_load_global_invocation_id:
|
|
|
|
|
if (shader->info.workgroup_size_variable) {
|
2025-09-14 17:43:57 +02:00
|
|
|
*result = mul_clamp(get_max_workgroup_invocations(shader),
|
|
|
|
|
get_max_workgroup_count(shader, q.scalar.comp)) -
|
2023-08-08 12:00:35 -05:00
|
|
|
1u;
|
2023-02-10 16:24:39 +00:00
|
|
|
} else {
|
|
|
|
|
*result = (shader->info.workgroup_size[q.scalar.comp] *
|
2025-09-14 17:43:57 +02:00
|
|
|
get_max_workgroup_count(shader, q.scalar.comp)) -
|
2023-08-08 12:00:35 -05:00
|
|
|
1u;
|
2023-02-10 16:24:39 +00:00
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case nir_intrinsic_load_invocation_id:
|
|
|
|
|
if (shader->info.stage == MESA_SHADER_TESS_CTRL)
|
|
|
|
|
*result = shader->info.tess.tcs_vertices_out
|
2023-08-08 12:00:35 -05:00
|
|
|
? (shader->info.tess.tcs_vertices_out - 1)
|
|
|
|
|
: 511; /* Generous maximum output patch size of 512 */
|
2023-02-10 16:24:39 +00:00
|
|
|
break;
|
|
|
|
|
case nir_intrinsic_load_subgroup_invocation:
|
|
|
|
|
case nir_intrinsic_first_invocation:
|
2025-09-14 17:09:45 +02:00
|
|
|
*result = shader->info.max_subgroup_size - 1;
|
2023-02-10 16:24:39 +00:00
|
|
|
break;
|
|
|
|
|
case nir_intrinsic_mbcnt_amd: {
|
|
|
|
|
if (!q.head.pushed_queries) {
|
2025-08-13 10:56:51 +01:00
|
|
|
push_scalar_query(state, nir_get_scalar(intrin->src[1].ssa, 0));
|
2023-02-10 16:24:39 +00:00
|
|
|
return;
|
|
|
|
|
} else {
|
2025-09-14 17:09:45 +02:00
|
|
|
uint32_t src0 = shader->info.max_subgroup_size - 1;
|
2023-02-10 16:24:39 +00:00
|
|
|
uint32_t src1 = src[0];
|
|
|
|
|
if (src0 + src1 >= src0) /* check overflow */
|
|
|
|
|
*result = src0 + src1;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case nir_intrinsic_load_subgroup_size:
|
2025-09-14 17:09:45 +02:00
|
|
|
if (shader->info.api_subgroup_size)
|
|
|
|
|
*result = shader->info.api_subgroup_size;
|
|
|
|
|
else
|
|
|
|
|
*result = shader->info.max_subgroup_size;
|
2023-02-10 16:24:39 +00:00
|
|
|
break;
|
|
|
|
|
case nir_intrinsic_load_subgroup_id:
|
|
|
|
|
case nir_intrinsic_load_num_subgroups: {
|
2025-09-14 17:43:57 +02:00
|
|
|
uint32_t workgroup_size = get_max_workgroup_invocations(shader);
|
2025-08-05 16:50:43 +08:00
|
|
|
if (mesa_shader_stage_uses_workgroup(shader->info.stage) &&
|
2023-02-10 16:24:39 +00:00
|
|
|
!shader->info.workgroup_size_variable) {
|
|
|
|
|
workgroup_size = shader->info.workgroup_size[0] *
|
|
|
|
|
shader->info.workgroup_size[1] *
|
|
|
|
|
shader->info.workgroup_size[2];
|
|
|
|
|
}
|
2025-09-14 17:09:45 +02:00
|
|
|
*result = DIV_ROUND_UP(workgroup_size, shader->info.min_subgroup_size);
|
2023-02-10 16:24:39 +00:00
|
|
|
if (intrin->intrinsic == nir_intrinsic_load_subgroup_id)
|
|
|
|
|
(*result)--;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case nir_intrinsic_reduce:
|
|
|
|
|
case nir_intrinsic_inclusive_scan:
|
|
|
|
|
case nir_intrinsic_exclusive_scan: {
|
|
|
|
|
nir_op op = nir_intrinsic_reduction_op(intrin);
|
2025-08-20 12:29:03 +02:00
|
|
|
|
2025-08-20 12:43:07 +02:00
|
|
|
switch (op) {
|
|
|
|
|
case nir_op_umin:
|
|
|
|
|
case nir_op_umax:
|
|
|
|
|
case nir_op_imax:
|
|
|
|
|
case nir_op_imin:
|
|
|
|
|
case nir_op_iand:
|
|
|
|
|
case nir_op_ior:
|
|
|
|
|
case nir_op_ixor:
|
|
|
|
|
case nir_op_iadd:
|
2023-02-10 16:24:39 +00:00
|
|
|
if (!q.head.pushed_queries) {
|
2025-08-13 10:56:51 +01:00
|
|
|
push_scalar_query(state, nir_get_scalar(intrin->src[0].ssa, q.scalar.comp));
|
2023-02-10 16:24:39 +00:00
|
|
|
return;
|
2019-11-12 17:51:19 +00:00
|
|
|
}
|
2025-08-20 12:43:07 +02:00
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unsigned bit_size = q.scalar.def->bit_size;
|
|
|
|
|
bool exclusive = intrin->intrinsic == nir_intrinsic_exclusive_scan;
|
|
|
|
|
switch (op) {
|
|
|
|
|
case nir_op_umin:
|
|
|
|
|
case nir_op_umax:
|
|
|
|
|
case nir_op_imax:
|
|
|
|
|
case nir_op_imin:
|
|
|
|
|
case nir_op_iand:
|
|
|
|
|
*result = src[0];
|
|
|
|
|
break;
|
|
|
|
|
case nir_op_ior:
|
|
|
|
|
case nir_op_ixor:
|
|
|
|
|
*result = bitmask(util_last_bit64(src[0]));
|
|
|
|
|
break;
|
|
|
|
|
case nir_op_iadd:
|
2025-09-14 17:09:45 +02:00
|
|
|
*result = MIN2(*result, (uint64_t)src[0] * (shader->info.max_subgroup_size - exclusive));
|
2025-08-20 12:43:07 +02:00
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
UNREACHABLE("unhandled op");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (exclusive) {
|
|
|
|
|
uint32_t identity = nir_const_value_as_uint(nir_alu_binop_identity(op, bit_size), bit_size);
|
|
|
|
|
*result = MAX2(*result, identity);
|
2019-11-12 17:51:19 +00:00
|
|
|
}
|
2025-08-20 12:43:07 +02:00
|
|
|
|
2023-02-10 16:24:39 +00:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case nir_intrinsic_read_first_invocation:
|
|
|
|
|
case nir_intrinsic_read_invocation:
|
|
|
|
|
case nir_intrinsic_shuffle:
|
|
|
|
|
case nir_intrinsic_shuffle_xor:
|
|
|
|
|
case nir_intrinsic_shuffle_up:
|
|
|
|
|
case nir_intrinsic_shuffle_down:
|
|
|
|
|
case nir_intrinsic_quad_broadcast:
|
|
|
|
|
case nir_intrinsic_quad_swap_horizontal:
|
|
|
|
|
case nir_intrinsic_quad_swap_vertical:
|
|
|
|
|
case nir_intrinsic_quad_swap_diagonal:
|
|
|
|
|
case nir_intrinsic_quad_swizzle_amd:
|
|
|
|
|
case nir_intrinsic_masked_swizzle_amd:
|
|
|
|
|
if (!q.head.pushed_queries) {
|
2025-08-13 10:56:51 +01:00
|
|
|
push_scalar_query(state, nir_get_scalar(intrin->src[0].ssa, q.scalar.comp));
|
2023-02-10 16:24:39 +00:00
|
|
|
return;
|
|
|
|
|
} else {
|
|
|
|
|
*result = src[0];
|
2019-11-12 17:51:19 +00:00
|
|
|
}
|
2023-02-10 16:24:39 +00:00
|
|
|
break;
|
|
|
|
|
case nir_intrinsic_write_invocation_amd:
|
|
|
|
|
if (!q.head.pushed_queries) {
|
2025-08-13 10:56:51 +01:00
|
|
|
push_scalar_query(state, nir_get_scalar(intrin->src[0].ssa, q.scalar.comp));
|
|
|
|
|
push_scalar_query(state, nir_get_scalar(intrin->src[1].ssa, q.scalar.comp));
|
2023-02-10 16:24:39 +00:00
|
|
|
return;
|
|
|
|
|
} else {
|
|
|
|
|
*result = MAX2(src[0], src[1]);
|
2019-11-12 17:51:19 +00:00
|
|
|
}
|
2023-02-10 16:24:39 +00:00
|
|
|
break;
|
|
|
|
|
case nir_intrinsic_load_tess_rel_patch_id_amd:
|
|
|
|
|
case nir_intrinsic_load_tcs_num_patches_amd:
|
|
|
|
|
/* Very generous maximum: TCS/TES executed by largest possible workgroup */
|
2025-09-14 17:43:57 +02:00
|
|
|
*result = get_max_workgroup_invocations(shader) / MAX2(shader->info.tess.tcs_vertices_out, 1u);
|
2023-02-10 16:24:39 +00:00
|
|
|
break;
|
|
|
|
|
case nir_intrinsic_load_typed_buffer_amd: {
|
|
|
|
|
const enum pipe_format format = nir_intrinsic_format(intrin);
|
|
|
|
|
if (format == PIPE_FORMAT_NONE)
|
2021-02-15 22:01:02 +01:00
|
|
|
break;
|
2023-02-02 10:47:58 +01:00
|
|
|
|
2023-08-08 12:00:35 -05:00
|
|
|
const struct util_format_description *desc = util_format_description(format);
|
2023-02-10 16:24:39 +00:00
|
|
|
if (desc->channel[q.scalar.comp].type != UTIL_FORMAT_TYPE_UNSIGNED)
|
2022-03-23 18:44:57 +01:00
|
|
|
break;
|
2023-02-10 16:24:39 +00:00
|
|
|
|
|
|
|
|
if (desc->channel[q.scalar.comp].normalized) {
|
|
|
|
|
*result = fui(1.0);
|
2019-11-12 17:51:19 +00:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-10 16:24:39 +00:00
|
|
|
const uint32_t chan_max = u_uintN_max(desc->channel[q.scalar.comp].size);
|
|
|
|
|
*result = desc->channel[q.scalar.comp].pure_integer ? chan_max : fui(chan_max);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2026-01-31 14:54:30 -05:00
|
|
|
case nir_intrinsic_load_ttmp_register_amd:
|
2023-02-10 16:24:39 +00:00
|
|
|
case nir_intrinsic_load_scalar_arg_amd:
|
|
|
|
|
case nir_intrinsic_load_vector_arg_amd: {
|
|
|
|
|
uint32_t upper_bound = nir_intrinsic_arg_upper_bound_u32_amd(intrin);
|
|
|
|
|
if (upper_bound)
|
|
|
|
|
*result = upper_bound;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2025-11-24 16:28:44 -08:00
|
|
|
|
|
|
|
|
case nir_intrinsic_image_samples:
|
|
|
|
|
if (state->shader->options->max_samples > 0)
|
|
|
|
|
*result = state->shader->options->max_samples;
|
|
|
|
|
break;
|
|
|
|
|
|
2023-02-10 16:24:39 +00:00
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-11-12 17:51:19 +00:00
|
|
|
|
2023-02-10 16:24:39 +00:00
|
|
|
static void
|
2025-08-13 10:56:51 +01:00
|
|
|
get_alu_uub(struct analysis_state *state, struct scalar_query q, uint32_t *result, const uint32_t *src)
|
2023-02-10 16:24:39 +00:00
|
|
|
{
|
2023-08-12 16:17:15 -04:00
|
|
|
nir_op op = nir_scalar_alu_op(q.scalar);
|
2023-02-10 16:24:39 +00:00
|
|
|
|
|
|
|
|
/* Early exit for unsupported ALU opcodes. */
|
|
|
|
|
switch (op) {
|
|
|
|
|
case nir_op_umin:
|
|
|
|
|
case nir_op_imin:
|
|
|
|
|
case nir_op_imax:
|
|
|
|
|
case nir_op_umax:
|
|
|
|
|
case nir_op_iand:
|
|
|
|
|
case nir_op_ior:
|
|
|
|
|
case nir_op_ixor:
|
|
|
|
|
case nir_op_ishl:
|
|
|
|
|
case nir_op_imul:
|
|
|
|
|
case nir_op_ushr:
|
|
|
|
|
case nir_op_ishr:
|
|
|
|
|
case nir_op_iadd:
|
|
|
|
|
case nir_op_umod:
|
|
|
|
|
case nir_op_udiv:
|
|
|
|
|
case nir_op_bcsel:
|
|
|
|
|
case nir_op_b32csel:
|
|
|
|
|
case nir_op_ubfe:
|
nir/range_analysis: Handle bfi and bitfield_select in get_alu_uub
I noticed some things related to this while implementing support for
bitfield_select / BFN in BRW.
shader-db:
Lunar Lake
total instructions in shared programs: 17183140 -> 17183128 (<.01%)
instructions in affected programs: 3830 -> 3818 (-0.31%)
helped: 6 / HURT: 0
total cycles in shared programs: 889936934 -> 889936056 (<.01%)
cycles in affected programs: 253758 -> 252880 (-0.35%)
helped: 4 / HURT: 2
No shader-db changes on any other Intel platform.
fossil-db:
Lunar Lake
Totals:
Instrs: 233285343 -> 233284796 (-0.00%); split: -0.00%, +0.00%
Cycle count: 32756777978 -> 32756399804 (-0.00%); split: -0.00%, +0.00%
Max live registers: 71738646 -> 71738626 (-0.00%)
Non SSA regs after NIR: 67837900 -> 67837902 (+0.00%)
Totals from 177 (0.02% of 790723) affected shaders:
Instrs: 389849 -> 389302 (-0.14%); split: -0.14%, +0.00%
Cycle count: 356341872 -> 355963698 (-0.11%); split: -0.11%, +0.01%
Max live registers: 39364 -> 39344 (-0.05%)
Non SSA regs after NIR: 70453 -> 70455 (+0.00%)
Meteor Lake, DG2, and Ice Lake had similar results. (Meteor Lake shown)
Totals:
Instrs: 264095611 -> 264095358 (-0.00%)
Cycle count: 26555705299 -> 26554303407 (-0.01%); split: -0.01%, +0.00%
Fill count: 613233 -> 613231 (-0.00%)
Totals from 123 (0.01% of 905547) affected shaders:
Instrs: 334830 -> 334577 (-0.08%)
Cycle count: 326531667 -> 325129775 (-0.43%); split: -0.65%, +0.22%
Fill count: 4145 -> 4143 (-0.05%)
Tiger Lake and Skylake had similar results. (Tiger Lake shown)
Totals:
Instrs: 269733849 -> 269733590 (-0.00%)
Cycle count: 25240548036 -> 25241435039 (+0.00%); split: -0.00%, +0.01%
Totals from 123 (0.01% of 903812) affected shaders:
Instrs: 338617 -> 338358 (-0.08%)
Cycle count: 326605644 -> 327492647 (+0.27%); split: -0.13%, +0.40%
Reviewed-by: Matt Turner <mattst88@gmail.com>
Reviewed-by: Georg Lehmann <dadschoorse@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/37186>
2025-06-16 11:38:53 -07:00
|
|
|
case nir_op_bfi:
|
2023-02-10 16:24:39 +00:00
|
|
|
case nir_op_bfm:
|
nir/range_analysis: Handle bfi and bitfield_select in get_alu_uub
I noticed some things related to this while implementing support for
bitfield_select / BFN in BRW.
shader-db:
Lunar Lake
total instructions in shared programs: 17183140 -> 17183128 (<.01%)
instructions in affected programs: 3830 -> 3818 (-0.31%)
helped: 6 / HURT: 0
total cycles in shared programs: 889936934 -> 889936056 (<.01%)
cycles in affected programs: 253758 -> 252880 (-0.35%)
helped: 4 / HURT: 2
No shader-db changes on any other Intel platform.
fossil-db:
Lunar Lake
Totals:
Instrs: 233285343 -> 233284796 (-0.00%); split: -0.00%, +0.00%
Cycle count: 32756777978 -> 32756399804 (-0.00%); split: -0.00%, +0.00%
Max live registers: 71738646 -> 71738626 (-0.00%)
Non SSA regs after NIR: 67837900 -> 67837902 (+0.00%)
Totals from 177 (0.02% of 790723) affected shaders:
Instrs: 389849 -> 389302 (-0.14%); split: -0.14%, +0.00%
Cycle count: 356341872 -> 355963698 (-0.11%); split: -0.11%, +0.01%
Max live registers: 39364 -> 39344 (-0.05%)
Non SSA regs after NIR: 70453 -> 70455 (+0.00%)
Meteor Lake, DG2, and Ice Lake had similar results. (Meteor Lake shown)
Totals:
Instrs: 264095611 -> 264095358 (-0.00%)
Cycle count: 26555705299 -> 26554303407 (-0.01%); split: -0.01%, +0.00%
Fill count: 613233 -> 613231 (-0.00%)
Totals from 123 (0.01% of 905547) affected shaders:
Instrs: 334830 -> 334577 (-0.08%)
Cycle count: 326531667 -> 325129775 (-0.43%); split: -0.65%, +0.22%
Fill count: 4145 -> 4143 (-0.05%)
Tiger Lake and Skylake had similar results. (Tiger Lake shown)
Totals:
Instrs: 269733849 -> 269733590 (-0.00%)
Cycle count: 25240548036 -> 25241435039 (+0.00%); split: -0.00%, +0.01%
Totals from 123 (0.01% of 903812) affected shaders:
Instrs: 338617 -> 338358 (-0.08%)
Cycle count: 326605644 -> 327492647 (+0.27%); split: -0.13%, +0.40%
Reviewed-by: Matt Turner <mattst88@gmail.com>
Reviewed-by: Georg Lehmann <dadschoorse@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/37186>
2025-06-16 11:38:53 -07:00
|
|
|
case nir_op_bitfield_select:
|
2023-02-10 16:24:39 +00:00
|
|
|
case nir_op_extract_u8:
|
|
|
|
|
case nir_op_extract_i8:
|
|
|
|
|
case nir_op_extract_u16:
|
|
|
|
|
case nir_op_extract_i16:
|
|
|
|
|
case nir_op_b2i8:
|
|
|
|
|
case nir_op_b2i16:
|
|
|
|
|
case nir_op_b2i32:
|
|
|
|
|
break;
|
|
|
|
|
case nir_op_u2u1:
|
|
|
|
|
case nir_op_u2u8:
|
|
|
|
|
case nir_op_u2u16:
|
|
|
|
|
case nir_op_u2u32:
|
2023-08-12 16:17:15 -04:00
|
|
|
if (nir_scalar_chase_alu_src(q.scalar, 0).def->bit_size > 32) {
|
2023-02-10 16:24:39 +00:00
|
|
|
/* If src is >32 bits, return max */
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
break;
|
2024-12-09 22:47:51 +01:00
|
|
|
case nir_op_fsat:
|
2024-12-09 22:57:58 +01:00
|
|
|
case nir_op_fmul:
|
|
|
|
|
case nir_op_fmulz:
|
|
|
|
|
case nir_op_f2u32:
|
2024-12-09 22:28:09 +01:00
|
|
|
case nir_op_f2i32:
|
2024-12-09 22:57:58 +01:00
|
|
|
if (nir_scalar_chase_alu_src(q.scalar, 0).def->bit_size != 32) {
|
|
|
|
|
/* Only 32bit floats support for now, return max */
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
break;
|
2025-08-20 12:49:57 +02:00
|
|
|
case nir_op_bit_count:
|
|
|
|
|
if (nir_scalar_chase_alu_src(q.scalar, 0).def->bit_size > 32) {
|
|
|
|
|
*result = nir_scalar_chase_alu_src(q.scalar, 0).def->bit_size;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
break;
|
2023-02-10 16:24:39 +00:00
|
|
|
default:
|
|
|
|
|
return;
|
|
|
|
|
}
|
2019-11-12 17:51:19 +00:00
|
|
|
|
2023-02-10 16:24:39 +00:00
|
|
|
if (!q.head.pushed_queries) {
|
|
|
|
|
for (unsigned i = 0; i < nir_op_infos[op].num_inputs; i++)
|
2025-08-13 10:56:51 +01:00
|
|
|
push_scalar_query(state, nir_scalar_chase_alu_src(q.scalar, i));
|
2023-02-10 16:24:39 +00:00
|
|
|
return;
|
|
|
|
|
}
|
2019-11-12 17:51:19 +00:00
|
|
|
|
2023-02-10 16:24:39 +00:00
|
|
|
uint32_t max = bitmask(q.scalar.def->bit_size);
|
|
|
|
|
switch (op) {
|
|
|
|
|
case nir_op_umin:
|
|
|
|
|
*result = src[0] < src[1] ? src[0] : src[1];
|
|
|
|
|
break;
|
|
|
|
|
case nir_op_imin:
|
|
|
|
|
case nir_op_imax:
|
|
|
|
|
case nir_op_umax:
|
|
|
|
|
*result = src[0] > src[1] ? src[0] : src[1];
|
|
|
|
|
break;
|
2025-06-13 11:08:47 +01:00
|
|
|
case nir_op_iand: {
|
|
|
|
|
nir_scalar src0_scalar = nir_scalar_chase_alu_src(q.scalar, 0);
|
|
|
|
|
nir_scalar src1_scalar = nir_scalar_chase_alu_src(q.scalar, 1);
|
|
|
|
|
if (nir_scalar_is_const(src0_scalar))
|
|
|
|
|
*result = bitmask(util_last_bit64(src[1])) & nir_scalar_as_uint(src0_scalar);
|
|
|
|
|
else if (nir_scalar_is_const(src1_scalar))
|
|
|
|
|
*result = bitmask(util_last_bit64(src[0])) & nir_scalar_as_uint(src1_scalar);
|
|
|
|
|
else
|
|
|
|
|
*result = bitmask(util_last_bit64(src[0])) & bitmask(util_last_bit64(src[1]));
|
2023-02-10 16:24:39 +00:00
|
|
|
break;
|
2025-06-13 11:08:47 +01:00
|
|
|
}
|
2023-02-10 16:24:39 +00:00
|
|
|
case nir_op_ior:
|
2025-06-13 11:13:00 +01:00
|
|
|
case nir_op_ixor: {
|
|
|
|
|
nir_scalar src0_scalar = nir_scalar_chase_alu_src(q.scalar, 0);
|
|
|
|
|
nir_scalar src1_scalar = nir_scalar_chase_alu_src(q.scalar, 1);
|
|
|
|
|
if (nir_scalar_is_const(src0_scalar))
|
|
|
|
|
*result = bitmask(util_last_bit64(src[1])) | nir_scalar_as_uint(src0_scalar);
|
|
|
|
|
else if (nir_scalar_is_const(src1_scalar))
|
|
|
|
|
*result = bitmask(util_last_bit64(src[0])) | nir_scalar_as_uint(src1_scalar);
|
|
|
|
|
else
|
|
|
|
|
*result = bitmask(util_last_bit64(src[0])) | bitmask(util_last_bit64(src[1]));
|
2023-02-10 16:24:39 +00:00
|
|
|
break;
|
2025-06-13 11:13:00 +01:00
|
|
|
}
|
2023-02-10 16:24:39 +00:00
|
|
|
case nir_op_ishl: {
|
|
|
|
|
uint32_t src1 = MIN2(src[1], q.scalar.def->bit_size - 1u);
|
|
|
|
|
if (util_last_bit64(src[0]) + src1 <= q.scalar.def->bit_size) /* check overflow */
|
|
|
|
|
*result = src[0] << src1;
|
2025-07-25 10:28:55 +01:00
|
|
|
*result = MIN2(*result, max);
|
2025-06-13 11:06:49 +01:00
|
|
|
|
|
|
|
|
nir_scalar src1_scalar = nir_scalar_chase_alu_src(q.scalar, 1);
|
|
|
|
|
if (nir_scalar_is_const(src1_scalar)) {
|
|
|
|
|
uint32_t const_val = 1u << (nir_scalar_as_uint(src1_scalar) & (q.scalar.def->bit_size - 1u));
|
|
|
|
|
*result = MIN2(*result, max / const_val * const_val);
|
|
|
|
|
}
|
2023-02-10 16:24:39 +00:00
|
|
|
break;
|
|
|
|
|
}
|
2025-06-13 11:06:49 +01:00
|
|
|
case nir_op_imul: {
|
2023-02-10 16:24:39 +00:00
|
|
|
if (src[0] == 0 || (src[0] * src[1]) / src[0] == src[1]) /* check overflow */
|
|
|
|
|
*result = src[0] * src[1];
|
2025-07-25 10:28:55 +01:00
|
|
|
*result = MIN2(*result, max);
|
2025-06-13 11:06:49 +01:00
|
|
|
|
|
|
|
|
nir_scalar src0_scalar = nir_scalar_chase_alu_src(q.scalar, 0);
|
|
|
|
|
nir_scalar src1_scalar = nir_scalar_chase_alu_src(q.scalar, 1);
|
|
|
|
|
if (nir_scalar_is_const(src0_scalar)) {
|
|
|
|
|
uint32_t const_val = nir_scalar_as_uint(src0_scalar);
|
2025-08-17 21:53:26 +02:00
|
|
|
*result = const_val ? MIN2(*result, max / const_val * const_val) : 0;
|
2025-06-13 11:06:49 +01:00
|
|
|
} else if (nir_scalar_is_const(src1_scalar)) {
|
|
|
|
|
uint32_t const_val = nir_scalar_as_uint(src1_scalar);
|
2025-08-17 21:53:26 +02:00
|
|
|
*result = const_val ? MIN2(*result, max / const_val * const_val) : 0;
|
2025-06-13 11:06:49 +01:00
|
|
|
}
|
2023-02-10 16:24:39 +00:00
|
|
|
break;
|
2025-06-13 11:06:49 +01:00
|
|
|
}
|
2023-02-10 16:24:39 +00:00
|
|
|
case nir_op_ushr: {
|
2023-08-12 16:17:15 -04:00
|
|
|
nir_scalar src1_scalar = nir_scalar_chase_alu_src(q.scalar, 1);
|
2023-02-10 16:24:39 +00:00
|
|
|
uint32_t mask = q.scalar.def->bit_size - 1u;
|
2023-08-12 16:17:15 -04:00
|
|
|
if (nir_scalar_is_const(src1_scalar))
|
|
|
|
|
*result = src[0] >> (nir_scalar_as_uint(src1_scalar) & mask);
|
2023-02-10 16:24:39 +00:00
|
|
|
else
|
|
|
|
|
*result = src[0];
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case nir_op_ishr: {
|
2023-08-12 16:17:15 -04:00
|
|
|
nir_scalar src1_scalar = nir_scalar_chase_alu_src(q.scalar, 1);
|
2023-02-10 16:24:39 +00:00
|
|
|
uint32_t mask = q.scalar.def->bit_size - 1u;
|
2023-08-12 16:17:15 -04:00
|
|
|
if (src[0] <= 2147483647 && nir_scalar_is_const(src1_scalar))
|
|
|
|
|
*result = src[0] >> (nir_scalar_as_uint(src1_scalar) & mask);
|
2023-02-10 16:24:39 +00:00
|
|
|
else
|
|
|
|
|
*result = src[0];
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case nir_op_iadd:
|
|
|
|
|
if (src[0] + src[1] >= src[0]) /* check overflow */
|
|
|
|
|
*result = src[0] + src[1];
|
2025-07-25 10:28:55 +01:00
|
|
|
*result = MIN2(*result, max);
|
2023-02-10 16:24:39 +00:00
|
|
|
break;
|
|
|
|
|
case nir_op_umod:
|
|
|
|
|
*result = src[1] ? src[1] - 1 : 0;
|
|
|
|
|
break;
|
|
|
|
|
case nir_op_udiv: {
|
2023-08-12 16:17:15 -04:00
|
|
|
nir_scalar src1_scalar = nir_scalar_chase_alu_src(q.scalar, 1);
|
|
|
|
|
if (nir_scalar_is_const(src1_scalar))
|
|
|
|
|
*result = nir_scalar_as_uint(src1_scalar)
|
|
|
|
|
? src[0] / nir_scalar_as_uint(src1_scalar)
|
2023-08-08 12:00:35 -05:00
|
|
|
: 0;
|
2023-02-10 16:24:39 +00:00
|
|
|
else
|
|
|
|
|
*result = src[0];
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case nir_op_bcsel:
|
|
|
|
|
case nir_op_b32csel:
|
|
|
|
|
*result = src[1] > src[2] ? src[1] : src[2];
|
|
|
|
|
break;
|
|
|
|
|
case nir_op_ubfe:
|
|
|
|
|
*result = bitmask(MIN2(src[2], q.scalar.def->bit_size));
|
|
|
|
|
break;
|
|
|
|
|
case nir_op_bfm: {
|
2023-08-12 16:17:15 -04:00
|
|
|
nir_scalar src1_scalar = nir_scalar_chase_alu_src(q.scalar, 1);
|
|
|
|
|
if (nir_scalar_is_const(src1_scalar)) {
|
2023-02-10 16:24:39 +00:00
|
|
|
uint32_t src0 = MIN2(src[0], 31);
|
2023-08-12 16:17:15 -04:00
|
|
|
uint32_t src1 = nir_scalar_as_uint(src1_scalar) & 0x1fu;
|
2023-02-10 16:24:39 +00:00
|
|
|
*result = bitmask(src0) << src1;
|
2019-11-12 17:51:19 +00:00
|
|
|
} else {
|
2023-02-10 16:24:39 +00:00
|
|
|
uint32_t src0 = MIN2(src[0], 31);
|
|
|
|
|
uint32_t src1 = MIN2(src[1], 31);
|
|
|
|
|
*result = bitmask(MIN2(src0 + src1, 32));
|
2019-11-12 17:51:19 +00:00
|
|
|
}
|
2023-02-10 16:24:39 +00:00
|
|
|
break;
|
2019-11-12 17:51:19 +00:00
|
|
|
}
|
nir/range_analysis: Handle bfi and bitfield_select in get_alu_uub
I noticed some things related to this while implementing support for
bitfield_select / BFN in BRW.
shader-db:
Lunar Lake
total instructions in shared programs: 17183140 -> 17183128 (<.01%)
instructions in affected programs: 3830 -> 3818 (-0.31%)
helped: 6 / HURT: 0
total cycles in shared programs: 889936934 -> 889936056 (<.01%)
cycles in affected programs: 253758 -> 252880 (-0.35%)
helped: 4 / HURT: 2
No shader-db changes on any other Intel platform.
fossil-db:
Lunar Lake
Totals:
Instrs: 233285343 -> 233284796 (-0.00%); split: -0.00%, +0.00%
Cycle count: 32756777978 -> 32756399804 (-0.00%); split: -0.00%, +0.00%
Max live registers: 71738646 -> 71738626 (-0.00%)
Non SSA regs after NIR: 67837900 -> 67837902 (+0.00%)
Totals from 177 (0.02% of 790723) affected shaders:
Instrs: 389849 -> 389302 (-0.14%); split: -0.14%, +0.00%
Cycle count: 356341872 -> 355963698 (-0.11%); split: -0.11%, +0.01%
Max live registers: 39364 -> 39344 (-0.05%)
Non SSA regs after NIR: 70453 -> 70455 (+0.00%)
Meteor Lake, DG2, and Ice Lake had similar results. (Meteor Lake shown)
Totals:
Instrs: 264095611 -> 264095358 (-0.00%)
Cycle count: 26555705299 -> 26554303407 (-0.01%); split: -0.01%, +0.00%
Fill count: 613233 -> 613231 (-0.00%)
Totals from 123 (0.01% of 905547) affected shaders:
Instrs: 334830 -> 334577 (-0.08%)
Cycle count: 326531667 -> 325129775 (-0.43%); split: -0.65%, +0.22%
Fill count: 4145 -> 4143 (-0.05%)
Tiger Lake and Skylake had similar results. (Tiger Lake shown)
Totals:
Instrs: 269733849 -> 269733590 (-0.00%)
Cycle count: 25240548036 -> 25241435039 (+0.00%); split: -0.00%, +0.01%
Totals from 123 (0.01% of 903812) affected shaders:
Instrs: 338617 -> 338358 (-0.08%)
Cycle count: 326605644 -> 327492647 (+0.27%); split: -0.13%, +0.40%
Reviewed-by: Matt Turner <mattst88@gmail.com>
Reviewed-by: Georg Lehmann <dadschoorse@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/37186>
2025-06-16 11:38:53 -07:00
|
|
|
|
|
|
|
|
case nir_op_bfi: {
|
|
|
|
|
nir_scalar src0_scalar = nir_scalar_chase_alu_src(q.scalar, 0);
|
|
|
|
|
const uint64_t s1 = bitmask(util_last_bit64(src[1]));
|
|
|
|
|
const uint64_t s2 = bitmask(util_last_bit64(src[2]));
|
|
|
|
|
|
|
|
|
|
if (nir_scalar_is_const(src0_scalar)) {
|
|
|
|
|
const uint64_t s0 = nir_scalar_as_uint(src0_scalar);
|
|
|
|
|
|
|
|
|
|
/* This case should be eliminated by opt_algebraic. */
|
|
|
|
|
if (s0 == 0) {
|
|
|
|
|
*result = s2;
|
|
|
|
|
} else {
|
|
|
|
|
const int x = ffsll(s0) - 1;
|
|
|
|
|
*result = (s0 & (s1 << x)) | (~s0 & s2);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
const uint64_t s0 = bitmask(util_last_bit64(src[0]));
|
|
|
|
|
|
|
|
|
|
/* Due to the unpredictable shift, the true maximum value of (s0 &
|
|
|
|
|
* (s1 << x)) cannot be known. However, it cannot be larger than
|
|
|
|
|
* s0.
|
|
|
|
|
*
|
|
|
|
|
* inot doesn't work in get_alu_uub. It is known that (~s0 & s2)
|
|
|
|
|
* cannot be larger than s2, so just use s2 as a loose upper bound.
|
|
|
|
|
*/
|
|
|
|
|
*result = s0 | s2;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case nir_op_bitfield_select: {
|
|
|
|
|
nir_scalar src0_scalar = nir_scalar_chase_alu_src(q.scalar, 0);
|
|
|
|
|
const uint64_t s1 = bitmask(util_last_bit64(src[1]));
|
|
|
|
|
const uint64_t s2 = bitmask(util_last_bit64(src[2]));
|
|
|
|
|
|
|
|
|
|
if (nir_scalar_is_const(src0_scalar)) {
|
|
|
|
|
const uint64_t s0 = nir_scalar_as_uint(src0_scalar);
|
|
|
|
|
|
|
|
|
|
*result = (s0 & s1) | (~s0 & s2);
|
|
|
|
|
} else {
|
|
|
|
|
const uint64_t s0 = bitmask(util_last_bit64(src[0]));
|
|
|
|
|
|
|
|
|
|
/* inot doesn't work in get_alu_uub. It is known that (~s0 & s2)
|
|
|
|
|
* cannot be larger than s2, so just use s2 as a loose upper bound.
|
|
|
|
|
*/
|
|
|
|
|
*result = (s0 & s1) | s2;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-10 16:24:39 +00:00
|
|
|
/* limited floating-point support for f2u32(fmul(load_input(), <constant>)) */
|
2024-12-09 22:28:09 +01:00
|
|
|
case nir_op_f2i32:
|
2023-02-10 16:24:39 +00:00
|
|
|
case nir_op_f2u32:
|
|
|
|
|
/* infinity/NaN starts at 0x7f800000u, negative numbers at 0x80000000 */
|
|
|
|
|
if (src[0] < 0x7f800000u) {
|
|
|
|
|
float val;
|
|
|
|
|
memcpy(&val, &src[0], 4);
|
|
|
|
|
*result = (uint32_t)val;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case nir_op_fmul:
|
|
|
|
|
case nir_op_fmulz:
|
|
|
|
|
/* infinity/NaN starts at 0x7f800000u, negative numbers at 0x80000000 */
|
|
|
|
|
if (src[0] < 0x7f800000u && src[1] < 0x7f800000u) {
|
|
|
|
|
float src0_f, src1_f;
|
|
|
|
|
memcpy(&src0_f, &src[0], 4);
|
|
|
|
|
memcpy(&src1_f, &src[1], 4);
|
|
|
|
|
/* not a proper rounding-up multiplication, but should be good enough */
|
|
|
|
|
float max_f = ceilf(src0_f) * ceilf(src1_f);
|
|
|
|
|
memcpy(result, &max_f, 4);
|
|
|
|
|
}
|
|
|
|
|
break;
|
2024-12-09 22:47:51 +01:00
|
|
|
case nir_op_fsat:
|
|
|
|
|
*result = 0x3f800000u;
|
|
|
|
|
break;
|
2023-02-10 16:24:39 +00:00
|
|
|
case nir_op_u2u1:
|
|
|
|
|
case nir_op_u2u8:
|
|
|
|
|
case nir_op_u2u16:
|
|
|
|
|
case nir_op_u2u32:
|
|
|
|
|
*result = MIN2(src[0], max);
|
|
|
|
|
break;
|
|
|
|
|
case nir_op_b2i8:
|
|
|
|
|
case nir_op_b2i16:
|
|
|
|
|
case nir_op_b2i32:
|
|
|
|
|
*result = 1;
|
|
|
|
|
break;
|
2023-11-17 11:21:19 +00:00
|
|
|
case nir_op_msad_4x8:
|
|
|
|
|
*result = MIN2((uint64_t)src[2] + 4 * 255, UINT32_MAX);
|
2023-02-10 16:24:39 +00:00
|
|
|
break;
|
|
|
|
|
case nir_op_extract_u8:
|
|
|
|
|
*result = MIN2(src[0], UINT8_MAX);
|
|
|
|
|
break;
|
|
|
|
|
case nir_op_extract_i8:
|
|
|
|
|
*result = (src[0] >= 0x80) ? max : MIN2(src[0], INT8_MAX);
|
|
|
|
|
break;
|
|
|
|
|
case nir_op_extract_u16:
|
|
|
|
|
*result = MIN2(src[0], UINT16_MAX);
|
|
|
|
|
break;
|
|
|
|
|
case nir_op_extract_i16:
|
|
|
|
|
*result = (src[0] >= 0x8000) ? max : MIN2(src[0], INT16_MAX);
|
|
|
|
|
break;
|
2025-08-20 12:49:57 +02:00
|
|
|
case nir_op_bit_count:
|
|
|
|
|
*result = util_last_bit64(src[0]);
|
|
|
|
|
break;
|
2023-02-10 16:24:39 +00:00
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-11-12 17:51:19 +00:00
|
|
|
|
2025-11-24 16:28:44 -08:00
|
|
|
static void
|
|
|
|
|
get_tex_uub(struct analysis_state *state, struct scalar_query q, uint32_t *result, const uint32_t *src)
|
|
|
|
|
{
|
|
|
|
|
nir_tex_instr *tex = nir_scalar_as_tex(q.scalar);
|
|
|
|
|
|
|
|
|
|
if (tex->op == nir_texop_texture_samples && state->shader->options->max_samples > 0)
|
|
|
|
|
*result = state->shader->options->max_samples;
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-10 16:24:39 +00:00
|
|
|
static void
|
2025-08-13 10:56:51 +01:00
|
|
|
get_phi_uub(struct analysis_state *state, struct scalar_query q, uint32_t *result, const uint32_t *src)
|
2023-02-10 16:24:39 +00:00
|
|
|
{
|
2025-07-31 09:49:36 -04:00
|
|
|
nir_phi_instr *phi = nir_def_as_phi(q.scalar.def);
|
2019-11-12 17:51:19 +00:00
|
|
|
|
2023-02-10 16:24:39 +00:00
|
|
|
if (exec_list_is_empty(&phi->srcs))
|
|
|
|
|
return;
|
2019-11-12 17:51:19 +00:00
|
|
|
|
2023-02-10 16:24:39 +00:00
|
|
|
if (q.head.pushed_queries) {
|
|
|
|
|
*result = src[0];
|
|
|
|
|
for (unsigned i = 1; i < q.head.pushed_queries; i++)
|
|
|
|
|
*result = MAX2(*result, src[i]);
|
|
|
|
|
return;
|
2019-11-12 17:51:19 +00:00
|
|
|
}
|
|
|
|
|
|
2023-02-10 16:24:39 +00:00
|
|
|
nir_cf_node *prev = nir_cf_node_prev(&phi->instr.block->cf_node);
|
|
|
|
|
if (!prev || prev->type == nir_cf_node_block) {
|
|
|
|
|
/* Resolve cycles by inserting max into range_ht. */
|
|
|
|
|
uint32_t max = bitmask(q.scalar.def->bit_size);
|
2026-03-02 16:20:26 +00:00
|
|
|
scalar_insert(state->range_ht, get_scalar_key(&q.head), max);
|
2023-02-10 16:24:39 +00:00
|
|
|
|
|
|
|
|
struct set *visited = _mesa_pointer_set_create(NULL);
|
2023-08-12 16:17:15 -04:00
|
|
|
nir_scalar *defs = alloca(sizeof(nir_scalar) * 64);
|
2023-02-10 16:24:39 +00:00
|
|
|
unsigned def_count = search_phi_bcsel(q.scalar, defs, 64, visited);
|
|
|
|
|
_mesa_set_destroy(visited, NULL);
|
|
|
|
|
|
|
|
|
|
for (unsigned i = 0; i < def_count; i++)
|
2025-08-13 10:56:51 +01:00
|
|
|
push_scalar_query(state, defs[i]);
|
2023-02-10 16:24:39 +00:00
|
|
|
} else {
|
|
|
|
|
nir_foreach_phi_src(src, phi)
|
2025-08-13 10:56:51 +01:00
|
|
|
push_scalar_query(state, nir_get_scalar(src->src.ssa, q.scalar.comp));
|
2023-02-10 16:24:39 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
process_uub_query(struct analysis_state *state, struct analysis_query *aq, uint32_t *result,
|
|
|
|
|
const uint32_t *src)
|
|
|
|
|
{
|
2025-08-13 10:56:51 +01:00
|
|
|
struct scalar_query q = *(struct scalar_query *)aq;
|
2023-02-10 16:24:39 +00:00
|
|
|
|
|
|
|
|
*result = bitmask(q.scalar.def->bit_size);
|
2023-08-12 16:17:15 -04:00
|
|
|
if (nir_scalar_is_const(q.scalar))
|
|
|
|
|
*result = nir_scalar_as_uint(q.scalar);
|
2023-08-13 00:03:03 +02:00
|
|
|
else if (nir_scalar_is_intrinsic(q.scalar))
|
2023-02-10 16:24:39 +00:00
|
|
|
get_intrinsic_uub(state, q, result, src);
|
2023-08-12 16:17:15 -04:00
|
|
|
else if (nir_scalar_is_alu(q.scalar))
|
2023-02-10 16:24:39 +00:00
|
|
|
get_alu_uub(state, q, result, src);
|
2025-11-24 16:28:44 -08:00
|
|
|
else if (nir_def_instr_type(q.scalar.def) == nir_instr_type_tex)
|
|
|
|
|
get_tex_uub(state, q, result, src);
|
2025-11-07 21:38:36 +08:00
|
|
|
else if (nir_def_instr_type(q.scalar.def) == nir_instr_type_phi)
|
2023-02-10 16:24:39 +00:00
|
|
|
get_phi_uub(state, q, result, src);
|
2019-11-12 17:51:19 +00:00
|
|
|
}
|
|
|
|
|
|
2023-01-10 16:12:34 +01:00
|
|
|
uint32_t
|
|
|
|
|
nir_unsigned_upper_bound(nir_shader *shader, struct hash_table *range_ht,
|
2025-09-14 17:43:57 +02:00
|
|
|
nir_scalar scalar)
|
2023-08-08 12:00:35 -05:00
|
|
|
{
|
2025-08-13 10:56:51 +01:00
|
|
|
struct scalar_query query_alloc[16];
|
2023-02-10 16:24:39 +00:00
|
|
|
uint32_t result_alloc[16];
|
|
|
|
|
|
|
|
|
|
struct analysis_state state;
|
|
|
|
|
state.shader = shader;
|
|
|
|
|
state.range_ht = range_ht;
|
|
|
|
|
util_dynarray_init_from_stack(&state.query_stack, query_alloc, sizeof(query_alloc));
|
|
|
|
|
util_dynarray_init_from_stack(&state.result_stack, result_alloc, sizeof(result_alloc));
|
2025-08-13 10:56:51 +01:00
|
|
|
state.query_size = sizeof(struct scalar_query);
|
|
|
|
|
state.get_key = &get_scalar_key;
|
2026-03-02 16:20:26 +00:00
|
|
|
state.lookup = &scalar_lookup,
|
|
|
|
|
state.insert = &scalar_insert,
|
2023-02-10 16:24:39 +00:00
|
|
|
state.process_query = &process_uub_query;
|
|
|
|
|
|
2025-08-13 10:56:51 +01:00
|
|
|
push_scalar_query(&state, scalar);
|
2023-02-10 16:24:39 +00:00
|
|
|
|
2026-03-03 13:44:01 +00:00
|
|
|
_mesa_hash_table_set_deleted_key(range_ht, (void *)(uintptr_t)UINT32_MAX);
|
2023-02-10 16:24:39 +00:00
|
|
|
return perform_analysis(&state);
|
2023-01-10 16:12:34 +01:00
|
|
|
}
|
|
|
|
|
|
2019-11-12 17:51:19 +00:00
|
|
|
bool
|
|
|
|
|
nir_addition_might_overflow(nir_shader *shader, struct hash_table *range_ht,
|
2025-09-14 17:43:57 +02:00
|
|
|
nir_scalar ssa, unsigned const_val)
|
2019-11-12 17:51:19 +00:00
|
|
|
{
|
2025-09-14 17:43:57 +02:00
|
|
|
uint32_t ub = nir_unsigned_upper_bound(shader, range_ht, ssa);
|
2019-11-12 17:51:19 +00:00
|
|
|
return const_val + ub < const_val;
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-04 11:38:40 -06:00
|
|
|
static uint64_t
|
2023-08-12 16:17:15 -04:00
|
|
|
ssa_def_bits_used(const nir_def *def, int recur)
|
2021-02-04 11:38:40 -06:00
|
|
|
{
|
|
|
|
|
uint64_t bits_used = 0;
|
|
|
|
|
uint64_t all_bits = BITFIELD64_MASK(def->bit_size);
|
|
|
|
|
|
2021-02-17 19:40:07 -08:00
|
|
|
/* Querying the bits used from a vector is too hard of a question to
|
|
|
|
|
* answer. Return the conservative answer that all bits are used. To
|
|
|
|
|
* handle this, the function would need to be extended to be a query of a
|
|
|
|
|
* single component of the vector. That would also necessary to fully
|
|
|
|
|
* handle the 'num_components > 1' inside the loop below.
|
|
|
|
|
*
|
|
|
|
|
* FINISHME: This restriction will eventually need to be restricted to be
|
|
|
|
|
* useful for hardware that uses u16vec2 as the native 16-bit integer type.
|
|
|
|
|
*/
|
|
|
|
|
if (def->num_components > 1)
|
|
|
|
|
return all_bits;
|
|
|
|
|
|
2021-02-04 11:38:40 -06:00
|
|
|
/* Limit recursion */
|
|
|
|
|
if (recur-- <= 0)
|
|
|
|
|
return all_bits;
|
|
|
|
|
|
|
|
|
|
nir_foreach_use(src, def) {
|
2023-08-14 09:58:47 -04:00
|
|
|
switch (nir_src_parent_instr(src)->type) {
|
2021-02-04 11:38:40 -06:00
|
|
|
case nir_instr_type_alu: {
|
2023-08-14 09:58:47 -04:00
|
|
|
nir_alu_instr *use_alu = nir_instr_as_alu(nir_src_parent_instr(src));
|
2021-02-04 11:38:40 -06:00
|
|
|
unsigned src_idx = container_of(src, nir_alu_src, src) - use_alu->src;
|
|
|
|
|
|
2021-02-17 19:40:07 -08:00
|
|
|
/* If a user of the value produces a vector result, return the
|
|
|
|
|
* conservative answer that all bits are used. It is possible to
|
|
|
|
|
* answer this query by looping over the components used. For example,
|
|
|
|
|
*
|
|
|
|
|
* vec4 32 ssa_5 = load_const(0x0000f000, 0x00000f00, 0x000000f0, 0x0000000f)
|
|
|
|
|
* ...
|
|
|
|
|
* vec4 32 ssa_8 = iand ssa_7.xxxx, ssa_5
|
|
|
|
|
*
|
|
|
|
|
* could conceivably return 0x0000ffff when queyring the bits used of
|
|
|
|
|
* ssa_7. This is unlikely to be worth the effort because the
|
|
|
|
|
* question can eventually answered after the shader has been
|
|
|
|
|
* scalarized.
|
|
|
|
|
*/
|
2023-08-14 11:43:35 -05:00
|
|
|
if (use_alu->def.num_components > 1)
|
2021-02-17 19:40:07 -08:00
|
|
|
return all_bits;
|
|
|
|
|
|
2021-02-04 11:38:40 -06:00
|
|
|
switch (use_alu->op) {
|
|
|
|
|
case nir_op_u2u8:
|
|
|
|
|
case nir_op_i2i8:
|
|
|
|
|
case nir_op_u2u16:
|
|
|
|
|
case nir_op_i2i16:
|
|
|
|
|
case nir_op_u2u32:
|
|
|
|
|
case nir_op_i2i32:
|
2025-04-13 19:47:56 -04:00
|
|
|
case nir_op_u2u64:
|
|
|
|
|
case nir_op_i2i64: {
|
|
|
|
|
uint64_t def_bits_used = ssa_def_bits_used(&use_alu->def, recur);
|
|
|
|
|
|
|
|
|
|
/* If one of the sign-extended bits is used, set the last src bit
|
|
|
|
|
* as used.
|
|
|
|
|
*/
|
|
|
|
|
if ((use_alu->op == nir_op_i2i8 || use_alu->op == nir_op_i2i16 ||
|
|
|
|
|
use_alu->op == nir_op_i2i32 || use_alu->op == nir_op_i2i64) &&
|
|
|
|
|
def_bits_used & ~all_bits)
|
|
|
|
|
def_bits_used |= BITFIELD64_BIT(def->bit_size - 1);
|
|
|
|
|
|
|
|
|
|
bits_used |= def_bits_used & all_bits;
|
2021-02-04 11:38:40 -06:00
|
|
|
break;
|
2025-04-13 19:47:56 -04:00
|
|
|
}
|
2021-02-04 11:38:40 -06:00
|
|
|
|
|
|
|
|
case nir_op_extract_u8:
|
|
|
|
|
case nir_op_extract_i8:
|
|
|
|
|
case nir_op_extract_u16:
|
|
|
|
|
case nir_op_extract_i16:
|
|
|
|
|
if (src_idx == 0 && nir_src_is_const(use_alu->src[1].src)) {
|
2025-04-13 20:25:01 -04:00
|
|
|
unsigned chunk = nir_alu_src_as_uint(use_alu->src[1]);
|
|
|
|
|
uint64_t defs_bits_used = ssa_def_bits_used(&use_alu->def, recur);
|
|
|
|
|
unsigned field_bits = use_alu->op == nir_op_extract_u8 ||
|
|
|
|
|
use_alu->op == nir_op_extract_i8 ? 8 : 16;
|
|
|
|
|
uint64_t field_bitmask = BITFIELD64_MASK(field_bits);
|
|
|
|
|
|
|
|
|
|
/* If one of the sign-extended bits is used, set the last src bit
|
|
|
|
|
* as used.
|
|
|
|
|
*/
|
|
|
|
|
if ((use_alu->op == nir_op_extract_i8 ||
|
|
|
|
|
use_alu->op == nir_op_extract_i16) &&
|
|
|
|
|
defs_bits_used & ~field_bitmask)
|
|
|
|
|
defs_bits_used |= BITFIELD64_BIT(field_bits - 1);
|
|
|
|
|
|
|
|
|
|
bits_used |= (field_bitmask & defs_bits_used) <<
|
|
|
|
|
(chunk * field_bits);
|
2021-02-04 11:38:40 -06:00
|
|
|
break;
|
|
|
|
|
} else {
|
|
|
|
|
return all_bits;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case nir_op_ishl:
|
|
|
|
|
case nir_op_ishr:
|
|
|
|
|
case nir_op_ushr:
|
2025-04-10 20:49:50 -04:00
|
|
|
if (src_idx == 0 && nir_src_is_const(use_alu->src[1].src)) {
|
|
|
|
|
unsigned bit_size = def->bit_size;
|
|
|
|
|
unsigned shift = nir_alu_src_as_uint(use_alu->src[1]) & (bit_size - 1);
|
|
|
|
|
uint64_t def_bits_used = ssa_def_bits_used(&use_alu->def, recur);
|
|
|
|
|
|
|
|
|
|
/* If one of the sign-extended bits is used, set the "last src
|
|
|
|
|
* bit before shifting" as used.
|
|
|
|
|
*/
|
|
|
|
|
if (use_alu->op == nir_op_ishr &&
|
|
|
|
|
def_bits_used & ~(all_bits >> shift))
|
|
|
|
|
def_bits_used |= BITFIELD64_BIT(bit_size - 1 - shift);
|
|
|
|
|
|
|
|
|
|
/* Reverse the shift to get the bits before shifting. */
|
|
|
|
|
if (use_alu->op == nir_op_ushr || use_alu->op == nir_op_ishr)
|
|
|
|
|
bits_used |= (def_bits_used << shift) & all_bits;
|
|
|
|
|
else
|
|
|
|
|
bits_used |= def_bits_used >> shift;
|
|
|
|
|
break;
|
|
|
|
|
} else if (src_idx == 1) {
|
|
|
|
|
bits_used |= use_alu->def.bit_size - 1;
|
2021-02-04 11:38:40 -06:00
|
|
|
break;
|
|
|
|
|
} else {
|
|
|
|
|
return all_bits;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case nir_op_iand:
|
|
|
|
|
case nir_op_ior:
|
|
|
|
|
assert(src_idx < 2);
|
|
|
|
|
if (nir_src_is_const(use_alu->src[1 - src_idx].src)) {
|
2025-04-13 20:25:46 -04:00
|
|
|
uint64_t other_src = nir_alu_src_as_uint(use_alu->src[1 - src_idx]);
|
|
|
|
|
if (use_alu->op == nir_op_iand)
|
|
|
|
|
bits_used |= ssa_def_bits_used(&use_alu->def, recur) & other_src;
|
|
|
|
|
else
|
|
|
|
|
bits_used |= ssa_def_bits_used(&use_alu->def, recur) & ~other_src;
|
2021-02-04 11:38:40 -06:00
|
|
|
break;
|
|
|
|
|
} else {
|
|
|
|
|
return all_bits;
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-10 20:47:23 -04:00
|
|
|
case nir_op_ibfe:
|
|
|
|
|
case nir_op_ubfe:
|
|
|
|
|
if (src_idx == 0 && nir_src_is_const(use_alu->src[1].src)) {
|
|
|
|
|
uint64_t def_bits_used = ssa_def_bits_used(&use_alu->def, recur);
|
|
|
|
|
unsigned bit_size = use_alu->def.bit_size;
|
|
|
|
|
unsigned offset = nir_alu_src_as_uint(use_alu->src[1]) & (bit_size - 1);
|
|
|
|
|
unsigned bits = nir_src_is_const(use_alu->src[2].src) ?
|
|
|
|
|
nir_alu_src_as_uint(use_alu->src[2]) & (bit_size - 1) :
|
|
|
|
|
/* Worst case if bits is not constant. */
|
|
|
|
|
(bit_size - offset);
|
|
|
|
|
uint64_t field_bitmask = BITFIELD64_MASK(bits);
|
|
|
|
|
|
|
|
|
|
/* If one of the sign-extended bits is used, set the last src
|
|
|
|
|
* bit as used.
|
|
|
|
|
* If bits is not constant, all bits can be the last one.
|
|
|
|
|
*/
|
|
|
|
|
if (use_alu->op == nir_op_ibfe &&
|
|
|
|
|
(def_bits_used >> offset) & ~field_bitmask) {
|
|
|
|
|
if (nir_alu_src_as_uint(use_alu->src[2]))
|
|
|
|
|
def_bits_used |= BITFIELD64_BIT(bits - 1);
|
|
|
|
|
else
|
|
|
|
|
def_bits_used |= field_bitmask;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bits_used |= (field_bitmask & def_bits_used) << offset;
|
|
|
|
|
break;
|
|
|
|
|
} else if (src_idx == 1 || src_idx == 2) {
|
|
|
|
|
bits_used |= use_alu->src[0].src.ssa->bit_size - 1;
|
|
|
|
|
break;
|
|
|
|
|
} else {
|
|
|
|
|
return all_bits;
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-10 20:49:50 -04:00
|
|
|
case nir_op_imul24:
|
|
|
|
|
case nir_op_umul24:
|
|
|
|
|
bits_used |= all_bits & 0xffffff;
|
|
|
|
|
break;
|
|
|
|
|
|
2025-05-12 20:43:51 -04:00
|
|
|
case nir_op_mov:
|
|
|
|
|
bits_used |= ssa_def_bits_used(&use_alu->def, recur);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case nir_op_bcsel:
|
|
|
|
|
if (src_idx == 0)
|
|
|
|
|
bits_used |= 0x1;
|
|
|
|
|
else
|
|
|
|
|
bits_used |= ssa_def_bits_used(&use_alu->def, recur);
|
|
|
|
|
break;
|
|
|
|
|
|
2021-02-04 11:38:40 -06:00
|
|
|
default:
|
|
|
|
|
/* We don't know what this op does */
|
|
|
|
|
return all_bits;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case nir_instr_type_intrinsic: {
|
|
|
|
|
nir_intrinsic_instr *use_intrin =
|
2023-08-14 09:58:47 -04:00
|
|
|
nir_instr_as_intrinsic(nir_src_parent_instr(src));
|
2021-02-04 11:38:40 -06:00
|
|
|
unsigned src_idx = src - use_intrin->src;
|
|
|
|
|
|
|
|
|
|
switch (use_intrin->intrinsic) {
|
|
|
|
|
case nir_intrinsic_read_invocation:
|
|
|
|
|
case nir_intrinsic_shuffle:
|
|
|
|
|
case nir_intrinsic_shuffle_up:
|
|
|
|
|
case nir_intrinsic_shuffle_down:
|
|
|
|
|
case nir_intrinsic_shuffle_xor:
|
|
|
|
|
case nir_intrinsic_quad_broadcast:
|
|
|
|
|
case nir_intrinsic_quad_swap_horizontal:
|
|
|
|
|
case nir_intrinsic_quad_swap_vertical:
|
|
|
|
|
case nir_intrinsic_quad_swap_diagonal:
|
|
|
|
|
if (src_idx == 0) {
|
2023-08-14 11:56:00 -05:00
|
|
|
bits_used |= ssa_def_bits_used(&use_intrin->def, recur);
|
2021-02-04 11:38:40 -06:00
|
|
|
} else {
|
|
|
|
|
if (use_intrin->intrinsic == nir_intrinsic_quad_broadcast) {
|
|
|
|
|
bits_used |= 3;
|
|
|
|
|
} else {
|
|
|
|
|
/* Subgroups larger than 128 are not a thing */
|
|
|
|
|
bits_used |= 127;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case nir_intrinsic_reduce:
|
|
|
|
|
case nir_intrinsic_inclusive_scan:
|
|
|
|
|
case nir_intrinsic_exclusive_scan:
|
|
|
|
|
assert(src_idx == 0);
|
|
|
|
|
switch (nir_intrinsic_reduction_op(use_intrin)) {
|
|
|
|
|
case nir_op_iadd:
|
|
|
|
|
case nir_op_imul:
|
|
|
|
|
case nir_op_ior:
|
|
|
|
|
case nir_op_iand:
|
|
|
|
|
case nir_op_ixor:
|
2023-08-14 11:56:00 -05:00
|
|
|
bits_used |= ssa_def_bits_used(&use_intrin->def, recur);
|
2021-02-04 11:38:40 -06:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
return all_bits;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
/* We don't know what this op does */
|
|
|
|
|
return all_bits;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case nir_instr_type_phi: {
|
2023-08-14 09:58:47 -04:00
|
|
|
nir_phi_instr *use_phi = nir_instr_as_phi(nir_src_parent_instr(src));
|
2023-08-14 11:56:00 -05:00
|
|
|
bits_used |= ssa_def_bits_used(&use_phi->def, recur);
|
2021-02-04 11:38:40 -06:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
return all_bits;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* If we've somehow shown that all our bits are used, we're done */
|
|
|
|
|
assert((bits_used & ~all_bits) == 0);
|
|
|
|
|
if (bits_used == all_bits)
|
|
|
|
|
return all_bits;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return bits_used;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uint64_t
|
2023-08-12 16:17:15 -04:00
|
|
|
nir_def_bits_used(const nir_def *def)
|
2021-02-04 11:38:40 -06:00
|
|
|
{
|
|
|
|
|
return ssa_def_bits_used(def, 2);
|
|
|
|
|
}
|
2025-08-13 10:56:51 +01:00
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
get_alu_num_lsb(struct analysis_state *state, struct scalar_query q, uint32_t *result, const uint32_t *src)
|
|
|
|
|
{
|
|
|
|
|
nir_op op = nir_scalar_alu_op(q.scalar);
|
|
|
|
|
|
|
|
|
|
switch (op) {
|
|
|
|
|
case nir_op_ior:
|
|
|
|
|
case nir_op_ixor:
|
|
|
|
|
case nir_op_iadd:
|
|
|
|
|
case nir_op_iand:
|
|
|
|
|
case nir_op_imul:
|
|
|
|
|
if (!q.head.pushed_queries) {
|
|
|
|
|
push_scalar_query(state, nir_scalar_chase_alu_src(q.scalar, 0));
|
|
|
|
|
push_scalar_query(state, nir_scalar_chase_alu_src(q.scalar, 1));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case nir_op_ishl:
|
|
|
|
|
if (!q.head.pushed_queries) {
|
|
|
|
|
push_scalar_query(state, nir_scalar_chase_alu_src(q.scalar, 0));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case nir_op_ishr:
|
|
|
|
|
case nir_op_ushr:
|
|
|
|
|
if (!q.head.pushed_queries) {
|
|
|
|
|
if (nir_scalar_is_const(nir_scalar_chase_alu_src(q.scalar, 1)))
|
|
|
|
|
push_scalar_query(state, nir_scalar_chase_alu_src(q.scalar, 0));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case nir_op_bcsel:
|
|
|
|
|
if (!q.head.pushed_queries) {
|
|
|
|
|
push_scalar_query(state, nir_scalar_chase_alu_src(q.scalar, 1));
|
|
|
|
|
push_scalar_query(state, nir_scalar_chase_alu_src(q.scalar, 2));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch (op) {
|
|
|
|
|
case nir_op_ior:
|
|
|
|
|
case nir_op_ixor:
|
|
|
|
|
case nir_op_iadd: {
|
|
|
|
|
*result = MIN2(src[0], src[1]);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case nir_op_iand: {
|
|
|
|
|
*result = MAX2(src[0], src[1]);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case nir_op_imul: {
|
|
|
|
|
*result = MIN2(src[0] + src[1], q.scalar.def->bit_size);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case nir_op_ishl: {
|
|
|
|
|
nir_scalar src1 = nir_scalar_chase_alu_src(q.scalar, 1);
|
|
|
|
|
uint32_t mask = q.scalar.def->bit_size - 1;
|
|
|
|
|
unsigned amount = nir_scalar_is_const(src1) ? nir_scalar_as_uint(src1) & mask : 0;
|
|
|
|
|
*result = MIN2(src[0] + amount, q.scalar.def->bit_size);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case nir_op_ishr:
|
|
|
|
|
case nir_op_ushr: {
|
|
|
|
|
nir_scalar src1 = nir_scalar_chase_alu_src(q.scalar, 1);
|
|
|
|
|
unsigned amount = nir_scalar_as_uint(src1) & (q.scalar.def->bit_size - 1);
|
|
|
|
|
*result = amount > src[0] ? 0 : src[0] - amount;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case nir_op_bcsel: {
|
|
|
|
|
*result = MIN2(src[0], src[1]);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
default:
|
|
|
|
|
UNREACHABLE("Unknown opcode");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
process_num_lsb_query(struct analysis_state *state, struct analysis_query *aq, uint32_t *result,
|
|
|
|
|
const uint32_t *src)
|
|
|
|
|
{
|
|
|
|
|
struct scalar_query q = *(struct scalar_query *)aq;
|
|
|
|
|
|
|
|
|
|
*result = 0;
|
|
|
|
|
if (nir_scalar_is_const(q.scalar)) {
|
|
|
|
|
uint64_t val = nir_scalar_as_uint(q.scalar);
|
|
|
|
|
*result = val ? ffsll(val) - 1 : q.scalar.def->bit_size;
|
|
|
|
|
} else if (nir_scalar_is_alu(q.scalar)) {
|
|
|
|
|
get_alu_num_lsb(state, q, result, src);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unsigned
|
|
|
|
|
nir_def_num_lsb_zero(struct hash_table *numlsb_ht, nir_scalar def)
|
|
|
|
|
{
|
|
|
|
|
struct scalar_query query_alloc[16];
|
|
|
|
|
uint32_t result_alloc[16];
|
|
|
|
|
|
|
|
|
|
struct analysis_state state;
|
|
|
|
|
state.shader = NULL;
|
|
|
|
|
state.range_ht = numlsb_ht;
|
|
|
|
|
util_dynarray_init_from_stack(&state.query_stack, query_alloc, sizeof(query_alloc));
|
|
|
|
|
util_dynarray_init_from_stack(&state.result_stack, result_alloc, sizeof(result_alloc));
|
|
|
|
|
state.query_size = sizeof(struct scalar_query);
|
|
|
|
|
state.get_key = &get_scalar_key;
|
2026-03-02 16:20:26 +00:00
|
|
|
state.lookup = &scalar_lookup,
|
|
|
|
|
state.insert = &scalar_insert,
|
2025-08-13 10:56:51 +01:00
|
|
|
state.process_query = &process_num_lsb_query;
|
|
|
|
|
|
|
|
|
|
push_scalar_query(&state, def);
|
|
|
|
|
|
2026-03-03 13:44:01 +00:00
|
|
|
_mesa_hash_table_set_deleted_key(numlsb_ht, (void *)(uintptr_t)UINT32_MAX);
|
2025-08-13 10:56:51 +01:00
|
|
|
return perform_analysis(&state);
|
|
|
|
|
}
|