All of lore.kernel.org
 help / color / mirror / Atom feed
From: Wolfgang Denk <wd@denx.de>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH V2] console: Implement pre-console buffer
Date: Tue, 30 Aug 2011 22:57:01 +0200	[thread overview]
Message-ID: <20110830205701.BF5E718C46FA@gemini.denx.de> (raw)
In-Reply-To: <CAPnjgZ1dQXMVeFk47=Gg5y+TCHG7WTdGk0b1WjSqOBhu2d0xnQ@mail.gmail.com>

Dear Simon Glass,

In message <CAPnjgZ1dQXMVeFk47=Gg5y+TCHG7WTdGk0b1WjSqOBhu2d0xnQ@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

  reply	other threads:[~2011-08-30 20:57 UTC|newest]

Thread overview: 50+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-08-29 12:14 [U-Boot] [PATCH 0/2] console: Squelch and pre-console buffer Graeme Russ
2011-08-29 12:14 ` [U-Boot] [PATCH 1/2] console: Squelch pre-console output in console functions Graeme Russ
2011-08-30 17:16   ` Mike Frysinger
2011-08-30 19:01     ` Wolfgang Denk
2011-09-21 23:21   ` Simon Glass
2011-10-01 19:54   ` Wolfgang Denk
2011-08-29 12:14 ` [U-Boot] [PATCH 2/2] console: Implement pre-console buffer Graeme Russ
2011-08-30 12:49   ` [U-Boot] [PATCH V2] " Graeme Russ
2011-08-30 17:19     ` Mike Frysinger
2011-08-30 19:45     ` Simon Glass
2011-08-30 19:52       ` Wolfgang Denk
2011-08-30 19:58         ` Mike Frysinger
2011-08-30 20:08           ` Wolfgang Denk
2011-08-30 20:18             ` Simon Glass
2011-08-30 20:57               ` Wolfgang Denk [this message]
2011-08-30 21:02                 ` Simon Glass
2011-08-30 23:00                   ` Graeme Russ
2011-08-30 23:39                     ` Graeme Russ
2011-08-31  2:46                       ` Mike Frysinger
2011-08-30 20:07         ` Simon Glass
2011-08-31 12:35     ` [U-Boot] (no subject) Graeme Russ
2011-08-31 12:38       ` Graeme Russ
2011-08-31 12:58       ` [U-Boot] [PATCH V4] console: Implement pre-console buffer Graeme Russ
2011-08-31 15:09         ` Mike Frysinger
2011-08-31 21:15           ` Graeme Russ
2011-08-31 21:33             ` Mike Frysinger
2011-08-31 21:59               ` Graeme Russ
2011-08-31 22:44                 ` Mike Frysinger
2011-08-31 22:51                   ` Graeme Russ
2011-08-31 16:58         ` Simon Glass
2011-08-31 19:18           ` Wolfgang Denk
2011-08-31 20:05             ` Simon Glass
2011-08-31 20:22               ` Mike Frysinger
2011-08-31 20:26                 ` Simon Glass
2011-09-01 10:48         ` [U-Boot] [PATCH V5] " Graeme Russ
2011-09-01 10:52           ` Graeme Russ
2011-09-01 14:02             ` Mike Frysinger
2011-09-01 18:51               ` Simon Glass
2011-09-01 23:34                 ` Graeme Russ
2011-09-02  2:41                   ` Mike Frysinger
2011-09-02  2:58                   ` Simon Glass
2011-09-21 23:18             ` Simon Glass
2011-10-04  5:30               ` Simon Glass
2011-10-05 18:50             ` Wolfgang Denk
2011-09-26 22:50         ` [U-Boot] [PATCH V4] " Vadim Bendebury
2011-09-27 11:22           ` Graeme Russ
2011-09-27 14:55             ` Vadim Bendebury
2011-09-29 23:15               ` Graeme Russ
2011-09-29 23:39                 ` Vadim Bendebury
2011-09-29 23:47                   ` Graeme Russ

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20110830205701.BF5E718C46FA@gemini.denx.de \
    --to=wd@denx.de \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.