@
KeyboardManS 这个测试 c#作弊,nobody 的数学计算测试项就 c#用的 AVX simd ,rust 就是硬算
···
using System;
using System.Runtime.CompilerServices;
using System.Runtime.Intrinsics;
using System.Runtime.Intrinsics.X86;
using static System.Runtime.CompilerServices.MethodImplOptions;
using V256d = System.Runtime.Intrinsics.Vector256<double>;
public static unsafe class Net60_NBody_AVX_9_3b {
[MethodImpl(AggressiveOptimization | AggressiveInlining)]
private static V256d Square(V256d x)
=> Avx.Multiply(x, x);
[MethodImpl(AggressiveOptimization | AggressiveInlining)]
private static V256d Permute2x128AndBlend(V256d t0, V256d t1)
=> Avx.Add(Avx.Permute2x128(t0, t1, 0b10_0001), Avx.Blend(t0, t1, 0b1100));
[MethodImpl(AggressiveOptimization | AggressiveInlining)][SkipLocalsInit]
private static void InitDiffs(V256d* positions, V256d* rsqrts) {
V256d* r = rsqrts, p = positions;
for (int i = 1, k = 0; i < 5; ++i) {
V256d pi = p[i];
for (int j = 0; j < i; ++j, ++k) {
V256d pj = p[j];
r[k] = Avx.Subtract(pi, pj);
}
}
}
···