Re: [Mesa-dev] [PATCH 06/26] python: Better iterate over dictionaries

2018-07-06 Thread Mathieu Bridon
On Thu, 2018-07-05 at 08:48 -0700, Dylan Baker wrote:
> I've asked a couple of people who have (in the past at least) had a
> hard requirement on python 2.x if moving to 3.x will be okay for
> them. If it's not then we may need to do something else here. I've
> used six in the past (although I know a lot of other pythonistas
> don't like six), so that would be an option I think.
> 
> While this works fine, it's going to create a lot of overhead for
> anyone using python 2, since some of these data structures are huge,
> and returning a copy (or copy of a copy) is going to be fairly
> expensive. If we can drop python 2 support that of course isn't a
> problem.

I tested the scripts with Python 2 as well, and they didn't seem to
take significantly more time to complete. (I didn't look at memory
consumption though, which is a bit hard for scripts running so fast)

Are some of those platforms that require Python 2 very low-performance
ones, where it would have an actual impact?

I have a very slow ARM machine handy, I can try and see whether the
patches make a big difference there if it helps?

> Assuming that those people are okay with python 3,

If everyone is ok moving fully to Python 3, then the patch series could
be quite different and simpler. ^_^


-- 
Mathieu
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev


Re: [Mesa-dev] [PATCH 06/26] python: Better iterate over dictionaries

2018-07-05 Thread Dylan Baker
I've asked a couple of people who have (in the past at least) had a hard
requirement on python 2.x if moving to 3.x will be okay for them. If it's not
then we may need to do something else here. I've used six in the past (although
I know a lot of other pythonistas don't like six), so that would be an option I
think.

While this works fine, it's going to create a lot of overhead for anyone using
python 2, since some of these data structures are huge, and returning a copy (or
copy of a copy) is going to be fairly expensive. If we can drop python 2 support
that of course isn't a problem.

Assuming that those people are okay with python 3,
Reviewed-by: Dylan Baker 

Quoting Mathieu Bridon (2018-07-05 06:17:37)
> In Python 2, dictionaries have 2 sets of methods to iterate over their
> keys and values: keys()/values()/items() and 
> iterkeys()/itervalues()/iteritems().
> 
> The former return lists while the latter return iterators.
> 
> Python 3 dropped the method which return lists, and renamed the methods
> returning iterators to keys()/values()/items().
> 
> Using those names makes the scripts compatible with both Python 2 and 3.
> 
> Signed-off-by: Mathieu Bridon 
> ---
>  src/amd/vulkan/radv_entrypoints_gen.py   |  2 +-
>  src/compiler/nir/nir_algebraic.py|  2 +-
>  src/compiler/nir/nir_builder_opcodes_h.py|  4 ++--
>  src/compiler/nir/nir_constant_expressions.py |  4 ++--
>  src/compiler/nir/nir_intrinsics_c.py |  2 +-
>  src/compiler/nir/nir_opcodes_c.py|  2 +-
>  src/compiler/nir/nir_opcodes_h.py|  2 +-
>  src/intel/genxml/gen_bits_header.py  | 10 +-
>  src/intel/vulkan/anv_entrypoints_gen.py  |  2 +-
>  src/mapi/glapi/gen/gl_XML.py | 12 ++--
>  src/mapi/glapi/gen/gl_gentable.py|  4 ++--
>  src/mesa/drivers/dri/i965/brw_oa.py  |  4 ++--
>  12 files changed, 25 insertions(+), 25 deletions(-)
> 
> diff --git a/src/amd/vulkan/radv_entrypoints_gen.py 
> b/src/amd/vulkan/radv_entrypoints_gen.py
> index bef0c447f6..9c4dfd02a0 100644
> --- a/src/amd/vulkan/radv_entrypoints_gen.py
> +++ b/src/amd/vulkan/radv_entrypoints_gen.py
> @@ -433,7 +433,7 @@ def get_entrypoints(doc, entrypoints_to_defines, 
> start_index):
>  e_clone.name = e.name
>  entrypoints[e.name] = e_clone
>  
> -return [e for e in entrypoints.itervalues() if e.enabled]
> +return [e for e in entrypoints.values() if e.enabled]
>  
>  
>  def get_entrypoints_defines(doc):
> diff --git a/src/compiler/nir/nir_algebraic.py 
> b/src/compiler/nir/nir_algebraic.py
> index 847c59dbd8..8c0b530f69 100644
> --- a/src/compiler/nir/nir_algebraic.py
> +++ b/src/compiler/nir/nir_algebraic.py
> @@ -512,7 +512,7 @@ struct transform {
>  
>  #endif
>  
> -% for (opcode, xform_list) in xform_dict.iteritems():
> +% for (opcode, xform_list) in xform_dict.items():
>  % for xform in xform_list:
> ${xform.search.render()}
> ${xform.replace.render()}
> diff --git a/src/compiler/nir/nir_builder_opcodes_h.py 
> b/src/compiler/nir/nir_builder_opcodes_h.py
> index 72cf5b4549..e600093e9f 100644
> --- a/src/compiler/nir/nir_builder_opcodes_h.py
> +++ b/src/compiler/nir/nir_builder_opcodes_h.py
> @@ -34,7 +34,7 @@ def src_list(num_srcs):
> return ', '.join('src' + str(i) if i < num_srcs else 'NULL' for i in 
> range(4))
>  %>
>  
> -% for name, opcode in sorted(opcodes.iteritems()):
> +% for name, opcode in sorted(opcodes.items()):
>  static inline nir_ssa_def *
>  nir_${name}(nir_builder *build, ${src_decl_list(opcode.num_inputs)})
>  {
> @@ -55,7 +55,7 @@ nir_load_system_value(nir_builder *build, nir_intrinsic_op 
> op, int index)
> return >dest.ssa;
>  }
>  
> -% for name, opcode in filter(lambda v: v[1].sysval, 
> sorted(INTR_OPCODES.iteritems())):
> +% for name, opcode in filter(lambda v: v[1].sysval, 
> sorted(INTR_OPCODES.items())):
>  static inline nir_ssa_def *
>  nir_${name}(nir_builder *build)
>  {
> diff --git a/src/compiler/nir/nir_constant_expressions.py 
> b/src/compiler/nir/nir_constant_expressions.py
> index 35dffe70ce..118af9f781 100644
> --- a/src/compiler/nir/nir_constant_expressions.py
> +++ b/src/compiler/nir/nir_constant_expressions.py
> @@ -387,7 +387,7 @@ struct bool32_vec {
> % endif
>  
>  
> -% for name, op in sorted(opcodes.iteritems()):
> +% for name, op in sorted(opcodes.items()):
>  static nir_const_value
>  evaluate_${name}(MAYBE_UNUSED unsigned num_components,
>   ${"UNUSED" if op_bit_sizes(op) is None else ""} unsigned 
> bit_size,
> @@ -420,7 +420,7 @@ nir_eval_const_opcode(nir_op op, unsigned num_components,
>unsigned bit_width, nir_const_value *src)
>  {
> switch (op) {
> -% for name in sorted(opcodes.iterkeys()):
> +% for name in sorted(opcodes.keys()):
> case nir_op_${name}:
>return evaluate_${name}(num_components, bit_width, src);
>  % endfor
> diff --git a/src/compiler/nir/nir_intrinsics_c.py 
> 

Re: [Mesa-dev] [PATCH 06/26] python: Better iterate over dictionaries

2018-07-05 Thread Eric Engestrom
On Thursday, 2018-07-05 15:17:37 +0200, Mathieu Bridon wrote:
> In Python 2, dictionaries have 2 sets of methods to iterate over their
> keys and values: keys()/values()/items() and 
> iterkeys()/itervalues()/iteritems().
> 
> The former return lists while the latter return iterators.
> 
> Python 3 dropped the method which return lists, and renamed the methods
> returning iterators to keys()/values()/items().
> 
> Using those names makes the scripts compatible with both Python 2 and 3.
> 
> Signed-off-by: Mathieu Bridon 

Reviewed-by: Eric Engestrom 

> ---
>  src/amd/vulkan/radv_entrypoints_gen.py   |  2 +-
>  src/compiler/nir/nir_algebraic.py|  2 +-
>  src/compiler/nir/nir_builder_opcodes_h.py|  4 ++--
>  src/compiler/nir/nir_constant_expressions.py |  4 ++--
>  src/compiler/nir/nir_intrinsics_c.py |  2 +-
>  src/compiler/nir/nir_opcodes_c.py|  2 +-
>  src/compiler/nir/nir_opcodes_h.py|  2 +-
>  src/intel/genxml/gen_bits_header.py  | 10 +-
>  src/intel/vulkan/anv_entrypoints_gen.py  |  2 +-
>  src/mapi/glapi/gen/gl_XML.py | 12 ++--
>  src/mapi/glapi/gen/gl_gentable.py|  4 ++--
>  src/mesa/drivers/dri/i965/brw_oa.py  |  4 ++--
>  12 files changed, 25 insertions(+), 25 deletions(-)
> 
> diff --git a/src/amd/vulkan/radv_entrypoints_gen.py 
> b/src/amd/vulkan/radv_entrypoints_gen.py
> index bef0c447f6..9c4dfd02a0 100644
> --- a/src/amd/vulkan/radv_entrypoints_gen.py
> +++ b/src/amd/vulkan/radv_entrypoints_gen.py
> @@ -433,7 +433,7 @@ def get_entrypoints(doc, entrypoints_to_defines, 
> start_index):
>  e_clone.name = e.name
>  entrypoints[e.name] = e_clone
>  
> -return [e for e in entrypoints.itervalues() if e.enabled]
> +return [e for e in entrypoints.values() if e.enabled]
>  
>  
>  def get_entrypoints_defines(doc):
> diff --git a/src/compiler/nir/nir_algebraic.py 
> b/src/compiler/nir/nir_algebraic.py
> index 847c59dbd8..8c0b530f69 100644
> --- a/src/compiler/nir/nir_algebraic.py
> +++ b/src/compiler/nir/nir_algebraic.py
> @@ -512,7 +512,7 @@ struct transform {
>  
>  #endif
>  
> -% for (opcode, xform_list) in xform_dict.iteritems():
> +% for (opcode, xform_list) in xform_dict.items():
>  % for xform in xform_list:
> ${xform.search.render()}
> ${xform.replace.render()}
> diff --git a/src/compiler/nir/nir_builder_opcodes_h.py 
> b/src/compiler/nir/nir_builder_opcodes_h.py
> index 72cf5b4549..e600093e9f 100644
> --- a/src/compiler/nir/nir_builder_opcodes_h.py
> +++ b/src/compiler/nir/nir_builder_opcodes_h.py
> @@ -34,7 +34,7 @@ def src_list(num_srcs):
> return ', '.join('src' + str(i) if i < num_srcs else 'NULL' for i in 
> range(4))
>  %>
>  
> -% for name, opcode in sorted(opcodes.iteritems()):
> +% for name, opcode in sorted(opcodes.items()):
>  static inline nir_ssa_def *
>  nir_${name}(nir_builder *build, ${src_decl_list(opcode.num_inputs)})
>  {
> @@ -55,7 +55,7 @@ nir_load_system_value(nir_builder *build, nir_intrinsic_op 
> op, int index)
> return >dest.ssa;
>  }
>  
> -% for name, opcode in filter(lambda v: v[1].sysval, 
> sorted(INTR_OPCODES.iteritems())):
> +% for name, opcode in filter(lambda v: v[1].sysval, 
> sorted(INTR_OPCODES.items())):
>  static inline nir_ssa_def *
>  nir_${name}(nir_builder *build)
>  {
> diff --git a/src/compiler/nir/nir_constant_expressions.py 
> b/src/compiler/nir/nir_constant_expressions.py
> index 35dffe70ce..118af9f781 100644
> --- a/src/compiler/nir/nir_constant_expressions.py
> +++ b/src/compiler/nir/nir_constant_expressions.py
> @@ -387,7 +387,7 @@ struct bool32_vec {
> % endif
>  
>  
> -% for name, op in sorted(opcodes.iteritems()):
> +% for name, op in sorted(opcodes.items()):
>  static nir_const_value
>  evaluate_${name}(MAYBE_UNUSED unsigned num_components,
>   ${"UNUSED" if op_bit_sizes(op) is None else ""} unsigned 
> bit_size,
> @@ -420,7 +420,7 @@ nir_eval_const_opcode(nir_op op, unsigned num_components,
>unsigned bit_width, nir_const_value *src)
>  {
> switch (op) {
> -% for name in sorted(opcodes.iterkeys()):
> +% for name in sorted(opcodes.keys()):
> case nir_op_${name}:
>return evaluate_${name}(num_components, bit_width, src);
>  % endfor
> diff --git a/src/compiler/nir/nir_intrinsics_c.py 
> b/src/compiler/nir/nir_intrinsics_c.py
> index 9604fcdf62..98af67c38a 100644
> --- a/src/compiler/nir/nir_intrinsics_c.py
> +++ b/src/compiler/nir/nir_intrinsics_c.py
> @@ -25,7 +25,7 @@ template = """\
>  #include "nir.h"
>  
>  const nir_intrinsic_info nir_intrinsic_infos[nir_num_intrinsics] = {
> -% for name, opcode in sorted(INTR_OPCODES.iteritems()):
> +% for name, opcode in sorted(INTR_OPCODES.items()):
>  {
> .name = "${name}",
> .num_srcs = ${opcode.num_srcs},
> diff --git a/src/compiler/nir/nir_opcodes_c.py 
> b/src/compiler/nir/nir_opcodes_c.py
> index 108e144b5f..4603cd3d74 100644
> ---