code snippet

J

jacob navia

A compiler must be correct for ALL possible programs that use a given
construct.

An assembly language programmer must be correct only for THIS program.

An assembly language program can pass values in registers beyond normal
calling conventions, etc.

Besides not all machine instructions map into high level constructs,
what most high level language programmers do not even know.
 
K

Keith Thompson

Rui Maciel said:
As a somewhat related oddity, here is a talk by Guy Steele himself[1]. In
it, he discusses some techniques he employed to write a couple of programs,
along with some optimization tricks he employed. Among those, he refers in
some parts how he reduced the program size by using the value of some
opcodes as constants. I doubt that today's compiler writers implement these
sort of tricks. This means that mr Steele's code is better than the
equivalent code which might be generated by a compiler. But the thing is,
not everyone is as proficient at it as mr Steele, or even close to it, which
brings us back to the assertion I've made.

[1] http://www.infoq.com/presentations/Thinking-Parallel-Programming

It would be better in the sense that it's *faster*. It would
probably not be very maintainable (by anyone other than Dr. Steele).
Imagine modifying the code when the value of one of those constants
needs to change.

A great benefit of automatically generated code, such as the assembly
or machine code generated by a compiler, is that it doesn't *have*
to be maintained. All the work that went into optimizing it can
be thrown away and re-done, perhaps very differently, in a matter
of moments.
 
8

88888 Dihedral

If I am paid well to help a commercial team to beat other teams, then
I have to hand optimize assembly code to get my rewards.

But if I am writing on some free projects or low paid projects,
I don't have to work too hard at that situation unless I am working to be
famous.
 
S

Seebs

If I am paid well to help a commercial team to beat other teams, then
I have to hand optimize assembly code to get my rewards.

If you are hand-optimizing assembly, you will usually lose to people who
spent their time on better payoffs. Cases where it's worth the trouble are
rare -- and probably rarer than cases where it's been done.

Keep in mind, it's not enough to beat the compiler. You have to beat the
compiler by enough that it's a better use of your time than adding features,
debugging, or improving algorithms.
But if I am writing on some free projects or low paid projects,
I don't have to work too hard at that situation unless I am working to be
famous.

Or unless you do everything you do to the best of your ability.

-s
 
R

Rui Maciel

88888 said:
If I am paid well to help a commercial team to beat other teams, then
I have to hand optimize assembly code to get my rewards.

But if I am writing on some free projects or low paid projects,
I don't have to work too hard at that situation unless I am working to be
famous.

Are you aware of any commercial project, developed recently, where the
project manager thought it would be a good idea to pay a dedicated team to
rewrite in assembly any specific part of their code?


Rui Maciel
 
8

88888 Dihedral

Rui Macielæ–¼ 2011å¹´12月27日星期二UTC+8上åˆ5時53分00秒寫é“:
Are you aware of any commercial project, developed recently, where the
project manager thought it would be a good idea to pay a dedicated team to
rewrite in assembly any specific part of their code?

Those working on operating systems and compilers mix assembly and c very
common. But a small portion in assembly is different from everything in
assembly.
 
K

Keith Thompson

88888 Dihedral said:
Those working on operating systems and compilers mix assembly and c very
common. But a small portion in assembly is different from everything in
assembly.

Operating systems, yes. An OS has to do some things that are
at a lower level than a language like C can support directly.
But why would the code for a compiler have a particular need for
assembly language?

The gcc source tree has a few *.s and *.S files, but few if any of
them are part of the implementation of the compiler itself.
 
8

88888 Dihedral

Keith Thompsonæ–¼ 2011å¹´12月27日星期二UTC+8上åˆ10時11分15秒寫é“:
Operating systems, yes. An OS has to do some things that are
at a lower level than a language like C can support directly.
But why would the code for a compiler have a particular need for
assembly language?

The gcc source tree has a few *.s and *.S files, but few if any of
them are part of the implementation of the compiler itself.

--
Keith Thompson (The_Other_Keith) (e-mail address removed) <http://www.ghoti.net/~kst>
Will write code for food.
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"

OK, the number of cores in a CPU and the L1 and L2 characteristics
are all hardware dependent. The compiler can get the information from the OS.

Most of the compiler part can be programmed in high level languages.

But one has to debug the compiler in development, then one still has
to understand the assembly instructions.
 
N

Nick Keighley

did you mean "would you consider it sensible to convert 5 to 10 lines
of C into assembly?". It would rather depend on the lines of C. How
fast does it need to be? Is it fast enough? Would recoding it in
assembler make any difference (likely not)? I think it very unlikely
that the vast majority of C code would benefit in anyway from this.

It's just a way to waste time and degrades the quality of your code.
i have just one argument against yours:
all code going out from one assembly programmer is from 10
to 1000 times better the one not know assembly

cite. Produce figures. You are mistaken.
this is only what i think

so you just made that up? All assembler programs can run faster than
any Olympic athelete. I just think this is so, I have never seen an
assembler programmer run anywhere.
one can not be sure of all and has to syntesis his results

please repost in a known language

<snip>
 
N

Nick Keighley

"Nick Keighley" <[email protected]> ha scritto nel messaggio

did you mean "would you consider it sensible to convert 5 to 10 lines
of C into assembly?". It would rather depend on the lines of C. How
fast does it need to be? Is it fast enough? Would recoding it in
assembler make any difference (likely not)? I think it very unlikely
that the vast majority of C code would benefit in anyway from this.

It's just a way to waste time and degrades the quality of your code.



cite. Produce figures. You are mistaken.

#i'm right
#for example this:
#i don't had the time full test it,
#for example one has to try that for double , long double etc
#you can write that in C or in assembly, your bsearch() can be faster
#but my error detectrion is better of yours bsearch()

does it run 1000 times faster than a C version? What errors do you
detect. I can't be bothered to read your assembler.

I'll give you that you can actually write assembler.
; would be like the C *library* bserach() function, with the only
; difference return (u8*)-1 for error
; return (u8*)-1 error, 0 not found, address of the found element in array
; if return 0 [not found]
;    in ecx return the address element of the array < than key if exist
;    else ecx=0
;    in edx return the address element of the array > than key if exist
;    else edx=0
;u8*  __stdcall
;binSearchR(u8* InPKey, u8* InBase,
;           u32 nElmBase,  u32 SizeElmBase, i32  cmp(const u8* elm1, const u8*
elm2) );
this is only what i think

so you just made that up? All assembler programs can run faster than
any Olympic athelete. I just think this is so, I have never seen an
assembler programmer run anywhere.

I should have picked a better metephor. I was making the point that if
you make things up you can make anything up. Assemler programs shit
diamonds. this is only what i think.

<snip.
please repost in a known language

#it is pure NASM x86 pentium 32 bits

no I meant in a natural languge (english, russian etc.) because the
bit I quoted makes no sense.
 
N

Nick Keighley

io_x said:
#i'm right
#for example this:
#i don't had the time full test it,
#for example one has to try that for double , long double etc
#you can write that in C or in assembly, your bsearch() can be faster
#but my error detectrion is better of yours bsearch()

i test it against double [64 bit double] too and for luck it send to stdout
the right output [afther some debug and some time to search the error
in the compare functions...]

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define d64 double
#define u32 unsigned
#define i32 int

as I've noted before I don't read code like this

<snip horrid C>

so what does your program do? Is it a binary search written in (what
you call) C?
--------------------------------
1, 2, 5, 7, 8, 8, 9, 13, 20
1.000000, 2.000000, 5.000000, 7.000000, 8.000000, 8.000000, 9.000000, 13.0000

For 0 w = 0- ww=0012FF50 find=1+
For 1 r=0012FF50 find=1
For 2 r=0012FF54 find=2

<snip more of same>

and what does it mean? Have you shown your assembler is 1000 times
faster than your C? Or 1000 times faster than my C?
 
8

88888 Dihedral

Seebsæ–¼ 2011å¹´12月23日星期五UTC+8上åˆ5時57分09秒寫é“:
Quite possibly, but it also has more overhead, and for some sizes of lists,
computing the hash is more expensive than the entire search anyway.
Implementations of the hash function and the hash table can use more memory and should avoid some slow operations.


I wrote a version that searches two items at a call to a variant of
a binary search algorithm.

This could speed up the search per item slightly.
 
N

Nick Keighley

"Nick Keighley" <[email protected]> ha scritto nel messaggio
"io_x" <[email protected]> ha scritto nel
messaggionews:[email protected]...
i test it against double [64 bit double] too and for luck it send to stdout
the right output [afther some debug and some time to search the error
in the compare functions...]
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define d64 double
#define u32 unsigned
#define i32 int

as I've noted before I don't read code like this

actually I meant code like /this/

#define R return
#define P printf
#define F for
<snip horrid C>
#it is the way C has to behavie

no, it's your bizzare way of coding. Write in a sensible style and
I'll read it.
so what does your program do? Is it a binary search written in (what
you call) C?
hello?



<snip more of same>

and what does it mean? Have you shown your assembler is 1000 times
faster than your C? Or 1000 times faster than my C?

#it is 10 times safer than your C version

well since I havn't shown you any code I don't know how you can tell
this. How do you measure safety? In what sense is your code 10 times
"safer" tahn typical C.

You claimed you could write asssmbler that was 10 to 1000 times faster
than typical C. I think you were mistaken (I thought of a ruder word)

#asm safer... people would laught on that

so you've dropped the faster claim?

#a binsearch algo something as O(log(n)) can not be the bottle neck
#right?-

could be if you had to search a lot of data
 
N

Nick Keighley

"Nick Keighley" <[email protected]> ha scritto nel messaggio

no I meant in a natural languge (english, russian etc.) because the
bit I quoted makes no sense.

#it is possible because i'm lazy on the speak languages
#all you have a good 2012 year...

and the same to you
 
W

Walter Banks

BartC said:
But if you're working in automobile design and production, this is just the
sort of thing you might do. Then you end with a version with a very slightly
better fuel consumption, but which is significant over a million units and
thousands of journeys each.

I have worked in automotive for close to a couple decades and it is the type
of thing that this industry would not do for a couple reasons.

First there is very few things that can be done in asm that cannot be done in C.
Very few as in some C compilers actually check that everything that can be
done in asm can be done in C.

Engine control code in current automotive applications has not been written
is not in a timing sensitive code eliminating that as an incentive.

As several others have said support of embedded asm is just too unreliable
and unneeded in the applications now.

I am willing to bet that in the compilers we have developed I can write anything
in C that can be written in asm in equal or less code space with equal or less
execution time.

Regards,


Walter..
 
K

Kaz Kylheku

I have worked in automotive for close to a couple decades and it is the type
of thing that this industry would not do for a couple reasons.

First there is very few things that can be done in asm that cannot be done in C.

However, those things are of high importance. Just maybe not to some C
programmers.

Assembly gives you the access to the machine at a level that allows you to
implement things like accurate stack unwinding, exception handling and
completely precise garbage collection.

Not all of these can be done by merely calling assembly routines or inline
code from C, because they depend coding conventions, and so control over the
compiler is necessary).

If your view of computing embraces such capabilities, then you will find
assembly language to be more capable than C.

For instance, take garbage collection. Suppose that in some function there is
a statement "x = NULL", where x is local and there are no more uses of x in the
remaining block. An optimizing C compiler could simply not bother with this
assignment since x has no next use. But what if there is garbage collection?
The variable x could be the last reference to a large amount of memory, whose
reclamation will be prevented if the assignment is optimized away.
The C compiler does not know that x has a kind of next use: it can be visited
"behind the scenes" by the garbage collector! C compilers are GC-unfriendly in
numerous ways, one of which is this generation of semantic garbage: keeping
values in memory or registers beyond the point at which they have become
garbage in the source semantics. In assembly we don't have this problem;
since we know what we put into every memory location and register.

We would like to be able to extend the C compiler with new rules such as
"whenever a pointer variable has no next use, generate code to overwrite it
with null", but the language doesn't give us a way to direct the translation in
such ways.
Very few as in some C compilers actually check that everything that can be
done in asm can be done in C.

Really? An example or two would go a long way here.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

code 34
URGENT 1
comparison error 12
code 50
error 28
Q for a source code in an exercise 1
no error by fscanf on reading from output file 18
malloc 40

Members online

Forum statistics

Threads
474,083
Messages
2,570,591
Members
47,212
Latest member
RobynWiley

Latest Threads

Top