File: guest_generic_x87.h

package info (click to toggle)
valgrind 1%3A3.12.0~svn20160714-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 120,428 kB
  • ctags: 70,855
  • sloc: ansic: 674,645; exp: 26,134; xml: 21,574; asm: 7,570; cpp: 7,567; makefile: 7,380; sh: 6,188; perl: 5,855; haskell: 195
file content (142 lines) | stat: -rw-r--r-- 4,929 bytes parent folder | download
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142

/*---------------------------------------------------------------*/
/*--- begin                               guest_generic_x87.h ---*/
/*---------------------------------------------------------------*/

/*
   This file is part of Valgrind, a dynamic binary instrumentation
   framework.

   Copyright (C) 2004-2015 OpenWorks LLP
      info@open-works.net

   This program is free software; you can redistribute it and/or
   modify it under the terms of the GNU General Public License as
   published by the Free Software Foundation; either version 2 of the
   License, or (at your option) any later version.

   This program is distributed in the hope that it will be useful, but
   WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
   02110-1301, USA.

   The GNU General Public License is contained in the file COPYING.

   Neither the names of the U.S. Department of Energy nor the
   University of California nor the names of its contributors may be
   used to endorse or promote products derived from this software
   without prior written permission.
*/

/* This file contains functions for doing some x87-specific
   operations.  Both the amd64 and x86 front ends (guests) indirectly
   call these functions via guest helper calls.  By putting them here,
   code duplication is avoided.  Some of these functions are tricky
   and hard to verify, so there is much to be said for only having one
   copy thereof.
*/

#ifndef __VEX_GUEST_GENERIC_X87_H
#define __VEX_GUEST_GENERIC_X87_H

#include "libvex_basictypes.h"


/* Convert an IEEE754 double (64-bit) into an x87 extended double
   (80-bit), mimicing the hardware fairly closely.  Both numbers are
   stored little-endian.  Limitations, all of which could be fixed,
   given some level of hassle:

   * Identity of NaNs is not preserved.

   See comments in the code for more details.
*/
extern
void convert_f64le_to_f80le ( /*IN*/UChar* f64, /*OUT*/UChar* f80 );


/* Convert an x87 extended double (80-bit) into an IEEE 754 double
   (64-bit), mimicking the hardware fairly closely.  Both numbers are
   stored little-endian.  Limitations, both of which could be fixed,
   given some level of hassle:

   * Rounding following truncation could be a bit better.

   * Identity of NaNs is not preserved.

   See comments in the code for more details.
*/
extern
void convert_f80le_to_f64le ( /*IN*/UChar* f80, /*OUT*/UChar* f64 );


/* Layout of the real x87 state. */
typedef
   struct {
      UShort env[14];
      UChar  reg[80];
   }
   Fpu_State;

/* Offsets, in 16-bit ints, into the FPU environment (env) area. */
#define FP_ENV_CTRL   0
#define FP_ENV_STAT   2
#define FP_ENV_TAG    4
#define FP_ENV_IP     6 /* and 7 */
#define FP_ENV_CS     8
#define FP_ENV_LSTOP  9
#define FP_ENV_OPOFF  10 /* and 11 */
#define FP_ENV_OPSEL  12
#define FP_REG(ii)    (10*(7-(ii)))


/* Layout of the 16-bit FNSAVE x87 state. */
typedef
   struct {
      UShort env[7];
      UChar  reg[80];
   }
   Fpu_State_16;

/* Offsets, in 16-bit ints, into the FPU environment (env) area. */
#define FPS_ENV_CTRL   0
#define FPS_ENV_STAT   1
#define FPS_ENV_TAG    2
#define FPS_ENV_IP     3
#define FPS_ENV_CS     4
#define FPS_ENV_OPOFF  5
#define FPS_ENV_OPSEL  6


/* Do the computations for x86/amd64 FXTRACT.  Called directly from
   generated code.  CLEAN HELPER. */
extern ULong x86amd64g_calculate_FXTRACT ( ULong arg, HWord getExp );

/* Compute result and new OSZACP flags for all 8-bit PCMP{E,I}STR{I,M}
   variants.  See bigger comment on implementation of this function
   for details on call/return conventions. */
extern Bool compute_PCMPxSTRx ( /*OUT*/V128* resV,
                                /*OUT*/UInt* resOSZACP,
                                V128* argLV,  V128* argRV,
                                UInt zmaskL, UInt zmaskR,
                                UInt imm8,   Bool isxSTRM );

/* Compute result and new OSZACP flags for all 16-bit PCMP{E,I}STR{I,M}
   variants.  See bigger comment on implementation of this function
   for details on call/return conventions. */
extern Bool compute_PCMPxSTRx_wide ( /*OUT*/V128* resV,
                                     /*OUT*/UInt* resOSZACP,
                                     V128* argLV,  V128* argRV,
                                     UInt zmaskL, UInt zmaskR,
                                     UInt imm8,   Bool isxSTRM );

#endif /* ndef __VEX_GUEST_GENERIC_X87_H */

/*---------------------------------------------------------------*/
/*--- end                                 guest_generic_x87.h ---*/
/*---------------------------------------------------------------*/