xref: /aosp_15_r20/external/angle/src/libANGLE/CLBitField.h (revision 8975f5c5ed3d1c378011245431ada316dfb6f244)
1 //
2 // Copyright 2021 The ANGLE Project Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5 //
6 // CLBitField.h: A bit field class that encapsulates the cl_bitfield type.
7 
8 #ifndef LIBANGLE_CLBITFIELD_H_
9 #define LIBANGLE_CLBITFIELD_H_
10 
11 #include <angle_cl.h>
12 
13 namespace cl
14 {
15 
16 class BitField
17 {
18   public:
BitField()19     BitField() noexcept : mBits(0u) {}
BitField(cl_bitfield bits)20     explicit BitField(cl_bitfield bits) noexcept : mBits(bits) {}
21 
22     BitField &operator=(cl_bitfield bits)
23     {
24         mBits = bits;
25         return *this;
26     }
27 
28     bool operator==(cl_bitfield bits) const { return mBits == bits; }
29     bool operator!=(cl_bitfield bits) const { return mBits != bits; }
30     bool operator==(const BitField &other) const { return mBits == other.mBits; }
31     bool operator!=(const BitField &other) const { return mBits != other.mBits; }
32 
get()33     cl_bitfield get() const { return mBits; }
34 
intersects(cl_bitfield bits)35     bool intersects(cl_bitfield bits) const { return (mBits & bits) != 0u; }
intersects(const BitField & other)36     bool intersects(const BitField &other) const { return (mBits & other.mBits) != 0u; }
excludes(cl_bitfield bits)37     bool excludes(cl_bitfield bits) const { return !intersects(bits); }
excludes(const BitField & other)38     bool excludes(const BitField &other) const { return !intersects(mBits); }
39 
hasOtherBitsThan(cl_bitfield bits)40     bool hasOtherBitsThan(cl_bitfield bits) const { return (mBits & ~bits) != 0u; }
hasOtherBitsThan(const BitField & other)41     bool hasOtherBitsThan(const BitField &other) const { return (mBits & ~other.mBits) != 0u; }
42 
areMutuallyExclusive(cl_bitfield bits1,cl_bitfield bits2)43     bool areMutuallyExclusive(cl_bitfield bits1, cl_bitfield bits2) const
44     {
45         return (intersects(bits1) ? 1 : 0) + (intersects(bits2) ? 1 : 0) <= 1;
46     }
47 
areMutuallyExclusive(cl_bitfield bits1,cl_bitfield bits2,cl_bitfield bits3)48     bool areMutuallyExclusive(cl_bitfield bits1, cl_bitfield bits2, cl_bitfield bits3) const
49     {
50         return (intersects(bits1) ? 1 : 0) + (intersects(bits2) ? 1 : 0) +
51                    (intersects(bits3) ? 1 : 0) <=
52                1;
53     }
54 
mask(cl_bitfield bits)55     BitField mask(cl_bitfield bits) const { return BitField(mBits & bits); }
mask(const BitField & other)56     BitField mask(const BitField &other) const { return BitField(mBits & other.mBits); }
57 
set(cl_bitfield bits)58     void set(cl_bitfield bits) { mBits |= bits; }
set(const BitField & other)59     void set(const BitField &other) { mBits |= other.mBits; }
clear(cl_bitfield bits)60     void clear(cl_bitfield bits) { mBits &= ~bits; }
clear(const BitField & other)61     void clear(const BitField &other) { mBits &= ~other.mBits; }
62 
63   private:
64     cl_bitfield mBits;
65 };
66 
67 static_assert(sizeof(BitField) == sizeof(cl_bitfield), "Type size mismatch");
68 
69 using DeviceType                = BitField;
70 using DeviceFpConfig            = BitField;
71 using DeviceExecCapabilities    = BitField;
72 using DeviceSvmCapabilities     = BitField;
73 using CommandQueueProperties    = BitField;
74 using DeviceAffinityDomain      = BitField;
75 using MemFlags                  = BitField;
76 using SVM_MemFlags              = BitField;
77 using MemMigrationFlags         = BitField;
78 using MapFlags                  = BitField;
79 using KernelArgTypeQualifier    = BitField;
80 using DeviceAtomicCapabilities  = BitField;
81 using DeviceEnqueueCapabilities = BitField;
82 
83 }  // namespace cl
84 
85 #endif  // LIBANGLE_CLBITFIELD_H_
86