floating.hh revision 12616:4b463b4dc098
1/*
2 * Copyright (c) 2009 The University of Edinburgh
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution;
12 * neither the name of the copyright holders nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 *
28 * Authors: Timothy M. Jones
29 *          Korey Sewell
30 */
31
32#ifndef __ARCH_POWER_INSTS_FLOATING_HH__
33#define __ARCH_POWER_INSTS_FLOATING_HH__
34
35#include "arch/power/insts/static_inst.hh"
36#include "base/bitfield.hh"
37#include "base/cprintf.hh"
38
39namespace PowerISA
40{
41
42/**
43 * Base class for floating point operations.
44 */
45class FloatOp : public PowerStaticInst
46{
47  protected:
48
49    bool rcSet;
50
51    /// Constructor
52    FloatOp(const char *mnem, MachInst _machInst, OpClass __opClass)
53      : PowerStaticInst(mnem, _machInst, __opClass)
54    {
55    }
56
57    // Test for NaN (maximum biased exponent & non-zero fraction)
58    inline bool
59    isNan(uint32_t val_bits) const
60    {
61        return ((bits(val_bits, 30, 23) == 0xFF) && bits(val_bits, 22, 0));
62    }
63
64    inline bool
65    isNan(uint64_t val_bits) const
66    {
67        return ((bits(val_bits, 62, 52) == 0x7FF) && bits(val_bits, 51, 0));
68    }
69
70    inline bool
71    isNan(float val) const
72    {
73        void *val_ptr = &val;
74        uint32_t val_bits = *(uint32_t *) val_ptr;
75        return isNan(val_bits);
76    }
77
78    inline bool
79    isNan(double val) const
80    {
81        void *val_ptr = &val;
82        uint64_t val_bits = *(uint64_t *) val_ptr;
83        return isNan(val_bits);
84    }
85
86    // Test for SNaN (NaN with high order bit of fraction set to 0)
87    inline bool
88    isSnan(uint32_t val_bits) const
89    {
90        return ((bits(val_bits, 30, 22) == 0x1FE) && bits(val_bits, 22, 0));
91    }
92
93    // Test for QNaN (NaN with high order bit of fraction set to 1)
94    inline bool
95    isQnan(uint32_t val_bits) const
96    {
97        return (bits(val_bits, 30, 22) == 0x1FF);
98    }
99
100    // Test for infinity (maximum biased exponent and zero fraction)
101    inline bool
102    isInfinity(uint32_t val_bits) const
103    {
104        return ((bits(val_bits, 30, 23) == 0xFF) && !bits(val_bits, 22, 0));
105    }
106
107    // Test for normalized numbers (biased exponent in the range 1 to 254)
108    inline bool
109    isNormalized(uint32_t val_bits) const
110    {
111        return ((bits(val_bits, 30, 23) != 0xFF) && bits(val_bits, 22, 0));
112    }
113
114    // Test for denormalized numbers (biased exponent of zero and
115    // non-zero fraction)
116    inline bool
117    isDenormalized(uint32_t val_bits) const
118    {
119        return (!bits(val_bits, 30, 23) && bits(val_bits, 22, 0));
120    }
121
122    // Test for zero (biased exponent of zero and fraction of zero)
123    inline bool
124    isZero(uint32_t val_bits) const
125    {
126        return (!bits(val_bits, 30, 23) && !bits(val_bits, 22, 0));
127    }
128
129    // Test for negative
130    inline bool
131    isNegative(uint32_t val_bits) const
132    {
133        return (bits(val_bits, 31));
134    }
135
136    // Compute the CR field
137    inline uint32_t
138    makeCRField(double a, double b) const
139    {
140        uint32_t c = 0;
141        if (isNan(a) || isNan(b)) { c = 0x1; }
142        else if (a < b)           { c = 0x8; }
143        else if (a > b)           { c = 0x4; }
144        else                      { c = 0x2; }
145        return c;
146    }
147
148    std::string generateDisassembly(
149            Addr pc, const SymbolTable *symtab) const override;
150};
151
152} // namespace PowerISA
153
154#endif //__ARCH_POWER_INSTS_FLOATING_HH__
155