1add_library( 2 libc_diff_test_utils STATIC 3 Timer.cpp 4 Timer.h 5) 6target_include_directories( 7 libc_diff_test_utils 8 PRIVATE 9 ${LIBC_SOURCE_DIR} 10) 11add_dependencies( 12 libc_diff_test_utils 13 libc.src.__support.macros.config 14) 15 16# A convenience target to build all performance tests. 17add_custom_target(libc-math-performance-tests) 18 19function(add_perf_binary target_name) 20 cmake_parse_arguments( 21 "PERF" 22 "" # No optional arguments 23 "SUITE;CXX_STANDARD" # Single value arguments 24 "SRCS;HDRS;DEPENDS;COMPILE_OPTIONS;LINK_LIBRARIES" # Multi-value arguments 25 ${ARGN} 26 ) 27 if(NOT PERF_SRCS) 28 message(FATAL_ERROR "'add_perf_binary' target requires a SRCS list of .cpp " 29 "files.") 30 endif() 31 if(NOT PERF_DEPENDS) 32 message(FATAL_ERROR "'add_perf_binary' target requires a DEPENDS list of " 33 "'add_entrypoint_object' targets.") 34 endif() 35 36 get_fq_target_name(${target_name} fq_target_name) 37 get_fq_deps_list(fq_deps_list ${PERF_DEPENDS}) 38 get_object_files_for_test( 39 link_object_files skipped_entrypoints_list ${fq_deps_list}) 40 if(skipped_entrypoints_list) 41 if(LIBC_CMAKE_VERBOSE_LOGGING) 42 set(msg "Will not build ${fq_target_name} as it has missing deps: " 43 "${skipped_entrypoints_list}.") 44 message(STATUS ${msg}) 45 endif() 46 return() 47 endif() 48 49 add_executable( 50 ${fq_target_name} 51 EXCLUDE_FROM_ALL 52 ${PERF_SRCS} 53 ${PERF_HDRS} 54 ) 55 target_include_directories( 56 ${fq_target_name} 57 PRIVATE 58 ${LIBC_SOURCE_DIR} 59 ) 60 if(PERF_COMPILE_OPTIONS) 61 target_compile_options( 62 ${fq_target_name} 63 PRIVATE ${PERF_COMPILE_OPTIONS} 64 ) 65 endif() 66 67 set(link_libraries ${link_object_files}) 68 foreach(lib IN LISTS PERF_LINK_LIBRARIES) 69 list(APPEND link_libraries ${lib}.unit) 70 endforeach() 71 target_link_libraries( 72 ${fq_target_name} 73 PRIVATE ${link_libraries} libc_diff_test_utils) 74 75 set_target_properties(${fq_target_name} 76 PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) 77 78 if(PERF_CXX_STANDARD) 79 set_target_properties( 80 ${fq_target_name} 81 PROPERTIES 82 CXX_STANDARD ${PERF_CXX_STANDARD} 83 ) 84 endif() 85 86 add_dependencies( 87 ${fq_target_name} 88 libc.src.__support.FPUtil.fp_bits 89 ${fq_deps_list} 90 ) 91 add_dependencies(libc-math-performance-tests ${fq_target_name}) 92endfunction() 93 94add_header_library( 95 single_input_single_output_diff 96 HDRS 97 SingleInputSingleOutputPerf.h 98 DEPENDS 99 libc.src.__support.CPP.algorithm 100 libc.src.__support.FPUtil.fp_bits 101) 102 103add_header_library( 104 binary_op_single_output_diff 105 HDRS 106 BinaryOpSingleOutputPerf.h 107 DEPENDS 108 libc.src.__support.CPP.algorithm 109 libc.src.__support.FPUtil.fp_bits 110) 111 112add_perf_binary( 113 sinf_perf 114 SRCS 115 sinf_perf.cpp 116 DEPENDS 117 .single_input_single_output_diff 118 libc.src.math.sinf 119 COMPILE_OPTIONS 120 -fno-builtin 121) 122 123add_perf_binary( 124 cosf_perf 125 SRCS 126 cosf_perf.cpp 127 DEPENDS 128 .single_input_single_output_diff 129 libc.src.math.cosf 130 COMPILE_OPTIONS 131 -fno-builtin 132) 133 134add_perf_binary( 135 expm1f_perf 136 SRCS 137 expm1f_perf.cpp 138 DEPENDS 139 .single_input_single_output_diff 140 libc.src.math.expm1f 141 COMPILE_OPTIONS 142 -fno-builtin 143) 144 145add_perf_binary( 146 ceilf_perf 147 SRCS 148 ceilf_perf.cpp 149 DEPENDS 150 .single_input_single_output_diff 151 libc.src.math.ceilf 152 COMPILE_OPTIONS 153 -fno-builtin 154) 155 156add_perf_binary( 157 exp10f16_perf 158 SRCS 159 exp10f16_perf.cpp 160 DEPENDS 161 .single_input_single_output_diff 162 libc.src.math.exp10f16 163 COMPILE_OPTIONS 164 -fno-builtin 165) 166 167add_perf_binary( 168 exp2f_perf 169 SRCS 170 exp2f_perf.cpp 171 DEPENDS 172 .single_input_single_output_diff 173 libc.src.math.exp2f 174 COMPILE_OPTIONS 175 -fno-builtin 176) 177 178add_perf_binary( 179 exp2f16_perf 180 SRCS 181 exp2f16_perf.cpp 182 DEPENDS 183 .single_input_single_output_diff 184 libc.src.math.exp2f16 185 COMPILE_OPTIONS 186 -fno-builtin 187) 188 189add_perf_binary( 190 expf_perf 191 SRCS 192 expf_perf.cpp 193 DEPENDS 194 .single_input_single_output_diff 195 libc.src.math.expf 196 COMPILE_OPTIONS 197 -fno-builtin 198) 199 200add_perf_binary( 201 expf16_perf 202 SRCS 203 expf16_perf.cpp 204 DEPENDS 205 .single_input_single_output_diff 206 libc.src.math.expf16 207 COMPILE_OPTIONS 208 -fno-builtin 209) 210 211add_perf_binary( 212 fabsf_perf 213 SRCS 214 fabsf_perf.cpp 215 DEPENDS 216 .single_input_single_output_diff 217 libc.src.math.fabsf 218 COMPILE_OPTIONS 219 -fno-builtin 220) 221 222add_perf_binary( 223 floorf_perf 224 SRCS 225 floorf_perf.cpp 226 DEPENDS 227 .single_input_single_output_diff 228 libc.src.math.floorf 229 COMPILE_OPTIONS 230 -fno-builtin 231) 232 233add_perf_binary( 234 log10f_perf 235 SRCS 236 log10f_perf.cpp 237 DEPENDS 238 .single_input_single_output_diff 239 libc.src.math.log10f 240 COMPILE_OPTIONS 241 -fno-builtin 242) 243 244add_perf_binary( 245 log1pf_perf 246 SRCS 247 log1pf_perf.cpp 248 DEPENDS 249 .single_input_single_output_diff 250 libc.src.math.log1pf 251 COMPILE_OPTIONS 252 -fno-builtin 253) 254 255add_perf_binary( 256 log2f_perf 257 SRCS 258 log2f_perf.cpp 259 DEPENDS 260 .single_input_single_output_diff 261 libc.src.math.log2f 262 COMPILE_OPTIONS 263 -fno-builtin 264) 265 266add_perf_binary( 267 logf_perf 268 SRCS 269 logf_perf.cpp 270 DEPENDS 271 .single_input_single_output_diff 272 libc.src.math.logf 273 COMPILE_OPTIONS 274 -fno-builtin 275) 276 277add_perf_binary( 278 logbf_perf 279 SRCS 280 logbf_perf.cpp 281 DEPENDS 282 .single_input_single_output_diff 283 libc.src.math.logbf 284 COMPILE_OPTIONS 285 -fno-builtin 286) 287 288add_perf_binary( 289 nearbyintf_perf 290 SRCS 291 nearbyintf_perf.cpp 292 DEPENDS 293 .single_input_single_output_diff 294 libc.src.math.nearbyintf 295 COMPILE_OPTIONS 296 -fno-builtin 297) 298 299add_perf_binary( 300 rintf_perf 301 SRCS 302 rintf_perf.cpp 303 DEPENDS 304 .single_input_single_output_diff 305 libc.src.math.rintf 306 COMPILE_OPTIONS 307 -fno-builtin 308) 309 310add_perf_binary( 311 roundf_perf 312 SRCS 313 roundf_perf.cpp 314 DEPENDS 315 .single_input_single_output_diff 316 libc.src.math.roundf 317 COMPILE_OPTIONS 318 -fno-builtin 319) 320 321add_perf_binary( 322 sqrtf_perf 323 SRCS 324 sqrtf_perf.cpp 325 DEPENDS 326 .single_input_single_output_diff 327 libc.src.math.sqrtf 328 COMPILE_OPTIONS 329 -fno-builtin 330) 331 332add_perf_binary( 333 truncf_perf 334 SRCS 335 truncf_perf.cpp 336 DEPENDS 337 .single_input_single_output_diff 338 libc.src.math.truncf 339 COMPILE_OPTIONS 340 -fno-builtin 341) 342 343add_perf_binary( 344 hypotf_perf 345 SRCS 346 hypotf_perf.cpp 347 DEPENDS 348 .binary_op_single_output_diff 349 libc.src.math.hypotf 350 COMPILE_OPTIONS 351 -fno-builtin 352) 353 354add_perf_binary( 355 hypot_perf 356 SRCS 357 hypot_perf.cpp 358 DEPENDS 359 .binary_op_single_output_diff 360 libc.src.math.hypot 361 COMPILE_OPTIONS 362 -fno-builtin 363) 364 365add_perf_binary( 366 fmodf_perf 367 SRCS 368 fmodf_perf.cpp 369 DEPENDS 370 .single_input_single_output_diff 371 libc.src.math.fmodf 372 COMPILE_OPTIONS 373 -fno-builtin 374) 375 376add_perf_binary( 377 fmod_perf 378 SRCS 379 fmod_perf.cpp 380 DEPENDS 381 .single_input_single_output_diff 382 libc.src.math.fmod 383 COMPILE_OPTIONS 384 -fno-builtin 385) 386 387add_perf_binary( 388 fmodl_perf 389 SRCS 390 fmodl_perf.cpp 391 DEPENDS 392 .single_input_single_output_diff 393 libc.src.math.fmodl 394 COMPILE_OPTIONS 395 -fno-builtin 396) 397 398add_perf_binary( 399 fmodf16_perf 400 SRCS 401 fmodf16_perf.cpp 402 DEPENDS 403 .binary_op_single_output_diff 404 libc.src.math.fmodf16 405 libc.src.__support.FPUtil.generic.fmod 406 libc.src.__support.macros.properties.types 407) 408 409add_perf_binary( 410 fmodf128_perf 411 SRCS 412 fmodf128_perf.cpp 413 DEPENDS 414 .single_input_single_output_diff 415 libc.src.math.fmodf128 416 COMPILE_OPTIONS 417 -fno-builtin 418) 419 420add_perf_binary( 421 nearest_integer_funcs_perf 422 SRCS 423 nearest_integer_funcs_perf.cpp 424 DEPENDS 425 libc.src.math.ceilf 426 libc.src.math.ceilf16 427 libc.src.math.floorf 428 libc.src.math.floorf16 429 libc.src.math.rintf 430 libc.src.math.rintf16 431 libc.src.math.roundf 432 libc.src.math.roundf16 433 libc.src.math.roundevenf 434 libc.src.math.roundevenf16 435 libc.src.math.truncf 436 libc.src.math.truncf16 437 COMPILE_OPTIONS 438 -fno-builtin 439 LINK_LIBRARIES 440 LibcFPTestHelpers 441) 442 443add_perf_binary( 444 misc_basic_ops_perf 445 SRCS 446 misc_basic_ops_perf.cpp 447 DEPENDS 448 .binary_op_single_output_diff 449 .single_input_single_output_diff 450 libc.src.math.copysignf 451 libc.src.math.copysignf16 452 libc.src.math.fabsf 453 libc.src.math.fabsf16 454 COMPILE_OPTIONS 455 -fno-builtin 456) 457 458add_perf_binary( 459 max_min_funcs_perf 460 SRCS 461 max_min_funcs_perf.cpp 462 DEPENDS 463 .binary_op_single_output_diff 464 libc.src.math.fmaxf 465 libc.src.math.fmaxf16 466 libc.src.math.fmaximumf 467 libc.src.math.fmaximumf16 468 libc.src.math.fmaximum_numf 469 libc.src.math.fmaximum_numf16 470 libc.src.math.fminf 471 libc.src.math.fminf16 472 libc.src.math.fminimumf 473 libc.src.math.fminimumf16 474 libc.src.math.fminimum_numf 475 libc.src.math.fminimum_numf16 476 COMPILE_OPTIONS 477 -fno-builtin 478) 479 480add_perf_binary( 481 fmul_perf 482 SRCS 483 fmul_perf.cpp 484 DEPENDS 485 .binary_op_single_output_diff 486 libc.src.math.fmul 487 libc.src.__support.FPUtil.generic.mul 488 libc.src.__support.FPUtil.fp_bits 489 COMPILE_OPTIONS 490 -fno-builtin 491) 492 493add_perf_binary( 494 fmull_perf 495 SRCS 496 fmull_perf.cpp 497 DEPENDS 498 .binary_op_single_output_diff 499 libc.src.math.fmull 500 COMPILE_OPTIONS 501 -fno-builtin 502) 503