New user self-registration is currently disabled. Please email eigen-core-team @ if you need an account.
Bug 873 - GCC error: 'asm' was not declared in this scope
GCC error: 'asm' was not declared in this scope
Product: Eigen
Classification: Unclassified
Component: Core - general
All All
: Low Compilation Problem
Assigned To: Nobody
Depends on:
  Show dependency treegraph
Reported: 2014-09-05 10:10 UTC by meisenmann.lba
Modified: 2014-09-06 13:00 UTC (History)
5 users (show)


Description meisenmann.lba 2014-09-05 10:10:54 UTC

Some of our (customer-) projects are compiled with GCC and the option ‘-fno-asm’. In this case, the compilation will fail with an error like:

[…]/Eigen/src/Core/products/GeneralBlockPanelKernel.h: (Ln: 642) error :'asm' was not declared in this scope

Whith a newer GCC-version like 4.8.3, the error-message will show additionaly:
test.cpp:19:2: note: in expansion of macro 'EIGEN_ASM_COMMENT'

The GCC-documentation implies, that ‘-fno-asm’ may not affect the standard-keywords asm (and inline); but that’s no true (for the keyword asm).

Similar to the header-file "Eigen\src\Core\util\Memory.h", which does already use the alternative keywords, following patch would solve this (small) issue:

---- Begin of (unified diff) patch ----
Index: Eigen/src/Core/arch/NEON/PacketMath.h
--- Eigen/src/Core/arch/NEON/PacketMath.h	(revision 222)
+++ Eigen/src/Core/arch/NEON/PacketMath.h	(working copy)
@@ -50,7 +50,7 @@
 #ifndef __pld
-#define __pld(x) asm volatile ( "   pld [%[addr]]\n" :: [addr] "r" (x) : "cc" );
+#define __pld(x) __asm__ __volatile__ ( " pld [%[addr]]\n" :: [addr] "r" (x) : "cc" );
 template<> struct packet_traits<float>  : default_packet_traits
Index: Eigen/src/Core/util/Macros.h
--- Eigen/src/Core/util/Macros.h	(revision 222)
+++ Eigen/src/Core/util/Macros.h	(working copy)
@@ -247,7 +247,7 @@
 #if !defined(EIGEN_ASM_COMMENT)
   #if (defined __GNUC__) && ( defined(__i386__) || defined(__x86_64__) )
-    #define EIGEN_ASM_COMMENT(X)  asm("#" X)
+    #define EIGEN_ASM_COMMENT(X)  __asm__("#" X)
     #define EIGEN_ASM_COMMENT(X)
---- End of (unified diff) patch ----

Ie., to use the alternative GCC-keyword(s), which are not affected by this GCC-option.

Best regards from Salzburg,
Comment 1 Jitse Niesen 2014-09-06 13:00:52 UTC
Thanks for the clear report.

This looks like a bug in GCC (or the documentation) that should probably be reported to them.

Having said that, given that we use __asm__ in Memory.h it seems sensible to be consistent and use __asm__ instead of asm everywhere. I was a bit worried about other non-GCC compilers, but it looks ICC is happy with __asm__ [1], the code in Eigen implies that clang is too, while Visual Studio interestingly seems to ignore any asm blocks and wants __asm instead [2]. 

Changesets: (dev branch) (3.2 branch)


Note You need to log in before you can comment on or make changes to this bug.