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
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
|
/*
* Copyright 2009-2015 Samy Al Bahra.
* Copyright 2011 David Joseph.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef CK_PR_H
#define CK_PR_H
#include <ck_cc.h>
#include <ck_limits.h>
#include <ck_md.h>
#include <ck_stdint.h>
#include <ck_stdbool.h>
/*
* Default to using builtins for clang analyzer, coverity, and sparse:
* inline assembly is often too opaque for useful analysis. Override
* the defaults by defining CK_USE_CC_BUILTINS=0 or 1.
*/
#if !defined(CK_USE_CC_BUILTINS)
#if defined(__clang_analyzer__) || defined(__COVERITY__) || defined(__CHECKER__)
#define CK_USE_CC_BUILTINS 1
#else
#define CK_USE_CC_BUILTINS 0
#endif
#endif
#if !CK_USE_CC_BUILTINS
#if defined(__x86_64__)
#include "gcc/x86_64/ck_pr.h"
#elif defined(__x86__)
#include "gcc/x86/ck_pr.h"
#elif defined(__sparcv9__)
#include "gcc/sparcv9/ck_pr.h"
#elif defined(__ppc64__)
#include "gcc/ppc64/ck_pr.h"
#elif defined(__s390x__)
#include "gcc/s390x/ck_pr.h"
#elif defined(__ppc__)
#include "gcc/ppc/ck_pr.h"
#elif defined(__arm__)
#include "gcc/arm/ck_pr.h"
#elif defined(__aarch64__)
#include "gcc/aarch64/ck_pr.h"
#elif !defined(__GNUC__)
#error Your platform is unsupported
#endif
#endif /* !CK_USE_CC_BUILTINS */
#if defined(__GNUC__)
#include "gcc/ck_pr.h"
#endif
#define CK_PR_FENCE_EMIT(T) \
CK_CC_INLINE static void \
ck_pr_fence_##T(void) \
{ \
ck_pr_fence_strict_##T(); \
return; \
}
#define CK_PR_FENCE_NOOP(T) \
CK_CC_INLINE static void \
ck_pr_fence_##T(void) \
{ \
ck_pr_barrier(); \
return; \
}
/*
* None of the currently supported platforms allow for data-dependent
* load ordering.
*/
CK_PR_FENCE_NOOP(load_depends)
#define ck_pr_fence_strict_load_depends ck_pr_fence_load_depends
/*
* In memory models where atomic operations do not have serializing
* effects, atomic read-modify-write operations are modeled as stores.
*/
#if defined(CK_MD_RMO)
/*
* Only stores to the same location have a global
* ordering.
*/
CK_PR_FENCE_EMIT(atomic)
CK_PR_FENCE_EMIT(atomic_load)
CK_PR_FENCE_EMIT(atomic_store)
CK_PR_FENCE_EMIT(store_atomic)
CK_PR_FENCE_EMIT(load_atomic)
CK_PR_FENCE_EMIT(load_store)
CK_PR_FENCE_EMIT(store_load)
CK_PR_FENCE_EMIT(load)
CK_PR_FENCE_EMIT(store)
CK_PR_FENCE_EMIT(memory)
CK_PR_FENCE_EMIT(acquire)
CK_PR_FENCE_EMIT(release)
CK_PR_FENCE_EMIT(acqrel)
CK_PR_FENCE_EMIT(lock)
CK_PR_FENCE_EMIT(unlock)
#elif defined(CK_MD_PSO)
/*
* Anything can be re-ordered with respect to stores.
* Otherwise, loads are executed in-order.
*/
CK_PR_FENCE_EMIT(atomic)
CK_PR_FENCE_NOOP(atomic_load)
CK_PR_FENCE_EMIT(atomic_store)
CK_PR_FENCE_EMIT(store_atomic)
CK_PR_FENCE_NOOP(load_atomic)
CK_PR_FENCE_EMIT(load_store)
CK_PR_FENCE_EMIT(store_load)
CK_PR_FENCE_NOOP(load)
CK_PR_FENCE_EMIT(store)
CK_PR_FENCE_EMIT(memory)
CK_PR_FENCE_EMIT(acquire)
CK_PR_FENCE_EMIT(release)
CK_PR_FENCE_EMIT(acqrel)
CK_PR_FENCE_EMIT(lock)
CK_PR_FENCE_EMIT(unlock)
#elif defined(CK_MD_TSO)
/*
* Only loads are re-ordered and only with respect to
* prior stores. Atomic operations are serializing.
*/
CK_PR_FENCE_NOOP(atomic)
CK_PR_FENCE_NOOP(atomic_load)
CK_PR_FENCE_NOOP(atomic_store)
CK_PR_FENCE_NOOP(store_atomic)
CK_PR_FENCE_NOOP(load_atomic)
CK_PR_FENCE_NOOP(load_store)
CK_PR_FENCE_EMIT(store_load)
CK_PR_FENCE_NOOP(load)
CK_PR_FENCE_NOOP(store)
CK_PR_FENCE_EMIT(memory)
CK_PR_FENCE_NOOP(acquire)
CK_PR_FENCE_NOOP(release)
CK_PR_FENCE_NOOP(acqrel)
CK_PR_FENCE_NOOP(lock)
CK_PR_FENCE_NOOP(unlock)
#else
#error "No memory model has been defined."
#endif /* CK_MD_TSO */
#undef CK_PR_FENCE_EMIT
#undef CK_PR_FENCE_NOOP
#ifndef CK_F_PR_RFO
#define CK_F_PR_RFO
CK_CC_INLINE static void
ck_pr_rfo(const void *m)
{
(void)m;
return;
}
#endif /* CK_F_PR_RFO */
#define CK_PR_STORE_SAFE(DST, VAL, TYPE) \
ck_pr_md_store_##TYPE( \
((void)sizeof(*(DST) = (VAL)), (DST)), \
(VAL))
#define ck_pr_store_ptr(DST, VAL) CK_PR_STORE_SAFE((DST), (VAL), ptr)
#define ck_pr_store_char(DST, VAL) CK_PR_STORE_SAFE((DST), (VAL), char)
#ifndef CK_PR_DISABLE_DOUBLE
#define ck_pr_store_double(DST, VAL) CK_PR_STORE_SAFE((DST), (VAL), double)
#endif
#define ck_pr_store_uint(DST, VAL) CK_PR_STORE_SAFE((DST), (VAL), uint)
#define ck_pr_store_int(DST, VAL) CK_PR_STORE_SAFE((DST), (VAL), int)
#define ck_pr_store_32(DST, VAL) CK_PR_STORE_SAFE((DST), (VAL), 32)
#define ck_pr_store_16(DST, VAL) CK_PR_STORE_SAFE((DST), (VAL), 16)
#define ck_pr_store_8(DST, VAL) CK_PR_STORE_SAFE((DST), (VAL), 8)
#define ck_pr_store_ptr_unsafe(DST, VAL) ck_pr_md_store_ptr((DST), (VAL))
#ifdef CK_F_PR_LOAD_64
#define ck_pr_store_64(DST, VAL) CK_PR_STORE_SAFE((DST), (VAL), 64)
#endif /* CK_F_PR_LOAD_64 */
#define CK_PR_LOAD_PTR_SAFE(SRC) (CK_CC_TYPEOF(*(SRC), (void *)))ck_pr_md_load_ptr((SRC))
#define ck_pr_load_ptr(SRC) CK_PR_LOAD_PTR_SAFE((SRC))
#define CK_PR_LOAD_SAFE(SRC, TYPE) ck_pr_md_load_##TYPE((SRC))
#define ck_pr_load_char(SRC) CK_PR_LOAD_SAFE((SRC), char)
#ifndef CK_PR_DISABLE_DOUBLE
#define ck_pr_load_double(SRC) CK_PR_LOAD_SAFE((SRC), double)
#endif
#define ck_pr_load_uint(SRC) CK_PR_LOAD_SAFE((SRC), uint)
#define ck_pr_load_int(SRC) CK_PR_LOAD_SAFE((SRC), int)
#define ck_pr_load_32(SRC) CK_PR_LOAD_SAFE((SRC), 32)
#define ck_pr_load_16(SRC) CK_PR_LOAD_SAFE((SRC), 16)
#define ck_pr_load_8(SRC) CK_PR_LOAD_SAFE((SRC), 8)
#ifdef CK_F_PR_LOAD_64
#define ck_pr_load_64(SRC) CK_PR_LOAD_SAFE((SRC), 64)
#endif /* CK_F_PR_LOAD_64 */
#define CK_PR_BIN(K, S, M, T, P, C) \
CK_CC_INLINE static void \
ck_pr_##K##_##S(M *target, T value) \
{ \
T previous; \
C punt; \
punt = ck_pr_md_load_##S(target); \
previous = (T)punt; \
while (ck_pr_cas_##S##_value(target, \
(C)previous, \
(C)(previous P value), \
&previous) == false) \
ck_pr_stall(); \
\
return; \
}
#define CK_PR_BIN_S(K, S, T, P) CK_PR_BIN(K, S, T, T, P, T)
#if defined(CK_F_PR_LOAD_CHAR) && defined(CK_F_PR_CAS_CHAR_VALUE)
#ifndef CK_F_PR_ADD_CHAR
#define CK_F_PR_ADD_CHAR
CK_PR_BIN_S(add, char, char, +)
#endif /* CK_F_PR_ADD_CHAR */
#ifndef CK_F_PR_SUB_CHAR
#define CK_F_PR_SUB_CHAR
CK_PR_BIN_S(sub, char, char, -)
#endif /* CK_F_PR_SUB_CHAR */
#ifndef CK_F_PR_AND_CHAR
#define CK_F_PR_AND_CHAR
CK_PR_BIN_S(and, char, char, &)
#endif /* CK_F_PR_AND_CHAR */
#ifndef CK_F_PR_XOR_CHAR
#define CK_F_PR_XOR_CHAR
CK_PR_BIN_S(xor, char, char, ^)
#endif /* CK_F_PR_XOR_CHAR */
#ifndef CK_F_PR_OR_CHAR
#define CK_F_PR_OR_CHAR
CK_PR_BIN_S(or, char, char, |)
#endif /* CK_F_PR_OR_CHAR */
#endif /* CK_F_PR_LOAD_CHAR && CK_F_PR_CAS_CHAR_VALUE */
#if defined(CK_F_PR_LOAD_INT) && defined(CK_F_PR_CAS_INT_VALUE)
#ifndef CK_F_PR_ADD_INT
#define CK_F_PR_ADD_INT
CK_PR_BIN_S(add, int, int, +)
#endif /* CK_F_PR_ADD_INT */
#ifndef CK_F_PR_SUB_INT
#define CK_F_PR_SUB_INT
CK_PR_BIN_S(sub, int, int, -)
#endif /* CK_F_PR_SUB_INT */
#ifndef CK_F_PR_AND_INT
#define CK_F_PR_AND_INT
CK_PR_BIN_S(and, int, int, &)
#endif /* CK_F_PR_AND_INT */
#ifndef CK_F_PR_XOR_INT
#define CK_F_PR_XOR_INT
CK_PR_BIN_S(xor, int, int, ^)
#endif /* CK_F_PR_XOR_INT */
#ifndef CK_F_PR_OR_INT
#define CK_F_PR_OR_INT
CK_PR_BIN_S(or, int, int, |)
#endif /* CK_F_PR_OR_INT */
#endif /* CK_F_PR_LOAD_INT && CK_F_PR_CAS_INT_VALUE */
#if defined(CK_F_PR_LOAD_DOUBLE) && defined(CK_F_PR_CAS_DOUBLE_VALUE) && \
!defined(CK_PR_DISABLE_DOUBLE)
#ifndef CK_F_PR_ADD_DOUBLE
#define CK_F_PR_ADD_DOUBLE
CK_PR_BIN_S(add, double, double, +)
#endif /* CK_F_PR_ADD_DOUBLE */
#ifndef CK_F_PR_SUB_DOUBLE
#define CK_F_PR_SUB_DOUBLE
CK_PR_BIN_S(sub, double, double, -)
#endif /* CK_F_PR_SUB_DOUBLE */
#endif /* CK_F_PR_LOAD_DOUBLE && CK_F_PR_CAS_DOUBLE_VALUE && !CK_PR_DISABLE_DOUBLE */
#if defined(CK_F_PR_LOAD_UINT) && defined(CK_F_PR_CAS_UINT_VALUE)
#ifndef CK_F_PR_ADD_UINT
#define CK_F_PR_ADD_UINT
CK_PR_BIN_S(add, uint, unsigned int, +)
#endif /* CK_F_PR_ADD_UINT */
#ifndef CK_F_PR_SUB_UINT
#define CK_F_PR_SUB_UINT
CK_PR_BIN_S(sub, uint, unsigned int, -)
#endif /* CK_F_PR_SUB_UINT */
#ifndef CK_F_PR_AND_UINT
#define CK_F_PR_AND_UINT
CK_PR_BIN_S(and, uint, unsigned int, &)
#endif /* CK_F_PR_AND_UINT */
#ifndef CK_F_PR_XOR_UINT
#define CK_F_PR_XOR_UINT
CK_PR_BIN_S(xor, uint, unsigned int, ^)
#endif /* CK_F_PR_XOR_UINT */
#ifndef CK_F_PR_OR_UINT
#define CK_F_PR_OR_UINT
CK_PR_BIN_S(or, uint, unsigned int, |)
#endif /* CK_F_PR_OR_UINT */
#endif /* CK_F_PR_LOAD_UINT && CK_F_PR_CAS_UINT_VALUE */
#if defined(CK_F_PR_LOAD_PTR) && defined(CK_F_PR_CAS_PTR_VALUE)
#ifndef CK_F_PR_ADD_PTR
#define CK_F_PR_ADD_PTR
CK_PR_BIN(add, ptr, void, uintptr_t, +, void *)
#endif /* CK_F_PR_ADD_PTR */
#ifndef CK_F_PR_SUB_PTR
#define CK_F_PR_SUB_PTR
CK_PR_BIN(sub, ptr, void, uintptr_t, -, void *)
#endif /* CK_F_PR_SUB_PTR */
#ifndef CK_F_PR_AND_PTR
#define CK_F_PR_AND_PTR
CK_PR_BIN(and, ptr, void, uintptr_t, &, void *)
#endif /* CK_F_PR_AND_PTR */
#ifndef CK_F_PR_XOR_PTR
#define CK_F_PR_XOR_PTR
CK_PR_BIN(xor, ptr, void, uintptr_t, ^, void *)
#endif /* CK_F_PR_XOR_PTR */
#ifndef CK_F_PR_OR_PTR
#define CK_F_PR_OR_PTR
CK_PR_BIN(or, ptr, void, uintptr_t, |, void *)
#endif /* CK_F_PR_OR_PTR */
#endif /* CK_F_PR_LOAD_PTR && CK_F_PR_CAS_PTR_VALUE */
#if defined(CK_F_PR_LOAD_64) && defined(CK_F_PR_CAS_64_VALUE)
#ifndef CK_F_PR_ADD_64
#define CK_F_PR_ADD_64
CK_PR_BIN_S(add, 64, uint64_t, +)
#endif /* CK_F_PR_ADD_64 */
#ifndef CK_F_PR_SUB_64
#define CK_F_PR_SUB_64
CK_PR_BIN_S(sub, 64, uint64_t, -)
#endif /* CK_F_PR_SUB_64 */
#ifndef CK_F_PR_AND_64
#define CK_F_PR_AND_64
CK_PR_BIN_S(and, 64, uint64_t, &)
#endif /* CK_F_PR_AND_64 */
#ifndef CK_F_PR_XOR_64
#define CK_F_PR_XOR_64
CK_PR_BIN_S(xor, 64, uint64_t, ^)
#endif /* CK_F_PR_XOR_64 */
#ifndef CK_F_PR_OR_64
#define CK_F_PR_OR_64
CK_PR_BIN_S(or, 64, uint64_t, |)
#endif /* CK_F_PR_OR_64 */
#endif /* CK_F_PR_LOAD_64 && CK_F_PR_CAS_64_VALUE */
#if defined(CK_F_PR_LOAD_32) && defined(CK_F_PR_CAS_32_VALUE)
#ifndef CK_F_PR_ADD_32
#define CK_F_PR_ADD_32
CK_PR_BIN_S(add, 32, uint32_t, +)
#endif /* CK_F_PR_ADD_32 */
#ifndef CK_F_PR_SUB_32
#define CK_F_PR_SUB_32
CK_PR_BIN_S(sub, 32, uint32_t, -)
#endif /* CK_F_PR_SUB_32 */
#ifndef CK_F_PR_AND_32
#define CK_F_PR_AND_32
CK_PR_BIN_S(and, 32, uint32_t, &)
#endif /* CK_F_PR_AND_32 */
#ifndef CK_F_PR_XOR_32
#define CK_F_PR_XOR_32
CK_PR_BIN_S(xor, 32, uint32_t, ^)
#endif /* CK_F_PR_XOR_32 */
#ifndef CK_F_PR_OR_32
#define CK_F_PR_OR_32
CK_PR_BIN_S(or, 32, uint32_t, |)
#endif /* CK_F_PR_OR_32 */
#endif /* CK_F_PR_LOAD_32 && CK_F_PR_CAS_32_VALUE */
#if defined(CK_F_PR_LOAD_16) && defined(CK_F_PR_CAS_16_VALUE)
#ifndef CK_F_PR_ADD_16
#define CK_F_PR_ADD_16
CK_PR_BIN_S(add, 16, uint16_t, +)
#endif /* CK_F_PR_ADD_16 */
#ifndef CK_F_PR_SUB_16
#define CK_F_PR_SUB_16
CK_PR_BIN_S(sub, 16, uint16_t, -)
#endif /* CK_F_PR_SUB_16 */
#ifndef CK_F_PR_AND_16
#define CK_F_PR_AND_16
CK_PR_BIN_S(and, 16, uint16_t, &)
#endif /* CK_F_PR_AND_16 */
#ifndef CK_F_PR_XOR_16
#define CK_F_PR_XOR_16
CK_PR_BIN_S(xor, 16, uint16_t, ^)
#endif /* CK_F_PR_XOR_16 */
#ifndef CK_F_PR_OR_16
#define CK_F_PR_OR_16
CK_PR_BIN_S(or, 16, uint16_t, |)
#endif /* CK_F_PR_OR_16 */
#endif /* CK_F_PR_LOAD_16 && CK_F_PR_CAS_16_VALUE */
#if defined(CK_F_PR_LOAD_8) && defined(CK_F_PR_CAS_8_VALUE)
#ifndef CK_F_PR_ADD_8
#define CK_F_PR_ADD_8
CK_PR_BIN_S(add, 8, uint8_t, +)
#endif /* CK_F_PR_ADD_8 */
#ifndef CK_F_PR_SUB_8
#define CK_F_PR_SUB_8
CK_PR_BIN_S(sub, 8, uint8_t, -)
#endif /* CK_F_PR_SUB_8 */
#ifndef CK_F_PR_AND_8
#define CK_F_PR_AND_8
CK_PR_BIN_S(and, 8, uint8_t, &)
#endif /* CK_F_PR_AND_8 */
#ifndef CK_F_PR_XOR_8
#define CK_F_PR_XOR_8
CK_PR_BIN_S(xor, 8, uint8_t, ^)
#endif /* CK_F_PR_XOR_8 */
#ifndef CK_F_PR_OR_8
#define CK_F_PR_OR_8
CK_PR_BIN_S(or, 8, uint8_t, |)
#endif /* CK_F_PR_OR_8 */
#endif /* CK_F_PR_LOAD_8 && CK_F_PR_CAS_8_VALUE */
#undef CK_PR_BIN_S
#undef CK_PR_BIN
#define CK_PR_BTX(K, S, M, T, P, C, R) \
CK_CC_INLINE static bool \
ck_pr_##K##_##S(M *target, unsigned int offset) \
{ \
T previous; \
C punt; \
punt = ck_pr_md_load_##S(target); \
previous = (T)punt; \
while (ck_pr_cas_##S##_value(target, (C)previous, \
(C)(previous P (R ((T)1 << offset))), &previous) == false) \
ck_pr_stall(); \
return ((previous >> offset) & 1); \
}
#define CK_PR_BTX_S(K, S, T, P, R) CK_PR_BTX(K, S, T, T, P, T, R)
#if defined(CK_F_PR_LOAD_INT) && defined(CK_F_PR_CAS_INT_VALUE)
#ifndef CK_F_PR_BTC_INT
#define CK_F_PR_BTC_INT
CK_PR_BTX_S(btc, int, int, ^,)
#endif /* CK_F_PR_BTC_INT */
#ifndef CK_F_PR_BTR_INT
#define CK_F_PR_BTR_INT
CK_PR_BTX_S(btr, int, int, &, ~)
#endif /* CK_F_PR_BTR_INT */
#ifndef CK_F_PR_BTS_INT
#define CK_F_PR_BTS_INT
CK_PR_BTX_S(bts, int, int, |,)
#endif /* CK_F_PR_BTS_INT */
#endif /* CK_F_PR_LOAD_INT && CK_F_PR_CAS_INT_VALUE */
#if defined(CK_F_PR_LOAD_UINT) && defined(CK_F_PR_CAS_UINT_VALUE)
#ifndef CK_F_PR_BTC_UINT
#define CK_F_PR_BTC_UINT
CK_PR_BTX_S(btc, uint, unsigned int, ^,)
#endif /* CK_F_PR_BTC_UINT */
#ifndef CK_F_PR_BTR_UINT
#define CK_F_PR_BTR_UINT
CK_PR_BTX_S(btr, uint, unsigned int, &, ~)
#endif /* CK_F_PR_BTR_UINT */
#ifndef CK_F_PR_BTS_UINT
#define CK_F_PR_BTS_UINT
CK_PR_BTX_S(bts, uint, unsigned int, |,)
#endif /* CK_F_PR_BTS_UINT */
#endif /* CK_F_PR_LOAD_UINT && CK_F_PR_CAS_UINT_VALUE */
#if defined(CK_F_PR_LOAD_PTR) && defined(CK_F_PR_CAS_PTR_VALUE)
#ifndef CK_F_PR_BTC_PTR
#define CK_F_PR_BTC_PTR
CK_PR_BTX(btc, ptr, void, uintptr_t, ^, void *,)
#endif /* CK_F_PR_BTC_PTR */
#ifndef CK_F_PR_BTR_PTR
#define CK_F_PR_BTR_PTR
CK_PR_BTX(btr, ptr, void, uintptr_t, &, void *, ~)
#endif /* CK_F_PR_BTR_PTR */
#ifndef CK_F_PR_BTS_PTR
#define CK_F_PR_BTS_PTR
CK_PR_BTX(bts, ptr, void, uintptr_t, |, void *,)
#endif /* CK_F_PR_BTS_PTR */
#endif /* CK_F_PR_LOAD_PTR && CK_F_PR_CAS_PTR_VALUE */
#if defined(CK_F_PR_LOAD_64) && defined(CK_F_PR_CAS_64_VALUE)
#ifndef CK_F_PR_BTC_64
#define CK_F_PR_BTC_64
CK_PR_BTX_S(btc, 64, uint64_t, ^,)
#endif /* CK_F_PR_BTC_64 */
#ifndef CK_F_PR_BTR_64
#define CK_F_PR_BTR_64
CK_PR_BTX_S(btr, 64, uint64_t, &, ~)
#endif /* CK_F_PR_BTR_64 */
#ifndef CK_F_PR_BTS_64
#define CK_F_PR_BTS_64
CK_PR_BTX_S(bts, 64, uint64_t, |,)
#endif /* CK_F_PR_BTS_64 */
#endif /* CK_F_PR_LOAD_64 && CK_F_PR_CAS_64_VALUE */
#if defined(CK_F_PR_LOAD_32) && defined(CK_F_PR_CAS_32_VALUE)
#ifndef CK_F_PR_BTC_32
#define CK_F_PR_BTC_32
CK_PR_BTX_S(btc, 32, uint32_t, ^,)
#endif /* CK_F_PR_BTC_32 */
#ifndef CK_F_PR_BTR_32
#define CK_F_PR_BTR_32
CK_PR_BTX_S(btr, 32, uint32_t, &, ~)
#endif /* CK_F_PR_BTR_32 */
#ifndef CK_F_PR_BTS_32
#define CK_F_PR_BTS_32
CK_PR_BTX_S(bts, 32, uint32_t, |,)
#endif /* CK_F_PR_BTS_32 */
#endif /* CK_F_PR_LOAD_32 && CK_F_PR_CAS_32_VALUE */
#if defined(CK_F_PR_LOAD_16) && defined(CK_F_PR_CAS_16_VALUE)
#ifndef CK_F_PR_BTC_16
#define CK_F_PR_BTC_16
CK_PR_BTX_S(btc, 16, uint16_t, ^,)
#endif /* CK_F_PR_BTC_16 */
#ifndef CK_F_PR_BTR_16
#define CK_F_PR_BTR_16
CK_PR_BTX_S(btr, 16, uint16_t, &, ~)
#endif /* CK_F_PR_BTR_16 */
#ifndef CK_F_PR_BTS_16
#define CK_F_PR_BTS_16
CK_PR_BTX_S(bts, 16, uint16_t, |,)
#endif /* CK_F_PR_BTS_16 */
#endif /* CK_F_PR_LOAD_16 && CK_F_PR_CAS_16_VALUE */
#undef CK_PR_BTX_S
#undef CK_PR_BTX
#define CK_PR_UNARY(K, X, S, M, T) \
CK_CC_INLINE static void \
ck_pr_##K##_##S(M *target) \
{ \
ck_pr_##X##_##S(target, (T)1); \
return; \
}
#define CK_PR_UNARY_Z(K, S, M, T, P, C, Z) \
CK_CC_INLINE static bool \
ck_pr_##K##_##S##_is_zero(M *target) \
{ \
T previous; \
C punt; \
punt = (C)ck_pr_md_load_##S(target); \
previous = (T)punt; \
while (ck_pr_cas_##S##_value(target, \
(C)previous, \
(C)(previous P 1), \
&previous) == false) \
ck_pr_stall(); \
return previous == (T)Z; \
}
#define CK_PR_UNARY_Z_STUB(K, S, M) \
CK_CC_INLINE static void \
ck_pr_##K##_##S##_zero(M *target, bool *zero) \
{ \
*zero = ck_pr_##K##_##S##_is_zero(target); \
return; \
}
#define CK_PR_UNARY_S(K, X, S, M) CK_PR_UNARY(K, X, S, M, M)
#define CK_PR_UNARY_Z_S(K, S, M, P, Z) \
CK_PR_UNARY_Z(K, S, M, M, P, M, Z) \
CK_PR_UNARY_Z_STUB(K, S, M)
#if defined(CK_F_PR_LOAD_CHAR) && defined(CK_F_PR_CAS_CHAR_VALUE)
#ifndef CK_F_PR_INC_CHAR
#define CK_F_PR_INC_CHAR
CK_PR_UNARY_S(inc, add, char, char)
#endif /* CK_F_PR_INC_CHAR */
#ifndef CK_F_PR_INC_CHAR_ZERO
#define CK_F_PR_INC_CHAR_ZERO
CK_PR_UNARY_Z_S(inc, char, char, +, -1)
#else
CK_PR_UNARY_Z_STUB(inc, char, char)
#endif /* CK_F_PR_INC_CHAR_ZERO */
#ifndef CK_F_PR_DEC_CHAR
#define CK_F_PR_DEC_CHAR
CK_PR_UNARY_S(dec, sub, char, char)
#endif /* CK_F_PR_DEC_CHAR */
#ifndef CK_F_PR_DEC_CHAR_ZERO
#define CK_F_PR_DEC_CHAR_ZERO
CK_PR_UNARY_Z_S(dec, char, char, -, 1)
#else
CK_PR_UNARY_Z_STUB(dec, char, char)
#endif /* CK_F_PR_DEC_CHAR_ZERO */
#endif /* CK_F_PR_LOAD_CHAR && CK_F_PR_CAS_CHAR_VALUE */
#if defined(CK_F_PR_LOAD_INT) && defined(CK_F_PR_CAS_INT_VALUE)
#ifndef CK_F_PR_INC_INT
#define CK_F_PR_INC_INT
CK_PR_UNARY_S(inc, add, int, int)
#endif /* CK_F_PR_INC_INT */
#ifndef CK_F_PR_INC_INT_ZERO
#define CK_F_PR_INC_INT_ZERO
CK_PR_UNARY_Z_S(inc, int, int, +, -1)
#else
CK_PR_UNARY_Z_STUB(inc, int, int)
#endif /* CK_F_PR_INC_INT_ZERO */
#ifndef CK_F_PR_DEC_INT
#define CK_F_PR_DEC_INT
CK_PR_UNARY_S(dec, sub, int, int)
#endif /* CK_F_PR_DEC_INT */
#ifndef CK_F_PR_DEC_INT_ZERO
#define CK_F_PR_DEC_INT_ZERO
CK_PR_UNARY_Z_S(dec, int, int, -, 1)
#else
CK_PR_UNARY_Z_STUB(dec, int, int)
#endif /* CK_F_PR_DEC_INT_ZERO */
#endif /* CK_F_PR_LOAD_INT && CK_F_PR_CAS_INT_VALUE */
#if defined(CK_F_PR_LOAD_DOUBLE) && defined(CK_F_PR_CAS_DOUBLE_VALUE) && \
!defined(CK_PR_DISABLE_DOUBLE)
#ifndef CK_F_PR_INC_DOUBLE
#define CK_F_PR_INC_DOUBLE
CK_PR_UNARY_S(inc, add, double, double)
#endif /* CK_F_PR_INC_DOUBLE */
#ifndef CK_F_PR_DEC_DOUBLE
#define CK_F_PR_DEC_DOUBLE
CK_PR_UNARY_S(dec, sub, double, double)
#endif /* CK_F_PR_DEC_DOUBLE */
#endif /* CK_F_PR_LOAD_DOUBLE && CK_F_PR_CAS_DOUBLE_VALUE && !CK_PR_DISABLE_DOUBLE */
#if defined(CK_F_PR_LOAD_UINT) && defined(CK_F_PR_CAS_UINT_VALUE)
#ifndef CK_F_PR_INC_UINT
#define CK_F_PR_INC_UINT
CK_PR_UNARY_S(inc, add, uint, unsigned int)
#endif /* CK_F_PR_INC_UINT */
#ifndef CK_F_PR_INC_UINT_ZERO
#define CK_F_PR_INC_UINT_ZERO
CK_PR_UNARY_Z_S(inc, uint, unsigned int, +, UINT_MAX)
#else
CK_PR_UNARY_Z_STUB(inc, uint, unsigned int)
#endif /* CK_F_PR_INC_UINT_ZERO */
#ifndef CK_F_PR_DEC_UINT
#define CK_F_PR_DEC_UINT
CK_PR_UNARY_S(dec, sub, uint, unsigned int)
#endif /* CK_F_PR_DEC_UINT */
#ifndef CK_F_PR_DEC_UINT_ZERO
#define CK_F_PR_DEC_UINT_ZERO
CK_PR_UNARY_Z_S(dec, uint, unsigned int, -, 1)
#else
CK_PR_UNARY_Z_STUB(dec, uint, unsigned int)
#endif /* CK_F_PR_DEC_UINT_ZERO */
#endif /* CK_F_PR_LOAD_UINT && CK_F_PR_CAS_UINT_VALUE */
#if defined(CK_F_PR_LOAD_PTR) && defined(CK_F_PR_CAS_PTR_VALUE)
#ifndef CK_F_PR_INC_PTR
#define CK_F_PR_INC_PTR
CK_PR_UNARY(inc, add, ptr, void, uintptr_t)
#endif /* CK_F_PR_INC_PTR */
#ifndef CK_F_PR_INC_PTR_ZERO
#define CK_F_PR_INC_PTR_ZERO
CK_PR_UNARY_Z(inc, ptr, void, uintptr_t, +, void *, UINT_MAX)
#else
CK_PR_UNARY_Z_STUB(inc, ptr, void)
#endif /* CK_F_PR_INC_PTR_ZERO */
#ifndef CK_F_PR_DEC_PTR
#define CK_F_PR_DEC_PTR
CK_PR_UNARY(dec, sub, ptr, void, uintptr_t)
#endif /* CK_F_PR_DEC_PTR */
#ifndef CK_F_PR_DEC_PTR_ZERO
#define CK_F_PR_DEC_PTR_ZERO
CK_PR_UNARY_Z(dec, ptr, void, uintptr_t, -, void *, 1)
#else
CK_PR_UNARY_Z_STUB(dec, ptr, void)
#endif /* CK_F_PR_DEC_PTR_ZERO */
#endif /* CK_F_PR_LOAD_PTR && CK_F_PR_CAS_PTR_VALUE */
#if defined(CK_F_PR_LOAD_64) && defined(CK_F_PR_CAS_64_VALUE)
#ifndef CK_F_PR_INC_64
#define CK_F_PR_INC_64
CK_PR_UNARY_S(inc, add, 64, uint64_t)
#endif /* CK_F_PR_INC_64 */
#ifndef CK_F_PR_INC_64_ZERO
#define CK_F_PR_INC_64_ZERO
CK_PR_UNARY_Z_S(inc, 64, uint64_t, +, UINT64_MAX)
#else
CK_PR_UNARY_Z_STUB(inc, 64, uint64_t)
#endif /* CK_F_PR_INC_64_ZERO */
#ifndef CK_F_PR_DEC_64
#define CK_F_PR_DEC_64
CK_PR_UNARY_S(dec, sub, 64, uint64_t)
#endif /* CK_F_PR_DEC_64 */
#ifndef CK_F_PR_DEC_64_ZERO
#define CK_F_PR_DEC_64_ZERO
CK_PR_UNARY_Z_S(dec, 64, uint64_t, -, 1)
#else
CK_PR_UNARY_Z_STUB(dec, 64, uint64_t)
#endif /* CK_F_PR_DEC_64_ZERO */
#endif /* CK_F_PR_LOAD_64 && CK_F_PR_CAS_64_VALUE */
#if defined(CK_F_PR_LOAD_32) && defined(CK_F_PR_CAS_32_VALUE)
#ifndef CK_F_PR_INC_32
#define CK_F_PR_INC_32
CK_PR_UNARY_S(inc, add, 32, uint32_t)
#endif /* CK_F_PR_INC_32 */
#ifndef CK_F_PR_INC_32_ZERO
#define CK_F_PR_INC_32_ZERO
CK_PR_UNARY_Z_S(inc, 32, uint32_t, +, UINT32_MAX)
#else
CK_PR_UNARY_Z_STUB(inc, 32, uint32_t)
#endif /* CK_F_PR_INC_32_ZERO */
#ifndef CK_F_PR_DEC_32
#define CK_F_PR_DEC_32
CK_PR_UNARY_S(dec, sub, 32, uint32_t)
#endif /* CK_F_PR_DEC_32 */
#ifndef CK_F_PR_DEC_32_ZERO
#define CK_F_PR_DEC_32_ZERO
CK_PR_UNARY_Z_S(dec, 32, uint32_t, -, 1)
#else
CK_PR_UNARY_Z_STUB(dec, 32, uint32_t)
#endif /* CK_F_PR_DEC_32_ZERO */
#endif /* CK_F_PR_LOAD_32 && CK_F_PR_CAS_32_VALUE */
#if defined(CK_F_PR_LOAD_16) && defined(CK_F_PR_CAS_16_VALUE)
#ifndef CK_F_PR_INC_16
#define CK_F_PR_INC_16
CK_PR_UNARY_S(inc, add, 16, uint16_t)
#endif /* CK_F_PR_INC_16 */
#ifndef CK_F_PR_INC_16_ZERO
#define CK_F_PR_INC_16_ZERO
CK_PR_UNARY_Z_S(inc, 16, uint16_t, +, UINT16_MAX)
#else
CK_PR_UNARY_Z_STUB(inc, 16, uint16_t)
#endif /* CK_F_PR_INC_16_ZERO */
#ifndef CK_F_PR_DEC_16
#define CK_F_PR_DEC_16
CK_PR_UNARY_S(dec, sub, 16, uint16_t)
#endif /* CK_F_PR_DEC_16 */
#ifndef CK_F_PR_DEC_16_ZERO
#define CK_F_PR_DEC_16_ZERO
CK_PR_UNARY_Z_S(dec, 16, uint16_t, -, 1)
#else
CK_PR_UNARY_Z_STUB(dec, 16, uint16_t)
#endif /* CK_F_PR_DEC_16_ZERO */
#endif /* CK_F_PR_LOAD_16 && CK_F_PR_CAS_16_VALUE */
#if defined(CK_F_PR_LOAD_8) && defined(CK_F_PR_CAS_8_VALUE)
#ifndef CK_F_PR_INC_8
#define CK_F_PR_INC_8
CK_PR_UNARY_S(inc, add, 8, uint8_t)
#endif /* CK_F_PR_INC_8 */
#ifndef CK_F_PR_INC_8_ZERO
#define CK_F_PR_INC_8_ZERO
CK_PR_UNARY_Z_S(inc, 8, uint8_t, +, UINT8_MAX)
#else
CK_PR_UNARY_Z_STUB(inc, 8, uint8_t)
#endif /* CK_F_PR_INC_8_ZERO */
#ifndef CK_F_PR_DEC_8
#define CK_F_PR_DEC_8
CK_PR_UNARY_S(dec, sub, 8, uint8_t)
#endif /* CK_F_PR_DEC_8 */
#ifndef CK_F_PR_DEC_8_ZERO
#define CK_F_PR_DEC_8_ZERO
CK_PR_UNARY_Z_S(dec, 8, uint8_t, -, 1)
#else
CK_PR_UNARY_Z_STUB(dec, 8, uint8_t)
#endif /* CK_F_PR_DEC_8_ZERO */
#endif /* CK_F_PR_LOAD_8 && CK_F_PR_CAS_8_VALUE */
#undef CK_PR_UNARY_Z_S
#undef CK_PR_UNARY_S
#undef CK_PR_UNARY_Z
#undef CK_PR_UNARY
#define CK_PR_N(K, S, M, T, P, C) \
CK_CC_INLINE static void \
ck_pr_##K##_##S(M *target) \
{ \
T previous; \
C punt; \
punt = (C)ck_pr_md_load_##S(target); \
previous = (T)punt; \
while (ck_pr_cas_##S##_value(target, \
(C)previous, \
(C)(P previous), \
&previous) == false) \
ck_pr_stall(); \
\
return; \
}
#define CK_PR_N_Z(S, M, T, C) \
CK_CC_INLINE static void \
ck_pr_neg_##S##_zero(M *target, bool *zero) \
{ \
T previous; \
C punt; \
punt = (C)ck_pr_md_load_##S(target); \
previous = (T)punt; \
while (ck_pr_cas_##S##_value(target, \
(C)previous, \
(C)(-previous), \
&previous) == false) \
ck_pr_stall(); \
\
*zero = previous == 0; \
return; \
}
#define CK_PR_N_S(K, S, M, P) CK_PR_N(K, S, M, M, P, M)
#define CK_PR_N_Z_S(S, M) CK_PR_N_Z(S, M, M, M)
#if defined(CK_F_PR_LOAD_CHAR) && defined(CK_F_PR_CAS_CHAR_VALUE)
#ifndef CK_F_PR_NOT_CHAR
#define CK_F_PR_NOT_CHAR
CK_PR_N_S(not, char, char, ~)
#endif /* CK_F_PR_NOT_CHAR */
#ifndef CK_F_PR_NEG_CHAR
#define CK_F_PR_NEG_CHAR
CK_PR_N_S(neg, char, char, -)
#endif /* CK_F_PR_NEG_CHAR */
#ifndef CK_F_PR_NEG_CHAR_ZERO
#define CK_F_PR_NEG_CHAR_ZERO
CK_PR_N_Z_S(char, char)
#endif /* CK_F_PR_NEG_CHAR_ZERO */
#endif /* CK_F_PR_LOAD_CHAR && CK_F_PR_CAS_CHAR_VALUE */
#if defined(CK_F_PR_LOAD_INT) && defined(CK_F_PR_CAS_INT_VALUE)
#ifndef CK_F_PR_NOT_INT
#define CK_F_PR_NOT_INT
CK_PR_N_S(not, int, int, ~)
#endif /* CK_F_PR_NOT_INT */
#ifndef CK_F_PR_NEG_INT
#define CK_F_PR_NEG_INT
CK_PR_N_S(neg, int, int, -)
#endif /* CK_F_PR_NEG_INT */
#ifndef CK_F_PR_NEG_INT_ZERO
#define CK_F_PR_NEG_INT_ZERO
CK_PR_N_Z_S(int, int)
#endif /* CK_F_PR_NEG_INT_ZERO */
#endif /* CK_F_PR_LOAD_INT && CK_F_PR_CAS_INT_VALUE */
#if defined(CK_F_PR_LOAD_DOUBLE) && defined(CK_F_PR_CAS_DOUBLE_VALUE) && \
!defined(CK_PR_DISABLE_DOUBLE)
#ifndef CK_F_PR_NEG_DOUBLE
#define CK_F_PR_NEG_DOUBLE
CK_PR_N_S(neg, double, double, -)
#endif /* CK_F_PR_NEG_DOUBLE */
#endif /* CK_F_PR_LOAD_DOUBLE && CK_F_PR_CAS_DOUBLE_VALUE && !CK_PR_DISABLE_DOUBLE */
#if defined(CK_F_PR_LOAD_UINT) && defined(CK_F_PR_CAS_UINT_VALUE)
#ifndef CK_F_PR_NOT_UINT
#define CK_F_PR_NOT_UINT
CK_PR_N_S(not, uint, unsigned int, ~)
#endif /* CK_F_PR_NOT_UINT */
#ifndef CK_F_PR_NEG_UINT
#define CK_F_PR_NEG_UINT
CK_PR_N_S(neg, uint, unsigned int, -)
#endif /* CK_F_PR_NEG_UINT */
#ifndef CK_F_PR_NEG_UINT_ZERO
#define CK_F_PR_NEG_UINT_ZERO
CK_PR_N_Z_S(uint, unsigned int)
#endif /* CK_F_PR_NEG_UINT_ZERO */
#endif /* CK_F_PR_LOAD_UINT && CK_F_PR_CAS_UINT_VALUE */
#if defined(CK_F_PR_LOAD_PTR) && defined(CK_F_PR_CAS_PTR_VALUE)
#ifndef CK_F_PR_NOT_PTR
#define CK_F_PR_NOT_PTR
CK_PR_N(not, ptr, void, uintptr_t, ~, void *)
#endif /* CK_F_PR_NOT_PTR */
#ifndef CK_F_PR_NEG_PTR
#define CK_F_PR_NEG_PTR
CK_PR_N(neg, ptr, void, uintptr_t, -, void *)
#endif /* CK_F_PR_NEG_PTR */
#ifndef CK_F_PR_NEG_PTR_ZERO
#define CK_F_PR_NEG_PTR_ZERO
CK_PR_N_Z(ptr, void, uintptr_t, void *)
#endif /* CK_F_PR_NEG_PTR_ZERO */
#endif /* CK_F_PR_LOAD_PTR && CK_F_PR_CAS_PTR_VALUE */
#if defined(CK_F_PR_LOAD_64) && defined(CK_F_PR_CAS_64_VALUE)
#ifndef CK_F_PR_NOT_64
#define CK_F_PR_NOT_64
CK_PR_N_S(not, 64, uint64_t, ~)
#endif /* CK_F_PR_NOT_64 */
#ifndef CK_F_PR_NEG_64
#define CK_F_PR_NEG_64
CK_PR_N_S(neg, 64, uint64_t, -)
#endif /* CK_F_PR_NEG_64 */
#ifndef CK_F_PR_NEG_64_ZERO
#define CK_F_PR_NEG_64_ZERO
CK_PR_N_Z_S(64, uint64_t)
#endif /* CK_F_PR_NEG_64_ZERO */
#endif /* CK_F_PR_LOAD_64 && CK_F_PR_CAS_64_VALUE */
#if defined(CK_F_PR_LOAD_32) && defined(CK_F_PR_CAS_32_VALUE)
#ifndef CK_F_PR_NOT_32
#define CK_F_PR_NOT_32
CK_PR_N_S(not, 32, uint32_t, ~)
#endif /* CK_F_PR_NOT_32 */
#ifndef CK_F_PR_NEG_32
#define CK_F_PR_NEG_32
CK_PR_N_S(neg, 32, uint32_t, -)
#endif /* CK_F_PR_NEG_32 */
#ifndef CK_F_PR_NEG_32_ZERO
#define CK_F_PR_NEG_32_ZERO
CK_PR_N_Z_S(32, uint32_t)
#endif /* CK_F_PR_NEG_32_ZERO */
#endif /* CK_F_PR_LOAD_32 && CK_F_PR_CAS_32_VALUE */
#if defined(CK_F_PR_LOAD_16) && defined(CK_F_PR_CAS_16_VALUE)
#ifndef CK_F_PR_NOT_16
#define CK_F_PR_NOT_16
CK_PR_N_S(not, 16, uint16_t, ~)
#endif /* CK_F_PR_NOT_16 */
#ifndef CK_F_PR_NEG_16
#define CK_F_PR_NEG_16
CK_PR_N_S(neg, 16, uint16_t, -)
#endif /* CK_F_PR_NEG_16 */
#ifndef CK_F_PR_NEG_16_ZERO
#define CK_F_PR_NEG_16_ZERO
CK_PR_N_Z_S(16, uint16_t)
#endif /* CK_F_PR_NEG_16_ZERO */
#endif /* CK_F_PR_LOAD_16 && CK_F_PR_CAS_16_VALUE */
#if defined(CK_F_PR_LOAD_8) && defined(CK_F_PR_CAS_8_VALUE)
#ifndef CK_F_PR_NOT_8
#define CK_F_PR_NOT_8
CK_PR_N_S(not, 8, uint8_t, ~)
#endif /* CK_F_PR_NOT_8 */
#ifndef CK_F_PR_NEG_8
#define CK_F_PR_NEG_8
CK_PR_N_S(neg, 8, uint8_t, -)
#endif /* CK_F_PR_NEG_8 */
#ifndef CK_F_PR_NEG_8_ZERO
#define CK_F_PR_NEG_8_ZERO
CK_PR_N_Z_S(8, uint8_t)
#endif /* CK_F_PR_NEG_8_ZERO */
#endif /* CK_F_PR_LOAD_8 && CK_F_PR_CAS_8_VALUE */
#undef CK_PR_N_Z_S
#undef CK_PR_N_S
#undef CK_PR_N_Z
#undef CK_PR_N
#define CK_PR_FAA(S, M, T, C) \
CK_CC_INLINE static C \
ck_pr_faa_##S(M *target, T delta) \
{ \
T previous; \
C punt; \
punt = (C)ck_pr_md_load_##S(target); \
previous = (T)punt; \
while (ck_pr_cas_##S##_value(target, \
(C)previous, \
(C)(previous + delta), \
&previous) == false) \
ck_pr_stall(); \
\
return ((C)previous); \
}
#define CK_PR_FAS(S, M, C) \
CK_CC_INLINE static C \
ck_pr_fas_##S(M *target, C update) \
{ \
C previous; \
previous = ck_pr_md_load_##S(target); \
while (ck_pr_cas_##S##_value(target, \
previous, \
update, \
&previous) == false) \
ck_pr_stall(); \
\
return (previous); \
}
#define CK_PR_FAA_S(S, M) CK_PR_FAA(S, M, M, M)
#define CK_PR_FAS_S(S, M) CK_PR_FAS(S, M, M)
#if defined(CK_F_PR_LOAD_CHAR) && defined(CK_F_PR_CAS_CHAR_VALUE)
#ifndef CK_F_PR_FAA_CHAR
#define CK_F_PR_FAA_CHAR
CK_PR_FAA_S(char, char)
#endif /* CK_F_PR_FAA_CHAR */
#ifndef CK_F_PR_FAS_CHAR
#define CK_F_PR_FAS_CHAR
CK_PR_FAS_S(char, char)
#endif /* CK_F_PR_FAS_CHAR */
#endif /* CK_F_PR_LOAD_CHAR && CK_F_PR_CAS_CHAR_VALUE */
#if defined(CK_F_PR_LOAD_INT) && defined(CK_F_PR_CAS_INT_VALUE)
#ifndef CK_F_PR_FAA_INT
#define CK_F_PR_FAA_INT
CK_PR_FAA_S(int, int)
#endif /* CK_F_PR_FAA_INT */
#ifndef CK_F_PR_FAS_INT
#define CK_F_PR_FAS_INT
CK_PR_FAS_S(int, int)
#endif /* CK_F_PR_FAS_INT */
#endif /* CK_F_PR_LOAD_INT && CK_F_PR_CAS_INT_VALUE */
#if defined(CK_F_PR_LOAD_DOUBLE) && defined(CK_F_PR_CAS_DOUBLE_VALUE) && \
!defined(CK_PR_DISABLE_DOUBLE)
#ifndef CK_F_PR_FAA_DOUBLE
#define CK_F_PR_FAA_DOUBLE
CK_PR_FAA_S(double, double)
#endif /* CK_F_PR_FAA_DOUBLE */
#ifndef CK_F_PR_FAS_DOUBLE
#define CK_F_PR_FAS_DOUBLE
CK_PR_FAS_S(double, double)
#endif /* CK_F_PR_FAS_DOUBLE */
#endif /* CK_F_PR_LOAD_DOUBLE && CK_F_PR_CAS_DOUBLE_VALUE && !CK_PR_DISABLE_DOUBLE */
#if defined(CK_F_PR_LOAD_UINT) && defined(CK_F_PR_CAS_UINT_VALUE)
#ifndef CK_F_PR_FAA_UINT
#define CK_F_PR_FAA_UINT
CK_PR_FAA_S(uint, unsigned int)
#endif /* CK_F_PR_FAA_UINT */
#ifndef CK_F_PR_FAS_UINT
#define CK_F_PR_FAS_UINT
CK_PR_FAS_S(uint, unsigned int)
#endif /* CK_F_PR_FAS_UINT */
#endif /* CK_F_PR_LOAD_UINT && CK_F_PR_CAS_UINT_VALUE */
#if defined(CK_F_PR_LOAD_PTR) && defined(CK_F_PR_CAS_PTR_VALUE)
#ifndef CK_F_PR_FAA_PTR
#define CK_F_PR_FAA_PTR
CK_PR_FAA(ptr, void, uintptr_t, void *)
#endif /* CK_F_PR_FAA_PTR */
#ifndef CK_F_PR_FAS_PTR
#define CK_F_PR_FAS_PTR
CK_PR_FAS(ptr, void, void *)
#endif /* CK_F_PR_FAS_PTR */
#endif /* CK_F_PR_LOAD_PTR && CK_F_PR_CAS_PTR_VALUE */
#if defined(CK_F_PR_LOAD_64) && defined(CK_F_PR_CAS_64_VALUE)
#ifndef CK_F_PR_FAA_64
#define CK_F_PR_FAA_64
CK_PR_FAA_S(64, uint64_t)
#endif /* CK_F_PR_FAA_64 */
#ifndef CK_F_PR_FAS_64
#define CK_F_PR_FAS_64
CK_PR_FAS_S(64, uint64_t)
#endif /* CK_F_PR_FAS_64 */
#endif /* CK_F_PR_LOAD_64 && CK_F_PR_CAS_64_VALUE */
#if defined(CK_F_PR_LOAD_32) && defined(CK_F_PR_CAS_32_VALUE)
#ifndef CK_F_PR_FAA_32
#define CK_F_PR_FAA_32
CK_PR_FAA_S(32, uint32_t)
#endif /* CK_F_PR_FAA_32 */
#ifndef CK_F_PR_FAS_32
#define CK_F_PR_FAS_32
CK_PR_FAS_S(32, uint32_t)
#endif /* CK_F_PR_FAS_32 */
#endif /* CK_F_PR_LOAD_32 && CK_F_PR_CAS_32_VALUE */
#if defined(CK_F_PR_LOAD_16) && defined(CK_F_PR_CAS_16_VALUE)
#ifndef CK_F_PR_FAA_16
#define CK_F_PR_FAA_16
CK_PR_FAA_S(16, uint16_t)
#endif /* CK_F_PR_FAA_16 */
#ifndef CK_F_PR_FAS_16
#define CK_F_PR_FAS_16
CK_PR_FAS_S(16, uint16_t)
#endif /* CK_F_PR_FAS_16 */
#endif /* CK_F_PR_LOAD_16 && CK_F_PR_CAS_16_VALUE */
#if defined(CK_F_PR_LOAD_8) && defined(CK_F_PR_CAS_8_VALUE)
#ifndef CK_F_PR_FAA_8
#define CK_F_PR_FAA_8
CK_PR_FAA_S(8, uint8_t)
#endif /* CK_F_PR_FAA_8 */
#ifndef CK_F_PR_FAS_8
#define CK_F_PR_FAS_8
CK_PR_FAS_S(8, uint8_t)
#endif /* CK_F_PR_FAS_8 */
#endif /* CK_F_PR_LOAD_8 && CK_F_PR_CAS_8_VALUE */
#undef CK_PR_FAA_S
#undef CK_PR_FAS_S
#undef CK_PR_FAA
#undef CK_PR_FAS
#endif /* CK_PR_H */
|