This is an archive of the discontinued LLVM Phabricator instance.

[CodeGen] Clarify the semantics of ADDCARRY/SUBCARRY
ClosedPublic

Authored by kazu on May 6 2022, 1:58 PM.

Details

Summary

This patch clarifies the semantics of ADDCARRY/SUBCARRY, specifically
stating that both the incoming and outgoing carries are active high.

Diff Detail

Event Timeline

kazu created this revision.May 6 2022, 1:58 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 6 2022, 1:58 PM
kazu requested review of this revision.May 6 2022, 1:58 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 6 2022, 1:58 PM

I don't think most people are going to be familiar with "active high"/"active low" terminology. At least, I had to look it up.

I think it makes sense to:

  1. Explicitly mention the relationship with UADDO/USUBO.
  2. Explicitly call out that for subtraction, the native carry flag is the inverse of what USUBO produces.

I don't think most people are going to be familiar with "active high"/"active low" terminology. At least, I had to look it up.

I think it makes sense to:

  1. Explicitly mention the relationship with UADDO/USUBO.
  2. Explicitly call out that for subtraction, the native carry flag is the inverse of what USUBO produces.

What is meant by "native carry flag" here? X86's carry flag matches the USUBO output.

I wonder if the use of the word "carry" on subtract is misleading. Should it be "borrow" instead?

What is meant by "native carry flag" here? X86's carry flag matches the USUBO output.

Sorry, missed a few words. Meant to say "Explicitly call out that for subtraction, on many targets, the native carry flag is the inverse of what USUBO produces." x86 is not one of those targets. AArch64 is.

kazu updated this revision to Diff 427892.May 7 2022, 1:15 PM

Included a comparison to [US]{ADD,SUB}O.

Split the description to several paragraphs, separating the definition
proper and supplemental information.

kazu added a comment.May 7 2022, 1:20 PM

I don't think most people are going to be familiar with "active high"/"active low" terminology. At least, I had to look it up.

OK. I've replaced them with "if and only if" phrases.

I think it makes sense to:

  1. Explicitly mention the relationship with UADDO/USUBO.
  2. Explicitly call out that for subtraction, the native carry flag is the inverse of what USUBO produces.

I am not sure if the latest revision addresses your comment about UADD/USUBO. If not, I'd like to drop the last paragraph about [US]{ADD,SUB}O and check in the rest. I think it's important to check in the precise definition first. We can always add supplemental information later. Thanks!

The reason I mention UADDO/USUBO is because that's what we use to represent the initial operation, usually. If you think it's not important, we can leave that bit out.

Kmeakin accepted this revision.May 9 2022, 8:46 AM

Typo in spelling of "semantics". Otherwise seems fine to me.

This revision is now accepted and ready to land.May 9 2022, 8:46 AM
craig.topper added inline comments.May 9 2022, 9:25 AM
llvm/include/llvm/CodeGen/ISDOpcodes.h
293

Should this be "add/sub" to match the order of "carry/borrow" used?

kazu updated this revision to Diff 428120.May 9 2022, 10:11 AM

Fixed the typo of semantics.

Replaced sub/add with add/sub.

This revision was landed with ongoing or failed builds.May 9 2022, 10:17 AM
This revision was automatically updated to reflect the committed changes.