From 5b810c7de303e32900fed18b1303648eb74a6415 Mon Sep 17 00:00:00 2001 From: Boris Brezillon Date: Mon, 20 Jan 2020 22:02:40 +0100 Subject: [PATCH] panfrost/midgard: Add missing lowering passes for type/size conversion ops Replace the manual type/size conversion lowering description by one that's automatically generated and covers all type/size conversions. Signed-off-by: Boris Brezillon Reviewed-by: Alyssa Rosenzweig Tested-by: Marge Bot Part-of: --- src/panfrost/midgard/midgard_nir_algebraic.py | 47 ++++++++++++++----- 1 file changed, 34 insertions(+), 13 deletions(-) diff --git a/src/panfrost/midgard/midgard_nir_algebraic.py b/src/panfrost/midgard/midgard_nir_algebraic.py index 951b4b23241..2ba9f226d22 100644 --- a/src/panfrost/midgard/midgard_nir_algebraic.py +++ b/src/panfrost/midgard/midgard_nir_algebraic.py @@ -48,19 +48,40 @@ algebraic_late = [ # Midgard is able to type convert down by only one "step" per instruction; if # NIR wants more than one step, we need to break up into multiple instructions -converts = [ - (('i2i8', 'a@32'), ('i2i8', ('i2i16', a))), - (('u2u8', 'a@32'), ('u2u8', ('u2u16', a))), - - (('i2i32', 'a@8'), ('i2i32', ('i2i16', a))), - (('u2u32', 'a@8'), ('u2u32', ('u2u16', a))), - - (('f2i32', 'a@16'), ('f2i32', ('f2f32', a))), - (('f2u32', 'a@16'), ('f2u32', ('f2f32', a))), - - # Totally redundant - (('~f2f16', ('f2f32', 'a@16')), a), -] +converts = [] + +for op in ('u2u', 'i2i', 'f2f', 'i2f', 'u2f', 'f2i', 'f2u'): + srcsz_max = 64 + dstsz_max = 64 + # 8 bit float doesn't exist + srcsz_min = 8 if op[0] != 'f' else 16 + dstsz_min = 8 if op[2] != 'f' else 16 + dstsz = dstsz_min + # Iterate over all possible destination and source sizes + while dstsz <= dstsz_max: + srcsz = srcsz_min + while srcsz <= srcsz_max: + # Size converter lowering is only needed if src and dst sizes are + # spaced by a factor > 2. + # Type converter lowering is needed as soon as src_size != dst_size + if srcsz != dstsz and ((srcsz * 2 != dstsz and srcsz != dstsz * 2) or op[0] != op[2]): + cursz = srcsz + rule = a + # When converting down we first do the type conversion followed + # by one or more size conversions. When converting up, we do + # the type conversion at the end. This way we don't have to + # deal with the fact that f2f8 doesn't exists. + sizeconvop = op[0] + '2' + op[0] if srcsz < dstsz else op[2] + '2' + op[2] + if srcsz > dstsz and op[0] != op[2]: + rule = (op + str(int(cursz)), rule) + while cursz != dstsz: + cursz = cursz / 2 if dstsz < srcsz else cursz * 2 + rule = (sizeconvop + str(int(cursz)), rule) + if srcsz < dstsz and op[0] != op[2]: + rule = (op + str(int(cursz)), rule) + converts += [((op + str(int(dstsz)), 'a@' + str(int(srcsz))), rule)] + srcsz *= 2 + dstsz *= 2 # Midgard scales fsin/fcos arguments by pi. # Pass must be run only once, after the main loop -- 2.30.2