mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-03-12 22:00:31 +01:00
util,intel: move probably_float to common code
This helper is generally useful when trying to prettyprint a 32-bit value, so make it available to the rest of the tree. Signed-off-by: Alyssa Rosenzweig <alyssa.rosenzweig@intel.com> Reviewed-by: Mary Guillemard <mary@mary.zone> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/40021>
This commit is contained in:
parent
48c685ee39
commit
da4296c27c
2 changed files with 25 additions and 26 deletions
|
|
@ -183,31 +183,6 @@ ctx_disassemble_program(struct intel_batch_decode_ctx *ctx,
|
|||
ctx->disassemble_program(ctx, ksp, short_name, name);
|
||||
}
|
||||
|
||||
/* Heuristic to determine whether a uint32_t is probably actually a float
|
||||
* (http://stackoverflow.com/a/2953466)
|
||||
*/
|
||||
|
||||
static bool
|
||||
probably_float(uint32_t bits)
|
||||
{
|
||||
int exp = ((bits & 0x7f800000U) >> 23) - 127;
|
||||
uint32_t mant = bits & 0x007fffff;
|
||||
|
||||
/* +- 0.0 */
|
||||
if (exp == -127 && mant == 0)
|
||||
return true;
|
||||
|
||||
/* +- 1 billionth to 1 billion */
|
||||
if (-30 <= exp && exp <= 30)
|
||||
return true;
|
||||
|
||||
/* some value with only a few binary digits */
|
||||
if ((mant & 0x0000ffff) == 0)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static void
|
||||
ctx_print_buffer(struct intel_batch_decode_ctx *ctx,
|
||||
struct intel_batch_decode_bo bo,
|
||||
|
|
@ -232,7 +207,7 @@ ctx_print_buffer(struct intel_batch_decode_ctx *ctx,
|
|||
}
|
||||
fprintf(ctx->fp, column_count == 0 ? " " : " ");
|
||||
|
||||
if ((ctx->flags & INTEL_BATCH_DECODE_FLOATS) && probably_float(*dw))
|
||||
if ((ctx->flags & INTEL_BATCH_DECODE_FLOATS) && util_is_probably_float(*dw))
|
||||
fprintf(ctx->fp, " %8.2f", *(float *) dw);
|
||||
else
|
||||
fprintf(ctx->fp, " 0x%08x", *dw);
|
||||
|
|
|
|||
|
|
@ -873,6 +873,30 @@ util_is_sint16(int x)
|
|||
return x >= INT16_MIN && x <= INT16_MAX;
|
||||
}
|
||||
|
||||
/* Heuristic to determine whether a uint32_t is probably actually a float
|
||||
* (http://stackoverflow.com/a/2953466)
|
||||
*/
|
||||
static inline bool
|
||||
util_is_probably_float(uint32_t bits)
|
||||
{
|
||||
int exp = ((bits & 0x7f800000U) >> 23) - 127;
|
||||
uint32_t mant = bits & 0x007fffff;
|
||||
|
||||
/* +- 0.0 */
|
||||
if (exp == -127 && mant == 0)
|
||||
return true;
|
||||
|
||||
/* +- 1 billionth to 1 billion */
|
||||
if (-30 <= exp && exp <= 30)
|
||||
return true;
|
||||
|
||||
/* some value with only a few binary digits */
|
||||
if ((mant & 0x0000ffff) == 0)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue