128-bit structure or 2 64-bit records for performance and readability

I am sorting 128-bit entries in a large file (10 with GB). The algorithm works fine and currently uses uint64_t , and two of them are equal to the same record. This is on a modern 64-bit system.

In the interest of code readability, it is interesting to know whether it is possible to create a structure of type typedef struct u128t {uint64_t hi, uint64_t} u128t instead of two 64-bit records. This will do an array index cleanup and assignment, but I will have to implement a comparator function.

Is this a portable solution and should I expect it to work at the same speed as the original implementation?

Further reading:

+7
performance c sorting algorithm
source share
1 answer

Using the structure is fine.

I would do something like this:

 #if COMPILER_WHICH_SUPPORTS_128_BIT_TYPE typedef __uint128 u128t; #define COMPARE(a, b) ((a) == (b)) #else typedef struct { uint64_t hi; uint64_t lo; } u128t; #define COMPARE(a, b) MyCompareFunction((a), (b)) #endif 
+5
source share

All Articles