libTriton version 1.0 build 1590
Loading...
Searching...
No Matches
coreUtils.cpp
Go to the documentation of this file.
1
2/*
3** Copyright (C) - Triton
4**
5** This program is under the terms of the Apache License 2.0.
6*/
7
9#include <triton/cpuSize.hpp>
10
11
12
13namespace triton {
14 namespace utils {
15
17 for (triton::uint32 i = 0; i < triton::size::fword; i++) {
18 buffer[i] = static_cast<triton::uint8>(value & 0xff);
19 value >>= triton::bitsize::byte;
20 }
21 }
22
23
25 for (triton::uint32 i = 0; i < triton::size::dqword; i++) {
26 buffer[i] = static_cast<triton::uint8>(value & 0xff);
27 value >>= triton::bitsize::byte;
28 }
29 }
30
31
33 for (triton::uint32 i = 0; i < triton::size::qqword; i++) {
34 buffer[i] = static_cast<triton::uint8>(value & 0xff);
35 value >>= triton::bitsize::byte;
36 }
37 }
38
39
41 for (triton::uint32 i = 0; i < triton::size::dqqword; i++) {
42 buffer[i] = static_cast<triton::uint8>(value & 0xff);
43 value >>= triton::bitsize::byte;
44 }
45 }
46
47
48 template <> triton::uint80 cast<>(const triton::uint8* buffer) {
49 triton::uint80 value = 0;
50 for (triton::sint32 i = triton::size::fword-1; i >= 0; i--)
51 value = ((value << triton::bitsize::byte) | buffer[i]);
52 return value;
53 }
54
55
56 template <> triton::uint128 cast<>(const triton::uint8* buffer) {
57 triton::uint128 value = 0;
58 for (triton::sint32 i = triton::size::dqword-1; i >= 0; i--)
59 value = ((value << triton::bitsize::byte) | buffer[i]);
60 return value;
61 }
62
63
64 template <> triton::uint256 cast<>(const triton::uint8* buffer) {
65 triton::uint256 value = 0;
66 for (triton::sint32 i = triton::size::qqword-1; i >= 0; i--)
67 value = ((value << triton::bitsize::byte) | buffer[i]);
68 return value;
69 }
70
71
72 template <> triton::uint512 cast<>(const triton::uint8* buffer) {
73 triton::uint512 value = 0;
74 for (triton::sint32 i = triton::size::dqqword-1; i >= 0; i--)
75 value = ((value << triton::bitsize::byte) | buffer[i]);
76 return value;
77 }
78
79
81 template <> triton::uint80 cast<>(const triton::uint512& value) {
82 #ifdef TRITON_BOOST_INTERFACE
83 return static_cast<triton::uint80>(value);
84 #else
85 #if defined(WIDE_INTEGER_NAMESPACE)
86 using WIDE_INTEGER_NAMESPACE::math::wide_integer::detail::make_lo;
87 using WIDE_INTEGER_NAMESPACE::math::wide_integer::detail::make_hi;
88 #else
89 using math::wide_integer::detail::make_lo;
90 using math::wide_integer::detail::make_hi;
91 #endif
92
93 static_assert(
94 std::numeric_limits<typename triton::uint80::limb_type>::digits * 2 == std::numeric_limits<typename triton::uint512::limb_type>::digits,
95 "Error: Wrong input/output limb types for this conversion"
96 );
97
98 using local_value_type = typename triton::uint80::representation_type::value_type;
99
100 return triton::uint80::from_rep({
101 make_lo<local_value_type>(*(value.crepresentation().data() + 0U)),
102 make_hi<local_value_type>(*(value.crepresentation().data() + 0U)),
103 make_lo<local_value_type>(*(value.crepresentation().data() + 1U)),
104 make_hi<local_value_type>(*(value.crepresentation().data() + 1U)),
105 make_lo<local_value_type>(*(value.crepresentation().data() + 2U))
106 });
107 #endif
108 }
109
110
112 template <> triton::uint512 cast<>(const triton::uint80& value) {
113 #ifdef TRITON_BOOST_INTERFACE
114 return static_cast<triton::uint512>(value);
115 #else
116 #if defined(WIDE_INTEGER_NAMESPACE)
117 using WIDE_INTEGER_NAMESPACE::math::wide_integer::detail::make_large;
118 #else
119 using math::wide_integer::detail::make_large;
120 #endif
121
122 static_assert(
123 std::numeric_limits<typename triton::uint80::limb_type>::digits * 2 == std::numeric_limits<typename triton::uint512::limb_type>::digits,
124 "Error: Wrong input/output limb types for this conversion"
125 );
126
127 using local_value_type = typename triton::uint80::representation_type::value_type;
128
129 return triton::uint512::from_rep({
130 make_large(*(value.crepresentation().data() + 0U), *(value.crepresentation().data() + 1U)),
131 make_large(*(value.crepresentation().data() + 2U), *(value.crepresentation().data() + 3U)),
132 make_large(*(value.crepresentation().data() + 4U), static_cast<local_value_type>(0U))
133 });
134 #endif
135 }
136
137 }; /* utils namespace */
138}; /* triton namespace */
constexpr triton::uint32 byte
byte size in bit
Definition cpuSize.hpp:60
constexpr triton::uint32 fword
fword size in byte
Definition cpuSize.hpp:38
constexpr triton::uint32 dqqword
dqqword size in byte
Definition cpuSize.hpp:44
constexpr triton::uint32 dqword
dqword size in byte
Definition cpuSize.hpp:40
constexpr triton::uint32 qqword
qqword size in byte
Definition cpuSize.hpp:42
math::wide_integer::uint128_t uint128
unsigned 128-bits
std::int32_t sint32
signed 32-bits
math::wide_integer::uint256_t uint256
unsigned 256-bits
math::wide_integer::uintwide_t< static_cast< size_t >(UINT32_C(80)), std::uint16_t > uint80
unsigned 80-bits
math::wide_integer::uint512_t uint512
unsigned 512-bits
std::uint32_t uint32
unisgned 32-bits
std::uint8_t uint8
unisgned 8-bits
TRITON_EXPORT void fromUintToBuffer(triton::uint80 value, triton::uint8 *buffer)
Inject the value into the buffer. Make sure that the buffer contains at least 10 allocated bytes.
Definition coreUtils.cpp:16
The Triton namespace.