mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-05-07 11:28:05 +02:00
nir/algebraic: Add a mechanism for specifying the bit size of a value
Reviewed-by: Iago Toral Quiroga <itoral@igalia.com>
This commit is contained in:
parent
cafb885e45
commit
fcc1c8a437
3 changed files with 31 additions and 4 deletions
|
|
@ -25,6 +25,7 @@
|
||||||
# Jason Ekstrand (jason@jlekstrand.net)
|
# Jason Ekstrand (jason@jlekstrand.net)
|
||||||
|
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
|
import ast
|
||||||
import itertools
|
import itertools
|
||||||
import struct
|
import struct
|
||||||
import sys
|
import sys
|
||||||
|
|
@ -63,7 +64,7 @@ class Value(object):
|
||||||
|
|
||||||
__template = mako.template.Template("""
|
__template = mako.template.Template("""
|
||||||
static const ${val.c_type} ${val.name} = {
|
static const ${val.c_type} ${val.name} = {
|
||||||
{ ${val.type_enum} },
|
{ ${val.type_enum}, ${val.bit_size} },
|
||||||
% if isinstance(val, Constant):
|
% if isinstance(val, Constant):
|
||||||
${val.type()}, { ${hex(val)} /* ${val.value} */ },
|
${val.type()}, { ${hex(val)} /* ${val.value} */ },
|
||||||
% elif isinstance(val, Variable):
|
% elif isinstance(val, Variable):
|
||||||
|
|
@ -99,10 +100,23 @@ static const ${val.c_type} ${val.name} = {
|
||||||
Variable=Variable,
|
Variable=Variable,
|
||||||
Expression=Expression)
|
Expression=Expression)
|
||||||
|
|
||||||
|
_constant_re = re.compile(r"(?P<value>[^@]+)(?:@(?P<bits>\d+))?")
|
||||||
|
|
||||||
class Constant(Value):
|
class Constant(Value):
|
||||||
def __init__(self, val, name):
|
def __init__(self, val, name):
|
||||||
Value.__init__(self, name, "constant")
|
Value.__init__(self, name, "constant")
|
||||||
self.value = val
|
|
||||||
|
if isinstance(val, (str)):
|
||||||
|
m = _constant_re.match(val)
|
||||||
|
self.value = ast.literal_eval(m.group('value'))
|
||||||
|
self.bit_size = int(m.group('bits')) if m.group('bits') else 0
|
||||||
|
else:
|
||||||
|
self.value = val
|
||||||
|
self.bit_size = 0
|
||||||
|
|
||||||
|
if isinstance(self.value, bool):
|
||||||
|
assert self.bit_size == 0 or self.bit_size == 32
|
||||||
|
self.bit_size = 32
|
||||||
|
|
||||||
def __hex__(self):
|
def __hex__(self):
|
||||||
if isinstance(self.value, (bool)):
|
if isinstance(self.value, (bool)):
|
||||||
|
|
@ -122,7 +136,8 @@ class Constant(Value):
|
||||||
elif isinstance(self.value, float):
|
elif isinstance(self.value, float):
|
||||||
return "nir_type_float"
|
return "nir_type_float"
|
||||||
|
|
||||||
_var_name_re = re.compile(r"(?P<const>#)?(?P<name>\w+)(?:@(?P<type>\w+))?")
|
_var_name_re = re.compile(r"(?P<const>#)?(?P<name>\w+)"
|
||||||
|
r"(?:@(?P<type>int|uint|bool|float)?(?P<bits>\d+)?)?")
|
||||||
|
|
||||||
class Variable(Value):
|
class Variable(Value):
|
||||||
def __init__(self, val, name, varset):
|
def __init__(self, val, name, varset):
|
||||||
|
|
@ -134,6 +149,11 @@ class Variable(Value):
|
||||||
self.var_name = m.group('name')
|
self.var_name = m.group('name')
|
||||||
self.is_constant = m.group('const') is not None
|
self.is_constant = m.group('const') is not None
|
||||||
self.required_type = m.group('type')
|
self.required_type = m.group('type')
|
||||||
|
self.bit_size = int(m.group('bits')) if m.group('bits') else 0
|
||||||
|
|
||||||
|
if self.required_type == 'bool':
|
||||||
|
assert self.bit_size == 0 or self.bit_size == 32
|
||||||
|
self.bit_size = 32
|
||||||
|
|
||||||
if self.required_type is not None:
|
if self.required_type is not None:
|
||||||
assert self.required_type in ('float', 'bool', 'int', 'uint')
|
assert self.required_type in ('float', 'bool', 'int', 'uint')
|
||||||
|
|
@ -148,7 +168,7 @@ class Variable(Value):
|
||||||
elif self.required_type == 'float':
|
elif self.required_type == 'float':
|
||||||
return "nir_type_float"
|
return "nir_type_float"
|
||||||
|
|
||||||
_opcode_re = re.compile(r"(?P<inexact>~)?(?P<opcode>\w+)")
|
_opcode_re = re.compile(r"(?P<inexact>~)?(?P<opcode>\w+)(?:@(?P<bits>\d+))?")
|
||||||
|
|
||||||
class Expression(Value):
|
class Expression(Value):
|
||||||
def __init__(self, expr, name_base, varset):
|
def __init__(self, expr, name_base, varset):
|
||||||
|
|
@ -159,6 +179,7 @@ class Expression(Value):
|
||||||
assert m and m.group('opcode') is not None
|
assert m and m.group('opcode') is not None
|
||||||
|
|
||||||
self.opcode = m.group('opcode')
|
self.opcode = m.group('opcode')
|
||||||
|
self.bit_size = int(m.group('bits')) if m.group('bits') else 0
|
||||||
self.inexact = m.group('inexact') is not None
|
self.inexact = m.group('inexact') is not None
|
||||||
self.sources = [ Value.create(src, "{0}_{1}".format(name_base, i), varset)
|
self.sources = [ Value.create(src, "{0}_{1}".format(name_base, i), varset)
|
||||||
for (i, src) in enumerate(expr[1:]) ]
|
for (i, src) in enumerate(expr[1:]) ]
|
||||||
|
|
|
||||||
|
|
@ -53,6 +53,10 @@ d = 'd'
|
||||||
# For constants, you have to be careful to make sure that it is the right
|
# For constants, you have to be careful to make sure that it is the right
|
||||||
# type because python is unaware of the source and destination types of the
|
# type because python is unaware of the source and destination types of the
|
||||||
# opcodes.
|
# opcodes.
|
||||||
|
#
|
||||||
|
# All expression types can have a bit-size specified. For opcodes, this
|
||||||
|
# looks like "op@32", for variables it is "a@32" or "a@uint32" to specify a
|
||||||
|
# type and size, and for literals, you can write "2.0@32".
|
||||||
|
|
||||||
optimizations = [
|
optimizations = [
|
||||||
(('fneg', ('fneg', a)), a),
|
(('fneg', ('fneg', a)), a),
|
||||||
|
|
|
||||||
|
|
@ -40,6 +40,8 @@ typedef enum {
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
nir_search_value_type type;
|
nir_search_value_type type;
|
||||||
|
|
||||||
|
unsigned bit_size;
|
||||||
} nir_search_value;
|
} nir_search_value;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue