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?

  • 1
    I think "hybrid coupling" is when two mules try to mate. – Nosredna Jul 29 '09 at 14:40
  • In OOP, we'd call it an object. – OMG Ponies Jul 29 '09 at 14:48
  • Your first example is packed and the second example is unpacked. But you can make up a name if you need it in-house. Call it "hybrid coupling" or "mule mating" or whatever you like. – Nosredna Jul 29 '09 at 15:44
  • Thanks, fair point. I think I'm slightly hung up on this because saying "x and y are packed" puts the emphasis on the storage format rather than the implications of storing them; saying "x and y are logically coupled" puts the emphasis more on the potential usage implications. For example when data is packed it's much easier to clobber both x and y in the same action than it is if they aren't. If there's not a widely used term I guess "mule mating" is as good as any ;-). – Mike Streatfield Jul 29 '09 at 15:57
  • You make a good point about clobbering. Makes the argument for good naming of variables. – Nosredna Jul 29 '09 at 16:31
  • Or perhaps the use of inline accessors (to preserve speed) and private data members to restrict the cases where it might happen. – Mike Streatfield Jul 29 '09 at 16:34

2 Answers2

5

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

Community
  • 1
  • 1
Nosredna
  • 83,000
  • 15
  • 95
  • 122
0

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
  • 46,381
  • 14
  • 112
  • 137
  • @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 Jul 29 '09 at 15:01
  • @Nosrenda, agreed the term used is packing, but it can be efficiently impleemnted ass a c union – ennuikiller Jul 29 '09 at 15:05
  • 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 Jul 29 '09 at 15:07
  • @ennuikiller, yes, you can use union for bit packing. Another example: http://stackoverflow.com/questions/979050/union-and-struct-packing-problem – Nosredna Jul 29 '09 at 15:16