/*========================== begin_copyright_notice ============================
Copyright (C) 2024-2026 Intel Corporation

SPDX-License-Identifier: MIT
============================= end_copyright_notice ===========================*/

/*!
 * @file Library of High-Level Instrumentation (HLI) functions used by the simdprof_hlif tool
 */

#include "hlif_basic_defs.h"
#include "simdprof_hlif.h"


#define PER_CHANNEL

/*!
 * @brief HLI function that counts enabled channels
 * @see simdprof_hlif.h for details
 */
IGC_STACK_CALL void CountEnableChannels(uint32_t accessMask, __global SimdProfCountArgs* counter)
{
#ifndef  PER_CHANNEL
    uint64_t channelCount = (uint64_t)popcount(accessMask);
    atom_add(&(counter->out.channelCounts[0]), channelCount);
#else
    if (accessMask != 0)
    {
        for (uint32_t cIndx = 0; cIndx < 32; ++cIndx)
        {
            if ((accessMask & (0x1 << cIndx)) != 0)
            {
                atomic_inc(&(counter->out.channelCounts[cIndx]));
            }
        }
    }
#endif
}

/*!
 * @brief HLI function that counts enabled channels
 * @see simdprof_hlif.h for details
 */
IGC_STACK_CALL void CountEnableChannelsForSend(uint32_t accessMask, __global SimdProfCountArgs* counter)
{
    if (accessMask != 0)
    {
        atomic_inc(&(counter->out.channelCounts[0]));
    }
}
