IDA C++ SDK 9.2
Loading...
Searching...
No Matches
ieee.h
Go to the documentation of this file.
1/*
2 * Interactive disassembler (IDA)
3 * Copyright (c) 1990-2025 Hex-Rays
4 * ALL RIGHTS RESERVED.
5
6 * Floating Point Number Libary.
7 * Copyright (c) 1995-2006 by Iouri Kharon.
8 * E-mail: yjh@styx.cabel.net
9 *
10 */
11
12#ifndef _IEEE_H_
13#define _IEEE_H_
14
20
21struct fpvalue_t; // processor-independent representation of floats
22
23#define FPVAL_NWORDS 8
24
35
39const uint32
40 MAXEXP_FLOAT = 0x80,
41 MAXEXP_DOUBLE = 0x400,
42 MAXEXP_LNGDBL = 0x4000;
44
58
75
76idaman THREAD_SAFE fpvalue_error_t ida_export ieee_realcvt(void *m, fpvalue_t *out, uint16 swt);
77
78// Helper functions. Better use members of fpvalue_t, they are nicer.
79idaman THREAD_SAFE void ida_export realtoasc(char *buf, size_t bufsize, const fpvalue_t &x, uint mode);
80idaman THREAD_SAFE fpvalue_error_t ida_export asctoreal(const char **sss, fpvalue_t *out);
81idaman THREAD_SAFE void ida_export eltoe(sval_t l, fpvalue_t *vout);
82idaman THREAD_SAFE void ida_export eltoe64(int64 l, fpvalue_t *vout);
83idaman THREAD_SAFE void ida_export eltoe64u(uint64 l, fpvalue_t *vout);
84idaman THREAD_SAFE fpvalue_error_t ida_export eetol(sval_t *out, const fpvalue_t &a, bool roundflg);
85idaman THREAD_SAFE fpvalue_error_t ida_export eetol64(int64 *out, const fpvalue_t &a, bool roundflg);
86idaman THREAD_SAFE fpvalue_error_t ida_export eetol64u(uint64 *out, const fpvalue_t &a, bool roundflg);
87idaman THREAD_SAFE fpvalue_error_t ida_export eldexp(const fpvalue_t &a, int32 pwr2, fpvalue_t *zout);
88idaman THREAD_SAFE fpvalue_error_t ida_export eadd(const fpvalue_t &a, const fpvalue_t &b, fpvalue_t *zout, bool subflg);
89idaman THREAD_SAFE fpvalue_error_t ida_export emul(const fpvalue_t &a, const fpvalue_t &b, fpvalue_t *zout);
90idaman THREAD_SAFE fpvalue_error_t ida_export ediv(const fpvalue_t &a, const fpvalue_t &b, fpvalue_t *zout);
91idaman THREAD_SAFE int ida_export ecmp(const fpvalue_t &a, const fpvalue_t &b);
92idaman THREAD_SAFE fpvalue_kind_t ida_export get_fpvalue_kind(const fpvalue_t &a, uint16 reserved = 0);
93
94//------------------------------------------------------------------------
98{
99 uint16 w[FPVAL_NWORDS];
100
101 void clear(void) { memset(this, 0, sizeof(*this)); }
102 DECLARE_COMPARISONS(fpvalue_t) { return ecmp(*this, r); }
103
105 fpvalue_error_t from_half(uint16 fpval) { return ieee_realcvt(&fpval, this, sizeof(fpval)/2-1); }
106 fpvalue_error_t from_float(float fpval) { return ieee_realcvt(&fpval, this, sizeof(fpval)/2-1); }
107 fpvalue_error_t from_double(double fpval) { return ieee_realcvt(&fpval, this, sizeof(fpval)/2-1); }
108
110 fpvalue_error_t to_half(uint16 *fpval) const { return ieee_realcvt(fpval, (fpvalue_t*)this, 8|(sizeof(*fpval)/2-1)); }
111 fpvalue_error_t to_float(float *fpval) const { return ieee_realcvt(fpval, (fpvalue_t*)this, 8|(sizeof(*fpval)/2-1)); }
112 fpvalue_error_t to_double(double *fpval) const { return ieee_realcvt(fpval, (fpvalue_t*)this, 8|(sizeof(*fpval)/2-1)); }
113
115 fpvalue_error_t from_10bytes(const void *fpval) { return ieee_realcvt((void *)fpval, this, 4); }
116 fpvalue_error_t to_10bytes(void *fpval) const { return ieee_realcvt(fpval, (fpvalue_t*)this, 8|4); }
117
119 fpvalue_error_t from_12bytes(const void *fpval) { return ieee_realcvt((void*)fpval, this, 5); }
120 fpvalue_error_t to_12bytes(void *fpval) const { return ieee_realcvt(fpval, (fpvalue_t*)this, 8|5); }
121
124 fpvalue_error_t from_str(const char **p_str) { return asctoreal(p_str, this); }
125
133 void to_str(char *buf, size_t bufsize, uint mode) const { realtoasc(buf, bufsize, *this, mode); }
134
136 void from_sval(sval_t x) { eltoe(x, this); }
137 void from_int64(int64 x) { eltoe64(x, this); }
138 void from_uint64(uint64 x) { eltoe64u(x, this); }
139
141 fpvalue_error_t to_sval(sval_t *out, bool round=false) const { return eetol(out, *this, round); }
142 fpvalue_error_t to_int64(int64 *out, bool round=false) const { return eetol64(out, *this, round); }
143 fpvalue_error_t to_uint64(uint64 *out, bool round=false) const { return eetol64u(out, *this, round); }
144
146 fpvalue_error_t fadd(const fpvalue_t &y) { return eadd(*this, y, this, false); }
147 fpvalue_error_t fsub(const fpvalue_t &y) { return eadd(*this, y, this, true); }
148 fpvalue_error_t fmul(const fpvalue_t &y) { return emul(*this, y, this); }
149 fpvalue_error_t fdiv(const fpvalue_t &y) { return ediv(*this, y, this); }
150
152 fpvalue_error_t mul_pow2(int32 power_of_2) { return eldexp(*this, power_of_2, this); }
153
155 void eabs() { w[FPVAL_NWORDS-1] &= 0x7fff; }
156
158 bool is_negative() const { return (w[FPVAL_NWORDS-1] & 0x8000) != 0; }
159
161 void negate()
162 {
163 if ( w[FPVAL_NWORDS-1] != 0 )
164 w[FPVAL_NWORDS-1] ^= 0x8000;
165 }
166
168 fpvalue_kind_t get_kind() const { return get_fpvalue_kind(*this, 0); }
169};
170
171//------------------------------------------------------------------------
173#define IEEE_EXONE (0x3FFF)
175#define E_SPECIAL_EXP 0x7FFF
176#if !defined(NO_OBSOLETE_FUNCS) || defined(IEEE_SOURCE)
177#define IEEE_NI (FPVAL_NWORDS+3)
178#define IEEE_E 1
179#define IEEE_M 2
184typedef uint16 eNI[IEEE_NI];
185
186#ifdef IEEE_SOURCE
187# define IEEE_DEPRECATED
188#else
189# define IEEE_DEPRECATED DEPRECATED
190#endif
191inline IEEE_DEPRECATED void ecleaz(eNI x)
192{
193 if ( x != nullptr )
194 memset(x, 0, sizeof(eNI));
195}
196idaman IEEE_DEPRECATED THREAD_SAFE void ida_export emovo(const eNI a, fpvalue_t *vout);
197idaman IEEE_DEPRECATED THREAD_SAFE void ida_export emovi(const fpvalue_t &a, eNI vout);
198idaman IEEE_DEPRECATED THREAD_SAFE int ida_export eshift(eNI x, int sc);
212idaman IEEE_DEPRECATED THREAD_SAFE bool ida_export emdnorm(eNI s, bool lost, bool subflg, int32 exp, int rndbase);
213
214#endif
215
216#endif
IEEE_DEPRECATED void ecleaz(eNI x)
Definition ieee.h:191
idaman THREAD_SAFE void ida_export eltoe(sval_t l, fpvalue_t *vout)
idaman THREAD_SAFE fpvalue_error_t ida_export emul(const fpvalue_t &a, const fpvalue_t &b, fpvalue_t *zout)
idaman THREAD_SAFE fpvalue_kind_t ida_export get_fpvalue_kind(const fpvalue_t &a, uint16 reserved=0)
idaman THREAD_SAFE void ida_export eltoe64u(uint64 l, fpvalue_t *vout)
idaman THREAD_SAFE fpvalue_error_t ida_export asctoreal(const char **sss, fpvalue_t *out)
idaman THREAD_SAFE fpvalue_error_t ida_export eldexp(const fpvalue_t &a, int32 pwr2, fpvalue_t *zout)
idaman THREAD_SAFE fpvalue_error_t ida_export eetol(sval_t *out, const fpvalue_t &a, bool roundflg)
idaman IEEE_DEPRECATED THREAD_SAFE bool ida_export emdnorm(eNI s, bool lost, bool subflg, int32 exp, int rndbase)
Shift NI format up (+) or down.
const uint32 MAXEXP_LNGDBL
maximum exponent for 80-bit long double
Definition ieee.h:42
const uint32 MAXEXP_FLOAT
maximum exponent for 32-bit float
Definition ieee.h:40
const uint32 MAXEXP_DOUBLE
maximum exponent for 64-bit double
Definition ieee.h:41
idaman THREAD_SAFE void ida_export realtoasc(char *buf, size_t bufsize, const fpvalue_t &x, uint mode)
idaman THREAD_SAFE fpvalue_error_t ida_export eetol64u(uint64 *out, const fpvalue_t &a, bool roundflg)
fpvalue_error_t
Definition ieee.h:48
@ REAL_ERROR_BADSTR
asctoreal: illegal input string
Definition ieee.h:54
@ REAL_ERROR_FORMAT
realcvt: not supported format for current .idp
Definition ieee.h:50
@ REAL_ERROR_ZERODIV
ediv: divide by 0
Definition ieee.h:55
@ REAL_ERROR_OK
no error
Definition ieee.h:49
@ REAL_ERROR_BADDATA
realcvt: illegal real data for load (IEEE data not filled)
Definition ieee.h:52
@ REAL_ERROR_INTOVER
eetol*: integer overflow
Definition ieee.h:56
@ REAL_ERROR_FPOVER
floating overflow or underflow
Definition ieee.h:53
@ REAL_ERROR_RANGE
realcvt: number too big (small) for store (mem NOT modified)
Definition ieee.h:51
idaman THREAD_SAFE fpvalue_error_t ida_export ieee_realcvt(void *m, fpvalue_t *out, uint16 swt)
Standard IEEE 754 floating point conversion function.
idaman THREAD_SAFE fpvalue_error_t ida_export eadd(const fpvalue_t &a, const fpvalue_t &b, fpvalue_t *zout, bool subflg)
uint16 eNI[IEEE_NI]
There is one more internal format used by IDA to store intermediate values.
Definition ieee.h:184
idaman IEEE_DEPRECATED THREAD_SAFE int ida_export eshift(eNI x, int sc)
Move eNE => eNI.
idaman THREAD_SAFE int ida_export ecmp(const fpvalue_t &a, const fpvalue_t &b)
idaman THREAD_SAFE fpvalue_error_t ida_export ediv(const fpvalue_t &a, const fpvalue_t &b, fpvalue_t *zout)
idaman THREAD_SAFE fpvalue_error_t ida_export eetol64(int64 *out, const fpvalue_t &a, bool roundflg)
idaman IEEE_DEPRECATED THREAD_SAFE void ida_export emovi(const fpvalue_t &a, eNI vout)
Move eNI => eNE.
idaman THREAD_SAFE void ida_export eltoe64(int64 l, fpvalue_t *vout)
idaman IEEE_DEPRECATED THREAD_SAFE void ida_export emovo(const eNI a, fpvalue_t *vout)
fpvalue_kind_t
Floating value kinds.
Definition ieee.h:28
@ FPV_NINF
negative infinity
Definition ieee.h:33
@ FPV_PINF
positive infinity
Definition ieee.h:32
@ FPV_NORM
regular value
Definition ieee.h:30
@ FPV_NAN
NaN.
Definition ieee.h:31
@ FPV_BADARG
wrong value of max_exp
Definition ieee.h:29
unsigned __int64 uint64
Definition llong.hpp:13
__int64 int64
Definition llong.hpp:14
unsigned short uint16
unsigned 16 bit value
Definition pro.h:346
unsigned int uint32
unsigned 32 bit value
Definition pro.h:348
adiff_t sval_t
signed value used by the processor.
Definition pro.h:446
int int32
signed 32 bit value
Definition pro.h:347
idaman size_t bufsize
Definition pro.h:600
unsigned int uint
unsigned 32 bit value
Definition pro.h:339
Processor-independent representation of a floating point value.
Definition ieee.h:98
fpvalue_error_t to_10bytes(void *fpval) const
Definition ieee.h:116
fpvalue_error_t from_float(float fpval)
Definition ieee.h:106
void eabs()
Calculate absolute value.
Definition ieee.h:155
fpvalue_error_t from_str(const char **p_str)
Convert string to IEEE.
Definition ieee.h:124
fpvalue_error_t to_double(double *fpval) const
Definition ieee.h:112
fpvalue_error_t fdiv(const fpvalue_t &y)
Definition ieee.h:149
void to_str(char *buf, size_t bufsize, uint mode) const
Convert IEEE to string.
Definition ieee.h:133
fpvalue_error_t to_12bytes(void *fpval) const
Definition ieee.h:120
fpvalue_error_t fsub(const fpvalue_t &y)
Definition ieee.h:147
fpvalue_error_t from_double(double fpval)
Definition ieee.h:107
void from_int64(int64 x)
Definition ieee.h:137
fpvalue_error_t to_uint64(uint64 *out, bool round=false) const
Definition ieee.h:143
fpvalue_error_t from_10bytes(const void *fpval)
Conversions for 10-byte floating point values.
Definition ieee.h:115
fpvalue_error_t mul_pow2(int32 power_of_2)
Multiply by a power of 2.
Definition ieee.h:152
fpvalue_error_t to_float(float *fpval) const
Definition ieee.h:111
bool is_negative() const
Is negative value?
Definition ieee.h:158
uint16 w[FPVAL_NWORDS]
Definition ieee.h:99
void from_uint64(uint64 x)
Definition ieee.h:138
DECLARE_COMPARISONS(fpvalue_t)
Definition ieee.h:102
void from_sval(sval_t x)
Convert integer to IEEE.
Definition ieee.h:136
fpvalue_error_t fadd(const fpvalue_t &y)
Arithmetic operations.
Definition ieee.h:146
void clear(void)
Definition ieee.h:101
fpvalue_error_t fmul(const fpvalue_t &y)
Definition ieee.h:148
fpvalue_error_t from_half(uint16 fpval)
Convert to the processor-independent representation.
Definition ieee.h:105
fpvalue_error_t to_int64(int64 *out, bool round=false) const
Definition ieee.h:142
fpvalue_error_t to_half(uint16 *fpval) const
Convert from the processor-independent representation.
Definition ieee.h:110
void negate()
Negate.
Definition ieee.h:161
fpvalue_error_t from_12bytes(const void *fpval)
Conversions for 12-byte floating point values.
Definition ieee.h:119
fpvalue_error_t to_sval(sval_t *out, bool round=false) const
Convert IEEE to integer (+-0.5 if round)
Definition ieee.h:141
fpvalue_kind_t get_kind() const
Get value kind.
Definition ieee.h:168