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

Modifying the way has_include is used #519

Merged
merged 8 commits into from
Feb 23, 2022
Merged

Modifying the way has_include is used #519

merged 8 commits into from
Feb 23, 2022

Conversation

Frosne
Copy link
Contributor

@Frosne Frosne commented Jan 27, 2022

Summary

The PR modifies the has_include ('config.h') like in order to support the compilers where 'has_include' itself is not defined.

Motivation

We would like to support gcc4.4 and gcc4.8 compilers that fail because of the has_include.

This PR…
-->

  • Modifies the has_include to have a wrapper around it checking that has_include is supported

Copy link
Contributor

@msprotz msprotz left a comment

Choose a reason for hiding this comment

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

Thanks Natalia, this looks good. I have two questions.

Can you please explain a little bit more about intrin.h? Which toolchains is it needed on? What functions does it provide that were not in scope already? We've been successfully building on Windows via GitHub actions so it'd be great to document why we need another inclusion, when CI says we're fine.

Second request: the other obvious option is to always require config.h, and to always require that people who integrate the library create a (possibly-empty) config.h. It's less flexible, but has less macro-checking. Can you say a little more about why you prefer to define features via compiler flags?

None of these are issues -- it's just that we have been going back and forth on these things a lot, so if there's a good reason to pick one solution over the other, I want to document for the future. Thanks!

Copy link
Member

@franziskuskiefer franziskuskiefer left a comment

Choose a reason for hiding this comment

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

Thanks. Two nits

@@ -18,11 +18,13 @@
#define TARGET_ARCHITECTURE_ID_SYSTEMZ 5
#define TARGET_ARCHITECTURE_ID_POWERPC64 6

#if defined(__has_include)
#if __has_include("config.h")
#include "config.h"
#else
#define TARGET_ARCHITECTURE TARGET_ARCHITECTURE_ID_UNKNOWN
Copy link
Member

Choose a reason for hiding this comment

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

So TARGET_ARCHITECTURE isn't defined at all when __has_include is not available? We might want this defined in any case where we don't have the config.h.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm wondering if we should just get rid of TARGET_ARCHITECTURE. It doesn't seem to provide much added value and brings us further away from our goal of thinking exclusively in terms of features (rather than in terms of specific targets)

Copy link
Member

Choose a reason for hiding this comment

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

I wouldn't mind getting rid of it. But this PR changes when and how it gets added. I think we should keep the logic here and then think about removing it.

Copy link
Contributor

Choose a reason for hiding this comment

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

agreed that this should be a separate PR... it's just that we don't use that thing anywhere else (as far as I can tell) except for hacl_vec128_not_avx () and we could refactor that code to not depend on it...

@@ -25,6 +27,10 @@
#include <tmmintrin.h>
#include <smmintrin.h>

#if defined(_MSC_VER)
#include <intrin.h>
Copy link
Member

Choose a reason for hiding this comment

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

As @msprotz mentioned, some information on this would be good. Why is this needed now and what wasn't working before?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think I just remembered: intrin.h breaks the build when using cygwin-packaged, native mingw compilers. We should have CI for that toolchain, too.

Copy link
Contributor Author

@Frosne Frosne Feb 2, 2022

Choose a reason for hiding this comment

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

Would it then be better to have smth like:


#ifdef _MSC_VER
#if _MSC_VER > version
#include <intrin.h> 
#endif
#endif

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Or will mingw be already filtered out by the #ifdef _MSC_VER clause?

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure -- I think you would need to check. Basically, I'm fine with any solution, as long as it doesn't break the mingw-based setup that several of us currently rely on.

@tahina-pro do we still have windows CI anywhere in our system that could check Natalia's patch? Or alternatively, could you tell us quickly if #include <intrin.h> works with x86_64-mingw64-gcc?

Copy link
Contributor

@tahina-pro tahina-pro Feb 2, 2022

Choose a reason for hiding this comment

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

Right now we have no working Windows CI on our side. We only have a nightly ./everest make test on Windows, which has been failing for months now...
Re. intrin.h with x86_64-mingw64-gcc, I managed to compile a dummy C file containing just that include, but I guess that won't tell us much. I don't fully understand here, but I think the header in question might be https://sourceforge.net/p/mingw-w64/mingw-w64/ci/master/tree/mingw-w64-headers/crt/intrin.h and the
discussion at https://mingw-w64-public.narkive.com/9uy03D8V/what-is-the-purpose-of-intrin-h might be relevant

Copy link
Contributor

Choose a reason for hiding this comment

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

thanks Tahina... so intrin.h appears to define MSVC-like macros for mingw... at this point I'm thoroughly confused why we need that header

maybe to re-center the discussion, @Frosne, you can provide us with the compilation error that this include fixes? thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It looks like it's indeed required by mingw

Copy link
Member

Choose a reason for hiding this comment

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

I would suggest pulling this change out of this PR and handling it separately as it appears to need clarification. The __has_include is uncontroversial and could go in.

Looking at the official documentation for MSVC intrin.h should be the only one needed. The others (tmmintrin.h and smmintrin) appear to be outdated.

MinGW supports intrin.h as well such that it should work for both environment.
We will have a Windows CI in a couple weeks to test this on and I might be able to tell you more next week. But I have to set up a Windows environment first.
If someone else has a Windows setup, they could give this a go with intrin.h only.

@Frosne
Copy link
Contributor Author

Frosne commented Feb 2, 2022

Thanks Natalia, this looks good. I have two questions.

Can you please explain a little bit more about intrin.h? Which toolchains is it needed on? What functions does it provide that were not in scope already? We've been successfully building on Windows via GitHub actions so it'd be great to document why we need another inclusion, when CI says we're fine.

Small helpful link: https://dev.to/yumetodo/list-of-mscver-and-mscfullver-8nd.

It seems that our windows build requires it. Otherwise, our build returns the following exception: _mm_cmpgt_epi64': intrinsic function not declared. The problem gets solves once we add intrin.h file.

We use 191125547 MSC_VER(sion), HACL* CI runs using 192930139 Version.

@franziskuskiefer
Copy link
Member

It seems that our windows build requires it. Otherwise, our build returns the following exception: _mm_cmpgt_epi64': intrinsic function not declared. The problem gets solves once we add intrin.h file.

Another issue here is that _mm_cmpgt_epi64 is SSE4.2 but is used when HACL_CAN_COMPILE_VEC128 is set. But HACL_CAN_COMPILE_VEC128 doesn't actually check for SSE4.2 but only for SSE2 and SSE3

@Frosne
Copy link
Contributor Author

Frosne commented Feb 14, 2022

Btw, Lib_Memzero0.h header includes #include "libintvector.h" without using it. What do you think about removing it?

@msprotz
Copy link
Contributor

msprotz commented Feb 14, 2022

So this PR is blocked on @franziskuskiefer and I's lack of understanding of why intrin.h is needed. To move forward, I suggest:

  • removing the intrin.h change from this PR so that we can merge it
  • opening a separate PR for intrin.h with a precise description of the build error (including error message), along with a description of the toolchain that needs this.

Regarding libintvector.h being over-included: yes, it would be good to fix. It's relatively easy to fix, see https://github.com/project-everest/hacl-star/blob/master/Makefile#L641-L645 -- libintvector.h is included indiscriminately, rather, it should be included once for each file that needs it like is the case for lib_intrinsics.h just below.

Thanks!

@Frosne Frosne changed the title Modifying the way has_include is used and adding an intrinsic file Modifying the way has_include is used Feb 22, 2022
Copy link
Contributor

@msprotz msprotz left a comment

Choose a reason for hiding this comment

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

All looks good to me, thanks!

@msprotz
Copy link
Contributor

msprotz commented Feb 22, 2022

@franziskuskiefer this PR now has the intrin.h bit removed and only concerns __has_include

Copy link
Member

@franziskuskiefer franziskuskiefer left a comment

Choose a reason for hiding this comment

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

Thanks!

@beurdouche beurdouche merged commit bdcfbe6 into master Feb 23, 2022
@karthikbhargavan karthikbhargavan deleted the anilam_config branch September 6, 2022 14:46
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

Successfully merging this pull request may close these issues.

None yet

6 participants