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-Users] PATCH: itest - an integer compare function
Date: Sat, 07 Feb 2004 00:34:13 +0100	[thread overview]
Message-ID: <20040206233418.9B73DC1096@atlas.denx.de> (raw)
In-Reply-To: Your message of "Tue, 06 Jan 2004 17:11:10 +1300." <3FFA355E.4090306@tait.co.nz>

Dear Robin,

in message <3FFA355E.4090306@tait.co.nz> you wrote:
> 
> Introduce a new command to be used in conditional expressions (such as 
> hush 'if') to test the value of a memory location.
> Supports -eq, -ne, -gt, -lt, -ge, -le
> Allows scalars or memory contents (value prefixed by '*')
> Makes use of command data width expression of .l, .wm .b for 4, 2 or 1 
> byte wide comparisons
> e.g.
> if itest.l *40000 -eq 12345678; then bootm 41000; else bootm 80000; fi

Sorry, but I don;t want to add the code as is.

May I suggest you rewrite it a bit?


> +	switch (op) {
> +	case EQ:
> +		return (l == r);
> +	case NE:
> +		return (l != r);
> +	case LT:
> +		return (l < r);
> +	case GT:
> +		return (l > r);
> +	case LE:
> +		return (l <= r);
> +	case GE:
> +		return (l >= r);
> +	}
> +
> +	return (FALSE);
> +}
> +
> +
> +int binary_test(char *op, char *arg1, char *arg2, int w)
> +{
> +
> +	if (op[2] == 't') {
> +		switch (op[1]) {
> +		case 'l':
> +			return (arithcomp(arg1, arg2, LT, w));	/* -lt */
> +		case 'g':
> +			return (arithcomp(arg1, arg2, GT, w));	/* -gt */
> +		}
> +	} else if (op[1] == 'e') {
> +		switch (op[2]) {
> +		case 'q':
> +			return (arithcomp(arg1, arg2, EQ, w));	/* -eq */
> +		}
> +	} else if (op[2] == 'e') {
> +		switch (op[1]) {
> +		case 'n':
> +			return (arithcomp(arg1, arg2, NE, w));	/* -ne */
> +		case 'g':
> +			return (arithcomp(arg1, arg2, GE, w));	/* -ge */
> +		case 'l':
> +			return (arithcomp(arg1, arg2, LE, w));	/* -le */
> +		}
> +	}

Instead of all the nested tests we could use an  array  with  command
names and table lookup - which would also allow to use operators like
'<'  or ">=", and I also expect the total memory footprint to be even
smaller.

Also, instead of just returning FALSE we should  at  least  print  an
error message for invalid input / operators.

Finally, maybe you even want to add string compare :-)

Best regards,

Wolfgang Denk

-- 
See us @ Embedded World, Nuremberg, Feb 17 - 19,  Hall 12.0 Booth 440
Phone: (+49)-8142-4596-87  Fax: (+49)-8142-4596-88  Email: wd at denx.de
"We have the right to survive!"
"Not be killing others."
	-- Deela and Kirk, "Wink of An Eye", stardate 5710.5

      reply	other threads:[~2004-02-06 23:34 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-01-06  4:11 [U-Boot-Users] PATCH: itest - an integer compare function Robin Gilks
2004-02-06 23:34 ` Wolfgang Denk [this message]

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=20040206233418.9B73DC1096@atlas.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.