|
4 | 4 | * Copyright (c) 2015 Jannik Vogel
|
5 | 5 | * Copyright (c) 2013 espes
|
6 | 6 | * Copyright (c) 2007-2010 The Nouveau Project.
|
| 7 | + * Copyright (c) 2025 Matt Borgerson |
7 | 8 | *
|
8 | 9 | * This library is free software; you can redistribute it and/or
|
9 | 10 | * modify it under the terms of the GNU Lesser General Public
|
@@ -68,7 +69,7 @@ static void generate_swizzle_masks(unsigned int width,
|
68 | 69 | *mask_z = z;
|
69 | 70 | }
|
70 | 71 |
|
71 |
| -void swizzle_box( |
| 72 | +static inline void swizzle_box_internal( |
72 | 73 | const uint8_t *src_buf,
|
73 | 74 | unsigned int width,
|
74 | 75 | unsigned int height,
|
@@ -114,7 +115,7 @@ void swizzle_box(
|
114 | 115 | }
|
115 | 116 | }
|
116 | 117 |
|
117 |
| -void unswizzle_box( |
| 118 | +static inline void unswizzle_box_internal( |
118 | 119 | const uint8_t *src_buf,
|
119 | 120 | unsigned int width,
|
120 | 121 | unsigned int height,
|
@@ -148,3 +149,36 @@ void unswizzle_box(
|
148 | 149 | off_z = (off_z - mask_z) & mask_z;
|
149 | 150 | }
|
150 | 151 | }
|
| 152 | + |
| 153 | +/* Multiversioned to optimize for common bytes_per_pixel */ \ |
| 154 | +#define C(m, bpp) \ |
| 155 | + m##_internal(src_buf, width, height, depth, dst_buf, row_pitch, \ |
| 156 | + slice_pitch, bpp) |
| 157 | +#define MULTIVERSION(m) \ |
| 158 | + void m(const uint8_t *src_buf, unsigned int width, unsigned int height, \ |
| 159 | + unsigned int depth, uint8_t *dst_buf, unsigned int row_pitch, \ |
| 160 | + unsigned int slice_pitch, unsigned int bytes_per_pixel) \ |
| 161 | + { \ |
| 162 | + switch (bytes_per_pixel) { \ |
| 163 | + case 1: \ |
| 164 | + C(m, 1); \ |
| 165 | + break; \ |
| 166 | + case 2: \ |
| 167 | + C(m, 2); \ |
| 168 | + break; \ |
| 169 | + case 3: \ |
| 170 | + C(m, 3); \ |
| 171 | + break; \ |
| 172 | + case 4: \ |
| 173 | + C(m, 4); \ |
| 174 | + break; \ |
| 175 | + default: \ |
| 176 | + C(m, bytes_per_pixel); \ |
| 177 | + } \ |
| 178 | + } |
| 179 | + |
| 180 | +MULTIVERSION(swizzle_box) |
| 181 | +MULTIVERSION(unswizzle_box) |
| 182 | + |
| 183 | +#undef C |
| 184 | +#undef MULTIVERSION |
0 commit comments