|
| 1 | +// Copyright 2018-2021 The Khronos Group. This work is licensed under a |
| 2 | +// Creative Commons Attribution 4.0 International License; see |
| 3 | +// http://creativecommons.org/licenses/by/4.0/ |
| 4 | + |
| 5 | +[[cl_khr_extended_bit_ops]] |
| 6 | +== Extended Bit Operations |
| 7 | + |
| 8 | +This extension adds OpenCL C functions for performing extended bit operations. |
| 9 | +Specifically, the following functions are added: |
| 10 | + |
| 11 | +* bitfield insert: insert bits from one source operand into another source operand. |
| 12 | +* bitfield extract: extract bits from a source operand, with sign- or zero-extension. |
| 13 | +* bit reverse: reverse the bits of a source operand. |
| 14 | + |
| 15 | +=== General Information |
| 16 | + |
| 17 | +==== Name Strings |
| 18 | + |
| 19 | +`cl_khr_extended_bit_ops` |
| 20 | + |
| 21 | +==== Version History |
| 22 | + |
| 23 | +[cols="1,1,3",options="header",] |
| 24 | +|==== |
| 25 | +| *Date* | *Version* | *Description* |
| 26 | +| 2021-04-22 | 1.0.0 | Initial version. |
| 27 | +|==== |
| 28 | + |
| 29 | +==== Dependencies |
| 30 | + |
| 31 | +This extension is written against the OpenCL 3.0 C Language Specification and the OpenCL SPIR-V Environment Specification Version V3.0.6. |
| 32 | + |
| 33 | +This extension requires OpenCL 1.0. |
| 34 | + |
| 35 | +=== New OpenCL C Functions |
| 36 | + |
| 37 | +[source] |
| 38 | +---- |
| 39 | +gentype bitfield_insert( gentype base, gentype insert, uint offset, uint count ) |
| 40 | +igentype bitfield_extract_signed( gentype base, uint offset, uint count ) |
| 41 | +ugentype bitfield_extract_unsigned( gentype base, uint offset, uint count ) |
| 42 | +gentype bit_reverse( gentype base ) |
| 43 | +---- |
| 44 | + |
| 45 | +=== Modifications to the OpenCL C Specification |
| 46 | + |
| 47 | +==== Modify Section 6.15.3. Integer Functions: |
| 48 | + |
| 49 | +Add a new Section 6.15.3.X. Extended Bit Operations: :: |
| 50 | ++ |
| 51 | +-- |
| 52 | +The functions described in the following table can be used with built-in scalar or vector integer types to perform extended bit operations. |
| 53 | +The functions that operate on vector types operate component-wise. |
| 54 | +The description is per-component. |
| 55 | + |
| 56 | +In the table below, the generic type name `gentype` refers to the built-in integer types `char`, `char__n__`, `uchar`, `uchar__n__`, `short`, `short__n__`, `ushort`, `ushort__n__`, `int`, `int__n__`, `uint`, `uint__n__`, `long`, `long__n__`, `ulong`, and `ulong__n__`. |
| 57 | +The generic type name `igentype` refers to the built-in signed integer types `char`, `char__n__`, `short`, `short__n__`, `int`, `int__n__`, `long`, and `long__n__`. |
| 58 | +The generic type name `ugentype` refers to the built-in unsigned integer types `uchar`, `uchar__n__`, `ushort`, `ushort__n__`, `uint`, `uint__n__`, `ulong`, and `ulong__n__`. |
| 59 | +_n_ is 2, 3, 4, 8, or 16. |
| 60 | + |
| 61 | +.Built-in Scalar and Vector Extended Bit Operations |
| 62 | +[cols="1a,1", options="header"] |
| 63 | +|=== |
| 64 | +|*Function* |
| 65 | +|*Description* |
| 66 | + |
| 67 | +|[source,c] |
| 68 | +---- |
| 69 | +gentype bitfield_insert( |
| 70 | + gentype base, gentype insert, |
| 71 | + uint offset, uint count) |
| 72 | +---- |
| 73 | + |
| 74 | +|Returns a copy of _base_, with a modified bitfield that comes from _insert_. |
| 75 | + |
| 76 | +Any bits of the result value numbered outside [_offset_, _offset_ + _count_ - 1] (inclusive) will come from the corresponding bits in _base_. |
| 77 | + |
| 78 | +Any bits of the result value numbered inside [_offset_, _offset_ + _count_ - 1] (inclusive) will come from the bits numbered [0, _count_ - 1] (inclusive) of _insert_. |
| 79 | + |
| 80 | +_count_ is the number of bits to be modified. |
| 81 | +If _count_ equals 0, the return value will be equal to _base_. |
| 82 | + |
| 83 | +If _count_ or _offset_ or _offset_ + _count_ is greater than number of bits in `gentype` (for scalar types) or components of `gentype` (for vector types), the result is undefined. |
| 84 | + |
| 85 | +|[source,c] |
| 86 | +---- |
| 87 | +igentype bitfield_extract_signed( |
| 88 | + gentype base, |
| 89 | + uint offset, uint count) |
| 90 | +---- |
| 91 | + |
| 92 | +|Returns an extracted bitfield from _base_ with sign extension. |
| 93 | +The type of the return value is always a signed type. |
| 94 | + |
| 95 | +The bits of _base_ numbered in [_offset_, _offset_ + _count_ - 1] (inclusive) are returned as the bits numbered in [0, _count_ - 1] (inclusive) of the result. |
| 96 | +The remaining bits in the result will be sign extended by replicating the bit numbered _offset_ + _count_ - 1 of _base_. |
| 97 | + |
| 98 | +_count_ is the number of bits to be extracted. |
| 99 | +If _count_ equals 0, the result is 0. |
| 100 | + |
| 101 | +If the _count_ or _offset_ or _offset_ + _count_ is greater than number of bits in `gentype` (for scalar types) or components of `gentype` (for vector types), the result is undefined. |
| 102 | + |
| 103 | +|[source,c] |
| 104 | +---- |
| 105 | +ugentype bitfield_extract_unsigned( |
| 106 | + gentype base, |
| 107 | + uint offset, uint count) |
| 108 | +---- |
| 109 | + |
| 110 | +|Returns an extracted bitfield from _base_ with zero extension. |
| 111 | +The type of the return value is always an unsigned type. |
| 112 | + |
| 113 | +The bits of _base_ numbered in [_offset_, _offset_ + _count_ - 1] (inclusive) are returned as the bits numbered in [0, _count_ - 1] (inclusive) of the result. |
| 114 | +The remaining bits in the result will be zero. |
| 115 | + |
| 116 | +_count_ is the number of bits to be extracted. |
| 117 | +If _count_ equals 0, the result is 0. |
| 118 | + |
| 119 | +If the _count_ or _offset_ or _offset_ + _count_ is greater than number of bits in `gentype` (for scalar types) or components of `gentype` (for vector types), the result is undefined. |
| 120 | + |
| 121 | +|[source,c] |
| 122 | +---- |
| 123 | +gentype bit_reverse( |
| 124 | + gentype base) |
| 125 | +---- |
| 126 | + |
| 127 | +|Returns the value of _base_ with reversed bits. |
| 128 | +That is, the bit numbered _n_ of the result value will be taken from the bit numbered _width_ - _n_ - 1 of _base_ (for scalar types) or a component of _base_ (for vector types), where _width_ is number of bits of `gentype` (for scalar types) or components of `gentype` (for vector types). |
| 129 | + |
| 130 | +|=== |
| 131 | +-- |
| 132 | + |
| 133 | +=== Modifications to the OpenCL SPIR-V Environment Specification |
| 134 | + |
| 135 | +==== Add to Section 5 - OpenCL Extensions |
| 136 | + |
| 137 | +Add a new Section 5.2.X - `cl_khr_extended_bit_ops`: :: |
| 138 | ++ |
| 139 | +-- |
| 140 | +If the OpenCL environment supports the extension `cl_khr_extended_bit_ops`, then the environment must accept modules that declare use of the extension `SPV_KHR_bit_instructions` via *OpExtension*. |
| 141 | + |
| 142 | +If the OpenCL environment supports the extension `cl_khr_extended_bit_ops` and use of the SPIR-V extension `SPV_KHR_bit_instructions` is declared in the module via *OpExtension*, then the environment must accept modules that declare the *BitInstructions* capability. |
| 143 | +-- |
0 commit comments