gallivm: add support for 8-bit/16-bit integer builders
authorDave Airlie <airlied@redhat.com>
Tue, 10 Dec 2019 04:47:07 +0000 (14:47 +1000)
committerDave Airlie <airlied@redhat.com>
Fri, 27 Dec 2019 03:22:43 +0000 (13:22 +1000)
Acked-by: Roland Scheidegger <sroland@vmware.com>
src/gallium/auxiliary/gallivm/lp_bld_nir.c
src/gallium/auxiliary/gallivm/lp_bld_nir.h
src/gallium/auxiliary/gallivm/lp_bld_nir_soa.c

index a3b57e86a6fd1ef4771c31a9af2ae5a690e1240d..b04bba1a11c3a85d4e39762b49f5015eec749d09 100644 (file)
@@ -57,6 +57,10 @@ static LLVMValueRef cast_type(struct lp_build_nir_context *bld_base, LLVMValueRe
       break;
    case nir_type_int:
       switch (bit_size) {
+      case 8:
+         return LLVMBuildBitCast(builder, val, bld_base->int8_bld.vec_type, "");
+      case 16:
+         return LLVMBuildBitCast(builder, val, bld_base->int16_bld.vec_type, "");
       case 32:
          return LLVMBuildBitCast(builder, val, bld_base->int_bld.vec_type, "");
       case 64:
@@ -68,6 +72,10 @@ static LLVMValueRef cast_type(struct lp_build_nir_context *bld_base, LLVMValueRe
       break;
    case nir_type_uint:
       switch (bit_size) {
+      case 8:
+         return LLVMBuildBitCast(builder, val, bld_base->uint8_bld.vec_type, "");
+      case 16:
+         return LLVMBuildBitCast(builder, val, bld_base->uint16_bld.vec_type, "");
       case 32:
          return LLVMBuildBitCast(builder, val, bld_base->uint_bld.vec_type, "");
       case 64:
@@ -85,20 +93,6 @@ static LLVMValueRef cast_type(struct lp_build_nir_context *bld_base, LLVMValueRe
    return NULL;
 }
 
-static struct lp_build_context *get_int_bld(struct lp_build_nir_context *bld_base,
-                                            bool is_unsigned,
-                                            unsigned op_bit_size)
-{
-   if (is_unsigned)
-      if (op_bit_size == 64)
-         return &bld_base->uint64_bld;
-      else
-         return &bld_base->uint_bld;
-   else if (op_bit_size == 64)
-      return &bld_base->int64_bld;
-   else
-      return &bld_base->int_bld;
-}
 
 static struct lp_build_context *get_flt_bld(struct lp_build_nir_context *bld_base,
                                             unsigned op_bit_size)
index 9a20d14834d66f93a3cc0cbd26a68c8616f8445c..dbfed24074b629453e63cd45187d5f93aa92c0d3 100644 (file)
@@ -45,6 +45,10 @@ struct lp_build_nir_context
    struct lp_build_context base;
    struct lp_build_context uint_bld;
    struct lp_build_context int_bld;
+   struct lp_build_context uint8_bld;
+   struct lp_build_context int8_bld;
+   struct lp_build_context uint16_bld;
+   struct lp_build_context int16_bld;
    struct lp_build_context dbl_bld;
    struct lp_build_context uint64_bld;
    struct lp_build_context int64_bld;
@@ -218,4 +222,36 @@ lp_nir_array_build_gather_values(LLVMBuilderRef builder,
    return arr;
 }
 
+
+static inline struct lp_build_context *get_int_bld(struct lp_build_nir_context *bld_base,
+                                                   bool is_unsigned,
+                                                   unsigned op_bit_size)
+{
+   if (is_unsigned) {
+      switch (op_bit_size) {
+      case 64:
+         return &bld_base->uint64_bld;
+      case 32:
+      default:
+         return &bld_base->uint_bld;
+      case 16:
+         return &bld_base->uint16_bld;
+      case 8:
+         return &bld_base->uint8_bld;
+      }
+   } else {
+      switch (op_bit_size) {
+      case 64:
+         return &bld_base->int64_bld;
+      default:
+      case 32:
+         return &bld_base->int_bld;
+      case 16:
+         return &bld_base->int16_bld;
+      case 8:
+         return &bld_base->int8_bld;
+      }
+   }
+}
+
 #endif
index 0c848db45561651eee00f086f1e174b488237640..f31561f2b9e664fbc8c7f9cfd24c339592d74c76 100644 (file)
@@ -1238,6 +1238,30 @@ void lp_build_nir_soa(struct gallivm_state *gallivm,
       int64_type.width *= 2;
       lp_build_context_init(&bld.bld_base.int64_bld, gallivm, int64_type);
    }
+   {
+      struct lp_type uint16_type;
+      uint16_type = lp_uint_type(type);
+      uint16_type.width /= 2;
+      lp_build_context_init(&bld.bld_base.uint16_bld, gallivm, uint16_type);
+   }
+   {
+      struct lp_type int16_type;
+      int16_type = lp_int_type(type);
+      int16_type.width /= 2;
+      lp_build_context_init(&bld.bld_base.int16_bld, gallivm, int16_type);
+   }
+   {
+      struct lp_type uint8_type;
+      uint8_type = lp_uint_type(type);
+      uint8_type.width /= 4;
+      lp_build_context_init(&bld.bld_base.uint8_bld, gallivm, uint8_type);
+   }
+   {
+      struct lp_type int8_type;
+      int8_type = lp_int_type(type);
+      int8_type.width /= 4;
+      lp_build_context_init(&bld.bld_base.int8_bld, gallivm, int8_type);
+   }
    bld.bld_base.load_var = emit_load_var;
    bld.bld_base.store_var = emit_store_var;
    bld.bld_base.load_reg = emit_load_reg;