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

Simon Glass sjg at chromium.org
Tue Aug 30 22:18:35 CEST 2011


Hi Wolfgang,

On Tue, Aug 30, 2011 at 1:08 PM, Wolfgang Denk <wd at denx.de> wrote:
> Dear Mike Frysinger,
>
> In message <201108301558.08010.vapier at gentoo.org> you wrote:
>>
>> > Please see my previous posting
>> > (http://article.gmane.org/gmane.comp.boot-loaders.u-boot/106810)
>> >
>> > I don't think 3 additional addembler instructions really play a big
>> > role here.
>>
>> i'm pretty sure if you define CONFIG_PRE_CON_BUF_SZ as a power of 2 value, you
>> get nice & simple assembly code.  so if the generated code is undesirable,
>> pick a CONFIG value that is power-of-2 ?
>
> This was the test code I compiled:
>
> ---------------------------------------------
> #define CONFIG_SYS_TMP_CON_BUF_SZ       1024
>
> int foo(int i)
> {
>        return i & (CONFIG_SYS_TMP_CON_BUF_SZ-1);
> }
>
> int bar(int i)
> {
>        return i % CONFIG_SYS_TMP_CON_BUF_SZ;
> }
> ---------------------------------------------
>
> So was actually checking for a power-of-2 value.

In case it is interesting (which may be unlikely) here is the code
generated by my compiler (common code stripped) for your example, and
one I added. It seems that % makes it worry about sign.

#define CONFIG_SYS_TMP_CON_BUF_SZ       1024

int foo(int i)
{
       return i & (CONFIG_SYS_TMP_CON_BUF_SZ-1);
  14:	e1a03b03 	lsl	r3, r3, #22
  18:	e1a03b23 	lsr	r3, r3, #22
}

int bar(int i)
{
       return i % CONFIG_SYS_TMP_CON_BUF_SZ;
  40:	e1a02fc3 	asr	r2, r3, #31
  44:	e1a02b22 	lsr	r2, r2, #22
  48:	e0833002 	add	r3, r3, r2
  4c:	e1a03b03 	lsl	r3, r3, #22
  50:	e1a03b23 	lsr	r3, r3, #22
  54:	e0623003 	rsb	r3, r2, r3
}

int lee(int i)
{
       return i % (CONFIG_SYS_TMP_CON_BUF_SZ - 1);
  7c:	e3003803 	movw	r3, #2051	; 0x803
  80:	e3483020 	movt	r3, #32800	; 0x8020
  84:	e0c31293 	smull	r1, r3, r3, r2
  88:	e0833002 	add	r3, r3, r2
  8c:	e1a014c3 	asr	r1, r3, #9
  90:	e1a03fc2 	asr	r3, r2, #31
  94:	e0633001 	rsb	r3, r3, r1
  98:	e1a01003 	mov	r1, r3
  9c:	e1a01501 	lsl	r1, r1, #10
  a0:	e0631001 	rsb	r1, r3, r1
  a4:	e0613002 	rsb	r3, r1, r2
}

Regards,
Simon

>
> 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
> "Maintain an awareness for contribution --  to  your  schedule,  your
> project, our company."                         - A Group of Employees
>


More information about the U-Boot mailing list