Commit Graph

13 Commits

Author SHA1 Message Date
Tom de Vries 11fb784ac5 [libatomic] Fix return value in libat_test_and_set
On nvptx (using a Quadro K2000 with driver 470.103.01) I ran into this:
...
FAIL: gcc.dg/atomic/stdatomic-flag-2.c -O1 execution test
...
which mimimized to:
...
  #include <stdatomic.h>
  atomic_flag a = ATOMIC_FLAG_INIT;
  int main () {
    if ((atomic_flag_test_and_set) (&a))
      __builtin_abort ();
    return 0;
  }
...

The atomic_flag_test_and_set is implemented using __atomic_test_and_set_1,
which corresponds to the "word-sized compare-and-swap loop" version of
libat_test_and_set in libatomic/tas_n.c.

The semantics of a test-and-set is that the return value is "true if and only
if the previous contents were 'set'".

But the code uses:
...
  return woldval != 0;
...
which means it doesn't look only at the byte that was either set or not set,
but at the entire word.

Fix this by using instead:
...
  return (woldval & ((UTYPE) ~(UTYPE) 0 << shift)) != 0;
...

Tested on nvptx.

libatomic/ChangeLog:

2022-03-24  Tom de Vries  <tdevries@suse.de>

	PR target/105011
	* tas_n.c (libat_test_and_set): Fix return value.
2022-03-24 13:30:57 +01:00
Jakub Jelinek 7adcbafe45 Update copyright years. 2022-01-03 10:42:10 +01:00
Jakub Jelinek 99dee82307 Update copyright years. 2021-01-04 10:26:59 +01:00
Jakub Jelinek 8d9254fc8a Update copyright years.
From-SVN: r279813
2020-01-01 12:51:42 +01:00
Jakub Jelinek a554497024 Update copyright years.
From-SVN: r267494
2019-01-01 13:31:55 +01:00
Jakub Jelinek 85ec4feb11 Update copyright years.
From-SVN: r256169
2018-01-03 11:03:58 +01:00
Jakub Jelinek cbe34bb5ed Update copyright years.
From-SVN: r243994
2017-01-01 13:07:43 +01:00
Jakub Jelinek 818ab71a41 Update copyright years.
From-SVN: r232055
2016-01-04 15:30:50 +01:00
Jakub Jelinek 5624e564d2 Update copyright years.
From-SVN: r219188
2015-01-05 13:33:28 +01:00
Richard Sandiford 3e6a2e378c Update copyright years in libatomic/
From-SVN: r206291
2014-01-02 22:24:30 +00:00
Richard Sandiford 69b2c4233b Update copyright years in libatomic.
From-SVN: r195164
2013-01-14 18:16:23 +00:00
John David Anglin 917344232c re PR other/53231 (libatomic/tas_n.c💯10: error: 'ret' undeclared (first use in this function))
PR other/53231
	* tas_n.c (libat_test_and_set): Correct return.  Remove unused variable.

From-SVN: r187783
2012-05-22 23:54:32 +00:00
Richard Henderson 483104922a Add libatomic as a target library.
From-SVN: r187018
2012-05-01 08:48:28 -07:00