diff mbox series

[v2,6/8] sm501: Use stn_he_p/ldn_he_p instead of switch/case

Message ID 59fd9656e72cd56e6dcd3c9ffc04ff91f8b3d907.1592266950.git.balaton@eik.bme.hu
State New
Headers show
Series More sm501 fixes and optimisations | expand

Commit Message

BALATON Zoltan June 16, 2020, 12:22 a.m. UTC
Instead of open coding op with different sizes using a switch and type
casting it can be written more compactly using stn_he_p/ldn_he_p.

Suggested-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: BALATON Zoltan <balaton@eik.bme.hu>
---
 hw/display/sm501.c | 12 +-----------
 1 file changed, 1 insertion(+), 11 deletions(-)

Comments

Philippe Mathieu-Daudé June 19, 2020, 10:54 a.m. UTC | #1
On 6/16/20 2:22 AM, BALATON Zoltan wrote:
> Instead of open coding op with different sizes using a switch and type
> casting it can be written more compactly using stn_he_p/ldn_he_p.
> 
> Suggested-by: Peter Maydell <peter.maydell@linaro.org>
> Signed-off-by: BALATON Zoltan <balaton@eik.bme.hu>
> ---
>  hw/display/sm501.c | 12 +-----------
>  1 file changed, 1 insertion(+), 11 deletions(-)
> 
> diff --git a/hw/display/sm501.c b/hw/display/sm501.c
> index b6356ea1ee..6e914d3162 100644
> --- a/hw/display/sm501.c
> +++ b/hw/display/sm501.c
> @@ -766,17 +766,7 @@ static void sm501_2d_operation(SM501State *s)
>              for (y = 0; y < height; y++) {
>                  i = (dst_x + (dst_y + y) * dst_pitch) * bypp;
>                  for (x = 0; x < width; x++, i += bypp) {
> -                    switch (format) {
> -                    case 0:
> -                        d[i] = ~d[i];
> -                        break;
> -                    case 1:
> -                        *(uint16_t *)&d[i] = ~*(uint16_t *)&d[i];
> -                        break;
> -                    case 2:
> -                        *(uint32_t *)&d[i] = ~*(uint32_t *)&d[i];
> -                        break;
> -                    }
> +                    stn_he_p(&d[i], bypp, ~ldn_he_p(&d[i], bypp));
>                  }
>              }
>          } else {
> 

Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
diff mbox series

Patch

diff --git a/hw/display/sm501.c b/hw/display/sm501.c
index b6356ea1ee..6e914d3162 100644
--- a/hw/display/sm501.c
+++ b/hw/display/sm501.c
@@ -766,17 +766,7 @@  static void sm501_2d_operation(SM501State *s)
             for (y = 0; y < height; y++) {
                 i = (dst_x + (dst_y + y) * dst_pitch) * bypp;
                 for (x = 0; x < width; x++, i += bypp) {
-                    switch (format) {
-                    case 0:
-                        d[i] = ~d[i];
-                        break;
-                    case 1:
-                        *(uint16_t *)&d[i] = ~*(uint16_t *)&d[i];
-                        break;
-                    case 2:
-                        *(uint32_t *)&d[i] = ~*(uint32_t *)&d[i];
-                        break;
-                    }
+                    stn_he_p(&d[i], bypp, ~ldn_he_p(&d[i], bypp));
                 }
             }
         } else {