• Re: Performance of xchg reg,reg

    From Stefan Monnier@monnier@iro.umontreal.ca to comp.arch on Tue Oct 20 10:00:15 2026
    From Newsgroup: comp.arch

    Stephen Fuld [2026-10-19 06:57:48] wrote:
    On 10/18/2026 8:43 PM, Stefan Monnier wrote:
    Anton Ertl [2026-10-18 16:57:26] wrote:
    And actually all the stuff about XCHG with memory operands does not
    contradict this sentence. It could be understood as meaning that
    while all the other aspects of locking don't apply to "XCHG reg, reg",
    the assertion of the LOCK# signal still has to occur, and that's why
    Intel processors implement a slow XCHG reg, reg.
    How could code witness the difference?
    I believe AMD can claim that its behavior is consistent with the
    behavior you'd get when asserting the LOCK# signal.
    === Stefan
    I believe this all started with empirical data from Anton showing different performance between Intel and AMD processors for XCHG reg,reg.

    Indeed but my question is about the ISA definition, i.e. independent
    from any specific implementation.


    === Stefan
    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From cross@cross@spitfire.i.gajendra.net (Dan Cross) to comp.arch on Tue Oct 20 19:56:43 2026
    From Newsgroup: comp.arch

    In article <jwvzew8mpwv.fsf-monnier+comp.arch@gnu.org>,
    Stefan Monnier <monnier@iro.umontreal.ca> wrote:
    Dan Cross [2026-10-20 02:00:48] wrote:
    In article <jwv8q3uqrxf.fsf-monnier+comp.arch@gnu.org>,
    Stefan Monnier <monnier@iro.umontreal.ca> wrote:
    How could code witness the difference?
    The effects of a bus lock include disallowing memory operations
    (except for instruction fetches or page table accesses) passing
    a locked operation.

    Ah, so it doesn't just make the operation atomic, but it additionally
    imposes barrier-style restrictions on reordering surrounding memory >operations? I see, thanks.

    Well, to be clear, I don't think that _that particular form_ of
    `xchg` actually does. But if the destination were a memory
    operand, it would, yes. :-)

    - Dan C.

    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From Chris M. Thomasson@chris.m.thomasson.1@gmail.com to comp.arch on Tue Oct 20 16:44:11 2026
    From Newsgroup: comp.arch

    On 10/20/2026 7:09 AM, Scott Lurndal wrote:
    cross@spitfire.i.gajendra.net (Dan Cross) writes:
    In article <jwv8q3uqrxf.fsf-monnier+comp.arch@gnu.org>,
    Stefan Monnier <monnier@iro.umontreal.ca> wrote:
    Anton Ertl [2026-10-18 16:57:26] wrote:
    And actually all the stuff about XCHG with memory operands does not
    contradict this sentence. It could be understood as meaning that
    while all the other aspects of locking don't apply to "XCHG reg, reg", >>>> the assertion of the LOCK# signal still has to occur, and that's why
    Intel processors implement a slow XCHG reg, reg.

    How could code witness the difference?

    I believe AMD can claim that its behavior is consistent with the
    behavior you'd get when asserting the LOCK# signal.

    The effects of a bus lock include disallowing memory operations
    (except for instruction fetches or page table accesses) passing
    a locked operation. If `XCHG reg,reg` where indeed treated as
    though it asserted `LOCK#` for the duration of its execution, it
    could be (ab)used to force that behavior: From sec 11.1.2.2 of
    SDM Volume 3a (Sept 2026 version):


    It's worth noting that AMD processors (in the 2008 timeframe) would
    assert the LOCK# signal if a highly contended cache line could not
    be acquired in exclusive mode within a certain window of time,
    even if the access was completely encapsulated in said cache line.

    I suspect that is still the case.

    I almost have to agree. I think it was there for some sort of anti livelock...? Try bashing the shit out of a LOCK CMPXCHG with another
    thread just writing to the address trying to make the CAS fail, over and
    over again... It might force some internal logic to assert a real bus lock.
    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From quadibloc@quadibloc@invalid.com (John Savard) to comp.arch on Wed Oct 21 14:15:04 2026
    From Newsgroup: comp.arch

    On Mon, 19 Oct 2026 01:46:21 -0000 (UTC), Lawrence =?iso-8859-13?q?D=FFOliveiro?= <ldo@nz.invalid> wrote:

    Niklaus Wirth was possibly the biggest critic of the Algol 68 effort.
    He and Tony Hoare had previously created Algol-W, which pioneered the
    concept of record structures (taking a simpler form than COBOLrCOs
    convoluted record structures). Pascal was basically the next step in
    the evolution of that.

    And, of course, one might mention MODULA-2, which took certain
    advanced ideas seen in Ada and put them in a Pascal-like context.

    John Savard
    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From Niklas Holsti@niklas.holsti@tidorum.invalid to comp.arch on Wed Oct 21 18:34:46 2026
    From Newsgroup: comp.arch

    On 2026-10-21 17:15, John Savard wrote:
    On Mon, 19 Oct 2026 01:46:21 -0000 (UTC), Lawrence =?iso-8859-13?q?D=FFOliveiro?= <ldo@nz.invalid> wrote:

    Niklaus Wirth was possibly the biggest critic of the Algol 68 effort.
    He and Tony Hoare had previously created Algol-W, which pioneered the
    concept of record structures (taking a simpler form than COBOLrCOs
    convoluted record structures). Pascal was basically the next step in
    the evolution of that.

    And, of course, one might mention MODULA-2, which took certain
    advanced ideas seen in Ada and put them in a Pascal-like context.

    My understanding is that the influences went from Modula-2 to Ada, and Wikipedia agrees with me, saying that Modula-2 first appeared in 1978.
    The development of these languages overlapped in time, but Modula-2 was finalized and published before Ada.

    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From quadibloc@quadibloc@invalid.com (John Savard) to comp.arch on Wed Oct 21 19:38:00 2026
    From Newsgroup: comp.arch

    On Wed, 21 Oct 2026 18:34:46 +0300, Niklas Holsti <niklas.holsti@tidorum.invalid> wrote:

    My understanding is that the influences went from Modula-2 to Ada, and >Wikipedia agrees with me, saying that Modula-2 first appeared in 1978.

    You're quite right. I searched for more information, and apparently
    Concurrent Pascal was "first", with MODULA-2 coming very shortly
    after. And then, after the two competing models of those languages
    were discussed for a while, Ada included the feature as well.

    However, one source claimed that PL/I should really be given the
    credit for including parallel constructs well before Concurrent
    Pascal.

    John Savard
    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From aph@aph@littlepinkcloud.invalid to comp.arch on Thu Oct 22 09:51:38 2026
    From Newsgroup: comp.arch

    John Savard <quadibloc@invalid.com> wrote:
    On Wed, 21 Oct 2026 18:34:46 +0300, Niklas Holsti <niklas.holsti@tidorum.invalid> wrote:

    My understanding is that the influences went from Modula-2 to Ada, and >>Wikipedia agrees with me, saying that Modula-2 first appeared in 1978.

    You're quite right. I searched for more information, and apparently Concurrent Pascal was "first", with MODULA-2 coming very shortly
    after. And then, after the two competing models of those languages
    were discussed for a while, Ada included the feature as well.

    However, one source claimed that PL/I should really be given the
    credit for including parallel constructs well before Concurrent
    Pascal.

    I think that's a rather IBM-centric view. The Burroughs B5000 (after
    1961) OS was written in an Algol dialect called ESPOL, which
    necessarily had concurrency support. The first production PL/I
    compiler shipped in 1966.

    Andrew.
    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From anton@anton@mips.complang.tuwien.ac.at (Anton Ertl) to comp.arch on Thu Oct 22 10:54:04 2026
    From Newsgroup: comp.arch

    Stefan Monnier <monnier@iro.umontreal.ca> writes:
    Anton Ertl [2026-10-18 16:57:26] wrote:
    And actually all the stuff about XCHG with memory operands does not
    contradict this sentence. It could be understood as meaning that
    while all the other aspects of locking don't apply to "XCHG reg, reg",
    the assertion of the LOCK# signal still has to occur, and that's why
    Intel processors implement a slow XCHG reg, reg.

    How could code witness the difference?

    Depends on the hardware. If there is some device connected t the
    LOCK# signal (e.g., another CPU), and that behaves differently when
    the signal is asserted, the code can measure that.

    - anton
    --
    'Anyone trying for "industrial quality" ISA should avoid undefined behavior.'
    Mitch Alsup, <c17fcd89-f024-40e7-a594-88a85ac10d20o@googlegroups.com>
    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From Michael S@already5chosen@yahoo.com to comp.arch on Thu Oct 22 22:11:32 2026
    From Newsgroup: comp.arch

    On Thu, 22 Oct 2026 10:54:04 GMT
    anton@mips.complang.tuwien.ac.at (Anton Ertl) wrote:

    Stefan Monnier <monnier@iro.umontreal.ca> writes:
    Anton Ertl [2026-10-18 16:57:26] wrote:
    And actually all the stuff about XCHG with memory operands does not
    contradict this sentence. It could be understood as meaning that
    while all the other aspects of locking don't apply to "XCHG reg,
    reg", the assertion of the LOCK# signal still has to occur, and
    that's why Intel processors implement a slow XCHG reg, reg.

    How could code witness the difference?

    Depends on the hardware. If there is some device connected t the
    LOCK# signal (e.g., another CPU), and that behaves differently when
    the signal is asserted, the code can measure that.

    - anton

    My undersanding is that in server x86 CPU physical LOCK# signal does not
    exist for more than decade. Probably much longer in desktop and laptop
    devices.

    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From Stephen Fuld@sfuld@alumni.cmu.edu.invalid to comp.arch on Thu Oct 22 14:15:57 2026
    From Newsgroup: comp.arch

    On 10/21/2026 12:38 PM, John Savard wrote:
    On Wed, 21 Oct 2026 18:34:46 +0300, Niklas Holsti <niklas.holsti@tidorum.invalid> wrote:

    My understanding is that the influences went from Modula-2 to Ada, and
    Wikipedia agrees with me, saying that Modula-2 first appeared in 1978.

    You're quite right. I searched for more information, and apparently Concurrent Pascal was "first", with MODULA-2 coming very shortly
    after. And then, after the two competing models of those languages
    were discussed for a while, Ada included the feature as well.

    However, one source claimed that PL/I should really be given the
    credit for including parallel constructs well before Concurrent
    Pascal.

    I vaguely recall that there was an optional feature in the COBOL
    standard for concurrent processing, or something like that. It wasn't implemented in the compiler I used and I never investigated exactly what
    it was. But it certainly predated Pascal, Ad and other such languages.

    Does anyone else know anything about this?
    --
    - Stephen Fuld
    (e-mail address disguised to prevent spam)
    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From scott@scott@slp53.sl.home (Scott Lurndal) to comp.arch on Fri Oct 23 14:08:09 2026
    From Newsgroup: comp.arch

    Stephen Fuld <sfuld@alumni.cmu.edu.invalid> writes:
    On 10/21/2026 12:38 PM, John Savard wrote:
    On Wed, 21 Oct 2026 18:34:46 +0300, Niklas Holsti
    <niklas.holsti@tidorum.invalid> wrote:

    My understanding is that the influences went from Modula-2 to Ada, and
    Wikipedia agrees with me, saying that Modula-2 first appeared in 1978.

    You're quite right. I searched for more information, and apparently
    Concurrent Pascal was "first", with MODULA-2 coming very shortly
    after. And then, after the two competing models of those languages
    were discussed for a while, Ada included the feature as well.

    However, one source claimed that PL/I should really be given the
    credit for including parallel constructs well before Concurrent
    Pascal.

    I vaguely recall that there was an optional feature in the COBOL
    standard for concurrent processing, or something like that. It wasn't >implemented in the compiler I used and I never investigated exactly what
    it was. But it certainly predated Pascal, Ad and other such languages.

    Does anyone else know anything about this?

    Burroughs added concurrent programming extensions to COBOL74 back
    in the 70's. USAGE IS TASK, for example; also the PROCESS verb
    was added.
    --- Synchronet 3.22a-Linux NewsLink 1.2