• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
isSet(cl_bitfield bits)35     bool isSet(cl_bitfield bits) const { return (mBits & bits) != 0u; }
isSet(const BitField & other)36     bool isSet(const BitField &other) const { return (mBits & other.mBits) != 0u; }
isNotSet(cl_bitfield bits)37     bool isNotSet(cl_bitfield bits) const { return (mBits & bits) == 0u; }
isNotSet(const BitField & other)38     bool isNotSet(const BitField &other) const { return (mBits & other.mBits) == 0u; }
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 (isSet(bits1) ? 1 : 0) + (isSet(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 (isSet(bits1) ? 1 : 0) + (isSet(bits2) ? 1 : 0) + (isSet(bits3) ? 1 : 0) <= 1;
51     }
52 
mask(cl_bitfield bits)53     BitField mask(cl_bitfield bits) const { return BitField(mBits & bits); }
mask(const BitField & other)54     BitField mask(const BitField &other) const { return BitField(mBits & other.mBits); }
55 
set(cl_bitfield bits)56     void set(cl_bitfield bits) { mBits |= bits; }
set(const BitField & other)57     void set(const BitField &other) { mBits |= other.mBits; }
clear(cl_bitfield bits)58     void clear(cl_bitfield bits) { mBits &= ~bits; }
clear(const BitField & other)59     void clear(const BitField &other) { mBits &= ~other.mBits; }
60 
61   private:
62     cl_bitfield mBits;
63 };
64 
65 static_assert(sizeof(BitField) == sizeof(cl_bitfield), "Type size mismatch");
66 
67 using DeviceType                = BitField;
68 using DeviceFpConfig            = BitField;
69 using DeviceExecCapabilities    = BitField;
70 using DeviceSvmCapabilities     = BitField;
71 using CommandQueueProperties    = BitField;
72 using DeviceAffinityDomain      = BitField;
73 using MemFlags                  = BitField;
74 using SVM_MemFlags              = BitField;
75 using MemMigrationFlags         = BitField;
76 using MapFlags                  = BitField;
77 using KernelArgTypeQualifier    = BitField;
78 using DeviceAtomicCapabilities  = BitField;
79 using DeviceEnqueueCapabilities = BitField;
80 
81 }  // namespace cl
82 
83 #endif  // LIBANGLE_CLBITFIELD_H_
84