Page MenuHomePhabricator

Expose cache line size in __builtin_get_cpu_cache_line_size
Needs ReviewPublic

Authored by zoecarver on Fri, Mar 20, 2:00 PM.

Details

Summary

This patch creates the __builtin_get_cpu_cache_line_size to wrap the cpu cache line size API from D74918.

Diff Detail

Unit TestsFailed

TimeTest
130 msClang.SemaCXX::builtin-cache-line-size.cpp
Script: -- : 'RUN: at line 1'; /mnt/disks/ssd0/agent/workspace/amd64_debian_testing_clang8/build/bin/clang -mcpu=i368 /mnt/disks/ssd0/agent/workspace/amd64_debian_testing_clang8/clang/test/SemaCXX/builtin-cache-line-size.cpp

Event Timeline

zoecarver created this revision.Fri, Mar 20, 2:00 PM
Herald added a project: Restricted Project. · View Herald TranscriptFri, Mar 20, 2:00 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript

What should the behavior of the builtin be if the calling function has its own target cpu like attribute((target("arch=sandybridge"))) and that CPU has a different size than the CPU that was passed on the command line?

clang/include/clang/Basic/Builtins.def
1483

Can this be "zv" and drop the "tu" from the second string?

@craig.topper thanks for the comments! I'm going to hold off on updating this until we figure out what's happening with D74918, though.

I don't think there's a particularly good reason to expose this as a builtin, unless it's to be used by the standard library implementation. (Which again I do not think we should implement.)

@jyknight yes, the current plan is to use it in libc++'s implementation. I can put that implementation (which uses this builtin) up for review before this lands. That way we can discuss the implementation before adding a (possibly unneeded) builtin. Sound good?

zoecarver updated this revision to Diff 252741.Wed, Mar 25, 9:32 PM
  • Fix based on review comments

@craig.topper I'm not sure what should happen. It should probably just use that CPU (although that's not a great solution). Is there a way to detect if an attribute was used to change the target in which case we could error? What do you think should happen?

zoecarver updated this revision to Diff 252742.Wed, Mar 25, 9:37 PM
  • Diff from master

@craig.topper I'm not sure what should happen. It should probably just use that CPU (although that's not a great solution). Is there a way to detect if an attribute was used to change the target in which case we could error? What do you think should happen?

I'm not sure what should happen as I'm not familiar with the library feature being implemented. As implemented here, the target attribute will be ignored and it will just follow the command line. Why do you say that following the attribute is not a great solution?

clang/test/SemaCXX/builtin-cache-line-size.cpp
1

This say i368 which is not a valid cpu. Did you mean i386? Also x86 uses use -march not -mcpu. I don't think -mcpu does anything.