From 4d653c7df9270b70ae55d6f5c1ec3f2c5a215056 Mon Sep 17 00:00:00 2001 From: Sil Vilerino Date: Thu, 9 Jan 2025 08:21:25 -0500 Subject: [PATCH] util: Fix warning C4244 'argument' : conversion from 'type1' to 'type2', possible loss of data Reviewed-By: Jesse Natalie Reviewed-by: Jesse Natalie Part-of: --- src/gallium/auxiliary/util/u_inlines.h | 10 +++++----- src/util/bitscan.h | 2 +- src/util/box.h | 10 +++++----- src/util/half_float.h | 2 +- src/util/simple_mtx.h | 4 ++-- src/util/u_atomic.h | 16 ++++++++-------- src/util/u_queue.h | 4 ++-- 7 files changed, 24 insertions(+), 24 deletions(-) diff --git a/src/gallium/auxiliary/util/u_inlines.h b/src/gallium/auxiliary/util/u_inlines.h index fefab6dffe4..c39577733a0 100644 --- a/src/gallium/auxiliary/util/u_inlines.h +++ b/src/gallium/auxiliary/util/u_inlines.h @@ -79,13 +79,13 @@ pipe_reference_described(struct pipe_reference *dst, if (dst != src) { /* bump the src.count first */ if (src) { - ASSERTED int count = p_atomic_inc_return(&src->count); + ASSERTED int64_t count = p_atomic_inc_return(&src->count); assert(count != 1); /* src had to be referenced */ debug_reference(src, get_desc, 1); } if (dst) { - int count = p_atomic_dec_return(&dst->count); + int64_t count = p_atomic_dec_return(&dst->count); assert(count != -1); /* dst had to be referenced */ debug_reference(dst, get_desc, -1); if (!count) @@ -171,7 +171,7 @@ pipe_resource_reference(struct pipe_resource **dst, struct pipe_resource *src) static inline void pipe_drop_resource_references(struct pipe_resource *dst, int num_refs) { - int count = p_atomic_add_return(&dst->reference.count, -num_refs); + int64_t count = p_atomic_add_return(&dst->reference.count, -num_refs); assert(count >= 0); /* Underflows shouldn't happen, but let's be safe. */ @@ -282,8 +282,8 @@ pipe_surface_reset(struct pipe_context *ctx, struct pipe_surface* ps, { pipe_resource_reference(&ps->texture, pt); ps->format = pt->format; - ps->width = u_minify(pt->width0, level); - ps->height = u_minify(pt->height0, level); + ps->width = (uint16_t)u_minify(pt->width0, level); + ps->height = (uint16_t)u_minify(pt->height0, level); ps->u.tex.level = level; ps->u.tex.first_layer = ps->u.tex.last_layer = layer; ps->context = ctx; diff --git a/src/util/bitscan.h b/src/util/bitscan.h index 01f6d80b1c3..e233ee257f6 100644 --- a/src/util/bitscan.h +++ b/src/util/bitscan.h @@ -367,7 +367,7 @@ util_bitcount64(uint64_t n) #ifdef HAVE___BUILTIN_POPCOUNTLL return __builtin_popcountll(n); #else - return util_bitcount(n) + util_bitcount(n >> 32); + return util_bitcount((unsigned)n) + util_bitcount((unsigned)(n >> 32)); #endif } diff --git a/src/util/box.h b/src/util/box.h index c073101118d..53b00079b7f 100644 --- a/src/util/box.h +++ b/src/util/box.h @@ -59,7 +59,7 @@ u_box_2d_zslice(unsigned x, unsigned y, unsigned z, { box->x = x; box->y = y; - box->z = z; + box->z = (int16_t)z; box->width = w; box->height = h; box->depth = 1; @@ -72,10 +72,10 @@ u_box_3d(unsigned x, unsigned y, unsigned z, { box->x = x; box->y = y; - box->z = z; + box->z = (int16_t)z; box->width = w; box->height = h; - box->depth = d; + box->depth = (int16_t)d; } /* Clips @dst to width @w and height @h. @@ -203,10 +203,10 @@ u_box_union_3d(struct pipe_box *dst, dst->width = MAX2(a->x + a->width, b->x + b->width) - x; dst->height = MAX2(a->y + a->height, b->y + b->height) - y; - dst->depth = MAX2(a->z + a->depth, b->z + b->depth) - z; + dst->depth = (int16_t) (MAX2(a->z + a->depth, b->z + b->depth) - z); dst->x = x; dst->y = y; - dst->z = z; + dst->z = (int16_t)z; } static inline bool diff --git a/src/util/half_float.h b/src/util/half_float.h index a74d9a632dc..fed99277d58 100644 --- a/src/util/half_float.h +++ b/src/util/half_float.h @@ -131,7 +131,7 @@ _mesa_half_is_negative(uint16_t h) struct float16_t { uint16_t bits; float16_t(float f) : bits(_mesa_float_to_half(f)) {} - float16_t(double d) : bits(_mesa_float_to_half(d)) {} + float16_t(double d) : bits(_mesa_float_to_half((float)d)) {} float16_t(uint16_t raw_bits) : bits(raw_bits) {} static float16_t one() { return float16_t(FP16_ONE); } static float16_t zero() { return float16_t(FP16_ZERO); } diff --git a/src/util/simple_mtx.h b/src/util/simple_mtx.h index cddf86e8315..1508bacb604 100644 --- a/src/util/simple_mtx.h +++ b/src/util/simple_mtx.h @@ -101,7 +101,7 @@ simple_mtx_destroy(ASSERTED simple_mtx_t *mtx) static inline void simple_mtx_lock(simple_mtx_t *mtx) { - uint32_t c; + int64_t c; c = p_atomic_cmpxchg(&mtx->val, 0, 1); @@ -122,7 +122,7 @@ simple_mtx_lock(simple_mtx_t *mtx) static inline void simple_mtx_unlock(simple_mtx_t *mtx) { - uint32_t c; + int64_t c; HG(ANNOTATE_RWLOCK_RELEASED(mtx, 1)); diff --git a/src/util/u_atomic.h b/src/util/u_atomic.h index 6d604a6de04..c9ce666c015 100644 --- a/src/util/u_atomic.h +++ b/src/util/u_atomic.h @@ -166,17 +166,17 @@ __forceinline short _interlockedadd16(short volatile * _Addend, short _Value) ((void) p_atomic_fetch_add((_v), (_i))) #define p_atomic_add_return(_v, _i) (\ - sizeof *(_v) == sizeof(char) ? _interlockedadd8 ((char *) (_v), (_i)) : \ - sizeof *(_v) == sizeof(short) ? _interlockedadd16((short *) (_v), (_i)) : \ - sizeof *(_v) == sizeof(long) ? _interlockedadd ((long *) (_v), (_i)) : \ - sizeof *(_v) == sizeof(__int64) ? _interlockedadd64((__int64 *)(_v), (_i)) : \ + sizeof *(_v) == sizeof(char) ? _interlockedadd8 ((char *) (_v), (char) (_i)) : \ + sizeof *(_v) == sizeof(short) ? _interlockedadd16((short *) (_v), (short) (_i)) : \ + sizeof *(_v) == sizeof(long) ? _interlockedadd ((long *) (_v), (long) (_i)) : \ + sizeof *(_v) == sizeof(__int64) ? _interlockedadd64((__int64 *)(_v), (__int64) (_i)) : \ (assert(!"should not get here"), 0)) #define p_atomic_fetch_add(_v, _i) (\ - sizeof *(_v) == sizeof(char) ? _InterlockedExchangeAdd8 ((char *) (_v), (_i)) : \ - sizeof *(_v) == sizeof(short) ? _InterlockedExchangeAdd16((short *) (_v), (_i)) : \ - sizeof *(_v) == sizeof(long) ? _InterlockedExchangeAdd ((long *) (_v), (_i)) : \ - sizeof *(_v) == sizeof(__int64) ? _interlockedexchangeadd64((__int64 *)(_v), (_i)) : \ + sizeof *(_v) == sizeof(char) ? _InterlockedExchangeAdd8 ((char *) (_v), (char) (_i)) : \ + sizeof *(_v) == sizeof(short) ? _InterlockedExchangeAdd16((short *) (_v), (short) (_i)) : \ + sizeof *(_v) == sizeof(long) ? _InterlockedExchangeAdd ((long *) (_v), (long) (_i)) : \ + sizeof *(_v) == sizeof(__int64) ? _interlockedexchangeadd64((__int64 *)(_v), (__int64) (_i)) : \ (assert(!"should not get here"), 0)) #define p_atomic_cmpxchg(_v, _old, _new) (\ diff --git a/src/util/u_queue.h b/src/util/u_queue.h index a1b26994365..7cbb89cdec3 100644 --- a/src/util/u_queue.h +++ b/src/util/u_queue.h @@ -87,7 +87,7 @@ util_queue_fence_destroy(struct util_queue_fence *fence) static inline void util_queue_fence_signal(struct util_queue_fence *fence) { - uint32_t val = p_atomic_xchg(&fence->val, 0); + uint32_t val = (uint32_t)p_atomic_xchg(&fence->val, 0); assert(val != 0); @@ -107,7 +107,7 @@ util_queue_fence_reset(struct util_queue_fence *fence) #ifdef NDEBUG fence->val = 1; #else - uint32_t v = p_atomic_xchg(&fence->val, 1); + uint32_t v = (uint32_t)p_atomic_xchg(&fence->val, 1); assert(v == 0); #endif }