Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ SequenceEqual()

static unsafe bool System.SpanHelpers.SequenceEqual ( ref byte first,
ref byte second,
nuint length )
inlinestatic

Definition at line 1190 of file SpanHelpers.cs.

1191 {
1192 if (length < (nuint)sizeof(UIntPtr))
1193 {
1194 if (length < 4)
1195 {
1196 uint num = 0u;
1197 nuint num2 = length & 2;
1198 if (num2 != 0)
1199 {
1200 num = LoadUShort(ref first);
1201 num -= LoadUShort(ref second);
1202 }
1203 if ((length & 1) != 0)
1204 {
1205 num |= (uint)(Unsafe.AddByteOffset(ref first, num2) - Unsafe.AddByteOffset(ref second, num2));
1206 }
1207 return num == 0;
1208 }
1209 nuint offset = length - 4;
1210 uint num3 = LoadUInt(ref first) - LoadUInt(ref second);
1211 num3 |= LoadUInt(ref first, offset) - LoadUInt(ref second, offset);
1212 return num3 == 0;
1213 }
1214 if (Unsafe.AreSame(ref first, ref second))
1215 {
1216 goto IL_0087;
1217 }
1218 nuint num5;
1219 nuint num7;
1220 nuint num9;
1223 if (Sse2.IsSupported)
1224 {
1225 if (Avx2.IsSupported && length >= (nuint)Vector256<byte>.Count)
1226 {
1227 nuint num4 = 0u;
1228 num5 = length - (nuint)Vector256<byte>.Count;
1229 if (num5 == 0)
1230 {
1231 goto IL_00ea;
1232 }
1233 while (true)
1234 {
1236 if (Avx2.MoveMask(value) != -1)
1237 {
1238 break;
1239 }
1240 num4 += (nuint)Vector256<byte>.Count;
1241 if (num5 > num4)
1242 {
1243 continue;
1244 }
1245 goto IL_00ea;
1246 }
1247 }
1248 else
1249 {
1250 if (length < 16)
1251 {
1252 goto IL_01fc;
1253 }
1254 nuint num6 = 0u;
1255 num7 = length - 16;
1256 if (num7 == 0)
1257 {
1258 goto IL_0161;
1259 }
1260 while (true)
1261 {
1263 if (Sse2.MoveMask(value2) != 65535)
1264 {
1265 break;
1266 }
1267 num6 += 16;
1268 if (num7 > num6)
1269 {
1270 continue;
1271 }
1272 goto IL_0161;
1273 }
1274 }
1275 }
1276 else
1277 {
1279 {
1280 goto IL_01fc;
1281 }
1282 nuint num8 = 0u;
1283 num9 = length - (nuint)Vector<byte>.Count;
1284 if (num9 == 0)
1285 {
1286 goto IL_01dd;
1287 }
1288 while (!(LoadVector(ref first, num8) != LoadVector(ref second, num8)))
1289 {
1290 num8 += (nuint)Vector<byte>.Count;
1291 if (num9 > num8)
1292 {
1293 continue;
1294 }
1295 goto IL_01dd;
1296 }
1297 }
1298 goto IL_0290;
1299 IL_01dd:
1300 if (LoadVector(ref first, num9) == LoadVector(ref second, num9))
1301 {
1302 goto IL_0087;
1303 }
1304 goto IL_0290;
1305 IL_0278:
1306 nuint num10;
1307 return LoadNUInt(ref first, num10) == LoadNUInt(ref second, num10);
1308 IL_0161:
1310 if (Sse2.MoveMask(value2) == 65535)
1311 {
1312 goto IL_0087;
1313 }
1314 goto IL_0290;
1315 IL_00ea:
1317 if (Avx2.MoveMask(value) == -1)
1318 {
1319 goto IL_0087;
1320 }
1321 goto IL_0290;
1322 IL_0290:
1323 return false;
1324 IL_0087:
1325 return true;
1326 IL_01fc:
1327 if (Sse2.IsSupported)
1328 {
1329 nuint offset2 = length - (nuint)sizeof(UIntPtr);
1330 nuint num11 = LoadNUInt(ref first) - LoadNUInt(ref second);
1331 num11 |= LoadNUInt(ref first, offset2) - LoadNUInt(ref second, offset2);
1332 return num11 == 0;
1333 }
1334 nuint num12 = 0u;
1335 num10 = length - (nuint)sizeof(UIntPtr);
1336 if (num10 == 0)
1337 {
1338 goto IL_0278;
1339 }
1340 while (LoadNUInt(ref first, num12) == LoadNUInt(ref second, num12))
1341 {
1342 num12 += (nuint)sizeof(UIntPtr);
1343 if (num10 > num12)
1344 {
1345 continue;
1346 }
1347 goto IL_0278;
1348 }
1349 goto IL_0290;
1350 }
static bool IsHardwareAccelerated
Definition Vector.cs:14
static int MoveMask(Vector256< sbyte > value)
Definition Avx2.cs:1578
static Vector256< sbyte > CompareEqual(Vector256< sbyte > left, Vector256< sbyte > right)
Definition Avx2.cs:512
static new bool IsSupported
Definition Avx2.cs:15
static int MoveMask(Vector128< sbyte > value)
Definition Sse2.cs:772
static Vector128< sbyte > CompareEqual(Vector128< sbyte > left, Vector128< sbyte > right)
Definition Sse2.cs:232
static new bool IsSupported
Definition Sse2.cs:60
static Vector< byte > LoadVector(ref byte start, nuint offset)
static Vector128< byte > LoadVector128(ref byte start, nuint offset)
static ushort LoadUShort(ref byte start)
static nuint LoadNUInt(ref byte start)
static uint LoadUInt(ref byte start)
static Vector256< byte > LoadVector256(ref byte start, nuint offset)

References System.Runtime.Intrinsics.X86.Sse2.CompareEqual(), System.Runtime.Intrinsics.X86.Avx2.CompareEqual(), System.Collections.Generic.Dictionary< TKey, TValue >.Count, System.Numerics.Vector< T >.IsHardwareAccelerated, System.Runtime.Intrinsics.X86.Avx2.IsSupported, System.Runtime.Intrinsics.X86.Sse2.IsSupported, System.length, System.SpanHelpers.LoadNUInt(), System.SpanHelpers.LoadUInt(), System.SpanHelpers.LoadUShort(), System.SpanHelpers.LoadVector(), System.SpanHelpers.LoadVector128(), System.SpanHelpers.LoadVector256(), System.Runtime.Intrinsics.X86.Sse2.MoveMask(), System.Runtime.Intrinsics.X86.Avx2.MoveMask(), System.offset, and System.value.

Referenced by System.MemoryExtensions.EndsWith< T >(), System.MemoryExtensions.EndsWith< T >(), System.MdUtf8String.Equals(), System.String.EqualsHelper(), System.SpanHelpers.IndexOf(), System.SpanHelpers.IndexOf(), System.SpanHelpers.IndexOf< T >(), System.SpanHelpers.LastIndexOf(), System.SpanHelpers.LastIndexOf< T >(), System.MemoryExtensions.SequenceEqual< T >(), System.MemoryExtensions.SequenceEqual< T >(), System.MemoryExtensions.SequenceEqual< T >(), System.String.StartsWith(), System.MemoryExtensions.StartsWith< T >(), and System.MemoryExtensions.StartsWith< T >().