123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555 |
- /* Test __atomic routines for existence and proper execution on 1 byte
- values with each valid memory model. */
- /* { dg-do run } */
- /* Test the execution of the __atomic_*OP builtin routines for a char. */
- extern void abort(void);
- char v, count, res;
- const char init = ~0;
- /* The fetch_op routines return the original value before the operation. */
- void
- test_fetch_add ()
- {
- v = 0;
- count = 1;
- if (__atomic_fetch_add (&v, count, __ATOMIC_RELAXED) != 0)
- abort ();
- if (__atomic_fetch_add (&v, 1, __ATOMIC_CONSUME) != 1)
- abort ();
- if (__atomic_fetch_add (&v, count, __ATOMIC_ACQUIRE) != 2)
- abort ();
- if (__atomic_fetch_add (&v, 1, __ATOMIC_RELEASE) != 3)
- abort ();
- if (__atomic_fetch_add (&v, count, __ATOMIC_ACQ_REL) != 4)
- abort ();
- if (__atomic_fetch_add (&v, 1, __ATOMIC_SEQ_CST) != 5)
- abort ();
- }
- void
- test_fetch_sub()
- {
- v = res = 20;
- count = 0;
- if (__atomic_fetch_sub (&v, count + 1, __ATOMIC_RELAXED) != res--)
- abort ();
- if (__atomic_fetch_sub (&v, 1, __ATOMIC_CONSUME) != res--)
- abort ();
- if (__atomic_fetch_sub (&v, count + 1, __ATOMIC_ACQUIRE) != res--)
- abort ();
- if (__atomic_fetch_sub (&v, 1, __ATOMIC_RELEASE) != res--)
- abort ();
- if (__atomic_fetch_sub (&v, count + 1, __ATOMIC_ACQ_REL) != res--)
- abort ();
- if (__atomic_fetch_sub (&v, 1, __ATOMIC_SEQ_CST) != res--)
- abort ();
- }
- void
- test_fetch_and ()
- {
- v = init;
- if (__atomic_fetch_and (&v, 0, __ATOMIC_RELAXED) != init)
- abort ();
- if (__atomic_fetch_and (&v, init, __ATOMIC_CONSUME) != 0)
- abort ();
- if (__atomic_fetch_and (&v, 0, __ATOMIC_ACQUIRE) != 0)
- abort ();
- v = ~v;
- if (__atomic_fetch_and (&v, init, __ATOMIC_RELEASE) != init)
- abort ();
- if (__atomic_fetch_and (&v, 0, __ATOMIC_ACQ_REL) != init)
- abort ();
- if (__atomic_fetch_and (&v, 0, __ATOMIC_SEQ_CST) != 0)
- abort ();
- }
- void
- test_fetch_nand ()
- {
- v = init;
- if (__atomic_fetch_nand (&v, 0, __ATOMIC_RELAXED) != init)
- abort ();
- if (__atomic_fetch_nand (&v, init, __ATOMIC_CONSUME) != init)
- abort ();
- if (__atomic_fetch_nand (&v, 0, __ATOMIC_ACQUIRE) != 0 )
- abort ();
- if (__atomic_fetch_nand (&v, init, __ATOMIC_RELEASE) != init)
- abort ();
- if (__atomic_fetch_nand (&v, init, __ATOMIC_ACQ_REL) != 0)
- abort ();
- if (__atomic_fetch_nand (&v, 0, __ATOMIC_SEQ_CST) != init)
- abort ();
- }
- void
- test_fetch_xor ()
- {
- v = init;
- count = 0;
- if (__atomic_fetch_xor (&v, count, __ATOMIC_RELAXED) != init)
- abort ();
- if (__atomic_fetch_xor (&v, ~count, __ATOMIC_CONSUME) != init)
- abort ();
- if (__atomic_fetch_xor (&v, 0, __ATOMIC_ACQUIRE) != 0)
- abort ();
- if (__atomic_fetch_xor (&v, ~count, __ATOMIC_RELEASE) != 0)
- abort ();
- if (__atomic_fetch_xor (&v, 0, __ATOMIC_ACQ_REL) != init)
- abort ();
- if (__atomic_fetch_xor (&v, ~count, __ATOMIC_SEQ_CST) != init)
- abort ();
- }
- void
- test_fetch_or ()
- {
- v = 0;
- count = 1;
- if (__atomic_fetch_or (&v, count, __ATOMIC_RELAXED) != 0)
- abort ();
- count *= 2;
- if (__atomic_fetch_or (&v, 2, __ATOMIC_CONSUME) != 1)
- abort ();
- count *= 2;
- if (__atomic_fetch_or (&v, count, __ATOMIC_ACQUIRE) != 3)
- abort ();
- count *= 2;
- if (__atomic_fetch_or (&v, 8, __ATOMIC_RELEASE) != 7)
- abort ();
- count *= 2;
- if (__atomic_fetch_or (&v, count, __ATOMIC_ACQ_REL) != 15)
- abort ();
- count *= 2;
- if (__atomic_fetch_or (&v, count, __ATOMIC_SEQ_CST) != 31)
- abort ();
- }
- /* The OP_fetch routines return the new value after the operation. */
- void
- test_add_fetch ()
- {
- v = 0;
- count = 1;
- if (__atomic_add_fetch (&v, count, __ATOMIC_RELAXED) != 1)
- abort ();
- if (__atomic_add_fetch (&v, 1, __ATOMIC_CONSUME) != 2)
- abort ();
- if (__atomic_add_fetch (&v, count, __ATOMIC_ACQUIRE) != 3)
- abort ();
- if (__atomic_add_fetch (&v, 1, __ATOMIC_RELEASE) != 4)
- abort ();
- if (__atomic_add_fetch (&v, count, __ATOMIC_ACQ_REL) != 5)
- abort ();
- if (__atomic_add_fetch (&v, count, __ATOMIC_SEQ_CST) != 6)
- abort ();
- }
- void
- test_sub_fetch ()
- {
- v = res = 20;
- count = 0;
- if (__atomic_sub_fetch (&v, count + 1, __ATOMIC_RELAXED) != --res)
- abort ();
- if (__atomic_sub_fetch (&v, 1, __ATOMIC_CONSUME) != --res)
- abort ();
-
- if (__atomic_sub_fetch (&v, count + 1, __ATOMIC_ACQUIRE) != --res)
- abort ();
-
- if (__atomic_sub_fetch (&v, 1, __ATOMIC_RELEASE) != --res)
- abort ();
-
- if (__atomic_sub_fetch (&v, count + 1, __ATOMIC_ACQ_REL) != --res)
- abort ();
-
- if (__atomic_sub_fetch (&v, count + 1, __ATOMIC_SEQ_CST) != --res)
- abort ();
- }
- void
- test_and_fetch ()
- {
- v = init;
- if (__atomic_and_fetch (&v, 0, __ATOMIC_RELAXED) != 0)
- abort ();
- v = init;
- if (__atomic_and_fetch (&v, init, __ATOMIC_CONSUME) != init)
- abort ();
- if (__atomic_and_fetch (&v, 0, __ATOMIC_ACQUIRE) != 0)
- abort ();
- v = ~v;
- if (__atomic_and_fetch (&v, init, __ATOMIC_RELEASE) != init)
- abort ();
- if (__atomic_and_fetch (&v, 0, __ATOMIC_ACQ_REL) != 0)
- abort ();
- v = ~v;
- if (__atomic_and_fetch (&v, 0, __ATOMIC_SEQ_CST) != 0)
- abort ();
- }
- void
- test_nand_fetch ()
- {
- v = init;
- if (__atomic_nand_fetch (&v, 0, __ATOMIC_RELAXED) != init)
- abort ();
-
- if (__atomic_nand_fetch (&v, init, __ATOMIC_CONSUME) != 0)
- abort ();
-
- if (__atomic_nand_fetch (&v, 0, __ATOMIC_ACQUIRE) != init)
- abort ();
-
- if (__atomic_nand_fetch (&v, init, __ATOMIC_RELEASE) != 0)
- abort ();
-
- if (__atomic_nand_fetch (&v, init, __ATOMIC_ACQ_REL) != init)
- abort ();
-
- if (__atomic_nand_fetch (&v, 0, __ATOMIC_SEQ_CST) != init)
- abort ();
- }
- void
- test_xor_fetch ()
- {
- v = init;
- count = 0;
- if (__atomic_xor_fetch (&v, count, __ATOMIC_RELAXED) != init)
- abort ();
- if (__atomic_xor_fetch (&v, ~count, __ATOMIC_CONSUME) != 0)
- abort ();
- if (__atomic_xor_fetch (&v, 0, __ATOMIC_ACQUIRE) != 0)
- abort ();
- if (__atomic_xor_fetch (&v, ~count, __ATOMIC_RELEASE) != init)
- abort ();
- if (__atomic_xor_fetch (&v, 0, __ATOMIC_ACQ_REL) != init)
- abort ();
- if (__atomic_xor_fetch (&v, ~count, __ATOMIC_SEQ_CST) != 0)
- abort ();
- }
- void
- test_or_fetch ()
- {
- v = 0;
- count = 1;
- if (__atomic_or_fetch (&v, count, __ATOMIC_RELAXED) != 1)
- abort ();
- count *= 2;
- if (__atomic_or_fetch (&v, 2, __ATOMIC_CONSUME) != 3)
- abort ();
- count *= 2;
- if (__atomic_or_fetch (&v, count, __ATOMIC_ACQUIRE) != 7)
- abort ();
- count *= 2;
- if (__atomic_or_fetch (&v, 8, __ATOMIC_RELEASE) != 15)
- abort ();
- count *= 2;
- if (__atomic_or_fetch (&v, count, __ATOMIC_ACQ_REL) != 31)
- abort ();
- count *= 2;
- if (__atomic_or_fetch (&v, count, __ATOMIC_SEQ_CST) != 63)
- abort ();
- }
- /* Test the OP routines with a result which isn't used. Use both variations
- within each function. */
- void
- test_add ()
- {
- v = 0;
- count = 1;
- __atomic_add_fetch (&v, count, __ATOMIC_RELAXED);
- if (v != 1)
- abort ();
- __atomic_fetch_add (&v, count, __ATOMIC_CONSUME);
- if (v != 2)
- abort ();
- __atomic_add_fetch (&v, 1 , __ATOMIC_ACQUIRE);
- if (v != 3)
- abort ();
- __atomic_fetch_add (&v, 1, __ATOMIC_RELEASE);
- if (v != 4)
- abort ();
- __atomic_add_fetch (&v, count, __ATOMIC_ACQ_REL);
- if (v != 5)
- abort ();
- __atomic_fetch_add (&v, count, __ATOMIC_SEQ_CST);
- if (v != 6)
- abort ();
- }
- void
- test_sub()
- {
- v = res = 20;
- count = 0;
- __atomic_sub_fetch (&v, count + 1, __ATOMIC_RELAXED);
- if (v != --res)
- abort ();
- __atomic_fetch_sub (&v, count + 1, __ATOMIC_CONSUME);
- if (v != --res)
- abort ();
-
- __atomic_sub_fetch (&v, 1, __ATOMIC_ACQUIRE);
- if (v != --res)
- abort ();
-
- __atomic_fetch_sub (&v, 1, __ATOMIC_RELEASE);
- if (v != --res)
- abort ();
-
- __atomic_sub_fetch (&v, count + 1, __ATOMIC_ACQ_REL);
- if (v != --res)
- abort ();
-
- __atomic_fetch_sub (&v, count + 1, __ATOMIC_SEQ_CST);
- if (v != --res)
- abort ();
- }
- void
- test_and ()
- {
- v = init;
- __atomic_and_fetch (&v, 0, __ATOMIC_RELAXED);
- if (v != 0)
- abort ();
- v = init;
- __atomic_fetch_and (&v, init, __ATOMIC_CONSUME);
- if (v != init)
- abort ();
- __atomic_and_fetch (&v, 0, __ATOMIC_ACQUIRE);
- if (v != 0)
- abort ();
- v = ~v;
- __atomic_fetch_and (&v, init, __ATOMIC_RELEASE);
- if (v != init)
- abort ();
- __atomic_and_fetch (&v, 0, __ATOMIC_ACQ_REL);
- if (v != 0)
- abort ();
- v = ~v;
- __atomic_fetch_and (&v, 0, __ATOMIC_SEQ_CST);
- if (v != 0)
- abort ();
- }
- void
- test_nand ()
- {
- v = init;
- __atomic_fetch_nand (&v, 0, __ATOMIC_RELAXED);
- if (v != init)
- abort ();
- __atomic_fetch_nand (&v, init, __ATOMIC_CONSUME);
- if (v != 0)
- abort ();
- __atomic_nand_fetch (&v, 0, __ATOMIC_ACQUIRE);
- if (v != init)
- abort ();
- __atomic_nand_fetch (&v, init, __ATOMIC_RELEASE);
- if (v != 0)
- abort ();
- __atomic_fetch_nand (&v, init, __ATOMIC_ACQ_REL);
- if (v != init)
- abort ();
- __atomic_nand_fetch (&v, 0, __ATOMIC_SEQ_CST);
- if (v != init)
- abort ();
- }
- void
- test_xor ()
- {
- v = init;
- count = 0;
- __atomic_xor_fetch (&v, count, __ATOMIC_RELAXED);
- if (v != init)
- abort ();
- __atomic_fetch_xor (&v, ~count, __ATOMIC_CONSUME);
- if (v != 0)
- abort ();
- __atomic_xor_fetch (&v, 0, __ATOMIC_ACQUIRE);
- if (v != 0)
- abort ();
- __atomic_fetch_xor (&v, ~count, __ATOMIC_RELEASE);
- if (v != init)
- abort ();
- __atomic_fetch_xor (&v, 0, __ATOMIC_ACQ_REL);
- if (v != init)
- abort ();
- __atomic_xor_fetch (&v, ~count, __ATOMIC_SEQ_CST);
- if (v != 0)
- abort ();
- }
- void
- test_or ()
- {
- v = 0;
- count = 1;
- __atomic_or_fetch (&v, count, __ATOMIC_RELAXED);
- if (v != 1)
- abort ();
- count *= 2;
- __atomic_fetch_or (&v, count, __ATOMIC_CONSUME);
- if (v != 3)
- abort ();
- count *= 2;
- __atomic_or_fetch (&v, 4, __ATOMIC_ACQUIRE);
- if (v != 7)
- abort ();
- count *= 2;
- __atomic_fetch_or (&v, 8, __ATOMIC_RELEASE);
- if (v != 15)
- abort ();
- count *= 2;
- __atomic_or_fetch (&v, count, __ATOMIC_ACQ_REL);
- if (v != 31)
- abort ();
- count *= 2;
- __atomic_fetch_or (&v, count, __ATOMIC_SEQ_CST);
- if (v != 63)
- abort ();
- }
- int
- main ()
- {
- test_fetch_add ();
- test_fetch_sub ();
- test_fetch_and ();
- test_fetch_nand ();
- test_fetch_xor ();
- test_fetch_or ();
- test_add_fetch ();
- test_sub_fetch ();
- test_and_fetch ();
- test_nand_fetch ();
- test_xor_fetch ();
- test_or_fetch ();
- test_add ();
- test_sub ();
- test_and ();
- test_nand ();
- test_xor ();
- test_or ();
- return 0;
- }
|