All of lore.kernel.org
 help / color / mirror / Atom feed
* [RESEND/PATCH] nv50/ir: Handle OP_CVT when folding constant expressions
@ 2015-01-09 23:47 Tobias Klausmann
       [not found] ` <1420847276-8754-1-git-send-email-tobias.johannes.klausmann-AqjdNwhu20eELgA04lAiVw@public.gmane.org>
  0 siblings, 1 reply; 18+ messages in thread
From: Tobias Klausmann @ 2015-01-09 23:47 UTC (permalink / raw)
  To: nouveau-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW

Folding for conversions: F32->(U{16/32}, S{16/32}) and (U{16/32}, {S16/32})->F32

Signed-off-by: Tobias Klausmann <tobias.johannes.klausmann@mni.thm.de>
---
 .../drivers/nouveau/codegen/nv50_ir_peephole.cpp   | 109 +++++++++++++++++++++
 1 file changed, 109 insertions(+)

diff --git a/src/gallium/drivers/nouveau/codegen/nv50_ir_peephole.cpp b/src/gallium/drivers/nouveau/codegen/nv50_ir_peephole.cpp
index 9a0bb60..6a3d515 100644
--- a/src/gallium/drivers/nouveau/codegen/nv50_ir_peephole.cpp
+++ b/src/gallium/drivers/nouveau/codegen/nv50_ir_peephole.cpp
@@ -997,6 +997,115 @@ ConstantFolding::opnd(Instruction *i, ImmediateValue &imm0, int s)
       i->op = OP_MOV;
       break;
    }
+   case OP_CVT: {
+      Storage res;
+      bld.setPosition(i, true); /* make sure bld is init'ed */
+      switch(i->dType) {
+      case TYPE_U16:
+         switch (i->sType) {
+         case TYPE_F32:
+            if (i->saturate)
+               res.data.u16 = util_iround(CLAMP(imm0.reg.data.f32, 0,
+                                                UINT16_MAX));
+            else
+               res.data.u16 = util_iround(imm0.reg.data.f32);
+            break;
+         case TYPE_F64:
+            if (i->saturate)
+               res.data.u16 = util_iround(CLAMP(imm0.reg.data.f64, 0,
+                                                UINT16_MAX));
+            else
+               res.data.u16 = util_iround(imm0.reg.data.f64);
+            break;
+         default:
+            return;
+         }
+         i->setSrc(0, bld.mkImm(res.data.u16));
+         break;
+      case TYPE_U32:
+         switch (i->sType) {
+         case TYPE_F32:
+            if (i->saturate)
+               res.data.u32 = util_iround(CLAMP(imm0.reg.data.f32, 0,
+                                                UINT32_MAX));
+            else
+               res.data.u32 = util_iround(imm0.reg.data.f32);
+            break;
+         case TYPE_F64:
+            if (i->saturate)
+               res.data.u32 = util_iround(CLAMP(imm0.reg.data.f64, 0,
+                                                UINT32_MAX));
+            else
+               res.data.u32 = util_iround(imm0.reg.data.f64);
+         break;
+         default:
+            return;
+         }
+         i->setSrc(0, bld.mkImm(res.data.u32));
+         break;
+      case TYPE_S16:
+         switch (i->sType) {
+         case TYPE_F32:
+            if (i->saturate)
+               res.data.s16 = util_iround(CLAMP(imm0.reg.data.f32, INT16_MIN,
+                                                INT16_MAX));
+            else
+               res.data.s16 = util_iround(imm0.reg.data.f32);
+            break;
+         case TYPE_F64:
+            if (i->saturate)
+               res.data.s16 = util_iround(CLAMP(imm0.reg.data.f64, INT16_MIN,
+                                                INT16_MAX));
+            else
+               res.data.s16 = util_iround(imm0.reg.data.f64);
+         break;
+         default:
+            return;
+         }
+         i->setSrc(0, bld.mkImm(res.data.s16));
+         break;
+      case TYPE_S32:
+         switch (i->sType) {
+         case TYPE_F32:
+            if (i->saturate)
+               res.data.s32 = util_iround(CLAMP(imm0.reg.data.f32, INT32_MIN,
+                                               INT32_MAX));
+            else
+               res.data.s32 = util_iround(imm0.reg.data.f32);
+            break;
+         case TYPE_F64:
+            if (i->saturate)
+               res.data.s32 = util_iround(CLAMP(imm0.reg.data.f64, INT32_MIN,
+                                               INT32_MAX));
+            else
+               res.data.s32 = util_iround(imm0.reg.data.f64);
+            break;
+         default:
+            return;
+         }
+         i->setSrc(0, bld.mkImm(res.data.s32));
+         break;
+      case TYPE_F32:
+         switch (i->sType) {
+         case TYPE_U16: res.data.f32 = (float) imm0.reg.data.u16; break;
+         case TYPE_U32: res.data.f32 = (float) imm0.reg.data.u32; break;
+         case TYPE_S16: res.data.f32 = (float) imm0.reg.data.s16; break;
+         case TYPE_S32: res.data.f32 = (float) imm0.reg.data.s32; break;
+         default:
+            return;
+         }
+         i->setSrc(0, bld.mkImm(res.data.f32));
+         break;
+      default:
+         return;
+      }
+      i->setType(i->dType); /* Remove i->sType, which we don't need anymore */
+      i->setSrc(1, NULL);
+      i->op = OP_MOV;
+
+      i->src(0).mod = Modifier(0); /* Clear the already applied modifier */
+      break;
+   }
    default:
       return;
    }
-- 
2.2.1

_______________________________________________
Nouveau mailing list
Nouveau@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/nouveau

^ permalink raw reply related	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2015-01-24 18:19 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-01-09 23:47 [RESEND/PATCH] nv50/ir: Handle OP_CVT when folding constant expressions Tobias Klausmann
     [not found] ` <1420847276-8754-1-git-send-email-tobias.johannes.klausmann-AqjdNwhu20eELgA04lAiVw@public.gmane.org>
2015-01-10  1:41   ` Ilia Mirkin
     [not found]     ` <CAKb7UvhkHtoRFP1rk8=9w68ZcgesV21mGAMmdB5LsHvFVNzo3Q-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-01-10  1:08       ` Tobias Klausmann
2015-01-10  1:24       ` [PATCH v2] " Tobias Klausmann
     [not found]         ` <1420853067-13115-1-git-send-email-tobias.johannes.klausmann-AqjdNwhu20eELgA04lAiVw@public.gmane.org>
2015-01-11  0:58           ` Ilia Mirkin
     [not found]             ` <CAKb7UvinNbgsgz7PGzzy0fAmfzAykm9Fph_FRDxoZKV5cS+ybg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-01-11 17:27               ` Tobias Klausmann
     [not found]                 ` <54B2B283.9020400-AqjdNwhu20eELgA04lAiVw@public.gmane.org>
2015-01-11 19:19                   ` Ilia Mirkin
     [not found]                     ` <CAKb7Uvg_dR3U_swgod0oLb5cLm8OX8OtTQPU514VG92G1vYg2A-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-01-11 19:56                       ` Tobias Klausmann
     [not found]                         ` <54B2D552.6030700-AqjdNwhu20eELgA04lAiVw@public.gmane.org>
2015-01-11 19:57                           ` Ilia Mirkin
     [not found]                             ` <CAKb7Uvi7Ke_fzbpQ_JvLvv-1u2H=F-udRdb0A+dCM0=tsqBKBg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-01-11 20:17                               ` Tobias Klausmann
     [not found]                                 ` <54B2DA6A.7080505-AqjdNwhu20eELgA04lAiVw@public.gmane.org>
2015-01-11 21:40                                   ` [PATCH] " Tobias Klausmann
     [not found]                                     ` <1421012422-30607-1-git-send-email-tobias.johannes.klausmann-AqjdNwhu20eELgA04lAiVw@public.gmane.org>
2015-01-11 21:54                                       ` Ilia Mirkin
     [not found]                                         ` <CAKb7Uvgnd25Ubm4m_-auNHw8p_Z9g=7sSxDrRb+CmbE5MZtohA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-01-11 22:08                                           ` Tobias Klausmann
     [not found]                                             ` <54B2F467.3050007-AqjdNwhu20eELgA04lAiVw@public.gmane.org>
2015-01-11 22:12                                               ` Ilia Mirkin
     [not found]                                                 ` <CAKb7UvgiWyNAumaKaiw_B2f49Q+xXszdwBE1abJwoC8SEpH8Lg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-01-11 22:48                                                   ` Tobias Klausmann
     [not found]                                                     ` <54B2FDB9.60906-AqjdNwhu20eELgA04lAiVw@public.gmane.org>
2015-01-11 22:53                                                       ` Ilia Mirkin
     [not found]                                                         ` <CAKb7UvidgoVLmvvG3r2M2Eio-EexLh1RsXh9GK8Pf-UMSVOPgw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-01-24 18:18                                                           ` [PATCH v4] " Tobias Klausmann
2015-01-24 18:19                                                           ` [PATCH] " Tobias Klausmann

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.