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

[PATCH] Use PTRSIZE in compiletime, not runtime #13785

Closed
p5pRT opened this issue Apr 30, 2014 · 10 comments
Closed

[PATCH] Use PTRSIZE in compiletime, not runtime #13785

p5pRT opened this issue Apr 30, 2014 · 10 comments
Labels

Comments

@p5pRT
Copy link

p5pRT commented Apr 30, 2014

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

Searchable as RT121768$

@p5pRT
Copy link
Author

p5pRT commented Apr 30, 2014

From @jhi

Minor nit noticed in passing​: does not make sense to use PTRSIZE in
runtime when we can do it in compiletime (perl.c​:perl_parse(), in the
computation of Perl_origalen)

Patch attached.

@p5pRT
Copy link
Author

p5pRT commented Apr 30, 2014

From @jhi

0001-Use-PTRSIZE-in-compiletime-not-runtime.patch
From 34182552ece7d209f632ba15d8feb44105da416a Mon Sep 17 00:00:00 2001
From: Jarkko Hietaniemi <jhi@iki.fi>
Date: Wed, 30 Apr 2014 07:49:07 -0400
Subject: [PATCH] Use PTRSIZE in compiletime, not runtime.

---
 perl.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/perl.c b/perl.c
index 27d0d9e..1b9b429 100644
--- a/perl.c
+++ b/perl.c
@@ -1496,8 +1496,7 @@ perl_parse(pTHXx_ XSINIT_t xsinit, int argc, char **argv, char **env)
 	 * --jhi */
 	 const char *s = NULL;
 	 int i;
-	 const UV mask =
-	   ~(UV)(PTRSIZE == 4 ? 3 : PTRSIZE == 8 ? 7 : PTRSIZE == 16 ? 15 : 0);
+	 const UV mask = ~(UV)(PTRSIZE-1);
          /* Do the mask check only if the args seem like aligned. */
 	 const UV aligned =
 	   (mask < ~(UV)0) && ((PTR2UV(argv[0]) & mask) == PTR2UV(argv[0]));
-- 
1.9.2

@p5pRT
Copy link
Author

p5pRT commented May 1, 2014

From @tonycoz

On Wed Apr 30 04​:54​:26 2014, jhi wrote​:

Minor nit noticed in passing​: does not make sense to use PTRSIZE in
runtime when we can do it in compiletime (perl.c​:perl_parse(), in the
computation of Perl_origalen)

Patch attached.

They're both compile-time, your version is certainly terser.

I'm not sure the alignments used here are correct, the preferred alignment for x86_64 (64-bit, 8 byte pointers) is 16 bytes[1], though whether anyone bothers to align argv[] on 16-byte boundaries, I don't know.

Tony

[1] some SSE instructions require 16-byte alignment

@p5pRT
Copy link
Author

p5pRT commented May 1, 2014

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

@p5pRT
Copy link
Author

p5pRT commented May 1, 2014

From @jhi

On Thursday-201405-01, 2​:18, Tony Cook via RT wrote​:

They're both compile-time, your version is certainly terser.

Argh, yes, right.

I'm not sure the alignments used here are correct, the preferred alignment for x86_64 (64-bit, 8 byte pointers) is 16 bytes[1], though whether anyone bothers to align argv[] on 16-byte boundaries, I don't know.

Well, my change is not at least not making the alignments different...
(except in the fallback case of not-4/8/16, which likely never to be
reached, unless someone tries to compile Perl on 6502/Z80...) I don't
know whether we have anything for "preferred alignment of pointers" in
our config vars.

That being said, the whole environment peeking/poking code is horrendous.

@p5pRT
Copy link
Author

p5pRT commented May 2, 2014

From @jhi

On Thursday-201405-01, 6​:43, Jarkko Hietaniemi wrote​:

On Thursday-201405-01, 2​:18, Tony Cook via RT wrote​:

They're both compile-time, your version is certainly terser.

Argh, yes, right.

I'm not sure the alignments used here are correct, the preferred alignment for x86_64 (64-bit, 8 byte pointers) is 16 bytes[1], though whether anyone bothers to align argv[] on 16-byte boundaries, I don't know.

Well, my change is not at least not making the alignments different...
(except in the fallback case of not-4/8/16, which likely never to be
reached, unless someone tries to compile Perl on 6502/Z80...) I don't
know whether we have anything for "preferred alignment of pointers" in
our config vars.

That being said, the whole environment peeking/poking code is horrendous.

Better described patch attached.

@p5pRT
Copy link
Author

p5pRT commented May 2, 2014

From @jhi

0001-For-ptr-masking-use-PTRSIZE-1-not-nested-conditional.patch
From a54bfd42793134ffec3b400cef07845fcf2c5f48 Mon Sep 17 00:00:00 2001
From: Jarkko Hietaniemi <jhi@iki.fi>
Date: Wed, 30 Apr 2014 07:49:07 -0400
Subject: [PATCH] For ptr masking use PTRSIZE-1, not nested conditional
 statement.

---
 perl.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/perl.c b/perl.c
index 27d0d9e..1b9b429 100644
--- a/perl.c
+++ b/perl.c
@@ -1496,8 +1496,7 @@ perl_parse(pTHXx_ XSINIT_t xsinit, int argc, char **argv, char **env)
 	 * --jhi */
 	 const char *s = NULL;
 	 int i;
-	 const UV mask =
-	   ~(UV)(PTRSIZE == 4 ? 3 : PTRSIZE == 8 ? 7 : PTRSIZE == 16 ? 15 : 0);
+	 const UV mask = ~(UV)(PTRSIZE-1);
          /* Do the mask check only if the args seem like aligned. */
 	 const UV aligned =
 	   (mask < ~(UV)0) && ((PTR2UV(argv[0]) & mask) == PTR2UV(argv[0]));
-- 
1.9.2

@p5pRT
Copy link
Author

p5pRT commented May 6, 2014

From @tonycoz

On Thu May 01 17​:44​:59 2014, jhi wrote​:

Better described patch attached.

Added to the ever growing 5.21.1 blockers list

Tony

@p5pRT
Copy link
Author

p5pRT commented May 28, 2014

From @tsee

Thanks, second version of the patch applied as b7249aa.

@p5pRT
Copy link
Author

p5pRT commented May 28, 2014

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

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

No branches or pull requests

1 participant