# 64 bit integer and structures

**URL:** <https://forums.developer.nvidia.com/t/64-bit-integer-and-structures/9681>\
**Category:** CUDA Programming and Performance\
**Created:** [May 24, 2009, 5:52pm UTC](https://forums.developer.nvidia.com/t/64-bit-integer-and-structures/9681 "2009-05-24T17:52:27Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Antrox87](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@Antrox87](https://forums.developer.nvidia.com/u/Antrox87)\
**Post date:** [May 24, 2009, 5:52pm UTC](https://forums.developer.nvidia.com/t/64-bit-integer-and-structures/9681/1 "2009-05-24T17:52:27Z")

</div>

Does exist a 64 bit integer data type in CUDA? And… can I use structures like “STRUCT” and “UNION”?

I have to work with an equivalent structure of this:

```auto
union magic {

  struct {

	ogg_int32_t lo;

	ogg_int32_t hi;

  } halves;

  ogg_int64_t whole;

};

```

ogg\_int32\_t and ogg\_int64\_t are equivalent respectively to a 32 and 64 bit integer

About the significance of bits… nvidia memory cards adopts a little or big endian notation? (Notice that the value of “lo” and “hi” in the struct wuold be different and it should be inverted eventually)

Besides… I’ve read (somewhere) that shifting is possible… if unions aren’t usable… can I take 32 bit of the 64 bit integer using a shifting on the last one followed by ad 32 integer cast?

Thx to all

---

<div class="post-metadata">

**Author:** ![seibert](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/seibert/32/520688_2.png) [@seibert](https://forums.developer.nvidia.com/u/seibert)\
**Post date:** [May 26, 2009, 3:19pm UTC](https://forums.developer.nvidia.com/t/64-bit-integer-and-structures/9681/2 "2009-05-26T15:19:08Z")

</div>

> [@](#):
>
> Does exist a 64 bit integer data type in CUDA? And… can I use structures like “STRUCT” and “UNION”?
> 
> I have to work with an equivalent structure of this:
> 
> ```auto
> union magic {
> 
> struct {
> 
> ogg_int32_t lo;
> 
> ogg_int32_t hi;
> 
> } halves;
> 
> ogg_int64_t whole;
> 
> };
> 
> ```
> 
> ogg\_int32\_t and ogg\_int64\_t are equivalent respectively to a 32 and 64 bit integer
> 
> About the significance of bits… nvidia memory cards adopts a little or big endian notation? (Notice that the value of “lo” and “hi” in the struct wuold be different and it should be inverted eventually)
> 
> Besides… I’ve read (somewhere) that shifting is possible… if unions aren’t usable… can I take 32 bit of the 64 bit integer using a shifting on the last one followed by ad 32 integer cast?

Yes, there does appear to be a 64 bit integer type in CUDA, though it’s not obvious to me whether it requires compute capability 1.3 (which is required for 64-bit floats). Structs are fine, bit shifting is fine, and though I’ve never used a union, I don’t see why that wouldn’t work too.

I see you are parsing the Ogg container format… Out of curiosity, what project are you working on? (I used to maintain ogg123 in a previous life.)

---

<div class="post-metadata">

**Author:** ![tmurray](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@tmurray](https://forums.developer.nvidia.com/u/tmurray)\
**Post date:** [May 26, 2009, 4:21pm UTC](https://forums.developer.nvidia.com/t/64-bit-integer-and-structures/9681/3 "2009-05-26T16:21:49Z")

</div>

64-bit integers are supported on all hardware.

---

<div class="post-metadata">

**Author:** ![asm](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@asm](https://forums.developer.nvidia.com/u/asm)\
**Post date:** [May 27, 2009, 1:30pm UTC](https://forums.developer.nvidia.com/t/64-bit-integer-and-structures/9681/4 "2009-05-27T13:30:41Z")

</div>

… and you can easily access hi/lo words of 64-bit word without using structs (which are likely to be placed in local mem),

e.g., packing:  
uint64 x = \_\_double\_as\_longlong(\_\_hiloint2double(hi, lo));

unpacking:  
hi = \_\_double2hiint(\_\_longlong\_as\_double(x));  
lo = \_\_double2loint(\_\_longlong\_as\_double(x));

internally uint64 is stored in 2 registers,  
so these constructions produce efficient code
