forked from CarlVerret/csFastFloat
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestSIMD.cs
More file actions
130 lines (82 loc) · 2.42 KB
/
Copy pathTestSIMD.cs
File metadata and controls
130 lines (82 loc) · 2.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
using csFastFloat;
using csFastFloat.Structures;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TestcsFastFloat.Tests;
using Xunit;
#if NET5_0
using System.Runtime.Intrinsics.X86;
#endif
namespace TestcsFastFloat.Basic.SIMD
{
public class TestsSIMD : BaseTestClass
{
#if NET5_0
[InlineData(true, "12345678")]
[InlineData(true, "123456789")]
[InlineData(false, "1")]
[InlineData(false, "12")]
[InlineData(false, "123")]
[InlineData(false, "1234")]
[InlineData(false, "12345")]
[InlineData(false, "123456")]
[InlineData(false, "1234567")]
[InlineData(false, "/1234567")]
[InlineData(false, ":1234567")]
[InlineData(false, "1:234567")]
[InlineData(false, "1234567:")]
[InlineData(false, "1234567 ")]
[InlineData(false, "1234 567")]
[Theory]
#pragma warning disable xUnit1026 // Theory methods should use all of their parameters
public unsafe void EvalAndParseEightDigits_SIMD_works_Scenarios(bool shouldPass, string sut)
#pragma warning restore xUnit1026 // Theory methods should use all of their parameters
{
Skip.If(!Sse41.IsSupported, "No SIMD support");
fixed (char* pos = sut)
{
Assert.Equal(shouldPass, Utils.TryParseEightConsecutiveDigits_SIMD(pos, out uint res));
}
}
[SkippableFact]
public void EvalAndParseEightDigits_SIMD_works_RandomInput()
{
Skip.If(!Sse41.IsSupported, "No SIMD support");
Random RandNum = new Random();
for (int i = 0; i != 850000; i++)
{
int RandomNumber = RandNum.Next(10000000, 99999999);
string sut = RandomNumber.ToString();
unsafe
{
fixed (char* pos = sut)
{
Assert.True(Utils.TryParseEightConsecutiveDigits_SIMD(pos, out uint res));
Assert.Equal(double.Parse(sut), res);
}
}
}
}
[SkippableFact]
public void parse_eight_digits_simd_works()
{
Skip.If(!Sse41.IsSupported, "No SIMD support");
for (int i = 0; i <= 9; i++)
{
string sut = new string(i.ToString()[0], 8);
unsafe
{
fixed (char* pos = sut)
{
Assert.True(Utils.TryParseEightConsecutiveDigits_SIMD(pos, out uint res));
Assert.Equal(double.Parse(sut), res);
}
}
}
}
#endif
}
}