1010namespace ra {
1111
1212_Use_decl_annotations_
13- std::string ByteAddressToString (ByteAddress nAddr)
13+ std::string ByteAddressToString (ra::data:: ByteAddress nAddr)
1414{
1515#ifndef RA_UTEST
1616 const auto & pEmulatorContext = ra::services::ServiceLocator::Get<ra::data::context::EmulatorContext>();
@@ -21,9 +21,9 @@ std::string ByteAddressToString(ByteAddress nAddr)
2121}
2222
2323_Use_decl_annotations_
24- ByteAddress ByteAddressFromString (const std::string& sByteAddress )
24+ ra::data:: ByteAddress ByteAddressFromString (const std::string& sByteAddress )
2525{
26- ra::ByteAddress address{};
26+ ra::data:: ByteAddress address{};
2727
2828 if (!ra::StringStartsWith (sByteAddress , " -" )) // negative addresses not supported
2929 {
@@ -42,69 +42,6 @@ ByteAddress ByteAddressFromString(const std::string& sByteAddress)
4242
4343namespace data {
4444
45- static std::wstring U32ToFloatString (unsigned nValue, char nFloatType)
46- {
47- rc_typed_value_t value;
48- value.type = RC_VALUE_TYPE_UNSIGNED;
49- value.value .u32 = nValue;
50- rc_transform_memref_value (&value, nFloatType);
51-
52- if (value.value .f32 < 0.000001 )
53- {
54- if (value.value .f32 > 0.0 )
55- return ra::StringPrintf (L" %e" , value.value .f32 );
56-
57- if (value.value .f32 < 0.0 && value.value .f32 > -0.000001 )
58- return ra::StringPrintf (L" %e" , value.value .f32 );
59- }
60-
61- std::wstring sValue = ra::StringPrintf (L" %f" , value.value .f32 );
62- while (sValue .back () == L' 0' )
63- sValue .pop_back ();
64- if (sValue .back () == L' .' )
65- sValue .push_back (L' 0' );
66-
67- return sValue ;
68- }
69-
70- std::wstring MemSizeFormat (unsigned nValue, MemSize nSize, MemFormat nFormat)
71- {
72- switch (nSize)
73- {
74- case MemSize::Float:
75- return U32ToFloatString (nValue, RC_MEMSIZE_FLOAT);
76-
77- case MemSize::FloatBigEndian:
78- return U32ToFloatString (nValue, RC_MEMSIZE_FLOAT_BE);
79-
80- case MemSize::Double32:
81- return U32ToFloatString (nValue, RC_MEMSIZE_DOUBLE32);
82-
83- case MemSize::Double32BigEndian:
84- return U32ToFloatString (nValue, RC_MEMSIZE_DOUBLE32_BE);
85-
86- case MemSize::MBF32:
87- return U32ToFloatString (nValue, RC_MEMSIZE_MBF32);
88-
89- case MemSize::MBF32LE:
90- return U32ToFloatString (nValue, RC_MEMSIZE_MBF32_LE);
91-
92- default :
93- if (nFormat == MemFormat::Dec)
94- return std::to_wstring (nValue);
95-
96- const auto nBits = MemSizeBits (nSize);
97- switch (nBits / 8 )
98- {
99- default : return ra::StringPrintf (L" %x" , nValue);
100- case 1 : return ra::StringPrintf (L" %02x" , nValue);
101- case 2 : return ra::StringPrintf (L" %04x" , nValue);
102- case 3 : return ra::StringPrintf (L" %06x" , nValue);
103- case 4 : return ra::StringPrintf (L" %08x" , nValue);
104- }
105- }
106- }
107-
10845const char * ValueFormatToString (ValueFormat nFormat) noexcept
10946{
11047 switch (nFormat)
@@ -138,109 +75,5 @@ ValueFormat ValueFormatFromString(const std::string& sFormat) noexcept
13875 return ra::itoe<ValueFormat>(rc_parse_format (sFormat .c_str ()));
13976}
14077
141- unsigned FloatToU32 (float fValue , MemSize nFloatType) noexcept
142- {
143- // this leverages the fact that Windows uses IEE754 floats
144- union u
145- {
146- float fValue ;
147- unsigned nValue;
148- } uUnion;
149-
150- uUnion.fValue = fValue ;
151-
152- switch (nFloatType)
153- {
154- case MemSize::Float:
155- return uUnion.nValue ;
156-
157- case MemSize::FloatBigEndian:
158- return ReverseBytes (uUnion.nValue );
159-
160- case MemSize::Double32:
161- case MemSize::Double32BigEndian:
162- {
163- // double has 3 extra bits for the exponent
164- const int32_t exponent = ra::to_signed ((uUnion.nValue >> 23 ) & 0xFF ) - 127 + 1023 ; // change exponent base from 127 to 1023
165- const unsigned nValue = ((uUnion.nValue & 0x007FFFFF ) >> 3 ) | // mantissa is shifted three bits right
166- ((ra::to_unsigned (exponent) & 0x7FF ) << 20 ) | // adjusted exponent
167- ((uUnion.nValue & 0x80000000 )); // sign is unmoved
168-
169- return (nFloatType == MemSize::Double32) ? nValue : ReverseBytes (nValue);
170- }
171-
172- case MemSize::MBF32:
173- case MemSize::MBF32LE:
174- {
175- // MBF32 puts the sign after the exponent, uses a 129 base instead of 127, and stores in big endian
176- unsigned nValue = ((uUnion.nValue & 0x007FFFFF )) | // mantissa is unmoved
177- ((uUnion.nValue & 0x7F800000 ) << 1 ) | // exponent is shifted one bit left
178- ((uUnion.nValue & 0x80000000 ) >> 8 ); // sign is shifted eight bits right
179-
180- nValue += 0x02000000 ; // adjust to 129 base
181- return (nFloatType == MemSize::MBF32LE) ? nValue : ReverseBytes (nValue);
182- }
183-
184- default :
185- return 0 ;
186- }
187- }
188-
189- float U32ToFloat (unsigned nValue, MemSize nFloatType) noexcept
190- {
191- // this leverages the fact that Windows uses IEE754 floats
192- union u
193- {
194- float fValue ;
195- unsigned nValue;
196- } uUnion{};
197-
198- switch (nFloatType)
199- {
200- case MemSize::FloatBigEndian:
201- nValue = ReverseBytes (nValue);
202- __fallthrough; // to MemSize::Float
203-
204- case MemSize::Float:
205- uUnion.nValue = nValue;
206- break ;
207-
208- case MemSize::Double32BigEndian:
209- nValue = ReverseBytes (nValue);
210- __fallthrough; // to MemSize::Double32
211-
212- case MemSize::Double32:
213- {
214- // double has 3 extra bits for the exponent, and uses a 1023 base instead of a 127 base
215- const int32_t exponent = ra::to_signed ((uUnion.nValue >> 20 ) & 0x7FF ) - 1023 + 127 ; // change exponent base from 1023 to 127
216- nValue = ((uUnion.nValue & 0x000FFFFF ) << 3 ) | // mantissa is shifted three bits left
217- ((ra::to_unsigned (exponent) & 0xFF ) << 23 ) | // adjusted exponent
218- ((uUnion.nValue & 0x80000000 )); // sign is unmoved
219-
220- uUnion.nValue = nValue;
221- break ;
222- }
223-
224- case MemSize::MBF32:
225- nValue = ReverseBytes (nValue);
226- __fallthrough; // to MemSize::MBF32LE
227-
228- case MemSize::MBF32LE:
229- // MBF32 puts the sign after the exponent, uses a 129 base instead of 127, and stores in big endian
230- nValue -= 0x02000000 ; // adjust to 129 base
231- nValue = ((nValue & 0x007FFFFF )) | // mantissa is unmoved
232- ((nValue & 0xFF000000 ) >> 1 ) | // exponent is shifted one bit right
233- ((nValue & 0x00800000 ) << 8 ); // sign is shifted eight bits left
234-
235- uUnion.nValue = nValue;
236- break ;
237-
238- default :
239- return 0 .0f ;
240- }
241-
242- return uUnion.fValue ;
243- }
244-
24578} /* namespace data */
24679} /* namespace ra */
0 commit comments