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

Use _mm_getcsr intrinsics on MSVC #1008

Closed
wants to merge 1 commit into from
Closed

Conversation

isuruf
Copy link
Contributor

@isuruf isuruf commented Feb 20, 2020

No description provided.

new_mxcsr |= 0x8000;
new_mxcsr |= 0x0040;
} else {
new_mxcsr &= 0x8000;
Copy link
Collaborator

Choose a reason for hiding this comment

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

These are also broken, for the same reason as the ones above.

@@ -30,13 +33,25 @@ void HostFloatingPointEnvironment::SetUpHostFloatingPointEnvironment(
}
#if __x86_64__
hasSubnormalFlushingHardwareControl_ = true;
#ifdef _MSC_VER
int new_mxcsr = _mm_getcsr();
Copy link
Collaborator

Choose a reason for hiding this comment

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

First, why is this necessary? Is fesetenv() broken on Windows?

Second, please conform to the surrounding style; specifically, we use modern braced initialization.

Third, you omitted the bitwise complementation of the right-hand sides of the &= forms, so they're not going to do what you think they're going to do.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

First, why is this necessary?

Because the fenv_t structure in windows doesn't have a __mxcsr. It looks like below,

    typedef struct fenv_t
    {
        unsigned long _Fe_ctl, _Fe_stat;
    } fenv_t;

Is fesetenv() broken on Windows?

No. It works fine.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Why not #define __mxcsr _Fe_ctl for Windows and leave the rest of the code alone?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I checked and that doesn't work.

Copy link
Collaborator

Choose a reason for hiding this comment

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

How did it fail?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here's the program that I ran,

#include <fenv.h>
#include <xmmintrin.h>
#include <stdio.h>

#ifdef _WIN32
#define __mxcsr _Fe_ctl
#endif
int main() {
  fenv_t f;
  fegetenv(&f);
  unsigned int orig_mxcsr = _mm_getcsr();
  printf("original value from _mm_getcsr %x\n", orig_mxcsr);
  printf("original value from fgetenv %lx\n", f.__mxcsr);
  f.__mxcsr |= 0x8040;
  int ret = fesetenv(&f);
  unsigned int new_mxcsr = _mm_getcsr();
  printf("new value from _mm_getcsr %x\n", new_mxcsr);
}

On Linux, this gave me,

$ ./a.out 
original value from _mm_getcsr 1f80
original value from fgetenv 1f80
new value from _mm_getcsr 9fc0

On windows, this gave me,

original value from _mm_getcsr 1f80
original value from fgetenv 3f00003f
new value from _mm_getcsr 1f80

@isuruf
Copy link
Contributor Author

isuruf commented Mar 12, 2020

ping

@isuruf
Copy link
Contributor Author

isuruf commented Apr 2, 2020

ping on this again.

@isuruf
Copy link
Contributor Author

isuruf commented Apr 9, 2020

Superceded by https://reviews.llvm.org/D77815

@isuruf isuruf closed this Apr 9, 2020
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.

2 participants