Stories
Slash Boxes
Comments

Dev.SN ♥ developers

posted by Cactus on Saturday March 08 2014, @03:30AM   Printer-friendly
from the don't-tell-me-upgrade-PCs dept.

Subsentient writes:

"I'm a C programmer and Linux enthusiast. For some time, I've had it on my agenda to build the new version of my i586/Pentium 1 compatible distro, since I have a lot of machines that aren't i686 that are still pretty useful.

Let me tell you, since I started working on this, I've been in hell these last few days! The Pentium Pro was the first chip to support CMOV (Conditional move), and although that was many years ago, lots of chips were still manufactured that didn't support this (or had it broken), including many semi-modern VIA chips, and the old AMD K6.

Just about every package that has to deal with multimedia has lots of inline assembler, and most of it contains CMOV. Most packages let you disable it, either with a switch like ./configure --disable-asm or by tricking it into thinking your chip doesn't support it, but some of them (like MPlayer, libvpx/vp9) do NOT. This means, that although my machines are otherwise full blown, good, honest x86-32 chips, I cannot use that software at all, because it always builds in bad instructions, thanks to these huge amounts of inline assembly!

Of course, then there's the fact that these packages, that could otherwise possibly build and work on all types of chips, are now limited to what's usually the ARM/PPC/x86 triumvirate (sorry, no SPARC Linux!), and the small issue that inline assembly is not actually supported by the C standard.

Is assembly worth it for the handicaps and trouble that it brings? Personally I am a language lawyer/standard Nazi, so inline ASM doesn't sit well with me for additional reasons."

 
This discussion has been archived. No new comments can be posted.
Display Options Breakthrough Mark All as Read Mark All as Unread
The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
  • (Score: 5, Funny) by jt on Saturday March 08 2014, @05:17AM

    by jt (2890) on Saturday March 08 2014, @05:17AM (#13136)

    C _is_ a nice, portable macro assembly language :)

    Starting Score:    1  point
    Moderation   +4  
       Interesting=1, Informative=1, Funny=2, Total=4
    Extra 'Funny' Modifier   0  
    Karma-Bonus Modifier   +1  

    Total Score:   5  
  • (Score: 3, Insightful) by neagix on Saturday March 08 2014, @05:47AM

    by neagix (25) on Saturday March 08 2014, @05:47AM (#13139)

    Sure, but is it maintainable to extend C with the CPU-specific trove of shiny optimized instructions for very specific tasks?

    But yeah, I get it's a flaming discussion..

    • (Score: 2) by mojo chan on Saturday March 08 2014, @11:07AM

      by mojo chan (266) on Saturday March 08 2014, @11:07AM (#13200)

      It's easy to maintain such a collection, just add them to the compiler's optimizer. Your compiler is open source, right? ;-)

      --
      const int one = 65536; (Silvermoon, Texture.cs)
    • (Score: 1, Funny) by Anonymous Coward on Saturday March 08 2014, @02:30PM

      by Anonymous Coward on Saturday March 08 2014, @02:30PM (#13259)

      > Sure, but is it maintainable to extend C with the CPU-specific trove of shiny optimized instructions for very specific tasks?

      Yes, we call those "libraries." :)

    • (Score: 2) by TheRaven on Sunday March 09 2014, @06:14AM

      by TheRaven (270) on Sunday March 09 2014, @06:14AM (#13519) Journal
      That's what most compilers do. Very often, the SSE or equivalent instructions are exposed as intrinsics. You use them as if they were functions from C, but they will use the compiler's register allocator, will typically be expanded to a single instruction, can be mixed with other constructs, and have known semantics and so can be reordered based on the compiler's knowledge of the target pipeline (or to reduce register pressure elsewhere). When clang didn't support some inline assembly from a package, we tried replacing it with some C using compiler intrinsics and found that the result ran faster, with both gcc and clang, than the original.
      --
      sudo mod me up
      • (Score: 2) by neagix on Sunday March 09 2014, @08:27AM

        by neagix (25) on Sunday March 09 2014, @08:27AM (#13547)

        Although it's a nice anecdotal example, since my OP I was referring to all cases where you can't ignore assembly for extra juice or features, but still you would prefer a graceful fallback to the #ifdef jungle.

        Please don't let me open the "bestiary", we would fight on each case with anecdotes, but I am talking about emulation (also dynamic recompilation), GPU/CPU integration quirks, codecs, and architecture-specific gotchas for embedded devices, more in general where - as I said - you want the best available OR a graceful fallback, without having to lay boilerplates.

        I know libraries is the most obvious answer, but not a perfect solution (higher cost, less elegant because of very tiny functional payload). Another way could be CMAKE sorcerery, but CMAKE is far high in the foodchain to not strip the power of being in contact with the machine. In a perfect standardized world [xkcd.com] we wouldn't have these problems in first place (discussing this is OT).
        So I was wondering if there could be a "framework-like" approach/solution to the problem (maybe not). The premise to discuss is if there is enough redundancy to find common patterns/development shortcuts.

        I know the riddle, "let's make a factory to make factories of hammers" and so on, but I would consider such idea IIF (if and only if) it doesn't clash with C. It's quite a theoretical discussion, but basically nothing new at thinking to put a portability patch on the mess vendors do with hardware we buy (just look at the hard work in Linux kernel over the years).

  • (Score: 1, Informative) by Anonymous Coward on Saturday March 08 2014, @03:00PM

    by Anonymous Coward on Saturday March 08 2014, @03:00PM (#13267)

    > C _is_ a nice, portable macro assembly language :)

    I know this is an old joke, but it still bugs me when I hear it. Coding in C is nothing like coding in assembly. Assembly coding is about more than just fast, compact code.

    • (Score: 1) by HiThere on Saturday March 08 2014, @03:59PM

      by HiThere (866) on Saturday March 08 2014, @03:59PM (#13290)

      FWIW, it's not entirely a joke. I've seen an implementation of C that was nearly complete done in M6800 (or possibly M68000) assembly language. It was in an old issue of Byte. And it was nearly as complete, though possibly not as fast, as Lifeboat C, which was then a commercial C (subset) for the i8080 or z80.

      That said, I agree that the thought processes used in assembler coding are different from those used in C coding...but they CAN be made to be the same.

      --
      Put not your faith in princes.
    • (Score: 2) by jt on Saturday March 08 2014, @05:29PM

      by jt (2890) on Saturday March 08 2014, @05:29PM (#13310)

      Having spent years writing C and various assembly languages, as well as higher level stuff more recently, it is only partially a joke. Much of the C language design makes sense when you consider the transformation of language features into machine code structures and typical general lurpose CPU instruction sets.