I am working on a 32-bit architecture where int64_t
is defined only with the most recent version of the compiler (software emulation). Since we did not entirely upgraded to the last compiler, I would like to manage 64-bit integers with a union and define basic arithmetic operations.
I wrote this:
typedef union _int64_u {
int64_t int64;
int64_32 int32;
} int64_u;
typedef struct _int64_32 {
int32_t hi;
int32_t lo;
}
I would like to clarify the following points:
- What is the naming standards for such definition (part and types)?
- Is this solution correct?
Hereafter, an example of the add and sub functions:
#pragma inline
#pragma always_inline
int64_u int64_sub(int64_u x, int64_u y)
{
int64_u n;
asm("%0 = %1 - %2;"
: "=d" (n.int32.lo)
: "d" (x.int32.lo), "d" (y.int32.lo));
asm("%0 = %1 - %2 + CI - 1;"
: "=d" (n.int32.hi)
: "d" (x.int32.hi), "d" (y.int32.hi));
return n;
}
#pragma inline
#pragma always_inline
int64_u int64_add(int64_u x, int64_u y)
{
int64_u n;
asm("%0 = %1 + %2;"
: "=d" (n.int32.lo)
: "d" (x.int32.lo), "d" (y.int32.lo));
asm("%0 = %1 + %2 + CI;"
: "=d" (n.int32.hi)
: "d" (x.int32.hi), "d" (y.int32.hi));
return n;
}