Allows compiler to do its job and optimize this code. We don't really want to repack in-place.
Unified · Split
| @@ -63,14 +63,14 @@ struct mp_repack { · 62 unmodified lines | ||
| 63 | 63 | int components[4]; // b[n] = mp_image.planes[components[n]] |
| 64 | 64 | // pack: a is dst, b is src |
| 65 | 65 | // unpack: a is src, b is dst |
| 66 | − void (*packed_repack_scanline)(void *a, void *b[], int w); | |
| 66 | + void (*packed_repack_scanline)(void *restrict a, void *restrict b[], int w); | |
| 67 | 67 | |
| 68 | 68 | // Fringe RGB/YUV. |
| 69 | 69 | uint8_t comp_size; |
| 70 | 70 | uint8_t comp_map[6]; |
| 71 | 71 | uint8_t comp_shifts[3]; |
| 72 | 72 | uint8_t *comp_lut; |
| 73 | − void (*repack_fringe_yuv)(void *dst, void *src[], int w, uint8_t *c); | |
| 73 | + void (*repack_fringe_yuv)(void *restrict dst, void *restrict src[], int w, uint8_t *restrict c); | |
| 74 | 74 | |
| 75 | 75 | // F32 repacking. |
| 76 | 76 | int f32_comp_size; |
| @@ -133,8 +133,8 @@ static void copy_plane(struct mp_image *dst, int dst_x, int dst_y, · 56 unmodified lines | ||
| 133 | 133 | assert(dst->fmt.bpp[p] == src->fmt.bpp[p]); |
| 134 | 134 | |
| 135 | 135 | for (int y = 0; y < h; y++) { |
| 136 | − void *pd = mp_image_pixel_ptr_ny(dst, p, dst_x, dst_y + y); | |
| 137 | − void *ps = mp_image_pixel_ptr_ny(src, p, src_x, src_y + y); | |
| 136 | + void *restrict pd = mp_image_pixel_ptr_ny(dst, p, dst_x, dst_y + y); | |
| 137 | + void *restrict ps = mp_image_pixel_ptr_ny(src, p, src_x, src_y + y); | |
| 138 | 138 | memcpy(pd, ps, size); |
| 139 | 139 | } |
| 140 | 140 | } |
| @@ -157,8 +157,8 @@ static void swap_endian(struct mp_image *dst, int dst_x, int dst_y, · 16 unmodified lines | ||
| 157 | 157 | assert(src->fmt.bpp[p] == bpp * 8); |
| 158 | 158 | |
| 159 | 159 | for (int y = 0; y < h; y++) { |
| 160 | − void *s = mp_image_pixel_ptr_ny(src, p, src_x, src_y + y); | |
| 161 | − void *d = mp_image_pixel_ptr_ny(dst, p, dst_x, dst_y + y); | |
| 160 | + void *restrict s = mp_image_pixel_ptr_ny(src, p, src_x, src_y + y); | |
| 161 | + void *restrict d = mp_image_pixel_ptr_ny(dst, p, dst_x, dst_y + y); | |
| 162 | 162 | switch (endian_size) { |
| 163 | 163 | case 2: |
| 164 | 164 | for (int x = 0; x < num_words; x++) |
| @@ -191,7 +191,7 @@ static void swap_endian(struct mp_image *dst, int dst_x, int dst_y, · 26 unmodified lines | ||
| 191 | 191 | // packers will use "z" because they write zero. |
| 192 | 192 | |
| 193 | 193 | #define PA_WORD_4(name, packed_t, plane_t, sh_c0, sh_c1, sh_c2, sh_c3) \ |
| 194 | − static void name(void *dst, void *src[], int w) { \ | |
| 194 | + static void name(void *restrict dst, void *restrict src[], int w) { \ | |
| 195 | 195 | for (int x = 0; x < w; x++) { \ |
| 196 | 196 | ((packed_t *)dst)[x] = \ |
| 197 | 197 | ((packed_t)((plane_t *)src[0])[x] << (sh_c0)) | \ |
| @@ -202,7 +202,7 @@ static void swap_endian(struct mp_image *dst, int dst_x, int dst_y, · 4 unmodified lines | ||
| 202 | 202 | } |
| 203 | 203 | |
| 204 | 204 | #define UN_WORD_4(name, packed_t, plane_t, sh_c0, sh_c1, sh_c2, sh_c3, mask)\ |
| 205 | − static void name(void *src, void *dst[], int w) { \ | |
| 205 | + static void name(void *restrict src, void *restrict dst[], int w) { \ | |
| 206 | 206 | for (int x = 0; x < w; x++) { \ |
| 207 | 207 | packed_t c = ((packed_t *)src)[x]; \ |
| 208 | 208 | ((plane_t *)dst[0])[x] = (c >> (sh_c0)) & (mask); \ |
| @@ -214,7 +214,7 @@ static void swap_endian(struct mp_image *dst, int dst_x, int dst_y, · 5 unmodified lines | ||
| 214 | 214 | |
| 215 | 215 | |
| 216 | 216 | #define PA_WORD_3(name, packed_t, plane_t, sh_c0, sh_c1, sh_c2, pad) \ |
| 217 | − static void name(void *dst, void *src[], int w) { \ | |
| 217 | + static void name(void *restrict dst, void *restrict src[], int w) { \ | |
| 218 | 218 | for (int x = 0; x < w; x++) { \ |
| 219 | 219 | ((packed_t *)dst)[x] = (pad) | \ |
| 220 | 220 | ((packed_t)((plane_t *)src[0])[x] << (sh_c0)) | \ |
| @@ -230,7 +230,7 @@ UN_WORD_4(un_cccc16, uint64_t, uint16_t, 0, 16, 32, 48, 0xFFFFu) · 9 unmodified lines | ||
| 230 | 230 | PA_WORD_4(pa_cccc16, uint64_t, uint16_t, 0, 16, 32, 48) |
| 231 | 231 | |
| 232 | 232 | #define UN_WORD_3(name, packed_t, plane_t, sh_c0, sh_c1, sh_c2, mask) \ |
| 233 | − static void name(void *src, void *dst[], int w) { \ | |
| 233 | + static void name(void *restrict src, void *restrict dst[], int w) { \ | |
| 234 | 234 | for (int x = 0; x < w; x++) { \ |
| 235 | 235 | packed_t c = ((packed_t *)src)[x]; \ |
| 236 | 236 | ((plane_t *)dst[0])[x] = (c >> (sh_c0)) & (mask); \ |
| @@ -249,7 +249,7 @@ UN_WORD_3(un_ccc16x16, uint64_t, uint16_t, 0, 16, 32, 0xFFFFu) · 12 unmodified lines | ||
| 249 | 249 | PA_WORD_3(pa_ccc16z16, uint64_t, uint16_t, 0, 16, 32, 0) |
| 250 | 250 | |
| 251 | 251 | #define PA_WORD_2(name, packed_t, plane_t, sh_c0, sh_c1, pad) \ |
| 252 | − static void name(void *dst, void *src[], int w) { \ | |
| 252 | + static void name(void *restrict dst, void *restrict src[], int w) { \ | |
| 253 | 253 | for (int x = 0; x < w; x++) { \ |
| 254 | 254 | ((packed_t *)dst)[x] = (pad) | \ |
| 255 | 255 | ((packed_t)((plane_t *)src[0])[x] << (sh_c0)) | \ |
| @@ -258,7 +258,7 @@ PA_WORD_3(pa_ccc16z16, uint64_t, uint16_t, 0, 16, 32, 0) · 2 unmodified lines | ||
| 258 | 258 | } |
| 259 | 259 | |
| 260 | 260 | #define UN_WORD_2(name, packed_t, plane_t, sh_c0, sh_c1, mask) \ |
| 261 | − static void name(void *src, void *dst[], int w) { \ | |
| 261 | + static void name(void *restrict src, void *restrict dst[], int w) { \ | |
| 262 | 262 | for (int x = 0; x < w; x++) { \ |
| 263 | 263 | packed_t c = ((packed_t *)src)[x]; \ |
| 264 | 264 | ((plane_t *)dst[0])[x] = (c >> (sh_c0)) & (mask); \ |
| @@ -272,7 +272,7 @@ UN_WORD_2(un_cc16, uint32_t, uint16_t, 0, 16, 0xFFFFu) · 7 unmodified lines | ||
| 272 | 272 | PA_WORD_2(pa_cc16, uint32_t, uint16_t, 0, 16, 0) |
| 273 | 273 | |
| 274 | 274 | #define PA_SEQ_3(name, comp_t) \ |
| 275 | − static void name(void *dst, void *src[], int w) { \ | |
| 275 | + static void name(void *restrict dst, void *restrict src[], int w) { \ | |
| 276 | 276 | comp_t *r = dst; \ |
| 277 | 277 | for (int x = 0; x < w; x++) { \ |
| 278 | 278 | *r++ = ((comp_t *)src[0])[x]; \ |
| @@ -282,7 +282,7 @@ PA_WORD_2(pa_cc16, uint32_t, uint16_t, 0, 16, 0) · 3 unmodified lines | ||
| 282 | 282 | } |
| 283 | 283 | |
| 284 | 284 | #define UN_SEQ_3(name, comp_t) \ |
| 285 | − static void name(void *src, void *dst[], int w) { \ | |
| 285 | + static void name(void *restrict src, void *restrict dst[], int w) { \ | |
| 286 | 286 | comp_t *r = src; \ |
| 287 | 287 | for (int x = 0; x < w; x++) { \ |
| 288 | 288 | ((comp_t *)dst[0])[x] = *r++; \ |
| @@ -302,8 +302,8 @@ struct regular_repacker { · 13 unmodified lines | ||
| 302 | 302 | int component_width; // number of bits for a single component |
| 303 | 303 | int prepadding; // number of bits of LSB padding |
| 304 | 304 | int num_components; // number of components that can be accessed |
| 305 | − void (*pa_scanline)(void *a, void *b[], int w); | |
| 306 | − void (*un_scanline)(void *a, void *b[], int w); | |
| 305 | + void (*pa_scanline)(void *restrict a, void *restrict b[], int w); | |
| 306 | + void (*un_scanline)(void *restrict a, void *restrict b[], int w); | |
| 307 | 307 | }; |
| 308 | 308 | |
| 309 | 309 | static const struct regular_repacker regular_repackers[] = { |
| @@ -384,7 +384,7 @@ static void setup_packed_packer(struct mp_repack *rp) · 74 unmodified lines | ||
| 384 | 384 | |
| 385 | 385 | int prepad = components[0] ? 0 : 8; |
| 386 | 386 | int first_comp = components[0] ? 0 : 1; |
| 387 | − void (*repack_cb)(void *pa, void *pb[], int w) = | |
| 387 | + void (*repack_cb)(void *restrict pa, void *restrict pb[], int w) = | |
| 388 | 388 | rp->pack ? pa->pa_scanline : pa->un_scanline; |
| 389 | 389 | |
| 390 | 390 | if (pa->packed_width != desc.bpp[0] || |
| @@ -408,8 +408,8 @@ static void setup_packed_packer(struct mp_repack *rp) · 17 unmodified lines | ||
| 408 | 408 | } |
| 409 | 409 | |
| 410 | 410 | #define PA_SHIFT_LUT8(name, packed_t) \ |
| 411 | − static void name(void *dst, void *src[], int w, uint8_t *lut, \ | |
| 412 | − uint8_t s0, uint8_t s1, uint8_t s2) { \ | |
| 411 | + static void name(void *restrict dst, void *restrict src[], int w, \ | |
| 412 | + uint8_t *restrict lut, uint8_t s0, uint8_t s1, uint8_t s2) { \ | |
| 413 | 413 | for (int x = 0; x < w; x++) { \ |
| 414 | 414 | ((packed_t *)dst)[x] = \ |
| 415 | 415 | (lut[((uint8_t *)src[0])[x] + 256 * 0] << s0) | \ |
| @@ -420,8 +420,8 @@ static void setup_packed_packer(struct mp_repack *rp) · 4 unmodified lines | ||
| 420 | 420 | |
| 421 | 421 | |
| 422 | 422 | #define UN_SHIFT_LUT8(name, packed_t) \ |
| 423 | − static void name(void *src, void *dst[], int w, uint8_t *lut, \ | |
| 424 | − uint8_t s0, uint8_t s1, uint8_t s2) { \ | |
| 423 | + static void name(void *restrict src, void *restrict dst[], int w, \ | |
| 424 | + uint8_t *restrict lut, uint8_t s0, uint8_t s1, uint8_t s2) { \ | |
| 425 | 425 | for (int x = 0; x < w; x++) { \ |
| 426 | 426 | packed_t c = ((packed_t *)src)[x]; \ |
| 427 | 427 | ((uint8_t *)dst[0])[x] = lut[((c >> s0) & 0xFF) + 256 * 0]; \ |
| @@ -449,7 +449,7 @@ static void fringe_rgb_repack(struct mp_repack *rp, · 21 unmodified lines | ||
| 449 | 449 | |
| 450 | 450 | assert(rp->comp_size == 1 || rp->comp_size == 2); |
| 451 | 451 | |
| 452 | − void (*repack)(void *pa, void *pb[], int w, uint8_t *lut, | |
| 452 | + void (*repack)(void *restrict pa, void *restrict pb[], int w, uint8_t *restrict lut, | |
| 453 | 453 | uint8_t s0, uint8_t s1, uint8_t s2) = NULL; |
| 454 | 454 | if (rp->pack) { |
| 455 | 455 | repack = rp->comp_size == 1 ? pa_shift_lut8_8 : pa_shift_lut8_16; |
| @@ -525,10 +525,10 @@ static void unpack_pal(struct mp_repack *rp, · 69 unmodified lines | ||
| 525 | 525 | struct mp_image *a, int a_x, int a_y, |
| 526 | 526 | struct mp_image *b, int b_x, int b_y, int w) |
| 527 | 527 | { |
| 528 | − uint8_t *src = mp_image_pixel_ptr(a, 0, a_x, a_y); | |
| 528 | + uint8_t *restrict src = mp_image_pixel_ptr(a, 0, a_x, a_y); | |
| 529 | 529 | uint32_t *pal = (void *)a->planes[1]; |
| 530 | 530 | |
| 531 | − uint8_t *dst[4] = {0}; | |
| 531 | + uint8_t *restrict dst[4] = {0}; | |
| 532 | 532 | for (int p = 0; p < b->num_planes; p++) |
| 533 | 533 | dst[p] = mp_image_pixel_ptr(b, p, b_x, b_y); |
| 534 | 534 | |
| @@ -545,8 +545,8 @@ static void bitmap_repack(struct mp_repack *rp, · 10 unmodified lines | ||
| 545 | 545 | struct mp_image *a, int a_x, int a_y, |
| 546 | 546 | struct mp_image *b, int b_x, int b_y, int w) |
| 547 | 547 | { |
| 548 | − uint8_t *pa = mp_image_pixel_ptr(a, 0, a_x, a_y); | |
| 549 | − uint8_t *pb = mp_image_pixel_ptr(b, 0, b_x, b_y); | |
| 548 | + uint8_t *restrict pa = mp_image_pixel_ptr(a, 0, a_x, a_y); | |
| 549 | + uint8_t *restrict pb = mp_image_pixel_ptr(b, 0, b_x, b_y); | |
| 550 | 550 | |
| 551 | 551 | if (rp->pack) { |
| 552 | 552 | for (unsigned x = 0; x < w; x += 8) { |
| @@ -596,7 +596,7 @@ static void setup_misc_packer(struct mp_repack *rp) · 43 unmodified lines | ||
| 596 | 596 | } |
| 597 | 597 | |
| 598 | 598 | #define PA_P422(name, comp_t) \ |
| 599 | − static void name(void *dst, void *src[], int w, uint8_t *c) { \ | |
| 599 | + static void name(void *restrict dst, void *restrict src[], int w, uint8_t *restrict c) { \ | |
| 600 | 600 | for (int x = 0; x < w; x += 2) { \ |
| 601 | 601 | ((comp_t *)dst)[x * 2 + c[0]] = ((comp_t *)src[0])[x + 0]; \ |
| 602 | 602 | ((comp_t *)dst)[x * 2 + c[1]] = ((comp_t *)src[0])[x + 1]; \ |
| @@ -607,7 +607,7 @@ static void setup_misc_packer(struct mp_repack *rp) · 4 unmodified lines | ||
| 607 | 607 | |
| 608 | 608 | |
| 609 | 609 | #define UN_P422(name, comp_t) \ |
| 610 | − static void name(void *src, void *dst[], int w, uint8_t *c) { \ | |
| 610 | + static void name(void *restrict src, void *restrict dst[], int w, uint8_t *restrict c) { \ | |
| 611 | 611 | for (int x = 0; x < w; x += 2) { \ |
| 612 | 612 | ((comp_t *)dst[0])[x + 0] = ((comp_t *)src)[x * 2 + c[0]]; \ |
| 613 | 613 | ((comp_t *)dst[0])[x + 1] = ((comp_t *)src)[x * 2 + c[1]]; \ |
| @@ -621,7 +621,7 @@ PA_P422(pa_p422_16, uint16_t) · 7 unmodified lines | ||
| 621 | 621 | UN_P422(un_p422_8, uint8_t) |
| 622 | 622 | UN_P422(un_p422_16, uint16_t) |
| 623 | 623 | |
| 624 | −static void pa_p411_8(void *dst, void *src[], int w, uint8_t *c) | |
| 624 | +static void pa_p411_8(void *restrict dst, void *restrict src[], int w, uint8_t *restrict c) | |
| 625 | 625 | { |
| 626 | 626 | for (int x = 0; x < w; x += 4) { |
| 627 | 627 | ((uint8_t *)dst)[x / 4 * 6 + c[0]] = ((uint8_t *)src[0])[x + 0]; |
| @@ -634,7 +634,7 @@ static void pa_p411_8(void *dst, void *src[], int w, uint8_t *c) · 6 unmodified lines | ||
| 634 | 634 | } |
| 635 | 635 | |
| 636 | 636 | |
| 637 | −static void un_p411_8(void *src, void *dst[], int w, uint8_t *c) | |
| 637 | +static void un_p411_8(void *restrict src, void *restrict dst[], int w, uint8_t *restrict c) | |
| 638 | 638 | { |
| 639 | 639 | for (int x = 0; x < w; x += 4) { |
| 640 | 640 | ((uint8_t *)dst[0])[x + 0] = ((uint8_t *)src)[x / 4 * 6 + c[0]]; |
| @@ -773,7 +773,7 @@ static void setup_nv_packer(struct mp_repack *rp) · 132 unmodified lines | ||
| 773 | 773 | for (int i = 0; i < MP_ARRAY_SIZE(regular_repackers); i++) { |
| 774 | 774 | const struct regular_repacker *pa = ®ular_repackers[i]; |
| 775 | 775 | |
| 776 | − void (*repack_cb)(void *pa, void *pb[], int w) = | |
| 776 | + void (*repack_cb)(void *restrict pa, void *restrict pb[], int w) = | |
| 777 | 777 | rp->pack ? pa->pa_scanline : pa->un_scanline; |
| 778 | 778 | |
| 779 | 779 | if (pa->packed_width != desc.component_size * 2 * 8 || |
| @@ -794,8 +794,8 @@ static void setup_nv_packer(struct mp_repack *rp) · 14 unmodified lines | ||
| 794 | 794 | } |
| 795 | 795 | |
| 796 | 796 | #define PA_F32(name, packed_t) \ |
| 797 | − static void name(void *dst, float *src, int w, float m, float o, \ | |
| 798 | − uint32_t p_max) { \ | |
| 797 | + static void name(void *restrict dst, float *restrict src, int w, float m, \ | |
| 798 | + float o, uint32_t p_max) { \ | |
| 799 | 799 | for (int x = 0; x < w; x++) { \ |
| 800 | 800 | ((packed_t *)dst)[x] = \ |
| 801 | 801 | MPCLAMP(lrint((src[x] + o) * m), 0, (packed_t)p_max); \ |
| @@ -803,8 +803,8 @@ static void setup_nv_packer(struct mp_repack *rp) · 1 unmodified line | ||
| 803 | 803 | } |
| 804 | 804 | |
| 805 | 805 | #define UN_F32(name, packed_t) \ |
| 806 | − static void name(void *src, float *dst, int w, float m, float o, \ | |
| 807 | − uint32_t unused) { \ | |
| 806 | + static void name(void *restrict src, float *restrict dst, int w, float m, \ | |
| 807 | + float o, uint32_t unused) { \ | |
| 808 | 808 | for (int x = 0; x < w; x++) \ |
| 809 | 809 | dst[x] = ((packed_t *)src)[x] * m + o; \ |
| 810 | 810 | } |
| @@ -821,7 +821,7 @@ static void repack_float(struct mp_repack *rp, · 10 unmodified lines | ||
| 821 | 821 | { |
| 822 | 822 | assert(rp->f32_comp_size == 1 || rp->f32_comp_size == 2); |
| 823 | 823 | |
| 824 | − void (*packer)(void *a, float *b, int w, float fm, float fb, uint32_t max) | |
| 824 | + void (*packer)(void *restrict a, float *restrict b, int w, float fm, float fb, uint32_t max) | |
| 825 | 825 | = rp->pack ? (rp->f32_comp_size == 1 ? pa_f32_8 : pa_f32_16) |
| 826 | 826 | : (rp->f32_comp_size == 1 ? un_f32_8 : un_f32_16); |
| 827 | 827 | |