|
|
|
@ -63,9 +63,10 @@ internal partial struct Block8x8 |
|
|
|
|
|
|
|
public static Block8x8 Load(Span<short> data) |
|
|
|
{ |
|
|
|
Unsafe.SkipInit(out Block8x8 result); |
|
|
|
result.LoadFrom(data); |
|
|
|
return result; |
|
|
|
DebugGuard.MustBeGreaterThanOrEqualTo(data.Length, Size, "data is too small"); |
|
|
|
|
|
|
|
ref byte src = ref Unsafe.As<short, byte>(ref MemoryMarshal.GetReference(data)); |
|
|
|
return Unsafe.ReadUnaligned<Block8x8>(ref src); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
@ -93,9 +94,10 @@ internal partial struct Block8x8 |
|
|
|
/// </summary>
|
|
|
|
public void CopyTo(Span<short> destination) |
|
|
|
{ |
|
|
|
ref byte selfRef = ref Unsafe.As<Block8x8, byte>(ref this); |
|
|
|
ref byte destRef = ref MemoryMarshal.GetReference(MemoryMarshal.Cast<short, byte>(destination)); |
|
|
|
Unsafe.CopyBlockUnaligned(ref destRef, ref selfRef, Size * sizeof(short)); |
|
|
|
DebugGuard.MustBeGreaterThanOrEqualTo(destination.Length, Size, "destination is too small"); |
|
|
|
|
|
|
|
ref byte destRef = ref Unsafe.As<short, byte>(ref MemoryMarshal.GetReference(destination)); |
|
|
|
Unsafe.WriteUnaligned(ref destRef, this); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
@ -124,19 +126,6 @@ internal partial struct Block8x8 |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Load raw 16bit integers from source.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="source">Source</param>
|
|
|
|
[MethodImpl(InliningOptions.ShortMethod)] |
|
|
|
public void LoadFrom(Span<short> source) |
|
|
|
{ |
|
|
|
ref byte sourceRef = ref Unsafe.As<short, byte>(ref MemoryMarshal.GetReference(source)); |
|
|
|
ref byte destRef = ref Unsafe.As<Block8x8, byte>(ref this); |
|
|
|
|
|
|
|
Unsafe.CopyBlockUnaligned(ref destRef, ref sourceRef, Size * sizeof(short)); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Cast and copy <see cref="Size"/> <see cref="int"/>-s from the beginning of 'source' span.
|
|
|
|
/// </summary>
|
|
|
|
|