[U-Boot] [PATCH V2] console: Implement pre-console buffer

Wolfgang Denk wd at denx.de
Tue Aug 30 22:57:01 CEST 2011


Dear Simon Glass,

In message <CAPnjgZ1dQXMVeFk47=Gg5y+TCHG7WTdGk0b1WjSqOBhu2d0xnQ at mail.gmail.com> you wrote:
> 
> In case it is interesting (which may be unlikely) here is the code
> generated by my compiler (common code stripped) for your example, and

Which architecture / which compiler is this?

> one I added. It seems that % makes it worry about sign.

Indeed!  We should use unsigned numbers here.  MUCH better now:


unsigned int ufoo(unsigned int i)
{
        return i & (CONFIG_SYS_TMP_CON_BUF_SZ-1);
}

For ARM, BUF_SZ = 1024

        mov     r0, r0, asl #22
        mov     r0, r0, lsr #22

For PPC, BUF_SZ = 1024

	rlwinm 3,3,0,22,31

The following two entries make no sense, just for completeness:

For ARM, BUF_SZ = 1021  (Note: 1021 is a prime number)

	and     r0, r0, #1020

For PPC, BUF_SZ = 1021

        rlwinm 3,3,0,22,29



unsigned int ubar(unsigned int i)
{
        return i % CONFIG_SYS_TMP_CON_BUF_SZ;
}

For ARM, BUF_SZ = 1024

        mov     r0, r0, asl #22
        mov     r0, r0, lsr #22

For PPC, BUF_SZ = 1024

	rlwinm 3,3,0,22,31

For ARM, BUF_SZ = 1021

        ldr     r2, .L11
        mov     ip, r0
        umull   r1, r3, r2, r0
        rsb     r1, r3, r0
        add     r3, r3, r1, lsr #1
        mov     r3, r3, lsr #9
        mov     r0, r3, asl #10
        sub     r0, r0, r3, asl #2
        add     r0, r0, r3
        rsb     r0, r0, ip

For PPC, BUF_SZ = 1021

        lis 0,0xc0
        ori 0,0,36973
        mulhwu 0,3,0
        subf 9,0,3
        srwi 9,9,1
        add 0,0,9
        srwi 0,0,9
        mulli 0,0,1021
        subf 3,0,3


So indeed we should use unsigned arithmetics, and try to use
power-of-two sizes where possible.

Best regards,

Wolfgang Denk

-- 
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
You can't evaluate a man by logic alone.
	-- McCoy, "I, Mudd", stardate 4513.3


More information about the U-Boot mailing list