Slightly OT : New Language

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
Therx

Slightly OT : New Language

Post by Therx »

Why do we assume that anything like C hsa to be a high level language. Surely you could design a new C compiler with more in built functions such as loadgdt (replacing the assembly lgdt) and allow the compiler to skip the assembling step and convert it straight to an object file or flat binary. Why hasn't this been done as it incorperates the speed and low level functions of assembly with the easier programming of C. Have I missed something? Does anyone know how this would be done? Any other comments? If there are no problems would anybody else be interested in the project?

Therx
pskyboy

Re:Slightly OT : New Language

Post by pskyboy »

Why not just create an inline function called GDT with the asm code for GDT inside it?

What you are suggesting would also reduce the portability of the language and tie a particular subset to a specific platform.

Peter
Tim

Re:Slightly OT : New Language

Post by Tim »

Right, this can all be achieved by writing some inline assembly-language functions and linking to flat binary. Granted, it's not Standard C (there's that word again! :) ) but it does already exist.
Therx

Re:Slightly OT : New Language

Post by Therx »

But it would still increase speed as it would turn C from being a language to an assembler
Tim

Re:Slightly OT : New Language

Post by Tim »

Not necessarily. Some C code is faster than some assembler code, and some assembler code is faster than some C code. It's all machine code in the end.

Maybe you're thinking of a language where each source line translates directly to one instruction; something like HLA.
jamescox3k

Re:Slightly OT : New Language

Post by jamescox3k »

I hate to pick up on tecnicalitys. But C can only be AS fast as asm, not faster. Because the code produced by the compiler can be copied in asm.
Tim

Re:Slightly OT : New Language

Post by Tim »

There is slow assembly and fast assembly. For example, a quicksort routine written in C will out-perform a heapsort algorithm written in assembly. Assembly vs. C is only one small factor in overall speed; rewriting a bad routine in assembly won't make it any better.
jamescox3k

Re:Slightly OT : New Language

Post by jamescox3k »

I know that, all I was saying was you can wright assembly code that is just as fast as C's output. But you can NOT make code in C that is faster than asm.
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:Slightly OT : New Language

Post by Pype.Clicker »

jamescox3k wrote: I know that, all I was saying was you can wright assembly code that is just as fast as C's output. But you can NOT make code in C that is faster than asm.
i have to disagree with this. The compiler can make use of complex optimization rules (for a better use of the pipelines) than a human being will miss ... Some new optimization technique can be learned by disassembling compiler-generated code, but in most of the case a human just do what it guess being the fastest (provided that he want to do the best optimization when the code is written - which is not the case in 80%), while a compiler can try out several options, quantify them (in terms of bytes consumed or cycles consumed) to produce the best code for the target platform ...
Perica
Member
Member
Posts: 454
Joined: Sat Nov 25, 2006 12:50 am

Re:Slightly OT : New Language

Post by Perica »

..
Last edited by Perica on Sun Dec 03, 2006 9:07 pm, edited 1 time in total.
Curufir

Re:Slightly OT : New Language

Post by Curufir »

Yeah, but let's face it, human beings can cheat by looking at the output from a compiler and improving on it. So a skilled human can always (Unless it's a very simple program) beat the compiler simply by taking the compiler's output and adding some of the seriously complicated optimisations that can't be done in a generic fashion by the compiler.

Of course there's a very good reason why we use compilers more than assembly language now. There's also a very good reason why there aren't that many gifted assembly language programmers left. Pity.
Perica
Member
Member
Posts: 454
Joined: Sat Nov 25, 2006 12:50 am

Re:Slightly OT : New Language

Post by Perica »

..
Last edited by Perica on Sun Dec 03, 2006 9:07 pm, edited 1 time in total.
_mark

Re:Slightly OT : New Language

Post by _mark »

The answer to the second question intuitively lies in the obvious answer to the first question.

All in all though, I just see a lack of truly gifted programmers (regardless of language) in the market all together. It is pretty easy to fake your way though programming - and many people do never really understanding what they are doing. But more important, is why. A common question I ask in interviews for C++ canadat is why would you NOT declare a destructor virtual. You should see some of the answers I get - even from people with CS degrees and 5+ years C++ experience. And ask a person to write you some code in an interview sometime, and God forbit you ask them to do it on a white board.

It is funny to see how many people get offended that I might test their "said" skill set.

_mark()
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:Slightly OT : New Language

Post by Pype.Clicker »

Therx wrote: Why do we assume that anything like C hsa to be a high level language. Surely you could design a new C compiler with more in built functions such as loadgdt
Of what use would be such a language ? i mean, consider how often you use low-level functions like "lgdt" or "lsl" in a kernel ... you only have a couple of call to them ... if not a single one
And i'm not even talking about the use of such features in a system program like a file server or a device driver nor about their use in a common user program ...
Why hasn't this been done as it incorperates the speed and low level functions of assembly with the easier programming of C. Have
where do the speed of asm come from ? isn't it just a myth .... i mean, in 80486 times, it was much faster to unroll your loops and use registers ... Now with the multi-level caches of the Pentium processor, it has roughly the same cost to access a register-held variable or a L1-cached memory location (and most of the stack content for your local frame *will* be cached ... so is there really a measurable advantage of using very low-level code ?

even replacing stack by register in calling conventions don't really speed up the code nowadays ...

and virtually nothing prevents you to write your C code so that you explicitly reuse the result of intermediate computation.
If you doubt the compiler will optimize

Code: Select all

x*y + (z*x*y)/2
you still can write

Code: Select all

{int xy = x*y; xy+(z*xy)>>1;}
i mean, i've been using ASM for about 5 years until i discovered GCC. And now that i often look at the code it produces for debugging purpose, the cases where i can find more efficient code sequence are very rare ... and most of the times, the inefficiences comes from some "volatile asm" i wrote because i was a bit paranoiac ...
jamescox3k

Re:Slightly OT : New Language

Post by jamescox3k »

Yeah, but let's face it, human beings can cheat by looking at the output from a compiler and improving on it. So a skilled human can always (Unless it's a very simple program) beat the compiler simply by taking the compiler's output and adding some of the seriously complicated optimisations that can't be done in a generic fashion by the compiler.

Of course there's a very good reason why we use compilers more than assembly language now. There's also a very good reason why there aren't that many gifted assembly language programmers left. Pity.
This is the point i've been trying to get at. You can craete code in asm that is faster than C. But you can never code any thing in C that couldn't be done in asm at the same speed. Simply becuase C compiles to machine code and asm is just a slight layer above machine code.
Post Reply