+/* Return the bit size of a type. Note that this differs from
+ * glsl_get_bit_size in that it returns 32 bits for bools, whereas at
+ * the NIR level we would want to return 1 bit for bools.
+ */
+static unsigned glsl_base_type_bit_size(enum glsl_base_type type)
+{
+ switch (type) {
+ case GLSL_TYPE_BOOL:
+ case GLSL_TYPE_INT:
+ case GLSL_TYPE_UINT:
+ case GLSL_TYPE_FLOAT: /* TODO handle mediump */
+ case GLSL_TYPE_SUBROUTINE:
+ return 32;
+
+ case GLSL_TYPE_FLOAT16:
+ case GLSL_TYPE_UINT16:
+ case GLSL_TYPE_INT16:
+ return 16;
+
+ case GLSL_TYPE_UINT8:
+ case GLSL_TYPE_INT8:
+ return 8;
+
+ case GLSL_TYPE_DOUBLE:
+ case GLSL_TYPE_INT64:
+ case GLSL_TYPE_UINT64:
+ case GLSL_TYPE_IMAGE:
+ case GLSL_TYPE_SAMPLER:
+ return 64;
+
+ default:
+ /* For GLSL_TYPE_STRUCT etc, it should be ok to return 0. This usually
+ * happens when calling this method through is_64bit and is_16bit
+ * methods
+ */
+ return 0;
+ }
+
+ return 0;
+}
+
+static inline bool glsl_base_type_is_16bit(enum glsl_base_type type)
+{
+ return glsl_base_type_bit_size(type) == 16;
+}
+
+static inline bool glsl_base_type_is_64bit(enum glsl_base_type type)
+{
+ return glsl_base_type_bit_size(type) == 64;
+}
+
+static inline bool glsl_base_type_is_integer(enum glsl_base_type type)
+{
+ return type == GLSL_TYPE_UINT8 ||
+ type == GLSL_TYPE_INT8 ||
+ type == GLSL_TYPE_UINT16 ||
+ type == GLSL_TYPE_INT16 ||
+ type == GLSL_TYPE_UINT ||
+ type == GLSL_TYPE_INT ||
+ type == GLSL_TYPE_UINT64 ||
+ type == GLSL_TYPE_INT64 ||
+ type == GLSL_TYPE_BOOL ||
+ type == GLSL_TYPE_SAMPLER ||
+ type == GLSL_TYPE_IMAGE;
+}
+
+static inline unsigned int
+glsl_base_type_get_bit_size(const enum glsl_base_type base_type)
+{
+ switch (base_type) {
+ case GLSL_TYPE_BOOL:
+ return 1;
+
+ case GLSL_TYPE_INT:
+ case GLSL_TYPE_UINT:
+ case GLSL_TYPE_FLOAT: /* TODO handle mediump */
+ case GLSL_TYPE_SUBROUTINE:
+ return 32;
+
+ case GLSL_TYPE_FLOAT16:
+ case GLSL_TYPE_UINT16:
+ case GLSL_TYPE_INT16:
+ return 16;
+
+ case GLSL_TYPE_UINT8:
+ case GLSL_TYPE_INT8:
+ return 8;
+
+ case GLSL_TYPE_DOUBLE:
+ case GLSL_TYPE_INT64:
+ case GLSL_TYPE_UINT64:
+ case GLSL_TYPE_IMAGE:
+ case GLSL_TYPE_SAMPLER:
+ return 64;
+
+ default:
+ unreachable("unknown base type");
+ }
+
+ return 0;
+}
+
+static inline enum glsl_base_type
+glsl_unsigned_base_type_of(enum glsl_base_type type)
+{
+ switch (type) {
+ case GLSL_TYPE_INT:
+ return GLSL_TYPE_UINT;
+ case GLSL_TYPE_INT8:
+ return GLSL_TYPE_UINT8;
+ case GLSL_TYPE_INT16:
+ return GLSL_TYPE_UINT16;
+ case GLSL_TYPE_INT64:
+ return GLSL_TYPE_UINT64;
+ default:
+ assert(type == GLSL_TYPE_UINT ||
+ type == GLSL_TYPE_UINT8 ||
+ type == GLSL_TYPE_UINT16 ||
+ type == GLSL_TYPE_UINT64);
+ return type;
+ }
+}
+