11#include "dawn/io/common.hxx"
12#include "dawn/io/ddata.hxx"
18inline bool isBitwiseDtype(uint8_t dtype)
24inline size_t getLogicalElementBits(uint8_t dtype,
size_t storageSize)
29inline size_t getLogicalBits(uint8_t dtype,
size_t storageSize,
size_t dim)
31 return dim * getLogicalElementBits(dtype, storageSize);
34inline size_t getLogicalBits(
const CIOCommon *io)
36 return getLogicalBits(io->getDtype(), io->getDtypeSize(), io->getDataDim());
39inline size_t getLogicalBits(io_ddata_t *data)
41 return getLogicalBits(data->getDtype(), data->getSize(), data->getItems());
44inline bool readLogicalBit(uint8_t dtype,
size_t storageSize,
const void *data,
size_t bitIndex)
46 const size_t elementBits = getLogicalElementBits(dtype, storageSize);
47 const size_t element = bitIndex / elementBits;
48 const size_t bitInElem = bitIndex % elementBits;
49 const uint8_t *ptr =
static_cast<const uint8_t *
>(data) + element * storageSize;
56 return ((ptr[bitInElem / 8] >> (bitInElem % 8)) & 1u) != 0;
59inline bool readLogicalBit(
const CIOCommon *io,
const void *data,
size_t bitIndex)
61 return readLogicalBit(io->getDtype(), io->getDtypeSize(), data, bitIndex);
64inline void writeLogicalBit(uint8_t dtype,
70 const size_t elementBits = getLogicalElementBits(dtype, storageSize);
71 const size_t element = bitIndex / elementBits;
72 const size_t bitInElem = bitIndex % elementBits;
73 uint8_t *ptr =
static_cast<uint8_t *
>(data) + element * storageSize;
77 ptr[0] = value ? 1 : 0;
83 ptr[bitInElem / 8] |=
static_cast<uint8_t
>(1u << (bitInElem % 8));
87inline void writeLogicalBit(CIOCommon *io,
void *data,
size_t bitIndex,
bool value)
89 writeLogicalBit(io->getDtype(), io->getDtypeSize(), data, bitIndex, value);
Out-of-tree user-extension hooks for Dawn.
@ DTYPE_ANY
Wildcard data type (matches any actual type).
@ DTYPE_BLOCK
Opaque block/byte-stream data type.
@ DTYPE_CHAR
Character/string type (null-terminated, 4-byte aligned).
@ DTYPE_BOOL
Boolean data type (stored in 32-bit container).