views:

70

answers:

2

For example, if I have a 64-bit variable and store two 32-bit items of data in it, perhaps for the purposes of SIMD processing, is there a name to describe the logical coupling of those two items of data?

A colleague of mine suggests "Hybrid Coupling", is this a widely used term?

To clarify: we're after a higher level concept than specific implementations. Say, for example, in a C-like language we have these two structs:

struct CoupledData
{
    uint64 x_and_y; // x is stored in the top 4 bytes, y in the bottom 4
}

struct UncoupledData
{
    uint32 x;
    uint32 y;
}

Regardless of the reasons for doing so, there is an implicit coupling between the x and y data members in CoupledData that doesn't exist in UncoupledData. Is there a term which describes this coupling between x and y?

+4  A: 

I've always called it "packing." You pack R, G, B, and alpha bytes into a long.

pixel=(a<<24)+(r<<16)+(g<<8)+b;

Here's a reference for SIMD instructions in particular (from MMX/SSE):

ADDPS: Add Packed Single-Precision FP Values

CMPccPS: Packed Single-Precision FP Compare

Nosredna
Thanks :-) However, we're looking for a higher level concept, I've editted my question to clarify.
Mike Streatfield
It's just called packed. Naturally, the packed data is often related.
Nosredna
A: 

In the c world its called a union

A "union declaration" specifies a set of variable values and, optionally, a tag naming the union. The variable values are called "members" of the union and can have different types. Unions are similar to "variant records" in other languages

A variable with union type stores one of the values defined by that type. The same rules govern structure and union declarations. Unions can also have bit fields.

In his example you would have this psuedocode:

union 32_64 {

64_bit_specifier sixty_four;
32_bit_specifier thirty_two;

}

ennuikiller
Don't you mean `struct`?
Vinay Sajip
@ennuikiller, also, some C compilers (and I think Pascal, but it's been so long) let you specify that a struct is "packed". So you can do byte-level packing without union tricks. But the process is called "packing" in any language.
Nosredna
@Nosrenda, agreed the term used is packing, but it can be efficiently impleemnted ass a c union
ennuikiller
I think when you do packing with structs (rather than with shifts), you have to do some experimenting because storage order is not dictated by the standard, and not necessarily portable. But usually you're doing hardware stuff that's specific to one machine anyhow.
Nosredna
@ennuikiller, yes, you can use union for bit packing. Another example: http://stackoverflow.com/questions/979050/union-and-struct-packing-problem
Nosredna