File: vstore_half.cl

package info (click to toggle)
pocl 1.6-5
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 17,816 kB
  • sloc: lisp: 135,476; ansic: 64,403; cpp: 32,196; vhdl: 1,040; sh: 382; python: 336; makefile: 151; pascal: 140; java: 72; xml: 49
file content (623 lines) | stat: -rw-r--r-- 34,776 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
/* OpenCL built-in library: vstore_half()

   Copyright (c) 2011 Universidad Rey Juan Carlos
   Copyright (c) 2017 Michal Babej / Tampere University of Technology

   Permission is hereby granted, free of charge, to any person obtaining a copy
   of this software and associated documentation files (the "Software"), to deal
   in the Software without restriction, including without limitation the rights
   to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
   copies of the Software, and to permit persons to whom the Software is
   furnished to do so, subject to the following conditions:

   The above copyright notice and this permission notice shall be included in
   all copies or substantial portions of the Software.

   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
   IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
   AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
   OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
   THE SOFTWARE.
*/

/* The following code is taken & adapted from half library @
 * http://half.sourceforge.net
 *
 * half - IEEE 754-based half-precision floating point library.
 *
 * Copyright (c) 2012-2017 Christian Rau <rauy@users.sourceforge.net>
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation
 * files (the "Software"), to deal in the Software without restriction,
 * including without limitation the rights to use, copy,
 * modify, merge, publish, distribute, sublicense, and/or sell copies of the
 * Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE
 * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 * DEALINGS IN THE SOFTWARE.
 */

#define ROUND_TOWARD_INFINITY 1
#define ROUND_TOWARD_NEG_INFINITY 2
#define ROUND_TOWARD_ZERO 3
#define ROUND_TO_NEAREST 4

static ushort
_cl_float2half_round (float f, int round_mode)
{
  uint bits = as_uint (f);
  ushort hbits = (bits >> 16) & 0x8000;
  bits &= 0x7FFFFFFF;
  int exp = bits >> 23;
  if (exp == 255)
    {
      ushort temp = (((bits & 0x7FFFFF) != 0) ? 0x03FF : 0x0);
      return (hbits | 0x7C00 | temp);
    }
  if (exp > 142)
    {
      if (round_mode == ROUND_TOWARD_INFINITY)
        return hbits | 0x7C00 - (hbits >> 15);
      if (round_mode == ROUND_TOWARD_NEG_INFINITY)
        return hbits | 0x7BFF + (hbits >> 15);
      return hbits | 0x7BFF + (round_mode != ROUND_TOWARD_ZERO);
    }
  int g, s;
  if (exp > 112)
    {
      g = (bits >> 12) & 1;
      s = (bits & 0xFFF) != 0;
      hbits |= ((exp - 112) << 10) | ((bits >> 13) & 0x3FF);
    }
  else if (exp > 101)
    {
      int i = 125 - exp;
      bits = (bits & 0x7FFFFF) | 0x800000;
      g = (bits >> i) & 1;
      s = (bits & ((1L << i) - 1)) != 0;
      hbits |= bits >> (i + 1);
    }
  else
    {
      g = 0;
      s = bits != 0;
    }
  if (round_mode == ROUND_TO_NEAREST)
    hbits += g & (s | hbits);
  else if (round_mode == ROUND_TOWARD_INFINITY)
    hbits += ~(hbits >> 15) & (s | g);
  else if (round_mode == ROUND_TOWARD_NEG_INFINITY)
    hbits += (hbits >> 15) & (g | s);
  return hbits;
}

static ushort
_cl_float2half (float d)
{
  return _cl_float2half_round (d, ROUND_TO_NEAREST);
}

static ushort
_cl_float2half_rte (float d)
{
  return _cl_float2half_round (d, ROUND_TO_NEAREST);
}

static ushort
_cl_float2half_rtz (float d)
{
  return _cl_float2half_round (d, ROUND_TOWARD_ZERO);
}

static ushort
_cl_float2half_rtn (float d)
{
  return _cl_float2half_round (d, ROUND_TOWARD_NEG_INFINITY);
}

static ushort
_cl_float2half_rtp (float d)
{
  return _cl_float2half_round (d, ROUND_TOWARD_INFINITY);
}

#ifdef cl_khr_fp64

static ushort
_cl_double2half_round (double value, int round_mode)
{
  ulong bits = as_ulong (value);
  uint hi = (bits >> 32);
  uint lo = (bits & 0xFFFFFFFF);
  ushort hbits = (hi >> 16) & 0x8000;
  hi &= 0x7FFFFFFF;
  int exp = hi >> 20;
  if (exp == 2047)
    {
      ushort temp = ((bits & 0xFFFFFFFFFFFFF) != 0 ? 0x03FF : 0x0);
      return (hbits | 0x7C00 | temp);
    }
  if (exp > 1038)
    {
      if (round_mode == ROUND_TOWARD_INFINITY)
        return (hbits | 0x7C00 - (hbits >> 15));
      if (round_mode == ROUND_TOWARD_NEG_INFINITY)
        return (hbits | 0x7BFF + (hbits >> 15));
      return (hbits | 0x7BFF + (round_mode != ROUND_TOWARD_ZERO));
    }
  int g;
  int s = (lo != 0);
  if (exp > 1008)
    {
      g = (hi >> 9) & 1;
      s |= (hi & 0x1FF) != 0;
      hbits |= ((exp - 1008) << 10) | ((hi >> 10) & 0x3FF);
    }
  else if (exp > 997)
    {
      int i = 1018 - exp;
      hi = (hi & 0xFFFFF) | 0x100000;
      g = (hi >> i) & 1;
      s |= (hi & ((1L << i) - 1)) != 0;
      hbits |= hi >> (i + 1);
    }
  else
    {
      g = 0;
      s |= hi != 0;
    }
  if (round_mode == ROUND_TO_NEAREST)
    hbits += g & (s | hbits);
  else if (round_mode == ROUND_TOWARD_INFINITY)
    hbits += ~(hbits >> 15) & (s | g);
  else if (round_mode == ROUND_TOWARD_NEG_INFINITY)
    hbits += (hbits >> 15) & (g | s);
  return hbits;
}

static ushort
_cl_double2half (double d)
{
  return _cl_double2half_round (d, ROUND_TO_NEAREST);
}

static ushort
_cl_double2half_rte (double d)
{
  return _cl_double2half_round (d, ROUND_TO_NEAREST);
}

static ushort
_cl_double2half_rtz (double d)
{
  return _cl_double2half_round (d, ROUND_TOWARD_ZERO);
}

static ushort
_cl_double2half_rtn (double d)
{
  return _cl_double2half_round (d, ROUND_TOWARD_NEG_INFINITY);
}

static ushort
_cl_double2half_rtp (double d)
{
  return _cl_double2half_round (d, ROUND_TOWARD_INFINITY);
}

#endif

#ifdef __F16C__

ushort4 _cl_float2half4 (const float4 data);
ushort8 _cl_float2half8 (const float8 data);
ushort4 _cl_float2half4_rte (const float4 data);
ushort8 _cl_float2half8_rte (const float8 data);
ushort4 _cl_float2half4_rtn (const float4 data);
ushort8 _cl_float2half8_rtn (const float8 data);
ushort4 _cl_float2half4_rtp (const float4 data);
ushort8 _cl_float2half8_rtp (const float8 data);
ushort4 _cl_float2half4_rtz (const float4 data);
ushort8 _cl_float2half8_rtz (const float8 data);

#define IMPLEMENT_VSTORE_HALF(MOD, SUFFIX)                                    \
                                                                              \
  void _CL_OVERLOADABLE vstore_half##SUFFIX (float data, size_t offset,       \
                                             MOD half *p)                     \
  {                                                                           \
    ((MOD ushort *)p)[offset] = _cl_float2half##SUFFIX (data);                \
  }                                                                           \
                                                                              \
  void _CL_OVERLOADABLE vstore_half2##SUFFIX (float2 data, size_t offset,     \
                                              MOD half *p)                    \
  {                                                                           \
    vstore_half##SUFFIX (data.lo, offset * 2, p);                             \
    vstore_half##SUFFIX (data.hi, offset * 2 + 1, p);                         \
  }                                                                           \
                                                                              \
  void _CL_OVERLOADABLE vstore_half3##SUFFIX (float3 data, size_t offset,     \
                                              MOD half *p)                    \
  {                                                                           \
    vstore_half##SUFFIX (data.x, offset * 3, p);                              \
    vstore_half##SUFFIX (data.y, offset * 3 + 1, p);                          \
    vstore_half##SUFFIX (data.z, offset * 3 + 2, p);                          \
  }                                                                           \
                                                                              \
  void _CL_OVERLOADABLE vstore_half4##SUFFIX (float4 data, size_t offset,     \
                                              MOD half *p)                    \
  {                                                                           \
    ((MOD ushort4 *)p)[offset] = _cl_float2half4##SUFFIX (data);              \
  }                                                                           \
                                                                              \
  void _CL_OVERLOADABLE vstore_half8##SUFFIX (float8 data, size_t offset,     \
                                              MOD half *p)                    \
  {                                                                           \
    ((MOD ushort8 *)p)[offset] = _cl_float2half8##SUFFIX (data);              \
  }                                                                           \
                                                                              \
  void _CL_OVERLOADABLE vstore_half16##SUFFIX (float16 data, size_t offset,   \
                                               MOD half *p)                   \
  {                                                                           \
    ((MOD ushort8 *)p)[offset * 2] = _cl_float2half8##SUFFIX (data.lo);       \
    ((MOD ushort8 *)p)[offset * 2 + 1] = _cl_float2half8##SUFFIX (data.hi);   \
  }                                                                           \
                                                                              \
  void _CL_OVERLOADABLE vstorea_half##SUFFIX (float data, size_t offset,      \
                                              MOD half *p)                    \
  {                                                                           \
    ((MOD ushort *)p)[offset] = _cl_float2half##SUFFIX (data);                \
  }                                                                           \
                                                                              \
  void _CL_OVERLOADABLE vstorea_half2##SUFFIX (float2 data, size_t offset,    \
                                               MOD half *p)                   \
  {                                                                           \
    vstorea_half##SUFFIX (data.lo, offset * 2, p);                            \
    vstorea_half##SUFFIX (data.hi, offset * 2 + 1, p);                        \
  }                                                                           \
                                                                              \
  void _CL_OVERLOADABLE vstorea_half3##SUFFIX (float3 data, size_t offset,    \
                                               MOD half *p)                   \
  {                                                                           \
    vstorea_half2##SUFFIX (data.lo, offset * 2, p);                           \
    vstorea_half2##SUFFIX ((float2) (data.z, 0.0f), offset * 2 + 1, p);       \
  }                                                                           \
                                                                              \
  void _CL_OVERLOADABLE vstorea_half4##SUFFIX (float4 data, size_t offset,    \
                                               MOD half *p)                   \
  {                                                                           \
    ((MOD ushort4 *)p)[offset] = _cl_float2half4##SUFFIX (data);              \
  }                                                                           \
                                                                              \
  void _CL_OVERLOADABLE vstorea_half8##SUFFIX (float8 data, size_t offset,    \
                                               MOD half *p)                   \
  {                                                                           \
    ((MOD ushort8 *)p)[offset] = _cl_float2half8##SUFFIX (data);              \
  }                                                                           \
                                                                              \
  void _CL_OVERLOADABLE vstorea_half16##SUFFIX (float16 data, size_t offset,  \
                                                MOD half *p)                  \
  {                                                                           \
    ((MOD ushort8 *)p)[offset * 2] = _cl_float2half8##SUFFIX (data.lo);       \
    ((MOD ushort8 *)p)[offset * 2 + 1] = _cl_float2half8##SUFFIX (data.hi);   \
  }

// __F16C__
#else

#define IMPLEMENT_VSTORE_HALF(MOD, SUFFIX)                                    \
                                                                              \
  void _CL_OVERLOADABLE vstore_half##SUFFIX (float data, size_t offset,       \
                                             MOD half *p)                     \
  {                                                                           \
    ((MOD ushort *)p)[offset] = _cl_float2half##SUFFIX (data);                \
  }                                                                           \
                                                                              \
  void _CL_OVERLOADABLE vstore_half2##SUFFIX (float2 data, size_t offset,     \
                                              MOD half *p)                    \
  {                                                                           \
    vstore_half##SUFFIX (data.lo, offset * 2, p);                             \
    vstore_half##SUFFIX (data.hi, offset * 2 + 1, p);                         \
  }                                                                           \
                                                                              \
  void _CL_OVERLOADABLE vstore_half3##SUFFIX (float3 data, size_t offset,     \
                                              MOD half *p)                    \
  {                                                                           \
    vstore_half##SUFFIX (data.x, offset * 3, p);                              \
    vstore_half##SUFFIX (data.y, offset * 3 + 1, p);                          \
    vstore_half##SUFFIX (data.z, offset * 3 + 2, p);                          \
  }                                                                           \
                                                                              \
  void _CL_OVERLOADABLE vstore_half4##SUFFIX (float4 data, size_t offset,     \
                                              MOD half *p)                    \
  {                                                                           \
    vstore_half2##SUFFIX (data.lo, offset * 2, p);                            \
    vstore_half2##SUFFIX (data.hi, offset * 2 + 1, p);                        \
  }                                                                           \
                                                                              \
  void _CL_OVERLOADABLE vstore_half8##SUFFIX (float8 data, size_t offset,     \
                                              MOD half *p)                    \
  {                                                                           \
    vstore_half4##SUFFIX (data.lo, offset * 2, p);                            \
    vstore_half4##SUFFIX (data.hi, offset * 2 + 1, p);                        \
  }                                                                           \
                                                                              \
  void _CL_OVERLOADABLE vstore_half16##SUFFIX (float16 data, size_t offset,   \
                                               MOD half *p)                   \
  {                                                                           \
    vstore_half8##SUFFIX (data.lo, offset * 2, p);                            \
    vstore_half8##SUFFIX (data.hi, offset * 2 + 1, p);                        \
  }                                                                           \
                                                                              \
  void _CL_OVERLOADABLE vstorea_half##SUFFIX (float data, size_t offset,      \
                                              MOD half *p)                    \
  {                                                                           \
    ((MOD ushort *)p)[offset] = _cl_float2half##SUFFIX (data);                \
  }                                                                           \
                                                                              \
  void _CL_OVERLOADABLE vstorea_half2##SUFFIX (float2 data, size_t offset,    \
                                               MOD half *p)                   \
  {                                                                           \
    vstorea_half##SUFFIX (data.lo, offset * 2, p);                            \
    vstorea_half##SUFFIX (data.hi, offset * 2 + 1, p);                        \
  }                                                                           \
                                                                              \
  void _CL_OVERLOADABLE vstorea_half3##SUFFIX (float3 data, size_t offset,    \
                                               MOD half *p)                   \
  {                                                                           \
    vstorea_half2##SUFFIX (data.lo, offset * 2, p);                           \
    vstorea_half2##SUFFIX ((float2) (data.z, 0.0f), offset * 2 + 1, p);       \
  }                                                                           \
                                                                              \
  void _CL_OVERLOADABLE vstorea_half4##SUFFIX (float4 data, size_t offset,    \
                                               MOD half *p)                   \
  {                                                                           \
    vstorea_half2##SUFFIX (data.lo, offset * 2, p);                           \
    vstorea_half2##SUFFIX (data.hi, offset * 2 + 1, p);                       \
  }                                                                           \
                                                                              \
  void _CL_OVERLOADABLE vstorea_half8##SUFFIX (float8 data, size_t offset,    \
                                               MOD half *p)                   \
  {                                                                           \
    vstorea_half4##SUFFIX (data.lo, offset * 2, p);                           \
    vstorea_half4##SUFFIX (data.hi, offset * 2 + 1, p);                       \
  }                                                                           \
                                                                              \
  void _CL_OVERLOADABLE vstorea_half16##SUFFIX (float16 data, size_t offset,  \
                                                MOD half *p)                  \
  {                                                                           \
    vstorea_half8##SUFFIX (data.lo, offset * 2, p);                           \
    vstorea_half8##SUFFIX (data.hi, offset * 2 + 1, p);                       \
  }

#endif

IMPLEMENT_VSTORE_HALF (__global, )
IMPLEMENT_VSTORE_HALF (__global, _rte)
IMPLEMENT_VSTORE_HALF (__global, _rtz)
IMPLEMENT_VSTORE_HALF (__global, _rtp)
IMPLEMENT_VSTORE_HALF (__global, _rtn)
IMPLEMENT_VSTORE_HALF (__local, )
IMPLEMENT_VSTORE_HALF (__local, _rte)
IMPLEMENT_VSTORE_HALF (__local, _rtz)
IMPLEMENT_VSTORE_HALF (__local, _rtp)
IMPLEMENT_VSTORE_HALF (__local, _rtn)
IMPLEMENT_VSTORE_HALF (__private, )
IMPLEMENT_VSTORE_HALF (__private, _rte)
IMPLEMENT_VSTORE_HALF (__private, _rtz)
IMPLEMENT_VSTORE_HALF (__private, _rtp)
IMPLEMENT_VSTORE_HALF (__private, _rtn)

#ifdef cl_khr_fp64

///#ifdef __F16C__
#if 0

#define IMPLEMENT_VSTORE_HALF_DBL(MOD, SUFFIX)                                \
                                                                              \
  void _CL_OVERLOADABLE vstore_half##SUFFIX (double data, size_t offset,      \
                                             MOD half *p)                     \
  {                                                                           \
    ((MOD ushort *)p)[offset] = _cl_double2half##SUFFIX (data);               \
  }                                                                           \
                                                                              \
  void _CL_OVERLOADABLE vstore_half2##SUFFIX (double2 data, size_t offset,    \
                                              MOD half *p)                    \
  {                                                                           \
    vstore_half##SUFFIX (data.lo, offset * 2, p);                             \
    vstore_half##SUFFIX (data.hi, offset * 2 + 1, p);                         \
  }                                                                           \
                                                                              \
  void _CL_OVERLOADABLE vstore_half3##SUFFIX (double3 data, size_t offset,    \
                                              MOD half *p)                    \
  {                                                                           \
    vstore_half##SUFFIX (data.x, offset * 3, p);                              \
    vstore_half##SUFFIX (data.y, offset * 3 + 1, p);                          \
    vstore_half##SUFFIX (data.z, offset * 3 + 2, p);                          \
  }                                                                           \
                                                                              \
  void _CL_OVERLOADABLE vstore_half4##SUFFIX (double4 data, size_t offset,    \
                                              MOD half *p)                    \
  {                                                                           \
    ((MOD ushort4 *)p)[offset]                                                \
        = _cl_float2half4##SUFFIX (convert_float4##SUFFIX (data));            \
  }                                                                           \
                                                                              \
  void _CL_OVERLOADABLE vstore_half8##SUFFIX (double8 data, size_t offset,    \
                                              MOD half *p)                    \
  {                                                                           \
    ((MOD ushort8 *)p)[offset]                                                \
        = _cl_float2half8##SUFFIX (convert_float8##SUFFIX (data));            \
  }                                                                           \
                                                                              \
  void _CL_OVERLOADABLE vstore_half16##SUFFIX (double16 data, size_t offset,  \
                                               MOD half *p)                   \
  {                                                                           \
    ((MOD ushort8 *)p)[offset * 2]                                            \
        = _cl_float2half8##SUFFIX (convert_float8##SUFFIX (data.lo));         \
    ((MOD ushort8 *)p)[offset * 2 + 1]                                        \
        = _cl_float2half8##SUFFIX (convert_float8##SUFFIX (data.hi));         \
  }                                                                           \
                                                                              \
  void _CL_OVERLOADABLE vstorea_half##SUFFIX (double data, size_t offset,     \
                                              MOD half *p)                    \
  {                                                                           \
    ((MOD ushort *)p)[offset] = _cl_double2half##SUFFIX (data);               \
  }                                                                           \
                                                                              \
  void _CL_OVERLOADABLE vstorea_half2##SUFFIX (double2 data, size_t offset,   \
                                               MOD half *p)                   \
  {                                                                           \
    vstorea_half##SUFFIX (data.lo, offset * 2, p);                            \
    vstorea_half##SUFFIX (data.hi, offset * 2 + 1, p);                        \
  }                                                                           \
                                                                              \
  void _CL_OVERLOADABLE vstorea_half3##SUFFIX (double3 data, size_t offset,   \
                                               MOD half *p)                   \
  {                                                                           \
    vstorea_half2##SUFFIX (data.lo, offset * 2, p);                           \
    vstorea_half2##SUFFIX ((float2) (data.z, 0.0f), offset * 2 + 1, p);       \
  }                                                                           \
                                                                              \
  void _CL_OVERLOADABLE vstorea_half4##SUFFIX (double4 data, size_t offset,   \
                                               MOD half *p)                   \
  {                                                                           \
    ((MOD ushort4 *)p)[offset]                                                \
        = _cl_float2half4##SUFFIX (convert_float4##SUFFIX (data));            \
  }                                                                           \
                                                                              \
  void _CL_OVERLOADABLE vstorea_half8##SUFFIX (double8 data, size_t offset,   \
                                               MOD half *p)                   \
  {                                                                           \
    ((MOD ushort8 *)p)[offset]                                                \
        = _cl_float2half8##SUFFIX (convert_float8##SUFFIX (data));            \
  }                                                                           \
                                                                              \
  void _CL_OVERLOADABLE vstorea_half16##SUFFIX (double16 data, size_t offset, \
                                                MOD half *p)                  \
  {                                                                           \
    ((MOD ushort8 *)p)[offset * 2]                                            \
        = _cl_float2half8##SUFFIX (convert_float8##SUFFIX (data.lo));         \
    ((MOD ushort8 *)p)[offset * 2 + 1]                                        \
        = _cl_float2half8##SUFFIX (convert_float8##SUFFIX (data.hi));         \
  }

// __F16C__
#else

#define IMPLEMENT_VSTORE_HALF_DBL(MOD, SUFFIX)                                \
                                                                              \
  void _CL_OVERLOADABLE vstore_half##SUFFIX (double data, size_t offset,      \
                                             MOD half *p)                     \
  {                                                                           \
    ((MOD ushort *)p)[offset] = _cl_double2half##SUFFIX (data);               \
  }                                                                           \
                                                                              \
  void _CL_OVERLOADABLE vstore_half2##SUFFIX (double2 data, size_t offset,    \
                                              MOD half *p)                    \
  {                                                                           \
    vstore_half##SUFFIX (data.lo, offset * 2, p);                             \
    vstore_half##SUFFIX (data.hi, offset * 2 + 1, p);                         \
  }                                                                           \
                                                                              \
  void _CL_OVERLOADABLE vstore_half3##SUFFIX (double3 data, size_t offset,    \
                                              MOD half *p)                    \
  {                                                                           \
    vstore_half##SUFFIX (data.x, offset * 3, p);                              \
    vstore_half##SUFFIX (data.y, offset * 3 + 1, p);                          \
    vstore_half##SUFFIX (data.z, offset * 3 + 2, p);                          \
  }                                                                           \
                                                                              \
  void _CL_OVERLOADABLE vstore_half4##SUFFIX (double4 data, size_t offset,    \
                                              MOD half *p)                    \
  {                                                                           \
    vstore_half2##SUFFIX (data.lo, offset * 2, p);                            \
    vstore_half2##SUFFIX (data.hi, offset * 2 + 1, p);                        \
  }                                                                           \
                                                                              \
  void _CL_OVERLOADABLE vstore_half8##SUFFIX (double8 data, size_t offset,    \
                                              MOD half *p)                    \
  {                                                                           \
    vstore_half4##SUFFIX (data.lo, offset * 2, p);                            \
    vstore_half4##SUFFIX (data.hi, offset * 2 + 1, p);                        \
  }                                                                           \
                                                                              \
  void _CL_OVERLOADABLE vstore_half16##SUFFIX (double16 data, size_t offset,  \
                                               MOD half *p)                   \
  {                                                                           \
    vstore_half8##SUFFIX (data.lo, offset * 2, p);                            \
    vstore_half8##SUFFIX (data.hi, offset * 2 + 1, p);                        \
  }                                                                           \
                                                                              \
  void _CL_OVERLOADABLE vstorea_half##SUFFIX (double data, size_t offset,     \
                                              MOD half *p)                    \
  {                                                                           \
    ((MOD ushort *)p)[offset] = _cl_double2half##SUFFIX (data);               \
  }                                                                           \
                                                                              \
  void _CL_OVERLOADABLE vstorea_half2##SUFFIX (double2 data, size_t offset,   \
                                               MOD half *p)                   \
  {                                                                           \
    vstorea_half##SUFFIX (data.lo, offset * 2, p);                            \
    vstorea_half##SUFFIX (data.hi, offset * 2 + 1, p);                        \
  }                                                                           \
                                                                              \
  void _CL_OVERLOADABLE vstorea_half3##SUFFIX (double3 data, size_t offset,   \
                                               MOD half *p)                   \
  {                                                                           \
    vstorea_half2##SUFFIX (data.lo, offset * 2, p);                           \
    vstorea_half2##SUFFIX ((double2) (data.z, 0.0), offset * 2 + 1, p);       \
  }                                                                           \
                                                                              \
  void _CL_OVERLOADABLE vstorea_half4##SUFFIX (double4 data, size_t offset,   \
                                               MOD half *p)                   \
  {                                                                           \
    vstorea_half2##SUFFIX (data.lo, offset * 2, p);                           \
    vstorea_half2##SUFFIX (data.hi, offset * 2 + 1, p);                       \
  }                                                                           \
                                                                              \
  void _CL_OVERLOADABLE vstorea_half8##SUFFIX (double8 data, size_t offset,   \
                                               MOD half *p)                   \
  {                                                                           \
    vstorea_half4##SUFFIX (data.lo, offset * 2, p);                           \
    vstorea_half4##SUFFIX (data.hi, offset * 2 + 1, p);                       \
  }                                                                           \
                                                                              \
  void _CL_OVERLOADABLE vstorea_half16##SUFFIX (double16 data, size_t offset, \
                                                MOD half *p)                  \
  {                                                                           \
    vstorea_half8##SUFFIX (data.lo, offset * 2, p);                           \
    vstorea_half8##SUFFIX (data.hi, offset * 2 + 1, p);                       \
  }

#endif

IMPLEMENT_VSTORE_HALF_DBL (__global, )
IMPLEMENT_VSTORE_HALF_DBL (__global, _rte)
IMPLEMENT_VSTORE_HALF_DBL (__global, _rtz)
IMPLEMENT_VSTORE_HALF_DBL (__global, _rtp)
IMPLEMENT_VSTORE_HALF_DBL (__global, _rtn)
IMPLEMENT_VSTORE_HALF_DBL (__local, )
IMPLEMENT_VSTORE_HALF_DBL (__local, _rte)
IMPLEMENT_VSTORE_HALF_DBL (__local, _rtz)
IMPLEMENT_VSTORE_HALF_DBL (__local, _rtp)
IMPLEMENT_VSTORE_HALF_DBL (__local, _rtn)
IMPLEMENT_VSTORE_HALF_DBL (__private, )
IMPLEMENT_VSTORE_HALF_DBL (__private, _rte)
IMPLEMENT_VSTORE_HALF_DBL (__private, _rtz)
IMPLEMENT_VSTORE_HALF_DBL (__private, _rtp)
IMPLEMENT_VSTORE_HALF_DBL (__private, _rtn)

#endif