herumi / xbyak

A JIT assembler for x86/x64 architectures supporting MMX, SSE (1-4), AVX (1-2, 512), FPU, APX, and AVX10.2
BSD 3-Clause "New" or "Revised" License
2.05k stars 278 forks source link

Cpu::has() check is inconsistent #148

Closed nivas-x86 closed 2 years ago

nivas-x86 commented 2 years ago

The Cpu::has() parallel check seems to broken.

Below code on Haswell machine prints "WRONG" . (The commit https://github.com/herumi/xbyak/commit/3ea8e45d33bbe22b4130d1bf01edc91b8aadf7fa prints "OK")

#include <stdio.h>
#include "xbyak/xbyak_util.h"

using namespace Xbyak::util;

int main() {
    Cpu hsw;
    if ((hsw.has(Cpu::tAVX2) && hsw.has(Cpu::tAVX512F)) == hsw.has(Cpu::tAVX2 | Cpu::tAVX512F)) {
        printf("OK\n");
        return 0;
    } else {
        printf("WRONG\n");
        return -1;
    }
}
herumi commented 2 years ago

Sorry for the incompleteness. Is this patch okay?

nivas-x86 commented 2 years ago

No problem. Thank you for the quick fix, it works fine now.

herumi commented 2 years ago

Thank you for the quick check. I've pushed it into the master branch.