shithub: dav1d

Download patch

ref: 35b1cde28a153b54e3534b8bae75319197dca2f2
parent: 4c21c9312d31300401554404b188478f8f25f404
author: Martin Storsjö <martin@martin.st>
date: Thu Feb 7 09:44:24 EST 2019

Add casts to silence warnings about intended type conversions/shortenings

--- a/src/decode.c
+++ b/src/decode.c
@@ -303,7 +303,7 @@
     if ((unsigned) masks[0] == 1 && !(masks[1] >> 32)) {
         const int off = t->bx & (bs(&r[-b4_stride])[0] - 1);
         add_sample(-off, 0, 1, -1, &r[-b4_stride]);
-    } else for (unsigned off = 0, xmask = masks[0]; np < 8 && xmask;) { // top
+    } else for (unsigned off = 0, xmask = (uint32_t) masks[0]; np < 8 && xmask;) { // top
         const int tz = ctz(xmask);
         off += tz;
         xmask >>= tz;
@@ -313,7 +313,7 @@
     if (np < 8 && masks[1] == 1) {
         const int off = t->by & (bs(&r[-1])[1] - 1);
         add_sample(0, -off, -1, 1, &r[-1 - off * b4_stride]);
-    } else for (unsigned off = 0, ymask = masks[1]; np < 8 && ymask;) { // left
+    } else for (unsigned off = 0, ymask = (uint32_t) masks[1]; np < 8 && ymask;) { // left
         const int tz = ctz(ymask);
         off += tz;
         ymask >>= tz;
@@ -2667,7 +2667,7 @@
             lr_ptr += lr_stride * 12;
         }
 
-        f->lf.lr_line_sz = lr_stride;
+        f->lf.lr_line_sz = (int) lr_stride;
     }
 
     // update allocation for loopfilter masks
--- a/src/env.h
+++ b/src/env.h
@@ -602,8 +602,8 @@
         }
 #undef MERGE_CTX
 
-        const int max = imin(la | ll, 4);
-        const int min = imin(imin(la, ll), 4);
+        const int max = imin((int) (la | ll), 4);
+        const int min = imin(imin((int) la, (int) ll), 4);
 
         return skip_contexts[min][max];
     }
--- a/src/getbits.c
+++ b/src/getbits.c
@@ -70,7 +70,7 @@
     c->bits_left -= n;
     c->state <<= n;
 
-    return state >> (64 - n);
+    return (unsigned) (state >> (64 - n));
 }
 
 int dav1d_get_sbits(GetBits *const c, const unsigned n) {
--- a/src/getbits.h
+++ b/src/getbits.h
@@ -52,7 +52,7 @@
 
 // Return the current bit position relative to the start of the buffer.
 static inline unsigned dav1d_get_bits_pos(const GetBits *c) {
-    return (c->ptr - c->ptr_start) * 8 - c->bits_left;
+    return (unsigned) (c->ptr - c->ptr_start) * 8 - c->bits_left;
 }
 
 #endif /* __DAV1D_SRC_GETBITS_H__ */
--- a/src/ipred_tmpl.c
+++ b/src/ipred_tmpl.c
@@ -719,7 +719,7 @@
 {
     for (int y = 0; y < h; y++) {
         for (int x = 0; x < w; x++)
-            dst[x] = pal[idx[x]];
+            dst[x] = (pixel) pal[idx[x]];
         idx += w;
         dst += PXSTRIDE(stride);
     }
--- a/src/lf_mask.c
+++ b/src/lf_mask.c
@@ -177,7 +177,7 @@
     // inner (tx) left|right edges
     const int hstep = t_dim->w;
     unsigned t = 1U << by4;
-    unsigned inner = (((uint64_t) t) << h4) - t;
+    unsigned inner = (unsigned) ((((uint64_t) t) << h4) - t);
     unsigned inner1 = inner & 0xffff, inner2 = inner >> 16;
     for (x = hstep; x < w4; x += hstep) {
         if (inner1) masks[0][bx4 + x][twl4c][0] |= inner1;
@@ -189,7 +189,7 @@
     //           bottom
     const int vstep = t_dim->h;
     t = 1U << bx4;
-    inner = (((uint64_t) t) << w4) - t;
+    inner = (unsigned) ((((uint64_t) t) << w4) - t);
     inner1 = inner & 0xffff;
     inner2 = inner >> 16;
     for (y = vstep; y < h4; y += vstep) {
@@ -248,7 +248,7 @@
         // inner (tx) left|right edges
         const int hstep = t_dim->w;
         unsigned t = 1U << cby4;
-        unsigned inner = (((uint64_t) t) << ch4) - t;
+        unsigned inner = (unsigned) ((((uint64_t) t) << ch4) - t);
         unsigned inner1 = inner & ((1 << vmask) - 1), inner2 = inner >> vmask;
         for (x = hstep; x < cw4; x += hstep) {
             if (inner1) masks[0][cbx4 + x][twl4c][0] |= inner1;
@@ -260,7 +260,7 @@
         //           bottom
         const int vstep = t_dim->h;
         t = 1U << cbx4;
-        inner = (((uint64_t) t) << cw4) - t;
+        inner = (unsigned) ((((uint64_t) t) << cw4) - t);
         inner1 = inner & ((1 << hmask) - 1), inner2 = inner >> hmask;
         for (y = vstep; y < ch4; y += vstep) {
             if (inner1) masks[1][cby4 + y][thl4c][0] |= inner1;
--- a/src/mc_tmpl.c
+++ b/src/mc_tmpl.c
@@ -829,20 +829,21 @@
                        const pixel *ref, const ptrdiff_t ref_stride)
 {
     // find offset in reference of visible block to copy
-    ref += iclip(y, 0, ih - 1) * PXSTRIDE(ref_stride) + iclip(x, 0, iw - 1);
+    ref += iclip((int) y, 0, (int) ih - 1) * PXSTRIDE(ref_stride) +
+           iclip((int) x, 0, (int) iw - 1);
 
     // number of pixels to extend (left, right, top, bottom)
-    const int left_ext = iclip(-x, 0, bw - 1);
-    const int right_ext = iclip(x + bw - iw, 0, bw - 1);
+    const int left_ext = iclip((int) -x, 0, (int) bw - 1);
+    const int right_ext = iclip((int) (x + bw - iw), 0, (int) bw - 1);
     assert(left_ext + right_ext < bw);
-    const int top_ext = iclip(-y, 0, bh - 1);
-    const int bottom_ext = iclip(y + bh - ih, 0, bh - 1);
+    const int top_ext = iclip((int) -y, 0, (int) bh - 1);
+    const int bottom_ext = iclip((int) (y + bh - ih), 0, (int) bh - 1);
     assert(top_ext + bottom_ext < bh);
 
     // copy visible portion first
     pixel *blk = dst + top_ext * PXSTRIDE(dst_stride);
-    const int center_w = bw - left_ext - right_ext;
-    const int center_h = bh - top_ext - bottom_ext;
+    const int center_w = (int) (bw - left_ext - right_ext);
+    const int center_h = (int) (bh - top_ext - bottom_ext);
     for (int y = 0; y < center_h; y++) {
         pixel_copy(blk + left_ext, ref, center_w);
         // extend left edge for this line
--- a/src/msac.c
+++ b/src/msac.c
@@ -88,7 +88,7 @@
 
     assert(u <= s->rng);
 
-    ctx_norm(s, s->dif - (v << (EC_WIN_SIZE - 16)), u - v);
+    ctx_norm(s, s->dif - (v << (EC_WIN_SIZE - 16)), (unsigned) (u - v));
     return ret - 1;
 }
 
@@ -104,7 +104,7 @@
     ret  = dif >= vw;
     dif -= ret*vw;
     v   += ret*(r - 2*v);
-    ctx_norm(s, dif, v);
+    ctx_norm(s, dif, (unsigned) v);
     return !ret;
 }
 
@@ -121,7 +121,7 @@
     ret  = dif >= vw;
     dif -= ret*vw;
     v   += ret*(r - 2*v);
-    ctx_norm(s, dif, v);
+    ctx_norm(s, dif, (unsigned) v);
     return !ret;
 }
 
--- a/src/obu.c
+++ b/src/obu.c
@@ -1198,7 +1198,7 @@
             if (more && ++i == 8) goto error;
         } while (more);
     else
-        len = in->sz - 1 - has_extension;
+        len = (int) in->sz - 1 - has_extension;
     if (gb.error) goto error;
 
     const unsigned init_bit_pos = dav1d_get_bits_pos(&gb);
--- a/src/recon_tmpl.c
+++ b/src/recon_tmpl.c
@@ -200,7 +200,8 @@
             } while (tok < 15);
         }
 
-        levels[x * stride + y] = cf[rc] = tok;
+        cf[rc] = tok;
+        levels[x * stride + y] = (uint8_t) cf[rc];
     }
 
     // residual and sign
@@ -559,7 +560,7 @@
         int orig_pos_x = (bx * h_mul << 4) + mvx * (1 << !ss_hor);
 #define scale_mv(res, val, scale) do { \
             const int64_t tmp = (int64_t)(val) * scale + (scale - 0x4000) * 8; \
-            res = (int)apply_sign64((llabs(tmp) + 128) >> 8, tmp) + 32; \
+            res = apply_sign64((int) ((llabs(tmp) + 128) >> 8), tmp) + 32;     \
         } while (0)
         int pos_y, pos_x;
         scale_mv(pos_x, orig_pos_x, f->svc[refidx][0].scale);
--- a/src/ref_mvs.c
+++ b/src/ref_mvs.c
@@ -1916,7 +1916,7 @@
 {
     const int bw4 = dav1d_block_dimensions[bs][0];
     const int bh4 = dav1d_block_dimensions[bs][1];
-    int stride = cm->cur_frame.mv_stride;
+    int stride = (int) cm->cur_frame.mv_stride;
     MACROBLOCKD xd = (MACROBLOCKD) {
         .n8_w = bw4,
         .n8_h = bh4,
@@ -2018,7 +2018,7 @@
             cm->frame_refs[i].idx = i;
         cm->mi_cols = w8 << 1;
         cm->mi_rows = h8 << 1;
-        cm->mi_stride = stride;
+        cm->mi_stride = (int) stride;
         for (int i = 0; i < 7; i++) {
             cm->buffer_pool.frame_bufs[i].mi_rows = cm->mi_rows;
             cm->buffer_pool.frame_bufs[i].mi_cols = cm->mi_cols;
--- a/src/thread_task.c
+++ b/src/thread_task.c
@@ -59,7 +59,7 @@
     Dav1dTileContext *const t = data;
     struct FrameTileThreadData *const fttd = t->tile_thread.fttd;
     const Dav1dFrameContext *const f = t->f;
-    const int tile_thread_idx = t - f->tc;
+    const int tile_thread_idx = (int) (t - f->tc);
     const uint64_t mask = 1ULL << tile_thread_idx;
 
     for (;;) {
--- a/src/warpmv.c
+++ b/src/warpmv.c
@@ -90,10 +90,10 @@
     const int y = apply_sign(resolve_divisor_32(abs(mat[2]), &shift), mat[2]);
     const int64_t v1 = ((int64_t) mat[4] * 0x10000) * y;
     const int rnd = (1 << shift) >> 1;
-    wm->gamma = iclip_wmp(apply_sign64((llabs(v1) + rnd) >> shift, v1));
+    wm->gamma = iclip_wmp(apply_sign64((int) ((llabs(v1) + rnd) >> shift), v1));
     const int64_t v2 = ((int64_t) mat[3] * mat[4]) * y;
     wm->delta = iclip_wmp(mat[5] -
-                          (int) apply_sign64((llabs(v2) + rnd) >> shift, v2) -
+                          apply_sign64((int) ((llabs(v2) + rnd) >> shift), v2) -
                           0x10000);
 
     return (4 * abs(wm->alpha) + 7 * abs(wm->beta) >= 0x10000) ||
@@ -115,7 +115,9 @@
                                 const int idet, const int shift)
 {
     const int64_t v1 = px * idet;
-    const int v2 = apply_sign64((llabs(v1) + ((1LL << shift) >> 1)) >> shift, v1);
+    const int v2 = apply_sign64((int) ((llabs(v1) +
+                                        ((1LL << shift) >> 1)) >> shift),
+                                v1);
     return iclip(v2, -0x1fff, 0x1fff);
 }
 
@@ -123,7 +125,9 @@
                                const int idet, const int shift)
 {
     const int64_t v1 = px * idet;
-    const int v2 = apply_sign64((llabs(v1) + ((1LL << shift) >> 1)) >> shift, v1);
+    const int v2 = apply_sign64((int) ((llabs(v1) +
+                                        ((1LL << shift) >> 1)) >> shift),
+                                v1);
     return iclip(v2, 0xe001, 0x11fff);
 }
 
--- a/tests/checkasm/checkasm.c
+++ b/tests/checkasm/checkasm.c
@@ -53,7 +53,7 @@
 static unsigned get_seed(void) {
     struct timeval tv;
     gettimeofday(&tv, NULL);
-    return tv.tv_usec + tv.tv_sec * 1000000;
+    return (unsigned) (tv.tv_usec + tv.tv_sec * 1000000);
 }
 #endif
 
@@ -325,7 +325,7 @@
 
     for (i = 0; i < 10000; i++) {
         uint64_t t = readtime();
-        nops[i] = readtime() - t;
+        nops[i] = (uint16_t) (readtime() - t);
     }
 
     qsort(nops, 10000, sizeof(uint16_t), cmp_nop);
@@ -345,8 +345,8 @@
             const CheckasmFuncVersion *v = &f->versions;
             do {
                 if (v->iterations) {
-                    int decicycles = (10*v->cycles/v->iterations -
-                                      state.nop_time) / 4;
+                    int decicycles = (int) (10*v->cycles/v->iterations -
+                                            state.nop_time) / 4;
                     printf("%s_%s: %d.%d\n", f->name, cpu_suffix(v->cpu),
                            decicycles/10, decicycles%10);
                 }
--- a/tests/checkasm/itx.c
+++ b/tests/checkasm/itx.c
@@ -215,7 +215,7 @@
 
     for (int y = 0; y < sh; y++)
         for (int x = 0; x < sw; x++)
-            buf[y * sw + x] = out[y * w + x] + 0.5;
+            buf[y * sw + x] = (coef) (out[y * w + x] + 0.5);
 
     return copy_subcoefs(buf, tx, txtp, sw, sh, subsh);
 }