2007-06-23 01:03:42 +02:00
|
|
|
/*
|
2007-11-13 22:58:16 +01:00
|
|
|
* Copyright (c) 2007 MIPS Technologies, Inc.
|
2007-06-23 01:03:42 +02:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions are
|
|
|
|
* met: redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer;
|
|
|
|
* redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution;
|
|
|
|
* neither the name of the copyright holders nor the names of its
|
|
|
|
* contributors may be used to endorse or promote products derived from
|
|
|
|
* this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
* Authors: Brett Miller
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "arch/mips/dsp.hh"
|
2011-04-15 19:44:06 +02:00
|
|
|
#include "arch/mips/isa_traits.hh"
|
|
|
|
#include "base/bitfield.hh"
|
|
|
|
#include "base/misc.hh"
|
2007-06-23 01:03:42 +02:00
|
|
|
#include "config/full_system.hh"
|
|
|
|
#include "cpu/static_inst.hh"
|
|
|
|
#include "sim/serialize.hh"
|
|
|
|
|
|
|
|
using namespace MipsISA;
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
int32_t
|
2008-09-26 17:18:53 +02:00
|
|
|
MipsISA::bitrev(int32_t value)
|
2007-06-23 01:03:42 +02:00
|
|
|
{
|
|
|
|
int32_t result = 0;
|
2008-09-26 17:18:53 +02:00
|
|
|
int shift;
|
2007-06-23 01:03:42 +02:00
|
|
|
|
2008-09-26 17:18:53 +02:00
|
|
|
for (int i = 0; i < 16; i++) {
|
|
|
|
shift = 2 * i - 15;
|
2007-06-23 01:03:42 +02:00
|
|
|
|
2008-09-26 17:18:53 +02:00
|
|
|
if (shift < 0)
|
|
|
|
result |= (value & 1 << i) << -shift;
|
2007-06-23 01:03:42 +02:00
|
|
|
else
|
2008-09-26 17:18:53 +02:00
|
|
|
result |= (value & 1 << i) >> shift;
|
2007-06-23 01:03:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t
|
2008-09-26 17:18:53 +02:00
|
|
|
MipsISA::dspSaturate(uint64_t value, int32_t fmt, int32_t sign,
|
|
|
|
uint32_t *overflow)
|
2007-06-23 01:03:42 +02:00
|
|
|
{
|
2008-09-26 17:18:53 +02:00
|
|
|
int64_t svalue = (int64_t)value;
|
2007-06-23 01:03:42 +02:00
|
|
|
|
2008-09-26 18:37:21 +02:00
|
|
|
switch (sign) {
|
2007-06-23 01:03:42 +02:00
|
|
|
case SIGNED:
|
2008-09-26 17:18:53 +02:00
|
|
|
if (svalue > (int64_t)FIXED_SMAX[fmt]) {
|
2007-06-23 01:03:42 +02:00
|
|
|
*overflow = 1;
|
|
|
|
svalue = (int64_t)FIXED_SMAX[fmt];
|
2008-09-26 17:18:53 +02:00
|
|
|
} else if (svalue < (int64_t)FIXED_SMIN[fmt]) {
|
2007-06-23 01:03:42 +02:00
|
|
|
*overflow = 1;
|
|
|
|
svalue = (int64_t)FIXED_SMIN[fmt];
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case UNSIGNED:
|
2008-09-26 17:18:53 +02:00
|
|
|
if (svalue > (int64_t)FIXED_UMAX[fmt]) {
|
2007-06-23 01:03:42 +02:00
|
|
|
*overflow = 1;
|
|
|
|
svalue = FIXED_UMAX[fmt];
|
2008-09-26 17:18:53 +02:00
|
|
|
} else if (svalue < (int64_t)FIXED_UMIN[fmt]) {
|
2007-06-23 01:03:42 +02:00
|
|
|
*overflow = 1;
|
|
|
|
svalue = FIXED_UMIN[fmt];
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2008-09-26 17:18:53 +02:00
|
|
|
return (uint64_t)svalue;
|
2007-06-23 01:03:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t
|
2008-09-26 17:18:53 +02:00
|
|
|
MipsISA::checkOverflow(uint64_t value, int32_t fmt, int32_t sign,
|
|
|
|
uint32_t *overflow)
|
2007-06-23 01:03:42 +02:00
|
|
|
{
|
2008-09-26 17:18:53 +02:00
|
|
|
int64_t svalue = (int64_t)value;
|
2007-06-23 01:03:42 +02:00
|
|
|
|
2008-09-26 18:37:21 +02:00
|
|
|
switch (sign)
|
2007-06-23 01:03:42 +02:00
|
|
|
{
|
|
|
|
case SIGNED:
|
2008-09-26 17:18:53 +02:00
|
|
|
if (svalue > (int64_t)FIXED_SMAX[fmt] ||
|
|
|
|
svalue < (int64_t)FIXED_SMIN[fmt])
|
2007-06-23 01:03:42 +02:00
|
|
|
*overflow = 1;
|
|
|
|
break;
|
|
|
|
case UNSIGNED:
|
2008-09-26 17:18:53 +02:00
|
|
|
if (svalue > (int64_t)FIXED_UMAX[fmt] ||
|
|
|
|
svalue < (int64_t)FIXED_UMIN[fmt])
|
2007-06-23 01:03:42 +02:00
|
|
|
*overflow = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2008-09-26 17:18:53 +02:00
|
|
|
return (uint64_t)svalue;
|
2007-06-23 01:03:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t
|
2008-09-26 17:18:53 +02:00
|
|
|
MipsISA::signExtend(uint64_t value, int32_t fmt)
|
2007-06-23 01:03:42 +02:00
|
|
|
{
|
|
|
|
int32_t signpos = SIMD_NBITS[fmt];
|
2008-09-26 17:18:53 +02:00
|
|
|
uint64_t sign = uint64_t(1) << (signpos - 1);
|
2007-06-23 01:03:42 +02:00
|
|
|
uint64_t ones = ~(0ULL);
|
|
|
|
|
2008-09-26 17:18:53 +02:00
|
|
|
if (value & sign)
|
2007-06-23 01:03:42 +02:00
|
|
|
value |= (ones << signpos); // extend with ones
|
|
|
|
else
|
|
|
|
value &= (ones >> (64 - signpos)); // extend with zeros
|
|
|
|
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t
|
2008-09-26 17:18:53 +02:00
|
|
|
MipsISA::addHalfLsb(uint64_t value, int32_t lsbpos)
|
2007-06-23 01:03:42 +02:00
|
|
|
{
|
2008-09-26 17:18:53 +02:00
|
|
|
return value += ULL(1) << (lsbpos - 1);
|
2007-06-23 01:03:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int32_t
|
2008-09-26 17:18:53 +02:00
|
|
|
MipsISA::dspAbs(int32_t a, int32_t fmt, uint32_t *dspctl)
|
2007-06-23 01:03:42 +02:00
|
|
|
{
|
|
|
|
int nvals = SIMD_NVALS[fmt];
|
|
|
|
int32_t result;
|
|
|
|
int64_t svalue;
|
|
|
|
uint32_t ouflag = 0;
|
|
|
|
uint64_t a_values[SIMD_MAX_VALS];
|
|
|
|
|
2008-09-26 17:18:53 +02:00
|
|
|
simdUnpack(a, a_values, fmt, SIGNED);
|
2007-06-23 01:03:42 +02:00
|
|
|
|
2008-09-26 17:18:53 +02:00
|
|
|
for (int i = 0; i < nvals; i++) {
|
2007-06-23 01:03:42 +02:00
|
|
|
svalue = (int64_t)a_values[i];
|
|
|
|
|
2008-09-26 17:18:53 +02:00
|
|
|
if (a_values[i] == FIXED_SMIN[fmt]) {
|
2007-06-23 01:03:42 +02:00
|
|
|
a_values[i] = FIXED_SMAX[fmt];
|
|
|
|
ouflag = 1;
|
2008-09-26 17:18:53 +02:00
|
|
|
} else if (svalue < 0) {
|
|
|
|
a_values[i] = uint64_t(0 - svalue);
|
2007-06-23 01:03:42 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-09-26 17:18:53 +02:00
|
|
|
simdPack(a_values, &result, fmt);
|
2007-06-23 01:03:42 +02:00
|
|
|
|
2008-09-26 17:18:53 +02:00
|
|
|
if (ouflag)
|
|
|
|
writeDSPControl(dspctl, (ouflag << 4) << DSP_CTL_POS[DSP_OUFLAG],
|
|
|
|
1 << DSP_OUFLAG);
|
2007-06-23 01:03:42 +02:00
|
|
|
|
2008-09-26 17:18:53 +02:00
|
|
|
return result;
|
2007-06-23 01:03:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int32_t
|
2008-09-26 17:18:53 +02:00
|
|
|
MipsISA::dspAdd(int32_t a, int32_t b, int32_t fmt, int32_t saturate,
|
|
|
|
int32_t sign, uint32_t *dspctl)
|
2007-06-23 01:03:42 +02:00
|
|
|
{
|
|
|
|
int nvals = SIMD_NVALS[fmt];
|
|
|
|
int32_t result;
|
|
|
|
uint32_t ouflag = 0;
|
|
|
|
uint64_t a_values[SIMD_MAX_VALS];
|
|
|
|
uint64_t b_values[SIMD_MAX_VALS];
|
|
|
|
|
2008-09-26 17:18:53 +02:00
|
|
|
simdUnpack(a, a_values, fmt, sign);
|
|
|
|
simdUnpack(b, b_values, fmt, sign);
|
2007-06-23 01:03:42 +02:00
|
|
|
|
2008-09-26 17:18:53 +02:00
|
|
|
for (int i = 0; i < nvals; i++)
|
2007-06-23 01:03:42 +02:00
|
|
|
{
|
2008-09-26 17:18:53 +02:00
|
|
|
if (saturate)
|
|
|
|
a_values[i] = dspSaturate(a_values[i] + b_values[i], fmt, sign,
|
|
|
|
&ouflag);
|
2007-06-23 01:03:42 +02:00
|
|
|
else
|
2008-09-26 17:18:53 +02:00
|
|
|
a_values[i] = checkOverflow(a_values[i] + b_values[i], fmt, sign,
|
|
|
|
&ouflag);
|
2007-06-23 01:03:42 +02:00
|
|
|
}
|
|
|
|
|
2008-09-26 17:18:53 +02:00
|
|
|
simdPack(a_values, &result, fmt);
|
2007-06-23 01:03:42 +02:00
|
|
|
|
2008-09-26 17:18:53 +02:00
|
|
|
if (ouflag)
|
|
|
|
writeDSPControl(dspctl, (ouflag << 4) << DSP_CTL_POS[DSP_OUFLAG],
|
|
|
|
1 << DSP_OUFLAG);
|
2007-06-23 01:03:42 +02:00
|
|
|
|
2008-09-26 17:18:53 +02:00
|
|
|
return result;
|
2007-06-23 01:03:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int32_t
|
2008-09-26 17:18:53 +02:00
|
|
|
MipsISA::dspAddh(int32_t a, int32_t b, int32_t fmt, int32_t round,
|
|
|
|
int32_t sign)
|
2007-06-23 01:03:42 +02:00
|
|
|
{
|
|
|
|
int nvals = SIMD_NVALS[fmt];
|
|
|
|
int32_t result;
|
|
|
|
uint64_t a_values[SIMD_MAX_VALS];
|
|
|
|
uint64_t b_values[SIMD_MAX_VALS];
|
|
|
|
|
2008-09-26 17:18:53 +02:00
|
|
|
simdUnpack(a, a_values, fmt, sign);
|
|
|
|
simdUnpack(b, b_values, fmt, sign);
|
2007-06-23 01:03:42 +02:00
|
|
|
|
2008-09-26 17:18:53 +02:00
|
|
|
for (int i = 0; i < nvals; i++) {
|
|
|
|
if (round)
|
|
|
|
a_values[i] = addHalfLsb(a_values[i] + b_values[i], 1) >> 1;
|
2007-06-23 01:03:42 +02:00
|
|
|
else
|
2008-09-26 17:18:53 +02:00
|
|
|
a_values[i] = (a_values[i] + b_values[i]) >> 1;
|
2007-06-23 01:03:42 +02:00
|
|
|
}
|
|
|
|
|
2008-09-26 17:18:53 +02:00
|
|
|
simdPack(a_values, &result, fmt);
|
2007-06-23 01:03:42 +02:00
|
|
|
|
2008-09-26 17:18:53 +02:00
|
|
|
return result;
|
2007-06-23 01:03:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int32_t
|
2008-09-26 17:18:53 +02:00
|
|
|
MipsISA::dspSub(int32_t a, int32_t b, int32_t fmt, int32_t saturate,
|
|
|
|
int32_t sign, uint32_t *dspctl)
|
2007-06-23 01:03:42 +02:00
|
|
|
{
|
|
|
|
int nvals = SIMD_NVALS[fmt];
|
|
|
|
int32_t result;
|
|
|
|
uint32_t ouflag = 0;
|
|
|
|
uint64_t a_values[SIMD_MAX_VALS];
|
|
|
|
uint64_t b_values[SIMD_MAX_VALS];
|
|
|
|
|
2008-09-26 17:18:53 +02:00
|
|
|
simdUnpack(a, a_values, fmt, sign);
|
|
|
|
simdUnpack(b, b_values, fmt, sign);
|
2007-06-23 01:03:42 +02:00
|
|
|
|
2008-09-26 17:18:53 +02:00
|
|
|
for (int i = 0; i < nvals; i++) {
|
|
|
|
if (saturate)
|
|
|
|
a_values[i] = dspSaturate(a_values[i] - b_values[i], fmt, sign,
|
|
|
|
&ouflag);
|
2007-06-23 01:03:42 +02:00
|
|
|
else
|
2008-09-26 17:18:53 +02:00
|
|
|
a_values[i] = checkOverflow(a_values[i] - b_values[i], fmt, sign,
|
|
|
|
&ouflag);
|
2007-06-23 01:03:42 +02:00
|
|
|
}
|
|
|
|
|
2008-09-26 17:18:53 +02:00
|
|
|
simdPack(a_values, &result, fmt);
|
2007-06-23 01:03:42 +02:00
|
|
|
|
2008-09-26 17:18:53 +02:00
|
|
|
if (ouflag)
|
|
|
|
writeDSPControl(dspctl, (ouflag << 4) << DSP_CTL_POS[DSP_OUFLAG],
|
|
|
|
1 << DSP_OUFLAG);
|
2007-06-23 01:03:42 +02:00
|
|
|
|
2008-09-26 17:18:53 +02:00
|
|
|
return result;
|
2007-06-23 01:03:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int32_t
|
2008-09-26 17:18:53 +02:00
|
|
|
MipsISA::dspSubh(int32_t a, int32_t b, int32_t fmt, int32_t round,
|
|
|
|
int32_t sign)
|
2007-06-23 01:03:42 +02:00
|
|
|
{
|
|
|
|
int nvals = SIMD_NVALS[fmt];
|
|
|
|
int32_t result;
|
|
|
|
uint64_t a_values[SIMD_MAX_VALS];
|
|
|
|
uint64_t b_values[SIMD_MAX_VALS];
|
|
|
|
|
2008-09-26 17:18:53 +02:00
|
|
|
simdUnpack(a, a_values, fmt, sign);
|
|
|
|
simdUnpack(b, b_values, fmt, sign);
|
2007-06-23 01:03:42 +02:00
|
|
|
|
2008-09-26 17:18:53 +02:00
|
|
|
for (int i = 0; i < nvals; i++)
|
2007-06-23 01:03:42 +02:00
|
|
|
{
|
2008-09-26 17:18:53 +02:00
|
|
|
if (round)
|
|
|
|
a_values[i] = addHalfLsb(a_values[i] - b_values[i], 1) >> 1;
|
2007-06-23 01:03:42 +02:00
|
|
|
else
|
2008-09-26 17:18:53 +02:00
|
|
|
a_values[i] = (a_values[i] - b_values[i]) >> 1;
|
2007-06-23 01:03:42 +02:00
|
|
|
}
|
|
|
|
|
2008-09-26 17:18:53 +02:00
|
|
|
simdPack(a_values, &result, fmt);
|
2007-06-23 01:03:42 +02:00
|
|
|
|
2008-09-26 17:18:53 +02:00
|
|
|
return result;
|
2007-06-23 01:03:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int32_t
|
2008-09-26 17:18:53 +02:00
|
|
|
MipsISA::dspShll(int32_t a, uint32_t sa, int32_t fmt, int32_t saturate,
|
|
|
|
int32_t sign, uint32_t *dspctl)
|
2007-06-23 01:03:42 +02:00
|
|
|
{
|
|
|
|
int nvals = SIMD_NVALS[fmt];
|
|
|
|
int32_t result;
|
|
|
|
uint32_t ouflag = 0;
|
|
|
|
uint64_t a_values[SIMD_MAX_VALS];
|
|
|
|
|
2008-09-26 17:18:53 +02:00
|
|
|
sa = bits(sa, SIMD_LOG2N[fmt] - 1, 0);
|
|
|
|
simdUnpack(a, a_values, fmt, sign);
|
2007-06-23 01:03:42 +02:00
|
|
|
|
2008-09-26 17:18:53 +02:00
|
|
|
for (int i = 0; i < nvals; i++)
|
2007-06-23 01:03:42 +02:00
|
|
|
{
|
2008-09-26 17:18:53 +02:00
|
|
|
if (saturate)
|
|
|
|
a_values[i] = dspSaturate(a_values[i] << sa, fmt, sign, &ouflag);
|
2007-06-23 01:03:42 +02:00
|
|
|
else
|
2008-09-26 17:18:53 +02:00
|
|
|
a_values[i] = checkOverflow(a_values[i] << sa, fmt, sign, &ouflag);
|
2007-06-23 01:03:42 +02:00
|
|
|
}
|
|
|
|
|
2008-09-26 17:18:53 +02:00
|
|
|
simdPack(a_values, &result, fmt);
|
2007-06-23 01:03:42 +02:00
|
|
|
|
2008-09-26 17:18:53 +02:00
|
|
|
if (ouflag)
|
|
|
|
writeDSPControl(dspctl, (ouflag << 6) << DSP_CTL_POS[DSP_OUFLAG],
|
|
|
|
1 << DSP_OUFLAG);
|
2007-06-23 01:03:42 +02:00
|
|
|
|
2008-09-26 17:18:53 +02:00
|
|
|
return result;
|
2007-06-23 01:03:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int32_t
|
2008-09-26 17:18:53 +02:00
|
|
|
MipsISA::dspShrl(int32_t a, uint32_t sa, int32_t fmt, int32_t sign)
|
2007-06-23 01:03:42 +02:00
|
|
|
{
|
|
|
|
int nvals = SIMD_NVALS[fmt];
|
|
|
|
int32_t result;
|
|
|
|
uint64_t a_values[SIMD_MAX_VALS];
|
|
|
|
|
2008-09-26 17:18:53 +02:00
|
|
|
sa = bits(sa, SIMD_LOG2N[fmt] - 1, 0);
|
2007-06-23 01:03:42 +02:00
|
|
|
|
2008-09-26 17:18:53 +02:00
|
|
|
simdUnpack(a, a_values, fmt, UNSIGNED);
|
2007-06-23 01:03:42 +02:00
|
|
|
|
2008-09-26 17:18:53 +02:00
|
|
|
for (int i = 0; i < nvals; i++)
|
2007-06-23 01:03:42 +02:00
|
|
|
a_values[i] = a_values[i] >> sa;
|
|
|
|
|
2008-09-26 17:18:53 +02:00
|
|
|
simdPack(a_values, &result, fmt);
|
2007-06-23 01:03:42 +02:00
|
|
|
|
2008-09-26 17:18:53 +02:00
|
|
|
return result;
|
2007-06-23 01:03:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int32_t
|
2008-09-26 17:18:53 +02:00
|
|
|
MipsISA::dspShra(int32_t a, uint32_t sa, int32_t fmt, int32_t round,
|
|
|
|
int32_t sign, uint32_t *dspctl)
|
2007-06-23 01:03:42 +02:00
|
|
|
{
|
|
|
|
int nvals = SIMD_NVALS[fmt];
|
|
|
|
int32_t result;
|
|
|
|
uint64_t a_values[SIMD_MAX_VALS];
|
|
|
|
|
2008-09-26 17:18:53 +02:00
|
|
|
sa = bits(sa, SIMD_LOG2N[fmt] - 1, 0);
|
2007-06-23 01:03:42 +02:00
|
|
|
|
2008-09-26 17:18:53 +02:00
|
|
|
simdUnpack(a, a_values, fmt, SIGNED);
|
2007-06-23 01:03:42 +02:00
|
|
|
|
2008-09-26 17:18:53 +02:00
|
|
|
for (int i = 0; i < nvals; i++) {
|
|
|
|
if (round)
|
|
|
|
a_values[i] = addHalfLsb(a_values[i], sa) >> sa;
|
2007-06-23 01:03:42 +02:00
|
|
|
else
|
|
|
|
a_values[i] = a_values[i] >> sa;
|
|
|
|
}
|
|
|
|
|
2008-09-26 17:18:53 +02:00
|
|
|
simdPack(a_values, &result, fmt);
|
2007-06-23 01:03:42 +02:00
|
|
|
|
2008-09-26 17:18:53 +02:00
|
|
|
return result;
|
2007-06-23 01:03:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int32_t
|
2008-09-26 17:18:53 +02:00
|
|
|
MipsISA::dspMulq(int32_t a, int32_t b, int32_t fmt, int32_t saturate,
|
|
|
|
int32_t round, uint32_t *dspctl)
|
2007-06-23 01:03:42 +02:00
|
|
|
{
|
|
|
|
int nvals = SIMD_NVALS[fmt];
|
|
|
|
int sa = SIMD_NBITS[fmt];
|
|
|
|
int32_t result;
|
|
|
|
uint32_t ouflag = 0;
|
|
|
|
uint64_t a_values[SIMD_MAX_VALS];
|
|
|
|
uint64_t b_values[SIMD_MAX_VALS];
|
|
|
|
int64_t temp;
|
|
|
|
|
2008-09-26 17:18:53 +02:00
|
|
|
simdUnpack(a, a_values, fmt, SIGNED);
|
|
|
|
simdUnpack(b, b_values, fmt, SIGNED);
|
2007-06-23 01:03:42 +02:00
|
|
|
|
2008-09-26 17:18:53 +02:00
|
|
|
for (int i = 0; i < nvals; i++) {
|
|
|
|
if (round)
|
|
|
|
temp =
|
|
|
|
(int64_t)addHalfLsb(a_values[i] * b_values[i] << 1, sa) >> sa;
|
2007-06-23 01:03:42 +02:00
|
|
|
else
|
|
|
|
temp = (int64_t)(a_values[i] * b_values[i]) >> (sa - 1);
|
|
|
|
|
2008-09-26 17:18:53 +02:00
|
|
|
if (a_values[i] == FIXED_SMIN[fmt] && b_values[i] == FIXED_SMIN[fmt]) {
|
2007-06-23 01:03:42 +02:00
|
|
|
ouflag = 1;
|
|
|
|
|
2008-09-26 17:18:53 +02:00
|
|
|
if (saturate)
|
2007-06-23 01:03:42 +02:00
|
|
|
temp = FIXED_SMAX[fmt];
|
|
|
|
}
|
|
|
|
|
|
|
|
a_values[i] = temp;
|
|
|
|
}
|
|
|
|
|
2008-09-26 17:18:53 +02:00
|
|
|
simdPack(a_values, &result, fmt);
|
2007-06-23 01:03:42 +02:00
|
|
|
|
2008-09-26 17:18:53 +02:00
|
|
|
if (ouflag)
|
|
|
|
writeDSPControl(dspctl, (ouflag << 5) << DSP_CTL_POS[DSP_OUFLAG],
|
|
|
|
1 << DSP_OUFLAG);
|
2007-06-23 01:03:42 +02:00
|
|
|
|
2008-09-26 17:18:53 +02:00
|
|
|
return result;
|
2007-06-23 01:03:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int32_t
|
2008-09-26 17:18:53 +02:00
|
|
|
MipsISA::dspMul(int32_t a, int32_t b, int32_t fmt, int32_t saturate,
|
|
|
|
uint32_t *dspctl)
|
2007-06-23 01:03:42 +02:00
|
|
|
{
|
|
|
|
int nvals = SIMD_NVALS[fmt];
|
|
|
|
int32_t result;
|
|
|
|
uint32_t ouflag = 0;
|
|
|
|
uint64_t a_values[SIMD_MAX_VALS];
|
|
|
|
uint64_t b_values[SIMD_MAX_VALS];
|
|
|
|
|
2008-09-26 17:18:53 +02:00
|
|
|
simdUnpack(a, a_values, fmt, SIGNED);
|
|
|
|
simdUnpack(b, b_values, fmt, SIGNED);
|
2007-06-23 01:03:42 +02:00
|
|
|
|
2008-09-26 17:18:53 +02:00
|
|
|
for (int i = 0; i < nvals; i++)
|
2007-06-23 01:03:42 +02:00
|
|
|
{
|
2008-09-26 17:18:53 +02:00
|
|
|
if (saturate)
|
|
|
|
a_values[i] = dspSaturate(a_values[i] * b_values[i], fmt, SIGNED,
|
|
|
|
&ouflag);
|
2007-06-23 01:03:42 +02:00
|
|
|
else
|
2008-09-26 17:18:53 +02:00
|
|
|
a_values[i] = checkOverflow(a_values[i] * b_values[i], fmt, SIGNED,
|
|
|
|
&ouflag);
|
2007-06-23 01:03:42 +02:00
|
|
|
}
|
|
|
|
|
2008-09-26 17:18:53 +02:00
|
|
|
simdPack(a_values, &result, fmt);
|
2007-06-23 01:03:42 +02:00
|
|
|
|
2008-09-26 17:18:53 +02:00
|
|
|
if (ouflag)
|
|
|
|
writeDSPControl(dspctl, (ouflag << 5) << DSP_CTL_POS[DSP_OUFLAG],
|
|
|
|
1 << DSP_OUFLAG);
|
2007-06-23 01:03:42 +02:00
|
|
|
|
2008-09-26 17:18:53 +02:00
|
|
|
return result;
|
2007-06-23 01:03:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int32_t
|
2008-09-26 17:18:53 +02:00
|
|
|
MipsISA::dspMuleu(int32_t a, int32_t b, int32_t mode, uint32_t *dspctl)
|
2007-06-23 01:03:42 +02:00
|
|
|
{
|
|
|
|
int nvals = SIMD_NVALS[SIMD_FMT_PH];
|
|
|
|
int32_t result;
|
|
|
|
uint32_t ouflag = 0;
|
|
|
|
uint64_t a_values[SIMD_MAX_VALS];
|
|
|
|
uint64_t b_values[SIMD_MAX_VALS];
|
|
|
|
|
2008-09-26 17:18:53 +02:00
|
|
|
simdUnpack(a, a_values, SIMD_FMT_QB, UNSIGNED);
|
|
|
|
simdUnpack(b, b_values, SIMD_FMT_PH, UNSIGNED);
|
2007-06-23 01:03:42 +02:00
|
|
|
|
2008-09-26 18:37:21 +02:00
|
|
|
switch (mode) {
|
2007-06-23 01:03:42 +02:00
|
|
|
case MODE_L:
|
2008-09-26 17:18:53 +02:00
|
|
|
for (int i = 0; i < nvals; i++)
|
|
|
|
b_values[i] = dspSaturate(a_values[i + 2] * b_values[i],
|
|
|
|
SIMD_FMT_PH, UNSIGNED, &ouflag);
|
2007-06-23 01:03:42 +02:00
|
|
|
break;
|
|
|
|
case MODE_R:
|
2008-09-26 17:18:53 +02:00
|
|
|
for (int i = 0; i < nvals; i++)
|
|
|
|
b_values[i] = dspSaturate(a_values[i] * b_values[i], SIMD_FMT_PH,
|
|
|
|
UNSIGNED, &ouflag);
|
2007-06-23 01:03:42 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2008-09-26 17:18:53 +02:00
|
|
|
simdPack(b_values, &result, SIMD_FMT_PH);
|
2007-06-23 01:03:42 +02:00
|
|
|
|
2008-09-26 17:18:53 +02:00
|
|
|
if (ouflag)
|
|
|
|
writeDSPControl(dspctl, (ouflag << 5) << DSP_CTL_POS[DSP_OUFLAG],
|
|
|
|
1 << DSP_OUFLAG);
|
2007-06-23 01:03:42 +02:00
|
|
|
|
2008-09-26 17:18:53 +02:00
|
|
|
return result;
|
2007-06-23 01:03:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int32_t
|
2008-09-26 17:18:53 +02:00
|
|
|
MipsISA::dspMuleq(int32_t a, int32_t b, int32_t mode, uint32_t *dspctl)
|
2007-06-23 01:03:42 +02:00
|
|
|
{
|
|
|
|
int nvals = SIMD_NVALS[SIMD_FMT_W];
|
|
|
|
int32_t result;
|
|
|
|
uint32_t ouflag = 0;
|
|
|
|
uint64_t a_values[SIMD_MAX_VALS];
|
|
|
|
uint64_t b_values[SIMD_MAX_VALS];
|
|
|
|
uint64_t c_values[SIMD_MAX_VALS];
|
|
|
|
|
2009-11-05 01:57:01 +01:00
|
|
|
memset(c_values, 0, sizeof(c_values));
|
|
|
|
|
2008-09-26 17:18:53 +02:00
|
|
|
simdUnpack(a, a_values, SIMD_FMT_PH, SIGNED);
|
|
|
|
simdUnpack(b, b_values, SIMD_FMT_PH, SIGNED);
|
2007-06-23 01:03:42 +02:00
|
|
|
|
2008-09-26 18:37:21 +02:00
|
|
|
switch (mode) {
|
2007-06-23 01:03:42 +02:00
|
|
|
case MODE_L:
|
2008-09-26 17:18:53 +02:00
|
|
|
for (int i = 0; i < nvals; i++)
|
|
|
|
c_values[i] = dspSaturate(a_values[i + 1] * b_values[i + 1] << 1,
|
|
|
|
SIMD_FMT_W, SIGNED, &ouflag);
|
2007-06-23 01:03:42 +02:00
|
|
|
break;
|
|
|
|
case MODE_R:
|
2008-09-26 17:18:53 +02:00
|
|
|
for (int i = 0; i < nvals; i++)
|
|
|
|
c_values[i] = dspSaturate(a_values[i] * b_values[i] << 1,
|
|
|
|
SIMD_FMT_W, SIGNED, &ouflag);
|
2007-06-23 01:03:42 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2008-09-26 17:18:53 +02:00
|
|
|
simdPack(c_values, &result, SIMD_FMT_W);
|
2007-06-23 01:03:42 +02:00
|
|
|
|
2008-09-26 17:18:53 +02:00
|
|
|
if (ouflag)
|
|
|
|
writeDSPControl(dspctl, (ouflag << 5) << DSP_CTL_POS[DSP_OUFLAG],
|
|
|
|
1 << DSP_OUFLAG);
|
2007-06-23 01:03:42 +02:00
|
|
|
|
2008-09-26 17:18:53 +02:00
|
|
|
return result;
|
2007-06-23 01:03:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int64_t
|
2008-09-26 17:18:53 +02:00
|
|
|
MipsISA::dspDpaq(int64_t dspac, int32_t a, int32_t b, int32_t ac,
|
|
|
|
int32_t infmt, int32_t outfmt, int32_t postsat, int32_t mode,
|
|
|
|
uint32_t *dspctl)
|
2007-06-23 01:03:42 +02:00
|
|
|
{
|
|
|
|
int nvals = SIMD_NVALS[infmt];
|
|
|
|
int64_t result = 0;
|
|
|
|
int64_t temp = 0;
|
|
|
|
uint32_t ouflag = 0;
|
|
|
|
uint64_t a_values[SIMD_MAX_VALS];
|
|
|
|
uint64_t b_values[SIMD_MAX_VALS];
|
|
|
|
|
2008-09-26 17:18:53 +02:00
|
|
|
simdUnpack(a, a_values, infmt, SIGNED);
|
|
|
|
simdUnpack(b, b_values, infmt, SIGNED);
|
2007-06-23 01:03:42 +02:00
|
|
|
|
2008-09-26 17:18:53 +02:00
|
|
|
for (int i = 0; i < nvals; i++) {
|
2008-09-26 18:37:21 +02:00
|
|
|
switch (mode) {
|
2007-06-23 01:03:42 +02:00
|
|
|
case MODE_X:
|
2008-09-26 17:18:53 +02:00
|
|
|
if (a_values[nvals - 1 - i] == FIXED_SMIN[infmt] &&
|
|
|
|
b_values[i] == FIXED_SMIN[infmt]) {
|
2007-06-23 01:03:42 +02:00
|
|
|
result += FIXED_SMAX[outfmt];
|
|
|
|
ouflag = 1;
|
|
|
|
}
|
|
|
|
else
|
2008-09-26 17:18:53 +02:00
|
|
|
result += a_values[nvals - 1 - i] * b_values[i] << 1;
|
2007-06-23 01:03:42 +02:00
|
|
|
break;
|
|
|
|
default:
|
2008-09-26 17:18:53 +02:00
|
|
|
if (a_values[i] == FIXED_SMIN[infmt] &&
|
|
|
|
b_values[i] == FIXED_SMIN[infmt]) {
|
2007-06-23 01:03:42 +02:00
|
|
|
result += FIXED_SMAX[outfmt];
|
|
|
|
ouflag = 1;
|
2008-09-26 17:18:53 +02:00
|
|
|
} else {
|
2007-06-23 01:03:42 +02:00
|
|
|
result += a_values[i] * b_values[i] << 1;
|
2008-09-26 17:18:53 +02:00
|
|
|
}
|
2007-06-23 01:03:42 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-09-26 17:18:53 +02:00
|
|
|
if (postsat) {
|
|
|
|
if (outfmt == SIMD_FMT_L) {
|
|
|
|
int signa = bits(dspac, 63, 63);
|
|
|
|
int signb = bits(result, 63, 63);
|
2007-06-23 01:03:42 +02:00
|
|
|
|
|
|
|
temp = dspac + result;
|
|
|
|
|
2008-09-26 17:18:53 +02:00
|
|
|
if (signa == signb && bits(temp, 63, 63) != signa) {
|
2007-06-23 01:03:42 +02:00
|
|
|
ouflag = 1;
|
2008-09-26 17:18:53 +02:00
|
|
|
if (signa)
|
2007-06-23 01:03:42 +02:00
|
|
|
dspac = FIXED_SMIN[outfmt];
|
|
|
|
else
|
|
|
|
dspac = FIXED_SMAX[outfmt];
|
2008-09-26 17:18:53 +02:00
|
|
|
} else {
|
2007-06-23 01:03:42 +02:00
|
|
|
dspac = temp;
|
2008-09-26 17:18:53 +02:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
dspac = dspSaturate(dspac + result, outfmt, SIGNED, &ouflag);
|
2007-06-23 01:03:42 +02:00
|
|
|
}
|
2008-09-26 17:18:53 +02:00
|
|
|
} else {
|
2007-06-23 01:03:42 +02:00
|
|
|
dspac += result;
|
2008-09-26 17:18:53 +02:00
|
|
|
}
|
2007-06-23 01:03:42 +02:00
|
|
|
|
2008-09-26 17:18:53 +02:00
|
|
|
if (ouflag)
|
|
|
|
*dspctl = insertBits(*dspctl, 16 + ac, 16 + ac, 1);
|
2007-06-23 01:03:42 +02:00
|
|
|
|
2008-09-26 17:18:53 +02:00
|
|
|
return dspac;
|
2007-06-23 01:03:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int64_t
|
2008-09-26 17:18:53 +02:00
|
|
|
MipsISA::dspDpsq(int64_t dspac, int32_t a, int32_t b, int32_t ac,
|
|
|
|
int32_t infmt, int32_t outfmt, int32_t postsat, int32_t mode,
|
|
|
|
uint32_t *dspctl)
|
2007-06-23 01:03:42 +02:00
|
|
|
{
|
|
|
|
int nvals = SIMD_NVALS[infmt];
|
|
|
|
int64_t result = 0;
|
|
|
|
int64_t temp = 0;
|
|
|
|
uint32_t ouflag = 0;
|
|
|
|
uint64_t a_values[SIMD_MAX_VALS];
|
|
|
|
uint64_t b_values[SIMD_MAX_VALS];
|
|
|
|
|
2008-09-26 17:18:53 +02:00
|
|
|
simdUnpack(a, a_values, infmt, SIGNED);
|
|
|
|
simdUnpack(b, b_values, infmt, SIGNED);
|
2007-06-23 01:03:42 +02:00
|
|
|
|
2008-09-26 17:18:53 +02:00
|
|
|
for (int i = 0; i < nvals; i++) {
|
2008-09-26 18:37:21 +02:00
|
|
|
switch (mode) {
|
2007-06-23 01:03:42 +02:00
|
|
|
case MODE_X:
|
2008-09-26 17:18:53 +02:00
|
|
|
if (a_values[nvals - 1 - i] == FIXED_SMIN[infmt] &&
|
|
|
|
b_values[i] == FIXED_SMIN[infmt]) {
|
2007-06-23 01:03:42 +02:00
|
|
|
result += FIXED_SMAX[outfmt];
|
|
|
|
ouflag = 1;
|
2008-09-26 17:18:53 +02:00
|
|
|
} else {
|
|
|
|
result += a_values[nvals - 1 - i] * b_values[i] << 1;
|
2007-06-23 01:03:42 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
2008-09-26 17:18:53 +02:00
|
|
|
if (a_values[i] == FIXED_SMIN[infmt] &&
|
|
|
|
b_values[i] == FIXED_SMIN[infmt]) {
|
2007-06-23 01:03:42 +02:00
|
|
|
result += FIXED_SMAX[outfmt];
|
|
|
|
ouflag = 1;
|
2008-09-26 17:18:53 +02:00
|
|
|
} else {
|
2007-06-23 01:03:42 +02:00
|
|
|
result += a_values[i] * b_values[i] << 1;
|
2008-09-26 17:18:53 +02:00
|
|
|
}
|
2007-06-23 01:03:42 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-09-26 17:18:53 +02:00
|
|
|
if (postsat) {
|
|
|
|
if (outfmt == SIMD_FMT_L) {
|
|
|
|
int signa = bits(dspac, 63, 63);
|
|
|
|
int signb = bits(-result, 63, 63);
|
2007-06-23 01:03:42 +02:00
|
|
|
|
|
|
|
temp = dspac - result;
|
|
|
|
|
2008-09-26 17:18:53 +02:00
|
|
|
if (signa == signb && bits(temp, 63, 63) != signa) {
|
2007-06-23 01:03:42 +02:00
|
|
|
ouflag = 1;
|
2008-09-26 17:18:53 +02:00
|
|
|
if (signa)
|
2007-06-23 01:03:42 +02:00
|
|
|
dspac = FIXED_SMIN[outfmt];
|
|
|
|
else
|
|
|
|
dspac = FIXED_SMAX[outfmt];
|
2008-09-26 17:18:53 +02:00
|
|
|
} else {
|
2007-06-23 01:03:42 +02:00
|
|
|
dspac = temp;
|
2008-09-26 17:18:53 +02:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
dspac = dspSaturate(dspac - result, outfmt, SIGNED, &ouflag);
|
2007-06-23 01:03:42 +02:00
|
|
|
}
|
2008-09-26 17:18:53 +02:00
|
|
|
} else {
|
2007-06-23 01:03:42 +02:00
|
|
|
dspac -= result;
|
2008-09-26 17:18:53 +02:00
|
|
|
}
|
2007-06-23 01:03:42 +02:00
|
|
|
|
2008-09-26 17:18:53 +02:00
|
|
|
if (ouflag)
|
|
|
|
*dspctl = insertBits(*dspctl, 16 + ac, 16 + ac, 1);
|
2007-06-23 01:03:42 +02:00
|
|
|
|
2008-09-26 17:18:53 +02:00
|
|
|
return dspac;
|
2007-06-23 01:03:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int64_t
|
2008-09-26 17:18:53 +02:00
|
|
|
MipsISA::dspDpa(int64_t dspac, int32_t a, int32_t b, int32_t ac,
|
|
|
|
int32_t fmt, int32_t sign, int32_t mode)
|
2007-06-23 01:03:42 +02:00
|
|
|
{
|
|
|
|
int nvals = SIMD_NVALS[fmt];
|
|
|
|
uint64_t a_values[SIMD_MAX_VALS];
|
|
|
|
uint64_t b_values[SIMD_MAX_VALS];
|
|
|
|
|
2008-09-26 17:18:53 +02:00
|
|
|
simdUnpack(a, a_values, fmt, sign);
|
|
|
|
simdUnpack(b, b_values, fmt, sign);
|
2007-06-23 01:03:42 +02:00
|
|
|
|
2008-09-26 17:18:53 +02:00
|
|
|
for (int i = 0; i < 2; i++) {
|
2008-09-26 18:37:21 +02:00
|
|
|
switch (mode) {
|
2007-06-23 01:03:42 +02:00
|
|
|
case MODE_L:
|
2008-09-26 17:18:53 +02:00
|
|
|
dspac += a_values[nvals - 1 - i] * b_values[nvals - 1 - i];
|
2007-06-23 01:03:42 +02:00
|
|
|
break;
|
|
|
|
case MODE_R:
|
2008-09-26 17:18:53 +02:00
|
|
|
dspac += a_values[nvals - 3 - i] * b_values[nvals - 3 - i];
|
2007-06-23 01:03:42 +02:00
|
|
|
break;
|
|
|
|
case MODE_X:
|
2008-09-26 17:18:53 +02:00
|
|
|
dspac += a_values[nvals - 1 - i] * b_values[i];
|
2007-06-23 01:03:42 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return dspac;
|
|
|
|
}
|
|
|
|
|
|
|
|
int64_t
|
2008-09-26 17:18:53 +02:00
|
|
|
MipsISA::dspDps(int64_t dspac, int32_t a, int32_t b, int32_t ac,
|
|
|
|
int32_t fmt, int32_t sign, int32_t mode)
|
2007-06-23 01:03:42 +02:00
|
|
|
{
|
|
|
|
int nvals = SIMD_NVALS[fmt];
|
|
|
|
uint64_t a_values[SIMD_MAX_VALS];
|
|
|
|
uint64_t b_values[SIMD_MAX_VALS];
|
|
|
|
|
2008-09-26 17:18:53 +02:00
|
|
|
simdUnpack(a, a_values, fmt, sign);
|
|
|
|
simdUnpack(b, b_values, fmt, sign);
|
2007-06-23 01:03:42 +02:00
|
|
|
|
2008-09-26 17:18:53 +02:00
|
|
|
for (int i = 0; i < 2; i++) {
|
2008-09-26 18:37:21 +02:00
|
|
|
switch (mode) {
|
2007-06-23 01:03:42 +02:00
|
|
|
case MODE_L:
|
2008-09-26 17:18:53 +02:00
|
|
|
dspac -= a_values[nvals - 1 - i] * b_values[nvals - 1 - i];
|
2007-06-23 01:03:42 +02:00
|
|
|
break;
|
|
|
|
case MODE_R:
|
2008-09-26 17:18:53 +02:00
|
|
|
dspac -= a_values[nvals - 3 - i] * b_values[nvals - 3 - i];
|
2007-06-23 01:03:42 +02:00
|
|
|
break;
|
|
|
|
case MODE_X:
|
2008-09-26 17:18:53 +02:00
|
|
|
dspac -= a_values[nvals - 1 - i] * b_values[i];
|
2007-06-23 01:03:42 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return dspac;
|
|
|
|
}
|
|
|
|
|
|
|
|
int64_t
|
2008-09-26 17:18:53 +02:00
|
|
|
MipsISA::dspMaq(int64_t dspac, int32_t a, int32_t b, int32_t ac,
|
|
|
|
int32_t fmt, int32_t mode, int32_t saturate, uint32_t *dspctl)
|
2007-06-23 01:03:42 +02:00
|
|
|
{
|
2008-09-26 17:18:53 +02:00
|
|
|
int nvals = SIMD_NVALS[fmt - 1];
|
2007-06-23 01:03:42 +02:00
|
|
|
uint64_t a_values[SIMD_MAX_VALS];
|
|
|
|
uint64_t b_values[SIMD_MAX_VALS];
|
|
|
|
int64_t temp = 0;
|
|
|
|
uint32_t ouflag = 0;
|
|
|
|
|
2008-09-26 17:18:53 +02:00
|
|
|
simdUnpack(a, a_values, fmt, SIGNED);
|
|
|
|
simdUnpack(b, b_values, fmt, SIGNED);
|
2007-06-23 01:03:42 +02:00
|
|
|
|
2008-09-26 17:18:53 +02:00
|
|
|
for (int i = 0; i < nvals; i++) {
|
2008-09-26 18:37:21 +02:00
|
|
|
switch (mode) {
|
2007-06-23 01:03:42 +02:00
|
|
|
case MODE_L:
|
2008-09-26 17:18:53 +02:00
|
|
|
temp = a_values[i + 1] * b_values[i + 1] << 1;
|
|
|
|
if (a_values[i + 1] == FIXED_SMIN[fmt] &&
|
|
|
|
b_values[i + 1] == FIXED_SMIN[fmt]) {
|
|
|
|
temp = (int64_t)FIXED_SMAX[fmt - 1];
|
2007-06-23 01:03:42 +02:00
|
|
|
ouflag = 1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case MODE_R:
|
|
|
|
temp = a_values[i] * b_values[i] << 1;
|
2008-09-26 17:18:53 +02:00
|
|
|
if (a_values[i] == FIXED_SMIN[fmt] &&
|
|
|
|
b_values[i] == FIXED_SMIN[fmt]) {
|
|
|
|
temp = (int64_t)FIXED_SMAX[fmt - 1];
|
2007-06-23 01:03:42 +02:00
|
|
|
ouflag = 1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
temp += dspac;
|
|
|
|
|
2008-09-26 17:18:53 +02:00
|
|
|
if (saturate)
|
|
|
|
temp = dspSaturate(temp, fmt - 1, SIGNED, &ouflag);
|
|
|
|
if (ouflag)
|
|
|
|
*dspctl = insertBits(*dspctl, 16 + ac, 16 + ac, 1);
|
2007-06-23 01:03:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return temp;
|
|
|
|
}
|
|
|
|
|
|
|
|
int64_t
|
2008-09-26 17:18:53 +02:00
|
|
|
MipsISA::dspMulsa(int64_t dspac, int32_t a, int32_t b, int32_t ac, int32_t fmt)
|
2007-06-23 01:03:42 +02:00
|
|
|
{
|
|
|
|
uint64_t a_values[SIMD_MAX_VALS];
|
|
|
|
uint64_t b_values[SIMD_MAX_VALS];
|
|
|
|
|
2008-09-26 17:18:53 +02:00
|
|
|
simdUnpack(a, a_values, fmt, SIGNED);
|
|
|
|
simdUnpack(b, b_values, fmt, SIGNED);
|
2007-06-23 01:03:42 +02:00
|
|
|
|
|
|
|
dspac += a_values[1] * b_values[1] - a_values[0] * b_values[0];
|
|
|
|
|
|
|
|
return dspac;
|
|
|
|
}
|
|
|
|
|
|
|
|
int64_t
|
2008-09-26 17:18:53 +02:00
|
|
|
MipsISA::dspMulsaq(int64_t dspac, int32_t a, int32_t b, int32_t ac,
|
|
|
|
int32_t fmt, uint32_t *dspctl)
|
2007-06-23 01:03:42 +02:00
|
|
|
{
|
|
|
|
int nvals = SIMD_NVALS[fmt];
|
|
|
|
uint64_t a_values[SIMD_MAX_VALS];
|
|
|
|
uint64_t b_values[SIMD_MAX_VALS];
|
2009-11-05 01:57:01 +01:00
|
|
|
int64_t temp[2] = {0, 0};
|
2007-06-23 01:03:42 +02:00
|
|
|
uint32_t ouflag = 0;
|
|
|
|
|
2008-09-26 17:18:53 +02:00
|
|
|
simdUnpack(a, a_values, fmt, SIGNED);
|
|
|
|
simdUnpack(b, b_values, fmt, SIGNED);
|
2007-06-23 01:03:42 +02:00
|
|
|
|
2008-09-26 17:18:53 +02:00
|
|
|
for (int i = nvals - 1; i > -1; i--) {
|
2007-06-23 01:03:42 +02:00
|
|
|
temp[i] = a_values[i] * b_values[i] << 1;
|
2008-09-26 17:18:53 +02:00
|
|
|
if (a_values[i] == FIXED_SMIN[fmt] && b_values[i] == FIXED_SMIN[fmt]) {
|
|
|
|
temp[i] = FIXED_SMAX[fmt - 1];
|
2007-06-23 01:03:42 +02:00
|
|
|
ouflag = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
dspac += temp[1] - temp[0];
|
|
|
|
|
2008-09-26 17:18:53 +02:00
|
|
|
if (ouflag)
|
|
|
|
*dspctl = insertBits(*dspctl, 16 + ac, 16 + ac, 1);
|
2007-06-23 01:03:42 +02:00
|
|
|
|
|
|
|
return dspac;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2008-09-26 17:18:53 +02:00
|
|
|
MipsISA::dspCmp(int32_t a, int32_t b, int32_t fmt, int32_t sign, int32_t op,
|
|
|
|
uint32_t *dspctl)
|
2007-06-23 01:03:42 +02:00
|
|
|
{
|
|
|
|
int nvals = SIMD_NVALS[fmt];
|
|
|
|
int ccond = 0;
|
|
|
|
uint64_t a_values[SIMD_MAX_VALS];
|
|
|
|
uint64_t b_values[SIMD_MAX_VALS];
|
|
|
|
|
2008-09-26 17:18:53 +02:00
|
|
|
simdUnpack(a, a_values, fmt, sign);
|
|
|
|
simdUnpack(b, b_values, fmt, sign);
|
2007-06-23 01:03:42 +02:00
|
|
|
|
2008-09-26 17:18:53 +02:00
|
|
|
for (int i = 0; i < nvals; i++) {
|
2007-06-23 01:03:42 +02:00
|
|
|
int cc = 0;
|
|
|
|
|
2008-09-26 18:37:21 +02:00
|
|
|
switch (op) {
|
2008-09-26 17:18:53 +02:00
|
|
|
case CMP_EQ:
|
|
|
|
cc = (a_values[i] == b_values[i]);
|
|
|
|
break;
|
|
|
|
case CMP_LT:
|
|
|
|
cc = (a_values[i] < b_values[i]);
|
|
|
|
break;
|
|
|
|
case CMP_LE:
|
|
|
|
cc = (a_values[i] <= b_values[i]);
|
|
|
|
break;
|
2007-06-23 01:03:42 +02:00
|
|
|
}
|
|
|
|
|
2008-09-26 17:18:53 +02:00
|
|
|
ccond |= cc << (DSP_CTL_POS[DSP_CCOND] + i);
|
2007-06-23 01:03:42 +02:00
|
|
|
}
|
|
|
|
|
2008-09-26 17:18:53 +02:00
|
|
|
writeDSPControl(dspctl, ccond, 1 << DSP_CCOND);
|
2007-06-23 01:03:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int32_t
|
2008-09-26 17:18:53 +02:00
|
|
|
MipsISA::dspCmpg(int32_t a, int32_t b, int32_t fmt, int32_t sign, int32_t op)
|
2007-06-23 01:03:42 +02:00
|
|
|
{
|
|
|
|
int nvals = SIMD_NVALS[fmt];
|
|
|
|
int32_t result = 0;
|
|
|
|
uint64_t a_values[SIMD_MAX_VALS];
|
|
|
|
uint64_t b_values[SIMD_MAX_VALS];
|
|
|
|
|
2008-09-26 17:18:53 +02:00
|
|
|
simdUnpack(a, a_values, fmt, sign);
|
|
|
|
simdUnpack(b, b_values, fmt, sign);
|
2007-06-23 01:03:42 +02:00
|
|
|
|
2008-09-26 17:18:53 +02:00
|
|
|
for (int i = 0; i < nvals; i++) {
|
2007-06-23 01:03:42 +02:00
|
|
|
int cc = 0;
|
|
|
|
|
2008-09-26 18:37:21 +02:00
|
|
|
switch (op) {
|
2008-09-26 17:18:53 +02:00
|
|
|
case CMP_EQ:
|
|
|
|
cc = (a_values[i] == b_values[i]);
|
|
|
|
break;
|
|
|
|
case CMP_LT:
|
|
|
|
cc = (a_values[i] < b_values[i]);
|
|
|
|
break;
|
|
|
|
case CMP_LE:
|
|
|
|
cc = (a_values[i] <= b_values[i]);
|
|
|
|
break;
|
2007-06-23 01:03:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
result |= cc << i;
|
|
|
|
}
|
|
|
|
|
2008-09-26 17:18:53 +02:00
|
|
|
return result;
|
2007-06-23 01:03:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int32_t
|
2008-09-26 17:18:53 +02:00
|
|
|
MipsISA::dspCmpgd(int32_t a, int32_t b, int32_t fmt, int32_t sign, int32_t op,
|
|
|
|
uint32_t *dspctl)
|
2007-06-23 01:03:42 +02:00
|
|
|
{
|
|
|
|
int nvals = SIMD_NVALS[fmt];
|
|
|
|
int32_t result = 0;
|
|
|
|
int ccond = 0;
|
|
|
|
uint64_t a_values[SIMD_MAX_VALS];
|
|
|
|
uint64_t b_values[SIMD_MAX_VALS];
|
|
|
|
|
2008-09-26 17:18:53 +02:00
|
|
|
simdUnpack(a, a_values, fmt, sign);
|
|
|
|
simdUnpack(b, b_values, fmt, sign);
|
2007-06-23 01:03:42 +02:00
|
|
|
|
2008-09-26 17:18:53 +02:00
|
|
|
for (int i = 0; i < nvals; i++) {
|
|
|
|
int cc = 0;
|
2007-06-23 01:03:42 +02:00
|
|
|
|
2008-09-26 18:37:21 +02:00
|
|
|
switch (op) {
|
2008-09-26 17:18:53 +02:00
|
|
|
case CMP_EQ:
|
|
|
|
cc = (a_values[i] == b_values[i]);
|
|
|
|
break;
|
|
|
|
case CMP_LT:
|
|
|
|
cc = (a_values[i] < b_values[i]);
|
|
|
|
break;
|
|
|
|
case CMP_LE:
|
|
|
|
cc = (a_values[i] <= b_values[i]);
|
|
|
|
break;
|
2007-06-23 01:03:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
result |= cc << i;
|
2008-09-26 17:18:53 +02:00
|
|
|
ccond |= cc << (DSP_CTL_POS[DSP_CCOND] + i);
|
2007-06-23 01:03:42 +02:00
|
|
|
}
|
|
|
|
|
2008-09-26 17:18:53 +02:00
|
|
|
writeDSPControl(dspctl, ccond, 1 << DSP_CCOND);
|
2007-06-23 01:03:42 +02:00
|
|
|
|
2008-09-26 17:18:53 +02:00
|
|
|
return result;
|
2007-06-23 01:03:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int32_t
|
2008-09-26 17:18:53 +02:00
|
|
|
MipsISA::dspPrece(int32_t a, int32_t infmt, int32_t insign, int32_t outfmt,
|
|
|
|
int32_t outsign, int32_t mode)
|
2007-06-23 01:03:42 +02:00
|
|
|
{
|
|
|
|
int sa = 0;
|
|
|
|
int ninvals = SIMD_NVALS[infmt];
|
|
|
|
int noutvals = SIMD_NVALS[outfmt];
|
|
|
|
int32_t result;
|
|
|
|
uint64_t in_values[SIMD_MAX_VALS];
|
|
|
|
uint64_t out_values[SIMD_MAX_VALS];
|
|
|
|
|
2008-09-26 17:18:53 +02:00
|
|
|
if (insign == SIGNED && outsign == SIGNED)
|
2007-06-23 01:03:42 +02:00
|
|
|
sa = SIMD_NBITS[infmt];
|
2008-09-26 17:18:53 +02:00
|
|
|
else if (insign == UNSIGNED && outsign == SIGNED)
|
2007-06-23 01:03:42 +02:00
|
|
|
sa = SIMD_NBITS[infmt] - 1;
|
2008-09-26 17:18:53 +02:00
|
|
|
else if (insign == UNSIGNED && outsign == UNSIGNED)
|
2007-06-23 01:03:42 +02:00
|
|
|
sa = 0;
|
|
|
|
|
2008-09-26 17:18:53 +02:00
|
|
|
simdUnpack(a, in_values, infmt, insign);
|
2007-06-23 01:03:42 +02:00
|
|
|
|
2008-09-26 17:18:53 +02:00
|
|
|
for (int i = 0; i<noutvals; i++) {
|
2008-09-26 18:37:21 +02:00
|
|
|
switch (mode) {
|
2008-09-26 17:18:53 +02:00
|
|
|
case MODE_L:
|
|
|
|
out_values[i] = in_values[i + (ninvals >> 1)] << sa;
|
|
|
|
break;
|
|
|
|
case MODE_R:
|
|
|
|
out_values[i] = in_values[i] << sa;
|
|
|
|
break;
|
|
|
|
case MODE_LA:
|
|
|
|
out_values[i] = in_values[(i << 1) + 1] << sa;
|
|
|
|
break;
|
|
|
|
case MODE_RA:
|
|
|
|
out_values[i] = in_values[i << 1] << sa;
|
|
|
|
break;
|
2007-06-23 01:03:42 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-09-26 17:18:53 +02:00
|
|
|
simdPack(out_values, &result, outfmt);
|
2007-06-23 01:03:42 +02:00
|
|
|
|
2008-09-26 17:18:53 +02:00
|
|
|
return result;
|
2007-06-23 01:03:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int32_t
|
2008-09-26 17:18:53 +02:00
|
|
|
MipsISA::dspPrecrqu(int32_t a, int32_t b, uint32_t *dspctl)
|
2007-06-23 01:03:42 +02:00
|
|
|
{
|
|
|
|
uint64_t a_values[SIMD_MAX_VALS];
|
|
|
|
uint64_t b_values[SIMD_MAX_VALS];
|
|
|
|
uint64_t r_values[SIMD_MAX_VALS];
|
|
|
|
uint32_t ouflag = 0;
|
|
|
|
int32_t result = 0;
|
|
|
|
|
2008-09-26 17:18:53 +02:00
|
|
|
simdUnpack(a, a_values, SIMD_FMT_PH, SIGNED);
|
|
|
|
simdUnpack(b, b_values, SIMD_FMT_PH, SIGNED);
|
2007-06-23 01:03:42 +02:00
|
|
|
|
2008-09-26 17:18:53 +02:00
|
|
|
for (int i = 0; i<2; i++) {
|
|
|
|
r_values[i] =
|
2008-09-28 06:03:49 +02:00
|
|
|
dspSaturate((int64_t)b_values[i] >> (SIMD_NBITS[SIMD_FMT_QB] - 1),
|
2008-09-26 17:18:53 +02:00
|
|
|
SIMD_FMT_QB, UNSIGNED, &ouflag);
|
|
|
|
r_values[i + 2] =
|
2008-09-28 06:03:49 +02:00
|
|
|
dspSaturate((int64_t)a_values[i] >> (SIMD_NBITS[SIMD_FMT_QB] - 1),
|
2008-09-26 17:18:53 +02:00
|
|
|
SIMD_FMT_QB, UNSIGNED, &ouflag);
|
2007-06-23 01:03:42 +02:00
|
|
|
}
|
|
|
|
|
2008-09-26 17:18:53 +02:00
|
|
|
simdPack(r_values, &result, SIMD_FMT_QB);
|
2007-06-23 01:03:42 +02:00
|
|
|
|
2008-09-26 17:18:53 +02:00
|
|
|
if (ouflag)
|
|
|
|
*dspctl = insertBits(*dspctl, 22, 22, 1);
|
2007-06-23 01:03:42 +02:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t
|
2008-09-26 17:18:53 +02:00
|
|
|
MipsISA::dspPrecrq(int32_t a, int32_t b, int32_t fmt, uint32_t *dspctl)
|
2007-06-23 01:03:42 +02:00
|
|
|
{
|
|
|
|
uint64_t a_values[SIMD_MAX_VALS];
|
|
|
|
uint64_t b_values[SIMD_MAX_VALS];
|
|
|
|
uint64_t r_values[SIMD_MAX_VALS];
|
|
|
|
uint32_t ouflag = 0;
|
|
|
|
int32_t result;
|
|
|
|
|
2008-09-26 17:18:53 +02:00
|
|
|
simdUnpack(a, a_values, fmt, SIGNED);
|
|
|
|
simdUnpack(b, b_values, fmt, SIGNED);
|
2007-06-23 01:03:42 +02:00
|
|
|
|
2008-09-26 17:18:53 +02:00
|
|
|
r_values[1] = dspSaturate((int64_t)addHalfLsb(a_values[0], 16) >> 16,
|
|
|
|
fmt + 1, SIGNED, &ouflag);
|
|
|
|
r_values[0] = dspSaturate((int64_t)addHalfLsb(b_values[0], 16) >> 16,
|
|
|
|
fmt + 1, SIGNED, &ouflag);
|
2007-06-23 01:03:42 +02:00
|
|
|
|
2008-09-26 17:18:53 +02:00
|
|
|
simdPack(r_values, &result, fmt + 1);
|
2007-06-23 01:03:42 +02:00
|
|
|
|
2008-09-26 17:18:53 +02:00
|
|
|
if (ouflag)
|
|
|
|
*dspctl = insertBits(*dspctl, 22, 22, 1);
|
2007-06-23 01:03:42 +02:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t
|
2008-09-26 17:18:53 +02:00
|
|
|
MipsISA::dspPrecrSra(int32_t a, int32_t b, int32_t sa, int32_t fmt,
|
|
|
|
int32_t round)
|
2007-06-23 01:03:42 +02:00
|
|
|
{
|
|
|
|
int nvals = SIMD_NVALS[fmt];
|
|
|
|
uint64_t a_values[SIMD_MAX_VALS];
|
|
|
|
uint64_t b_values[SIMD_MAX_VALS];
|
|
|
|
uint64_t c_values[SIMD_MAX_VALS];
|
|
|
|
int32_t result = 0;
|
|
|
|
|
2008-09-26 17:18:53 +02:00
|
|
|
simdUnpack(a, a_values, fmt, SIGNED);
|
|
|
|
simdUnpack(b, b_values, fmt, SIGNED);
|
2007-06-23 01:03:42 +02:00
|
|
|
|
2008-09-26 17:18:53 +02:00
|
|
|
for (int i = 0; i < nvals; i++) {
|
|
|
|
if (round) {
|
|
|
|
c_values[i] = addHalfLsb(b_values[i], sa) >> sa;
|
|
|
|
c_values[i + 1] = addHalfLsb(a_values[i], sa) >> sa;
|
|
|
|
} else {
|
2007-06-23 01:03:42 +02:00
|
|
|
c_values[i] = b_values[i] >> sa;
|
2008-09-26 17:18:53 +02:00
|
|
|
c_values[i + 1] = a_values[i] >> sa;
|
2007-06-23 01:03:42 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-09-26 17:18:53 +02:00
|
|
|
simdPack(c_values, &result, fmt + 1);
|
2007-06-23 01:03:42 +02:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t
|
2008-09-26 17:18:53 +02:00
|
|
|
MipsISA::dspPick(int32_t a, int32_t b, int32_t fmt, uint32_t *dspctl)
|
2007-06-23 01:03:42 +02:00
|
|
|
{
|
|
|
|
int nvals = SIMD_NVALS[fmt];
|
|
|
|
int32_t result;
|
|
|
|
uint64_t a_values[SIMD_MAX_VALS];
|
|
|
|
uint64_t b_values[SIMD_MAX_VALS];
|
|
|
|
uint64_t c_values[SIMD_MAX_VALS];
|
|
|
|
|
2008-09-26 17:18:53 +02:00
|
|
|
simdUnpack(a, a_values, fmt, UNSIGNED);
|
|
|
|
simdUnpack(b, b_values, fmt, UNSIGNED);
|
2007-06-23 01:03:42 +02:00
|
|
|
|
2008-09-26 17:18:53 +02:00
|
|
|
for (int i = 0; i < nvals; i++) {
|
2007-06-23 01:03:42 +02:00
|
|
|
int condbit = DSP_CTL_POS[DSP_CCOND] + i;
|
2008-09-26 17:18:53 +02:00
|
|
|
if (bits(*dspctl, condbit, condbit) == 1)
|
2007-06-23 01:03:42 +02:00
|
|
|
c_values[i] = a_values[i];
|
|
|
|
else
|
|
|
|
c_values[i] = b_values[i];
|
|
|
|
}
|
|
|
|
|
2008-09-26 17:18:53 +02:00
|
|
|
simdPack(c_values, &result, fmt);
|
2007-06-23 01:03:42 +02:00
|
|
|
|
2008-09-26 17:18:53 +02:00
|
|
|
return result;
|
2007-06-23 01:03:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int32_t
|
2008-09-26 17:18:53 +02:00
|
|
|
MipsISA::dspPack(int32_t a, int32_t b, int32_t fmt)
|
2007-06-23 01:03:42 +02:00
|
|
|
{
|
|
|
|
int32_t result;
|
|
|
|
uint64_t a_values[SIMD_MAX_VALS];
|
|
|
|
uint64_t b_values[SIMD_MAX_VALS];
|
|
|
|
uint64_t c_values[SIMD_MAX_VALS];
|
|
|
|
|
2008-09-26 17:18:53 +02:00
|
|
|
simdUnpack(a, a_values, fmt, UNSIGNED);
|
|
|
|
simdUnpack(b, b_values, fmt, UNSIGNED);
|
2007-06-23 01:03:42 +02:00
|
|
|
|
|
|
|
c_values[0] = b_values[1];
|
|
|
|
c_values[1] = a_values[0];
|
|
|
|
|
2008-09-26 17:18:53 +02:00
|
|
|
simdPack(c_values, &result, fmt);
|
2007-06-23 01:03:42 +02:00
|
|
|
|
2008-09-26 17:18:53 +02:00
|
|
|
return result;
|
2007-06-23 01:03:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int32_t
|
2008-09-26 17:18:53 +02:00
|
|
|
MipsISA::dspExtr(int64_t dspac, int32_t fmt, int32_t sa, int32_t round,
|
|
|
|
int32_t saturate, uint32_t *dspctl)
|
2007-06-23 01:03:42 +02:00
|
|
|
{
|
|
|
|
int32_t result = 0;
|
|
|
|
uint32_t ouflag = 0;
|
|
|
|
int64_t temp = 0;
|
|
|
|
|
2008-09-26 17:18:53 +02:00
|
|
|
sa = bits(sa, 4, 0);
|
2007-06-23 01:03:42 +02:00
|
|
|
|
2008-09-26 17:18:53 +02:00
|
|
|
if (sa > 0) {
|
|
|
|
if (round) {
|
|
|
|
temp = (int64_t)addHalfLsb(dspac, sa);
|
2007-06-23 01:03:42 +02:00
|
|
|
|
2008-09-26 17:18:53 +02:00
|
|
|
if (dspac > 0 && temp < 0) {
|
2007-06-23 01:03:42 +02:00
|
|
|
ouflag = 1;
|
2008-09-26 17:18:53 +02:00
|
|
|
if (saturate)
|
2007-06-23 01:03:42 +02:00
|
|
|
temp = FIXED_SMAX[SIMD_FMT_L];
|
|
|
|
}
|
|
|
|
temp = temp >> sa;
|
2008-09-26 17:18:53 +02:00
|
|
|
} else {
|
2007-06-23 01:03:42 +02:00
|
|
|
temp = dspac >> sa;
|
2008-09-26 17:18:53 +02:00
|
|
|
}
|
|
|
|
} else {
|
2007-06-23 01:03:42 +02:00
|
|
|
temp = dspac;
|
2008-09-26 17:18:53 +02:00
|
|
|
}
|
2007-06-23 01:03:42 +02:00
|
|
|
|
2008-09-26 17:18:53 +02:00
|
|
|
dspac = checkOverflow(dspac, fmt, SIGNED, &ouflag);
|
2007-06-23 01:03:42 +02:00
|
|
|
|
2008-09-26 17:18:53 +02:00
|
|
|
if (ouflag) {
|
|
|
|
*dspctl = insertBits(*dspctl, 23, 23, ouflag);
|
2007-06-23 01:03:42 +02:00
|
|
|
|
2008-09-26 17:18:53 +02:00
|
|
|
if (saturate)
|
|
|
|
result = (int32_t)dspSaturate(temp, fmt, SIGNED, &ouflag);
|
2007-06-23 01:03:42 +02:00
|
|
|
else
|
|
|
|
result = (int32_t)temp;
|
2008-09-26 17:18:53 +02:00
|
|
|
} else {
|
2007-06-23 01:03:42 +02:00
|
|
|
result = (int32_t)temp;
|
2008-09-26 17:18:53 +02:00
|
|
|
}
|
2007-06-23 01:03:42 +02:00
|
|
|
|
2008-09-26 17:18:53 +02:00
|
|
|
return result;
|
2007-06-23 01:03:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int32_t
|
2008-09-26 17:18:53 +02:00
|
|
|
MipsISA::dspExtp(int64_t dspac, int32_t size, uint32_t *dspctl)
|
2007-06-23 01:03:42 +02:00
|
|
|
{
|
|
|
|
int32_t pos = 0;
|
|
|
|
int32_t result = 0;
|
|
|
|
|
2008-09-26 17:18:53 +02:00
|
|
|
pos = bits(*dspctl, 5, 0);
|
|
|
|
size = bits(size, 4, 0);
|
2007-06-23 01:03:42 +02:00
|
|
|
|
2008-09-26 17:18:53 +02:00
|
|
|
if (pos - (size + 1) >= -1) {
|
|
|
|
result = bits(dspac, pos, pos - size);
|
|
|
|
*dspctl = insertBits(*dspctl, 14, 14, 0);
|
|
|
|
} else {
|
2007-06-23 01:03:42 +02:00
|
|
|
result = 0;
|
2008-09-26 17:18:53 +02:00
|
|
|
*dspctl = insertBits(*dspctl, 14, 14, 1);
|
2007-06-23 01:03:42 +02:00
|
|
|
}
|
|
|
|
|
2008-09-26 17:18:53 +02:00
|
|
|
return result;
|
2007-06-23 01:03:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int32_t
|
2008-09-26 17:18:53 +02:00
|
|
|
MipsISA::dspExtpd(int64_t dspac, int32_t size, uint32_t *dspctl)
|
2007-06-23 01:03:42 +02:00
|
|
|
{
|
|
|
|
int32_t pos = 0;
|
|
|
|
int32_t result = 0;
|
|
|
|
|
2008-09-26 17:18:53 +02:00
|
|
|
pos = bits(*dspctl, 5, 0);
|
|
|
|
size = bits(size, 4, 0);
|
|
|
|
|
|
|
|
if (pos - (size + 1) >= -1) {
|
|
|
|
result = bits(dspac, pos, pos - size);
|
|
|
|
*dspctl = insertBits(*dspctl, 14, 14, 0);
|
|
|
|
if (pos - (size + 1) >= 0)
|
|
|
|
*dspctl = insertBits(*dspctl, 5, 0, pos - (size + 1));
|
|
|
|
else if ((pos - (size + 1)) == -1)
|
|
|
|
*dspctl = insertBits(*dspctl, 5, 0, 63);
|
|
|
|
} else {
|
2007-06-23 01:03:42 +02:00
|
|
|
result = 0;
|
2008-09-26 17:18:53 +02:00
|
|
|
*dspctl = insertBits(*dspctl, 14, 14, 1);
|
2007-06-23 01:03:42 +02:00
|
|
|
}
|
|
|
|
|
2008-09-26 17:18:53 +02:00
|
|
|
return result;
|
2007-06-23 01:03:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2008-09-26 17:18:53 +02:00
|
|
|
MipsISA::simdPack(uint64_t *values_ptr, int32_t *reg, int32_t fmt)
|
2007-06-23 01:03:42 +02:00
|
|
|
{
|
|
|
|
int nvals = SIMD_NVALS[fmt];
|
|
|
|
int nbits = SIMD_NBITS[fmt];
|
|
|
|
|
|
|
|
*reg = 0;
|
|
|
|
|
2008-09-26 17:18:53 +02:00
|
|
|
for (int i = 0; i < nvals; i++)
|
|
|
|
*reg |= (int32_t)bits(values_ptr[i], nbits - 1, 0) << nbits * i;
|
2007-06-23 01:03:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2008-09-26 17:18:53 +02:00
|
|
|
MipsISA::simdUnpack(int32_t reg, uint64_t *values_ptr, int32_t fmt, int32_t sign)
|
2007-06-23 01:03:42 +02:00
|
|
|
{
|
|
|
|
int nvals = SIMD_NVALS[fmt];
|
|
|
|
int nbits = SIMD_NBITS[fmt];
|
|
|
|
|
2008-09-26 18:37:21 +02:00
|
|
|
switch (sign) {
|
2008-09-26 17:18:53 +02:00
|
|
|
case SIGNED:
|
|
|
|
for (int i = 0; i < nvals; i++) {
|
|
|
|
uint64_t tmp = (uint64_t)bits(reg, nbits * (i + 1) - 1, nbits * i);
|
|
|
|
values_ptr[i] = signExtend(tmp, fmt);
|
2007-06-23 01:03:42 +02:00
|
|
|
}
|
|
|
|
break;
|
2008-09-26 17:18:53 +02:00
|
|
|
case UNSIGNED:
|
|
|
|
for (int i = 0; i < nvals; i++) {
|
|
|
|
values_ptr[i] =
|
|
|
|
(uint64_t)bits(reg, nbits * (i + 1) - 1, nbits * i);
|
2007-06-23 01:03:42 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2008-09-26 17:18:53 +02:00
|
|
|
MipsISA::writeDSPControl(uint32_t *dspctl, uint32_t value, uint32_t mask)
|
2007-06-23 01:03:42 +02:00
|
|
|
{
|
|
|
|
uint32_t fmask = 0;
|
|
|
|
|
2008-09-26 17:18:53 +02:00
|
|
|
if (mask & 0x01) fmask |= DSP_CTL_MASK[DSP_POS];
|
|
|
|
if (mask & 0x02) fmask |= DSP_CTL_MASK[DSP_SCOUNT];
|
|
|
|
if (mask & 0x04) fmask |= DSP_CTL_MASK[DSP_C];
|
|
|
|
if (mask & 0x08) fmask |= DSP_CTL_MASK[DSP_OUFLAG];
|
|
|
|
if (mask & 0x10) fmask |= DSP_CTL_MASK[DSP_CCOND];
|
|
|
|
if (mask & 0x20) fmask |= DSP_CTL_MASK[DSP_EFI];
|
2007-06-23 01:03:42 +02:00
|
|
|
|
|
|
|
*dspctl &= ~fmask;
|
|
|
|
value &= fmask;
|
|
|
|
*dspctl |= value;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t
|
2008-09-26 17:18:53 +02:00
|
|
|
MipsISA::readDSPControl(uint32_t *dspctl, uint32_t mask)
|
2007-06-23 01:03:42 +02:00
|
|
|
{
|
|
|
|
uint32_t fmask = 0;
|
|
|
|
|
2008-09-26 17:18:53 +02:00
|
|
|
if (mask & 0x01) fmask |= DSP_CTL_MASK[DSP_POS];
|
|
|
|
if (mask & 0x02) fmask |= DSP_CTL_MASK[DSP_SCOUNT];
|
|
|
|
if (mask & 0x04) fmask |= DSP_CTL_MASK[DSP_C];
|
|
|
|
if (mask & 0x08) fmask |= DSP_CTL_MASK[DSP_OUFLAG];
|
|
|
|
if (mask & 0x10) fmask |= DSP_CTL_MASK[DSP_CCOND];
|
|
|
|
if (mask & 0x20) fmask |= DSP_CTL_MASK[DSP_EFI];
|
2007-06-23 01:03:42 +02:00
|
|
|
|
2008-09-26 17:18:53 +02:00
|
|
|
return *dspctl & fmask;
|
2007-06-23 01:03:42 +02:00
|
|
|
}
|