From: Aggelos Manousarides <amanous@inaccessnetworks.com>
To: u-boot@lists.denx.de
Subject: [U-Boot-Users] Spartan FPGA patch
Date: Wed, 14 Nov 2007 14:05:46 +0200 [thread overview]
Message-ID: <473AE49A.40801@inaccessnetworks.com> (raw)
In-Reply-To: <20071107195146.2526A248D3@gemini.denx.de>
Wolfgang Denk wrote:
> In message <4731ECA0.1010502@schweigstill.de> you wrote:
>> Wolfgang Denk schrieb:
>>> Oops? I can't parse that. What's the difference between "signed char"
>>> and "int" except the number of bits?
>> Like mentioned before, accessing data via a (signed|unsigned|.) char *
>> is independant of the processor endianess. If you want to read a
>
> Correct. And storing the result in an "int" type is independent of the
> byte order as well,if you do it right.
>
>> bitstream which is bytewise formatted you don't want to care about
>> endianess. Or do you also want some endianess string definitions?
>
> What has this to do with what we're discussing?
>
>> And it is even worse; on some architectures, like ARM, it is not
>> allowed to do a 16/32 bit memory access on a non-aligned address,
>> e.g.:
>
> Nobody intended to do that.
>
>> int val;
>> int * p_data;
>
> STOP! I asked why we cannot change "val" into an "int". I never said
> anything about using an "int *" to access to buffer data.
>
This is the main misunderstanding. When you said "int" I though you
meant dereferencing an "int *", in fact not only me but other people on
the list as well. So your proposal is to convert the "char val" to an
"int val". You don't solve the problem I mentioned by doing this.
This is the current code:
*********************
unsigned char *data = ...;
char val;
int i;
...
val = data [bytecount ++];
i = 8;
do {
...
write(..., (val < 0), ...);
...
val <<= 1;
i--
} while (i > 0);
*********************
Let us not forget that all we want to do here is take the *bits* of the
buffer one by one, starting from the MSB. Checking for negativity is
just a hack to acquire the MSB, since signed values are two's complement.
This code works on all platforms in which "char" defaults to "signed
char", because storing a byte from an "unsigned char *" to a "char" will
implicitly convert it to a negative value. On ARM, this fails, becuase
"char" is also "unsigned char", thus "val<0" is always zero.
Your proposed solution also fails. Just converting the "char val" to an
"int val", will never produce a negative value in any architecture. This
integer will always be positive.
To avoid a new series of misunderstandings, you said "if you do it
right" when you talked about the "int". This could be interpreted as
some kind of cast so that the "int val" is negative on all
architectures, but I fail to see how this is cleaner than converting the
val to "unsigned char" like the "data" and doing "val & 0x80".
--
Angelos Manousaridis
next prev parent reply other threads:[~2007-11-14 12:05 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-10-30 15:51 [U-Boot-Users] Spartan FPGA patch Aggelos Manousarides
2007-11-03 21:46 ` Wolfgang Denk
2007-11-05 12:58 ` Aggelos Manousarides
2007-11-05 19:21 ` Wolfgang Denk
2007-11-07 11:43 ` Aggelos Manousarides
2007-11-07 13:33 ` Wolfgang Denk
2007-11-07 16:49 ` Andreas Schweigstill
2007-11-07 19:51 ` Wolfgang Denk
2007-11-14 12:05 ` Aggelos Manousarides [this message]
2007-11-14 19:46 ` Wolfgang Denk
2007-11-07 14:29 ` Matthias Fuchs
2007-11-07 19:48 ` Wolfgang Denk
2007-11-07 21:07 ` Jerry Van Baren
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=473AE49A.40801@inaccessnetworks.com \
--to=amanous@inaccessnetworks.com \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox