diff --git a/src/intel/decoder/intel_batch_decoder.c b/src/intel/decoder/intel_batch_decoder.c index 227ca97bb56..1296939dbc4 100644 --- a/src/intel/decoder/intel_batch_decoder.c +++ b/src/intel/decoder/intel_batch_decoder.c @@ -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); diff --git a/src/util/u_math.h b/src/util/u_math.h index 54c2180f447..48bbe943999 100644 --- a/src/util/u_math.h +++ b/src/util/u_math.h @@ -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