X-Recipient: archive-cygwin@delorie.com
X-Original-To: cygwin@cygwin.com
Delivered-To: cygwin@cygwin.com
X-Authority-Analysis: v=2.3 cv=ZsqT1OzG c=1 sm=1 tr=0
 a=kiZT5GMN3KAWqtYcXc+/4Q==:117 a=kiZT5GMN3KAWqtYcXc+/4Q==:17
 a=jpOVt7BSZ2e4Z31A5e1TngXxSK0=:19 a=IkcTkHD0fZMA:10 a=aPJAEhiRf5J9oji7sMMA:9
 a=7Zwj6sZBwVKJAoWSPKxL6X1jA+E=:19 a=QEXdDO2ut3YA:10
Subject: Re: gcc and 128-bit compare/exchange
References: <ab69ca04-06a2-eeb9-4771-e37432b59a77@cs.umass.edu>
 <f27b324f-049c-7830-68cd-14813aab6eed@cs.umass.edu>
 <66f51c13-4c87-3bd6-3b8e-01901155ef2a@SystematicSw.ab.ca>
 <de26ff04-596e-1dad-f2ae-4b91ba53f5c1@cs.umass.edu>
To: "cygwin@cygwin.com" <cygwin@cygwin.com>
From: Brian Inglis <Brian.Inglis@SystematicSw.ab.ca>
Autocrypt: addr=Brian.Inglis@SystematicSw.ab.ca; prefer-encrypt=mutual;
 keydata=
 mQENBFg15Q0BCADc1LTYJN/oVKOJoXpIo+5yy+sBv535qYNRh5CFqp3pPZwIy6oILNKprWph
 8J+sXMqYd5H0G1jMDlXendiQbn9SiORuqI7xkV8vzguoFEMhNTxnO1pOQjqRnEnG/W7/5Yy+
 DkcCv+Y4O3NX3wol8yP+FaEx4EEEifaO5ZhC1U/ilvHvxE0wjNhRG6AqlvqX6J09bxkJC8Xd
 00MZWotDHtiq/wnd8YqyDmf0aJceGxSetHnqn/Cs3WiylEEUy2x/FqKbsBxUJHGQeeRTFAW1
 ii08djCemxdE+romE/M9J9CVisSZImbXMSilX6Z2Qtz0lYPkY0EqbiKo8o9zlkIPhaqJABEB
 AAG0REJyaWFuIEluZ2xpcyAoU3lzdGVtYXRpYyBTb2Z0d2FyZSkgPEJyaWFuLkluZ2xpc0BT
 eXN0ZW1hdGljU1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wMwyqb/2kFiKK7Q64B
 NKl8Y2kRXltaiXfqyvG2U/NiE4GOPA3yZgXs4Mzd1pzV/nkEIzGkneaeE5WGEWj/8dCnn6a3
 zIuq0L59QInxKsTdt10OQiUoRKl8Nx0vDCOzMy0wlJc349gJbQBCAZcumtBBBqAzCAmJ3J7T
 7ew8hznAEmOwr+LkSOdXFzEjdfTaryhN1AsRLYVUNloEWNA=
Organization: Systematic Software
Message-ID: <0a2c77b2-7ff2-8118-8631-29d186184ad9@SystematicSw.ab.ca>
Date: Tue, 10 Mar 2020 23:31:33 -0600
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101
 Thunderbird/68.5.0
MIME-Version: 1.0
In-Reply-To: <de26ff04-596e-1dad-f2ae-4b91ba53f5c1@cs.umass.edu>
Content-Language: en-CA
X-CMAE-Envelope: MS4wfOWuVLsnhFOPH/K3AnheeQoltHFmp4sLixDVpaJ40tK4g1dQjsEUAQtpeLigqEmQXkYOO9WDULxjUaejDZL/HLHdbz3pdGzYlHPfK+OI02DvdqFWQYQ3
 aUmfBB+Ax2VEaFnYfZDh7YRCVhHguumhI/D3Mi0EAzfaB8UKttcBlfih7qcydv5tFffjYMQVrqScgA==
X-Spam-Status: No, score=-0.1 required=5.0 tests=BAYES_00, GARBLED_BODY,
 RCVD_IN_DNSWL_LOW, SPF_HELO_NONE,
 SPF_NONE autolearn=no autolearn_force=no version=3.4.2
X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on
 server2.sourceware.org
X-BeenThere: cygwin@cygwin.com
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Cygwin mailing list <cygwin.cygwin.com>
List-Unsubscribe: <http://cygwin.com/mailman/options/cygwin>,
 <mailto:cygwin-request@cygwin.com?subject=unsubscribe>
List-Archive: <http://cygwin.com/pipermail/cygwin/>
List-Post: <mailto:cygwin@cygwin.com>
List-Help: <mailto:cygwin-request@cygwin.com?subject=help>
List-Subscribe: <http://cygwin.com/mailman/listinfo/cygwin>,
 <mailto:cygwin-request@cygwin.com?subject=subscribe>
Reply-To: "cygwin@cygwin.com" <cygwin@cygwin.com>
Content-Type: text/plain; charset="utf-8"
Errors-To: cygwin-bounces@cygwin.com
Sender: "Cygwin" <cygwin-bounces@cygwin.com>
Content-Transfer-Encoding: 8bit
X-MIME-Autoconverted: from base64 to 8bit by delorie.com id 02B5W2d4023551

On 2020-03-10 15:13, Eliot Moss wrote:
> On 3/10/2020 4:35 PM, Brian Inglis wrote:
>> On 2020-03-08 20:59, Eliot Moss wrote:
>>> On 3/8/2020 10:29 PM, Eliot Moss wrote:
>>>> This is probably to the gcc maintainer ...
>>>>
>>>> I am running on a processor that has compare/exchange 128-bit (cx16
>>>> capability),
>>>> and I compiler with -mcx16 and -latomic.  I'm on the latest release cygwin gcc
>>>> (9.2.0-3, I believe) and the corresponding libatomic.  I have a program with
>>>> this in it:
>>>>
>>>> __atomic_compare_exchange((__int128 *)&s1, (__int128 *)&z, (__int128 *)&s2, 0,
>>>> __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST);
>>>>
>>>> This compiles to a call (nice if it would inline, but ...) to
>>>> __atomic_compare_exchange_16, which uses mutex's, not the CMPXCHG16B
>>>> instruction I was hoping for.  Note I am doing dynamic linking,
>>>> which on at least one other platform results in dynamic selection
>>>> of a lib_at implementation of the compare/exchange, which does use
>>>> the desired instruction.
>>>>
>>>> Is this a limitation of cygwin gcc, or should I be doing something
>>>> different to achieve the desired effect?
>>>>
>>>> Obviously it would be best not to going an asm inline if I can avoid it,
>>>> but I suppose I can dig into the libatomic source to get the right
>>>> incantation for it if need be ...
>>>
>>> A quick followup: I was able to get __sync_val_compare_and_swap_16 to work
>>> (and its bool form).  That will do for now, though of course it's deprecated.
>>
>> You just needed to go to the next info page:
>>
>>     $ info gcc __atomic
>>
>> and use:
>>
>>     #include <stdatomic.h>
>>     extern bool __atomic_compare_exchange ( TYPE *ptr,
>>                         TYPE *expected,
>>                         TYPE *desired,
>>                         bool weak,
>>                         int success_memorder,
>>                         int failure_memorder);
>>
>> or higher level macro:
>>
>>     atomic_compare_exchange_strong(PTR, VAL, DES)
>>
>> defined in /lib/gcc/x86_64-pc-cygwin/*/include/stdatomic.h
> 
> That is what I was already doing :-) .... it compiles and runs,
> landing at libat_compare_exchange_16, which uses mutexes, not the
> 16-byte compare-exchange instruction.  So how do I get the compare-
> exchange instruction to be used in the library?

Digging further into the murk where a simple builtin inline cmpxchg16b isn't.

Doing what you're doing now seems easier and better supported than alternatives.
You can drop stdatomic.h and -latomic as the low level functions are builtins.

You could also write your own inline function using cmpxchg16b directly in asm.

Looks like because of cpu and library requirements, you would have to enable
indirect inline functions in gcc, write libatomic library functions which
support gcc indirect inline functions, to test cpu cx16 feature, then setup
indirection, to bypass mutexes.

-- 
Take care. Thanks, Brian Inglis, Calgary, Alberta, Canada

This email may be disturbing to some readers as it contains
too much technical detail. Reader discretion is advised.
--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

