Skip to content

Commit 86b4e18

Browse files
committed
Added missing attributes and reduced code size + fixed typos
1 parent d2f808d commit 86b4e18

File tree

66 files changed

+4427
-4457
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+4427
-4457
lines changed

Runtime/Data/Constants.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#endregion
66

77
using System.ComponentModel;
8+
using System.Runtime.CompilerServices;
89

910
namespace Unity.Mathematics
1011
{
@@ -118,8 +119,7 @@ public static partial class mathx
118119
// Utility Constants ----------------------------------------------------
119120

120121
///MethodImplOptions.AggressiveInlining
121-
public const int INLINE = 256; // MethodImpl.AggressiveInlining
122-
public const int IL = 256; // MethodImpl.AggressiveInlining
122+
public const MethodImplOptions IL = MethodImplOptions.AggressiveInlining; // MethodImpl.AggressiveInlining
123123
public const EditorBrowsableState NEVER = EditorBrowsableState.Never; // EditorBrowsableState.Never
124124
}
125125
}

Runtime/Structs/byte1.cs

Lines changed: 56 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@
77
using System;
88
using System.Runtime.CompilerServices;
99

10+
using MI = System.Runtime.CompilerServices.MethodImplAttribute;
11+
using static Unity.Mathematics.mathx;
12+
1013
namespace Unity.Mathematics
1114
{
12-
/// A 8-bit byte for Unity.Mathematics interoperability
15+
/// A 8-bit struct for Unity.Mathematics interoperability
1316
[Serializable]
14-
public struct byte1 :
15-
IEquatable<byte1>,
16-
IEquatable<byte>,
17-
IFormattable
17+
public struct byte1 : IEquatable<byte1>, IEquatable<byte>, IFormattable
1818
{
1919
/// The raw 8 bit value of the byte.
2020
internal byte value;
@@ -32,35 +32,33 @@ public struct byte1 :
3232
/// The minimum finite byte value as a byte.
3333
public static readonly byte1 MinValueAsByte1 = new(MinValue) ;
3434

35-
private const MethodImplOptions INLINE = MethodImplOptions.AggressiveInlining;
36-
3735
// Constructors
38-
[MethodImpl(INLINE)] public byte1(byte1 x) => value = x.value;
39-
[MethodImpl(INLINE)] public byte1(byte x) => value = x;
40-
[MethodImpl(INLINE)] public byte1(int x) => value = (byte)x;
41-
[MethodImpl(INLINE)] public byte1(float v) => value = (byte)v;
42-
[MethodImpl(INLINE)] public byte1(double v) => value = (byte)v;
36+
[MI(IL)] public byte1(byte1 x) => value = x.value;
37+
[MI(IL)] public byte1(byte x) => value = x;
38+
[MI(IL)] public byte1(int x) => value = (byte)x;
39+
[MI(IL)] public byte1(float v) => value = (byte)v;
40+
[MI(IL)] public byte1(double v) => value = (byte)v;
4341

4442
// Implicit Casts
45-
[MethodImpl(INLINE)] public static implicit operator byte1(byte v) => new(v);
46-
[MethodImpl(INLINE)] public static implicit operator byte1(float v) => new(v);
47-
[MethodImpl(INLINE)] public static implicit operator byte1(double v) => new(v);
48-
[MethodImpl(INLINE)] public static implicit operator byte1(int d) => (byte)d;
49-
[MethodImpl(INLINE)] public static implicit operator byte1(half d) => (byte)d;
50-
[MethodImpl(INLINE)] public static implicit operator byte(byte1 v) => v.value;
43+
[MI(IL)] public static implicit operator byte1(byte v) => new(v);
44+
[MI(IL)] public static implicit operator byte1(float v) => new(v);
45+
[MI(IL)] public static implicit operator byte1(double v) => new(v);
46+
[MI(IL)] public static implicit operator byte1(int d) => (byte)d;
47+
[MI(IL)] public static implicit operator byte1(half d) => (byte)d;
48+
[MI(IL)] public static implicit operator byte(byte1 v) => v.value;
5149
// Explicit casts
52-
[MethodImpl(INLINE)] public static explicit operator float(byte1 d) => d;
53-
[MethodImpl(INLINE)] public static explicit operator double(byte1 d) => d;
54-
[MethodImpl(INLINE)] public static explicit operator int(byte1 d) => d;
55-
[MethodImpl(INLINE)] public static explicit operator uint(byte1 d) => d;
56-
[MethodImpl(INLINE)] public static explicit operator short(byte1 d) => d;
57-
[MethodImpl(INLINE)] public static explicit operator ushort(byte1 d) => d;
58-
[MethodImpl(INLINE)] public static explicit operator half(byte1 d) => (half)d.value;
50+
[MI(IL)] public static explicit operator float(byte1 d) => d;
51+
[MI(IL)] public static explicit operator double(byte1 d) => d;
52+
[MI(IL)] public static explicit operator int(byte1 d) => d;
53+
[MI(IL)] public static explicit operator uint(byte1 d) => d;
54+
[MI(IL)] public static explicit operator short(byte1 d) => d;
55+
[MI(IL)] public static explicit operator ushort(byte1 d) => d;
56+
[MI(IL)] public static explicit operator half(byte1 d) => (half)d.value;
5957

6058
// /// <summary>Returns the bit pattern of a float as an int.</summary>
6159
// /// <param name="x">The float bits to copy.</param>
6260
// /// <returns>The byte with the same bit pattern as the input.</returns>
63-
// [MethodImpl(INLINE)]
61+
// [MI(IL)]
6462
// public static int asbyte(float x) {
6563
// ByteFloatUnion u;
6664
// u.byteValue = 0;
@@ -77,99 +75,99 @@ public struct byte1 :
7775

7876
/// Returns whether two byte values are bitwise equivalent.
7977
/// Returns True if the two byte values are bitwise equivalent, false otherwise.
80-
[MethodImpl(INLINE)] public static bool operator ==(byte1 a, byte1 b) => a.value == b.value;
78+
[MI(IL)] public static bool operator ==(byte1 a, byte1 b) => a.value == b.value;
8179
/// Returns whether two byte values are not bitwise equivalent.
82-
[MethodImpl(INLINE)] public static bool operator !=(byte1 a, byte1 b) => a.value != b.value;
80+
[MI(IL)] public static bool operator !=(byte1 a, byte1 b) => a.value != b.value;
8381
/// Returns True if the two byte values are not bitwise equivalent, false otherwise.
84-
[MethodImpl(INLINE)] public static bool operator <(byte1 a, byte1 b) => a.value < b.value;
82+
[MI(IL)] public static bool operator <(byte1 a, byte1 b) => a.value < b.value;
8583
/// Returns True if the two byte values are not bitwise equivalent, false otherwise.
86-
[MethodImpl(INLINE)] public static bool operator > (byte1 a, byte1 b) => a.value > b.value;
84+
[MI(IL)] public static bool operator > (byte1 a, byte1 b) => a.value > b.value;
8785
/// Returns True if the a is less or equal than the b, false otherwise.
88-
[MethodImpl(INLINE)] public static bool operator <= (byte1 a, byte1 b) => a.value <= b.value;
86+
[MI(IL)] public static bool operator <= (byte1 a, byte1 b) => a.value <= b.value;
8987
/// <returns>True if the a is greater or equal than the b, false otherwise.</returns>
90-
[MethodImpl(INLINE)] public static bool operator >= (byte1 a, byte1 b) => a.value >= b.value;
88+
[MI(IL)] public static bool operator >= (byte1 a, byte1 b) => a.value >= b.value;
9189

9290

9391
/// Returns the result of a modulation of two byte1 vectors into a byte1
94-
[MethodImpl(INLINE)] public static byte1 operator %(byte1 a, byte1 b) => a.value % b.value;
92+
[MI(IL)] public static byte1 operator %(byte1 a, byte1 b) => a.value % b.value;
9593
/// Returns the result of a division of two byte1 vectors into a float
96-
[MethodImpl(INLINE)] public static float operator /(byte1 a, byte1 b) => a.value / (float)b.value;
94+
[MI(IL)] public static float operator /(byte1 a, byte1 b) => a.value / (float)b.value;
9795
/// Returns the result of a multiplication of two byte1 vectors into a byte1
98-
[MethodImpl(INLINE)] public static int operator *(byte1 a, byte1 b) => a.value * b.value;
96+
[MI(IL)] public static int operator *(byte1 a, byte1 b) => a.value * b.value;
9997

10098

10199
/// Returns the result of a bitwise NOT of a byte1 vector into a byte1
102-
[MethodImpl(INLINE)] public static int operator +(byte1 a, byte1 b) => a.value + b.value;
100+
[MI(IL)] public static int operator +(byte1 a, byte1 b) => a.value + b.value;
103101
/// Returns the result of a bitwise NOT of a byte1 vector into a byte1
104-
[MethodImpl(INLINE)] public static int operator -(byte1 a, byte1 b) => a.value - b.value;
102+
[MI(IL)] public static int operator -(byte1 a, byte1 b) => a.value - b.value;
105103
/// Returns the result of a bitwise NOT of a byte1 vector into a byte1
106-
[MethodImpl(INLINE)] public static byte1 operator --(byte1 a) => --a.value;
104+
[MI(IL)] public static byte1 operator --(byte1 a) => --a.value;
107105
/// Returns the result of a bitwise NOT of a byte1 vector into a byte1
108-
[MethodImpl(INLINE)] public static byte1 operator ++(byte1 a) => ++a.value;
106+
[MI(IL)] public static byte1 operator ++(byte1 a) => ++a.value;
109107

110108
/// <summary>Returns the result of a componentwise bitwise not operation on an byte1 vector.</summary>
111-
[MethodImpl(INLINE)]public static int operator ~(byte1 val) => ~val.value;
109+
[MI(IL)]public static int operator ~(byte1 val) => ~val.value;
112110

113111
/// Returns the result of a bitwise AND of two byte1 vectors into a byte1
114-
[MethodImpl(INLINE)] public static int operator &(byte1 a, byte1 b) => a.value & b.value;
112+
[MI(IL)] public static int operator &(byte1 a, byte1 b) => a.value & b.value;
115113
/// <summary>Returns the result of a componentwise bitwise and operation on an byte1 vector and an int value.</summary>
116-
[MethodImpl(INLINE)] public static int operator &(byte1 a, int b) => a.value & b;
114+
[MI(IL)] public static int operator &(byte1 a, int b) => a.value & b;
117115
/// <summary>Returns the result of a componentwise bitwise and operation on an int value and an byte1 vector.</summary>
118-
[MethodImpl(INLINE)] public static int operator &(int a, byte1 b) => a & b.value;
116+
[MI(IL)] public static int operator &(int a, byte1 b) => a & b.value;
119117

120118
/// Returns the result of a bitwise OR of two byte1 vectors into a byte1
121-
[MethodImpl(INLINE)] public static int operator |(byte1 a, byte1 b) => a.value | b.value;
119+
[MI(IL)] public static int operator |(byte1 a, byte1 b) => a.value | b.value;
122120
/// <summary>Returns the result of a componentwise bitwise or operation on an byte1 vector and an int value.</summary>
123-
[MethodImpl(INLINE)] public static int operator |(byte1 a, int b) => a.value | b;
121+
[MI(IL)] public static int operator |(byte1 a, int b) => a.value | b;
124122
/// <summary>Returns the result of a componentwise bitwise or operation on an int value and an byte1 vector.</summary>
125-
[MethodImpl(INLINE)] public static int operator |(int a, byte1 b) => a | b.value;
123+
[MI(IL)] public static int operator |(int a, byte1 b) => a | b.value;
126124

127125
/// Returns the result of a bitwise XOR of two byte1 vectors into a byte1
128-
[MethodImpl(INLINE)] public static int operator ^(byte1 a, byte1 b) => a.value ^ b.value;
126+
[MI(IL)] public static int operator ^(byte1 a, byte1 b) => a.value ^ b.value;
129127
/// <summary>Returns the result of a componentwise bitwise exclusive or operation on an byte1 vector and an int value.</summary>
130-
[MethodImpl(INLINE)] public static int operator ^(byte1 a, int b) => a.value ^ b;
128+
[MI(IL)] public static int operator ^(byte1 a, int b) => a.value ^ b;
131129
/// <summary>Returns the result of a componentwise bitwise exclusive or operation on an int value and an byte1 vector.</summary>
132-
[MethodImpl(INLINE)] public static int operator ^(int a, byte1 b) => a ^ b.value;
130+
[MI(IL)] public static int operator ^(int a, byte1 b) => a ^ b.value;
133131

134132

135133
/// Returns true if the byte is bitwise equivalent to a given half, false otherwise.
136134
/// <returns>True if the byte value is bitwise equivalent to the input, false otherwise.</returns>
137-
[MethodImpl(INLINE)]
135+
[MI(IL)]
138136
public bool Equals(byte1 b) => value == b.value;
139137

140138
public bool Equals(byte b) => value == b;
141139

142140
/// Returns true if the byte is equal to a given half, false otherwise.
143141
/// <param name="o">Right hand side object to use in comparison.</param>
144142
/// <returns>True if the object is of type byte and is bitwise equivalent, false otherwise.</returns>
145-
[MethodImpl(INLINE)] public override bool Equals(object o) => o is byte1 converted && Equals(converted);
143+
[MI(IL)] public override bool Equals(object o) => o is byte1 converted && Equals(converted);
146144

147145
/// Returns a hash code for the byte.
148146
/// <returns>The computed hash code of the byte.</returns>
149-
[MethodImpl(INLINE)] public override int GetHashCode() => value.GetHashCode();
147+
[MI(IL)] public override int GetHashCode() => value.GetHashCode();
150148

151149
/// Returns a string representation of the byte.
152150
/// <returns>The string representation of the byte.</returns>
153-
[MethodImpl(INLINE)] public override string ToString() => value.ToString();
151+
[MI(IL)] public override string ToString() => value.ToString();
154152

155153

156154
/// Returns a string representation of the byte using a specified format and culture-specific format information.
157155
/// <param name="format">The format string to use during string formatting.</param>
158156
/// <param name="formatProvider">The format provider to use during string formatting.</param>
159157
/// <returns>The string representation of the byte.</returns>
160-
[MethodImpl(INLINE)] public string ToString(string format, IFormatProvider formatProvider) => value.ToString(format, formatProvider);
158+
[MI(IL)] public string ToString(string format, IFormatProvider formatProvider) => value.ToString(format, formatProvider);
161159
}
162160

163161
public static partial class mathx
164162
{
165163
/// Returns a byte value constructed from a byte values.
166-
[MethodImpl(INLINE)] public static byte1 byte1(byte1 x) => new(x);
164+
[MI(IL)] public static byte1 byte1(byte1 x) => new(x);
167165
/// Returns a byte value constructed from a float value.
168-
[MethodImpl(INLINE)] public static byte1 byte1(float v) => new(v);
166+
[MI(IL)] public static byte1 byte1(float v) => new(v);
169167
/// Returns a byte value constructed from a double value.
170-
[MethodImpl(INLINE)] public static byte1 byte1(double v) => new(v);
168+
[MI(IL)] public static byte1 byte1(double v) => new(v);
171169

172170
/// Returns a uint hash code of a byte value.
173-
[MethodImpl(INLINE)] public static uint hash(this byte1 v) => v.value * 0x745ED837u + 0x816EFB5Du;
171+
[MI(IL)] public static uint hash(this byte1 v) => v.value * 0x745ED837u + 0x816EFB5Du;
174172
}
175173
}

0 commit comments

Comments
 (0)