public static void SetVectorAligned(this byte[] array, Vector16b val, int offset) { for (int i = 0; i < 16; ++i) { array [offset + i] = val [i]; } }
public static unsafe Vector16b operator + (Vector16b va, Vector16b vb) { Vector16b res = new Vector16b (); byte *a = &va.v0; byte *b = &vb.v0; byte *c = &res.v0; for (int i = 0; i < 16; ++i) *c++ = (byte)(*a++ + *b++); return res; }
public static unsafe int ExtractByteMask(Vector16b va) { int res = 0; byte *a = (byte *)&va; for (int i = 0; i < 16; ++i) { res |= (*a++ & 0x80) >> 7 << i; } return(res); }
public static unsafe Vector16b Average(Vector16b va, Vector16b vb) { Vector16b res = new Vector16b(); byte * a = &va.v0; byte * b = &vb.v0; byte * c = &res.v0; for (int i = 0; i < 16; ++i) { *c++ = (byte)((*a++ + *b++ + 1) >> 1); } return(res); }
public static unsafe Vector16b SubWithSaturation(Vector16b va, Vector16b vb) { Vector16b res = new Vector16b(); byte * a = &va.v0; byte * b = &vb.v0; byte * c = &res.v0; for (int i = 0; i < 16; ++i) { *c++ = (byte)System.Math.Max(*a++ - *b++, 0); } return(res); }
public static unsafe Vector16b AddWithSaturation(this Vector16b va, Vector16b vb) { Vector16b res = new Vector16b(); byte * a = &va.v0; byte * b = &vb.v0; byte * c = &res.v0; for (int i = 0; i < 16; ++i) { *c++ = (byte)System.Math.Min(*a++ + *b++, byte.MaxValue); } return(res); }
public static unsafe Vector16b Min(Vector16b va, Vector16b vb) { Vector16b res = new Vector16b(); byte * a = &va.v0; byte * b = &vb.v0; byte * c = &res.v0; for (int i = 0; i < 16; ++i) { *c++ = (byte)System.Math.Min(*a++, *b++); } return(res); }
public static unsafe Vector16b operator ^(Vector16b va, Vector16b vb) { Vector16b res = new Vector16b(); uint * a = (uint *)&va.v0; uint * b = (uint *)&vb.v0; uint * c = (uint *)&res.v0; *c++ = *a++ ^ *b++; *c++ = *a++ ^ *b++; *c++ = *a++ ^ *b++; *c = *a ^ *b; return(res); }
public static unsafe Vector16b CompareEqual(Vector16b va, Vector16b vb) { Vector16b res = new Vector16b(); byte * a = &va.v0; byte * b = &vb.v0; byte * c = &res.v0; for (int i = 0; i < 16; ++i) { *c++ = (byte)(*a++ == *b++ ? -1 : 0); } return(res); }
public static unsafe Vector16b operator -(Vector16b va, Vector16b vb) { Vector16b res = new Vector16b(); byte * a = &va.v0; byte * b = &vb.v0; byte * c = &res.v0; for (int i = 0; i < 16; ++i) { *c++ = (byte)(*a++ - *b++); } return(res); }
public static unsafe Vector16b SignedPackWithUnsignedSaturation(Vector8us va, Vector8us vb) { Vector16b res = new Vector16b(); short * a = (short *)&va; short * b = (short *)&vb; byte * c = (byte *)&res; for (int i = 0; i < 8; ++i) { *c++ = (byte)System.Math.Max(0, System.Math.Min((int)*a++, byte.MaxValue)); } for (int i = 0; i < 8; ++i) { *c++ = (byte)System.Math.Max(0, System.Math.Min((int)*b++, byte.MaxValue)); } return(res); }
public static unsafe Vector8us SumOfAbsoluteDifferences(Vector16b va, Vector16sb vb) { Vector8us res = new Vector8us(); byte * a = &va.v0; sbyte * b = (sbyte *)&vb; int tmp = 0; for (int i = 0; i < 8; ++i) { tmp += System.Math.Abs((int)*a++ - (int)*b++); } res.V0 = (ushort)tmp; tmp = 0; for (int i = 0; i < 8; ++i) { tmp += System.Math.Abs((int)*a++ - (int)*b++); } res.V4 = (ushort)tmp; return(res); }
static int test_0_vector16b_add_ovf () { Vector16b a = new Vector16b (200,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15); Vector16b b = new Vector16b (200,10,11,12,13,14,15,0,1,2,3,4,5,6,7,8); Vector16b c = a + b; if (c.V0 != 144) return 1; if (c.V1 != 11) return 2; if (c.V15 != 23) return 3; return 0; }
public static void StoreAligned(ref Vector16b res, Vector16b val) { res = val; }
static unsafe Vector8us bad_method_regression_2 (Vector16b va, Vector16b vb) { Vector8us res = new Vector8us (); byte *a = (byte*)&va; byte *b = (byte*)&vb; int tmp = 0; for (int i = 0; i < 8; ++i) tmp += System.Math.Abs ((int)*a++ - (int)*b++); res.V0 = (ushort)tmp; tmp = 0; for (int i = 0; i < 8; ++i) tmp += System.Math.Abs ((int)*a++ - (int)*b++); res.V4 = (ushort)tmp; return res; }
public static int test_0_vector16b_extract_mask () { Vector16b a = new Vector16b (0xF0,0,0xF0,0,0,0,0xF0,0xAA,0x0F,0,0xFF,0,0,0,0,0); int c = a.ExtractByteMask (); if (c != 0x4C5) return 1; return 0; }
public static int vector16b_cmpeq () { Vector16b a = new Vector16b (1,0,9,0,0,0,0,0,0,0,0,0,0,0,0,1); Vector16b b = new Vector16b (0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0); Vector16b c = a.CompareEqual (b); if (c.V0 != 0) return 1; if (c.V1 != 0) return 2; if (c.V2 != 0) return 3; if (c.V3 != 0xff) return 4; if (c.V4 != 0xff) return 5; if (c.V5 != 0xff) return 6; if (c.V6 != 0xff) return 7; if (c.V7 != 0xff) return 8; if (c.V8 != 0xff) return 9; if (c.V9 != 0xff) return 10; if (c.V10 != 0xff) return 11; if (c.V11 != 0xff) return 12; if (c.V12 != 0xff) return 13; if (c.V13 != 0xff) return 14; if (c.V14 != 0xff) return 15; if (c.V15 != 0) return 16; return 0; }
public static unsafe Vector16b UnpackHigh (this Vector16b va, Vector16b vb) { return new Vector16b (va.v8, vb.v8, va.v9, vb.v9, va.v10, vb.v10, va.v11, vb.v11, va.v12, vb.v12, va.v13, vb.v13, va.v14, vb.v14, va.v15, vb.v15); }
public static unsafe Vector16b CompareEqual (this Vector16b va, Vector16b vb) { Vector16b res = new Vector16b (); byte *a = &va.v0; byte *b = &vb.v0; byte *c = &res.v0; for (int i = 0; i < 16; ++i) *c++ = (byte) (*a++ == *b++ ? -1 : 0); return res; }
public static void PrefetchNonTemporal (ref Vector16b res) { }
public static void PrefetchTemporal2ndLevelCache (ref Vector16b res) { }
public static void PrefetchTemporalAllCacheLevels (ref Vector16b res) { }
public static void PrefetchNonTemporal(ref Vector16b res) { }
public static void PrefetchTemporal2ndLevelCache(ref Vector16b res) { }
public static void PrefetchTemporalAllCacheLevels(ref Vector16b res) { }
public static unsafe void StoreAligned(Vector16b *res, Vector16b val) { *res = val; }
public static int test_0_vector16b_operator_eq () { Vector16b a = new Vector16b(1,2,3,5,5,6,7,8,1,2,3,5,5,6,7,8); Vector16b b = new Vector16b(1,2,3,5,5,6,7,8,1,2,3,5,5,6,7,8); if (!(a == b)) return 1; b.V0 = 99; if (a == b) return 2; return 0; }
public static unsafe void PrefetchTemporalAllCacheLevels (Vector16b *res) { }
public static unsafe void PrefetchTemporal2ndLevelCache (Vector16b *res) { }
public static unsafe Vector16b UnpackLow (this Vector16b va, Vector16b vb) { return new Vector16b (va.v0, vb.v0, va.v1, vb.v1, va.v2, vb.v2, va.v3, vb.v3, va.v4, vb.v4, va.v5, vb.v5, va.v6, vb.v6, va.v7, vb.v7); }
public static unsafe void PrefetchNonTemporal (Vector16b *res) { }
public static unsafe Vector16b SignedPackWithUnsignedSaturation (Vector8us va, Vector8us vb) { Vector16b res = new Vector16b (); short *a = (short*)&va; short *b = (short*)&vb; byte *c = (byte*)&res; for (int i = 0; i < 8; ++i) *c++ = (byte)System.Math.Max (0, System.Math.Min ((int)*a++, byte.MaxValue)); for (int i = 0; i < 8; ++i) *c++ = (byte)System.Math.Max (0, System.Math.Min ((int)*b++, byte.MaxValue)); return res; }
static unsafe Vector8us bad_method_regression (Vector16b va, Vector16b vb) { Vector8us res = new Vector8us (); byte *a = (byte*)&va; byte *b = (byte*)&vb; *((ushort*)&res) = 10; int tmp = 0; if (*b != 0) tmp++; Vector8us dd = res; dd = dd + dd - dd; return dd; }
public static int vector16b_sum_abs_diff () { Vector16b a = new Vector16b (100,20,20,20,0,0,0,0,0,0,0,0,0,0, 0, 0); Vector16sb b = new Vector16sb (0, 10,10,10,0,0,0,0,0,0,0,0,0,0,10,10); Vector8us c = a.SumOfAbsoluteDifferences (b); if (c.V0 != 130) return 1; if (c.V1 != 0) return 2; if (c.V2 != 0) return 3; if (c.V3 != 0) return 4; if (c.V4 != 20) return 5; if (c.V5 != 0) return 6; if (c.V6 != 0) return 7; if (c.V7 != 0) return 8; return 0; }
static int test_0_vector16b_one_element_ctor () { Vector16b a = new Vector16b (99); if (a.V0 != 99) return 1; if (a.V1 != 99) return 2; if (a.V2 != 99) return 3; if (a.V3 != 99) return 4; if (a.V4 != 99) return 5; if (a.V5 != 99) return 6; if (a.V6 != 99) return 7; if (a.V7 != 99) return 8; if (a.V8 != 99) return 9; if (a.V9 != 99) return 10; if (a.V10 != 99) return 11; if (a.V11 != 99) return 12; if (a.V12 != 99) return 13; if (a.V13 != 99) return 14; if (a.V14 != 99) return 15; if (a.V15 != 99) return 16; return 0; }
public static int test_0_vector16b_avg () { Vector16b a = new Vector16b (0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15); Vector16b b = new Vector16b (9,10,11,12,13,14,15,0,1,2,3,4,5,6,7,8); Vector16b c = a.Average (b); if (c.V0 != 5) return 1; if (c.V1 != 6) return 2; if (c.V2 != 7) return 3; if (c.V3 != 8) return 4; if (c.V4 != 9) return 5; if (c.V5 != 10) return 6; if (c.V6 != 11) return 7; if (c.V7 != 4) return 8; if (c.V8 != 5) return 9; if (c.V9 != 6) return 10; if (c.V10 != 7) return 11; if (c.V11 != 8) return 12; if (c.V12 != 9) return 13; if (c.V13 != 10) return 14; if (c.V14 != 11) return 15; if (c.V15 != 12) return 16; return 0; }
static int test_0_vector16b_sub_sat () { Vector16b a = new Vector16b (100,10,11,12,13,14,15,0,1,2,3,4,5,6,7,8); Vector16b b = new Vector16b (200,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15); Vector16b c = a.SubtractWithSaturation (b); if (c.V0 != 0) return 1; if (c.V1 != 9) return 2; if (c.V15 != 0) return 3; return 0; }
/*This bug was caused the simplifier not taking notice of LDADDR on the remaining blocks.*/ public static int test_2_local_simplifier_regression_other_blocks () { Vector16b a = new Vector16b (1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1); Vector16b b = new Vector16b (0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0); Vector8us res = bad_method_regression_2 (a,b); return (int)res.V0 + res.V4; }
public static Vector16b LoadAligned(ref Vector16b v) { return(v); }
/*This bug was caused the simplifier not taking notice of LDADDR on the first block.*/ public static int test_10_local_simplifier_regression_first_block () { Vector16b a = new Vector16b (); Vector16b b = new Vector16b (); Vector8us res = bad_method_regression (a,b); return (int)res.V0; }
public static unsafe Vector16b UnpackLow(Vector16b va, Vector16b vb) { return(new Vector16b(va.v0, vb.v0, va.v1, vb.v1, va.v2, vb.v2, va.v3, vb.v3, va.v4, vb.v4, va.v5, vb.v5, va.v6, vb.v6, va.v7, vb.v7)); }
static int test_0_vector16b_unpack_low () { Vector16b a = new Vector16b (0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15); Vector16b b = new Vector16b (9,10,11,12,13,14,15,0,1,2,3,4,5,6,7,8); Vector16b c = a.UnpackLow (b); if (c.V0 != 0) return 1; if (c.V1 != 9) return 2; if (c.V2 != 1) return 3; if (c.V3 != 10) return 4; if (c.V4 != 2) return 5; if (c.V5 != 11) return 6; if (c.V14 != 7) return 7; if (c.V15 != 0) return 8; return 0; }
public static unsafe Vector16b AddWithSaturation (this Vector16b va, Vector16b vb) { Vector16b res = new Vector16b (); byte *a = &va.v0; byte *b = &vb.v0; byte *c = &res.v0; for (int i = 0; i < 16; ++i) *c++ = (byte) System.Math.Min (*a++ + *b++, byte.MaxValue); return res; }
static int test_0_vector16b_add_sat () { Vector16b a = new Vector16b (200,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15); Vector16b b = new Vector16b (200,10,11,12,13,14,15,0,1,2,3,4,5,6,7,8); Vector16b c = a.AddWithSaturation (b); if (c.V0 != 255) return 1; if (c.V1 != 11) return 2; if (c.V15 != 23) return 3; return 0; }
public static unsafe Vector16b SubtractWithSaturation (this Vector16b va, Vector16b vb) { Vector16b res = new Vector16b (); byte *a = &va.v0; byte *b = &vb.v0; byte *c = &res.v0; for (int i = 0; i < 16; ++i) *c++ = (byte) System.Math.Max (*a++ - *b++, 0); return res; }
static int test_0_vector16b_accessors () { Vector16b a = new Vector16b (0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15); if (a.V0 != 0) return 1; if (a.V1 != 1) return 2; if (a.V2 != 2) return 3; if (a.V3 != 3) return 4; if (a.V4 != 4) return 5; if (a.V5 != 5) return 6; if (a.V6 != 6) return 7; if (a.V7 != 7) return 8; if (a.V8 != 8) return 9; if (a.V9 != 9) return 10; if (a.V10 != 10) return 11; if (a.V11 != 11) return 12; if (a.V12 != 12) return 13; if (a.V13 != 13) return 14; if (a.V14 != 14) return 15; if (a.V15 != 15) return 16; a.V0 = 10; a.V1 = 20; a.V2 = 30; a.V3 = 40; a.V4 = 50; a.V5 = 60; a.V6 = 70; a.V7 = 80; a.V8 = 90; a.V9 = 100; a.V10 = 110; a.V11 = 120; a.V12 = 130; a.V13 = 140; a.V14 = 150; a.V15 = 160; if (a.V0 != 10) return 17; if (a.V1 != 20) return 18; if (a.V2 != 30) return 19; if (a.V3 != 40) return 20; if (a.V4 != 50) return 21; if (a.V5 != 60) return 22; if (a.V6 != 70) return 23; if (a.V7 != 80) return 24; if (a.V8 != 90) return 25; if (a.V9 != 100) return 26; if (a.V10 != 110) return 27; if (a.V11 != 120) return 28; if (a.V12 != 130) return 29; if (a.V13 != 140) return 30; if (a.V14 != 150) return 31; if (a.V15 != 160) return 32; return 0; }
public static unsafe Vector16b Average (this Vector16b va, Vector16b vb) { Vector16b res = new Vector16b (); byte *a = &va.v0; byte *b = &vb.v0; byte *c = &res.v0; for (int i = 0; i < 16; ++i) *c++ = (byte) ((*a++ + *b++ + 1) >> 1); return res; }
public static unsafe Vector16b Min (this Vector16b va, Vector16b vb) { Vector16b res = new Vector16b (); byte *a = &va.v0; byte *b = &vb.v0; byte *c = &res.v0; for (int i = 0; i < 16; ++i) *c++ = (byte) System.Math.Min(*a++, *b++); return res; }
public static unsafe Vector16b UnpackHigh(Vector16b va, Vector16b vb) { return(new Vector16b(va.v8, vb.v8, va.v9, vb.v9, va.v10, vb.v10, va.v11, vb.v11, va.v12, vb.v12, va.v13, vb.v13, va.v14, vb.v14, va.v15, vb.v15)); }