From mboxrd@z Thu Jan 1 00:00:00 1970 From: Detlev Zundel Date: Wed, 01 Sep 2010 17:01:51 +0200 Subject: [U-Boot] [PATCH] display_buffer: fix misaligned buffer In-Reply-To: <4C7C9B85.6080202@emk-elektronik.de> (Reinhard Meyer's message of "Tue, 31 Aug 2010 08:04:53 +0200") References: <1282940584-27957-1-git-send-email-u-boot@emk-elektronik.de> <4C7B7864.2080607@emk-elektronik.de> <4C7B7C52.1040606@emk-elektronik.de> <4C7B889B.305@denx.de> <4C7BB41F.7030003@emk-elektronik.de> <4C7BF271.1050808@free.fr> <4C7C9550.2010703@free.fr> <4C7C9B85.6080202@emk-elektronik.de> Message-ID: List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de Hi Reinhard, > making the change to the union, I also realized that > > /* Copy from memory into linebuf and print hex values */ > for (i = 0; i < linelen; i++) { > uint32_t x; > if (width == 4) > x = lb.u32[i] = *(volatile uint32_t *)data; > else if (width == 2) > x = lb.u16[i] = *(volatile uint16_t *)data; > else > x = lb.u8[i] = *(volatile uint8_t *)data; > printf(" %0*x", width * 2, x); > data += width; > } > > is still a bit "ugly". What about: > > union data { > u_int32_t *u32; > u_int16_t *u16; > u_int8_t *u8; > void *v; > } dp; > dp.v = data; > > then: > > /* Copy from memory into linebuf and print hex values */ > for (i = 0; i < linelen; i++) { > if (width == 4) > x = lb.u32[i] = *(dp.u32)++; > else if (width == 2) > x = lb.u16[i] = *(dp.u16)++; > else > x = lb.u8[i] = *(dp.u8)++; > printf(" %0*x", width * 2, x); > } If this works then I have to admit, I like what I see :) > optionally calling printf inside the if: > > /* Copy from memory into linebuf and print hex values */ > for (i = 0; i < linelen; i++) { > if (width == 4) > printf(" %08x", lb.u32[i] = *(dp.u32)++); > else if (width == 2) > printf(" %04x", lb.u16[i] = *(dp.u16)++); > else > printf(" %02x", lb.u8[i] = *(dp.u8)++); > } Yes, this may speedup the printf also (ok, not much, but hey). > maybe it would even be more effective to swap for and if: > > /* Copy from memory into linebuf and print hex values */ > if (width == 4) { > for (i = 0; i < linelen; i++) > printf(" %08x", lb.u32[i] = *(dp.u32)++); > } else if (width == 2) { > for (i = 0; i < linelen; i++) > printf(" %04x", lb.u16[i] = *(dp.u16)++); > } else { > for (i = 0; i < linelen; i++) > printf(" %02x", lb.u8[i] = *(dp.u8)++); > } No, please don't, but why not do a switch on width? > Of course, all is purely cosmetic ;) Well this time my signature is in order :) Cheers Detlev -- The mathematician's patterns, like the painter's or the poet's, must be beautiful; the ideas, like the colours or the words, must fit together in a harmonious way. Beauty is the first test: there is no permanent place in the world for ugly mathematics. -- G. H. Hardy -- DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-40 Fax: (+49)-8142-66989-80 Email: dzu at denx.de