Announcement

Collapse
No announcement yet.

Is Assembly Still Relevant To Most Linux Software?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • erendorn
    replied
    Originally posted by frign View Post
    Given the big flexibility, every C++-programmer has his own coding style. There is no definite way of expressing something in C; you have a big freedom of choice.
    The reason I guess why C is favored in free software projects is the fact, that there are no big gaps when it comes to designing the software.
    I agree with that point on coding style. You can do OOP, template base, procedural, functional, even event based programming in C++. It's cool, but if you do that in the same project, it will bite you.. C++ may need more discipline, the kind you find more easily in corporate environment.
    Also true is what ciplogic said on binary interface (C defines it, but C++ is implementation dependent).

    But about being faster or slower, I think it boils down to the following:
    - If you misuse C++ features, it will be slower in C++
    - If you try to write yourself in C the features of C++, it will be faster in C++



    Also, source on the the comparison between gcc-c and gcc-cxx on the C and C++ subset.

    Leave a comment:


  • frign
    replied
    Definitely a hard topic

    Originally posted by ciplogic View Post
    Thanks for fixing my typo, I will double check in future. I use Wikipedia as it states properly most of the times.

    As C++ is the faster than C as you can use the C subset and have the same (baseline performance), but also other constructs (I'm talking here about templates):
    A Google engineer perspective: http://lingpipe-blog.com/2011/07/01/why-is-c-so-fast/
    This guy also seemed to agree that C++ is faster because it can do better inlining: http://radiospiel.org/sorting-in-c-3...faster-than-c/

    I'm still curios of your classes differences from C++ and C struct (a statement you made )
    Ok, starting with structs and classes: The main difference is that classes in C++ are way more complex than structs in C. This is not a bad thing right away. You can define constructors, destructors and the like, be able to to use templates for flexible typecasting or even overload operators.
    The main issue here is definitely maintainability: You can find many opinions/tests/rants on the Internet claiming one of the languages to be better/faster/stronger/... .
    While on the technical perspective C++ is way more flexible, it remains to be discussed if it is faster. Let's imagine both languages to be equally as fast:

    Given the big flexibility, every C++-programmer has his own coding style. There is no definite way of expressing something in C; you have a big freedom of choice.
    The reason I guess why C is favored in free software projects is the fact, that there are no big gaps when it comes to designing the software.
    10-20 years from now, another programmer will still be able to understand the code, and quite frankly, judging from my own experience, porting C++-code is much more of a pain (especially in Game engines), because of very frequent bad and complex design decisions.

    Nevertheless, you can write great C++ too and horribly design a C program at the same time! It's all about the person writing the code and how the code is structured.
    Especially today's architectures are hard to really "measure". Everything is parallelised and highly dependent on current memory-IO and other small factors. Neither the binary size nor the number of cycles give definite answers about the speed and efficiency of a program. This may be a mystery never to be solved with today's possibilities!

    Leave a comment:


  • ciplogic
    replied
    Originally posted by frign View Post
    If you look it that way, most developers program in C#. It's not about the technical perspective, why C-programs are faster, it's about how you design your software.
    I see you like Wikipedia very much, but I know what non sequitur means (not non sequitor).

    So, it's still a religious question and I guess we'll never rest in a consens.
    Thanks for fixing my typo, I will double check in future. I use Wikipedia as it states properly most of the times.

    As C++ is the faster than C as you can use the C subset and have the same (baseline performance), but also other constructs (I'm talking here about templates):
    A Google engineer perspective: http://lingpipe-blog.com/2011/07/01/why-is-c-so-fast/
    This guy also seemed to agree that C++ is faster because it can do better inlining: http://radiospiel.org/sorting-in-c-3...faster-than-c/

    I'm still curios of your classes differences from C++ and C struct (a statement you made )

    Leave a comment:


  • frign
    replied
    Religion

    Originally posted by ciplogic View Post
    In C++ specification, struct is a class with permissions set to public by default!
    Code:
    struct MyStruct{} ;
    is the same with:
    Code:
    class MyStruct{ public: } ;
    If you use classes/structs with virtual, you will have a virtual table pointer, but no one requires you to do so.

    If you talk about some things that are more verbose in C++, are the C++ name mangling to solve conflicts (because of function overloading) but has no final memory runtime issues as far as I'm aware. If you don't want to have this, you can write all C++ code and export functions with
    Code:
    extern "C" {
    (...)
    };

    This is a non-sequitor (http://en.wikipedia.org/wiki/Non_sequitur_%28logic%29 ): most developers may use C for a lot of reasons, and maybe none is about performance. (mistake explained in detail: http://en.wikipedia.org/wiki/Affirming_the_consequent )

    A link that states that "C faster than C++ is a myth": http://discuss.fogcreek.com/joelonso...ow&ixPost=7461

    In fact even people that are using assembly don't use it always for performance, just 30% of them would do (I'm using your numbers). GCC rewrite in C++ proved to some extend this as I've never heard that compile times grew as GCC is C++ based now. Or LLVM (which from ground-up was C++ based) has a strength of faster compilation than GCC. Cairo (C vectorial graphics library) was at least some years ago slower than the C++ counterpart in Qt: http://zrusin.blogspot.com/2006/10/benchmarks.html

    Where you use the biggest number most developers? Tiobe maybe? ( http://www.tiobe.com/index.php/conte...pci/index.html ). If it is so, why the second most developers pick Java? Is also performance? If you looked to the statistics, Dynamically Typed Languages 29.2% (more than C users which are around 18%) are using a dynamic language (which has some performance limitations/implications).

    The biggest reason I think that C is still powerful is related with interoperability: C is a target language for any language is interoperable with. Java, C#, JavaScript or any other language in Tiobe top 20 (including assembly) with notable exceptions of Transact-SQL and PL-SQL are C aware (sometimes, like in Lua you have to set some hook methods, but is easy to do so). Combined with his long history and that the language is fairly simple to start with (which means in turn that is taught in high-schools and universities) I think is a better reason why people are using C.

    There are transitions that are slower from C to C++, for example Quake3 was fairly light, when Doom 3 was heavy in resources, but was mostly because they were using an interpreter in the back, is not the fault of C++ (I'm not giving excuses though). Rage game engine was light (compared with their competition of end 2011, like Crysis 2) and both were written in C++. Many parts of fast parts of Windows (DirectX comes first to mind) are C++.
    If you look it that way, most developers program in C#. It's not about the technical perspective, why C-programs are faster, it's about how you design your software.
    I see you like Wikipedia very much, but I know what non sequitur means (not non sequitor).

    So, it's still a religious question and I guess we'll never rest in a consens.

    Leave a comment:


  • Obscene_CNN
    replied
    Here is a quick small asm hack I made to the radeon r600_shader.c file in mesa. Note it is only two instructions. It sure beats doing a loop with a test in the middle. lets see if you can get a c compiler to beat this .

    static int tgsi_last_instruction(unsigned writemask)
    {
    #if 1
    /*AND input with 0xF to confine the search to the four least significant bits */
    /* use BSR (Bit Scan Reverse) to find the most significant bit position 0 through 3 */
    /* Note: BSR instruction uses source as its destination to return zero if zero
    is its input. Officially documented as an undefined output for zero input but
    behaviour of the BSR instruction just doesn't change the destination register
    contents in this case */

    __asm (
    "and $0x0F, %0\n\t"
    "bsr %0, %0 \n\t"
    : "=&r" (writemask)
    : "0" (writemask)
    : "cc");

    return writemask;
    #else
    int i, lasti = 0;

    for (i = 0; i < 4; i++) {
    if (writemask & (1 << i)) {
    lasti = i;
    }
    }

    return lasti;
    #endif
    }

    Leave a comment:


  • ciplogic
    replied
    Originally posted by frign View Post
    Btw: I didn't write anything about C++ being better or worse, I just said there were big differences in classes and structs, which in my opinion lead to worse memory management. Don't smoke so much crack, you are really tempered!
    In C++ specification, struct is a class with permissions set to public by default!
    Code:
    struct MyStruct{} ;
    is the same with:
    Code:
    class MyStruct{ public: } ;
    If you use classes/structs with virtual, you will have a virtual table pointer, but no one requires you to do so.

    If you talk about some things that are more verbose in C++, are the C++ name mangling to solve conflicts (because of function overloading) but has no final memory runtime issues as far as I'm aware. If you don't want to have this, you can write all C++ code and export functions with
    Code:
    extern "C" {
    (...)
    };
    Originally posted by frign View Post
    When I was fully wrong and C++ the King of performance, why is it that most developers still use C instead of C++?
    This is a non-sequitor (http://en.wikipedia.org/wiki/Non_sequitur_%28logic%29 ): most developers may use C for a lot of reasons, and maybe none is about performance. (mistake explained in detail: http://en.wikipedia.org/wiki/Affirming_the_consequent )

    A link that states that "C faster than C++ is a myth": http://discuss.fogcreek.com/joelonso...ow&ixPost=7461

    In fact even people that are using assembly don't use it always for performance, just 30% of them would do (I'm using your numbers). GCC rewrite in C++ proved to some extend this as I've never heard that compile times grew as GCC is C++ based now. Or LLVM (which from ground-up was C++ based) has a strength of faster compilation than GCC. Cairo (C vectorial graphics library) was at least some years ago slower than the C++ counterpart in Qt: http://zrusin.blogspot.com/2006/10/benchmarks.html

    Where you use the biggest number most developers? Tiobe maybe? ( http://www.tiobe.com/index.php/conte...pci/index.html ). If it is so, why the second most developers pick Java? Is also performance? If you looked to the statistics, Dynamically Typed Languages 29.2% (more than C users which are around 18%) are using a dynamic language (which has some performance limitations/implications).

    The biggest reason I think that C is still powerful is related with interoperability: C is a target language for any language is interoperable with. Java, C#, JavaScript or any other language in Tiobe top 20 (including assembly) with notable exceptions of Transact-SQL and PL-SQL are C aware (sometimes, like in Lua you have to set some hook methods, but is easy to do so). Combined with his long history and that the language is fairly simple to start with (which means in turn that is taught in high-schools and universities) I think is a better reason why people are using C.

    There are transitions that are slower from C to C++, for example Quake3 was fairly light, when Doom 3 was heavy in resources, but was mostly because they were using an interpreter in the back, is not the fault of C++ (I'm not giving excuses though). Rage game engine was light (compared with their competition of end 2011, like Crysis 2) and both were written in C++. Many parts of fast parts of Windows (DirectX comes first to mind) are C++.
    Last edited by ciplogic; 10 April 2013, 01:46 PM.

    Leave a comment:


  • frign
    replied
    Nope

    Originally posted by ciplogic View Post
    You're fully wrong! If you don't write virtual you have the same memory footprint. In fact C++ is a stricter than C, so is less error prone. Like:
    int* array = malloc(sizeof(char)*length); //will give error in C++ not in C so is less likely you will make mistakes in C++.
    Also as you can override new operation, you can use the same C routines (or a custom memory allocator) if you want the same perf caracteristics.

    In the past C++ would do many "invisible copying" (like users copying std::vectors everywhere), and people not trained with C++ or people that would not use Ref and Const Ref, would get worse performance than using C, but this is not because C++ was badly designed, but badly used.

    Still C++ is really the king performance wise as it extensively uses inlining in templates, the "invisible copying" is solved many times by just using constant references or C++ 11 added "copy semantics" so your compiler will remove some copying by itself (with no extra assembly).

    At last I want to congratulate him of using Qt, is really a great framework, also Qml/JS side.
    When I was fully wrong and C++ the King of performance, why is it that most developers still use C instead of C++?

    Btw: I didn't write anything about C++ being better or worse, I just said there were big differences in classes and structs, which in my opinion lead to worse memory management. Don't smoke so much crack, you are really tempered!

    And: I don't see any problem with the example you gave.
    EDIT: Normally you would use n-times the size of an integer, and not a char. But this is a design-issue and might also be voluntary.
    Last edited by frign; 10 April 2013, 01:05 PM.

    Leave a comment:


  • ciplogic
    replied
    Originally posted by frign View Post
    Thanks! Nice to hear other opinions.

    The test you wrote about doesn't make sense, though, because GCC handles C as C++, so, when you compare two identical programs, you will get identical results.
    The differences are very small, but we can't talk of the C++-classes as being the same as structs in C. There are definitely big differences between them.
    You're fully wrong! If you don't write virtual you have the same memory footprint. In fact C++ is a stricter than C, so is less error prone. Like:
    int* array = malloc(sizeof(char)*length); //will give error in C++ not in C so is less likely you will make mistakes in C++.
    Also as you can override new operation, you can use the same C routines (or a custom memory allocator) if you want the same perf caracteristics.

    In the past C++ would do many "invisible copying" (like users copying std::vectors everywhere), and people not trained with C++ or people that would not use Ref and Const Ref, would get worse performance than using C, but this is not because C++ was badly designed, but badly used.

    Still C++ is really the king performance wise as it extensively uses inlining in templates, the "invisible copying" is solved many times by just using constant references or C++ 11 added "copy semantics" so your compiler will remove some copying by itself (with no extra assembly).

    At last I want to congratulate him of using Qt, is really a great framework, also Qml/JS side.

    Leave a comment:


  • frign
    replied
    Thanks

    Originally posted by erendorn View Post
    I thought that a C++ class was the same a a C struct, and as such didn't use more memory than C, and probably not much extra memory anyway (just a one time definition in the binary)?
    Recently, there was a test using GCC compiled in C and GCC compiled in C++, and the speed of the two versions were compared (using compile time of the linux kernel), with no observable difference.
    This proved that C++ in itself is not slower than C. Now, you can argue that some C++ specific constructs can be "slower" (often named are virtual functions and exceptions), but implementing these by hand in C would be at least as slow (and probably much slower). If you need fast polymorphism, you can use templates, which are 100x better than macro or copy paste.

    I personally like C++ a lot as a low but not-too-low language, but it's also mostly because I'm familiar with it.
    I'm never opposed using whatever language is best to the task at hand (except VBA. VBA sucks.). I'd be tasked on RT routines for embedded systems, I'd use C+assembly, but when writing GUI glue, I'm loving using JS/QML for Qt Quick. Languages are tools, not religion (plus, they won't blame you when flirt with some other ones)
    Thanks! Nice to hear other opinions.

    The test you wrote about doesn't make sense, though, because GCC handles C as C++, so, when you compare two identical programs, you will get identical results.
    The differences are very small, but we can't talk of the C++-classes as being the same as structs in C. There are definitely big differences between them.

    Leave a comment:


  • erendorn
    replied
    Originally posted by frign View Post
    Sadly, today's languages encourage to pile up a lot of stuff in memory. C++-classes are one example for an insufficient concept. Even though the compiler does a great job on keeping the code good enough, doing the same in C might have it's advantages (also in regards to inline-assembly). With no doubt, this is a religious question .

    So, it was nice discussing with you! Please let me know which language you prefer.
    I thought that a C++ class was the same a a C struct, and as such didn't use more memory than C, and probably not much extra memory anyway (just a one time definition in the binary)?
    Recently, there was a test using GCC compiled in C and GCC compiled in C++, and the speed of the two versions were compared (using compile time of the linux kernel), with no observable difference.
    This proved that C++ in itself is not slower than C. Now, you can argue that some C++ specific constructs can be "slower" (often named are virtual functions and exceptions), but implementing these by hand in C would be at least as slow (and probably much slower). If you need fast polymorphism, you can use templates, which are 100x better than macro or copy paste.

    I personally like C++ a lot as a low but not-too-low language, but it's also mostly because I'm familiar with it.
    I'm never opposed using whatever language is best to the task at hand (except VBA. VBA sucks.). I'd be tasked on RT routines for embedded systems, I'd use C+assembly, but when writing GUI glue, I'm loving using JS/QML for Qt Quick. Languages are tools, not religion (plus, they won't blame you when flirt with some other ones)

    Leave a comment:

Working...
X