Giter VIP home page Giter VIP logo

avx-avx2-example-code's Introduction

Hi there ๐Ÿ‘‹ Nice to meet U

Triple-Z's github stats

@triplez's Holopin board

avx-avx2-example-code's People

Contributors

triple-z avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

avx-avx2-example-code's Issues

Compiler optimization will discard SIMD extension flags if CPU doesn't support them

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.