473,473 Members | 2,009 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Assembler in C# code?

Will Whidbey will include the ability to put inline assembler into C#
code?

I found a previous thread in which it was implied that a future
version of .NET would support this.
(http://groups.google.com/groups?hl=e...%40tkmsftngp02)

My team is working on a program for defining and executing complex
economic calculations. We love C# but there are a number of
performance-critical sections that we would write in assembler if we
could.

Best,
Daniel Gackle
Nov 15 '05 #1
5 21177
As even the assembler would be converted to IL then converted to native exe,
not sure how much you could save over a fast c++ or c# routine. Maybe you
could do it in IL (never done this, but I think its possible.)

--
William Stacey, MVP

"Daniel Gackle" <do**************@yahoo.com> wrote in message
news:12*************************@posting.google.co m...
Will Whidbey will include the ability to put inline assembler into C#
code?

I found a previous thread in which it was implied that a future
version of .NET would support this.
(http://groups.google.com/groups?hl=e...elm=eDQxAcx3BH
A.2224%40tkmsftngp02)
My team is working on a program for defining and executing complex
economic calculations. We love C# but there are a number of
performance-critical sections that we would write in assembler if we
could.

Best,
Daniel Gackle

Nov 15 '05 #2
n!
> I found a previous thread in which it was implied that a future
version of .NET would support this.

(http://groups.google.com/groups?hl=e...elm=eDQxAcx3BH
A.2224%40tkmsftngp02)

My guess is that he was thinking of inlined 'IL' assembly rather than
inlined native assembly (though, of course, that's just my opinion).
One of the reasons for IL is so that the JIT and CLR can validate the
operation of the code, native assembly goes against this (or, at least,
makes it much more difficult).

Not only that, but by inlining native assembly, you will circumvent future
optimisations a JITter may make. As the JIT can be updated to support new
instructions within future processors you may end up with slower code on
some machines. I won't go further into these reason in case you didn't
actually mean inlined *native* assembly.

I see no reason why inlined IL assembly would be impossible, but then I
don't see the need to do that :)

n!
Nov 15 '05 #3
Daniel Gackle wrote:
Will Whidbey will include the ability to put inline assembler into C#
code?

I found a previous thread in which it was implied that a future
version of .NET would support this.
(http://groups.google.com/groups?hl=e...%40tkmsftngp02)

My team is working on a program for defining and executing complex
economic calculations. We love C# but there are a number of
performance-critical sections that we would write in assembler if we
could.


I haven't heard any rumors of inline asm being added to C#, and I'd be
surprised if it ever did get added. I'm not sure I'd read into Eric
Gunnerson's response the idea that it's planned (and the other response
in that thread was from someone who has no ties to Microsoft as far as I
can tell).

However, you can use the C++ compiler to build a managed assembly that
also contains unmanaged native code. In general, the managed code can
call the unmanaged code and vice-versa (you may see this called
"It-Just-Works" or IJW). So, you could use Managed C++ to compile a
module or assembly that contained a function that had inline asm, and
call it from your C# code.

Of course, this will mean that your application needs to be run in a
security context that allows unsafe code, so you need to understand what
that will do to your installation/deployment scenario.

--
mikeb
Nov 15 '05 #4
It's actually fairly trivial to handcode IL, if that's your intention, and
assemble and link it into your app using al.exe.

If you really want the speed of native code, then you need to do unmanaged
code. Wrapping it in a COM object makes it easy to use from C#.

Pete

"Daniel Gackle" <do**************@yahoo.com> wrote in message
news:12*************************@posting.google.co m...
Will Whidbey will include the ability to put inline assembler into C#
code?

I found a previous thread in which it was implied that a future
version of .NET would support this.
(http://groups.google.com/groups?hl=e...elm=eDQxAcx3BH
A.2224%40tkmsftngp02)
My team is working on a program for defining and executing complex
economic calculations. We love C# but there are a number of
performance-critical sections that we would write in assembler if we
could.

Best,
Daniel Gackle

Nov 15 '05 #5
One straight path, if you really do need to write some FPU assembler code,
is to put it in a regular DLL, and do a DLL import in your C# frontend :

[DllImport("myfasterfunctions.dll")]
public extern double[] MyCalculation(double[] myNumbers);

Btw, if you don't plan / can't use the SSE/SSE2/3DNow instructions in your
assembly code, a C++ compiler will probably do a better job than a manual
assembler implementation (the Intel compiler does wonders). It's getting
hard today, with all the prefetching/segmenting/whatever mecanisms of the
CPUs to beat the compilers on sequential coding. Of course, if your code can
be parallelized, some manual coding with the help of the SSE/SSE2/3DNow
instructions might almost double/quadruple the speed.
Nov 15 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

33
by: Tim Spujum | last post by:
Real men write their programs in pure assembler code. Sissies use C++.
3
by: fischerjd | last post by:
Is Microsoft still producing/releasing the Microsoft Macro Assembler (MASM)? I just installed Visual Studio .NET 2003 (p/o an MSDN/AA subscription) and apparently MASM is not provided/installed...
3
by: enfis.the.paladin | last post by:
Hi to all! I have something like this: class FWrap { public: virtual void READ (void) = 0; } class Optimized { private:
4
by: Neil Morris | last post by:
Hi I would like to know what the standard way to write a custom C library that links to assembler code? The reason is that, apart of been curious, I would like to know what format the C language...
3
by: verma_ashu | last post by:
hello friends, i need to design a small assembler in C language. but i donot know where to start. what machine to take as the environment for assembler or should i make a simulator also to run...
2
by: mclagett | last post by:
Can anyone please help me figure out why all of a sudden (even after many restarts of Visual Studio 2005 and reboots, etc) I am no longer able to set breakpoints in the disassembler window. I...
14
by: spamtrap | last post by:
Mostly for testing reasons I'd like to see if it makes sense to chose the following approach for just-in-time compilation of shaders for a renderer: Seeing as the shaders themsefs consist mostly...
12
by: Peter Anthony | last post by:
There are times it would be good to be able to write assembly code to integrate with other VS languages, such as VS C++ .NET. For example, I might want to write a REALLY fast algorithm that does...
3
by: =?ISO-8859-1?Q?Glenn_M=F8ller-Holst?= | last post by:
Hi! How do I get generated ARM assembler from this compiler: #arm-elf-gcc -dumpversion 4.2.0 #arm-elf-gcc -dumpmachine arm-elf kind regards,
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.