You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
option(CMAKE_POSITION_INDEPENDENT_CODE "Build with Position Independant Code."ON)
endif()
Can we provide two structures with bit-fields and without for shared lib?
#ifdefine(CPU_FEATURES_SHARED_LIB) && defined(CPU_FEATURES_SHARED_LIB_EXPORT)
typedefstruct {
intmsa; // MIPS SIMD Architecture// https://www.mips.com/products/architectures/ase/simd/inteva; // Enhanced Virtual Addressing// https://www.mips.com/products/architectures/mips64/intr6; // True if is release 6 of the processor.// Make sure to update MipsFeaturesEnum below if you add a field here.
} MipsFeatures;
#elsetypedefstruct {
intmsa : 1; // MIPS SIMD Architecture// https://www.mips.com/products/architectures/ase/simd/inteva : 1; // Enhanced Virtual Addressing// https://www.mips.com/products/architectures/mips64/intr6 : 1; // True if is release 6 of the processor.// Make sure to update MipsFeaturesEnum below if you add a field here.
} MipsFeatures;
#endif
or we can do it via bit operations, but this approach is too complicated and requires a lot of work:
It would be great to improve the public API for porting the library.
Are you talking about porting the library to different languages? Which ones?
however we have one point with shared library
Not only there's a potential issue with bitfields but we are also not providing any ABI stability guarantees.
That's why we strongly discourage the use of shared libraries.
When this project was created, the vision was that it could be run on embedded devices with small memory footprint - hence C99 and bitfields.
I'm not fond of the #ifdef/#endif solution which duplicates the code and is bound to diverge over time. Also it makes the header file harder to understand.
Now if we want to port the API to higher level languages (C#, Java, Python, Go) I think we can trade performance and use the reflection API instead. This should already work out of the box for features in the following (admittedly ugly) way:
walk GetX86FeaturesEnumName() by using an incrementing number from 0 up until you get "unknown_feature".
then you can query all features from 0 to the number you found with GetX86FeaturesEnumValue() which returns a non-0 or 0 value depending on if it's set or not.
Solution 1, a real API
It is not nice but I believe we can create a nicer API on top of that that abstracts cpu away completely. e.g.
Another option that requires much less work is to have the host language run list_cpu_features --json and parse its output (or provide a library function to prevent the overhead of creating a process, something like const char* GetJsonCpuInfo()).
If we choose this option then we need to properly define the content of the JSON output and make it stable over time.
It would be great to improve the public API for porting the library.
My proposal is to add macro
CPU_FEATURES_EXPORT
toinclude/cpu_features_macros.h
and add to public functions this export macro.however we have one point with shared library
cpu_features/CMakeLists.txt
Lines 20 to 31 in 1499163
Can we provide two structures with bit-fields and without for shared lib?
or we can do it via bit operations, but this approach is too complicated and requires a lot of work:
@gchatelet, @Mizux, what do you think?
The text was updated successfully, but these errors were encountered: