Skip to content

Commit

Permalink
Fix big endian issue in Interlocked test cases (#101429)
Browse files Browse the repository at this point in the history
Fix big indian issue wiht BitConverted as part of intercloked test cases.
These were causing failures in runtime_community pipeline

---------

Co-authored-by: root <root@t8375036.lnxero1.boe>
  • Loading branch information
giritrivedi and root committed Apr 25, 2024
1 parent 5bbd0e1 commit c028937
Showing 1 changed file with 2 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public static unsafe ushort Exchange(ref ushort location1, ushort value)
nuint offset = Unsafe.OpportunisticMisalignment(ref location1, sizeof(uint));
ref uint alignedRef = ref Unsafe.As<ushort, uint>(ref Unsafe.SubtractByteOffset(ref location1, offset));
int bitOffset =
(int)((BitConverter.IsLittleEndian ? offset : sizeof(uint) - offset - sizeof(byte)) * 8); // to bit offset
(int)((BitConverter.IsLittleEndian ? offset : sizeof(uint) - offset - sizeof(ushort)) * 8); // to bit offset
Debug.Assert(bitOffset is 0 or 16);
uint mask = ~((uint)ushort.MaxValue << bitOffset);
uint shiftedValue = (uint)value << bitOffset;
Expand Down Expand Up @@ -308,7 +308,7 @@ public static unsafe ushort CompareExchange(ref ushort location1, ushort value,
nuint offset = Unsafe.OpportunisticMisalignment(ref location1, sizeof(uint));
ref uint alignedRef = ref Unsafe.As<ushort, uint>(ref Unsafe.SubtractByteOffset(ref location1, offset));
int bitOffset =
(int)((BitConverter.IsLittleEndian ? offset : sizeof(uint) - offset - sizeof(byte)) * 8); // to bit offset
(int)((BitConverter.IsLittleEndian ? offset : sizeof(uint) - offset - sizeof(ushort)) * 8); // to bit offset
Debug.Assert(bitOffset is 0 or 16);
uint mask = ~((uint)ushort.MaxValue << bitOffset);
uint shiftedValue = (uint)value << bitOffset;
Expand Down

0 comments on commit c028937

Please sign in to comment.