2 /*---------------------------------------------------------------*/
3 /*--- begin guest_generic_x87.h ---*/
4 /*---------------------------------------------------------------*/
7 This file is part of Valgrind, a dynamic binary instrumentation
10 Copyright (C) 2004-2017 OpenWorks LLP
13 This program is free software; you can redistribute it and/or
14 modify it under the terms of the GNU General Public License as
15 published by the Free Software Foundation; either version 2 of the
16 License, or (at your option) any later version.
18 This program is distributed in the hope that it will be useful, but
19 WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 General Public License for more details.
23 You should have received a copy of the GNU General Public License
24 along with this program; if not, see <http://www.gnu.org/licenses/>.
26 The GNU General Public License is contained in the file COPYING.
28 Neither the names of the U.S. Department of Energy nor the
29 University of California nor the names of its contributors may be
30 used to endorse or promote products derived from this software
31 without prior written permission.
34 /* This file contains functions for doing some x87-specific
35 operations. Both the amd64 and x86 front ends (guests) indirectly
36 call these functions via guest helper calls. By putting them here,
37 code duplication is avoided. Some of these functions are tricky
38 and hard to verify, so there is much to be said for only having one
42 #ifndef __VEX_GUEST_GENERIC_X87_H
43 #define __VEX_GUEST_GENERIC_X87_H
45 #include "libvex_basictypes.h"
48 /* Convert an IEEE754 double (64-bit) into an x87 extended double
49 (80-bit), mimicing the hardware fairly closely. Both numbers are
50 stored little-endian. Limitations, all of which could be fixed,
51 given some level of hassle:
53 * Identity of NaNs is not preserved.
55 See comments in the code for more details.
58 void convert_f64le_to_f80le ( /*IN*/UChar
* f64
, /*OUT*/UChar
* f80
);
61 /* Convert an x87 extended double (80-bit) into an IEEE 754 double
62 (64-bit), mimicking the hardware fairly closely. Both numbers are
63 stored little-endian. Limitations, both of which could be fixed,
64 given some level of hassle:
66 * Rounding following truncation could be a bit better.
68 * Identity of NaNs is not preserved.
70 See comments in the code for more details.
73 void convert_f80le_to_f64le ( /*IN*/UChar
* f80
, /*OUT*/UChar
* f64
);
76 /* Layout of the real x87 state. */
84 /* Offsets, in 16-bit ints, into the FPU environment (env) area. */
88 #define FP_ENV_IP 6 /* and 7 */
90 #define FP_ENV_LSTOP 9
91 #define FP_ENV_OPOFF 10 /* and 11 */
92 #define FP_ENV_OPSEL 12
93 #define FP_REG(ii) (10*(7-(ii)))
96 /* Layout of the 16-bit FNSAVE x87 state. */
104 /* Offsets, in 16-bit ints, into the FPU environment (env) area. */
105 #define FPS_ENV_CTRL 0
106 #define FPS_ENV_STAT 1
107 #define FPS_ENV_TAG 2
110 #define FPS_ENV_OPOFF 5
111 #define FPS_ENV_OPSEL 6
114 /* Do the computations for x86/amd64 FXTRACT. Called directly from
115 generated code. CLEAN HELPER. */
116 extern ULong
x86amd64g_calculate_FXTRACT ( ULong arg
, HWord getExp
);
118 /* Compute result and new OSZACP flags for all 8-bit PCMP{E,I}STR{I,M}
119 variants. See bigger comment on implementation of this function
120 for details on call/return conventions. */
121 extern Bool
compute_PCMPxSTRx ( /*OUT*/V128
* resV
,
122 /*OUT*/UInt
* resOSZACP
,
123 V128
* argLV
, V128
* argRV
,
124 UInt zmaskL
, UInt zmaskR
,
125 UInt imm8
, Bool isxSTRM
);
127 /* Compute result and new OSZACP flags for all 16-bit PCMP{E,I}STR{I,M}
128 variants. See bigger comment on implementation of this function
129 for details on call/return conventions. */
130 extern Bool
compute_PCMPxSTRx_wide ( /*OUT*/V128
* resV
,
131 /*OUT*/UInt
* resOSZACP
,
132 V128
* argLV
, V128
* argRV
,
133 UInt zmaskL
, UInt zmaskR
,
134 UInt imm8
, Bool isxSTRM
);
136 #endif /* ndef __VEX_GUEST_GENERIC_X87_H */
138 /*---------------------------------------------------------------*/
139 /*--- end guest_generic_x87.h ---*/
140 /*---------------------------------------------------------------*/