-
December 31st, 2020, 06:22 AM
#1
__asm equivalent for 64-bit programming
I'm trying to update a program (previously built only as 32-bit) so that it'll build as 64-bit in VS2019. One of the functions uses this small section of assembly language - which is somehow connected to finding out some stuff about the FPU:-
Code:
char *buf = *fxbuf;
__asm {
mov eax, buf
fxsave [eax]
};
But AFAICT __asm is only valid for 32-bit compilation. Is there something equivalent for 64-bit ?
"A problem well stated is a problem half solved.” - Charles F. Kettering
-
December 31st, 2020, 09:09 AM
#2
Re: __asm equivalent for 64-bit programming
AFAIK, you can't use in-line assembler code with a 64bit compile. You'll need to add an assembler language file to the existing project.
For a starter, see https://docs.microsoft.com/en-us/cpp...?view=msvc-160
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
December 31st, 2020, 09:48 AM
#3
Re: __asm equivalent for 64-bit programming
Why not use an exposed api to "find out something about the fpu"? Then asm is not required.
-
December 31st, 2020, 12:07 PM
#4
Re: __asm equivalent for 64-bit programming
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
January 2nd, 2021, 04:25 AM
#5
Re: __asm equivalent for 64-bit programming
Some good reading material there - many thanks guys. I guess I might have missed something but I'm surprised VC++ has nothing equivalent to an __asm64 instruction
And it got me wondering if this is a Microsoft specific restriction or if it affects other compilers for Windows/x86/x64. For example there's a compiler called minGW (which can also handle inline assembler) but I've no idea if it has the same restriction.
"A problem well stated is a problem half solved.” - Charles F. Kettering
-
January 2nd, 2021, 08:43 AM
#6
Re: __asm equivalent for 64-bit programming
The idea is, at least on Windows, is for user level apps should not be directly accessing the hardware, but should access hardware through a device driver.
Microsoft has been steadily locking this down on the OS level starting from Win 2000. It wouldn't surprise me for them to no longer support asm calls at the compiler level.
-
January 4th, 2021, 05:39 AM
#7
Re: __asm equivalent for 64-bit programming
Thanks for the interesting content on 64-bit programming.
-
January 5th, 2021, 11:44 AM
#8
Re: __asm equivalent for 64-bit programming
I've just been reading about X64 intrinsics which are apparently intended to help with the lack of support for inline assembly. This was the original code - does any know if there's an intrinsic function available which would do the same thing??
Code:
char *buf = *fxbuf;
__asm {
mov eax, buf
fxsave [eax]
};
"A problem well stated is a problem half solved.” - Charles F. Kettering
-
January 5th, 2021, 01:02 PM
#9
Re: __asm equivalent for 64-bit programming
Probably this one https://software.intel.com/sites/lan.../#text=_fxsave which was suggested in my post #4.
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
January 5th, 2021, 01:47 PM
#10
Re: __asm equivalent for 64-bit programming
Apologies 2kaud - I hadn't yet got my head around it back then!!
"A problem well stated is a problem half solved.” - Charles F. Kettering
-
January 6th, 2021, 04:57 AM
#11
Re: __asm equivalent for 64-bit programming
Dumb question coming up...
https://software.intel.com/sites/lan.../#text=_fxsave
Can you see what the difference is between _fxsave() and _fxsave64() ? Is _fxsave() intended to accept a 32-bit memory pointer maybe??
[Edit...] I just came across this description (for the original asm code):- https://www.felixcloutier.com/x86/fxsave - which states:-
Additionally, there are two different layouts of the FXSAVE map in 64-bit mode, corresponding to FXSAVE64 (which requires REX.W=1) and FXSAVE (REX.W=0).
Any idea what that all means ???
Last edited by John E; January 6th, 2021 at 06:32 AM.
"A problem well stated is a problem half solved.” - Charles F. Kettering
-
January 6th, 2021, 06:45 AM
#12
Re: __asm equivalent for 64-bit programming
Originally, how is buf/fxbuf used in the code?
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
January 6th, 2021, 07:17 AM
#13
Re: __asm equivalent for 64-bit programming
Here's how it looks:-
Code:
char** fxbuf = 0;
#ifndef HAVE_POSIX_MEMALIGN
fxbuf = (char **) _aligned_malloc (sizeof (char *), 16);
assert (fxbuf);
*fxbuf = (char *) _aligned_malloc (512, 16);
assert (*fxbuf);
#else
(void) posix_memalign ((void **) &fxbuf, 16, sizeof (char *));
assert (fxbuf);
(void) posix_memalign ((void **) fxbuf, 16, 512);
assert (*fxbuf);
#endif
memset (*fxbuf, 0, 512);
char* buf = *fxbuf;
__asm {
mov eax, buf
fxsave [eax]
};
uint32_t mxcsr_mask = *((uint32_t*) &((*fxbuf)[28]));
"A problem well stated is a problem half solved.” - Charles F. Kettering
-
January 6th, 2021, 08:29 AM
#14
Re: __asm equivalent for 64-bit programming
OK - so mxcsr_mask is byte 28, which is byte 3 of the MXCSR register (lower 8 bits of the 4 byte MXCSR).
See https://software.intel.com/content/w...or-states.html
The documentation for MXCSR is on page 250 of https://software.intel.com/content/w...-3d-and-4.html
It looks like mxcsr_mask is used to determine if any errors have occurred (ie divide by zero, underflow, overflow etc).
How is mxcsr_mask used??
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
January 6th, 2021, 09:56 AM
#15
Re: __asm equivalent for 64-bit programming
Originally Posted by 2kaud
How is mxcsr_mask used??
It looks like it's for determining whether floating point denormals are enabled. Here's what comes next:-
Code:
uint32_t mxcsr_mask = *((uint32_t*) &((*fxbuf)[28]));
/* if the mask is zero, set its default value (from intel specs) */
if (mxcsr_mask == 0) {
mxcsr_mask = 0xffbf;
}
if (mxcsr_mask & (1<<6)) {
_flags = Flags (_flags | HasDenormalsAreZero);
}
"A problem well stated is a problem half solved.” - Charles F. Kettering
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|