mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-02-07 10:10:28 +01:00
nir: Allow [iu]mul_high on non-32-bit types
Reviewed-by: Ian Romanick ian.d.romanick@intel.com
This commit is contained in:
parent
a95ec13879
commit
9525971e2b
2 changed files with 40 additions and 4 deletions
|
|
@ -61,6 +61,7 @@ template = """\
|
|||
#include <math.h>
|
||||
#include "util/rounding.h" /* for _mesa_roundeven */
|
||||
#include "util/half_float.h"
|
||||
#include "util/bigmath.h"
|
||||
#include "nir_constant_expressions.h"
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -468,12 +468,47 @@ binop("isub", tint, "", "src0 - src1")
|
|||
binop("fmul", tfloat, commutative + associative, "src0 * src1")
|
||||
# low 32-bits of signed/unsigned integer multiply
|
||||
binop("imul", tint, commutative + associative, "src0 * src1")
|
||||
|
||||
# high 32-bits of signed integer multiply
|
||||
binop("imul_high", tint32, commutative,
|
||||
"(int32_t)(((int64_t) src0 * (int64_t) src1) >> 32)")
|
||||
binop("imul_high", tint, commutative, """
|
||||
if (bit_size == 64) {
|
||||
/* We need to do a full 128-bit x 128-bit multiply in order for the sign
|
||||
* extension to work properly. The casts are kind-of annoying but needed
|
||||
* to prevent compiler warnings.
|
||||
*/
|
||||
uint32_t src0_u32[4] = {
|
||||
src0,
|
||||
(int64_t)src0 >> 32,
|
||||
(int64_t)src0 >> 63,
|
||||
(int64_t)src0 >> 63,
|
||||
};
|
||||
uint32_t src1_u32[4] = {
|
||||
src1,
|
||||
(int64_t)src1 >> 32,
|
||||
(int64_t)src1 >> 63,
|
||||
(int64_t)src1 >> 63,
|
||||
};
|
||||
uint32_t prod_u32[4];
|
||||
ubm_mul_u32arr(prod_u32, src0_u32, src1_u32);
|
||||
dst = (uint64_t)prod_u32[2] | ((uint64_t)prod_u32[3] << 32);
|
||||
} else {
|
||||
dst = ((int64_t)src0 * (int64_t)src1) >> bit_size;
|
||||
}
|
||||
""")
|
||||
|
||||
# high 32-bits of unsigned integer multiply
|
||||
binop("umul_high", tuint32, commutative,
|
||||
"(uint32_t)(((uint64_t) src0 * (uint64_t) src1) >> 32)")
|
||||
binop("umul_high", tuint, commutative, """
|
||||
if (bit_size == 64) {
|
||||
/* The casts are kind-of annoying but needed to prevent compiler warnings. */
|
||||
uint32_t src0_u32[2] = { src0, (uint64_t)src0 >> 32 };
|
||||
uint32_t src1_u32[2] = { src1, (uint64_t)src1 >> 32 };
|
||||
uint32_t prod_u32[4];
|
||||
ubm_mul_u32arr(prod_u32, src0_u32, src1_u32);
|
||||
dst = (uint64_t)prod_u32[2] | ((uint64_t)prod_u32[3] << 32);
|
||||
} else {
|
||||
dst = ((uint64_t)src0 * (uint64_t)src1) >> bit_size;
|
||||
}
|
||||
""")
|
||||
|
||||
binop("fdiv", tfloat, "", "src0 / src1")
|
||||
binop("idiv", tint, "", "src1 == 0 ? 0 : (src0 / src1)")
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue