33 * Example demonstrating the C API for archspec
44 */
55
6- #include <stdio.h>
76#include "archspec/archspec_c.h"
7+ #include <stdio.h>
88
99int main (void ) {
1010 printf ("=== archspec C API Example ===\n\n" );
11-
11+
1212 /* Host CPU information */
1313 const char * host_name = archspec_host_name ();
1414 const char * host_vendor = archspec_host_vendor ();
15-
15+
1616 printf ("Host CPU:\n" );
1717 printf (" Name: %s\n" , host_name ? host_name : "(unknown)" );
1818 printf (" Vendor: %s\n" , host_vendor ? host_vendor : "(unknown)" );
19-
19+
2020 char * host_features = archspec_host_features ();
2121 if (host_features ) {
2222 printf (" Features: %s\n" , host_features );
2323 archspec_free (host_features );
2424 }
25-
25+
2626 /* Get optimization flags */
2727 char * gcc_flags = archspec_host_flags ("gcc" );
2828 if (gcc_flags ) {
2929 printf (" GCC flags: %s\n" , gcc_flags );
3030 archspec_free (gcc_flags );
3131 }
32-
32+
3333 char * clang_flags = archspec_host_flags ("clang" );
3434 if (clang_flags ) {
3535 printf (" Clang flags: %s\n" , clang_flags );
3636 archspec_free (clang_flags );
3737 }
38-
38+
3939 /* Check for specific features */
4040 printf ("\nFeature checks:\n" );
4141 printf (" Has SSE4.2: %s\n" , archspec_host_has_feature ("sse4_2" ) ? "yes" : "no" );
4242 printf (" Has AVX2: %s\n" , archspec_host_has_feature ("avx2" ) ? "yes" : "no" );
4343 printf (" Has NEON: %s\n" , archspec_host_has_feature ("neon" ) ? "yes" : "no" );
44-
44+
4545 /* Query a specific target */
4646 printf ("\nHaswell features:\n" );
4747 char * haswell_features = archspec_get_features ("haswell" );
@@ -51,32 +51,33 @@ int main(void) {
5151 } else {
5252 printf (" (not found)\n" );
5353 }
54-
54+
5555 char * haswell_flags = archspec_get_flags ("haswell" , "gcc" );
5656 if (haswell_flags ) {
5757 printf (" GCC flags: %s\n" , haswell_flags );
5858 archspec_free (haswell_flags );
5959 }
60-
60+
6161 /* List all targets */
6262 printf ("\nKnown targets (%zu total):\n " , archspec_target_count ());
6363 size_t count = archspec_target_count ();
6464 for (size_t i = 0 ; i < count && i < 10 ; i ++ ) {
6565 const char * name = archspec_target_name (i );
6666 if (name ) {
6767 printf ("%s" , name );
68- if (i < 9 && i < count - 1 ) printf (", " );
68+ if (i < 9 && i < count - 1 )
69+ printf (", " );
6970 }
7071 }
71- if (count > 10 ) printf (", ... (%zu more)" , count - 10 );
72+ if (count > 10 )
73+ printf (", ... (%zu more)" , count - 10 );
7274 printf ("\n" );
73-
75+
7476 /* Check if a target exists */
7577 printf ("\nTarget existence:\n" );
7678 printf (" 'skylake' exists: %s\n" , archspec_target_exists ("skylake" ) ? "yes" : "no" );
7779 printf (" 'zen4' exists: %s\n" , archspec_target_exists ("zen4" ) ? "yes" : "no" );
7880 printf (" 'foobar' exists: %s\n" , archspec_target_exists ("foobar" ) ? "yes" : "no" );
79-
81+
8082 return 0 ;
8183}
82-
0 commit comments