1

I'm writing a program in gcc that has asm language for performance-critical sections, and I want to ensure at run-time the program is running on the correct architecture. In particular, I need to differentiate ia64 (Itanium) and x86_64 on Linux.

Do I just read /proc/cpuinfo? Seems clunky, but I can't find an appropriate kernel call.

Fixee
  • 1,581
  • 2
  • 15
  • 25

3 Answers3

2

/proc/cpuinfo is the standard interface to CPU information on linux.

It is the best option, as it is intended to be architecture-independent.

Adam Eberlin
  • 14,005
  • 5
  • 37
  • 49
  • 1
    See http://stackoverflow.com/questions/9629850/how-to-get-cpu-info-in-c-on-linux-such-as-number-of-cores for sample code. – bleater Apr 08 '14 at 01:58
2

IA64 and x86_64 are entirely different architectures. A program built for one will simply not run on the other, so your question doesn't make sense (in fact, incompatibility with the x86 instruction set is one of the reasons for IA64's lackluster market penetration, because IA64-based systems couldn't run the wide array of existing, legacy 32-bit x86-based applicaitons).

The best you could do is compile two different versions of the program, and then use a wrapper script to select the appropriate binary when the user invokes the program.

Eric Melski
  • 16,432
  • 3
  • 38
  • 52
2

The answer is already posted, but I'll add this:

If the machine is x86 or x64, you can get more detailed information through the cpuid instruction.

http://en.wikipedia.org/wiki/CPUID

Mysticial
  • 464,885
  • 45
  • 335
  • 332
  • Thanks... this was exactly what I needed since I wanted to detect if SSE/MMX was available. Looking at other responses, looks like this is relevant only on x86_64 versus ia32. – Fixee Sep 19 '11 at 23:04