Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

optimize macro dXSARGS #7753

Closed
p5pRT opened this issue Jan 17, 2005 · 5 comments
Closed

optimize macro dXSARGS #7753

p5pRT opened this issue Jan 17, 2005 · 5 comments

Comments

@p5pRT
Copy link

p5pRT commented Jan 17, 2005

Migrated from rt.perl.org#33809 (status was 'resolved')

Searchable as RT33809$

@p5pRT
Copy link
Author

p5pRT commented Jan 17, 2005

From skv@protey.ru

Currently dXSARGS is defined as
dSP; dMARK; dAX; dITEMS

I offer to replace "dMARK; dAX;" with new macro "dAXMARK;"

Sequence "dMARK; dAX;" is expanded as​:
register SV **mark = PL_stack_base + POPMARK;
I32 ax = MARK - PL_stack_base + 1;

New macro dAXMARK optmize it via reducing by one "subtract" operation (and
replacing "add" with "inc")​:
I32 ax = POPMARK;
register SV **mark = PL_stack_base + ax++;

Also this patch replaces sequence "dMARK; dAX;" in universal.c in functions
hash_seed() and rehash_seed().

Offered optimization is clear and obvious.
This patch created and tested on perl 5.8.6.

Inline Patch
--- XSUB.h.orig	2005-01-16 20:29:03.031000000 +0300
+++ XSUB.h	2005-01-16 20:47:27.250000000 +0300
@@ -52,6 +52,9 @@

  =for apidoc Ams||dAX
  Sets up the C<ax> variable.
+
+=for apidoc Ams||dAXMARK
+Sets up the C<ax> variable and stack marker variable C<mark>.
  This is usually handled automatically by C<xsubpp> by calling C<dXSARGS>.

  =for apidoc Ams||dITEMS
@@ -80,11 +83,14 @@

  #define dAX I32 ax = MARK - PL_stack_base + 1

+#define dAXMARK				\
+	I32 ax = POPMARK;		\
+	register SV **mark = PL_stack_base + ax++
+
  #define dITEMS I32 items = SP - MARK

  #define dXSARGS				\
-	dSP; dMARK;			\
-	dAX; dITEMS
+	dSP; dAXMARK; dITEMS

  #define dXSTARG SV * targ = ((PL_op->op_private & OPpENTERSUB_HASTARG) \
  			     ? PAD_SV(PL_op->op_targ) : sv_newmortal())

--- universal.c.orig	2005-01-16 20:44:50.640625000 +0300
+++ universal.c	2005-01-16 20:45:03.656250000 +0300
@@ -690,7 +690,7 @@
  {
      /* Using dXSARGS would also have dITEM and dSP,
       * which define 2 unused local variables.  */
-    dMARK; dAX;
+    dAXMARK;
      XSRETURN_UV(PERL_HASH_SEED);
  }

@@ -698,7 +698,7 @@
  {
      /* Using dXSARGS would also have dITEM and dSP,
       * which define 2 unused local variables.  */
-    dMARK; dAX;
+    dAXMARK;
      XSRETURN_UV(PL_rehash_seed);
  }


-- 

Sergey Skvortsov
mailto​: skv@​protey.ru

@p5pRT
Copy link
Author

p5pRT commented Apr 27, 2005

From @smpeters

[godegisel - Mon Jan 17 01​:02​:32 2005]​:

Currently dXSARGS is defined as
dSP; dMARK; dAX; dITEMS

I offer to replace "dMARK; dAX;" with new macro "dAXMARK;"

Sequence "dMARK; dAX;" is expanded as​:
register SV **mark = PL_stack_base + POPMARK;
I32 ax = MARK - PL_stack_base + 1;

New macro dAXMARK optmize it via reducing by one "subtract" operation
(and
replacing "add" with "inc")​:
I32 ax = POPMARK;
register SV **mark = PL_stack_base + ax++;

Also this patch replaces sequence "dMARK; dAX;" in universal.c in
functions
hash_seed() and rehash_seed().

Offered optimization is clear and obvious.
This patch created and tested on perl 5.8.6.

--- XSUB.h.orig 2005-01-16 20​:29​:03.031000000 +0300
+++ XSUB.h 2005-01-16 20​:47​:27.250000000 +0300
@​@​ -52,6 +52,9 @​@​

=for apidoc Ams||dAX
Sets up the C<ax> variable.
+
+=for apidoc Ams||dAXMARK
+Sets up the C<ax> variable and stack marker variable C<mark>.
This is usually handled automatically by C<xsubpp> by calling
C<dXSARGS>.

=for apidoc Ams||dITEMS
@​@​ -80,11 +83,14 @​@​

#define dAX I32 ax = MARK - PL_stack_base + 1

+#define dAXMARK \
+ I32 ax = POPMARK; \
+ register SV **mark = PL_stack_base + ax++
+
#define dITEMS I32 items = SP - MARK

#define dXSARGS \
- dSP; dMARK; \
- dAX; dITEMS
+ dSP; dAXMARK; dITEMS

#define dXSTARG SV * targ = ((PL_op->op_private &
OPpENTERSUB_HASTARG) \
? PAD_SV(PL_op->op_targ) : sv_newmortal())

--- universal.c.orig 2005-01-16 20​:44​:50.640625000 +0300
+++ universal.c 2005-01-16 20​:45​:03.656250000 +0300
@​@​ -690,7 +690,7 @​@​
{
/* Using dXSARGS would also have dITEM and dSP,
* which define 2 unused local variables. */
- dMARK; dAX;
+ dAXMARK;
XSRETURN_UV(PERL_HASH_SEED);
}

@​@​ -698,7 +698,7 @​@​
{
/* Using dXSARGS would also have dITEM and dSP,
* which define 2 unused local variables. */
- dMARK; dAX;
+ dAXMARK;
XSRETURN_UV(PL_rehash_seed);
}

It appears that this ticket has been warnocked. Does this make any
sense to do?

Steve Peters
steve@​fisharerojo.org

@p5pRT
Copy link
Author

p5pRT commented Apr 27, 2005

The RT System itself - Status changed from 'new' to 'open'

@p5pRT
Copy link
Author

p5pRT commented May 3, 2005

@rgs - Status changed from 'open' to 'resolved'

@p5pRT p5pRT closed this as completed May 3, 2005
@p5pRT
Copy link
Author

p5pRT commented May 3, 2005

From @rgs

Sergey Skvortsov (via RT) wrote​:

Currently dXSARGS is defined as
dSP; dMARK; dAX; dITEMS

I offer to replace "dMARK; dAX;" with new macro "dAXMARK;"

Sequence "dMARK; dAX;" is expanded as​:
register SV **mark = PL_stack_base + POPMARK;
I32 ax = MARK - PL_stack_base + 1;

New macro dAXMARK optmize it via reducing by one "subtract" operation (and
replacing "add" with "inc")​:
I32 ax = POPMARK;
register SV **mark = PL_stack_base + ax++;

Also this patch replaces sequence "dMARK; dAX;" in universal.c in functions
hash_seed() and rehash_seed().

Thanks for this patch; I've applied it against the development branch
of perl as change #24372.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant