public static byte32 lcm(sbyte32 x, sbyte32 y) { byte32 absX = (byte32)abs(x); byte32 absY = (byte32)abs(y); return((absX / gcd(absX, absY)) * absY); }
public static int csum(sbyte32 x) { if (Avx2.IsAvx2Supported) { short16 cast = (short16)x.v16_0 + (short16)x.v16_16; short8 more = cast.v8_0 + cast.v8_8; more += Sse2.unpackhi_epi64(more, more); more += Sse2.shufflelo_epi16(more, Sse.SHUFFLE(0, 1, 2, 3)); return(Sse2.add_epi16(more, Sse2.shufflelo_epi16(more, Sse.SHUFFLE(0, 0, 0, 1))).SShort0); } else if (Sse2.IsSse2Supported) { short8 cast = ((short8)x.v8_0 + (short8)x.v8_8) + ((short8)x.v8_16 + (short8)x.v8_24); cast += Sse2.unpackhi_epi64(cast, cast); cast += Sse2.shufflelo_epi16(cast, Sse.SHUFFLE(0, 1, 2, 3)); return(Sse2.add_epi16(cast, Sse2.shufflelo_epi16(cast, Sse.SHUFFLE(0, 0, 0, 1))).SShort0); } else { return(((((x.x0 + x.x1) + (x.x2 + x.x3)) + ((x.x4 + x.x5) + (x.x6 + x.x7))) + (((x.x8 + x.x9) + (x.x10 + x.x11)) + ((x.x12 + x.x13) + (x.x14 + x.x15)))) + ((((x.x16 + x.x17) + (x.x18 + x.x19)) + ((x.x20 + x.x21) + (x.x22 + x.x23))) + (((x.x24 + x.x25) + (x.x26 + x.x27)) + ((x.x28 + x.x29) + (x.x30 + x.x31))))); } }
public sbyte32 NextSByte32(sbyte32 min, sbyte32 max) { Assert.IsNotSmaller(max.x0, min.x0); Assert.IsNotSmaller(max.x1, min.x1); Assert.IsNotSmaller(max.x2, min.x2); Assert.IsNotSmaller(max.x3, min.x3); Assert.IsNotSmaller(max.x4, min.x4); Assert.IsNotSmaller(max.x5, min.x5); Assert.IsNotSmaller(max.x6, min.x6); Assert.IsNotSmaller(max.x7, min.x7); Assert.IsNotSmaller(max.x8, min.x8); Assert.IsNotSmaller(max.x9, min.x9); Assert.IsNotSmaller(max.x10, min.x10); Assert.IsNotSmaller(max.x11, min.x11); Assert.IsNotSmaller(max.x12, min.x12); Assert.IsNotSmaller(max.x13, min.x13); Assert.IsNotSmaller(max.x14, min.x14); Assert.IsNotSmaller(max.x15, min.x15); Assert.IsNotSmaller(max.x16, min.x16); Assert.IsNotSmaller(max.x17, min.x17); Assert.IsNotSmaller(max.x18, min.x18); Assert.IsNotSmaller(max.x19, min.x19); Assert.IsNotSmaller(max.x20, min.x20); Assert.IsNotSmaller(max.x21, min.x21); Assert.IsNotSmaller(max.x22, min.x22); Assert.IsNotSmaller(max.x23, min.x23); Assert.IsNotSmaller(max.x24, min.x24); Assert.IsNotSmaller(max.x25, min.x25); Assert.IsNotSmaller(max.x26, min.x26); Assert.IsNotSmaller(max.x27, min.x27); Assert.IsNotSmaller(max.x28, min.x28); Assert.IsNotSmaller(max.x29, min.x29); Assert.IsNotSmaller(max.x30, min.x30); Assert.IsNotSmaller(max.x31, min.x31); if (Avx2.IsAvx2Supported) { max -= min; ushort16 lo = (ushort16)max.v16_0 * new ushort16(NextState(), NextState(), NextState(), NextState(), NextState(), NextState(), NextState(), NextState(), NextState(), NextState(), NextState(), NextState(), NextState(), NextState(), NextState(), NextState()); ushort16 hi = (ushort16)max.v16_16 * new ushort16(NextState(), NextState(), NextState(), NextState(), NextState(), NextState(), NextState(), NextState(), NextState(), NextState(), NextState(), NextState(), NextState(), NextState(), NextState(), NextState()); lo = Avx2.mm256_shuffle_epi8(lo, new v256(1, 3, 5, 7, 9, 11, 13, 15, 0, 0, 0, 0, 0, 0, 0, 0, 1, 3, 5, 7, 9, 11, 13, 15, 0, 0, 0, 0, 0, 0, 0, 0)); hi = Avx2.mm256_shuffle_epi8(hi, new v256(1, 3, 5, 7, 9, 11, 13, 15, 0, 0, 0, 0, 0, 0, 0, 0, 1, 3, 5, 7, 9, 11, 13, 15, 0, 0, 0, 0, 0, 0, 0, 0)); return(min + new sbyte32(Avx.mm256_castsi256_si128(Avx2.mm256_permute4x64_epi64(lo, Sse.SHUFFLE(0, 0, 2, 0))), Avx.mm256_castsi256_si128(Avx2.mm256_permute4x64_epi64(hi, Sse.SHUFFLE(0, 0, 2, 0))))); } else { return(new sbyte32(NextSByte8(min.v8_0, max.v8_0), NextSByte8(min.v8_8, max.v8_8), NextSByte8(min.v8_16, max.v8_16), NextSByte8(min.v8_24, max.v8_24))); } }
public static sbyte32 abs(sbyte32 x) { if (Avx2.IsAvx2Supported) { return(Avx2.mm256_abs_epi8(x)); } else { return(new sbyte32(abs(x.v16_0), abs(x.v16_16))); } }
public static sbyte32 sign(sbyte32 x) { if (Avx2.IsAvx2Supported) { return(Avx2.mm256_sign_epi8(new sbyte32(1), x)); } else { return(new sbyte32(sign(x.v16_0), sign(x.v16_16))); } }
public static sbyte32 max(sbyte32 a, sbyte32 b) { if (Avx2.IsAvx2Supported) { return(Avx2.mm256_max_epi8(a, b)); } else { return(new sbyte32(max(a.v16_0, b.v16_0), max(a.v16_16, b.v16_16))); } }
public static sbyte32 subadd(sbyte32 a, sbyte32 b) { if (Avx2.IsAvx2Supported) { return(a + Avx2.mm256_sign_epi8(b, new v256(255, 1, 255, 1, 255, 1, 255, 1, 255, 1, 255, 1, 255, 1, 255, 1, 255, 1, 255, 1, 255, 1, 255, 1, 255, 1, 255, 1, 255, 1, 255, 1))); } else { return(new sbyte32(subadd(a.v16_0, b.v16_0), subadd(a.v16_16, b.v16_16))); } }
public static sbyte32 nabs(sbyte32 x) { if (Avx2.IsAvx2Supported) { return(Avx2.mm256_sub_epi8(default(v256), Avx2.mm256_abs_epi8(x))); } else { return(new sbyte32(abs(x.v16_0), nabs(x.v16_16))); } }
public static sbyte32 divrem(sbyte32 dividend, sbyte divisor, out sbyte32 remainder) { if (Constant.IsConstantExpression(divisor)) { remainder = dividend % divisor; return(dividend / divisor); } else { return(divrem(dividend, (sbyte32)divisor, out remainder)); } }
public static bool32 ispow2(sbyte32 x) { if (Avx2.IsAvx2Supported) { return(Avx2.mm256_and_si256(Avx2.mm256_and_si256(Avx2.mm256_cmpgt_epi8(x, default(v256)), Avx2.mm256_cmpeq_epi8(default(v256), x & (x - 1))), new sbyte32(1))); } else { return(new bool32(ispow2(x.v16_0), ispow2(x.v16_16))); } }
public static void SByte32() { bool result = true; Random64 x = new Random64(47); for (int i = 0; i < Tests.SByte32.NUM_TESTS; i++) { bool32 b = x.NextBool32(); sbyte32 a = maxmath.negate(Tests.SByte32.TestData_LHS[i], b); result &= maxmath.all(a == maxmath.select(Tests.SByte32.TestData_LHS[i], -Tests.SByte32.TestData_LHS[i], b)); } Assert.AreEqual(true, result); }
public static sbyte32 compareto(sbyte32 x, sbyte32 y) { if (Avx2.IsAvx2Supported) { sbyte32 xGreatery = Avx2.mm256_cmpgt_epi8(x, y); sbyte32 yGreaterx = Avx2.mm256_cmpgt_epi8(y, x); return((0 - xGreatery) + yGreaterx); } else { return(new sbyte32(compareto(x.v16_0, y.v16_0), compareto(x.v16_16, y.v16_16))); } }
public static sbyte32 compareto(byte32 x, byte32 y) { if (Avx2.IsAvx2Supported) { sbyte32 xGreatery = Operator.greater_mask_byte(x, y); sbyte32 yGreaterx = Operator.greater_mask_byte(y, x); return((0 - xGreatery) + yGreaterx); } else { return(new sbyte32(compareto(x.v16_0, y.v16_0), compareto(x.v16_16, y.v16_16))); } }
internal static sbyte32 vrem_sbyte(sbyte32 dividend, sbyte32 divisor) { if (Avx2.IsAvx2Supported) { byte32 remainder = vrem_byte((byte32)maxmath.abs(dividend), (byte32)maxmath.abs(divisor)); byte32 mustNegate = Avx2.mm256_cmpgt_epi8(sbyte32.zero, dividend); return(Avx2.mm256_blendv_epi8(remainder, -((sbyte32)remainder), mustNegate)); } else { throw new CPUFeatureCheckException(); } }
public static sbyte32 divrem(sbyte32 dividend, sbyte32 divisor, out sbyte32 remainder) { if (Avx2.IsAvx2Supported) { return(Operator.vdivrem_sbyte(dividend, divisor, out remainder)); } else { sbyte32 quotients = new sbyte32(divrem(dividend.v16_0, divisor.v16_0, out sbyte16 remLo), divrem(dividend.v16_16, divisor.v16_16, out sbyte16 remHi)); remainder = new sbyte32(remLo, remHi); return(quotients); } }
internal static sbyte32 vdiv_sbyte(sbyte32 dividend, sbyte32 divisor) { if (Avx2.IsAvx2Supported) { byte32 quotient = vdiv_byte((byte32)maxmath.abs(dividend), (byte32)maxmath.abs(divisor)); byte32 mustNegate = Avx2.mm256_xor_si256(Avx2.mm256_cmpgt_epi8(sbyte32.zero, divisor), Avx2.mm256_cmpgt_epi8(sbyte32.zero, dividend)); return(Avx2.mm256_blendv_epi8(quotient, -((sbyte32)quotient), mustNegate)); } else { throw new CPUFeatureCheckException(); } }
public static sbyte32 negate(sbyte32 x, bool32 p) { Assert.IsSafeBoolean(p.x0); Assert.IsSafeBoolean(p.x1); Assert.IsSafeBoolean(p.x2); Assert.IsSafeBoolean(p.x3); Assert.IsSafeBoolean(p.x4); Assert.IsSafeBoolean(p.x5); Assert.IsSafeBoolean(p.x6); Assert.IsSafeBoolean(p.x7); Assert.IsSafeBoolean(p.x8); Assert.IsSafeBoolean(p.x9); Assert.IsSafeBoolean(p.x10); Assert.IsSafeBoolean(p.x11); Assert.IsSafeBoolean(p.x12); Assert.IsSafeBoolean(p.x13); Assert.IsSafeBoolean(p.x14); Assert.IsSafeBoolean(p.x15); Assert.IsSafeBoolean(p.x16); Assert.IsSafeBoolean(p.x17); Assert.IsSafeBoolean(p.x18); Assert.IsSafeBoolean(p.x19); Assert.IsSafeBoolean(p.x20); Assert.IsSafeBoolean(p.x21); Assert.IsSafeBoolean(p.x22); Assert.IsSafeBoolean(p.x23); Assert.IsSafeBoolean(p.x24); Assert.IsSafeBoolean(p.x25); Assert.IsSafeBoolean(p.x26); Assert.IsSafeBoolean(p.x27); Assert.IsSafeBoolean(p.x28); Assert.IsSafeBoolean(p.x29); Assert.IsSafeBoolean(p.x30); Assert.IsSafeBoolean(p.x31); if (Avx2.IsAvx2Supported) { sbyte32 mask = Avx2.mm256_cmpgt_epi8(p, default(v256)); return((x ^ mask) - mask); } else { return(new sbyte32(negate(x.v16_0, p.v16_0), negate(x.v16_16, p.v16_16)));; } }
public static bool32 toboolsafe(sbyte32 x) { if (Avx2.IsAvx2Supported) { return((v256)clamp(x, 0, 1)); } else if (Sse2.IsSse2Supported) { return(new bool32((v128)clamp(x.v16_0, 0, 1), (v128)clamp(x.v16_16, 0, 1))); } else { sbyte32 temp = clamp(x, 0, 1); return(*(bool32 *)&temp); } }
public static uint sad(sbyte32 a, sbyte32 b) { short16 sumUp = abs((short16)a.v16_0 - (short16)b.v16_0) + abs((short16)a.v16_16 - (short16)b.v16_16); short8 more = sumUp.v8_0 + sumUp.v8_8; if (Sse2.IsSse2Supported) { more += Sse2.shuffle_epi32(more, Sse.SHUFFLE(0, 1, 2, 3)); more += Sse2.shufflelo_epi16(more, Sse.SHUFFLE(0, 1, 2, 3)); return(Sse2.add_epi16(more, Sse2.shufflelo_epi16(more, Sse.SHUFFLE(0, 0, 0, 1))).UShort0); } else { return((uint)(((more.x0 + more.x1) + (more.x2 + more.x3)) + ((more.x4 + more.x5) + (more.x6 + more.x7)))); } }
public static void sbyte32() { Random8 rng = new Random8(135); for (int i = 0; i < 64; i++) { sbyte32 x = rng.NextSByte32(); byte32 n = rng.NextByte32(); Assert.AreEqual(new sbyte32((sbyte)_intpow(x.x0, n.x0), (sbyte)_intpow(x.x1, n.x1), (sbyte)_intpow(x.x2, n.x2), (sbyte)_intpow(x.x3, n.x3), (sbyte)_intpow(x.x4, n.x4), (sbyte)_intpow(x.x5, n.x5), (sbyte)_intpow(x.x6, n.x6), (sbyte)_intpow(x.x7, n.x7), (sbyte)_intpow(x.x8, n.x8), (sbyte)_intpow(x.x9, n.x9), (sbyte)_intpow(x.x10, n.x10), (sbyte)_intpow(x.x11, n.x11), (sbyte)_intpow(x.x12, n.x12), (sbyte)_intpow(x.x13, n.x13), (sbyte)_intpow(x.x14, n.x14), (sbyte)_intpow(x.x15, n.x15), (sbyte)_intpow(x.x16, n.x16), (sbyte)_intpow(x.x17, n.x17), (sbyte)_intpow(x.x18, n.x18), (sbyte)_intpow(x.x19, n.x19), (sbyte)_intpow(x.x20, n.x20), (sbyte)_intpow(x.x21, n.x21), (sbyte)_intpow(x.x22, n.x22), (sbyte)_intpow(x.x23, n.x23), (sbyte)_intpow(x.x24, n.x24), (sbyte)_intpow(x.x25, n.x25), (sbyte)_intpow(x.x26, n.x26), (sbyte)_intpow(x.x27, n.x27), (sbyte)_intpow(x.x28, n.x28), (sbyte)_intpow(x.x29, n.x29), (sbyte)_intpow(x.x30, n.x30), (sbyte)_intpow(x.x31, n.x31)), maxmath.intpow(x, n)); } }
public static void SByte32() { bool result = true; for (int i = 0; i < Tests.SByte32.NUM_TESTS; i++) { sbyte32 t = maxmath.sign(Tests.SByte32.TestData_LHS[i]); result &= t.x0 == ((Tests.SByte32.TestData_LHS[i].x0 == 0) ? 0 : ((Tests.SByte32.TestData_LHS[i].x0 < 0) ? -1 : 1)); result &= t.x1 == ((Tests.SByte32.TestData_LHS[i].x1 == 0) ? 0 : ((Tests.SByte32.TestData_LHS[i].x1 < 0) ? -1 : 1)); result &= t.x2 == ((Tests.SByte32.TestData_LHS[i].x2 == 0) ? 0 : ((Tests.SByte32.TestData_LHS[i].x2 < 0) ? -1 : 1)); result &= t.x3 == ((Tests.SByte32.TestData_LHS[i].x3 == 0) ? 0 : ((Tests.SByte32.TestData_LHS[i].x3 < 0) ? -1 : 1)); result &= t.x4 == ((Tests.SByte32.TestData_LHS[i].x4 == 0) ? 0 : ((Tests.SByte32.TestData_LHS[i].x4 < 0) ? -1 : 1)); result &= t.x5 == ((Tests.SByte32.TestData_LHS[i].x5 == 0) ? 0 : ((Tests.SByte32.TestData_LHS[i].x5 < 0) ? -1 : 1)); result &= t.x6 == ((Tests.SByte32.TestData_LHS[i].x6 == 0) ? 0 : ((Tests.SByte32.TestData_LHS[i].x6 < 0) ? -1 : 1)); result &= t.x7 == ((Tests.SByte32.TestData_LHS[i].x7 == 0) ? 0 : ((Tests.SByte32.TestData_LHS[i].x7 < 0) ? -1 : 1)); result &= t.x8 == ((Tests.SByte32.TestData_LHS[i].x8 == 0) ? 0 : ((Tests.SByte32.TestData_LHS[i].x8 < 0) ? -1 : 1)); result &= t.x9 == ((Tests.SByte32.TestData_LHS[i].x9 == 0) ? 0 : ((Tests.SByte32.TestData_LHS[i].x9 < 0) ? -1 : 1)); result &= t.x10 == ((Tests.SByte32.TestData_LHS[i].x10 == 0) ? 0 : ((Tests.SByte32.TestData_LHS[i].x10 < 0) ? -1 : 1)); result &= t.x11 == ((Tests.SByte32.TestData_LHS[i].x11 == 0) ? 0 : ((Tests.SByte32.TestData_LHS[i].x11 < 0) ? -1 : 1)); result &= t.x12 == ((Tests.SByte32.TestData_LHS[i].x12 == 0) ? 0 : ((Tests.SByte32.TestData_LHS[i].x12 < 0) ? -1 : 1)); result &= t.x13 == ((Tests.SByte32.TestData_LHS[i].x13 == 0) ? 0 : ((Tests.SByte32.TestData_LHS[i].x13 < 0) ? -1 : 1)); result &= t.x14 == ((Tests.SByte32.TestData_LHS[i].x14 == 0) ? 0 : ((Tests.SByte32.TestData_LHS[i].x14 < 0) ? -1 : 1)); result &= t.x15 == ((Tests.SByte32.TestData_LHS[i].x15 == 0) ? 0 : ((Tests.SByte32.TestData_LHS[i].x15 < 0) ? -1 : 1)); result &= t.x16 == ((Tests.SByte32.TestData_LHS[i].x16 == 0) ? 0 : ((Tests.SByte32.TestData_LHS[i].x16 < 0) ? -1 : 1)); result &= t.x17 == ((Tests.SByte32.TestData_LHS[i].x17 == 0) ? 0 : ((Tests.SByte32.TestData_LHS[i].x17 < 0) ? -1 : 1)); result &= t.x18 == ((Tests.SByte32.TestData_LHS[i].x18 == 0) ? 0 : ((Tests.SByte32.TestData_LHS[i].x18 < 0) ? -1 : 1)); result &= t.x19 == ((Tests.SByte32.TestData_LHS[i].x19 == 0) ? 0 : ((Tests.SByte32.TestData_LHS[i].x19 < 0) ? -1 : 1)); result &= t.x20 == ((Tests.SByte32.TestData_LHS[i].x20 == 0) ? 0 : ((Tests.SByte32.TestData_LHS[i].x20 < 0) ? -1 : 1)); result &= t.x21 == ((Tests.SByte32.TestData_LHS[i].x21 == 0) ? 0 : ((Tests.SByte32.TestData_LHS[i].x21 < 0) ? -1 : 1)); result &= t.x22 == ((Tests.SByte32.TestData_LHS[i].x22 == 0) ? 0 : ((Tests.SByte32.TestData_LHS[i].x22 < 0) ? -1 : 1)); result &= t.x23 == ((Tests.SByte32.TestData_LHS[i].x23 == 0) ? 0 : ((Tests.SByte32.TestData_LHS[i].x23 < 0) ? -1 : 1)); result &= t.x24 == ((Tests.SByte32.TestData_LHS[i].x24 == 0) ? 0 : ((Tests.SByte32.TestData_LHS[i].x24 < 0) ? -1 : 1)); result &= t.x25 == ((Tests.SByte32.TestData_LHS[i].x25 == 0) ? 0 : ((Tests.SByte32.TestData_LHS[i].x25 < 0) ? -1 : 1)); result &= t.x26 == ((Tests.SByte32.TestData_LHS[i].x26 == 0) ? 0 : ((Tests.SByte32.TestData_LHS[i].x26 < 0) ? -1 : 1)); result &= t.x27 == ((Tests.SByte32.TestData_LHS[i].x27 == 0) ? 0 : ((Tests.SByte32.TestData_LHS[i].x27 < 0) ? -1 : 1)); result &= t.x28 == ((Tests.SByte32.TestData_LHS[i].x28 == 0) ? 0 : ((Tests.SByte32.TestData_LHS[i].x28 < 0) ? -1 : 1)); result &= t.x29 == ((Tests.SByte32.TestData_LHS[i].x29 == 0) ? 0 : ((Tests.SByte32.TestData_LHS[i].x29 < 0) ? -1 : 1)); result &= t.x30 == ((Tests.SByte32.TestData_LHS[i].x30 == 0) ? 0 : ((Tests.SByte32.TestData_LHS[i].x30 < 0) ? -1 : 1)); result &= t.x31 == ((Tests.SByte32.TestData_LHS[i].x31 == 0) ? 0 : ((Tests.SByte32.TestData_LHS[i].x31 < 0) ? -1 : 1)); } Assert.AreEqual(true, result); }
public static void SByte32x2() { bool result = true; for (int i = 0; i < Tests.SByte32.NUM_TESTS; i++) { sbyte32 x = maxmath.avg(Tests.SByte32.TestData_LHS[i], Tests.SByte32.TestData_RHS[i]); result &= x.x0 == (((Tests.SByte32.TestData_LHS[i].x0 + Tests.SByte32.TestData_RHS[i].x0) > 0 ? 1 : -1) + Tests.SByte32.TestData_LHS[i].x0 + Tests.SByte32.TestData_RHS[i].x0) / 2; result &= x.x1 == (((Tests.SByte32.TestData_LHS[i].x1 + Tests.SByte32.TestData_RHS[i].x1) > 0 ? 1 : -1) + Tests.SByte32.TestData_LHS[i].x1 + Tests.SByte32.TestData_RHS[i].x1) / 2; result &= x.x2 == (((Tests.SByte32.TestData_LHS[i].x2 + Tests.SByte32.TestData_RHS[i].x2) > 0 ? 1 : -1) + Tests.SByte32.TestData_LHS[i].x2 + Tests.SByte32.TestData_RHS[i].x2) / 2; result &= x.x3 == (((Tests.SByte32.TestData_LHS[i].x3 + Tests.SByte32.TestData_RHS[i].x3) > 0 ? 1 : -1) + Tests.SByte32.TestData_LHS[i].x3 + Tests.SByte32.TestData_RHS[i].x3) / 2; result &= x.x4 == (((Tests.SByte32.TestData_LHS[i].x4 + Tests.SByte32.TestData_RHS[i].x4) > 0 ? 1 : -1) + Tests.SByte32.TestData_LHS[i].x4 + Tests.SByte32.TestData_RHS[i].x4) / 2; result &= x.x5 == (((Tests.SByte32.TestData_LHS[i].x5 + Tests.SByte32.TestData_RHS[i].x5) > 0 ? 1 : -1) + Tests.SByte32.TestData_LHS[i].x5 + Tests.SByte32.TestData_RHS[i].x5) / 2; result &= x.x6 == (((Tests.SByte32.TestData_LHS[i].x6 + Tests.SByte32.TestData_RHS[i].x6) > 0 ? 1 : -1) + Tests.SByte32.TestData_LHS[i].x6 + Tests.SByte32.TestData_RHS[i].x6) / 2; result &= x.x7 == (((Tests.SByte32.TestData_LHS[i].x7 + Tests.SByte32.TestData_RHS[i].x7) > 0 ? 1 : -1) + Tests.SByte32.TestData_LHS[i].x7 + Tests.SByte32.TestData_RHS[i].x7) / 2; result &= x.x8 == (((Tests.SByte32.TestData_LHS[i].x8 + Tests.SByte32.TestData_RHS[i].x8) > 0 ? 1 : -1) + Tests.SByte32.TestData_LHS[i].x8 + Tests.SByte32.TestData_RHS[i].x8) / 2; result &= x.x9 == (((Tests.SByte32.TestData_LHS[i].x9 + Tests.SByte32.TestData_RHS[i].x9) > 0 ? 1 : -1) + Tests.SByte32.TestData_LHS[i].x9 + Tests.SByte32.TestData_RHS[i].x9) / 2; result &= x.x10 == (((Tests.SByte32.TestData_LHS[i].x10 + Tests.SByte32.TestData_RHS[i].x10) > 0 ? 1 : -1) + Tests.SByte32.TestData_LHS[i].x10 + Tests.SByte32.TestData_RHS[i].x10) / 2; result &= x.x11 == (((Tests.SByte32.TestData_LHS[i].x11 + Tests.SByte32.TestData_RHS[i].x11) > 0 ? 1 : -1) + Tests.SByte32.TestData_LHS[i].x11 + Tests.SByte32.TestData_RHS[i].x11) / 2; result &= x.x12 == (((Tests.SByte32.TestData_LHS[i].x12 + Tests.SByte32.TestData_RHS[i].x12) > 0 ? 1 : -1) + Tests.SByte32.TestData_LHS[i].x12 + Tests.SByte32.TestData_RHS[i].x12) / 2; result &= x.x13 == (((Tests.SByte32.TestData_LHS[i].x13 + Tests.SByte32.TestData_RHS[i].x13) > 0 ? 1 : -1) + Tests.SByte32.TestData_LHS[i].x13 + Tests.SByte32.TestData_RHS[i].x13) / 2; result &= x.x14 == (((Tests.SByte32.TestData_LHS[i].x14 + Tests.SByte32.TestData_RHS[i].x14) > 0 ? 1 : -1) + Tests.SByte32.TestData_LHS[i].x14 + Tests.SByte32.TestData_RHS[i].x14) / 2; result &= x.x15 == (((Tests.SByte32.TestData_LHS[i].x15 + Tests.SByte32.TestData_RHS[i].x15) > 0 ? 1 : -1) + Tests.SByte32.TestData_LHS[i].x15 + Tests.SByte32.TestData_RHS[i].x15) / 2; result &= x.x16 == (((Tests.SByte32.TestData_LHS[i].x16 + Tests.SByte32.TestData_RHS[i].x16) > 0 ? 1 : -1) + Tests.SByte32.TestData_LHS[i].x16 + Tests.SByte32.TestData_RHS[i].x16) / 2; result &= x.x17 == (((Tests.SByte32.TestData_LHS[i].x17 + Tests.SByte32.TestData_RHS[i].x17) > 0 ? 1 : -1) + Tests.SByte32.TestData_LHS[i].x17 + Tests.SByte32.TestData_RHS[i].x17) / 2; result &= x.x18 == (((Tests.SByte32.TestData_LHS[i].x18 + Tests.SByte32.TestData_RHS[i].x18) > 0 ? 1 : -1) + Tests.SByte32.TestData_LHS[i].x18 + Tests.SByte32.TestData_RHS[i].x18) / 2; result &= x.x19 == (((Tests.SByte32.TestData_LHS[i].x19 + Tests.SByte32.TestData_RHS[i].x19) > 0 ? 1 : -1) + Tests.SByte32.TestData_LHS[i].x19 + Tests.SByte32.TestData_RHS[i].x19) / 2; result &= x.x20 == (((Tests.SByte32.TestData_LHS[i].x20 + Tests.SByte32.TestData_RHS[i].x20) > 0 ? 1 : -1) + Tests.SByte32.TestData_LHS[i].x20 + Tests.SByte32.TestData_RHS[i].x20) / 2; result &= x.x21 == (((Tests.SByte32.TestData_LHS[i].x21 + Tests.SByte32.TestData_RHS[i].x21) > 0 ? 1 : -1) + Tests.SByte32.TestData_LHS[i].x21 + Tests.SByte32.TestData_RHS[i].x21) / 2; result &= x.x22 == (((Tests.SByte32.TestData_LHS[i].x22 + Tests.SByte32.TestData_RHS[i].x22) > 0 ? 1 : -1) + Tests.SByte32.TestData_LHS[i].x22 + Tests.SByte32.TestData_RHS[i].x22) / 2; result &= x.x23 == (((Tests.SByte32.TestData_LHS[i].x23 + Tests.SByte32.TestData_RHS[i].x23) > 0 ? 1 : -1) + Tests.SByte32.TestData_LHS[i].x23 + Tests.SByte32.TestData_RHS[i].x23) / 2; result &= x.x24 == (((Tests.SByte32.TestData_LHS[i].x24 + Tests.SByte32.TestData_RHS[i].x24) > 0 ? 1 : -1) + Tests.SByte32.TestData_LHS[i].x24 + Tests.SByte32.TestData_RHS[i].x24) / 2; result &= x.x25 == (((Tests.SByte32.TestData_LHS[i].x25 + Tests.SByte32.TestData_RHS[i].x25) > 0 ? 1 : -1) + Tests.SByte32.TestData_LHS[i].x25 + Tests.SByte32.TestData_RHS[i].x25) / 2; result &= x.x26 == (((Tests.SByte32.TestData_LHS[i].x26 + Tests.SByte32.TestData_RHS[i].x26) > 0 ? 1 : -1) + Tests.SByte32.TestData_LHS[i].x26 + Tests.SByte32.TestData_RHS[i].x26) / 2; result &= x.x27 == (((Tests.SByte32.TestData_LHS[i].x27 + Tests.SByte32.TestData_RHS[i].x27) > 0 ? 1 : -1) + Tests.SByte32.TestData_LHS[i].x27 + Tests.SByte32.TestData_RHS[i].x27) / 2; result &= x.x28 == (((Tests.SByte32.TestData_LHS[i].x28 + Tests.SByte32.TestData_RHS[i].x28) > 0 ? 1 : -1) + Tests.SByte32.TestData_LHS[i].x28 + Tests.SByte32.TestData_RHS[i].x28) / 2; result &= x.x29 == (((Tests.SByte32.TestData_LHS[i].x29 + Tests.SByte32.TestData_RHS[i].x29) > 0 ? 1 : -1) + Tests.SByte32.TestData_LHS[i].x29 + Tests.SByte32.TestData_RHS[i].x29) / 2; result &= x.x30 == (((Tests.SByte32.TestData_LHS[i].x30 + Tests.SByte32.TestData_RHS[i].x30) > 0 ? 1 : -1) + Tests.SByte32.TestData_LHS[i].x30 + Tests.SByte32.TestData_RHS[i].x30) / 2; result &= x.x31 == (((Tests.SByte32.TestData_LHS[i].x31 + Tests.SByte32.TestData_RHS[i].x31) > 0 ? 1 : -1) + Tests.SByte32.TestData_LHS[i].x31 + Tests.SByte32.TestData_RHS[i].x31) / 2; } Assert.AreEqual(true, result); }
public static void sbyte32() { Random8 rng = new Random8(135); for (int i = 0; i < 64; i++) { sbyte32 x = rng.NextSByte32(); sbyte32 y = rng.NextSByte32(); Assert.AreEqual(new byte32((byte)_gcd(x.x0, y.x0), (byte)_gcd(x.x1, y.x1), (byte)_gcd(x.x2, y.x2), (byte)_gcd(x.x3, y.x3), (byte)_gcd(x.x4, y.x4), (byte)_gcd(x.x5, y.x5), (byte)_gcd(x.x6, y.x6), (byte)_gcd(x.x7, y.x7), (byte)_gcd(x.x8, y.x8), (byte)_gcd(x.x9, y.x9), (byte)_gcd(x.x10, y.x10), (byte)_gcd(x.x11, y.x11), (byte)_gcd(x.x12, y.x12), (byte)_gcd(x.x13, y.x13), (byte)_gcd(x.x14, y.x14), (byte)_gcd(x.x15, y.x15), (byte)_gcd(x.x16, y.x16), (byte)_gcd(x.x17, y.x17), (byte)_gcd(x.x18, y.x18), (byte)_gcd(x.x19, y.x19), (byte)_gcd(x.x20, y.x20), (byte)_gcd(x.x21, y.x21), (byte)_gcd(x.x22, y.x22), (byte)_gcd(x.x23, y.x23), (byte)_gcd(x.x24, y.x24), (byte)_gcd(x.x25, y.x25), (byte)_gcd(x.x26, y.x26), (byte)_gcd(x.x27, y.x27), (byte)_gcd(x.x28, y.x28), (byte)_gcd(x.x29, y.x29), (byte)_gcd(x.x30, y.x30), (byte)_gcd(x.x31, y.x31)), maxmath.gcd(x, y)); } }
public static void sbyte32() { Random8 rng = new Random8(135); for (int i = 0; i < 64; i++) { sbyte32 x = rng.NextSByte32(); Assert.AreEqual(new sbyte32((sbyte)maxmath.lzcnt(x.x0), (sbyte)maxmath.lzcnt(x.x1), (sbyte)maxmath.lzcnt(x.x2), (sbyte)maxmath.lzcnt(x.x3), (sbyte)maxmath.lzcnt(x.x4), (sbyte)maxmath.lzcnt(x.x5), (sbyte)maxmath.lzcnt(x.x6), (sbyte)maxmath.lzcnt(x.x7), (sbyte)maxmath.lzcnt(x.x8), (sbyte)maxmath.lzcnt(x.x9), (sbyte)maxmath.lzcnt(x.x10), (sbyte)maxmath.lzcnt(x.x11), (sbyte)maxmath.lzcnt(x.x12), (sbyte)maxmath.lzcnt(x.x13), (sbyte)maxmath.lzcnt(x.x14), (sbyte)maxmath.lzcnt(x.x15), (sbyte)maxmath.lzcnt(x.x16), (sbyte)maxmath.lzcnt(x.x17), (sbyte)maxmath.lzcnt(x.x18), (sbyte)maxmath.lzcnt(x.x19), (sbyte)maxmath.lzcnt(x.x20), (sbyte)maxmath.lzcnt(x.x21), (sbyte)maxmath.lzcnt(x.x22), (sbyte)maxmath.lzcnt(x.x23), (sbyte)maxmath.lzcnt(x.x24), (sbyte)maxmath.lzcnt(x.x25), (sbyte)maxmath.lzcnt(x.x26), (sbyte)maxmath.lzcnt(x.x27), (sbyte)maxmath.lzcnt(x.x28), (sbyte)maxmath.lzcnt(x.x29), (sbyte)maxmath.lzcnt(x.x30), (sbyte)maxmath.lzcnt(x.x31)), maxmath.lzcnt(x)); } }
public static sbyte32 avg(sbyte32 x, sbyte32 y) { if (Avx2.IsAvx2Supported) { short16 result_lo = (short16)x.v16_0 + (short16)y.v16_0; short16 result_hi = (short16)x.v16_16 + (short16)y.v16_16; // if the intermediate sum is positive add 1 short16 isPositiveMask = Avx2.mm256_cmpgt_epi16(result_lo, default(v256)); result_lo = (result_lo - isPositiveMask) >> 1; isPositiveMask = Avx2.mm256_cmpgt_epi16(result_hi, default(v256)); result_hi = (result_hi - isPositiveMask) >> 1; return(Avx2.mm256_permute4x64_epi64(Avx2.mm256_packs_epi16(result_lo, result_hi), Sse.SHUFFLE(3, 1, 2, 0))); } else { return(new sbyte32(avg(x.v8_0, y.v8_0), avg(x.v8_8, y.v8_8), avg(x.v8_16, y.v8_16), avg(x.v8_24, y.v8_24))); } }
public static sbyte32 intpow(sbyte32 x, byte32 n) { if (Avx2.IsAvx2Supported) { v256 ZERO = default(v256); sbyte32 ONE = new sbyte32(1); v256 doneMask = ZERO; v256 result = ZERO; sbyte32 p = x; sbyte32 y = ONE; Loop: v256 y_times_p = y * p; y = Avx2.mm256_blendv_epi8(y, y_times_p, Avx2.mm256_cmpeq_epi8(ONE, Avx2.mm256_and_si256(ONE, n))); n >>= 1; v256 n_is_zero = Avx2.mm256_cmpeq_epi8(ZERO, n); result = Avx2.mm256_blendv_epi8(result, y, Avx2.mm256_andnot_si256(doneMask, n_is_zero)); doneMask = n_is_zero; if (-1 != Avx2.mm256_movemask_epi8(doneMask)) { p *= p; goto Loop; } else { return(result); } } else { return(new sbyte32(intpow(x.v16_0, n.v16_0), intpow(x.v16_16, n.v16_16))); } }
public static bool32 isdivisible(sbyte32 dividend, sbyte32 divisor) { Assert.AreNotEqual(0, divisor.x0); Assert.AreNotEqual(0, divisor.x1); Assert.AreNotEqual(0, divisor.x2); Assert.AreNotEqual(0, divisor.x3); Assert.AreNotEqual(0, divisor.x4); Assert.AreNotEqual(0, divisor.x5); Assert.AreNotEqual(0, divisor.x6); Assert.AreNotEqual(0, divisor.x7); Assert.AreNotEqual(0, divisor.x8); Assert.AreNotEqual(0, divisor.x9); Assert.AreNotEqual(0, divisor.x10); Assert.AreNotEqual(0, divisor.x11); Assert.AreNotEqual(0, divisor.x12); Assert.AreNotEqual(0, divisor.x13); Assert.AreNotEqual(0, divisor.x14); Assert.AreNotEqual(0, divisor.x15); Assert.AreNotEqual(0, divisor.x16); Assert.AreNotEqual(0, divisor.x17); Assert.AreNotEqual(0, divisor.x18); Assert.AreNotEqual(0, divisor.x19); Assert.AreNotEqual(0, divisor.x20); Assert.AreNotEqual(0, divisor.x21); Assert.AreNotEqual(0, divisor.x22); Assert.AreNotEqual(0, divisor.x23); Assert.AreNotEqual(0, divisor.x24); Assert.AreNotEqual(0, divisor.x25); Assert.AreNotEqual(0, divisor.x26); Assert.AreNotEqual(0, divisor.x27); Assert.AreNotEqual(0, divisor.x28); Assert.AreNotEqual(0, divisor.x29); Assert.AreNotEqual(0, divisor.x30); Assert.AreNotEqual(0, divisor.x31); return(dividend % divisor == 0); }
public static sbyte32 bitmask8(sbyte32 numBits, sbyte32 index = default(sbyte32)) => (sbyte32)bitmask8((byte32)numBits, (byte32)index);
public static sbyte cmin(sbyte32 x) { return(cmin(min(x.v16_0, x.v16_16))); }
public static sbyte32 clamp(sbyte32 x, sbyte32 a, sbyte32 b) { return(max(a, min(x, b))); }