@@ -386,14 +386,200 @@ class half {
386
386
operator --();
387
387
return ret;
388
388
}
389
- constexpr half &operator -() {
390
- Data = -Data;
391
- return *this ;
392
- }
393
- constexpr half operator -() const {
394
- half r = *this ;
395
- return -r;
396
- }
389
+ __SYCL_CONSTEXPR_HALF friend half operator -(const half other) {
390
+ return half (-other.Data );
391
+ }
392
+
393
+ // Operator +, -, *, /
394
+ #define OP (op, op_eq ) \
395
+ __SYCL_CONSTEXPR_HALF friend half operator op (const half lhs, \
396
+ const half rhs) { \
397
+ half rtn = lhs; \
398
+ rtn op_eq rhs; \
399
+ return rtn; \
400
+ } \
401
+ __SYCL_CONSTEXPR_HALF friend double operator op (const half lhs, \
402
+ const double rhs) { \
403
+ double rtn = lhs; \
404
+ rtn op_eq rhs; \
405
+ return rtn; \
406
+ } \
407
+ __SYCL_CONSTEXPR_HALF friend double operator op (const double lhs, \
408
+ const half rhs) { \
409
+ double rtn = lhs; \
410
+ rtn op_eq rhs; \
411
+ return rtn; \
412
+ } \
413
+ __SYCL_CONSTEXPR_HALF friend float operator op (const half lhs, \
414
+ const float rhs) { \
415
+ float rtn = lhs; \
416
+ rtn op_eq rhs; \
417
+ return rtn; \
418
+ } \
419
+ __SYCL_CONSTEXPR_HALF friend float operator op (const float lhs, \
420
+ const half rhs) { \
421
+ float rtn = lhs; \
422
+ rtn op_eq rhs; \
423
+ return rtn; \
424
+ } \
425
+ __SYCL_CONSTEXPR_HALF friend half operator op (const half lhs, \
426
+ const int rhs) { \
427
+ half rtn = lhs; \
428
+ rtn op_eq rhs; \
429
+ return rtn; \
430
+ } \
431
+ __SYCL_CONSTEXPR_HALF friend half operator op (const int lhs, \
432
+ const half rhs) { \
433
+ half rtn = lhs; \
434
+ rtn op_eq rhs; \
435
+ return rtn; \
436
+ } \
437
+ __SYCL_CONSTEXPR_HALF friend half operator op (const half lhs, \
438
+ const long rhs) { \
439
+ half rtn = lhs; \
440
+ rtn op_eq rhs; \
441
+ return rtn; \
442
+ } \
443
+ __SYCL_CONSTEXPR_HALF friend half operator op (const long lhs, \
444
+ const half rhs) { \
445
+ half rtn = lhs; \
446
+ rtn op_eq rhs; \
447
+ return rtn; \
448
+ } \
449
+ __SYCL_CONSTEXPR_HALF friend half operator op (const half lhs, \
450
+ const long long rhs) { \
451
+ half rtn = lhs; \
452
+ rtn op_eq rhs; \
453
+ return rtn; \
454
+ } \
455
+ __SYCL_CONSTEXPR_HALF friend half operator op (const long long lhs, \
456
+ const half rhs) { \
457
+ half rtn = lhs; \
458
+ rtn op_eq rhs; \
459
+ return rtn; \
460
+ } \
461
+ __SYCL_CONSTEXPR_HALF friend half operator op (const half &lhs, \
462
+ const unsigned int &rhs) { \
463
+ half rtn = lhs; \
464
+ rtn op_eq rhs; \
465
+ return rtn; \
466
+ } \
467
+ __SYCL_CONSTEXPR_HALF friend half operator op (const unsigned int &lhs, \
468
+ const half &rhs) { \
469
+ half rtn = lhs; \
470
+ rtn op_eq rhs; \
471
+ return rtn; \
472
+ } \
473
+ __SYCL_CONSTEXPR_HALF friend half operator op (const half &lhs, \
474
+ const unsigned long &rhs) { \
475
+ half rtn = lhs; \
476
+ rtn op_eq rhs; \
477
+ return rtn; \
478
+ } \
479
+ __SYCL_CONSTEXPR_HALF friend half operator op (const unsigned long &lhs, \
480
+ const half &rhs) { \
481
+ half rtn = lhs; \
482
+ rtn op_eq rhs; \
483
+ return rtn; \
484
+ } \
485
+ __SYCL_CONSTEXPR_HALF friend half operator op ( \
486
+ const half &lhs, const unsigned long long &rhs) { \
487
+ half rtn = lhs; \
488
+ rtn op_eq rhs; \
489
+ return rtn; \
490
+ } \
491
+ __SYCL_CONSTEXPR_HALF friend half operator op (const unsigned long long &lhs, \
492
+ const half &rhs) { \
493
+ half rtn = lhs; \
494
+ rtn op_eq rhs; \
495
+ return rtn; \
496
+ }
497
+ OP (+, +=)
498
+ OP (-, -=)
499
+ OP (*, *=)
500
+ OP (/, /=)
501
+
502
+ #undef OP
503
+
504
+ // Operator ==, !=, <, >, <=, >=
505
+ #define OP (op ) \
506
+ __SYCL_CONSTEXPR_HALF friend bool operator op (const half &lhs, \
507
+ const half &rhs) { \
508
+ return lhs.Data op rhs.Data ; \
509
+ } \
510
+ __SYCL_CONSTEXPR_HALF friend bool operator op (const half &lhs, \
511
+ const double &rhs) { \
512
+ return lhs.Data op rhs; \
513
+ } \
514
+ __SYCL_CONSTEXPR_HALF friend bool operator op (const double &lhs, \
515
+ const half &rhs) { \
516
+ return lhs op rhs.Data ; \
517
+ } \
518
+ __SYCL_CONSTEXPR_HALF friend bool operator op (const half &lhs, \
519
+ const float &rhs) { \
520
+ return lhs.Data op rhs; \
521
+ } \
522
+ __SYCL_CONSTEXPR_HALF friend bool operator op (const float &lhs, \
523
+ const half &rhs) { \
524
+ return lhs op rhs.Data ; \
525
+ } \
526
+ __SYCL_CONSTEXPR_HALF friend bool operator op (const half &lhs, \
527
+ const int &rhs) { \
528
+ return lhs.Data op rhs; \
529
+ } \
530
+ __SYCL_CONSTEXPR_HALF friend bool operator op (const int &lhs, \
531
+ const half &rhs) { \
532
+ return lhs op rhs.Data ; \
533
+ } \
534
+ __SYCL_CONSTEXPR_HALF friend bool operator op (const half &lhs, \
535
+ const long &rhs) { \
536
+ return lhs.Data op rhs; \
537
+ } \
538
+ __SYCL_CONSTEXPR_HALF friend bool operator op (const long &lhs, \
539
+ const half &rhs) { \
540
+ return lhs op rhs.Data ; \
541
+ } \
542
+ __SYCL_CONSTEXPR_HALF friend bool operator op (const half &lhs, \
543
+ const long long &rhs) { \
544
+ return lhs.Data op rhs; \
545
+ } \
546
+ __SYCL_CONSTEXPR_HALF friend bool operator op (const long long &lhs, \
547
+ const half &rhs) { \
548
+ return lhs op rhs.Data ; \
549
+ } \
550
+ __SYCL_CONSTEXPR_HALF friend bool operator op (const half &lhs, \
551
+ const unsigned int &rhs) { \
552
+ return lhs.Data op rhs; \
553
+ } \
554
+ __SYCL_CONSTEXPR_HALF friend bool operator op (const unsigned int &lhs, \
555
+ const half &rhs) { \
556
+ return lhs op rhs.Data ; \
557
+ } \
558
+ __SYCL_CONSTEXPR_HALF friend bool operator op (const half &lhs, \
559
+ const unsigned long &rhs) { \
560
+ return lhs.Data op rhs; \
561
+ } \
562
+ __SYCL_CONSTEXPR_HALF friend bool operator op (const unsigned long &lhs, \
563
+ const half &rhs) { \
564
+ return lhs op rhs.Data ; \
565
+ } \
566
+ __SYCL_CONSTEXPR_HALF friend bool operator op ( \
567
+ const half &lhs, const unsigned long long &rhs) { \
568
+ return lhs.Data op rhs; \
569
+ } \
570
+ __SYCL_CONSTEXPR_HALF friend bool operator op (const unsigned long long &lhs, \
571
+ const half &rhs) { \
572
+ return lhs op rhs.Data ; \
573
+ }
574
+ OP (==)
575
+ OP (!=)
576
+ OP (<)
577
+ OP (>)
578
+ OP (<=)
579
+ OP (>=)
580
+
581
+ #undef OP
582
+
397
583
// Operator float
398
584
__SYCL_CONSTEXPR_HALF operator float () const {
399
585
return static_cast <float >(Data);
0 commit comments