<commit_before>#!/usr/bin/env python3

import os
import sys
import json
import xmltodict

def checkFeature(cpuid, feature):
    in_eax = feature["in_eax"]
    in_ecx = feature["in_ecx"]
    eax = feature["eax"]
    ebx = feature["ebx"]
    ecx = feature["ecx"]
    edx = feature["edx"]

    if in_eax not in cpuid or in_ecx not in cpuid[in_eax]:
        return False
    else:
        leaf = cpuid[in_eax][in_ecx]
        return ((eax > 0 and leaf["eax"] & eax > 0) or
                (ebx > 0 and leaf["ebx"] & ebx > 0) or
                (ecx > 0 and leaf["ecx"] & ecx > 0) or
                (edx > 0 and leaf["edx"] & edx > 0))


def addFeature(cpuid, feature):
    if feature["in_eax"] not in cpuid:
        cpuid[feature["in_eax"]] = {}
    leaf = cpuid[feature["in_eax"]]

    if feature["in_ecx"] not in leaf:
        leaf[feature["in_ecx"]] = {"eax": 0, "ebx": 0, "ecx": 0, "edx": 0}
    leaf = leaf[feature["in_ecx"]]

    for reg in ["eax", "ebx", "ecx", "edx"]:
        leaf[reg] |= feature[reg]


def parseQemu(path, features):
    cpuData = {}
    with open(path, "r") as f:
        data, pos = json.JSONDecoder().raw_decode(f.read())

    for (prop, val) in data["return"]["model"]["props"].items():
        if val and prop in features:
            addFeature(cpuData, features[prop])

    return cpuData


def parseCPUData(path):
    cpuData = {}<commit_msg>cputest: Fix comparison in checkCPUIDFeature in cpu-cpuid.py<commit_after>#!/usr/bin/env python3

import os
import sys
import json
import xmltodict

def checkFeature(cpuid, feature):
    in_eax = feature["in_eax"]
    in_ecx = feature["in_ecx"]
    eax = feature["eax"]
    ebx = feature["ebx"]
    ecx = feature["ecx"]
    edx = feature["edx"]

    if in_eax not in cpuid or in_ecx not in cpuid[in_eax]:
        return False

    leaf = cpuid[in_eax][in_ecx]
    return ((eax > 0 and leaf["eax"] & eax == eax) or
            (ebx > 0 and leaf["ebx"] & ebx == ebx) or
            (ecx > 0 and leaf["ecx"] & ecx == ecx) or
            (edx > 0 and leaf["edx"] & edx == edx))


def addFeature(cpuid, feature):
    if feature["in_eax"] not in cpuid:
        cpuid[feature["in_eax"]] = {}
    leaf = cpuid[feature["in_eax"]]

    if feature["in_ecx"] not in leaf:
        leaf[feature["in_ecx"]] = {"eax": 0, "ebx": 0, "ecx": 0, "edx": 0}
    leaf = leaf[feature["in_ecx"]]

    for reg in ["eax", "ebx", "ecx", "edx"]:
        leaf[reg] |= feature[reg]


def parseQemu(path, features):
    cpuData = {}
    with open(path, "r") as f:
        data, pos = json.JSONDecoder().raw_decode(f.read())

    for (prop, val) in data["return"]["model"]["props"].items():
        if val and prop in features:
            addFeature(cpuData, features[prop])

    return cpuData


def parseCPUData(path):
    cpuData = {}
{'fraction_non_alphanumeric': 0.16414686825053995, 'fraction_numerical': 0.007919366450683946, 'mean_word_length': 2.740242261103634, 'pattern_counts': {'":': 8, '<': 3, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '3843346', 'n_tokens_mistral': 1072, 'n_tokens_neox': 1009, 'n_words': 273}