-
Notifications
You must be signed in to change notification settings - Fork 160
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
Add C++ support to kernel; use it to reduce code duplication in permutat.c, objfgelm.c and others #2667
Conversation
return (const T *)(CONST_ADDR_OBJ(perm) + 1); | ||
} | ||
|
||
template<typename TL, typename TR> struct ResultType { typedef UInt4 type; }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very low-level comment, might want to give this another name before merging because I imagine we'll have other similar types. However, the same thing can be used for perms, trans and pperms.. not sure of a good name.
{ | ||
return sizeof(Obj) + deg * sizeof(T); | ||
} | ||
|
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
Actually, another major caveat I forgot about is that in HPC-GAP mode, we still are using |
Looks nice. I like the idea. 👍 |
This PR looks really nice, and I really like the way it it cleans up the code. Two opinions here:
|
I like the simplification of permutat.c a lot, and I'd be happy to see use of C++ templates of this level of sophistication. Essentially it's just a better C pre-processor. I'd want to move very slowly with things like the C++ runtime or use of the STL for two reasons:
|
I completely agree with the previous comment by @stevelinton. |
With respect to the content: Wouldn't it be easy and sensible to introduce a type |
@frankluebeck Adding a And I acknowledge the reservations about adding too much C++. While I personally am completely comfortable with using C++, I agree we should be careful about using it too much. Thus any PR that would add more C++ usage should be carefully reviewed for that (and I personally think we should strive to make sure that people with concerns about C++ usage, like Frank and Steve, get a chance to comment on whether they are comfortable with it). That said, there are a few things beyond basic templates which I think we could benefit from; but let's discuss those if and once we get there (and then ideally again based on a concrete PR to showcase what is intended). For now, the HPC-GAP problem with |
0c15969
to
008e1b7
Compare
The main part is that UInt1/2/4 were replaced by UIntN (#define'ed to the suitable real value). Also a few 8/16/32 occurrences were replaced by `8*sizeof(UIntN)`, and a few comments mentioning the bit count were removed.
Also add tests to verify this works as intended.
I'm going to go for the merge once tests pass, then investigate the cygwin issue if it isn't cleared up. |
@ChrisJefferson tests passed now |
The windows issue described above is not happening in the master branch. I suspect there is a bug somewhere in paths in scripts from Jenkins jobs to build and tests PRs on Windows. However, there are new Windows issues which seem to be cause by this PR. I've reported them in #2890. Finally, when this PR was tested on Windows, the directory for the binaries had name |
This is an incomplete proof of concept (POC) to show how using C++ code could be used to simplify some kernel code. For now, my main goal is to reduce code duplication, which is why I started with
permutat.c
. This modest PR already removes about a thousand lines of code.It was mentioned that not everybody who works (or wants to work) on the kernel is fluent in C++. Thus we should be careful about which features we use, and avoid overly complicated or intransparent / "magical" code, and add sufficient comments. Consider this PR as a first opportunity to get an idea of what the result of such a conversion to C++ code might look like, and please point out anything you don't understand, dislike (or like), etc.
Some things which still need to be done (assuming this PR gets a green light):
configure
, and abort (with a helpful message) if none is found.gac
to compile.cc
filesOther places that could benefit from a similar use of C++ templates:
permutat.cc
could actually be treated, the remaining ones each simply require a bit more work than the ones I already converted, so I didn't want to spend that effort for a proof of conceptpperm.c
: very similar topermutat.c
trans.c
: very similar topermutat.c
objccoll-impl.h
andobjscoll-impl.h
implement "poor man's template's" by abusing the C preprocessor, and are included multiple times byobjscoll.c
for thatsortbase.h
is included multiple times bylistfunc.c
objfgelm.c
: contains 8, 16 and 32 bit variants of many functions, e.g.:Func8Bits_ExponentSums3
,Func16Bits_ExponentSums3
,Func32Bits_ExponentSums3
objpcgel.c
: contains 8, 16 and 32 bit variants of many functions