Skip to content

Commit

Permalink
vga: use common endian swap macros
Browse files Browse the repository at this point in the history
The constant-expression bswap is provided by const_le32(), and GET_PLANE()
can also be implemented using cpu_to_le32().  Remove the custom macros in
vga.c.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
  • Loading branch information
bonzini committed Jan 18, 2024
1 parent 977542d commit 937de9a
Showing 1 changed file with 17 additions and 48 deletions.
65 changes: 17 additions & 48 deletions hw/display/vga.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,58 +90,27 @@ const uint8_t gr_mask[16] = {
0x00, /* 0x0f */
};

#define cbswap_32(__x) \
((uint32_t)( \
(((uint32_t)(__x) & (uint32_t)0x000000ffUL) << 24) | \
(((uint32_t)(__x) & (uint32_t)0x0000ff00UL) << 8) | \
(((uint32_t)(__x) & (uint32_t)0x00ff0000UL) >> 8) | \
(((uint32_t)(__x) & (uint32_t)0xff000000UL) >> 24) ))

#if HOST_BIG_ENDIAN
#define PAT(x) cbswap_32(x)
#else
#define PAT(x) (x)
#endif

#if HOST_BIG_ENDIAN
#define BIG 1
#else
#define BIG 0
#endif

#if HOST_BIG_ENDIAN
#define GET_PLANE(data, p) (((data) >> (24 - (p) * 8)) & 0xff)
#else
#define GET_PLANE(data, p) (((data) >> ((p) * 8)) & 0xff)
#endif
#define GET_PLANE(data, p) ((cpu_to_le32(data) >> ((p) * 8)) & 0xff)

static const uint32_t mask16[16] = {
PAT(0x00000000),
PAT(0x000000ff),
PAT(0x0000ff00),
PAT(0x0000ffff),
PAT(0x00ff0000),
PAT(0x00ff00ff),
PAT(0x00ffff00),
PAT(0x00ffffff),
PAT(0xff000000),
PAT(0xff0000ff),
PAT(0xff00ff00),
PAT(0xff00ffff),
PAT(0xffff0000),
PAT(0xffff00ff),
PAT(0xffffff00),
PAT(0xffffffff),
const_le32(0x00000000),
const_le32(0x000000ff),
const_le32(0x0000ff00),
const_le32(0x0000ffff),
const_le32(0x00ff0000),
const_le32(0x00ff00ff),
const_le32(0x00ffff00),
const_le32(0x00ffffff),
const_le32(0xff000000),
const_le32(0xff0000ff),
const_le32(0xff00ff00),
const_le32(0xff00ffff),
const_le32(0xffff0000),
const_le32(0xffff00ff),
const_le32(0xffffff00),
const_le32(0xffffffff),
};

#undef PAT

#if HOST_BIG_ENDIAN
#define PAT(x) (x)
#else
#define PAT(x) cbswap_32(x)
#endif

static uint32_t expand4[256];
static uint16_t expand2[256];
static uint8_t expand4to8[16];
Expand Down

0 comments on commit 937de9a

Please sign in to comment.