Availability of _rdrand_step intrinsics under Microsoft compilers? - c

According to Microsoft's x64 (amd64) Intrinsics List, Microsoft offers an intrinsic for RDRAND:
_rdrand16_step
_rdrand32_step
_rdrand64_step
However, the page does not discuss detecting the availability of the intrinsic. There is a footnote with [2], but it says its only available for Intel CPUs.
I have two questions. First, how can I detect the availability of the intrinsics. That is, what preprocessor macro should I use to guard the call to say _rdrand64_step.
Second, how can I access RDRAND under AMD CPUs? According to the AMD manual, AMD offers it too.
(More humorously, Microsoft titles the page amd64 Intrinsic List. Why do they call it AMD64 Intrinsic List when they don't include AMD???)
For AMD and the RDRAND instruction, reference AMD64 Architecture Programmer’s Manual Volume 3: General-Purpose and System Instructions, page 278.

First, how can I detect the availability of the intrinsics. That is, what preprocessor macro should I use to guard the call to say _rdrand64_step.
Here are the compiler versions needed for RDRAND intrinsics:
Microsoft added RDRAND in August 2012, VS2012. Test for _MSC_VER >= 1700.
GCC added RDRAND in December 2010, GCC 4.6.
Clang added RDRAND in July 2012, Clang 3.2.
Intel added RDRAND in September 2011, ICC 12.1.
Second, how can I access RDRAND under AMD CPUs. According to the AMD manual, AMD offers it too.
AMD CPUs that provide the RDRAND instruction appear to be forth coming. That is, there are currently no CPUs shipping with the feature.
The Microsoft docs clearly state the intrinsics are for Intel CPUs only. To ensure AMD support given the anti-competitive history between Intel and AMD, the ASM should be crafted by hand and assembled with MASM/ML and MASM64/ML64.

you can check the version of MS compiler using:
MSVC++ 14.0 _MSC_VER == 1900 (Visual Studio 2015)
Detailed
I am not sure how to use it with AMD architecture. Will let you know if I get some solution
You can get the answer why MS documentation calls it amd64 in this post.

Related

GNU GCC Intel i5 optimization settings?

I have a Microsoft Surface Pro (5th Generation) with the i5 processor and use the GNU GCC Compiler.
Now I want to use optimization settings for this compiler and I don't know what settings are "working" with my processor.
Overview of my system:
Microsoft Surface Pro
Intel Core i5-7300U CPU # 2,60 GHz
Microsoft Windows 10 Pro | 64-bit | Version 10.0.18363
IDE: Code::Blocks 20.03
Does anyone has an a similar system? Thanks in advance.
Kind Regards
randomcoder
You can always use the flag -march=native, which tells the compiler to detect the CPU of the computer that's being used to compile, and optimize the code for that type of CPU. This is ideal when you are compiling on the same machine you will be running the code on. Note that the resulting executable will not necessarily work on other computers with different CPUs.
Of course, you also have to use one of the -O options, typically -O2, to get optimizations at all. There are many other specific optimization options, but whether they are helpful will depend on what your program actually does.

ARMv8 backward compatibility with ARMv7 (Snapdragon 820 vs Cortex-A15)

I see that ARMv8 is merely an extension of ARMv7 architecture and all code compiled on ARMv7 should run on ARMv8. I am interested in the backward compatibility of ARMv8 to ARMv7. Will code that was compiled on ARMv8 run on ARMv7?
I have a particular exact case of interest: I would like to run the comma.ai's Openpilot visiond binary which was compiled for the OnePlus 3 smartphone (Qualcomm MSM8996 Snapdragon 820 CPU) on the Nvidia Jetson TK1 (NVIDIA Cortex-A15 CPU). Will the visiond run on Jetson?
EDIT: There may be more in question than CPU compatibility since visiond probably heavily uses GPU on that phone. Will probably depend whether they use some standard parallelization ways (OpenCL, NEON etc.) or have some custom code for Snapdragons GPU. Even with OpenCL the chance of compatibility is probably quite low on different HW.
I believe that aarch32 userland is fully or very highly backwards compatible with ARMv7, i.e. userland programs compiled for ARMv7 should just work in AArch32, but I couldn't find a precise quote in the ARM manual.
aarch32 does have new instructions added over ARMv7 however, most of them seem to be functionality that ARMv8 added and the designers decided to expose on aarch32. Therefore, aarch32 is not forward compatible with ARMv7, i.e., programs compiled for aarch32 might not run on ARMv7.
I'm not sure about system land. See also: Does ARMv8 AArch32 mode has backward compatible with armv4 , armv5 or armv6?

ds-5 ultimate evaluation version supports 64bit neon ( arm_v8 neon)

I have installed the current "DS-5 Ultimate 64-bit evaluation " version but am not able to build for ARMv8 64-bit neon.
In armclang am not able to find the cpu list it shows only option "Target: aarch64-arm-none-eabi".
please help me to solve the below issues
Does this version support ARMv8 neon?
How to find available cpu list (as in armcc --cpu list) or equivalent armclang options.
aarch64 is ARMv8. And NEON is mandatory in ARMv8, so it's included.

Xeon Phi: icc c++11 compatibility?

I am considering getting a Xeon Phi card. My code is using many features from c++11 (with gcc 4.7 or clang 3.2) and I will run it natively on the Xeon Phi card.
What is the version of icc provided with the card, targeting Xeon Phi? I found icc c++11 compatibility list and it seems that I need version 14. Do I get it with the card?
Related question: is there gcc/clang targeting Xeon Phi in development? I could not google anything out.
Xeon Phi works with the latest shipping versions of the icc, which is version 13 at this time.
There is also a Xeon Phi targeted version of gcc which ships with the card.

Do Intel and AMD processor have the same assembler?

The C language was used to write UNIX to achieve portability -- the same C language program compiled using different compilers produces different machine instructions. How come Windows OS is able to run on both Intel and AMD processors?
AMD and Intel processors(*) have a large set of instructions in common, so it is possible for a compiler or assembler to write binary code which runs "the same" on both.
However, different processor families even from one manufacturer have their own sets of instructions, usually referred to as "extensions" or whatever. Ignoring the x87 co-processor, the first time I remember this being a marketing point was when everything suddenly went "with MMX(TM) technology". Binary code expected to run on any processor either needs to avoid extensions, or to detect the CPU type before using them.
Intel's Itanium 64-bit architecture was completely different from AMD's x86-64 architecture, so for a while their 64bit offerings were non-compatible (and Itanium was nothing like x86, whereas x86-64 extended the instruction set by adding 64bit instructions). Intel blinked first and adopted x86-64, although there are still a few differences: http://en.wikipedia.org/wiki/X86-64#Differences_between_AMD64_and_Intel_64
Windows probably uses the common x86 or x86-64 instruction set for almost all code. I wouldn't be surprised if various drivers and codecs are shipped in multiple versions, and the correct one selected once the CPU has been interrogated.
(*) Actually, Intel make or have made various kinds of processors, including ARM (Intel's ARM processors were called XScale, but I think they've sold that business). And AMD make other processors too. But we know which Intel/AMD processors you mean :-)
AMD are Intel compatible, otherwise they would never have gained a foothold in the market place.
They are effectively clone compatible.
As you suspect, the main stream Intel and AMD processors have the same instruction set.
Windows does not run on ARM or PowerPC chips, for example, because it is somewhat dependant on the underlying instruction set.
However, most of Windows is written in C++ (as far as I know), which should be portable to other architectures. Windows NT even ran on PowerPC and other architectures.
Intel's 80x86 CPUs and AMD's 80x86 are "mostly the same sort of", but some things are completely different (e.g. virtual machine extensions - SVM vs. VT-x) and some things (extensions) may or may not be supported. However, some things are different on different CPUs from the same manufacturer too (e.g. some Intel chips support AVX2 and some don't).
There are multiple ways to deal with the differences:
only use the common subset so the same code runs on all 80x86 CPUs (e.g. treat it like an 8086 chip).
use a subset of features that is common to a range of CPUs so the same code runs on all 80x86 CPUs in that range. This is very common (e.g. "this software requires an 80x86 CPU (and OS) that supports 64-bit extensions").
use install-time tests. For example, there might be 4 different copies of software (compiled for 4 different ranges of CPUs) where the installer decides which copy makes sense for the computer the software is being installed on.
use run-time tests. For example, code can use the CPUID instruction to do if( AVX2_is_supported() ) { set_function_pointers_so_AVX2_is_used(); } else {set_function_pointers_so_AVX2_is_not_used(); }. Note: Some compilers (Intel's ICC) can automatically generate code that does run-time tests.
These aren't mutually exclusive options. For example, the installer might decide to install a 64-bit version (and not a 32-bit version), and then the 64-bit version might check which features are supported at run-time and have different code to use different features.
Also note that different parts of an OS can be treated separately. For example, an OS could have 6 different boot loaders, 4 different "HALs", 4 different kernels, and 3 different "kernel modules" to support virtualisation; where some of these things might do run-time tests and some might not.
Do Intel and AMD processor have the same assembler?
Almost all assemblers for 80x86 support almost all extensions (from all CPU manufacturers - e.g. Intel, AMD, VIA, Cyrix, SiS, ...). In general; it's up to the programmer (or compiler) to make sure they only use things that they know exist. Some assemblers provide features to make this easier (e.g. NASM provides a CPU ... directive so that the programmer can tell the assembler to generate errors if it sees instructions that aren't supported on the specified CPU).
AMD and Intel use the same instruction set.
When you install windows on an AMD processor or an Intel processor, it doesn't "compile" code on the machine.
I remember many people being confused on this subject back during college. They believe that a "setup" means that it is compiling code on your machine. It isn't. Most if not all Windows application outside of the free realms, are given to you by binary.
As for portability, that isn't neccessarily 100% true. While C is highly portable, in many cases writing for a specific OS or system will result in the code only being able to compile/executed on that box. For example, certain Unix machines handle files and directories differently so it might not be 100% portable.
Do Intel and AMD processor have the same assembler?
An assembler assembles a program to be run on a processor, so your question is flawed. Processors DO NOT use assemblers.
If you mean can Intel and AMD processor run the same assembler? Then the answer is YES!!!
All an assemblers are, is a program that assembles other programs from structured text files. Visual Basic is an example of an assembler.

Resources