aboutsummaryrefslogtreecommitdiff
path: root/riscv/insns/vnclip_wi.h
blob: ea6898cf509b1af9b7dea9082b6db00c93286622 (plain)
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
// vnclip: vd[i] = clip(round(vs2[i] + rnd) >> simm)
VRM xrm = P.VU.get_vround_mode();
int64_t int_max = INT64_MAX >> (64 - P.VU.vsew);
int64_t int_min = INT64_MIN >> (64 - P.VU.vsew);
VI_VI_LOOP_NARROW
({
  int128_t result = vs2;
  unsigned shift = zimm5 & ((sew * 2) - 1);

  // rounding
  INT_ROUNDING(result, xrm, shift);

  result = result >> shift;

  // saturation
  if (result < int_min) {
    result = int_min;
    P_SET_OV(1);
  } else if (result > int_max) {
    result = int_max;
    P_SET_OV(1);
  }

  vd = result;
})