// Auto-generated by ayasin's gen-kernel.py version 0.74 invoked with:
// (align=0, epilog_instructions=[], instructions=['vfmadd132pd %ymm10,%ymm11,%ymm11', 'vfmadd132ps %ymm12,%ymm13,%ymm13', 'vaddpd %xmm0,%xmm0,%xmm0', 'vaddps %xmm1,%xmm1,%xmm1', 'vsubsd %xmm2,%xmm2,%xmm2', 'vsubss %xmm3,%xmm3,%xmm3'], label_prefix='Lbl', loops=1, mode='basicblock', mode_args='', offset=0, prolog_instructions=[], reference='ICL-PMU', registers=0, registers_max=16, unroll_factor=1)
// Do not modify!
//
/* Demonstrates utilization of the extra counters in Icelake's PMU.
 * It collects TMA level 1 as well as FP arithmetic events where an HPC/ML developer may seek to see the high-level bottleneck as well as measure GFLOPs.
 * Profile with (requires new perf tool):
 *   perf stat -e instructions,cycles,ref-cycles,{slots,topdown-retiring,topdown-bad-spec,topdown-fe-bound,topdown-be-bound},fp_arith_inst_retired.128b_packed_double,fp_arith_inst_retired.128b_packed_single,fp_arith_inst_retired.256b_packed_double,fp_arith_inst_retired.256b_packed_single,fp_arith_inst_retired.512b_packed_double,fp_arith_inst_retired.512b_packed_single,fp_arith_inst_retired.scalar_double,fp_arith_inst_retired.scalar_single # on ICL onwards
 *   perf stat -e instructions,cycles,ref-cycles,topdown-fetch-bubbles,topdown-recovery-bubbles,topdown-slots-issued,topdown-slots-retired,topdown-total-slots,fp_arith_inst_retired.128b_packed_double,fp_arith_inst_retired.128b_packed_single,fp_arith_inst_retired.256b_packed_double,fp_arith_inst_retired.256b_packed_single,fp_arith_inst_retired.512b_packed_double,fp_arith_inst_retired.512b_packed_single,fp_arith_inst_retired.scalar_double,fp_arith_inst_retired.scalar_single # on Xeon prior to ICL
 * URL: https://dyninst.github.io/scalable_tools_workshop/petascale2018/assets/slides/TMA%20addressing%20challenges%20in%20Icelake%20-%20Ahmad%20Yasin.pdf
 */
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>

#define MSG "Reference: How TMA Addresses Challenges in Modern Servers and Enhancements Coming in IceLake. Ahmad Yasin. Scalable Tools Workshop, Utah, July 2018."

int main(int argc, const char* argv[])
{
    uint64_t n;
    if (argc<2) {
        printf("%s: missing <num-iterations> arg!\n", argv[0]);
        exit(-1);
    }
    if (MSG) printf("%s\n", MSG ? MSG : "");
    n= atol(argv[1]);
    asm("	PAUSE");
    for (uint64_t i0=0; i0<n; i0++) {
        asm("	vfmadd132pd %ymm10,%ymm11,%ymm11");
        asm("	vfmadd132ps %ymm12,%ymm13,%ymm13");
        asm("	vaddpd %xmm0,%xmm0,%xmm0");
        asm("	vaddps %xmm1,%xmm1,%xmm1");
        asm("	vsubsd %xmm2,%xmm2,%xmm2");
        asm("	vsubss %xmm3,%xmm3,%xmm3");
    }
    asm(".align 512; Lbl_end:");

    return 0;
}
