Skip to content
This repository was archived by the owner on Sep 2, 2018. It is now read-only.

Add atomics support #211

Merged
merged 5 commits into from
Jun 11, 2016
Merged

Add atomics support #211

merged 5 commits into from
Jun 11, 2016

Conversation

dylanmckay
Copy link
Member

@dylanmckay dylanmckay commented Jun 10, 2016

This PR adds atomics support to AVR.

Still need to implement

  • atomic_load_add
  • atomic_cmp_swap
  • atomic_swap
  • atomic_load_sub
  • atomic_load_and
  • atomic_load_or
  • atomic_load_xor
  • atomic_load_nand
  • atomic_load_min
  • atomic_load_max
  • atomic_load_umin
  • atomic_load_umax
  • atomic_fence

Ideally we should use the AVR RMW instructions (XCH, etc) when we can. Not a priority though because they aren't well supported.

Fixes #197.

@@ -1237,6 +1237,16 @@ isReMaterializable = 1 in
Requires<[HasSRAM]>;
}

def AtomicLoad8 : Pseudo<(outs GPR8:$rd),
(ins PTRREGS:$rr),
"atomic_laod $rd, $rr",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo: laod

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice catch!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have fixed this up and force pushed.

@dylanmckay dylanmckay force-pushed the support-atomics-v2 branch from 89f4777 to e9b4a6e Compare June 10, 2016 11:19

template<>
bool AVRExpandPseudo::expand<AVR::AtomicLoad8>(Block &MBB, BlockIt MBBI) {
return expandAtomicBinaryOp(AVR::MOVRdRr, MBB, MBBI);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we lower this to a MOV or an LD operation? I'm not that familiar with the atomics but 'atomic load' sounds more like a LD...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, my brain farted. Have got this on a local branch.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has now been pushed

@dylanmckay dylanmckay force-pushed the support-atomics-v2 branch from e9b4a6e to a2b5eb0 Compare June 10, 2016 12:21
; CHECK-NEXT: ldd [[RR2:r[0-9]+]], [[RD2:(X|Y|Z)]]+
; CHECK-NEXT: add [[RR1]], [[TMP:r[0-9]+]]
; CHECK-NEXT: adc [[RR2]], [[TMP:r[0-9]+]]
; CHECK-NEXT: out 63, r0

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is starting to look really nice 👍
Don't forget to store the result back to %foo though (see http://llvm.org/docs/LangRef.html#atomicrmw-instruction)

@dylanmckay
Copy link
Member Author

@rjordans did you want to review this?

@rjordans
Copy link

Sure no problem, I was mainly trying to follow how this would be implemented and figured that I could just as well give some suggestions whenever I spot things. I hope you didn't mind.

Anyway, I guess you missed my last comment but from looking at the LLVM language reference it seems that the atomicrmw operations require a write-back of the new value as well. It seems like you miss that in the currently generated code. Other than that it looks really nice now.

@dylanmckay
Copy link
Member Author

Suggestions and feedback are always appreciated :) I haven't worked with atomics much either so anything is useful.

Don't forget to store the result back to %foo though (see http://llvm.org/docs/LangRef.html#atomicrmw-instruction)

I didn't notice that before, nice catch!

@dylanmckay
Copy link
Member Author

The atomic RMW instructions now store the value back to the original pointer.

@dylanmckay dylanmckay force-pushed the support-atomics-v2 branch from 1729811 to 081b3a6 Compare June 11, 2016 11:23
@dylanmckay
Copy link
Member Author

Have also rebased the branch so it's a bit cleaner.

@dylanmckay dylanmckay merged commit ca5ea80 into avr-support Jun 11, 2016
@dylanmckay dylanmckay deleted the support-atomics-v2 branch June 11, 2016 11:26
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants