[Mesa-dev] [PATCH 4/4] nir: add helper functions for rounding mode

Karol Herbst kherbst at redhat.com
Sat Apr 28 11:14:15 UTC 2018


For easier implementing of the new conversion opcodes.

Signed-off-by: Karol Herbst <kherbst at redhat.com>
---
 src/compiler/nir/nir_opcodes_h.py | 57 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 57 insertions(+)

diff --git a/src/compiler/nir/nir_opcodes_h.py b/src/compiler/nir/nir_opcodes_h.py
index c9538e4e957..0309db1813e 100644
--- a/src/compiler/nir/nir_opcodes_h.py
+++ b/src/compiler/nir/nir_opcodes_h.py
@@ -38,6 +38,63 @@ typedef enum {
    nir_num_opcodes = nir_last_opcode + 1
 } nir_op;
 
+% for mode in [('rtne', '_rtne'), ('rtz', '_rtz'), ('ru', '_ru'), ('rd', '_rd'), ('undef', '')]:
+static inline bool
+nir_cvt_is_${mode[0]}(nir_op op)
+{
+   switch (op) {
+% for src_type in ['f', 'i', 'u']:
+%    if src_type == 'f':
+<%      dst_types = ['i', 'u', 'f'] %>
+%    else:
+<%      dst_types = ['f'] %>
+%    endif
+%    for dst_type in dst_types:
+%       if dst_type == 'f':
+<%         bit_sizes = [16, 32, 64] %>
+<%         sat_modes = [''] %>
+%       else:
+<%         bit_sizes = [8, 16, 32, 64] %>
+<%         sat_modes = ['_sat', ''] %>
+%       endif
+%       for bit_size in bit_sizes:
+%          for sat_mode in sat_modes:
+   case nir_op_${src_type}2${dst_type}${bit_size}${mode[1]}${sat_mode}:
+%          endfor
+%       endfor
+%    endfor
+% endfor
+      return true;
+   default:
+      return false;
+   }
+}
+% endfor
+
+static inline bool
+nir_cvt_is_sat(nir_op op)
+{
+   switch (op) {
+%  for dst_type in ['i', 'u']:
+%     for src_type in ['i', 'u', 'f']:
+%     if src_type == 'f':
+<%       rnd_modes = ['_rtne', '_rtz', '_ru', '_rd', ''] %>
+%     else:
+<%       rnd_modes = [''] %>
+%     endif
+%        for bit_size in [8, 16, 32, 64]:
+%           for rnd_mode in rnd_modes:
+   case nir_op_${src_type}2${dst_type}${bit_size}${rnd_mode}_sat:
+%           endfor
+%        endfor
+%     endfor
+%  endfor
+      return true;
+   default:
+      return false;
+   }
+}
+
 #endif /* _NIR_OPCODES_ */"""
 
 from nir_opcodes import opcodes
-- 
2.14.3



More information about the mesa-dev mailing list