triple-z / avx-avx2-example-code Goto Github PK
View Code? Open in Web Editor NEWExample code for Intel AVX / AVX2 intrinsics.
Home Page: https://blog.triplez.cn/posts/avx-avx2-learning-notes/
License: BSD 3-Clause "New" or "Revised" License
Example code for Intel AVX / AVX2 intrinsics.
Home Page: https://blog.triplez.cn/posts/avx-avx2-learning-notes/
License: BSD 3-Clause "New" or "Revised" License
Bringing #1
In the makefile, there's -O
flag specified. For an x86 CPU that doesn't support AVX and AVX2 instruction set with GCC's optimization flag enabled, the compiler will fall back and will not use these instructions, thus on runtime the program will not throw any "illegal instruction" error.
Both GCC and Clang do the same.
Example
#include <immintrin.h>
#include <stdio.h>
int main()
{
__m256i v0 = _mm256_set1_epi8(10);
__m256i v1 = _mm256_set1_epi8(10);
__m256i r = _mm256_add_epi8(v0, v1);
printf("%d", (char *)&r[0]);
}
For example with AVX2:
With gcc main.c -mavx2
creates an unoptimized binary output. Now if the CPU doesn't support AVX2, the program will return an illegal instruction error. However, here every program is compiled with optimization (-O
) flag, and now GCC checks if the CPU has AVX2 support and if not GCC generates an output binary that doesn't have AVX2 support.
Removing -O
flag from makefiles actually can give real results. Otherwise the output value might not actually be what a user thinks.
My CPU does not support AVX2, only support AVX. But it can run hadds.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.