#include "pnf.h" #include u64 pdnf_compute (u16 f) { u64 pdnf = 0; u8 xyzw = 0b1111; while (f) { xyzw -= CTZ (f); f >>= CTZ (f); pdnf <<= 4; pdnf |= xyzw; xyzw -= 1; f >>= 1; } return pdnf; } void pdnf_print (u64 pdnf, u8 numones) { for (u8 i = numones; i; --i) { printf ("%cx && %cy && %cz && %cw%s\n", pdnf & 1 << 3 ? ' ' : '!', pdnf & 1 << 2 ? ' ' : '!', pdnf & 1 << 1 ? ' ' : '!', pdnf & 1 << 0 ? ' ' : '!', i > 1 ? " ||" : ""); pdnf >>= 4; } } u64 pcnf_compute (u16 f) { u64 pcnf = 0; u8 xyzw = 0b1111; f = ~f; while (f) { xyzw -= CTZ (f); f >>= CTZ (f); pcnf <<= 4; pcnf |= xyzw; xyzw -= 1; f >>= 1; } return ~pcnf; } void pcnf_print (u64 pcnf, u8 numzeros) { for (u8 i = numzeros; i; --i) { printf ("(%cx || %cy || %cz || %cw)%s\n", pcnf & 1 << 3 ? ' ' : '!', pcnf & 1 << 2 ? ' ' : '!', pcnf & 1 << 1 ? ' ' : '!', pcnf & 1 << 0 ? ' ' : '!', i > 1 ? " &&" : ""); pcnf >>= 4; } } bool pdnf_eval (u64 pdnf, u8 numones, u8 xyzw) { for (u8 i = 0; i < numones; ++i) { u8 mask = pdnf & (1 << 4) - 1; if (xyzw == mask) return true; pdnf >>= 4; } return false; }