New submission from Mark Shannon <m...@hotpy.org>:

Currently, there are fourteen macros provided for stack manipulation.
Along with the fundamental, POP(), PUSH() and PEEK(n) the following eleven are 
also provided:

TOP()          
SECOND()       
THIRD()        
FOURTH()       
SET_TOP(v)     
SET_SECOND(v)  
SET_THIRD(v)   
SET_FOURTH(v)  
SET_VALUE(n, v)
STACK_GROW(n)
STACK_SHRINK(n) 

These are unnecessary as compilers have long understood the sequences of 
pointer increments and decrements that is generated by using POPs and PUSHes.

See https://godbolt.org/z/Htw-2k which shows GCC generating exactly the same 
code from just POP, PUSH and PEEK as from direct access to items on the stack.

Removing the redundant macros would make the code easier to reason about and 
analyze.
TOP() and SECOND() are used quite heavily and are trivial to convert to PEEK by 
tools, so should probably be left alone.

Notes:

I'm ignoring the stack debugging macros here, they aren't a problem.
The EMPTY() macro is only used twice, so might as well be replaced with 
STACK_LEVEL == 0.
Sadly, there is no "maintainability/code quality" selection for "type" of 
issue, so I've chosen "performance" :(

----------
components: Interpreter Core
keywords: easy (C)
messages: 371087
nosy: Mark.Shannon
priority: normal
severity: normal
stage: needs patch
status: open
title: Remove redundant macros used for stack manipulation in interpreter
type: performance

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue40925>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to