1 /* 2 * Copyright 2022 Alyssa Rosenzweig 3 * SPDX-License-Identifier: MIT 4 */ 5 6 #pragma once 7 8 #include "util/format/u_formats.h" 9 #include "nir_builder.h" 10 #include "nir_format_convert.h" 11 12 static inline nir_def * nir_sign_extend_if_sint(nir_builder * b,nir_def * x,enum pipe_format format)13nir_sign_extend_if_sint(nir_builder *b, nir_def *x, enum pipe_format format) 14 { 15 if (!util_format_is_pure_sint(format)) 16 return x; 17 18 const struct util_format_description *desc = util_format_description(format); 19 unsigned bits[4] = {0}; 20 21 for (unsigned i = 0; i < desc->nr_channels; ++i) { 22 assert(desc->channel[i].type == UTIL_FORMAT_TYPE_SIGNED || 23 desc->channel[i].type == UTIL_FORMAT_TYPE_VOID); 24 25 bits[i] = desc->channel[i].size; 26 } 27 28 return nir_format_sign_extend_ivec(b, x, bits); 29 } 30