Download Reference Manual
The Developer's Library for D
About Wiki Forums Source Search Contact

Ticket #1461 (new defect)

Opened 15 years ago

Last modified 14 years ago

Atomic increment only works for bytes

Reported by: jhouse Assigned to: kris
Priority: major Milestone: 2.0
Component: Tango Version: D2.0 branch
Keywords: Cc: jason.james.house@gmail.com

Description

The hand-coded assembly contains ambiguous code lock inc [eax]

Dmd accepts it and translates it to lock incb [eax]

To disambiguate integer increments, the code should be lock inc int ptr [eax]

Change History

01/27/09 01:45:49 changed by kris

  • owner changed from kris to fawzi.

01/27/09 16:57:29 changed by fawzi

  • status changed from new to closed.
  • resolution set to worksforme.

I don't understand your problem, inc [eax] is used only for 1 byte increments (as far as I can see), in which case it is perfectly ok to do incb [eax].

If I missed something please reopen and give more context (like line number).

01/27/09 17:43:57 changed by korDen

  • status changed from closed to reopened.
  • resolution deleted.

tango.core.Atomic.atomicIncrement should increment integer value up to int.max and then drop to 0.

It only increments the least significant byte as of now.

Here is a test case:

int i = 255; atomicIncrement(i); assert(i == 256); // fails

01/27/09 17:45:05 changed by korDen

Err, I meant "...and then drop to int.min", not to 0.

01/28/09 03:00:30 changed by kris

oh, you're saying the assembler should be something like:

inc dword ptr [eax];

?

01/28/09 09:27:41 changed by Don Clugston

Exactly. But it should be int ptr, not dword ptr. (Weird, I know).

01/28/09 12:45:29 changed by fawzi

well it *is*

inc int ptr [eax];

as far as I can see, and indeed the test case works for me on gdc/mac and dmd 1.039/ubuntu

If as Don says int ptr is correct (and Don is an asm expert, so I think it is so), I would say that looks like a compiler bug, can you give more info about your platform/compiler version korDen?

01/28/09 12:59:07 changed by fawzi

add also the tango version to that...

I just checked on codepad.org and indeed the example fails on it. They use Digital Mars D Compiler v1.026 and tango 0.99 I strongly suspect that with the latest versions it is fixed...

01/28/09 15:20:05 changed by korDen

Apparently, I was using an outdated version of Tango and the bug is already fixed per ticket #1221 in changeset [3929].

01/28/09 16:08:10 changed by larsivi

jhouse: can you confirm that your issue is fixed?

01/31/09 20:40:43 changed by jhouse

  • cc set to jason.james.house@gmail.com.
  • version changed from 0.99.7 Dominik to D2.0 branch.

It appears that's the right fix. It's unpatched in the D2.0 branch of Tango and exists in the 0.99.7 release. I've updated the version on the ticket.

I wish I was automatically cc'd on changes to tickets I submit. I forgot to add myself to the cc list when I submitted the bug report.

02/01/09 08:56:49 changed by larsivi

  • milestone changed from 0.99.8 to 2.0.

11/29/09 12:24:36 changed by fawzi

  • owner changed from fawzi to kris.
  • status changed from reopened to new.