39using namespace MipsISA;
47 for (
int i = 0;
i < 16;
i++) {
51 result |= (value & 1 <<
i) << -
shift;
53 result |= (value & 1 <<
i) >>
shift;
63 int64_t svalue = (int64_t)value;
70 }
else if (svalue < (int64_t)
FIXED_SMIN[fmt]) {
79 }
else if (svalue < (int64_t)
FIXED_UMIN[fmt]) {
86 return (uint64_t)svalue;
93 int64_t svalue = (int64_t)value;
109 return (uint64_t)svalue;
116 uint64_t sign = uint64_t(1) << (signpos - 1);
117 uint64_t ones = ~(0ULL);
120 value |= (ones << signpos);
122 value &= (ones >> (64 - signpos));
130 return value += 1ULL << (lsbpos - 1);
144 for (
int i = 0;
i < nvals;
i++) {
145 svalue = (int64_t)a_values[
i];
150 }
else if (svalue < 0) {
151 a_values[
i] = uint64_t(0 - svalue);
166 int32_t sign, uint32_t *dspctl)
177 for (
int i = 0;
i < nvals;
i++)
208 for (
int i = 0;
i < nvals;
i++) {
212 a_values[
i] = (a_values[
i] + b_values[
i]) >> 1;
222 int32_t sign, uint32_t *dspctl)
233 for (
int i = 0;
i < nvals;
i++) {
263 for (
int i = 0;
i < nvals;
i++)
268 a_values[
i] = (a_values[
i] - b_values[
i]) >> 1;
278 int32_t sign, uint32_t *dspctl)
288 for (
int i = 0;
i < nvals;
i++)
316 for (
int i = 0;
i < nvals;
i++)
317 a_values[
i] = a_values[
i] >>
sa;
326 int32_t sign, uint32_t *dspctl)
336 for (
int i = 0;
i < nvals;
i++) {
340 a_values[
i] = a_values[
i] >>
sa;
350 int32_t round, uint32_t *dspctl)
363 for (
int i = 0;
i < nvals;
i++) {
368 temp = (int64_t)(a_values[
i] * b_values[
i]) >> (
sa - 1);
402 for (
int i = 0;
i < nvals;
i++)
435 for (
int i = 0;
i < nvals;
i++)
440 for (
int i = 0;
i < nvals;
i++)
465 memset(c_values, 0,
sizeof(c_values));
472 for (
int i = 0;
i < nvals;
i++)
477 for (
int i = 0;
i < nvals;
i++)
494 int32_t infmt, int32_t outfmt, int32_t postsat, int32_t
mode,
507 for (
int i = 0;
i < nvals;
i++) {
510 if (a_values[nvals - 1 -
i] ==
FIXED_SMIN[infmt] &&
516 result += a_values[nvals - 1 -
i] * b_values[
i] << 1;
524 result += a_values[
i] * b_values[
i] << 1;
532 int signa =
bits(dspac, 63, 63);
533 int signb =
bits(result, 63, 63);
535 temp = dspac + result;
537 if (signa == signb &&
bits(temp, 63, 63) != signa) {
561 int32_t infmt, int32_t outfmt, int32_t postsat, int32_t
mode,
574 for (
int i = 0;
i < nvals;
i++) {
577 if (a_values[nvals - 1 -
i] ==
FIXED_SMIN[infmt] &&
582 result += a_values[nvals - 1 -
i] * b_values[
i] << 1;
591 result += a_values[
i] * b_values[
i] << 1;
599 int signa =
bits(dspac, 63, 63);
600 int signb =
bits(-result, 63, 63);
602 temp = dspac - result;
604 if (signa == signb &&
bits(temp, 63, 63) != signa) {
628 int32_t fmt, int32_t sign, int32_t
mode)
637 for (
int i = 0;
i < 2;
i++) {
640 dspac += a_values[nvals - 1 -
i] * b_values[nvals - 1 -
i];
643 dspac += a_values[nvals - 3 -
i] * b_values[nvals - 3 -
i];
646 dspac += a_values[nvals - 1 -
i] * b_values[
i];
656 int32_t fmt, int32_t sign, int32_t
mode)
665 for (
int i = 0;
i < 2;
i++) {
668 dspac -= a_values[nvals - 1 -
i] * b_values[nvals - 1 -
i];
671 dspac -= a_values[nvals - 3 -
i] * b_values[nvals - 3 -
i];
674 dspac -= a_values[nvals - 1 -
i] * b_values[
i];
684 int32_t fmt, int32_t
mode, int32_t saturate, uint32_t *dspctl)
695 for (
int i = 0;
i < nvals;
i++) {
698 temp = a_values[
i + 1] * b_values[
i + 1] << 1;
706 temp = a_values[
i] * b_values[
i] << 1;
735 dspac += a_values[1] * b_values[1] - a_values[0] * b_values[0];
742 int32_t fmt, uint32_t *dspctl)
747 int64_t temp[2] = {0, 0};
753 for (
int i = nvals - 1;
i > -1;
i--) {
754 temp[
i] = a_values[
i] * b_values[
i] << 1;
761 dspac += temp[1] - temp[0];
781 for (
int i = 0;
i < nvals;
i++) {
786 cc = (a_values[
i] == b_values[
i]);
789 cc = (a_values[
i] < b_values[
i]);
792 cc = (a_values[
i] <= b_values[
i]);
813 for (
int i = 0;
i < nvals;
i++) {
818 cc = (a_values[
i] == b_values[
i]);
821 cc = (a_values[
i] < b_values[
i]);
824 cc = (a_values[
i] <= b_values[
i]);
847 for (
int i = 0;
i < nvals;
i++) {
852 cc = (a_values[
i] == b_values[
i]);
855 cc = (a_values[
i] < b_values[
i]);
858 cc = (a_values[
i] <= b_values[
i]);
873 int32_t outsign, int32_t
mode)
891 for (
int i = 0;
i<noutvals;
i++) {
894 out_values[
i] = in_values[
i + (ninvals >> 1)] <<
sa;
897 out_values[
i] = in_values[
i] <<
sa;
900 out_values[
i] = in_values[(
i << 1) + 1] <<
sa;
903 out_values[
i] = in_values[
i << 1] <<
sa;
908 simdPack(out_values, &result, outfmt);
925 for (
int i = 0;
i<2;
i++) {
955 fmt + 1,
SIGNED, &ouflag);
957 fmt + 1,
SIGNED, &ouflag);
959 simdPack(r_values, &result, fmt + 1);
980 for (
int i = 0;
i < nvals;
i++) {
985 c_values[
i] = b_values[
i] >>
sa;
986 c_values[
i + 1] = a_values[
i] >>
sa;
990 simdPack(c_values, &result, fmt + 1);
1007 for (
int i = 0;
i < nvals;
i++) {
1009 if (
bits(*dspctl, condbit, condbit) == 1)
1010 c_values[
i] = a_values[
i];
1012 c_values[
i] = b_values[
i];
1031 c_values[0] = b_values[1];
1032 c_values[1] = a_values[0];
1041 int32_t saturate, uint32_t *dspctl)
1044 uint32_t ouflag = 0;
1053 if (dspac > 0 && temp < 0) {
1069 *dspctl =
insertBits(*dspctl, 23, 23, ouflag);
1074 result = (int32_t)temp;
1076 result = (int32_t)temp;
1088 pos =
bits(*dspctl, 5, 0);
1089 size =
bits(size, 4, 0);
1091 if (pos - (size + 1) >= -1) {
1092 result =
bits(dspac, pos, pos - size);
1108 pos =
bits(*dspctl, 5, 0);
1109 size =
bits(size, 4, 0);
1111 if (pos - (size + 1) >= -1) {
1112 result =
bits(dspac, pos, pos - size);
1114 if (pos - (size + 1) >= 0)
1115 *dspctl =
insertBits(*dspctl, 5, 0, pos - (size + 1));
1116 else if ((pos - (size + 1)) == -1)
1134 for (
int i = 0;
i < nvals;
i++)
1135 *
reg |= (int32_t)
bits(values_ptr[
i], nbits - 1, 0) << nbits *
i;
1146 for (
int i = 0;
i < nvals;
i++) {
1147 uint64_t tmp = (uint64_t)
bits(
reg, nbits * (
i + 1) - 1, nbits *
i);
1152 for (
int i = 0;
i < nvals;
i++) {
1154 (uint64_t)
bits(
reg, nbits * (
i + 1) - 1, nbits *
i);
1189 return *dspctl & fmask;
constexpr T bits(T val, unsigned first, unsigned last)
Extract the bitfield from position 'first' to 'last' (inclusive) from 'val' and right justify it.
constexpr T insertBits(T val, unsigned first, unsigned last, B bit_val)
Returns val with bits first to last set to the LSBs of bit_val.
void simdUnpack(int32_t reg, uint64_t *values_ptr, int32_t fmt, int32_t sign)
const uint32_t DSP_CTL_POS[DSP_NUM_FIELDS]
const uint64_t FIXED_SMIN[SIMD_NUM_FMTS]
const uint64_t FIXED_SMAX[SIMD_NUM_FMTS]
const uint32_t SIMD_MAX_VALS
int32_t dspPrecrqu(int32_t a, int32_t b, uint32_t *dspctl)
uint64_t checkOverflow(uint64_t value, int32_t fmt, int32_t sign, uint32_t *overflow)
int32_t dspCmpgd(int32_t a, int32_t b, int32_t fmt, int32_t sign, int32_t op, uint32_t *dspctl)
uint64_t signExtend(uint64_t value, int32_t signpos)
int32_t bitrev(int32_t value)
int64_t dspMulsaq(int64_t dspac, int32_t a, int32_t b, int32_t ac, int32_t fmt, uint32_t *dspctl)
int32_t dspPack(int32_t a, int32_t b, int32_t fmt)
void simdPack(uint64_t *values_ptr, int32_t *reg, int32_t fmt)
int32_t dspPrece(int32_t a, int32_t infmt, int32_t insign, int32_t outfmt, int32_t outsign, int32_t mode)
int32_t dspAddh(int32_t a, int32_t b, int32_t fmt, int32_t round, int32_t sign)
uint64_t addHalfLsb(uint64_t value, int32_t lsbpos)
int32_t dspSubh(int32_t a, int32_t b, int32_t fmt, int32_t round, int32_t sign)
int64_t dspMulsa(int64_t dspac, int32_t a, int32_t b, int32_t ac, int32_t fmt)
void writeDSPControl(uint32_t *dspctl, uint32_t value, uint32_t mask)
int64_t dspDps(int64_t dspac, int32_t a, int32_t b, int32_t ac, int32_t fmt, int32_t sign, int32_t mode)
int32_t dspMuleu(int32_t a, int32_t b, int32_t mode, uint32_t *dspctl)
int32_t dspMul(int32_t a, int32_t b, int32_t fmt, int32_t saturate, uint32_t *dspctl)
int64_t 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)
int32_t dspShra(int32_t a, uint32_t sa, int32_t fmt, int32_t round, int32_t sign, uint32_t *dspctl)
int32_t dspAdd(int32_t a, int32_t b, int32_t fmt, int32_t saturate, int32_t sign, uint32_t *dspctl)
int32_t dspMulq(int32_t a, int32_t b, int32_t fmt, int32_t saturate, int32_t round, uint32_t *dspctl)
const uint32_t SIMD_NBITS[SIMD_NUM_FMTS]
const uint32_t SIMD_NVALS[SIMD_NUM_FMTS]
int32_t dspPick(int32_t a, int32_t b, int32_t fmt, uint32_t *dspctl)
int32_t dspAbs(int32_t a, int32_t fmt, uint32_t *dspctl)
int32_t dspShrl(int32_t a, uint32_t sa, int32_t fmt, int32_t sign)
int32_t dspExtr(int64_t dspac, int32_t fmt, int32_t sa, int32_t round, int32_t saturate, uint32_t *dspctl)
int64_t 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)
int32_t dspShll(int32_t a, uint32_t sa, int32_t fmt, int32_t saturate, int32_t sign, uint32_t *dspctl)
int64_t 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)
const uint64_t FIXED_UMIN[SIMD_NUM_FMTS]
int32_t dspCmpg(int32_t a, int32_t b, int32_t fmt, int32_t sign, int32_t op)
const uint64_t FIXED_UMAX[SIMD_NUM_FMTS]
int32_t dspSub(int32_t a, int32_t b, int32_t fmt, int32_t saturate, int32_t sign, uint32_t *dspctl)
int32_t dspExtp(int64_t dspac, int32_t size, uint32_t *dspctl)
const uint32_t DSP_CTL_MASK[DSP_NUM_FIELDS]
uint64_t dspSaturate(uint64_t value, int32_t fmt, int32_t sign, uint32_t *overflow)
int64_t dspDpa(int64_t dspac, int32_t a, int32_t b, int32_t ac, int32_t fmt, int32_t sign, int32_t mode)
int32_t dspMuleq(int32_t a, int32_t b, int32_t mode, uint32_t *dspctl)
int32_t dspPrecrSra(int32_t a, int32_t b, int32_t sa, int32_t fmt, int32_t round)
uint32_t readDSPControl(uint32_t *dspctl, uint32_t mask)
void dspCmp(int32_t a, int32_t b, int32_t fmt, int32_t sign, int32_t op, uint32_t *dspctl)
int32_t dspPrecrq(int32_t a, int32_t b, int32_t fmt, uint32_t *dspctl)
int32_t dspExtpd(int64_t dspac, int32_t size, uint32_t *dspctl)
const uint32_t SIMD_LOG2N[SIMD_NUM_FMTS]
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.