This is an archive of the discontinued LLVM Phabricator instance.

[X86][BF16] delete `typedef unsigned short __bfloat16`
AbandonedPublic

Authored by FreddyYe on Dec 12 2021, 11:44 PM.

Details

Summary

The name __bfloat may mislead its real type is bfloat16, but in
fact it's not.

Diff Detail

Event Timeline

FreddyYe created this revision.Dec 12 2021, 11:44 PM
FreddyYe requested review of this revision.Dec 12 2021, 11:44 PM
Herald added a project: Restricted Project. · View Herald TranscriptDec 12 2021, 11:44 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript
craig.topper added inline comments.Dec 13 2021, 10:26 AM
clang/lib/Headers/avx512vlbf16intrin.h
416

I'm not sure if this change is a good idea this late. Users could have been dependent on it being an unsigned value before. I believe this changes the behavior of this code

int result = _mm_cvtness_sbh(X)

Previously it would have zero extended, but now it will sign extend.

FreddyYe added inline comments.Dec 13 2021, 5:39 PM
clang/lib/Headers/avx512vlbf16intrin.h
416

Yes, this should be a huge concern.

Notice that intrinsic update has just documented these two intrinsics on 12/7/2021. So maybe we still have change to change it? And it's more theory right to do sign extension from a bfloat16 to int32.

pengfei added inline comments.Dec 13 2021, 6:14 PM
clang/lib/Headers/avx512vlbf16intrin.h
416

I think this is the problem that we choose integer to represent BF16. Neither zero extend nor sign extend makes sense to a floating type. But considering the MSB of floating point is sign bit. Sign extend should be better in theory.
Maybe it's a good approach to use __bf16, but it is supported only by Clang. We can't use it for intrinsics.
Anyway, I'm fine with keeping zero extend here. @craig.topper , do you think it's acceptable to you if we just change __bfloat16 to short?

pengfei added inline comments.Dec 13 2021, 6:21 PM
clang/lib/Headers/avx512vlbf16intrin.h
416

Sorry, I mean unsigned short

craig.topper added inline comments.Dec 13 2021, 7:48 PM
clang/lib/Headers/avx512vlbf16intrin.h
416

I'm fine with just changing it to unsigned short

FreddyYe updated this revision to Diff 394134.Dec 13 2021, 9:16 PM

changed into unsigned short

FreddyYe updated this revision to Diff 394137.Dec 13 2021, 9:46 PM

clang-format

skan accepted this revision.Dec 13 2021, 9:49 PM

LGTM

This revision is now accepted and ready to land.Dec 13 2021, 9:49 PM
pengfei requested changes to this revision.Dec 13 2021, 10:23 PM

I would suggest we drop the change. Sorry for my fickleness :(

clang/lib/Headers/avx512bf16intrin.h
32

Sorry, when I reviewed the doxygen, I found a new problem. If we want to use unsigned short, we may need to change here too. But unsigned short is not clear to user since they actually want to convert a bfloat type instead of integer.
On the other hand, the double underscore naming conversion is reserved for compiler use and we have already used lots of these terminologies for X86 intrinsics. A much similar one is __mask16. So I think using __bfloat16 here is consistent with the existing types we have defined.

This revision now requires changes to proceed.Dec 13 2021, 10:23 PM
FreddyYe abandoned this revision.Dec 13 2021, 10:30 PM

agree with @pengfei . sorry for noise.