Download presentation
Presentation is loading. Please wait.
Published byScott Armstrong Modified over 9 years ago
1
Auto-Vectorization Jim Hogg Program Manager Visual C++ Compiler Microsoft Corporation
2
Auto-Vectorization : What is it? A feature in the Visual Studio 11 C++ native compiler Tries to make your C++ loops run faster, by using vector registers and instructions Speedup varies with application. In tight loops, can reach 4X on ints or floats You don’t need to request this option - it’s on-by-default Just recompile your code and measure the speedup
3
All modern PC chips include vector registers and instructions Vector registers are called XMM0 – XMM15 Each vector register holds 4 ints or 4 floats Vector instructions are called SSE Instructions perform 4 operations in parallel Auto-Vectorization : how does it work?
4
ADD RAX, RBX 1.10 1.20 RAX RBX 2.30 ADDPS XMM1, XMM2 XMM1 XMM2 1.102.103.104.10 RAX 1.202.203.204.20 2.304.306.308.30 XMM1 SCALAR VECTOR for (int i = 0; i < 1000; ++i) a[i] += b[i] for (int i = 0; i < 1000; i += 4) a[i : i+3] += b[i : i+3] Auto-Vectorization : Simple Loop
5
Auto-Vectorization : Example const int dim = 1000000; float a[dim], b[dim]; int main() { for (int n = 0; n < dim; ++n) a[n] += sin(b[n]) * cos(b[n]); } Vectorization Disabled Auto-VectorizedSpeedup 108.7 millisecs37.3 millisecs2.9X
6
Auto-Vectorization : Summary Prior to Visual Studio 11, the C++ compiler emitted code that performed only scalar operations In Visual Studio 11, the C++ compiler tries to use vector registers and instructions to speed up your C++ loops Emits code to uses SSE vector registers and instructions automatically No need to change your C++ source code The feature is on-by-default Adjusts to your computer at runtime (SSE2 or SSE4.1) Transformations are always safe! To try it out, just recompile your code, and run!
7
Auto-Vectorization : Links Channel 9 Video http://channel9.msdn.com/Shows/C9-GoingNative/GoingNative-7- VC11-Auto-Vectorizer-C-NOW-LangNEXT Blog Posts http://blogs.msdn.com/b/nativeconcurrency/archive/2012/04/12/au to-vectorizer-in-visual-studio-11-overview.aspx
8
© 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.