blob: a436ae2cee43b2a969ceb413edec1cb04337f079 [file] [log] [blame]
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="generator" content="AsciiDoc 8.6.9">
<title>The OpenCL C++ 1.0 Specification</title>
<style type="text/css">
/* Shared CSS for AsciiDoc xhtml11 and html5 backends */
/* Default font. */
body {
font-family: Georgia,serif;
}
/* Title font. */
h1, h2, h3, h4, h5, h6,
div.title, caption.title,
thead, p.table.header,
#toctitle,
#author, #revnumber, #revdate, #revremark,
#footer {
font-family: Arial,Helvetica,sans-serif;
}
body {
margin: 1em 5% 1em 5%;
}
a {
color: blue;
text-decoration: underline;
}
a:visited {
color: fuchsia;
}
em {
font-style: italic;
color: navy;
}
strong {
font-weight: bold;
color: #083194;
}
h1, h2, h3, h4, h5, h6 {
color: #527bbd;
margin-top: 1.2em;
margin-bottom: 0.5em;
line-height: 1.3;
}
h1, h2, h3 {
border-bottom: 2px solid silver;
}
h2 {
padding-top: 0.5em;
}
h3 {
float: left;
}
h3 + * {
clear: left;
}
h5 {
font-size: 1.0em;
}
div.sectionbody {
margin-left: 0;
}
hr {
border: 1px solid silver;
}
p {
margin-top: 0.5em;
margin-bottom: 0.5em;
}
ul, ol, li > p {
margin-top: 0;
}
ul > li { color: #aaa; }
ul > li > * { color: black; }
.monospaced, code, pre {
font-family: "Courier New", Courier, monospace;
font-size: inherit;
color: navy;
padding: 0;
margin: 0;
}
pre {
white-space: pre-wrap;
}
#author {
color: #527bbd;
font-weight: bold;
font-size: 1.1em;
}
#email {
}
#revnumber, #revdate, #revremark {
}
#footer {
font-size: small;
border-top: 2px solid silver;
padding-top: 0.5em;
margin-top: 4.0em;
}
#footer-text {
float: left;
padding-bottom: 0.5em;
}
#footer-badges {
float: right;
padding-bottom: 0.5em;
}
#preamble {
margin-top: 1.5em;
margin-bottom: 1.5em;
}
div.imageblock, div.exampleblock, div.verseblock,
div.quoteblock, div.literalblock, div.listingblock, div.sidebarblock,
div.admonitionblock {
margin-top: 1.0em;
margin-bottom: 1.5em;
}
div.admonitionblock {
margin-top: 2.0em;
margin-bottom: 2.0em;
margin-right: 10%;
color: #606060;
}
div.content { /* Block element content. */
padding: 0;
}
/* Block element titles. */
div.title, caption.title {
color: #527bbd;
font-weight: bold;
text-align: left;
margin-top: 1.0em;
margin-bottom: 0.5em;
}
div.title + * {
margin-top: 0;
}
td div.title:first-child {
margin-top: 0.0em;
}
div.content div.title:first-child {
margin-top: 0.0em;
}
div.content + div.title {
margin-top: 0.0em;
}
div.sidebarblock > div.content {
background: #ffffee;
border: 1px solid #dddddd;
border-left: 4px solid #f0f0f0;
padding: 0.5em;
}
div.listingblock > div.content {
border: 1px solid #dddddd;
border-left: 5px solid #f0f0f0;
background: #f8f8f8;
padding: 0.5em;
}
div.quoteblock, div.verseblock {
padding-left: 1.0em;
margin-left: 1.0em;
margin-right: 10%;
border-left: 5px solid #f0f0f0;
color: #888;
}
div.quoteblock > div.attribution {
padding-top: 0.5em;
text-align: right;
}
div.verseblock > pre.content {
font-family: inherit;
font-size: inherit;
}
div.verseblock > div.attribution {
padding-top: 0.75em;
text-align: left;
}
/* DEPRECATED: Pre version 8.2.7 verse style literal block. */
div.verseblock + div.attribution {
text-align: left;
}
div.admonitionblock .icon {
vertical-align: top;
font-size: 1.1em;
font-weight: bold;
text-decoration: underline;
color: #527bbd;
padding-right: 0.5em;
}
div.admonitionblock td.content {
padding-left: 0.5em;
border-left: 3px solid #dddddd;
}
div.exampleblock > div.content {
border-left: 3px solid #dddddd;
padding-left: 0.5em;
}
div.imageblock div.content { padding-left: 0; }
span.image img { border-style: none; vertical-align: text-bottom; }
a.image:visited { color: white; }
dl {
margin-top: 0.8em;
margin-bottom: 0.8em;
}
dt {
margin-top: 0.5em;
margin-bottom: 0;
font-style: normal;
color: navy;
}
dd > *:first-child {
margin-top: 0.1em;
}
ul, ol {
list-style-position: outside;
}
ol.arabic {
list-style-type: decimal;
}
ol.loweralpha {
list-style-type: lower-alpha;
}
ol.upperalpha {
list-style-type: upper-alpha;
}
ol.lowerroman {
list-style-type: lower-roman;
}
ol.upperroman {
list-style-type: upper-roman;
}
div.compact ul, div.compact ol,
div.compact p, div.compact p,
div.compact div, div.compact div {
margin-top: 0.1em;
margin-bottom: 0.1em;
}
tfoot {
font-weight: bold;
}
td > div.verse {
white-space: pre;
}
div.hdlist {
margin-top: 0.8em;
margin-bottom: 0.8em;
}
div.hdlist tr {
padding-bottom: 15px;
}
dt.hdlist1.strong, td.hdlist1.strong {
font-weight: bold;
}
td.hdlist1 {
vertical-align: top;
font-style: normal;
padding-right: 0.8em;
color: navy;
}
td.hdlist2 {
vertical-align: top;
}
div.hdlist.compact tr {
margin: 0;
padding-bottom: 0;
}
.comment {
background: yellow;
}
.footnote, .footnoteref {
font-size: 0.8em;
}
span.footnote, span.footnoteref {
vertical-align: super;
}
#footnotes {
margin: 20px 0 20px 0;
padding: 7px 0 0 0;
}
#footnotes div.footnote {
margin: 0 0 5px 0;
}
#footnotes hr {
border: none;
border-top: 1px solid silver;
height: 1px;
text-align: left;
margin-left: 0;
width: 20%;
min-width: 100px;
}
div.colist td {
padding-right: 0.5em;
padding-bottom: 0.3em;
vertical-align: top;
}
div.colist td img {
margin-top: 0.3em;
}
@media print {
#footer-badges { display: none; }
}
#toc {
margin-bottom: 2.5em;
}
#toctitle {
color: #527bbd;
font-size: 1.1em;
font-weight: bold;
margin-top: 1.0em;
margin-bottom: 0.1em;
}
div.toclevel0, div.toclevel1, div.toclevel2, div.toclevel3, div.toclevel4 {
margin-top: 0;
margin-bottom: 0;
}
div.toclevel2 {
margin-left: 2em;
font-size: 0.9em;
}
div.toclevel3 {
margin-left: 4em;
font-size: 0.9em;
}
div.toclevel4 {
margin-left: 6em;
font-size: 0.9em;
}
span.aqua { color: aqua; }
span.black { color: black; }
span.blue { color: blue; }
span.fuchsia { color: fuchsia; }
span.gray { color: gray; }
span.green { color: green; }
span.lime { color: lime; }
span.maroon { color: maroon; }
span.navy { color: navy; }
span.olive { color: olive; }
span.purple { color: purple; }
span.red { color: red; }
span.silver { color: silver; }
span.teal { color: teal; }
span.white { color: white; }
span.yellow { color: yellow; }
span.aqua-background { background: aqua; }
span.black-background { background: black; }
span.blue-background { background: blue; }
span.fuchsia-background { background: fuchsia; }
span.gray-background { background: gray; }
span.green-background { background: green; }
span.lime-background { background: lime; }
span.maroon-background { background: maroon; }
span.navy-background { background: navy; }
span.olive-background { background: olive; }
span.purple-background { background: purple; }
span.red-background { background: red; }
span.silver-background { background: silver; }
span.teal-background { background: teal; }
span.white-background { background: white; }
span.yellow-background { background: yellow; }
span.big { font-size: 2em; }
span.small { font-size: 0.6em; }
span.underline { text-decoration: underline; }
span.overline { text-decoration: overline; }
span.line-through { text-decoration: line-through; }
div.unbreakable { page-break-inside: avoid; }
/*
* xhtml11 specific
*
* */
div.tableblock {
margin-top: 1.0em;
margin-bottom: 1.5em;
}
div.tableblock > table {
border: 3px solid #527bbd;
}
thead, p.table.header {
font-weight: bold;
color: #527bbd;
}
p.table {
margin-top: 0;
}
/* Because the table frame attribute is overriden by CSS in most browsers. */
div.tableblock > table[frame="void"] {
border-style: none;
}
div.tableblock > table[frame="hsides"] {
border-left-style: none;
border-right-style: none;
}
div.tableblock > table[frame="vsides"] {
border-top-style: none;
border-bottom-style: none;
}
/*
* html5 specific
*
* */
table.tableblock {
margin-top: 1.0em;
margin-bottom: 1.5em;
}
thead, p.tableblock.header {
font-weight: bold;
color: #527bbd;
}
p.tableblock {
margin-top: 0;
}
table.tableblock {
border-width: 3px;
border-spacing: 0px;
border-style: solid;
border-color: #527bbd;
border-collapse: collapse;
}
th.tableblock, td.tableblock {
border-width: 1px;
padding: 4px;
border-style: solid;
border-color: #527bbd;
}
table.tableblock.frame-topbot {
border-left-style: hidden;
border-right-style: hidden;
}
table.tableblock.frame-sides {
border-top-style: hidden;
border-bottom-style: hidden;
}
table.tableblock.frame-none {
border-style: hidden;
}
th.tableblock.halign-left, td.tableblock.halign-left {
text-align: left;
}
th.tableblock.halign-center, td.tableblock.halign-center {
text-align: center;
}
th.tableblock.halign-right, td.tableblock.halign-right {
text-align: right;
}
th.tableblock.valign-top, td.tableblock.valign-top {
vertical-align: top;
}
th.tableblock.valign-middle, td.tableblock.valign-middle {
vertical-align: middle;
}
th.tableblock.valign-bottom, td.tableblock.valign-bottom {
vertical-align: bottom;
}
/*
* manpage specific
*
* */
body.manpage h1 {
padding-top: 0.5em;
padding-bottom: 0.5em;
border-top: 2px solid silver;
border-bottom: 2px solid silver;
}
body.manpage h2 {
border-style: none;
}
body.manpage div.sectionbody {
margin-left: 3em;
}
@media print {
body.manpage div#toc { display: none; }
}
@media screen {
body {
max-width: 50em; /* approximately 80 characters wide */
margin-left: 16em;
}
#toc {
position: fixed;
top: 0;
left: 0;
bottom: 0;
width: 13em;
padding: 0.5em;
padding-bottom: 1.5em;
margin: 0;
overflow: auto;
border-right: 3px solid #f8f8f8;
background-color: white;
}
#toc .toclevel1 {
margin-top: 0.5em;
}
#toc .toclevel2 {
margin-top: 0.25em;
display: list-item;
color: #aaaaaa;
}
#toctitle {
margin-top: 0.5em;
}
}
</style>
<script type="text/javascript">
/*<![CDATA[*/
var asciidoc = { // Namespace.
/////////////////////////////////////////////////////////////////////
// Table Of Contents generator
/////////////////////////////////////////////////////////////////////
/* Author: Mihai Bazon, September 2002
* http://students.infoiasi.ro/~mishoo
*
* Table Of Content generator
* Version: 0.4
*
* Feel free to use this script under the terms of the GNU General Public
* License, as long as you do not remove or alter this notice.
*/
/* modified by Troy D. Hanson, September 2006. License: GPL */
/* modified by Stuart Rackham, 2006, 2009. License: GPL */
// toclevels = 1..4.
toc: function (toclevels) {
function getText(el) {
var text = "";
for (var i = el.firstChild; i != null; i = i.nextSibling) {
if (i.nodeType == 3 /* Node.TEXT_NODE */) // IE doesn't speak constants.
text += i.data;
else if (i.firstChild != null)
text += getText(i);
}
return text;
}
function TocEntry(el, text, toclevel) {
this.element = el;
this.text = text;
this.toclevel = toclevel;
}
function tocEntries(el, toclevels) {
var result = new Array;
var re = new RegExp('[hH]([1-'+(toclevels+1)+'])');
// Function that scans the DOM tree for header elements (the DOM2
// nodeIterator API would be a better technique but not supported by all
// browsers).
var iterate = function (el) {
for (var i = el.firstChild; i != null; i = i.nextSibling) {
if (i.nodeType == 1 /* Node.ELEMENT_NODE */) {
var mo = re.exec(i.tagName);
if (mo && (i.getAttribute("class") || i.getAttribute("className")) != "float") {
result[result.length] = new TocEntry(i, getText(i), mo[1]-1);
}
iterate(i);
}
}
}
iterate(el);
return result;
}
var toc = document.getElementById("toc");
if (!toc) {
return;
}
// Delete existing TOC entries in case we're reloading the TOC.
var tocEntriesToRemove = [];
var i;
for (i = 0; i < toc.childNodes.length; i++) {
var entry = toc.childNodes[i];
if (entry.nodeName.toLowerCase() == 'div'
&& entry.getAttribute("class")
&& entry.getAttribute("class").match(/^toclevel/))
tocEntriesToRemove.push(entry);
}
for (i = 0; i < tocEntriesToRemove.length; i++) {
toc.removeChild(tocEntriesToRemove[i]);
}
// Rebuild TOC entries.
var entries = tocEntries(document.getElementById("content"), toclevels);
for (var i = 0; i < entries.length; ++i) {
var entry = entries[i];
if (entry.element.id == "")
entry.element.id = "_toc_" + i;
var a = document.createElement("a");
a.href = "#" + entry.element.id;
a.appendChild(document.createTextNode(entry.text));
var div = document.createElement("div");
div.appendChild(a);
div.className = "toclevel" + entry.toclevel;
toc.appendChild(div);
}
if (entries.length == 0)
toc.parentNode.removeChild(toc);
},
/////////////////////////////////////////////////////////////////////
// Footnotes generator
/////////////////////////////////////////////////////////////////////
/* Based on footnote generation code from:
* http://www.brandspankingnew.net/archive/2005/07/format_footnote.html
*/
footnotes: function () {
// Delete existing footnote entries in case we're reloading the footnodes.
var i;
var noteholder = document.getElementById("footnotes");
if (!noteholder) {
return;
}
var entriesToRemove = [];
for (i = 0; i < noteholder.childNodes.length; i++) {
var entry = noteholder.childNodes[i];
if (entry.nodeName.toLowerCase() == 'div' && entry.getAttribute("class") == "footnote")
entriesToRemove.push(entry);
}
for (i = 0; i < entriesToRemove.length; i++) {
noteholder.removeChild(entriesToRemove[i]);
}
// Rebuild footnote entries.
var cont = document.getElementById("content");
var spans = cont.getElementsByTagName("span");
var refs = {};
var n = 0;
for (i=0; i<spans.length; i++) {
if (spans[i].className == "footnote") {
n++;
var note = spans[i].getAttribute("data-note");
if (!note) {
// Use [\s\S] in place of . so multi-line matches work.
// Because JavaScript has no s (dotall) regex flag.
note = spans[i].innerHTML.match(/\s*\[([\s\S]*)]\s*/)[1];
spans[i].innerHTML =
"[<a id='_footnoteref_" + n + "' href='#_footnote_" + n +
"' title='View footnote' class='footnote'>" + n + "</a>]";
spans[i].setAttribute("data-note", note);
}
noteholder.innerHTML +=
"<div class='footnote' id='_footnote_" + n + "'>" +
"<a href='#_footnoteref_" + n + "' title='Return to text'>" +
n + "</a>. " + note + "</div>";
var id =spans[i].getAttribute("id");
if (id != null) refs["#"+id] = n;
}
}
if (n == 0)
noteholder.parentNode.removeChild(noteholder);
else {
// Process footnoterefs.
for (i=0; i<spans.length; i++) {
if (spans[i].className == "footnoteref") {
var href = spans[i].getElementsByTagName("a")[0].getAttribute("href");
href = href.match(/#.*/)[0]; // Because IE return full URL.
n = refs[href];
spans[i].innerHTML =
"[<a href='#_footnote_" + n +
"' title='View footnote' class='footnote'>" + n + "</a>]";
}
}
}
},
install: function(toclevels) {
var timerId;
function reinstall() {
asciidoc.footnotes();
if (toclevels) {
asciidoc.toc(toclevels);
}
}
function reinstallAndRemoveTimer() {
clearInterval(timerId);
reinstall();
}
timerId = setInterval(reinstall, 500);
if (document.addEventListener)
document.addEventListener("DOMContentLoaded", reinstallAndRemoveTimer, false);
else
window.onload = reinstallAndRemoveTimer;
}
}
asciidoc.install(3);
/*]]>*/
</script>
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
MathML: { extensions: ["content-mathml.js"] },
tex2jax: { inlineMath: [['$','$'], ['\\(','\\)']] }
});
</script>
<script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</script>
</head>
<body class="book">
<div id="header">
<h1>The OpenCL C++ 1.0 Specification</h1>
<span id="author">Khronos OpenCL Working Group</span><br>
<div id="toc">
<div id="toctitle">Table of Contents</div>
<noscript><p><b>JavaScript must be enabled in your browser to display the table of contents.</b></p></noscript>
</div>
</div>
<div id="content">
<div id="preamble">
<div class="sectionbody">
<div class="paragraph"><p>Copyright 2008-2017 The Khronos Group.</p></div>
<div class="paragraph"><p>This specification is protected by copyright laws and contains material proprietary
to the Khronos Group, Inc. Except as described by these terms, it or any components
may not be reproduced, republished, distributed, transmitted, displayed, broadcast
or otherwise exploited in any manner without the express prior written permission
of Khronos Group.</p></div>
<div class="paragraph"><p>Khronos Group grants a conditional copyright license to use and reproduce the
unmodified specification for any purpose, without fee or royalty, EXCEPT no licenses
to any patent, trademark or other intellectual property rights are granted under
these terms. Parties desiring to implement the specification and make use of
Khronos trademarks in relation to that implementation, and receive reciprocal patent
license protection under the Khronos IP Policy must become Adopters and confirm the
implementation as conformant under the process defined by Khronos for this
specification; see <a href="https://www.khronos.org/adopters">https://www.khronos.org/adopters</a>.</p></div>
<div class="paragraph"><p>Khronos Group makes no, and expressly disclaims any, representations or warranties,
express or implied, regarding this specification, including, without limitation:
merchantability, fitness for a particular purpose, non-infringement of any
intellectual property, correctness, accuracy, completeness, timeliness, and
reliability. Under no circumstances will the Khronos Group, or any of its Promoters,
Contributors or Members, or their respective partners, officers, directors,
employees, agents or representatives be liable for any damages, whether direct,
indirect, special or consequential damages for lost revenues, lost profits, or
otherwise, arising from or in connection with these materials.</p></div>
<div class="paragraph"><p>Vulkan is a registered trademark and Khronos, OpenXR, SPIR, SPIR-V, SYCL, WebGL,
WebCL, OpenVX, OpenVG, EGL, COLLADA, glTF, NNEF, OpenKODE, OpenKCAM, StreamInput,
OpenWF, OpenSL ES, OpenMAX, OpenMAX AL, OpenMAX IL, OpenMAX DL, OpenML and DevU are
trademarks of the Khronos Group Inc. ASTC is a trademark of ARM Holdings PLC,
OpenCL is a trademark of Apple Inc. and OpenGL and OpenML are registered trademarks
and the OpenGL ES and OpenGL SC logos are trademarks of Silicon Graphics
International used under license by Khronos. All other product names, trademarks,
and/or company names are used solely for identification and belong to their
respective owners.</p></div>
<div style="page-break-after:always"></div>
<h2 id="acknowledgements" class="float">Acknowledgements</h2>
<div class="paragraph"><p>The OpenCL C++ specification is the result of the contributions of many people, representing a cross section of the desktop, hand-held, and embedded computer industry.
Following is a partial list of the contributors, including the company that they represented at the time of their contribution:</p></div>
<div class="ulist"><ul>
<li>
<p>
Eric Berdahl, Adobe
</p>
</li>
<li>
<p>
Aaftab Munshi, Apple
</p>
</li>
<li>
<p>
Brian Sumner, AMD
</p>
</li>
<li>
<p>
Andrew Richards, Codeplay
</p>
</li>
<li>
<p>
Maria Rovatsou, Codeplay
</p>
</li>
<li>
<p>
Adam Stański, Intel
</p>
</li>
<li>
<p>
Alexey Bader, Intel
</p>
</li>
<li>
<p>
Allen Hux, Intel
</p>
</li>
<li>
<p>
Bartosz Sochacki, Intel
</p>
</li>
<li>
<p>
Ben Ashbaugh, Intel
</p>
</li>
<li>
<p>
Kevin Stevens, Intel
</p>
</li>
<li>
<p>
Łukasz Dudziak, Intel
</p>
</li>
<li>
<p>
Łukasz Towarek, Intel
</p>
</li>
<li>
<p>
Marcin Walkowiak, Intel
</p>
</li>
<li>
<p>
Michael Kinsner, Intel
</p>
</li>
<li>
<p>
Raun Krisch, Intel
</p>
</li>
<li>
<p>
Tomasz Fiechowski, Intel
</p>
</li>
<li>
<p>
Kedar Patil, NVIDIA
</p>
</li>
<li>
<p>
Yuan Lin, NVIDIA
</p>
</li>
<li>
<p>
Alex Bourd, Qualcomm
</p>
</li>
<li>
<p>
Lee Howes, Qualcomm
</p>
</li>
<li>
<p>
Anton Gorenko, StreamComputing
</p>
</li>
<li>
<p>
Jakub Szuppe, StreamComputing
</p>
</li>
<li>
<p>
James Price, University of Bristol
</p>
</li>
<li>
<p>
Paul Preney, University of Windsor
</p>
</li>
<li>
<p>
Ronan Keryell, Xilinx
</p>
</li>
<li>
<p>
AJ Guillon, YetiWare Inc.
</p>
</li>
</ul></div>
<div style="page-break-after:always"></div>
</div>
</div>
<div class="sect1">
<h2 id="generic-type-name-notation">1. Generic Type Name Notation</h2>
<div class="sectionbody">
<div class="paragraph"><p>The generic type names are used when some entity has multiple overloads which differ only by argument(s).
They can map to one or more built-in data types.
The tables below describe these mappings in details.</p></div>
<div class="paragraph"><p>Assuming that <span class="monospaced">gentype</span> maps to built-in types: <span class="monospaced">float</span>, <span class="monospaced">int</span> and <span class="monospaced">uint</span>, when coming across definition:</p></div>
<div class="listingblock">
<div class="content"><!-- Generator: GNU source-highlight 3.1.8
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt><span style="color: #008080">gentype</span> <span style="font-weight: bold"><span style="color: #000000">function</span></span><span style="color: #990000">(</span><span style="color: #008080">gentype</span> x<span style="color: #990000">);</span></tt></pre></div></div>
<div class="paragraph"><p>reader should understand that such function has in fact three overloads:</p></div>
<div class="listingblock">
<div class="content"><!-- Generator: GNU source-highlight 3.1.8
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt><span style="color: #009900">float</span> <span style="font-weight: bold"><span style="color: #000000">function</span></span><span style="color: #990000">(</span><span style="color: #009900">float</span> x<span style="color: #990000">);</span>
<span style="color: #009900">int</span> <span style="font-weight: bold"><span style="color: #000000">function</span></span><span style="color: #990000">(</span><span style="color: #009900">int</span> x<span style="color: #990000">);</span>
<span style="color: #008080">uint</span> <span style="font-weight: bold"><span style="color: #000000">function</span></span><span style="color: #990000">(</span><span style="color: #008080">uint</span> x<span style="color: #990000">);</span></tt></pre></div></div>
<div class="paragraph"><p>Note that if a function signature has multiple usages of <span class="monospaced">gentype</span> they all should map to the same type.
Following this rule such overloads are then invalid:</p></div>
<div class="listingblock">
<div class="content"><!-- Generator: GNU source-highlight 3.1.8
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt><span style="color: #009900">float</span> <span style="font-weight: bold"><span style="color: #000000">function</span></span><span style="color: #990000">(</span><span style="color: #009900">int</span> x<span style="color: #990000">);</span>
<span style="color: #008080">uint</span> <span style="font-weight: bold"><span style="color: #000000">function</span></span><span style="color: #990000">(</span><span style="color: #009900">float</span> x<span style="color: #990000">);</span>
<span style="font-style: italic"><span style="color: #9A1900">// etc.</span></span></tt></pre></div></div>
<div class="paragraph"><p>If a function is meant to have such overloads, respective gentypes in its signature should be postfixed with numbers to indicate they represent different types.
Declaration like this:</p></div>
<div class="listingblock">
<div class="content"><!-- Generator: GNU source-highlight 3.1.8
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt>cl<span style="color: #990000">::</span><span style="color: #008080">common_type_t&lt;gentype1, gentype2&gt;</span> <span style="font-weight: bold"><span style="color: #000000">greater</span></span><span style="color: #990000">(</span><span style="color: #008080">gentype1</span> x<span style="color: #990000">,</span> <span style="color: #008080">gentype2</span> y<span style="color: #990000">);</span></tt></pre></div></div>
<div class="paragraph"><p>would match following overloads:</p></div>
<div class="listingblock">
<div class="content"><!-- Generator: GNU source-highlight 3.1.8
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt>cl<span style="color: #990000">::</span><span style="color: #008080">common_type_t&lt;float, float&gt;</span> <span style="font-weight: bold"><span style="color: #000000">greater</span></span><span style="color: #990000">(</span><span style="color: #009900">float</span> x<span style="color: #990000">,</span> <span style="color: #009900">float</span> y<span style="color: #990000">);</span>
cl<span style="color: #990000">::</span><span style="color: #008080">common_type_t&lt;float, int&gt;</span> <span style="font-weight: bold"><span style="color: #000000">greater</span></span><span style="color: #990000">(</span><span style="color: #009900">float</span> x<span style="color: #990000">,</span> <span style="color: #009900">int</span> y<span style="color: #990000">);</span>
cl<span style="color: #990000">::</span><span style="color: #008080">common_type_t&lt;float, uint&gt;</span> <span style="font-weight: bold"><span style="color: #000000">greater</span></span><span style="color: #990000">(</span><span style="color: #009900">float</span> x<span style="color: #990000">,</span> <span style="color: #008080">uint</span> y<span style="color: #990000">);</span>
cl<span style="color: #990000">::</span><span style="color: #008080">common_type_t&lt;int, float&gt;</span> <span style="font-weight: bold"><span style="color: #000000">greater</span></span><span style="color: #990000">(</span><span style="color: #009900">int</span> x<span style="color: #990000">,</span> <span style="color: #009900">float</span> y<span style="color: #990000">);</span>
<span style="font-style: italic"><span style="color: #9A1900">// etc.</span></span></tt></pre></div></div>
<table class="tableblock frame-all grid-all"
style="
width:100%;
">
<caption class="title">Table 1. generic types</caption>
<col style="width:50%;">
<col style="width:50%;">
<thead>
<tr>
<th class="tableblock halign-left valign-top" ><div class="paragraph"><p><strong>generic type</strong></p></div></th>
<th class="tableblock halign-left valign-top" ><div class="paragraph"><p><strong>corresponding built-in types</strong></p></div></th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top" ><div><div class="paragraph"><p><span class="monospaced">typen</span></p></div></div></td>
<td class="tableblock halign-left valign-top" ><div><div class="paragraph"><p>scalar and all vector types of type</p></div>
<div class="paragraph"><p>Example:</p></div>
<div class="paragraph"><p><span class="monospaced">floatn</span> matches: <span class="monospaced">float</span>, <span class="monospaced">float2</span>, <span class="monospaced">float3</span>, <span class="monospaced">float4</span>, <span class="monospaced">float8</span> and <span class="monospaced">float16</span></p></div>
<div class="paragraph"><p><span class="monospaced">floatn</span> doesn&#8217;t match: <span class="monospaced">half</span>, <span class="monospaced">int2</span></p></div></div></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top" ><div><div class="paragraph"><p><span class="monospaced">gentype</span></p></div></div></td>
<td class="tableblock halign-left valign-top" ><div><div class="paragraph"><p>unspecified in global context, should be defined whenever used</p></div></div></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top" ><div><div class="paragraph"><p><span class="monospaced">sgentype</span></p></div></div></td>
<td class="tableblock halign-left valign-top" ><div><div class="paragraph"><p>subset of scalar types from types matched by <span class="monospaced">gentype</span></p></div></div></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top" ><div><div class="paragraph"><p><span class="monospaced">ugentype</span></p></div></div></td>
<td class="tableblock halign-left valign-top" ><div><div class="paragraph"><p>subset of unsigned integer types from types matched by <span class="monospaced">gentype</span></p></div></div></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top" ><div><div class="paragraph"><p><span class="monospaced">gentypeh</span></p></div></div></td>
<td class="tableblock halign-left valign-top" ><div><div class="paragraph"><p><span class="monospaced">half</span>, <span class="monospaced">half2</span>, <span class="monospaced">half3</span>, <span class="monospaced">half4</span>, <span class="monospaced">half8</span> or <span class="monospaced">half16</span></p></div></div></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top" ><div><div class="paragraph"><p><span class="monospaced">gentypef</span></p></div></div></td>
<td class="tableblock halign-left valign-top" ><div><div class="paragraph"><p><span class="monospaced">float</span>, <span class="monospaced">float2</span>, <span class="monospaced">float3</span>, <span class="monospaced">float4</span>, <span class="monospaced">float8</span> or <span class="monospaced">float16</span></p></div></div></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top" ><div><div class="paragraph"><p><span class="monospaced">gentyped</span></p></div></div></td>
<td class="tableblock halign-left valign-top" ><div><div class="paragraph"><p><span class="monospaced">double</span>, <span class="monospaced">double2</span>, <span class="monospaced">double3</span>, <span class="monospaced">double4</span>, <span class="monospaced">double8</span> or <span class="monospaced">double16</span></p></div></div></td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="sect1">
<h2 id="openclcpp-programming-language">2. OpenCL C++ Programming Language</h2>
<div class="sectionbody">
<div class="paragraph"><p>This section describes the OpenCL C++ programming language used to create kernels that are executed on OpenCL device(s).
The OpenCL C++ programming language is based on the ISO/IEC JTC1 SC22 WG21 N 3690 language specification (a.k.a. C++14 specification) with specific restrictions (<em><a href="#opencl_cxx_restrictions">OpenCL C++ restrictions</a> section</em>).
Please refer to this specification for a detailed description of the language grammar.
This section describes restrictions to the C++14 specification supported in OpenCL C++.</p></div>
<div class="sect2">
<h3 id="supported-builtin-data-types">2.1. Supported Built-in Data Types</h3>
<div class="paragraph"><p>The following data types are supported.</p></div>
<div class="sect3">
<h4 id="builtin-scalar-data-types">2.1.1. Built-in Scalar Data Types</h4>
<table class="tableblock frame-all grid-all" id="device_builtin_scalar_data_types"
style="
width:100%;
">
<caption class="title">Table 2. Device Built-in scalar data types</caption>
<col style="width:50%;">
<col style="width:50%;">
<thead>
<tr>
<th class="tableblock halign-left valign-top" ><strong>Type</strong></th>
<th class="tableblock halign-left valign-top" ><strong>Description</strong></th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top" ><p class="tableblock"><span class="monospaced">bool</span></p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock">A data type which is either <span class="monospaced">true</span> or <span class="monospaced">false</span>. (<em>See [ISO/IEC 14882:2014: lex.bool, &sect;2.14.6; basic.fundamental, &sect;3.9.1].</em>)</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top" ><p class="tableblock"><span class="monospaced">char</span>, <span class="monospaced">signed char</span></p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock">A signed two&#8217;s complement 8-bit integer.</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top" ><p class="tableblock"><span class="monospaced">unsigned char</span></p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock">An unsigned 8-bit integer.</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top" ><p class="tableblock"><span class="monospaced">short</span></p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock">A signed two&#8217;s complement 16-bit integer.</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top" ><p class="tableblock"><span class="monospaced">unsigned short</span></p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock">An unsigned 16-bit integer.</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top" ><p class="tableblock"><span class="monospaced">int</span></p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock">A signed two&#8217;s complement 32-bit integer.</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top" ><p class="tableblock"><span class="monospaced">unsigned int</span></p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock">An unsigned 32-bit integer.</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top" ><p class="tableblock"><span class="monospaced">long</span></p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock">A signed two&#8217;s complement 64-bit integer.</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top" ><p class="tableblock"><span class="monospaced">unsigned long</span></p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock">An unsigned 64-bit integer.</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top" ><p class="tableblock"><span class="monospaced">float</span></p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock">A 32-bit floating-point.
The float data type must conform to the IEEE 754 single precision storage format.</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top" ><p class="tableblock"><span class="monospaced">double</span> <a href="#ftn2">[2</a>]</p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock">A 64-bit floating-point.
The double data type must conform to the IEEE 754 double precision storage format.</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top" ><p class="tableblock"><span class="monospaced">half</span></p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock">A 16-bit floating-point.
The half data type must conform to the IEEE 754-2008 half precision storage format.</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top" ><p class="tableblock"><span class="monospaced">void</span></p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock">The <span class="monospaced">void</span> type comprises an empty set of values; it is an incomplete type that cannot be completed.</p></td>
</tr>
</tbody>
</table>
<div class="paragraph"><p>Most built-in scalar data types are also declared as appropriate types in the OpenCL API (and header files) that can be used by an application.
The following table describes the built-in scalar data type in the OpenCL C++ programming language and the corresponding data type available to the application:</p></div>
<table class="tableblock frame-all grid-all" id="host_scalar_builtin_data_types"
style="
width:100%;
">
<caption class="title">Table 3. Host Scalar Built-in Data Types</caption>
<col style="width:50%;">
<col style="width:50%;">
<thead>
<tr>
<th class="tableblock halign-left valign-top" ><strong>Type in OpenCL Language</strong></th>
<th class="tableblock halign-left valign-top" ><strong>API type for application</strong></th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top" ><p class="tableblock"><span class="monospaced">bool</span></p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock">n/a, i.e., there is no corresponding <span class="monospaced">cl_bool</span> type.</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top" ><p class="tableblock"><span class="monospaced">char</span></p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock"><span class="monospaced">cl_char</span></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top" ><p class="tableblock"><span class="monospaced">unsigned char</span>, <span class="monospaced">uchar</span></p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock"><span class="monospaced">cl_uchar</span></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top" ><p class="tableblock"><span class="monospaced">short</span></p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock"><span class="monospaced">cl_short</span></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top" ><p class="tableblock"><span class="monospaced">unsigned short</span>, <span class="monospaced">ushort</span></p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock"><span class="monospaced">cl_ushort</span></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top" ><p class="tableblock"><span class="monospaced">int</span></p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock"><span class="monospaced">cl_int</span></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top" ><p class="tableblock"><span class="monospaced">unsigned int</span>, <span class="monospaced">uint</span></p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock"><span class="monospaced">cl_uint</span></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top" ><p class="tableblock"><span class="monospaced">long</span></p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock"><span class="monospaced">cl_long</span></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top" ><p class="tableblock"><span class="monospaced">unsigned long</span>, <span class="monospaced">ulong</span></p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock"><span class="monospaced">cl_ulong</span></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top" ><p class="tableblock"><span class="monospaced">float</span></p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock"><span class="monospaced">cl_float</span></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top" ><p class="tableblock"><span class="monospaced">double</span></p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock"><span class="monospaced">cl_double</span></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top" ><p class="tableblock"><span class="monospaced">half</span></p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock"><span class="monospaced">cl_half</span></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top" ><p class="tableblock"><span class="monospaced">void</span></p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock"><span class="monospaced">void</span></p></td>
</tr>
</tbody>
</table>
<div class="sect4">
<h5 id="builtin-half-data-type">Built-in Half Data Type</h5>
<div class="paragraph"><p>The <span class="monospaced">half</span> data type must be IEEE 754-2008 compliant.
<span class="monospaced">half</span> numbers have 1 sign bit, 5 exponent bits, and 10 mantissa bits.
The interpretation of the sign, exponent and mantissa is analogous to IEEE 754 floating-point numbers.</p></div>
<div class="paragraph"><p>The exponent bias is 15.
The <span class="monospaced">half</span> data type must represent finite and normal numbers, denormalized numbers, infinities and NaN.
Denormalized numbers for the <span class="monospaced">half</span> data type which may be generated when converting a <span class="monospaced">float</span> to a <span class="monospaced">half</span> using <span class="monospaced">vstore_half</span> and converting a <span class="monospaced">half</span> to a <span class="monospaced">float</span> using <span class="monospaced">vload_half</span> cannot be flushed to zero.</p></div>
<div class="paragraph"><p>Conversions from <span class="monospaced">float</span> to <span class="monospaced">half</span> correctly round the mantissa to 11 bits of precision.</p></div>
<div class="paragraph"><p>Conversions from <span class="monospaced">half</span> to <span class="monospaced">float</span> are lossless; all <span class="monospaced">half</span> numbers are exactly representable as <span class="monospaced">float</span> values.</p></div>
<div class="paragraph"><p>The <span class="monospaced">half</span> data type can only be used to declare a pointer to a buffer that contains <span class="monospaced">half</span> values.
All other operations are not allowed if the <em>cl_khr_fp16</em> extension is not supported.</p></div>
<div class="paragraph"><p>A few valid examples are given below:</p></div>
<div class="listingblock">
<div class="content"><!-- Generator: GNU source-highlight 3.1.8
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt><span style="font-weight: bold"><span style="color: #000080">#include</span></span> <span style="color: #FF0000">&lt;opencl_def&gt;</span>
<span style="font-weight: bold"><span style="color: #000080">#include</span></span> <span style="color: #FF0000">&lt;opencl_memory&gt;</span>
<span style="font-weight: bold"><span style="color: #000080">#include</span></span> <span style="color: #FF0000">&lt;opencl_vector_load_store&gt;</span>
<span style="color: #009900">float</span> <span style="font-weight: bold"><span style="color: #000000">bar</span></span><span style="color: #990000">(</span><span style="color: #008080">half</span> <span style="color: #990000">*</span>a<span style="color: #990000">)</span> <span style="color: #FF0000">{</span>
<span style="font-weight: bold"><span style="color: #0000FF">return</span></span> cl<span style="color: #990000">::</span>vload_half<span style="color: #990000">&lt;</span> <span style="color: #993399">1</span> <span style="color: #990000">&gt;(</span><span style="color: #993399">0</span><span style="color: #990000">,</span> a<span style="color: #990000">);</span>
<span style="color: #FF0000">}</span>
kernel <span style="color: #008080">void</span> <span style="font-weight: bold"><span style="color: #000000">foo</span></span><span style="color: #990000">(</span>cl<span style="color: #990000">::</span><span style="color: #008080">global_ptr&lt;half&gt;</span> pg<span style="color: #990000">)</span> <span style="color: #FF0000">{</span> <span style="font-style: italic"><span style="color: #9A1900">//ok: a global pointer</span></span>
<span style="font-style: italic"><span style="color: #9A1900">// passed from the host</span></span>
<span style="color: #009900">int</span> offset <span style="color: #990000">=</span> <span style="color: #993399">1</span><span style="color: #990000">;</span>
<span style="color: #008080">half</span> <span style="color: #990000">*</span>ptr <span style="color: #990000">=</span> pg<span style="color: #990000">.</span><span style="font-weight: bold"><span style="color: #000000">get</span></span><span style="color: #990000">()</span> <span style="color: #990000">+</span> offset<span style="color: #990000">;</span> <span style="font-style: italic"><span style="color: #9A1900">//ok: half pointer arithmetic</span></span>
<span style="color: #009900">float</span> b <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000000">bar</span></span><span style="color: #990000">(</span>ptr<span style="color: #990000">);</span>
<span style="font-weight: bold"><span style="color: #0000FF">if</span></span><span style="color: #990000">(</span>b <span style="color: #990000">&lt;</span> <span style="color: #990000">*</span>ptr<span style="color: #990000">)</span> <span style="color: #FF0000">{</span> <span style="font-style: italic"><span style="color: #9A1900">//not allowed: it is only supported if cl_khr_fp16</span></span>
<span style="font-style: italic"><span style="color: #9A1900">// extension is enabled</span></span>
<span style="font-style: italic"><span style="color: #9A1900">//...</span></span>
<span style="color: #FF0000">}</span>
<span style="color: #FF0000">}</span></tt></pre></div></div>
<div class="paragraph"><p>The <span class="monospaced">half</span> scalar data type is required to be supported as a data storage format.
Vector data load and store functions (described in <em><a href="#vector-data-load-and-store-functions">Vector Data Load and Store Functions</a> section</em>) must be supported.</p></div>
</div>
<div class="sect4">
<h5 id="cl_khr_fp16-extension">cl_khr_fp16 extension</h5>
<div class="paragraph"><p>This extension adds support for <span class="monospaced">half</span> scalar and vector types as built-in types that can be used for arithmetic operations, conversions etc.
An application that wants to use <span class="monospaced">half</span> and <span class="monospaced">halfn</span> types will need to specify <em>-cl-fp16-enable</em> compiler option (<em><a href="#fp16_and_fp64_options">Double and half-precision floating-point options</a> section</em>).</p></div>
<div class="paragraph"><p>The OpenCL compiler accepts an h and H suffix on floating point literals, indicating the literal is typed as a <span class="monospaced">half</span></p></div>
<div class="paragraph"><p>A few valid examples:</p></div>
<div class="listingblock">
<div class="content"><!-- Generator: GNU source-highlight 3.1.8
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt><span style="font-weight: bold"><span style="color: #000080">#include</span></span> <span style="color: #FF0000">&lt;opencl_def&gt;</span>
<span style="font-weight: bold"><span style="color: #000080">#include</span></span> <span style="color: #FF0000">&lt;opencl_memory&gt;</span>
<span style="color: #008080">half</span> <span style="font-weight: bold"><span style="color: #000000">bar</span></span><span style="color: #990000">(</span><span style="color: #008080">half</span> a<span style="color: #990000">)</span> <span style="color: #FF0000">{</span>
<span style="color: #008080">half</span> b <span style="color: #990000">=</span> a<span style="color: #990000">;</span>
b <span style="color: #990000">+=</span> <span style="color: #993399">10</span><span style="color: #990000">.</span>0h<span style="color: #990000">;</span> <span style="font-style: italic"><span style="color: #9A1900">//ok: cl_khr_fp16 extension is enabled. All arithmetic</span></span>
<span style="font-style: italic"><span style="color: #9A1900">// operations on half built-in type are available</span></span>
<span style="font-weight: bold"><span style="color: #0000FF">return</span></span> b<span style="color: #990000">;</span>
<span style="color: #FF0000">}</span>
kernel <span style="color: #008080">void</span> <span style="font-weight: bold"><span style="color: #000000">foo</span></span><span style="color: #990000">(</span>cl<span style="color: #990000">::</span><span style="color: #008080">global_ptr&lt;half&gt;</span> pg<span style="color: #990000">)</span> <span style="color: #FF0000">{</span>
<span style="color: #009900">int</span> offset <span style="color: #990000">=</span> <span style="color: #993399">1</span><span style="color: #990000">;</span>
<span style="color: #008080">half</span> <span style="color: #990000">*</span>ptr <span style="color: #990000">=</span> pg<span style="color: #990000">.</span><span style="font-weight: bold"><span style="color: #000000">get</span></span><span style="color: #990000">()</span> <span style="color: #990000">+</span> offset<span style="color: #990000">;</span>
<span style="color: #008080">half</span> b <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000000">bar</span></span><span style="color: #990000">(*</span>ptr<span style="color: #990000">);</span>
<span style="font-weight: bold"><span style="color: #0000FF">if</span></span><span style="color: #990000">(</span>b <span style="color: #990000">&lt;</span> <span style="color: #990000">*</span>ptr<span style="color: #990000">)</span> <span style="color: #FF0000">{</span> <span style="font-style: italic"><span style="color: #9A1900">//ok: cl_khr_fp16 extension is enabled.</span></span>
<span style="font-style: italic"><span style="color: #9A1900">// All comparision operations are available</span></span>
<span style="font-style: italic"><span style="color: #9A1900">//...</span></span>
<span style="color: #FF0000">}</span>
<span style="color: #FF0000">}</span></tt></pre></div></div>
</div>
<div class="sect4">
<h5 id="hexadecimal-floating-point-literals">Hexadecimal floating point literals</h5>
<div class="paragraph"><p>Hexadecimal floating point literals are supported in OpenCL C++.</p></div>
<div class="listingblock">
<div class="content"><!-- Generator: GNU source-highlight 3.1.8
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt><span style="color: #009900">float</span> f <span style="color: #990000">=</span> <span style="color: #993399">0x1</span><span style="color: #990000">.</span>fffffep127f
<span style="color: #009900">double</span> d <span style="color: #990000">=</span> <span style="color: #993399">0x1</span><span style="color: #990000">.</span>fffffffffffffp1023<span style="color: #990000">;</span>
<span style="color: #008080">half</span> h <span style="color: #990000">=</span> <span style="color: #993399">0x1</span><span style="color: #990000">.</span>ffcp15h<span style="color: #990000">;</span></tt></pre></div></div>
</div>
</div>
<div class="sect3">
<h4 id="builtin-vector-data-types">2.1.2. Built-in Vector Data Types</h4>
<div class="sect4">
<h5 id="supported-vector-data-types">Supported Vector Data Types</h5>
<div class="paragraph"><p>The <span class="monospaced">bool</span>, <span class="monospaced">char</span>, <span class="monospaced">unsigned char</span>, <span class="monospaced">short</span>, <span class="monospaced">unsigned short</span>, <span class="monospaced">int</span>, <span class="monospaced">unsigned int</span>, <span class="monospaced">long</span>, <span class="monospaced">unsigned long</span>, <span class="monospaced">half</span>, <span class="monospaced">float</span> and <span class="monospaced">double</span> vector data types are supported.
The vector data type is defined with the type name i.e. <span class="monospaced">bool</span>, <span class="monospaced">char</span>, <span class="monospaced">uchar</span>, <span class="monospaced">short</span>, <span class="monospaced">ushort</span>, <span class="monospaced">int</span>, <span class="monospaced">uint</span>, <span class="monospaced">long</span>, <span class="monospaced">ulong</span>, <span class="monospaced">half</span>, <span class="monospaced">float</span> or <span class="monospaced">double</span> followed by a literal value <em>n</em> that defines the number of elements in the vector.
Supported values of <em>n</em> are 2, 3, 4, 8, and 16 for all vector data types.</p></div>
<table class="tableblock frame-all grid-all" id="device_builtin_vector_data_types"
style="
width:100%;
">
<caption class="title">Table 4. Device Built-in Vector Data Types</caption>
<col style="width:50%;">
<col style="width:50%;">
<thead>
<tr>
<th class="tableblock halign-left valign-top" ><strong>Type</strong></th>
<th class="tableblock halign-left valign-top" ><strong>Description</strong></th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top" ><p class="tableblock"><span class="monospaced">bool</span><em>n</em></p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock">A vector of <em>n</em> boolean values.</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top" ><p class="tableblock"><span class="monospaced">char</span><em>n</em></p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock">A vector of <em>n</em> 8-bit signed two&#8217;s complement integer values.</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top" ><p class="tableblock"><span class="monospaced">uchar</span><em>n</em></p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock">A vector of <em>n</em> 8-bit unsigned integer values.</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top" ><p class="tableblock"><span class="monospaced">short</span><em>n</em></p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock">vector of <em>n</em> 16-bit signed two&#8217;s complement integer values.</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top" ><p class="tableblock"><span class="monospaced">ushort</span><em>n</em></p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock">A vector of <em>n</em> 16-bit unsigned integer values.</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top" ><p class="tableblock"><span class="monospaced">int</span><em>n</em></p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock">A vector of <em>n</em> 32-bit signed two&#8217;s complement integer values.</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top" ><p class="tableblock"><span class="monospaced">uint</span><em>n</em></p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock">A vector of <em>n</em> 32-bit unsigned integer values.</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top" ><p class="tableblock"><span class="monospaced">long</span><em>n</em></p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock">A vector of <em>n</em> 64-bit signed two&#8217;s complement integer values.</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top" ><p class="tableblock"><span class="monospaced">ulong</span><em>n</em></p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock">A vector of <em>n</em> 64-bit unsigned integer values.</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top" ><p class="tableblock"><span class="monospaced">half</span><em>n</em></p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock">A vector of <em>n</em> 16-bit floating-point values.</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top" ><p class="tableblock"><span class="monospaced">float</span><em>n</em></p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock">A vector of <em>n</em> 32-bit floating-point values.</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top" ><p class="tableblock"><span class="monospaced">double</span><em>n</em></p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock">A vector of <em>n</em> 64-bit floating-point values.</p></td>
</tr>
</tbody>
</table>
<div class="paragraph"><p>The built-in vector data types are also declared as appropriate types in the OpenCL API (and header files) that can be used by an application.
The following table describes the built-in vector data type in the OpenCL C++ programming language and the corresponding data type available to the application:</p></div>
<table class="tableblock frame-all grid-all" id="host_builtin_vector_data_types"
style="
width:100%;
">
<caption class="title">Table 5. Host Built-in Vector Data Types</caption>
<col style="width:50%;">
<col style="width:50%;">
<thead>
<tr>
<th class="tableblock halign-left valign-top" ><strong>Type in OpenCL Language</strong></th>
<th class="tableblock halign-left valign-top" ><strong>API type for application</strong></th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top" ><p class="tableblock"><span class="monospaced">bool</span><em>n</em></p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock">n/a, i.e., there is no corresponding <span class="monospaced">cl_bool</span><em>n</em> type.</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top" ><p class="tableblock"><span class="monospaced">char</span><em>n</em></p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock"><span class="monospaced">cl_char</span><em>n</em></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top" ><p class="tableblock"><span class="monospaced">uchar</span><em>n</em></p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock"><span class="monospaced">cl_uchar</span><em>n</em></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top" ><p class="tableblock"><span class="monospaced">short</span><em>n</em></p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock"><span class="monospaced">cl_short</span><em>n</em></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top" ><p class="tableblock"><span class="monospaced">ushort</span><em>n</em></p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock"><span class="monospaced">cl_ushort</span><em>n</em></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top" ><p class="tableblock"><span class="monospaced">int</span><em>n</em></p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock"><span class="monospaced">cl_int</span><em>n</em></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top" ><p class="tableblock"><span class="monospaced">uint</span><em>n</em></p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock"><span class="monospaced">cl_uint</span><em>n</em></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top" ><p class="tableblock"><span class="monospaced">long</span><em>n</em></p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock"><span class="monospaced">cl_long</span><em>n</em></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top" ><p class="tableblock"><span class="monospaced">ulong</span><em>n</em></p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock"><span class="monospaced">cl_ulong</span><em>n</em></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top" ><p class="tableblock"><span class="monospaced">half</span><em>n</em></p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock"><span class="monospaced">cl_half</span><em>n</em></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top" ><p class="tableblock"><span class="monospaced">float</span><em>n</em></p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock"><span class="monospaced">cl_float</span><em>n</em></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top" ><p class="tableblock"><span class="monospaced">double</span><em>n</em></p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock"><span class="monospaced">cl_double</span><em>n</em></p></td>
</tr>
</tbody>
</table>
<div class="paragraph"><p>The <span class="monospaced">half</span><em>n</em> vector data type is required to be supported as a data storage format.
Vector data load and store functions (described in <em><a href="#vector-data-load-and-store-functions">Vector Data Load and Store Functions</a> section</em>) must be supported.</p></div>
<div class="paragraph"><p>Support for the <span class="monospaced">double</span><em>n</em> vector data type is optional.</p></div>
</div>
<div class="sect4">
<h5 id="vector-changes-to-cpp14-standard">Vector Changes to C++14 standard</h5>
<div class="olist arabic"><ol class="arabic">
<li>
<p>
Vector types are classified as fundamental (<em>[ISO/IEC 14882:2014: basic.fundamental, ch. 3.9.1]</em>) and literal types
</p>
<div class="admonitionblock">
<table><tr>
<td class="icon">
<div class="title">Note</div>
</td>
<td class="content">A vector type behave similarly to a trivially destructible class with all data members of literal type and all of its constructors defined as constexpr constructors</td>
</tr></table>
</div>
</li>
<li>
<p>
Abbreviating vector type as Tn, T is called the component type of a vector.
The numerical value n specifies number of components in a vector.
<a href="#device_builtin_vector_data_types">Device built-in vector data types</a> table specifies supported vector types.
</p>
<div class="paragraph"><p>A vector type which component type is <em>integral type</em> is called <em>integral vector type</em>.
A vector type which component is <em>floating-point type</em> is called <em>floating-point vector type</em>.</p></div>
<div class="listingblock">
<div class="content"><!-- Generator: GNU source-highlight 3.1.8
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt><span style="color: #008080">float8</span> a<span style="color: #990000">;</span> <span style="font-style: italic"><span style="color: #9A1900">// component type: float, number of components: 8</span></span>
<span style="color: #008080">uint16</span> b<span style="color: #990000">;</span> <span style="font-style: italic"><span style="color: #9A1900">// component type: uint, number of components: 16</span></span></tt></pre></div></div>
</li>
<li>
<p>
An <em>integral vector type</em> can be used as type of value of non-type template-parameter.
The change is introduced by following changes in C++ specification:
</p>
<div class="ulist"><ul>
<li>
<p>
<em>[ISO/IEC 14882:2014: temp.param, ch. 14.1 (4, 4.1)]</em> Template parameters: A non-type template-parameter shall have one of the following (optionally cv-qualified) types:
</p>
<div class="ulist"><ul>
<li>
<p>
integral, integral vector or enumeration type,
</p>
</li>
<li>
<p>
integral, integral vector or enumeration type,
</p>
</li>
<li>
<p>
[ &#8230; ]
</p>
</li>
</ul></div>
</li>
<li>
<p>
<em>[ISO/IEC 14882:2014: temp.param, ch. 14.1 (7)]</em> Template parameters: A non-type <em>template-parameter</em> shall not be declared to have floating point, floating-point vector, class, or void type.
</p>
</li>
<li>
<p>
<em>[ISO/IEC 14882:2014: temp.type, ch. 14.4 (1, 1.3)]</em> Type equivalence: Two <em>template-ids</em> refer to the same class, function, or variable if
</p>
<div class="ulist"><ul>
<li>
<p>
[ &#8230; ]
</p>
</li>
<li>
<p>
their corresponding non-type template arguments of integral, integral vector or enumeration type have identical values and
</p>
</li>
<li>
<p>
[ &#8230; ]
</p>
</li>
</ul></div>
</li>
<li>
<p>
<em>[ISO/IEC 14882:2014: temp.res, ch. 14.6 (8, 8.3, 8.3.1)]</em> Name resolution: [&#8230;] If the interpretation of such a construct in the hypothetical instantiation is different from the interpretation of the corresponding construct
</p>
<div class="ulist"><ul>
<li>
<p>
integral, integral vector or enumeration type, in any actual instantiation of the template, the program is ill-formed; no diagnostic is required.
This can happen in situations including the following:
</p>
</li>
<li>
<p>
[ &#8230; ]
</p>
</li>
<li>
<p>
constant expression evaluation (5.20) within the template instantiation uses
</p>
<div class="ulist"><ul>
<li>
<p>
the value of a const object of integral, integral vector or unscoped enumeration type or
</p>
</li>
<li>
<p>
[ &#8230; ]
</p>
</li>
</ul></div>
</li>
<li>
<p>
[ &#8230; ]
</p>
</li>
</ul></div>
</li>
</ul></div>
</li>
</ol></div>
</div>
<div class="sect4">
<h5 id="vector-component-access">Vector Component Access</h5>
<div class="olist arabic"><ol class="arabic">
<li>
<p>
The components of vector type can be accessed using swizzle expression.
The syntax of a swizzle expression is similar to syntax used in class member access expression <em>[ISO/IEC 14882:2014: expr.ref, ch. 5.2.5]</em>:
The swizzle expression is a postfix expression formed with a postfix expression followed by a dot <span class="monospaced">.</span> or an arrow <span class="monospaced">-&gt;</span> and then followed by an <em>vector-swizzle-selector</em>. The postfix expression before the dot or arrow is evaluated. The result of that evaluation, together with the <em>vector-swizzle-selector</em>, determines the result of the entire postfix expression.
</p>
<div class="listingblock">
<div class="content"><!-- Generator: GNU source-highlight 3.1.8
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt><span style="color: #008080">float4</span> v1 <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000000">float4</span></span><span style="color: #990000">(</span><span style="color: #993399">1</span><span style="color: #990000">.</span>0f<span style="color: #990000">,</span> <span style="color: #993399">2</span><span style="color: #990000">.</span>0f<span style="color: #990000">,</span> <span style="color: #993399">3</span><span style="color: #990000">.</span>0f<span style="color: #990000">,</span> <span style="color: #993399">4</span><span style="color: #990000">.</span>0f<span style="color: #990000">);</span>
<span style="color: #008080">float4</span> <span style="color: #990000">*</span>pv1 <span style="color: #990000">=</span> <span style="color: #990000">&amp;</span>v1<span style="color: #990000">;</span>
<span style="color: #008080">float2</span> v2 <span style="color: #990000">=</span> v1<span style="color: #990000">.</span>xz<span style="color: #990000">;</span> <span style="font-style: italic"><span style="color: #9A1900">// v1.xz is a swizzle expression</span></span>
<span style="color: #008080">float3</span> v3 <span style="color: #990000">=</span> pv1<span style="color: #990000">-&gt;</span>s321<span style="color: #990000">;</span> <span style="font-style: italic"><span style="color: #9A1900">// pv1-&gt;s321 is a swizzle expression</span></span>
<span style="font-style: italic"><span style="color: #9A1900">// equivalent to (*pv1).s321</span></span>
<span style="color: #990000">(*</span>pv1<span style="color: #990000">).</span>rgb <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000000">float3</span></span><span style="color: #990000">(</span><span style="color: #993399">0</span><span style="color: #990000">.</span>0f<span style="color: #990000">,</span> <span style="color: #993399">0</span><span style="color: #990000">.</span>5f<span style="color: #990000">,</span> <span style="color: #993399">1</span><span style="color: #990000">.</span>0f<span style="color: #990000">);</span> <span style="font-style: italic"><span style="color: #9A1900">// (*pv1).rgb is a swizzle expression</span></span>
pv1<span style="color: #990000">-&gt;</span>lo<span style="color: #990000">.</span>hi <span style="color: #990000">=</span> <span style="color: #993399">0</span><span style="color: #990000">.</span>0f<span style="color: #990000">;</span> <span style="font-style: italic"><span style="color: #9A1900">// pv1-&gt;lo and pv1-&gt;lo.hi are swizzle</span></span>
<span style="font-style: italic"><span style="color: #9A1900">// expressions</span></span></tt></pre></div></div>
</li>
<li>
<p>
For the first option (dot) the first expression shall have vector type or be a swizzle expression which results in vector-swizzle of vector type.
For the second option (arrow) the first expression shall have pointer to vector type.
The expression <span class="monospaced">E1-&gt;E2</span> is converted to the equivalent form <span class="monospaced">(*(E1)).E2</span>; the remainder of <a href="#vector-component-access">Vector Component Access</a> will address only the first option (dot).
</p>
<div class="admonitionblock">
<table><tr>
<td class="icon">
<div class="title">Note</div>
</td>
<td class="content"><span class="monospaced">(*(E1))</span> is lvalue. In either case, the <em>vector-swizzle-selector</em> shall name a vector component selection of a swizzle.</td>
</tr></table>
</div>
<div class="listingblock">
<div class="content"><!-- Generator: GNU source-highlight 3.1.8
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt><span style="color: #008080">uint8</span> v1 <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000000">uint8</span></span><span style="color: #990000">(</span><span style="color: #993399">10</span><span style="color: #990000">,</span> <span style="color: #993399">11</span><span style="color: #990000">,</span> <span style="color: #993399">12</span><span style="color: #990000">,</span> <span style="color: #993399">13</span><span style="color: #990000">,</span> <span style="color: #993399">14</span><span style="color: #990000">,</span> <span style="color: #993399">15</span><span style="color: #990000">,</span> <span style="color: #993399">16</span><span style="color: #990000">,</span> <span style="color: #993399">17</span><span style="color: #990000">);</span>
<span style="color: #008080">uint4</span> v2 <span style="color: #990000">=</span> v1<span style="color: #990000">.</span>s7301<span style="color: #990000">;</span> <span style="font-style: italic"><span style="color: #9A1900">// correct</span></span>
<span style="color: #008080">uint3</span> v3 <span style="color: #990000">=</span> <span style="color: #990000">(&amp;</span>v1<span style="color: #990000">)-&gt;</span>s246<span style="color: #990000">;</span> <span style="font-style: italic"><span style="color: #9A1900">// correct</span></span>
<span style="color: #008080">uint4</span> v4 <span style="color: #990000">=</span> v1<span style="color: #990000">-&gt;</span>s0123<span style="color: #990000">;</span> <span style="font-style: italic"><span style="color: #9A1900">// ill-formed: v1 is not a pointer to</span></span>
<span style="font-style: italic"><span style="color: #9A1900">// vector type</span></span>
<span style="color: #008080">uint8</span> <span style="color: #990000">*</span>pv1 <span style="color: #990000">=</span> <span style="color: #990000">&amp;</span>v1<span style="color: #990000">;</span>
<span style="color: #008080">uint2</span> v5 <span style="color: #990000">=</span> pv1<span style="color: #990000">-&gt;</span>S13<span style="color: #990000">;</span> <span style="font-style: italic"><span style="color: #9A1900">// correct</span></span>
<span style="color: #008080">uint2</span> v6 <span style="color: #990000">=</span> <span style="color: #990000">(*</span>pv1<span style="color: #990000">).</span>s0745<span style="color: #990000">.</span>even<span style="color: #990000">;</span> <span style="font-style: italic"><span style="color: #9A1900">// correct</span></span>
<span style="color: #008080">uint4</span> v7 <span style="color: #990000">=</span> pv1<span style="color: #990000">.</span>odd<span style="color: #990000">;</span> <span style="font-style: italic"><span style="color: #9A1900">// ill-formed: pv1 is not vector or</span></span>
<span style="font-style: italic"><span style="color: #9A1900">// vector-swizzle</span></span></tt></pre></div></div>
</li>
<li>
<p>
Abbreviating <em>postfix-expression.vector-swizzle-selector</em> as <span class="monospaced">E1.E2</span>, <span class="monospaced">E1</span> is called the vector expression.
The type and value category of <span class="monospaced">E1.E2</span> are determined as follows.
In the remainder of <a href="#vector-component-access">Vector Component Access</a>, <em>cq</em> represents either <span class="monospaced">const</span> or the absence of <span class="monospaced">const</span> and <em>vq</em> represents either <span class="monospaced">volatile</span> or the absence of <span class="monospaced">volatile</span>.
cv represents an arbitrary set of cv-qualifiers, as defined in <em>[ISO/IEC 14882:2014: basic.type.qualifier, ch. 3.9.3]</em> .
</p>
</li>
<li>
<p>
<em>vector-swizzle-selector</em> is subset of <em>identifier</em> with following syntax:
</p>
<div class="openblock">
<div class="content">
<div class="paragraph"><p><em>vector-swizzle-selector</em>:</p></div>
<div class="ulist"><ul>
<li>
<p>
<em>vector-swizzle-xyzw-selector</em>:
</p>
<div class="ulist"><ul>
<li>
<p>
<em>vector-swizzle-xyzw-selector-value</em>
</p>
</li>
<li>
<p>
<em>vector-swizzle-xyzw-selector vector-swizzle-xyzw-selector-value</em>
</p>
</li>
</ul></div>
</li>
<li>
<p>
<em>vector-swizzle-rgba-selector</em>:
</p>
<div class="ulist"><ul>
<li>
<p>
<em>vector-swizzle-rgba-selector-value</em>
</p>
</li>
<li>
<p>
<em>vector-swizzle-rgba-selector vector-swizzle-rgba-selector-value</em>
</p>
</li>
</ul></div>
</li>
<li>
<p>
<em>vector-swizzle-special-selector</em>:
</p>
<div class="ulist"><ul>
<li>
<p>
<span class="monospaced">hi</span>
</p>
</li>
<li>
<p>
<span class="monospaced">lo</span>
</p>
</li>
<li>
<p>
<span class="monospaced">even</span>
</p>
</li>
<li>
<p>
<span class="monospaced">odd</span>
</p>
</li>
</ul></div>
</li>
<li>
<p>
<em>vector-swizzle-num-selector</em>:
</p>
<div class="ulist"><ul>
<li>
<p>
<span class="monospaced">s</span> <em>vector-swizzle-num-selector-values</em>
</p>
</li>
<li>
<p>
<span class="monospaced">S</span> <em>vector-swizzle-num-selector-values</em>
</p>
</li>
</ul></div>
</li>
</ul></div>
</div></div>
<div class="openblock">
<div class="content">
<div class="paragraph"><p><em>vector-swizzle-num-selector-values</em>:</p></div>
<div class="ulist"><ul>
<li>
<p>
<em>vector-swizzle-num-selector-value</em>
</p>
</li>
<li>
<p>
<em>vector-swizzle-num-selector-values vector-swizzle-num-selector-value</em>
</p>
</li>
</ul></div>
</div></div>
<div class="paragraph"><p><em>vector-swizzle-xyzw-selector-value</em>: one of <span class="monospaced">x y z w</span></p></div>
<div class="paragraph"><p><em>vector-swizzle-rgba-selector-value</em>: one of <span class="monospaced">r g b a</span></p></div>
<div class="paragraph"><p><em>vector-swizzle-num-selector-value</em>: one of <span class="monospaced">0 1 2 3 4 5 6 7 8 9 a b c d e f A B C D E F</span></p></div>
<div class="openblock">
<div class="content">
<div class="paragraph"><p>with following restrictions:</p></div>
<div class="ulist"><ul>
<li>
<p>
<em>vector-swizzle-selector</em> in a form of <em>vector-swizzle-special-selector</em> shall only be used with vector expression with at least 2 components.
</p>
</li>
<li>
<p>
<em>vector-swizzle-selector</em> shall not select components beyond those available in vector expression.
</p>
<div class="admonitionblock">
<table><tr>
<td class="icon">
<div class="title">Note</div>
</td>
<td class="content"><a href="#selector_values_and_their_corresponding_components_in_swizzle">Selector values and their corresponding components in swizzle</a> table describes relation between selector value and components.</td>
</tr></table>
</div>
</li>
<li>
<p>
<em>vector-swizzle-selector</em> shall have swizzle size of 1, 2, 3, 4, 8 or 16.
</p>
<div class="admonitionblock">
<table><tr>
<td class="icon">
<div class="title">Note</div>
</td>
<td class="content">Result from the swizzle expression shall be either of scalar or of valid vector type.</td>
</tr></table>
</div>
</li>
</ul></div>
</div></div>
<div class="paragraph"><p>If <em>vector-swizzle-selector</em> does not meet requirements, the swizzle expression is ill-formed.</p></div>
<div class="listingblock">
<div class="content"><!-- Generator: GNU source-highlight 3.1.8
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt><span style="color: #008080">int2</span> v2<span style="color: #990000">;</span>
<span style="color: #008080">int3</span> v3<span style="color: #990000">;</span>
<span style="color: #008080">int4</span> v4<span style="color: #990000">;</span>
<span style="color: #008080">int8</span> v8<span style="color: #990000">;</span>
<span style="color: #008080">int16</span> v16<span style="color: #990000">;</span>
v4<span style="color: #990000">.</span>xyz <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000000">int3</span></span><span style="color: #990000">(</span><span style="color: #993399">1</span><span style="color: #990000">,</span> <span style="color: #993399">2</span><span style="color: #990000">,</span> <span style="color: #993399">3</span><span style="color: #990000">);</span> <span style="font-style: italic"><span style="color: #9A1900">// correct: xyz selector</span></span>
v4<span style="color: #990000">.</span>baS01 <span style="color: #990000">=</span> v8<span style="color: #990000">.</span>lo<span style="color: #990000">;</span> <span style="font-style: italic"><span style="color: #9A1900">// ill-formed: baS01 is mix of rgba</span></span>
<span style="font-style: italic"><span style="color: #9A1900">// and numerical selectors</span></span>
v3<span style="color: #990000">.</span>rx <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000000">int2</span></span><span style="color: #990000">(</span><span style="color: #993399">20</span><span style="color: #990000">,</span> <span style="color: #993399">7</span><span style="color: #990000">);</span> <span style="font-style: italic"><span style="color: #9A1900">// ill-formed: mix of rgba and</span></span>
<span style="font-style: italic"><span style="color: #9A1900">// xyzw selectors</span></span>
<span style="color: #009900">int</span> v2c1 <span style="color: #990000">=</span> v2<span style="color: #990000">.</span>z<span style="color: #990000">;</span> <span style="font-style: italic"><span style="color: #9A1900">// correct: xyzw selector</span></span>
<span style="color: #009900">int</span> v3c1 <span style="color: #990000">=</span> v3<span style="color: #990000">.</span>b<span style="color: #990000">;</span> <span style="font-style: italic"><span style="color: #9A1900">// correct: rgba selector</span></span>
<span style="color: #008080">int2</span> v4c1 <span style="color: #990000">=</span> v4<span style="color: #990000">.</span>ww<span style="color: #990000">;</span> <span style="font-style: italic"><span style="color: #9A1900">// correct: xyzw selector</span></span>
<span style="color: #008080">int3</span> v8c1 <span style="color: #990000">=</span> v8<span style="color: #990000">.</span>xyz<span style="color: #990000">;</span> <span style="font-style: italic"><span style="color: #9A1900">// ill-formed: xyzw and rgba selectors</span></span>
<span style="font-style: italic"><span style="color: #9A1900">// are not allowed on vector expressions</span></span>
<span style="font-style: italic"><span style="color: #9A1900">// with more than 4 components</span></span>
<span style="color: #008080">int2</span> v8c2 <span style="color: #990000">=</span> v8<span style="color: #990000">.</span>hi<span style="color: #990000">.</span>xyz<span style="color: #990000">;</span> <span style="font-style: italic"><span style="color: #9A1900">// correct: xyzw selector on vector</span></span>
<span style="font-style: italic"><span style="color: #9A1900">// expression v8.hi (vector-swizzle</span></span>
<span style="font-style: italic"><span style="color: #9A1900">// of int4 type)</span></span>
<span style="color: #008080">int2</span> v3c2 <span style="color: #990000">=</span> v3<span style="color: #990000">.</span>odd<span style="color: #990000">;</span> <span style="font-style: italic"><span style="color: #9A1900">// correct: special selector</span></span>
<span style="color: #008080">int2</span> v3c2 <span style="color: #990000">=</span> v3<span style="color: #990000">.</span>x<span style="color: #990000">.</span>even<span style="color: #990000">;</span> <span style="font-style: italic"><span style="color: #9A1900">// ill-formed: #1 vector expression</span></span>
<span style="font-style: italic"><span style="color: #9A1900">// is invalid (vector swizzle of</span></span>
<span style="font-style: italic"><span style="color: #9A1900">// scalar type)</span></span>
<span style="font-style: italic"><span style="color: #9A1900">// #2 special selector cannot be</span></span>
<span style="font-style: italic"><span style="color: #9A1900">// used with less than 2 components</span></span>
v3<span style="color: #990000">.</span>x <span style="color: #990000">=</span> <span style="color: #993399">1</span><span style="color: #990000">;</span> <span style="font-style: italic"><span style="color: #9A1900">// correct: xyzw selector</span></span>
v3<span style="color: #990000">.</span>w <span style="color: #990000">=</span> <span style="color: #993399">2</span><span style="color: #990000">;</span> <span style="font-style: italic"><span style="color: #9A1900">// ill-formed: there is no "w" component in int3</span></span>
v2<span style="color: #990000">.</span>gb <span style="color: #990000">=</span> v4<span style="color: #990000">.</span>hi<span style="color: #990000">;</span> <span style="font-style: italic"><span style="color: #9A1900">// ill-formed: there is no "b" component in int2</span></span>
v8<span style="color: #990000">.</span>S7890 <span style="color: #990000">=</span> v4<span style="color: #990000">;</span> <span style="font-style: italic"><span style="color: #9A1900">// ill-formed: int8 allows numerical selector</span></span>
<span style="font-style: italic"><span style="color: #9A1900">// in range 0-7</span></span>
<span style="font-weight: bold"><span style="color: #0000FF">auto</span></span> v16c1 <span style="color: #990000">=</span> v16<span style="color: #990000">.</span>s012<span style="color: #990000">;</span> <span style="font-style: italic"><span style="color: #9A1900">// correct: numerical selector</span></span>
<span style="font-weight: bold"><span style="color: #0000FF">auto</span></span> v16c2 <span style="color: #990000">=</span> v16<span style="color: #990000">.</span>s467899<span style="color: #990000">;</span> <span style="font-style: italic"><span style="color: #9A1900">// ill-formed: swizzle expression</span></span>
<span style="font-style: italic"><span style="color: #9A1900">// has not allowed size</span></span>
<span style="font-style: italic"><span style="color: #9A1900">// (there is no int6 type)</span></span>
<span style="color: #008080">int16</span> vv1 <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000000">int16</span></span><span style="color: #990000">(</span>v16<span style="color: #990000">.</span>S98aabb01<span style="color: #990000">,</span> v2<span style="color: #990000">,</span> v2<span style="color: #990000">.</span>gr<span style="color: #990000">,</span> v3<span style="color: #990000">.</span>xxxx<span style="color: #990000">);</span> <span style="font-style: italic"><span style="color: #9A1900">// correct</span></span>
<span style="color: #008080">int16</span> vv2 <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000000">int16</span></span><span style="color: #990000">(</span>v16<span style="color: #990000">.</span>S98aabb0123<span style="color: #990000">,</span> v2<span style="color: #990000">.</span>gr<span style="color: #990000">,</span> v3<span style="color: #990000">.</span>xxxx<span style="color: #990000">);</span>
<span style="font-style: italic"><span style="color: #9A1900">// ill-formed:</span></span>
<span style="font-style: italic"><span style="color: #9A1900">// although it sums up to 16</span></span>
<span style="font-style: italic"><span style="color: #9A1900">// components the</span></span>
<span style="font-style: italic"><span style="color: #9A1900">// S98aabb0123 selector has invalid</span></span>
<span style="font-style: italic"><span style="color: #9A1900">// swizzle size (there is no int10)</span></span>
</tt></pre></div></div>
</li>
<li>
<p>
<em>vector-swizzle-selector</em>, in a form of <em>vector-swizzle-xyzw-selector</em>, <em>vector-swizzle-rgba-selector</em> or <em>vector-swizzle-num-selector</em> can specify multiple values.
Each value selects single component.
Values in a selector can be repeated and specified in any order.
A number of values in a selector including repeated values is called the swizzle size.
</p>
<table class="tableblock frame-all grid-all" id="selector_values_and_their_corresponding_components_in_swizzle"
style="
width:100%;
">
<caption class="title">Table 6. Selector values and their corresponding components in swizzle</caption>
<col style="width:25%;">
<col style="width:25%;">
<col style="width:25%;">
<col style="width:25%;">
<thead>
<tr>
<th class="tableblock halign-left valign-top" ><strong>Selector</strong></th>
<th class="tableblock halign-left valign-top" ><strong>Selector value</strong></th>
<th class="tableblock halign-left valign-top" ><strong>Selected component</strong></th>
<th class="tableblock halign-left valign-top" ><strong>Required number of components in vector expression</strong></th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top" ><p class="tableblock"><em>vector-swizzle-xyzw-selector</em></p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock"><span class="monospaced">x</span></p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock">1<sup>st</sup></p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock">2, 3 or 4</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top" ><p class="tableblock"><em>vector-swizzle-xyzw-selector</em></p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock"><span class="monospaced">y</span></p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock">2<sup>nd</sup></p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock">2, 3 or 4</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top" ><p class="tableblock"><em>vector-swizzle-xyzw-selector</em></p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock"><span class="monospaced">z</span></p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock">3<sup>rd</sup></p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock">3 or 4</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top" ><p class="tableblock"><em>vector-swizzle-xyzw-selector</em></p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock"><span class="monospaced">w</span></p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock">4<sup>th</sup></p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock">4</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top" ><p class="tableblock"><em>vector-swizzle-rgba-selector</em></p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock"><span class="monospaced">r</span></p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock">1<sup>st</sup></p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock">2, 3 or 4</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top" ><p class="tableblock"><em>vector-swizzle-rgba-selector</em></p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock"><span class="monospaced">g</span></p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock">2<sup>nd</sup></p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock">2, 3 or 4</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top" ><p class="tableblock"><em>vector-swizzle-rgba-selector</em></p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock"><span class="monospaced">b</span></p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock">3<sup>rd</sup></p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock">3 or 4</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top" ><p class="tableblock"><em>vector-swizzle-rgba-selector</em></p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock"><span class="monospaced">a</span></p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock">4<sup>th</sup></p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock">4</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top" ><p class="tableblock"><em>vector-swizzle-num-selector</em></p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock"><span class="monospaced">0</span></p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock">1<sup>st</sup></p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock">2, 3, 4, 8 or 16</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top" ><p class="tableblock"><em>vector-swizzle-num-selector</em></p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock"><span class="monospaced">1</span></p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock">2<sup>nd</sup></p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock">2, 3, 4, 8 or 16</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top" ><p class="tableblock"><em>vector-swizzle-num-selector</em></p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock"><span class="monospaced">2</span></p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock">3<sup>rd</sup></p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock">3, 4, 8 or 16</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top" ><p class="tableblock"><em>vector-swizzle-num-selector</em></p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock"><span class="monospaced">3</span></p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock">4<sup>th</sup></p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock">4, 8 or 16</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top" ><p class="tableblock"><em>vector-swizzle-num-selector</em></p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock"><span class="monospaced">4</span></p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock">5<sup>th</sup></p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock">8 or 16</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top" ><p class="tableblock"><em>vector-swizzle-num-selector</em></p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock"><span class="monospaced">5</span></p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock">6<sup>th</sup></p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock">8 or 16</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top" ><p class="tableblock"><em>vector-swizzle-num-selector</em></p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock"><span class="monospaced">6</span></p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock">7<sup>th</sup></p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock">8 or 16</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top" ><p class="tableblock"><em>vector-swizzle-num-selector</em></p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock"><span class="monospaced">7</span></p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock">8<sup>th</sup></p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock">8 or 16</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top" ><p class="tableblock"><em>vector-swizzle-num-selector</em></p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock"><span class="monospaced">8</span></p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock">9<sup>th</sup></p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock">16</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top" ><p class="tableblock"><em>vector-swizzle-num-selector</em></p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock"><span class="monospaced">9</span></p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock">10<sup>th</sup></p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock">16</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top" ><p class="tableblock"><em>vector-swizzle-num-selector</em></p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock"><span class="monospaced">a</span> or <span class="monospaced">A</span></p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock">11<sup>th</sup></p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock">16</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top" ><p class="tableblock"><em>vector-swizzle-num-selector</em></p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock"><span class="monospaced">b</span> or <span class="monospaced">B</span></p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock">12<sup>th</sup></p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock">16</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top" ><p class="tableblock"><em>vector-swizzle-num-selector</em></p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock"><span class="monospaced">c</span> or <span class="monospaced">C</span></p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock">13<sup>th</sup></p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock">16</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top" ><p class="tableblock"><em>vector-swizzle-num-selector</em></p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock"><span class="monospaced">d</span> or <span class="monospaced">D</span></p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock">14<sup>th</sup></p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock">16</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top" ><p class="tableblock"><em>vector-swizzle-num-selector</em></p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock"><span class="monospaced">e</span> or <span class="monospaced">E</span></p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock">15<sup>th</sup></p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock">16</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top" ><p class="tableblock"><em>vector-swizzle-num-selector</em></p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock"><span class="monospaced">f</span> or <span class="monospaced">F</span></p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock">16<sup>th</sup></p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock">16</p></td>
</tr>
</tbody>
</table>
</li>
<li>
<p>
<em>vector-swizzle-selector</em> in a form of <em>vector-swizzle-special-selector</em> shall select:
</p>
<div class="ulist"><ul>
<li>
<p>
if number of components in vector expression is 3, the same components as if number of components of the vector expression was 4 and the 4-th component was undefined.