Hacker News new | past | comments | ask | show | jobs | submit login
AVX Bitwise ternary logic instruction busted (arnaud-carre.github.io)
84 points by msephton 2 hours ago | hide | past | favorite | 13 comments





There is a simple way to get that immediate from expression you want to calculate. For example, if you want to calculate following expression:

    (NOT A) OR ((NOT B) XOR (C AND A))
then you simply write

    ~_MM_TERNLOG_A | (~_MM_TERNLOG_B ^ (_MM_TERNLOG_C & _MM_TERNLOG_A))
Literally the expression you want to calculate. It evaluates to immediate from _MM_TERNLOG_A/B/C constants defined in intrinsic headers, at least for gcc & clang:

    typedef enum {
      _MM_TERNLOG_A = 0xF0,
      _MM_TERNLOG_B = 0xCC,
      _MM_TERNLOG_C = 0xAA
    } _MM_TERNLOG_ENUM;
For MSVC you define them yourself.

Oh, I thought the title was saying that the instruction doesn't work properly! (The article actually just explains how it works.)

Agreed on initial interpretation. Terrible title!

Amusingly, I had a third interpretation, which is "busted" as being too strong. I realized that when the author started talking about the Amiga though that's probably not what they meant (as busted is a fairly modern gaming term, I'd be surprised to see someone as old as to be familiar with Amiga to use it. Sorry to anyone that feels personally attacked by this description :P)

Is broken not cool enough anymore?

My teenage self did not write "CRAP!" on that page of the hardware manual, but I stared at it for so long trying to figure it out.

In the end I did what pretty much everyone else did, Found the BLTCON0 for Bobs and straight copies and then pretended I newer saw the thing.

I did however get an A+ in computational logic at university years later, so maybe some of the trauma turned out to be beneficial.


About the title: "Ternary logic" usually means "logic with three truth values". But this piece covers a compiler instruction which handles all binary logic gates with three inputs.

I'll point out that this is the same way that FPGAs implement arbitrary logic functions, as lookup tables (LUTs).

Most but not all. Actel/Microsemi use a small tree of muxes and gates.

So does the 74181 ALU.

Couldn't every Boolean operation be "busted" as a lookup table?

I didn't have the official Amiga hardware manual, but instead the book "Mapping the Amiga". It said the same thing in a slight more verbose way. I don't remember which minterms I used back then but I think I managed to work things out from this book to do shadebobs, bobs, XOR 3D line drawing and other things.

The page in Mapping the Amiga: https://archive.org/details/1993-thomson-randy-rhett-anderso...


it’s fundamentally just a lookup table



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: