develooper Front page | perl.perl5.porters | Postings from January 2015

[perl #123616] Weed out needless PERL_UNUSED_ARG

Thread Previous | Thread Next
bulk88 via RT
January 17, 2015 20:33
[perl #123616] Weed out needless PERL_UNUSED_ARG
Message ID:
On Sat Jan 17 09:00:57 2015, wrote:
> Hi there,
> This is my first time contributing a patch so I'm looking for a little
> guidance. As suggested by the subject and with assistance from Hugo at
> the London Perl Hackday, I've weeded out some obvious PERL_UNUSED_ARG
> statements inside static functions as requested in the Perl 5 todo.pod
> file.
> The remaining PERL_UNUSED_ARG statements appear to be for variables
> that are (1) contained in non-static functions, (2) conditionally used
> depending on pre-processor macros  or (3) placeholders so that the
> static function prototypes match particular function pointers.

Reading about dquote_static.c and grok_bslash_x brings up a couple questions how its implementation.

grok_bslash_x is 0x133 bytes of VC 2003 -O1 32 bit machine code. It is declared as PERL_STATIC_INLINE in dquote_static.c and in "EMiR" embed.fnc. Something that fat in machine code and pagefuls of C code should be inlined in exactly one scenario, it has only 1 caller, and it is unconditionally (basically not in a "if" branch) executed in that caller. VC optimizer refused to inline grok_bslash_x and instead it is called from 3 callers in VC machine code and in Perl C source code, S_regatom, S_regclass, and S_scan_const.

The inline came from by khw from 5.17.1.

If I didn't have VC's WPO/LTO/LTCG mode turned on, there would be 2 copies of S_grok_bslash_x in the perl binary (VC 6 doesn't have LTCG, too old, so it suffers too), since a normal C linker can't dedup nameless, symbol-less static functions. Here is a symbol list from HPUX HP C blead perl showing that HPUX ld didn't dedup the functions.

name              addr     length
S_grok_bslash_c   00097224 00000148
S_grok_bslash_c_1 000BFBE0 00000148
S_grok_bslash_o   0009736C 000001CC
S_grok_bslash_o_1 000BFD28 000001CC
S_grok_bslash_x   00097538 00000268
S_grok_bslash_x_1 000BFEF4 00000268

I assume that all 3 S_grok_blash* functions are used in re::* XS module. 

There are 2 things that should have been done.

Either S_grok* becomes Perl_grok*_*p and Xp or stays as S_grok* and becomes X in embed.fnc, so they are exported to re::* XS SO.


dquote_static.c becomes a formal translation unit for core but its functions are not exported in embed.fnc. Then on restricted visibility platforms (IE Win32) it is then #include-ed in re::* again but this time S_grok_bslash* are PERL_STATIC_INLINE. dquote_static.c and embed.fnc has an

iR	|bool	|grok_bslash_xp	|NN char** s|NN UV* uv           \
				|NN const char** error_msg       \
				|const bool strict               \
				|const bool silence_non_portable \
				|const bool utf8
pR	|bool	|grok_bslash_xp	|NN char** s|NN UV* uv           \
				|NN const char** error_msg       \
				|const bool strict               \
				|const bool silence_non_portable \
				|const bool utf8

#  error What are you doing?
S_grok_bslash_x(pTHX_ char **s, UV *uv, const char** error_msg,
                      const bool strict,
                      const bool silence_non_portable,
                      const bool UTF)

This way core's S_grok_bslash can get WPO optimized (random register calling conventions, removing unused params, merging params, etc) but re:: XS SO/DLL gets its own machine code copy that also was hopefully WPO-ed.

bulk88 ~ bulk88 at

via perlbug:  queue: perl5 status: new

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About