compilation error for avx512, is it a GCC issue? - c

I am trying to compile the following code with AVX512 intrinsic, but gives me the compile error.
#include <immintrin.h>
static inline __attribute__((always_inline)) void
mov64(uint8_t *dst, const uint8_t *src)
{
__m512i zmm0;
zmm0 = _mm512_load_si512((const void *)src);
_mm512_store_si512((void *)dst, zmm0);
}
The compilation error:
gcc -D_GNU_SOURCE -DINFO_LOG_DEBUG --std=c99 -march=native -O3 -DNDEBUG -m64 -mtune=native -Werror -Wall -Wundef -Wpointer-arith -Wstrict-prototypes -Wnested-externs -fomit-frame-pointer -DTRANSPORT_CONFIG_OPT_HDR='<ci/internal/transport_config_opt_extra.h>' -c src/main.c -o obj/main.o
src/main.c: In function ‘mov64’:
src/main.c:15:9: error: unknown type name ‘__m512i’
__m512i zmm0;
^
src/main.c:17:9: error: implicit declaration of function ‘_mm512_load_si512’ [-Werror=implicit-function-declaration]
zmm0 = _mm512_load_si512((const void *)src);
^
src/main.c:17:9: error: nested extern declaration of ‘_mm512_load_si512’ [-Werror=nested-externs]
src/main.c:18:9: error: implicit declaration of function ‘_mm512_store_si512’ [-Werror=implicit-function-declaration]
_mm512_store_si512((void *)dst, zmm0);
^
src/main.c:18:9: error: nested extern declaration of ‘_mm512_store_si512’ [-Werror=nested-externs]
cc1: all warnings being treated as errors
In addition, if I add -march=native,avx512f or -mavx512f or -march=skylake-avx512, it gives the following error:
src/main.c:1:0: error: bad value (skylake-avx512) for -march= switch
My GCC version is 4.8.5 20150623 and CPU is "Intel(R) Xeon(R) Gold 6154". What should I do to overcome this problem? Thanks in advance..

GCC 4.8 does not support any of the AVX-512 variants. If this is the system compiler from Red Hat Enterprise Linux 7, you can use a new GCC version from Red Hat Developer Toolset, which provides support for later CPU features. (DTS is also available for CentOS.)

Related

clang: warning: argument unused during compilation: '-always-inline' [-Wunused-command-line-argument]

I want to force the clang compiler to inline the code.
I have already use the inline __attribute__((always_inline)) while realizing the function:
inline __attribute__((always_inline)) void func() {
// ...
}
I tried to compile the code by using:
clang sort.c -O3 -DNDEBUG -g -Wall -std=gnu99 -gdwarf-3 -always-inline -lrt -lm -o sort
However I got the warning when compiling:
clang: warning: argument unused during compilation: '-always-inline' [-Wunused-command-line-argument]
And my function is not inlined.
What did I miss?

GCC how to suppress " discards 'volatile' qualifier from pointer target type"

How can i suppress this warning?
maybe some #pragma GCC diagnostic ignored in code or CFLAG in makefile?
If you had posted the full warning message it should show the specific warning [-Wdiscarded-qualifiers]. Like other warnings, just prefix with no- to suppress it.
From the gcc manual
-Wno-discarded-qualifiers (C and Objective-C only)
Do not warn if type qualifiers on pointers are being discarded. Typically, the compiler warns if a const char * variable is passed to a function that takes a char * parameter. This option can be used to suppress such a warning.
$ cat test.c
#include <stdio.h>
int a;
volatile int *p = &a;
int main (void)
{
int *q = p;
return 0;
}
$ gcc test.c
test.c: In function ‘main’:
test.c:8:11: warning: initialization discards ‘volatile’ qualifier from pointer target type [-Wdiscarded-qualifiers]
int *q = p;
^
$ gcc -Wno-discarded-qualifiers test.c
$
Although you probably already know it is a bad programming tactic, you can disable warnings in general when compiling and not only the one that bugs you.
Add -w option when compiling
I also attach you the documentation on Warnings Options.
http://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html
Hope i helped!
ok thanks guys. -Wdiscarded-qualifiers not really helped me.
actually ive tried to find it in gcc docs, but i am not good at this.
here`s my cflags in project
CFLAGS ?= -g0 -O3 -Wno-discarded-qualifiers -Wshadow -Wmaybe-uninitialized -Wall -Wextra -Wno-unused-function -Wno-error=strict-prototypes -Wpointer-arith -fno-strict-aliasing -Wno-error=cpp -Wuninitialized -Wmaybe-uninitialized -Wno-unused-parameter -Wno-missing-field-initializers -Wtype-limits -Wsizeof-pointer-memaccess -Wno-format-nonliteral -Wno-cast-qual -Wunreachable-code -Wno-switch-default -Wno-switch-enum -Wreturn-type -Wmultichar -Wformat-security -Wno-ignored-qualifiers -Wno-error=pedantic -Wno-sign-compare -Wno-error=missing-prototypes -Wdouble-promotion -Wclobbered -Wdeprecated -Wempty-body -Wtype-limits -Wno-unused-value -Wno-unused-parameter -Wno-missing-field-initializers -Wuninitialized -Wmaybe-uninitialized -Wall -Wextra -Wno-unused-parameter -Wno-missing-field-initializers -Wtype-limits -Wsizeof-pointer-memaccess -Wno-format-nonliteral -Wpointer-arith -Wno-cast-qual -Wunreachable-code -Wno-switch-default -Wreturn-type -Wmultichar -Wformat-security -Wno-ignored-qualifiers -Wno-sign-compare
LDFLAGS ?= -lm
and the reason that i am using discard volatile qualifiers is that i dont want to add volatile in function prototypes and dont want to cast it in function call, because some of variables works fine without volatile key, and others - not.
(its some common variables and also thread_t types)
so code works fine, also when ive tried to cast volatile types in function call - there some glitches happened, and now all works fine. Thanks for help i appreciate that!
now with that key i have
"discards 'volatile' qualifier from pointer target type"
its pointers that sometimes get optimizated by compiler.

Enforcing ANSI C89 with clang

I'm trying to make the C compiler clang go into ANSI C89 mode but without success.
Here is an example session:
$ cat t.c
#include <stdio.h>
int main(void)
{
puts(__FUNCTION__);
return 0;
}
$ gcc -pedantic -std=c89 -Wall t.c
t.c: In function ‘main’:
t.c:5:7: warning: ISO C does not support ‘__FUNCTION__’ predefined identifier [-Wpedantic]
puts(__FUNCTION__);
^~~~~~~~~~~~
$ clang -pedantic -std=c89 -Wall t.c
$ clang --version
clang version 3.8.1-24 (tags/RELEASE_381/final)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
As you can see, the clang command completes with no warning. Is there a command option that I'm missing here?
It seems as if this specific warning is not emitted by clang, but apparently -std=c89 does toggle ANSI C89 syntax checking.
For example:
inline int foo(int* restrict p)
{
return *p;
}
Will refuse to compile with -std=c89 -pedantic -Wall:
t.c:1:1: error: unknown type name 'inline'
t.c:1:23: error: expected ')'
int foo(int* restrict p)
But will compile without errors using -std=c99.
The non-standard predefined identifiers warning was introduced with GCC 5 (https://gcc.gnu.org/gcc-5/porting_to.html), and apparently clang did not adapt with it.

Why is gcc not complaining about missing symbol?

I have defined the following in a c file:
#ifdef __clang__
// clang definition here
#elif defined _GNULINUX
#define _ALIGNED_FREE(pMempointer) _free((pMempointer))
#elif defined _MSC_VER
// VS definition here
#else
// default definition
#endif
void * pMemory = 0L;
if(pMemory) {
_ALIGNED_FREE(pMemory);
}
gcc flags are:
-Wall -Wno-long-long -fexpensive-optimizations -fomit-frame-pointer -funroll-loops -pipe -fexceptions -Wpointer-arith -Wcast-align -Wsign-compare -pedantic -mmmx -msse
After compiling (in a Ubuntu 14.04 machine) with gcc version 4.8.2 successfully the program exits at runtime with undefined symbol: _free
Obviously the symbol _free is unknown, but why does gcc not complain about this? I would expect it to throw an error at linking time like the VS linker does.
free does not have a leading underscore in Linux nor by the C Standard.

c gcc compiler options for pointer arithmetic warning

I’m using the following flags, but still I m not able to get this warning:
pointer of type void * used in arithmetic
Flags used:
-O2 -Werror -Wall -Wno-main -Wno-format-zero-length -Wpointer-arith -Wmissing-prototypes -Wstrict-prototypes -Wswitch -Wshadow -Wcast-qual -Wwrite-strings -Wno-sign-compare -Wno-pointer-sign -Wno-attributes -fno-strict-aliasing
-Wpointer-arith should catch this type of warning, but I’m not able to get this warning:
pointer of type void * used in arithmetic
Which specific cflag should be used to get this warning?
Edit: my mistake, it is there as part of a macro check which is not defined. :( By defining that macro, I’m able to get that error.
You're right. -Wpointer-arith should give you a warning as per the documentation.
I have just tried the following program (with intentional error):
~/code/samples$ cat foo.c
#include <stdio.h>
int main (int argc, char **argv)
{
void * bar;
void * foo;
foo = bar + 1;
return 0;
}
I have compiled the program with just the -Wpointer-arith option, and all your options as listed above. Both attempts threw up the desired warning. I am using gcc version 4.3.4 (Debian 4.3.4-6).:
~/code/samples$ gcc -Wpointer-arith foo.c
foo.c: In function ‘main’:
foo.c:6: warning: pointer of type ‘void *’ used in arithmetic
and
~/code/samples$ gcc -O2 -Werror -Wall -Wno-main -Wno-format-zero-length -Wpointer-arith -Wmissing-prototypes -Wstrict-prototypes -Wswitch -Wshadow -Wcast-qual -Wwrite-strings -Wno-sign-compare -Wno-pointer-sign -Wno-attributes -fno-strict-aliasing foo.c
cc1: warnings being treated as errors
foo.c: In function ‘main’:
foo.c:6: error: pointer of type ‘void *’ used in arithmetic
The compiler does throw up the warning if you give it the 'right' code. So, I would recommend you examine why it is you expect this warning. Maybe the code you're compiling has changed?
One possible clue I can give you: foo = bar + 1; in the code above triggers the warning. But foo = bar ++; will not (You get a different warning). So if your code uses increment (or decrement) operators on pointers, it will probably not trigger the warning.
I know this is not a direct answer, but I hope this helps you focus your investigation.
With gcc 4.2.1 on OS X, I get this warning:
p.c:7: warning: wrong type argument to increment
for the following program:
#include <stdio.h>
int main(void)
{
int i[] = { 42 };
void *p = i;
printf("%p\n", p++);
return 0;
}
I am compiling it as:
$ gcc -Wpointer-arith p.c
Can you post your program, or post the result of compiling the above?

Resources