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

Fast method for ElmsBlist when positions are a range with increment 1 #1773

Merged
merged 3 commits into from
Oct 27, 2017

Conversation

stevelinton
Copy link
Contributor

Also used for copying pieces of GF2 vectors around.

@codecov
Copy link

codecov bot commented Oct 14, 2017

Codecov Report

Merging #1773 into master will decrease coverage by 0.04%.
The diff coverage is 74.41%.

@@            Coverage Diff             @@
##           master    #1773      +/-   ##
==========================================
- Coverage   62.92%   62.87%   -0.05%     
==========================================
  Files         968      968              
  Lines      294059   293097     -962     
  Branches    12987    12929      -58     
==========================================
- Hits       185031   184290     -741     
+ Misses     106227   106016     -211     
+ Partials     2801     2791      -10
Impacted Files Coverage Δ
src/vecgf2.c 57.64% <100%> (+1.11%) ⬆️
src/blister.h 80.37% <71.64%> (-14.63%) ⬇️
src/blister.c 77.14% <76.92%> (-0.28%) ⬇️
lib/files.gi 29.09% <0%> (-17.63%) ⬇️
lib/files.gd 56.7% <0%> (-5.16%) ⬇️
src/system.c 49.31% <0%> (-3.97%) ⬇️
hpcgap/pkg/gapdoc/PackageInfo.g 33.75% <0%> (-1.25%) ⬇️
lib/pager.gi 7.27% <0%> (-0.61%) ⬇️
src/c_oper1.c 87.03% <0%> (-0.57%) ⬇️
lib/init.g 43.67% <0%> (-0.5%) ⬇️
... and 52 more

@ChrisJefferson
Copy link
Contributor

While I imagine we'd have realised, some nice test which tests a large range of offsets and lengths would be nice, just to make sure there isn't some nasty corner case somewhere.

@stevelinton
Copy link
Contributor Author

@ChrisJefferson I have a stand along C program which is pretty exhaustive. I'll translate it into GAP.

@fingolfin fingolfin added the release notes: not needed PRs introducing changes that are wholly irrelevant to the release notes label Oct 18, 2017
@fingolfin
Copy link
Member

I added the "not-for-release-notes" label. But perhaps this PR gives a speed boost to something? Then of course this label should be removed again... but I couldn't tell from the description of the PR.

src/blister.h Outdated
@@ -140,6 +140,9 @@ static inline UInt * BLOCKS_BLIST(Obj list)
return BLOCKS_BLIST_UNSAFE(list);
}

static inline const UInt * CONST_BLOCKS_BLIST(Obj list) {
return (const UInt *)BLOCKS_BLIST(list);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm afraid this implementation defeats the ultimate purpose: to allow inserting read/write guards in an "optimal" fashion. Really need this (and use 4 spaces for indent):

static inline const UInt * CONST_BLOCKS_BLIST(Obj list)
{
    GAP_ASSERT(IS_BLIST_REP_WITH_COPYING(list));
    return ((const UInt *)(CONST_ADDR_OBJ(list) + 1));
}

src/blister.h Outdated
*/

/* constructs a mask that selects bits <from> to <to> inclusive of a UInt */
static inline UInt mask(UInt from, UInt to)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, mask is an awfully common name, not sure it's a good idea to use that for a global function.

src/blister.h Outdated
}


static inline __attribute__((always_inline)) void CopyBits(const UInt * fromblock,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should use ALWAYS_INLINE from PR #1779

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR #1779 has been merged, so you can now do this.

src/vecgf2.c Outdated
}
return;
}
CopyBits(sptr, soff, dptr, doff, nelts);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you conducted tests as to whether (and if so: how exactly) this change to the GF2 code affects performance?

@stevelinton
Copy link
Contributor Author

@fingolfin It speeds up ElmsBlist, which was missing this special case, and showed up as 10% of the CPU time in teststandard. More or less equivalent, but much much messier code was already in the vecgf2 applications, so I'd expect little or no change there, but I'll check.

@fingolfin fingolfin added this to the GAP 4.9.0 milestone Oct 19, 2017
@fingolfin fingolfin added kind: enhancement Label for issues suggesting enhancements; and for pull requests implementing enhancements topic: performance bugs or enhancements related to performance (improvements or regressions) and removed release notes: not needed PRs introducing changes that are wholly irrelevant to the release notes labels Oct 19, 2017
@fingolfin
Copy link
Member

OK, so it is a performance enhancement. Adjusted labels accordingly.

Copy link
Member

@fingolfin fingolfin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some more nitpicks. But the things I really would like to see addressed are: use ALWAYS_INLINE; correct CONST_BLOCKS_BLIST; avoid using misc as name of a globally visible function.

src/blister.h Outdated
}
/* Now move whole words */
if ((wholeblocks = nbits / BIPEB))
memcpy((void *)toblock, (void *)fromblock,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think you need the typecasts here (and the second one removes the const qualifier of fromblock.

src/blister.h Outdated
*toblock++ = x;
nbits -= BIPEB;
}
/* Finally we may need to fill up a partial block at destination */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is that comment attached to the preceding loop, instead of the following if (to which it refers, doesn't it?)

I.e.: maybe put the empty line before the comment, not after it?

src/vecgf2.c Outdated
SyExit(2);
}
soff = (smin-1) %BIPEB;
doff = (dmin-1) %BIPEB;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Either add spaces after % or remove the ones before... Or just use clang-format?

(If you add spaces, then perhaps also add them around the / in the next two lines?)

@stevelinton
Copy link
Contributor Author

Added test and addressed all comments, I think

Copy link
Member

@fingolfin fingolfin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All my original remarks are addressed, and in principle, we could merge this now.

However, I have two more nitpicks, for which I'd appreciate if they could be addressed. That said, if people are in a rush to merge this, go ahead... :-)

src/blister.h Outdated
fromblock += frombit / BIPEB;
frombit %= BIPEB;
toblock += tobit / BIPEB;
tobit %= BIPEB;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function is called from two places, and both already normalize. Is the optimizer clever enough to get rid of the second, redundant normalization?

Otherwise, I'd either remove the normalization in both calling places, or (the approach I personally favor slightly) replace the four lines above by

GAP_ASSERT(frombit < BIPEB);
GAP_ASSERT(tobit < BIPEB);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fine. I put it in because it made it easier to write my C level tests, but you're right it's not needed in GAP.

src/blister.h Outdated
** `CopyBits' copies <numbits> bits (numbering bits within a UInt
** from the least significant to the most significant) starting with
** bit number <from-starting-bit> of UInt *<fromblock> to a destination
** starting at bit <to-starting-bit> of *<toblock>.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are the two blocks assumed to be non-overlapping? I think it would be a good idea to document this explicitly.

@markuspf markuspf merged commit 144f39c into gap-system:master Oct 27, 2017
@olexandr-konovalov olexandr-konovalov added the release notes: added PRs introducing changes that have since been mentioned in the release notes label Jan 22, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: enhancement Label for issues suggesting enhancements; and for pull requests implementing enhancements release notes: added PRs introducing changes that have since been mentioned in the release notes topic: performance bugs or enhancements related to performance (improvements or regressions)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants