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

Assorted minor issues #1

Open
nemequ opened this issue Aug 17, 2019 · 2 comments
Open

Assorted minor issues #1

nemequ opened this issue Aug 17, 2019 · 2 comments

Comments

@nemequ
Copy link

nemequ commented Aug 17, 2019

First, awesome project. I already see some ideas I want to try out in my own code.

Just taking a quick look through the code I noticed some things I would have done differently. Not bugs, but a few suggestions… feel free to ignore this if you want.

  • I have more robust versions of several macros you use in Hedley which might be worth a look:
  • For WARN_UNUSED, I think you forgot the STORM_ prefix.
  • For __has_attribute and __has_builtin, please define STORM_HAS_* or something instead. Using __has_ can cause problems for other people.
  • It looks like you know this already, but CLANG_PREREQ is dangerous. https://sourceforge.net/p/predef/wiki/Compilers/#clang has an overview of the problem. I see you're checking __apple_build_version__ sometimes, too, but Apple isn't the only compiler that defines __clang__ and friends. For AVX2/AVX512, maybe you could use __has_builtin on the intrinsic(s) you're worried about?
  • Maybe a macro for __attribute__ ((target ("sse4.2"))) instead of checking for _MSC_VER every time?
  • Is there a reason to use uint64_t instead of size_t for buffer lengths? It's not really a problem, size_t is just the more idiomatic choice…
  • It would be nice to see conformant array parameters, at least in the public API. It would require putting the size before the data parameter, but I think it's a worthwhile change. Hedley has a macro if you want to copy it: HEDLEY_ARRAY_PARAM, or you could just unconditionally define it to nothing and you only get the documentation benefits. TBH, compilers and static analyzers aren't (yet?) great about taking advantage anyways ☹
  • GCC supports __builtin_popcount back to 3.4. Also, armcc 4.1+ and XL C/C++ 13.1.5+. (I didn't check armcc or xlc, either…)

For the Hedley macros, if you don't want to copy over the logic (which can be a huge pain; see the introduction in the Hedley User Guide…), you could make it an optional dependency:

#if defined(HEDLEY_RESTRICT)
#  define STORM_RESTRICT HEDLEY_RESTRICT
#elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
#  define STORM_RESTRICT   restrict
#else
/* note : it might be useful to define __restrict or STORM_RESTRICT for some C++ compilers */
#  define STORM_RESTRICT   /* disable */
#endif

I do that a lot in portable-snippets and I think it's a good compromise. People who want to can include hedley.h, everyone else just gets simpler fallbacks.

@mklarqvist
Copy link
Owner

Hello @nemequ. Thanks for this! I'll address most of this.

It looks like you know this already, but CLANG_PREREQ is dangerous. https://sourceforge.net/p/predef/wiki/Compilers/#clang has an overview of the problem. I see you're checking apple_build_version sometimes, too, but Apple isn't the only compiler that defines clang and friends. For AVX2/AVX512, maybe you could use __has_builtin on the intrinsic(s) you're worried about?

This is a good idea. I'll try it out.

@nemequ
Copy link
Author

nemequ commented Aug 17, 2019

One more tiny thing: lines 686-689 should probably use UINT64_C, or at least ull instead of ll.

@mklarqvist mklarqvist mentioned this issue Aug 18, 2019
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

2 participants