init.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /* Copyright (C) 2012-2022 Free Software Foundation, Inc.
  2. Contributed by Richard Henderson <rth@redhat.com>.
  3. This file is part of the GNU Atomic Library (libatomic).
  4. Libatomic is free software; you can redistribute it and/or modify it
  5. under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 3 of the License, or
  7. (at your option) any later version.
  8. Libatomic is distributed in the hope that it will be useful, but WITHOUT ANY
  9. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  10. FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  11. more details.
  12. Under Section 7 of GPL version 3, you are granted additional
  13. permissions described in the GCC Runtime Library Exception, version
  14. 3.1, as published by the Free Software Foundation.
  15. You should have received a copy of the GNU General Public License and
  16. a copy of the GCC Runtime Library Exception along with this program;
  17. see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
  18. <http://www.gnu.org/licenses/>. */
  19. #include "libatomic_i.h"
  20. #if HAVE_IFUNC
  21. unsigned int __libat_feat1;
  22. unsigned int
  23. __libat_feat1_init (void)
  24. {
  25. unsigned int eax, ebx, ecx, edx;
  26. FEAT1_REGISTER = 0;
  27. __get_cpuid (1, &eax, &ebx, &ecx, &edx);
  28. #ifdef __x86_64__
  29. if ((FEAT1_REGISTER & (bit_AVX | bit_CMPXCHG16B))
  30. == (bit_AVX | bit_CMPXCHG16B))
  31. {
  32. /* Intel SDM guarantees that 16-byte VMOVDQA on 16-byte aligned address
  33. is atomic, but so far we don't have this guarantee from AMD. */
  34. unsigned int ecx2 = 0;
  35. __get_cpuid (0, &eax, &ebx, &ecx2, &edx);
  36. if (ecx2 != signature_INTEL_ecx)
  37. FEAT1_REGISTER &= ~bit_AVX;
  38. }
  39. #endif
  40. /* See the load in load_feat1. */
  41. __atomic_store_n (&__libat_feat1, FEAT1_REGISTER, __ATOMIC_RELAXED);
  42. return FEAT1_REGISTER;
  43. }
  44. #endif /* HAVE_IFUNC */