aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/int128/ut/int128_ut_helpers.cpp
blob: cb712f869ac2f1eaf20b1fd6ca8958c5ceb82b63 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include "int128_ut_helpers.h" 
 
namespace NInt128Private { 
#if defined(_little_endian_) 
    std::array<ui8, 16> GetAsArray(const ui128 value) { 
        std::array<ui8, 16> result; 
        const ui64 low = GetLow(value); 
        const ui64 high = GetHigh(value); 
        MemCopy(result.data(), reinterpret_cast<const ui8*>(&low), sizeof(low)); 
        MemCopy(result.data() + sizeof(low), reinterpret_cast<const ui8*>(&high), sizeof(high)); 
        return result; 
    } 
 
    std::array<ui8, 16> GetAsArray(const i128 value) { 
        std::array<ui8, 16> result; 
        const ui64 low = GetLow(value); 
        const ui64 high = GetHigh(value); 
        MemCopy(result.data(), reinterpret_cast<const ui8*>(&low), sizeof(low)); 
        MemCopy(result.data() + sizeof(low), reinterpret_cast<const ui8*>(&high), sizeof(high)); 
        return result; 
    } 
#elif defined(_big_endian_) 
    std::array<ui8, 16> GetAsArray(const i128 value) { 
        std::array<ui8, 16> result; 
        const ui64 low = GetLow(value); 
        const ui64 high = GetHigh(value); 
        MemCopy(result.data(), reinterpret_cast<const ui8*>(&high), sizeof(high)); 
        MemCopy(result.data() + sizeof(high), reinterpret_cast<const ui8*>(&low), sizeof(low)); 
        return result; 
    } 
 
    std::array<ui8, 16> GetAsArray(const ui128 value) { 
        std::array<ui8, 16> result; 
        const ui64 low = GetLow(value); 
        const ui64 high = GetHigh(value); 
        MemCopy(result.data(), reinterpret_cast<const ui8*>(&high), sizeof(high)); 
        MemCopy(result.data() + sizeof(high), reinterpret_cast<const ui8*>(&low), sizeof(low)); 
        return result; 
    } 
#endif 
 
#if defined(Y_HAVE_INT128) 
    std::array<ui8, 16> GetAsArray(const unsigned __int128 value) { 
        std::array<ui8, 16> result; 
        MemCopy(result.data(), reinterpret_cast<const ui8*>(&value), sizeof(value)); 
        return result; 
    } 
 
    std::array<ui8, 16> GetAsArray(const signed __int128 value) { 
        std::array<ui8, 16> result; 
        MemCopy(result.data(), reinterpret_cast<const ui8*>(&value), sizeof(value)); 
        return result; 
    } 
#endif 
 
}