<commit_before>#include <stdbool.h>
#include <stdint.h>

#include "../codegen/codegen.h"

#if ENABLE_PROFILER_OPSTATS

static struct {
    uint32_t opcode[0x100];
    uint32_t opcode_0f[0x100];
} opstats_buffer = {
    .opcode = { 0 },
    .opcode_0f = { 0 },
};

void gen_opstats(uint32_t instruction)
{
    bool is_0f = false;

    for(int32_t i = 0; i < 4; i++)
    {
        int32_t opcode = instruction & 0xFF;
        instruction >>= 8;

        // TODO:
        // - If instruction depends on middle bits of modrm_byte, split
        // - Split depending on memory or register variant
        // - If the instruction uses 4 or more prefixes, only the prefixes will be counted

        if(is_0f)
        {
            gen_increment_mem32((int32_t)&opstats_buffer.opcode_0f[opcode]);
            break;
        }
        else
        {
            gen_increment_mem32((int32_t)&opstats_buffer.opcode[opcode]);

            if(opcode == 0x0F)
            {
                is_0f = true;
            }
            else if(opcode == 0x26 || opcode == 0x2E || opcode == 0x36 || opcode == 0x3E ||
                    opcode == 0x64 || opcode == 0x65 || opcode == 0x66 || opcode == 0x67 ||
                    opcode == 0xF0 || opcode == 0xF2 || opcode == 0xF3)
            {
                // prefix
            }
            else
            {
                break;
            }
        }
    }
}

int32_t get_opstats_buffer(int32_t index)
{
    assert(index >= 0 && index < 0x200);

    if(index < 0x100)
    {
        return opstats_buffer.opcode[index];
    }
    else
    {
        return opstats_buffer.opcode_0f[index - 0x100];
    }
}

#else

void gen_opstats(uint32_t instruction)
{
}

int32_t get_opstats_buffer(int32_t index)
{
    assert(index >= 0 && index < 0x200);

    return 0;
}

#endif
<commit_msg>Don't define functions multiple times in pre-processor directives<commit_after>#include <stdbool.h>
#include <stdint.h>

#include "../codegen/codegen.h"

#if ENABLE_PROFILER_OPSTATS

static struct {
    uint32_t opcode[0x100];
    uint32_t opcode_0f[0x100];
} opstats_buffer = {
    .opcode = { 0 },
    .opcode_0f = { 0 },
};

#endif

void gen_opstats(uint32_t instruction)
{
#if ENABLE_PROFILER_OPSTATS
    bool is_0f = false;

    for(int32_t i = 0; i < 4; i++)
    {
        int32_t opcode = instruction & 0xFF;
        instruction >>= 8;

        // TODO:
        // - If instruction depends on middle bits of modrm_byte, split
        // - Split depending on memory or register variant
        // - If the instruction uses 4 or more prefixes, only the prefixes will be counted

        if(is_0f)
        {
            gen_increment_mem32((int32_t)&opstats_buffer.opcode_0f[opcode]);
            break;
        }
        else
        {
            gen_increment_mem32((int32_t)&opstats_buffer.opcode[opcode]);

            if(opcode == 0x0F)
            {
                is_0f = true;
            }
            else if(opcode == 0x26 || opcode == 0x2E || opcode == 0x36 || opcode == 0x3E ||
                    opcode == 0x64 || opcode == 0x65 || opcode == 0x66 || opcode == 0x67 ||
                    opcode == 0xF0 || opcode == 0xF2 || opcode == 0xF3)
            {
                // prefix
            }
            else
            {
                break;
            }
        }
    }
#endif
}

int32_t get_opstats_buffer(int32_t index)
{
    assert(index >= 0 && index < 0x200);

#if ENABLE_PROFILER_OPSTATS
    if(index < 0x100)
    {
        return opstats_buffer.opcode[index];
    }
    else
    {
        return opstats_buffer.opcode_0f[index - 0x100];
    }
#else
    return 0;
#endif
}

{'fraction_non_alphanumeric': 0.11300992282249173, 'fraction_numerical': 0.05154355016538038, 'mean_word_length': 1.7450832072617246, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4985767', 'n_tokens_mistral': 1357, 'n_tokens_neox': 1255, 'n_words': 267}