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.
|
|
|
|
|
*/
|
|
|
|
|
#ifndef _NIR_RANGE_ANALYSIS_H_
|
|
|
|
|
#define _NIR_RANGE_ANALYSIS_H_
|
|
|
|
|
|
2026-03-02 15:44:38 +00:00
|
|
|
#include "util/bitset.h"
|
2025-02-07 00:58:16 +01:00
|
|
|
#include "util/u_hash_table.h"
|
2026-03-02 15:44:38 +00:00
|
|
|
#include "nir_defines.h"
|
2022-02-02 16:09:32 +01:00
|
|
|
|
2026-02-12 13:37:10 +01:00
|
|
|
#ifdef __cplusplus
|
|
|
|
|
extern "C" {
|
|
|
|
|
#endif
|
2018-01-23 09:48:43 +08:00
|
|
|
|
2026-03-02 15:32:41 +00:00
|
|
|
typedef struct {
|
2026-03-02 15:44:38 +00:00
|
|
|
nir_function_impl *impl;
|
2026-03-10 16:48:56 +00:00
|
|
|
uint16_t *arr;
|
2026-03-02 15:44:38 +00:00
|
|
|
BITSET_WORD *bitset;
|
|
|
|
|
uint32_t size;
|
|
|
|
|
int32_t max;
|
2026-03-02 15:32:41 +00:00
|
|
|
} nir_fp_analysis_state;
|
|
|
|
|
|
|
|
|
|
nir_fp_analysis_state nir_create_fp_analysis_state(nir_function_impl *impl);
|
|
|
|
|
void nir_invalidate_fp_analysis_state(nir_fp_analysis_state *state);
|
|
|
|
|
void nir_free_fp_analysis_state(nir_fp_analysis_state *state);
|
|
|
|
|
|
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
|
|
|
enum fp_class_bit {
|
|
|
|
|
FP_CLASS_NEG_INF = BITFIELD_BIT(0),
|
|
|
|
|
FP_CLASS_LT_NEG_ONE = BITFIELD_BIT(1),
|
|
|
|
|
FP_CLASS_NEG_ONE = BITFIELD_BIT(2),
|
|
|
|
|
FP_CLASS_LT_ZERO_GT_NEG_ONE = BITFIELD_BIT(3),
|
|
|
|
|
FP_CLASS_NEG_ZERO = BITFIELD_BIT(4),
|
|
|
|
|
FP_CLASS_POS_ZERO = BITFIELD_BIT(5),
|
|
|
|
|
FP_CLASS_GT_ZERO_LT_POS_ONE = BITFIELD_BIT(6),
|
|
|
|
|
FP_CLASS_POS_ONE = BITFIELD_BIT(7),
|
|
|
|
|
FP_CLASS_GT_POS_ONE = BITFIELD_BIT(8),
|
|
|
|
|
FP_CLASS_POS_INF = BITFIELD_BIT(9),
|
|
|
|
|
FP_CLASS_NAN = BITFIELD_BIT(10),
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* A floating-point value that can have non integer (fractional) values.
|
|
|
|
|
* Does not replace any of the values above.
|
|
|
|
|
*/
|
|
|
|
|
FP_CLASS_NON_INTEGRAL = BITFIELD_BIT(11),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#define FP_CLASS_UNKNOWN BITFIELD_MASK(12)
|
|
|
|
|
#define FP_CLASS_ANY_ZERO (FP_CLASS_NEG_ZERO | FP_CLASS_POS_ZERO)
|
|
|
|
|
#define FP_CLASS_ANY_INF (FP_CLASS_NEG_INF | FP_CLASS_POS_INF)
|
|
|
|
|
#define FP_CLASS_ANY_NEG_FINITE (FP_CLASS_LT_ZERO_GT_NEG_ONE | FP_CLASS_NEG_ONE | FP_CLASS_LT_NEG_ONE)
|
|
|
|
|
#define FP_CLASS_ANY_NEG (FP_CLASS_ANY_NEG_FINITE | FP_CLASS_NEG_INF)
|
|
|
|
|
#define FP_CLASS_ANY_POS_FINITE (FP_CLASS_GT_ZERO_LT_POS_ONE | FP_CLASS_POS_ONE | FP_CLASS_GT_POS_ONE)
|
|
|
|
|
#define FP_CLASS_ANY_POS (FP_CLASS_ANY_POS_FINITE | FP_CLASS_POS_INF)
|
|
|
|
|
#define FP_CLASS_ANY_FINITE (FP_CLASS_ANY_NEG_FINITE | FP_CLASS_ANY_ZERO | FP_CLASS_ANY_POS_FINITE)
|
|
|
|
|
#define FP_CLASS_ANY_NUMBER (FP_CLASS_ANY_FINITE | FP_CLASS_ANY_INF)
|
|
|
|
|
|
|
|
|
|
typedef uint16_t fp_class_mask;
|
|
|
|
|
|
|
|
|
|
fp_class_mask nir_analyze_fp_class(nir_fp_analysis_state *state, const nir_def *def);
|
|
|
|
|
|
2023-08-12 16:17:15 -04:00
|
|
|
uint64_t nir_def_bits_used(const nir_def *def);
|
2021-02-04 11:38:40 -06:00
|
|
|
|
2025-08-13 10:56:51 +01:00
|
|
|
unsigned nir_def_num_lsb_zero(struct hash_table *numlsb_ht, nir_scalar def);
|
|
|
|
|
|
2020-02-12 19:07:35 -08:00
|
|
|
#ifdef __cplusplus
|
|
|
|
|
}
|
|
|
|
|
#endif
|
2018-01-23 09:48:43 +08:00
|
|
|
#endif /* _NIR_RANGE_ANALYSIS_H_ */
|