Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

The C language doesn't, and has never, said anything about what the assembled code should look like. If you want performance, you have to use a good compiler. That's true with any language.

You're right, C11 doesn't have a 128-bit integer type; that should be remedied. Fortunately all major compilers (GCC, LLVM, VC++, and ICC) provide one.

Carry: "if (x + y < x)" compiles to code that uses the carry flag.

Overflow: "if ((int32_t) (x + y) < 0)" compiles to code that uses the overflow flag.

And the best part is, code written like this is portable to architectures such as TileGX that don't have status flags.



> Carry: "if (x + y < x)" compiles to code that uses the carry flag.

If x and y are signed, you're relying on UB, which the compiler might optimize out.

> "if ((int32_t) (x + y) < 0)" compiles to code that uses the overflow flag.

Again, which type are x and y? If signed, this code is UB. If unsigned, then the result of conversion to int32 may not fit into int32, in which case the result is implementation-defined, or and implementation-defined signal is raised.

Portable? Right.




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

Search: