1 /* 2 * Copyright 2020, Jérôme Duval, jerome.duval@gmail.com. 3 * Distributed under the terms of the MIT License. 4 */ 5 6 7 #include <stdio.h> 8 #include <stdlib.h> 9 #include <string.h> 10 11 #include <OS.h> 12 13 #include <x86intrin.h> 14 15 extern const char* __progname; 16 17 18 static void 19 print_usage(bool error) 20 { 21 fprintf(error ? stderr : stdout, 22 "Usage: %s\n", 23 __progname); 24 } 25 26 27 static void 28 print_usage_and_exit(bool error) 29 { 30 print_usage(error); 31 exit(error ? 1 : 0); 32 } 33 34 35 int 36 main(int argc, const char* const* argv) 37 { 38 39 if (argc > 2) 40 print_usage_and_exit(true); 41 42 if (argc > 1) { 43 const char* arg = argv[1]; 44 if (strcmp(arg, "-h") == 0 || strcmp(arg, "--help") == 0) 45 print_usage_and_exit(false); 46 } 47 48 #ifdef __x86_64__ 49 uint32 cpuNum; 50 __rdtscp(&cpuNum); 51 printf("%" B_PRIu32 "\n", cpuNum); 52 return 0; 53 #else 54 return 1; 55 #endif 56 } 57