New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
-march=i386 should not generate bswap/cmpxchg/xadd instructions #58470
Comments
@llvm/issue-subscribers-backend-x86 |
I think we don't divide enough in legacy instructions. One of the reason I guess is we don't have corresponding bit in CPUID as well. It doesn't look much value to me to do such things for a rather old product. |
It's not exactly For the 486 to Pentium differences ( #include <stdatomic.h>
_Bool cmpxchg8b(
volatile _Atomic unsigned long long * obj,
unsigned long long * expected,
unsigned long long desired)
{
return atomic_compare_exchange_strong(obj, expected, desired);
} (https://godbolt.org/z/PnM1hexav) So, there is some existing work for supporting very old CPUs. However, for 486 #include <stdatomic.h>
_Bool cmpxchg(
volatile _Atomic unsigned long * obj,
unsigned long * expected,
unsigned long desired)
{
return atomic_compare_exchange_strong(obj, expected, desired);
} (https://godbolt.org/z/ffGMo9596) Also, 486 #include <stdatomic.h>
unsigned long cmpxchg(
volatile _Atomic unsigned long * obj,
unsigned long arg)
{
return atomic_fetch_add(obj, arg);
} (https://godbolt.org/z/Tav5hGd9Y) The only other 486 instructions ( So, it looks like it's really just |
If Clang does not care about |
The last time anyone looked at stuff related to ancient CPUs was https://reviews.llvm.org/D59566 , I think, which fixed the use of cmpxchg8b on 486. There's basically zero interest in building open source operating systems for Intel CPUs older than 486. Linux dropped 386 support a decade ago, NetBSD also requires a 486 minimum. If you're interested, you could try to implement it, though. The main thing would be teaching the backend that i386 doesn't have native atomics. (If we don't have cmpxchg, then we can't implement arbitrary atomic operations, so all atomic ops have to fallback to libatomic.) |
Correct, there are no major systems still targeting i386, so this issue has not of any actual practical relevance as far as I can see. There is FreeDOS which still runs on i386 and there is DJGPP, but as far as I know, Clang cannot target DJGPP. |
It's reasonable for LLVM not to support 80386 targets, but It would be nice if |
While investigating a totally unrelated problem, I ran across Clang generating a
BSWAP
instruction with-march=i386
.BSWAP
is a 486 instruction (see https://www.felixcloutier.com/x86/bswap) and should thus not be available when targeting 386.Clang generates
BSWAP
for both, a call to__builtin_bswap32
, and as an optimization of a pure C implementation.(https://godbolt.org/z/8zhK7GnsM)
Now, I am not actually sure if Clang even wants to be able to target 386-class CPUs at all (I was not able to find any documentation indicating a positive or negative answer to that), however, it does accept
-march=i386
without any warning or error. IMHO, it should either generate proper instructions honoring the given target, or just fail accepting the target CPU in the first place.The text was updated successfully, but these errors were encountered: