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] rearrange initializations in S_intuit_more for better code gen #12710
Comments
From @bulk88See attached patch. |
From @bulk880001-rearrange-initializations-in-S_intuit_more-for-bette.patchFrom 7eff62ccd04b51539468d56f9d76f9753c42470c Mon Sep 17 00:00:00 2001
From: Daniel Dragan <bulk88@hotmail.com>
Date: Thu, 17 Jan 2013 18:38:07 -0500
Subject: [PATCH] rearrange initializations in S_intuit_more for better code
gen
MS VC 2003 in my experiance does not reorder var initializations with
constants to reduce their liveness. This commit attempts to defer
initialization until right before the var is first used. I can't explain
exactly why less instructions or shorter addressing happened since I didnt
record what the asm looked like before. On VC 2003 -O1 -GL, S_intuit_more
was previously 0x4B5 bytes of 32 bit machine code long, after it this
change it is 0x4A3 bytes long. These changes should have no user visible
effect.
The scope of the vars was not reduced to avoid large indentation changes
which would be required under C89 and Perl code formatting policy.
---
toke.c | 8 +++++---
1 files changed, 5 insertions(+), 3 deletions(-)
diff --git a/toke.c b/toke.c
index 987a68d..411fb42 100644
--- a/toke.c
+++ b/toke.c
@@ -3831,16 +3831,16 @@ S_intuit_more(pTHX_ char *s)
return FALSE;
else {
/* this is terrifying, and it works */
- int weight = 2; /* let's weigh the evidence */
+ int weight;
char seen[256];
- unsigned char un_char = 255, last_un_char;
const char * const send = strchr(s,']');
+ unsigned char un_char, last_un_char;
char tmpbuf[sizeof PL_tokenbuf * 4];
if (!send) /* has to be an expression */
return TRUE;
+ weight = 2; /* let's weigh the evidence */
- Zero(seen,256,char);
if (*s == '$')
weight -= 3;
else if (isDIGIT(*s)) {
@@ -3851,6 +3851,8 @@ S_intuit_more(pTHX_ char *s)
else
weight -= 100;
}
+ Zero(seen,256,char);
+ un_char = 255;
for (; s < send; s++) {
last_un_char = un_char;
un_char = (unsigned char)*s;
--
1.7.9.msysgit.0
|
From @iabynOn Thu, Jan 17, 2013 at 03:40:55PM -0800, bulk88 wrote:
I really don't understand the point of nano-optimisations such as this. You've removed (for a particular compiler), 19 bytes of code from a I would estimate that any performance improvements are indistinguishable The change itself is so subtle that the next change to this function -- |
The RT System itself - Status changed from 'new' to 'open' |
From @doughera88On Thu, 17 Jan 2013, bulk88 wrote:
Thanks, applied as commit 99f2bdb. With both gcc and Sun's C, this patch makes no difference for optimized Thanks, -- |
From @doughera88On Fri, 18 Jan 2013, Dave Mitchell wrote:
[Sorry I didn't see this message before I committed the patch.] I agree. I'd also point out that there are hidden costs to such In this case, the function in question has barely changed since 1993, so I In the future, though, I think I will probably look for more evidence of a -- |
@doughera88 - Status changed from 'open' to 'resolved' |
From @bulk88On Fri Jan 18 07:02:01 2013, davem wrote:
It was picked because it called memset, I was following an idea in Perl
This change is unmeasurable small, but every little bit counts.
I agree the chance of the optimization undoing itself is high. But the On Fri Jan 18 07:34:41 2013, doughera wrote:
The object or executable image file might be the same exactly the same If the function is smaller than a page/screen I would have reindented it On Fri Jan 18 08:03:30 2013, doughera wrote:
Some porters have an opinion my commits are too long, and too general -- |
From @doughera88On Fri, 18 Jan 2013, bulk88 via RT wrote:
But every little bit also has a cost, and those add up too.
You also have to include all the time for someone else to review the
It also might be exactly the same size if the compiler optimizer
No. Grouping multiple independent nano-optimizations together wouldn't My bigger point was that I don't think it's worth investing the time in -- |
Migrated from rt.perl.org#116443 (status was 'resolved')
Searchable as RT116443$
The text was updated successfully, but these errors were encountered: