diff --git a/modules/precision_generator/codegen.py b/modules/precision_generator/codegen.py index eb644d1228de32d136ef23d26b2d027d2da68f15..86ffa19581bc4d36387abc995468b7bbd2b2b3aa 100755 --- a/modules/precision_generator/codegen.py +++ b/modules/precision_generator/codegen.py @@ -181,7 +181,46 @@ class SourceFile( object ): # -------------------- def _substitute( self, text, precision ): - '''Apply substitutions to text for given precision.''' + '''Apply substitutions to text for given precision. + If we use mixed precision algrotihm as input and output, we + apply a first pass from single precision, and then the mixed + one. + ''' + if self._src[0] == 'x' and precision[0] == 'x': + precfrom = self._src[1] + precto = precision[1] + + try: + # Get substitution table based on self._table + subs_o = self._subs.subs[ self._table ] # original + subs_s = self._subs.subs_search[ self._table ] # compiled as search regexp + subs_r = self._subs.subs_replace[ self._table ] # with regexp removed for replacement + + # Get which column is from and to. + header = subs_o[0] + jfrom = header.index( precfrom ) + jto = header.index( precto ) + except Exception as err: + print( "Error: bad table or precision in '%s', @precisions %s %s -> %s:" % + (self._filename, self._table, precfrom, self._dsts), file=sys.stderr ) + traceback.print_exc() + exit(1) + + # Apply substitutions + try: + line = 0 + for (orig, search, replace) in zip( subs_o[1:], subs_s[1:], subs_r[1:] ): + line += 1 + if search[jfrom] is None: + search[jfrom] = re.compile( orig[jfrom] ) + text = re.sub( search[jfrom], replace[jto], text ) + # end + except Exception as err: + print( "Error: in row %d of substitution table '%s': %s" % + (line, self._table, subs_o[line]), file=sys.stderr ) + traceback.print_exc() + exit(1) + try: # Get substitution table based on self._table subs_o = self._subs.subs[ self._table ] # original