More routines for performing atomic bitwise AND/OR/XOR operations

This commit is contained in:
Rafal Kupiec 2023-02-12 23:11:23 +01:00
parent 5a86d61b78
commit 9e5fb84412
Signed by: belliash
GPG Key ID: 4E829243E0CFE6B4
2 changed files with 312 additions and 0 deletions

View File

@ -14,6 +14,26 @@
#include <xttypes.h> #include <xttypes.h>
XTFASTCALL
CHAR
RtlAtomicAnd8(IN VOLATILE PCHAR Address,
IN CHAR Mask);
XTFASTCALL
SHORT
RtlAtomicAnd16(IN VOLATILE PSHORT Address,
IN SHORT Mask);
XTFASTCALL
LONG
RtlAtomicAnd32(IN VOLATILE PLONG Address,
IN LONG Mask);
XTFASTCALL
LONGLONG
RtlAtomicAnd64(IN VOLATILE PLONGLONG Address,
IN LONGLONG Mask);
XTFASTCALL XTFASTCALL
CHAR CHAR
RtlAtomicCompareExchange8(IN VOLATILE PCHAR Address, RtlAtomicCompareExchange8(IN VOLATILE PCHAR Address,
@ -121,6 +141,46 @@ XTFASTCALL
LONGLONG LONGLONG
RtlAtomicIncrement64(IN VOLATILE PLONGLONG Address); RtlAtomicIncrement64(IN VOLATILE PLONGLONG Address);
XTFASTCALL
CHAR
RtlAtomicOr8(IN VOLATILE PCHAR Address,
IN CHAR Mask);
XTFASTCALL
SHORT
RtlAtomicOr16(IN VOLATILE PSHORT Address,
IN SHORT Mask);
XTFASTCALL
LONG
RtlAtomicOr32(IN VOLATILE PLONG Address,
IN LONG Mask);
XTFASTCALL
LONGLONG
RtlAtomicOr64(IN VOLATILE PLONGLONG Address,
IN LONGLONG Mask);
XTFASTCALL
CHAR
RtlAtomicXor8(IN VOLATILE PCHAR Address,
IN CHAR Mask);
XTFASTCALL
SHORT
RtlAtomicXor16(IN VOLATILE PSHORT Address,
IN SHORT Mask);
XTFASTCALL
LONG
RtlAtomicXor32(IN VOLATILE PLONG Address,
IN LONG Mask);
XTFASTCALL
LONGLONG
RtlAtomicXor64(IN VOLATILE PLONGLONG Address,
IN LONGLONG Mask);
XTAPI XTAPI
SIZE_T SIZE_T
RtlCompareMemory(IN PCVOID LeftBuffer, RtlCompareMemory(IN PCVOID LeftBuffer,

View File

@ -9,6 +9,90 @@
#include <xtos.h> #include <xtos.h>
/**
* Performs an atomic bitwise AND operation on the 8-bit value.
*
* @param Address
* Supplies the address of the value on which the bitwise AND operation is to be performed.
*
* @param Mask
* Supplies the mask with which the bitwise AND operation is to be performed
*
* @return This routine returns the initial value at the given address.
*
* @since XT 1.0
*/
XTFASTCALL
CHAR
RtlAtomicAnd8(IN VOLATILE PCHAR Address,
IN CHAR Mask)
{
return __sync_fetch_and_and(Address, Mask);
}
/**
* Performs an atomic bitwise AND operation on the 16-bit value.
*
* @param Address
* Supplies the address of the value on which the bitwise AND operation is to be performed.
*
* @param Mask
* Supplies the mask with which the bitwise AND operation is to be performed
*
* @return This routine returns the initial value at the given address.
*
* @since XT 1.0
*/
XTFASTCALL
SHORT
RtlAtomicAnd16(IN VOLATILE PSHORT Address,
IN SHORT Mask)
{
return __sync_fetch_and_and(Address, Mask);
}
/**
* Performs an atomic bitwise AND operation on the 32-bit value.
*
* @param Address
* Supplies the address of the value on which the bitwise AND operation is to be performed.
*
* @param Mask
* Supplies the mask with which the bitwise AND operation is to be performed
*
* @return This routine returns the initial value at the given address.
*
* @since XT 1.0
*/
XTFASTCALL
LONG
RtlAtomicAnd32(IN VOLATILE PLONG Address,
IN LONG Mask)
{
return __sync_fetch_and_and(Address, Mask);
}
/**
* Performs an atomic bitwise AND operation on the 64-bit value.
*
* @param Address
* Supplies the address of the value on which the bitwise AND operation is to be performed.
*
* @param Mask
* Supplies the mask with which the bitwise AND operation is to be performed
*
* @return This routine returns the initial value at the given address.
*
* @since XT 1.0
*/
XTFASTCALL
LONGLONG
RtlAtomicAnd64(IN VOLATILE PLONGLONG Address,
IN LONGLONG Mask)
{
return __sync_fetch_and_and(Address, Mask);
}
/** /**
* Performs atomically compare exchange operation on the 8-bit value. * Performs atomically compare exchange operation on the 8-bit value.
* *
@ -458,3 +542,171 @@ RtlAtomicIncrement64(IN VOLATILE PLONGLONG Address)
{ {
return __sync_add_and_fetch(Address, 1); return __sync_add_and_fetch(Address, 1);
} }
/**
* Performs an atomic bitwise OR operation on the 8-bit value.
*
* @param Address
* Supplies the address of the value on which the bitwise OR operation is to be performed.
*
* @param Mask
* Supplies the mask with which the bitwise OR operation is to be performed
*
* @return This routine returns the initial value at the given address.
*
* @since XT 1.0
*/
XTFASTCALL
CHAR
RtlAtomicOr8(IN VOLATILE PCHAR Address,
IN CHAR Mask)
{
return __sync_fetch_and_or(Address, Mask);
}
/**
* Performs an atomic bitwise OR operation on the 16-bit value.
*
* @param Address
* Supplies the address of the value on which the bitwise OR operation is to be performed.
*
* @param Mask
* Supplies the mask with which the bitwise OR operation is to be performed
*
* @return This routine returns the initial value at the given address.
*
* @since XT 1.0
*/
XTFASTCALL
SHORT
RtlAtomicOr16(IN VOLATILE PSHORT Address,
IN SHORT Mask)
{
return __sync_fetch_and_or(Address, Mask);
}
/**
* Performs an atomic bitwise OR operation on the 32-bit value.
*
* @param Address
* Supplies the address of the value on which the bitwise OR operation is to be performed.
*
* @param Mask
* Supplies the mask with which the bitwise OR operation is to be performed
*
* @return This routine returns the initial value at the given address.
*
* @since XT 1.0
*/
XTFASTCALL
LONG
RtlAtomicOr32(IN VOLATILE PLONG Address,
IN LONG Mask)
{
return __sync_fetch_and_or(Address, Mask);
}
/**
* Performs an atomic bitwise OR operation on the 64-bit value.
*
* @param Address
* Supplies the address of the value on which the bitwise OR operation is to be performed.
*
* @param Mask
* Supplies the mask with which the bitwise OR operation is to be performed
*
* @return This routine returns the initial value at the given address.
*
* @since XT 1.0
*/
XTFASTCALL
LONGLONG
RtlAtomicOr64(IN VOLATILE PLONGLONG Address,
IN LONGLONG Mask)
{
return __sync_fetch_and_or(Address, Mask);
}
/**
* Performs an atomic bitwise XOR operation on the 8-bit value.
*
* @param Address
* Supplies the address of the value on which the bitwise XOR operation is to be performed.
*
* @param Mask
* Supplies the mask with which the bitwise XOR operation is to be performed
*
* @return This routine returns the initial value at the given address.
*
* @since XT 1.0
*/
XTFASTCALL
CHAR
RtlAtomicXor8(IN VOLATILE PCHAR Address,
IN CHAR Mask)
{
return __sync_fetch_and_xor(Address, Mask);
}
/**
* Performs an atomic bitwise XOR operation on the 16-bit value.
*
* @param Address
* Supplies the address of the value on which the bitwise XOR operation is to be performed.
*
* @param Mask
* Supplies the mask with which the bitwise XOR operation is to be performed
*
* @return This routine returns the initial value at the given address.
*
* @since XT 1.0
*/
XTFASTCALL
SHORT
RtlAtomicXor16(IN VOLATILE PSHORT Address,
IN SHORT Mask)
{
return __sync_fetch_and_xor(Address, Mask);
}
/**
* Performs an atomic bitwise XOR operation on the 32-bit value.
*
* @param Address
* Supplies the address of the value on which the bitwise XOR operation is to be performed.
*
* @param Mask
* Supplies the mask with which the bitwise XOR operation is to be performed
*
* @return This routine returns the initial value at the given address.
*
* @since XT 1.0
*/
XTFASTCALL
LONG
RtlAtomicXor32(IN VOLATILE PLONG Address,
IN LONG Mask)
{
return __sync_fetch_and_xor(Address, Mask);
}
/**
* Performs an atomic bitwise XOR operation on the 64-bit value.
*
* @param Address
* Supplies the address of the value on which the bitwise XOR operation is to be performed.
*
* @param Mask
* Supplies the mask with which the bitwise XOR operation is to be performed
*
* @return This routine returns the initial value at the given address.
*
* @since XT 1.0
*/
XTFASTCALL
LONGLONG
RtlAtomicXor64(IN VOLATILE PLONGLONG Address,
IN LONGLONG Mask)
{
return __sync_fetch_and_xor(Address, Mask);
}