Re: Shift 'em bits
From: Don (none_at_given)
Date: 11/19/04
- Next message: Grant Edwards: "Re: Shift 'em bits"
- Previous message: Meindert Sprang: "Re: 1ch uart w/ narrow parallell interface...?"
- In reply to: WaldemarIII: "Shift 'em bits"
- Next in thread: Guy Macon: "Re: Shift 'em bits"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Fri, 19 Nov 2004 08:30:07 -0700
WaldemarIII <bleek004@hotmail.com> wrote in message
news:419dc904$0$46988$cd19a363@news.wanadoo.nl...
>
> Is there an atomic way to shift 64 bits either left or right?
Do you truly mean "atomic"? (i.e. an operation whose intermediate
results can NEVER be seen -- AS IF uninterruptible) Or, do you
just mean something that you can write in a simple C expression?
> Shifting a double (8 bytes) doesn't work. Compiler won't
The language won't allow it. Shift operators only apply to integer
data types (int, short, char, etc.)
And, if you were expecting to cast some "random" group of 64 contiguous
bits to a double, they might get *altered* in the process (since not all
groups of 64 bits represent valid doubles -- assuming your doubles *are*
64 bits!)
> allow it. Embedded assembly is out of the question and
Why?
> and a C function conating a loop shifting the individual
> bytes consumes too much time.
Also, there be dragons there. If you are presumably aspiring to
write portable code (hence the reason you rule out embedded
assembly), you have to be very careful about how you have
defined that "64 bit datum" (if, in fact, it *is* a 64 bit datum!)
E.g., char's aren't *guaranteed* to be 8 bits (read the standard
or argue the point with a language guru) -- though, chances are, your
compiler treats them as such.
But, you might find that you have defined an "8 uchar array" as your
"64 bit datum", yet, you try to manipulate it as a "2 ulong array".
Does your compiler ensure that char arrays are aligned in a manner
compatible with the alignment it (or the CPU!) expects for *longs*?
You also have to be wary of any right shift operations since
the language gives no assurances as to *what* gets shifted in
from the left.
Etc.
If you really are trying to write portable code (avoiding ASM for
some reason), use the manifest constants in <limits.h> and
conditionally chose the widest UNSIGNED data type you can.
Define your "64 bit datum" as an array of those and build
"monitors" to manipulate data of this (64 bit) type -- i.e. pretend
you are dealing with *objects*.
> Suggestions... Love to hear from you...
Use ASM and forget it! :-/
--don
- Next message: Grant Edwards: "Re: Shift 'em bits"
- Previous message: Meindert Sprang: "Re: 1ch uart w/ narrow parallell interface...?"
- In reply to: WaldemarIII: "Shift 'em bits"
- Next in thread: Guy Macon: "Re: Shift 'em bits"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|