Last active
June 3, 2019 14:54
-
-
Save EgorBo/70e879212440003d948ead6c1b824538 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Runtime.CompilerServices; | |
using System.Runtime.Intrinsics; | |
using System.Runtime.Intrinsics.X86; | |
public class C | |
{ | |
static void Main() | |
{ | |
Ok(new[] { Vector128.Create(1.0f) }); | |
NotOk(new[] { Vector128.Create(1.0f) }); | |
} | |
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] | |
public static Vector128<float> Add(Vector128<float> left, Vector128<float> right) | |
{ | |
if (Sse.IsSupported) | |
{ | |
return Sse.Add(left, right); | |
} | |
return default; | |
} | |
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] | |
public static Vector128<float> AddNoCheck(Vector128<float> left, Vector128<float> right) | |
{ | |
return Sse.Add(left, right); | |
} | |
[MethodImpl(MethodImplOptions.NoInlining)] | |
public static void Ok(Vector128<float>[] src) | |
{ | |
var vector = src[0]; | |
AddNoCheck(vector, vector); | |
} | |
[MethodImpl(MethodImplOptions.NoInlining)] | |
public static void NotOk(Vector128<float>[] src) | |
{ | |
var vector = src[0]; | |
Add(vector, vector); | |
// redundant vmovups is generated somewhere here | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment