By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,144 Members | 849 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,144 IT Pros & Developers. It's quick & easy.

C# and my indispensable inline assembly code

P: n/a
I am about to move my C++ application to C#. Parts of my previous
application consisted of inline SSE2 assembly code optimized for the P4
processor. What options do I have to integrate that part into my C#
application?
There are no such things as intrinsics support in C#, right?

Thank you very much!
regards, Teis
Nov 16 '05 #1
Share this Question
Share on Google+
14 Replies


P: n/a
As far as I know this is not possible. You could separate your assembly
code out into a DLL which you call from your C# code using p/invoke but of
course this won't be inlined.

--
Bob Powell [MVP]
Visual C#, System.Drawing

All you ever wanted to know about ListView custom drawing is in Well Formed.
http://www.bobpowell.net/currentissue.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/gdiplus_faq.htm

Read my Blog at http://bobpowelldotnet.blogspot.com

"Teis Draiby" <te*************@draiby.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
I am about to move my C++ application to C#. Parts of my previous
application consisted of inline SSE2 assembly code optimized for the P4
processor. What options do I have to integrate that part into my C#
application?
There are no such things as intrinsics support in C#, right?

Thank you very much!
regards, Teis

Nov 16 '05 #2

P: n/a
-Thank you for your reply!
Any way I reach my beloved assembly is perfect for me. I'm still a C#
novice; is your proposal using a DLL and p/invoke the best and only solution
or are there other options that I could take into consideration?
My SSE2 code handles reatime video so both bandwidth and latency are issues
while communicating with the assembly section.

thank you very much, Teis
"Bob Powell [MVP]" <bob@_spamkiller_bobpowell.net> wrote in message
news:ei*************@TK2MSFTNGP11.phx.gbl...
As far as I know this is not possible. You could separate your assembly
code out into a DLL which you call from your C# code using p/invoke but of
course this won't be inlined.

--
Bob Powell [MVP]
Visual C#, System.Drawing

All you ever wanted to know about ListView custom drawing is in Well Formed. http://www.bobpowell.net/currentissue.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/gdiplus_faq.htm

Read my Blog at http://bobpowelldotnet.blogspot.com

"Teis Draiby" <te*************@draiby.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
I am about to move my C++ application to C#. Parts of my previous
application consisted of inline SSE2 assembly code optimized for the P4
processor. What options do I have to integrate that part into my C#
application?
There are no such things as intrinsics support in C#, right?

Thank you very much!
regards, Teis


Nov 16 '05 #3

P: n/a
is this really true Bob? Seems odd that Anders would have left that ability
out (cos I'm sure I remember this ability in Delphi -which of course is part
of Anders' background).
Maybe he's done this for code safety/ seperation/ readability?
--

--

Br,
Mark Broadbent
mcdba , mcse+i
=============
"Bob Powell [MVP]" <bob@_spamkiller_bobpowell.net> wrote in message
news:ei*************@TK2MSFTNGP11.phx.gbl...
As far as I know this is not possible. You could separate your assembly
code out into a DLL which you call from your C# code using p/invoke but of
course this won't be inlined.

--
Bob Powell [MVP]
Visual C#, System.Drawing

All you ever wanted to know about ListView custom drawing is in Well Formed. http://www.bobpowell.net/currentissue.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/gdiplus_faq.htm

Read my Blog at http://bobpowelldotnet.blogspot.com

"Teis Draiby" <te*************@draiby.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
I am about to move my C++ application to C#. Parts of my previous
application consisted of inline SSE2 assembly code optimized for the P4
processor. What options do I have to integrate that part into my C#
application?
There are no such things as intrinsics support in C#, right?

Thank you very much!
regards, Teis


Nov 16 '05 #4

P: n/a
But Delphi is unmanaged code, while C# results in managed code (IL) running
in the CLR, where it's translated to machine code by the JITter. The IL
produced by the C# compiler is secure/verifiable code and this is essential
for the language, allowing to embed assembly (unverifiable) would render the
language unverifiable (you don't wan't your assembly code to be translated
int IL do you?).

Willy.
"Mark Broadbent" <no************@no-spam-please.com> wrote in message
news:OE**************@TK2MSFTNGP10.phx.gbl...
is this really true Bob? Seems odd that Anders would have left that
ability
out (cos I'm sure I remember this ability in Delphi -which of course is
part
of Anders' background).
Maybe he's done this for code safety/ seperation/ readability?
--

--

Br,
Mark Broadbent
mcdba , mcse+i
=============
"Bob Powell [MVP]" <bob@_spamkiller_bobpowell.net> wrote in message
news:ei*************@TK2MSFTNGP11.phx.gbl...
As far as I know this is not possible. You could separate your assembly
code out into a DLL which you call from your C# code using p/invoke but
of
course this won't be inlined.

--
Bob Powell [MVP]
Visual C#, System.Drawing

All you ever wanted to know about ListView custom drawing is in Well

Formed.
http://www.bobpowell.net/currentissue.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/gdiplus_faq.htm

Read my Blog at http://bobpowelldotnet.blogspot.com

"Teis Draiby" <te*************@draiby.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
> I am about to move my C++ application to C#. Parts of my previous
> application consisted of inline SSE2 assembly code optimized for the P4
> processor. What options do I have to integrate that part into my C#
> application?
> There are no such things as intrinsics support in C#, right?
>
> Thank you very much!
> regards, Teis
>
>



Nov 16 '05 #5

P: n/a
Yes, the embedding of assembly language would render the assembly (and the
language as a feature) unverifiable. The CLR has absolutely no visibility
into unmanaged code and thus cannot control it's type safety or lifetime.

You could use MC++ which using IJW allows you to mix and match unmanaged and
managed C++ even in the same module but as long as there is assembly
language, the assembly will be non-verifiable.

--
Sam Gentile
Microsoft MVP - C#/.NET
INETA Speaker
Read my CLR blog http://samgentile.com/blog/
"Willy Denoyette [MVP]" <wi*************@pandora.be> wrote in message
news:ep*************@TK2MSFTNGP12.phx.gbl...
But Delphi is unmanaged code, while C# results in managed code (IL)
running in the CLR, where it's translated to machine code by the JITter.
The IL produced by the C# compiler is secure/verifiable code and this is
essential for the language, allowing to embed assembly (unverifiable)
would render the language unverifiable (you don't wan't your assembly code
to be translated int IL do you?).

Willy.
"Mark Broadbent" <no************@no-spam-please.com> wrote in message
news:OE**************@TK2MSFTNGP10.phx.gbl...
is this really true Bob? Seems odd that Anders would have left that
ability
out (cos I'm sure I remember this ability in Delphi -which of course is
part
of Anders' background).
Maybe he's done this for code safety/ seperation/ readability?
--

--

Br,
Mark Broadbent
mcdba , mcse+i
=============
"Bob Powell [MVP]" <bob@_spamkiller_bobpowell.net> wrote in message
news:ei*************@TK2MSFTNGP11.phx.gbl...
As far as I know this is not possible. You could separate your assembly
code out into a DLL which you call from your C# code using p/invoke but
of
course this won't be inlined.

--
Bob Powell [MVP]
Visual C#, System.Drawing

All you ever wanted to know about ListView custom drawing is in Well

Formed.
http://www.bobpowell.net/currentissue.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/gdiplus_faq.htm

Read my Blog at http://bobpowelldotnet.blogspot.com

"Teis Draiby" <te*************@draiby.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
> I am about to move my C++ application to C#. Parts of my previous
> application consisted of inline SSE2 assembly code optimized for the
> P4
> processor. What options do I have to integrate that part into my C#
> application?
> There are no such things as intrinsics support in C#, right?
>
> Thank you very much!
> regards, Teis
>
>



Nov 16 '05 #6

P: n/a
I just miss the possibility in C# (.NET) to specifically target modern
processors supporting SIMD instructions like SSE2 and 3D Now. Nevertheless
inner loops making use of SIMD can boost the process by several times.
Is that completely incompatible with MSIL?

regards, Teis
"Willy Denoyette [MVP]" <wi*************@pandora.be> wrote in message
news:ep*************@TK2MSFTNGP12.phx.gbl...
But Delphi is unmanaged code, while C# results in managed code (IL) running in the CLR, where it's translated to machine code by the JITter. The IL
produced by the C# compiler is secure/verifiable code and this is essential for the language, allowing to embed assembly (unverifiable) would render the language unverifiable (you don't wan't your assembly code to be translated
int IL do you?).

Willy.
"Mark Broadbent" <no************@no-spam-please.com> wrote in message
news:OE**************@TK2MSFTNGP10.phx.gbl...
is this really true Bob? Seems odd that Anders would have left that
ability
out (cos I'm sure I remember this ability in Delphi -which of course is
part
of Anders' background).
Maybe he's done this for code safety/ seperation/ readability?
--

--

Br,
Mark Broadbent
mcdba , mcse+i
=============
"Bob Powell [MVP]" <bob@_spamkiller_bobpowell.net> wrote in message
news:ei*************@TK2MSFTNGP11.phx.gbl...
As far as I know this is not possible. You could separate your assembly code out into a DLL which you call from your C# code using p/invoke but
of
course this won't be inlined.

--
Bob Powell [MVP]
Visual C#, System.Drawing

All you ever wanted to know about ListView custom drawing is in Well

Formed.
http://www.bobpowell.net/currentissue.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/gdiplus_faq.htm

Read my Blog at http://bobpowelldotnet.blogspot.com

"Teis Draiby" <te*************@draiby.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
> I am about to move my C++ application to C#. Parts of my previous
> application consisted of inline SSE2 assembly code optimized for the P4 > processor. What options do I have to integrate that part into my C#
> application?
> There are no such things as intrinsics support in C#, right?
>
> Thank you very much!
> regards, Teis
>
>



Nov 16 '05 #7

P: n/a
Teis,

Yes I know, but this is not the level you are programming at when using a
managed language, if you really need this you should stick to (VS C++7.x)
C/C++ where you can mix managed code and unmanaged code (and asm).
As for your SSE2 support, this is up to the CLR (JITter) to decide whether
these are available and use them when appropriate, but again if you want
play with your own toys ;-) just ignore C# for this and use C++.

Willy.

"Teis Draiby" <te*************@draiby.com> wrote in message
news:Oa**************@TK2MSFTNGP09.phx.gbl...
I just miss the possibility in C# (.NET) to specifically target modern
processors supporting SIMD instructions like SSE2 and 3D Now. Nevertheless
inner loops making use of SIMD can boost the process by several times.
Is that completely incompatible with MSIL?

regards, Teis

Nov 16 '05 #8

P: n/a


----- Teis Draiby wrote: ----
I just miss the possibility in C# (.NET) to specifically target moder
processors supporting SIMD instructions like SSE2 and 3D Now. Nevertheles
inner loops making use of SIMD can boost the process by several times
Is that completely incompatible with MSIL


yes, because that defeats the whole purpose of having a "virtual machine". remember, when you right in .NET, you are writing code for something imaginary, there's no SSE2 or 3D Now in our imaginary world.
Nov 16 '05 #9

P: n/a
yeah your right, I personally thought it might be nice to be able to embed
code like assembly that would be unmanaged and bypass the CLR (obviously in
the unsafe context) but I guess it is just as easy to import it via a dll
like Bob suggested.

--

--

Br,
Mark Broadbent
mcdba , mcse+i
=============
"Willy Denoyette [MVP]" <wi*************@pandora.be> wrote in message
news:ep*************@TK2MSFTNGP12.phx.gbl...
But Delphi is unmanaged code, while C# results in managed code (IL) running in the CLR, where it's translated to machine code by the JITter. The IL
produced by the C# compiler is secure/verifiable code and this is essential for the language, allowing to embed assembly (unverifiable) would render the language unverifiable (you don't wan't your assembly code to be translated
int IL do you?).

Willy.
"Mark Broadbent" <no************@no-spam-please.com> wrote in message
news:OE**************@TK2MSFTNGP10.phx.gbl...
is this really true Bob? Seems odd that Anders would have left that
ability
out (cos I'm sure I remember this ability in Delphi -which of course is
part
of Anders' background).
Maybe he's done this for code safety/ seperation/ readability?
--

--

Br,
Mark Broadbent
mcdba , mcse+i
=============
"Bob Powell [MVP]" <bob@_spamkiller_bobpowell.net> wrote in message
news:ei*************@TK2MSFTNGP11.phx.gbl...
As far as I know this is not possible. You could separate your assembly code out into a DLL which you call from your C# code using p/invoke but
of
course this won't be inlined.

--
Bob Powell [MVP]
Visual C#, System.Drawing

All you ever wanted to know about ListView custom drawing is in Well

Formed.
http://www.bobpowell.net/currentissue.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/gdiplus_faq.htm

Read my Blog at http://bobpowelldotnet.blogspot.com

"Teis Draiby" <te*************@draiby.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
> I am about to move my C++ application to C#. Parts of my previous
> application consisted of inline SSE2 assembly code optimized for the P4 > processor. What options do I have to integrate that part into my C#
> application?
> There are no such things as intrinsics support in C#, right?
>
> Thank you very much!
> regards, Teis
>
>



Nov 16 '05 #10

P: n/a
They could probably hide the steps with sugar, but the steps would be the
same. The unmanaged code would need to be compiled and linked and the
managed code would need a ref to it. They could package that all up and
include the unmanaged dll into the exe like ilmerge does or something to do
everything automatic. Not sure much call for that. I would like to see
simple include of managed dlls into the exe or master dll be really easy and
automatic however.

--
William Stacey, MVP

"Mark Broadbent" <no************@no-spam-please.com> wrote in message
news:e7**************@tk2msftngp13.phx.gbl...
yeah your right, I personally thought it might be nice to be able to embed
code like assembly that would be unmanaged and bypass the CLR (obviously in the unsafe context) but I guess it is just as easy to import it via a dll
like Bob suggested.

--

--

Br,
Mark Broadbent
mcdba , mcse+i
=============
"Willy Denoyette [MVP]" <wi*************@pandora.be> wrote in message
news:ep*************@TK2MSFTNGP12.phx.gbl...
But Delphi is unmanaged code, while C# results in managed code (IL) running
in the CLR, where it's translated to machine code by the JITter. The IL
produced by the C# compiler is secure/verifiable code and this is

essential
for the language, allowing to embed assembly (unverifiable) would render

the
language unverifiable (you don't wan't your assembly code to be translated
int IL do you?).

Willy.
"Mark Broadbent" <no************@no-spam-please.com> wrote in message
news:OE**************@TK2MSFTNGP10.phx.gbl...
is this really true Bob? Seems odd that Anders would have left that
ability
out (cos I'm sure I remember this ability in Delphi -which of course is part
of Anders' background).
Maybe he's done this for code safety/ seperation/ readability?
--

--

Br,
Mark Broadbent
mcdba , mcse+i
=============
"Bob Powell [MVP]" <bob@_spamkiller_bobpowell.net> wrote in message
news:ei*************@TK2MSFTNGP11.phx.gbl...
> As far as I know this is not possible. You could separate your

assembly> code out into a DLL which you call from your C# code using p/invoke but> of
> course this won't be inlined.
>
> --
> Bob Powell [MVP]
> Visual C#, System.Drawing
>
> All you ever wanted to know about ListView custom drawing is in Well
Formed.
> http://www.bobpowell.net/currentissue.htm
>
> Answer those GDI+ questions with the GDI+ FAQ
> http://www.bobpowell.net/gdiplus_faq.htm
>
> Read my Blog at http://bobpowelldotnet.blogspot.com
>
> "Teis Draiby" <te*************@draiby.com> wrote in message
> news:%2****************@TK2MSFTNGP12.phx.gbl...
> > I am about to move my C++ application to C#. Parts of my previous
> > application consisted of inline SSE2 assembly code optimized for
the P4> > processor. What options do I have to integrate that part into my C#
> > application?
> > There are no such things as intrinsics support in C#, right?
> >
> > Thank you very much!
> > regards, Teis
> >
> >
>
>




Nov 16 '05 #11

P: n/a
Thank you for the reply's, they have been very helpfull to get me going. I
am considering whether to use P/Invoke or IJW, both proposed in this thread.
I have yet only found a few comparisons out there (which are contradicting).
What is the best choose due to the requirements of my function, if there are
any big difference at all? I've read that IJW is a bit faster than P/Invoke
and easier to code as well (And it even works).

Function requirements:
The function will be called about 30-60 times per second (The video
framerate)
The function returns a frame for each call (1 to 4 Mb)
The function requres direct access to 0.5 - 1 Gb 'unmanaged' RAM (for
instant access to every frame)
Since it operates on realtime video input latency is an issue.
Thank you very much, Teis

"William Stacey [MVP]" <st***********@mvps.org> wrote in message
news:et**************@TK2MSFTNGP09.phx.gbl...
They could probably hide the steps with sugar, but the steps would be the
same. The unmanaged code would need to be compiled and linked and the
managed code would need a ref to it. They could package that all up and
include the unmanaged dll into the exe like ilmerge does or something to do everything automatic. Not sure much call for that. I would like to see
simple include of managed dlls into the exe or master dll be really easy and automatic however.

--
William Stacey, MVP

"Mark Broadbent" <no************@no-spam-please.com> wrote in message
news:e7**************@tk2msftngp13.phx.gbl...
yeah your right, I personally thought it might be nice to be able to embed
code like assembly that would be unmanaged and bypass the CLR (obviously

in
the unsafe context) but I guess it is just as easy to import it via a dll like Bob suggested.

--

--

Br,
Mark Broadbent
mcdba , mcse+i
=============
"Willy Denoyette [MVP]" <wi*************@pandora.be> wrote in message
news:ep*************@TK2MSFTNGP12.phx.gbl...
But Delphi is unmanaged code, while C# results in managed code (IL)

running
in the CLR, where it's translated to machine code by the JITter. The IL produced by the C# compiler is secure/verifiable code and this is

essential
for the language, allowing to embed assembly (unverifiable) would render
the
language unverifiable (you don't wan't your assembly code to be

translated int IL do you?).

Willy.
"Mark Broadbent" <no************@no-spam-please.com> wrote in message
news:OE**************@TK2MSFTNGP10.phx.gbl...
> is this really true Bob? Seems odd that Anders would have left that
> ability
> out (cos I'm sure I remember this ability in Delphi -which of course is > part
> of Anders' background).
> Maybe he's done this for code safety/ seperation/ readability?
>
>
> --
>
> --
>
> Br,
> Mark Broadbent
> mcdba , mcse+i
> =============
> "Bob Powell [MVP]" <bob@_spamkiller_bobpowell.net> wrote in message
> news:ei*************@TK2MSFTNGP11.phx.gbl...
>> As far as I know this is not possible. You could separate your

assembly
>> code out into a DLL which you call from your C# code using p/invoke but >> of
>> course this won't be inlined.
>>
>> --
>> Bob Powell [MVP]
>> Visual C#, System.Drawing
>>
>> All you ever wanted to know about ListView custom drawing is in

Well > Formed.
>> http://www.bobpowell.net/currentissue.htm
>>
>> Answer those GDI+ questions with the GDI+ FAQ
>> http://www.bobpowell.net/gdiplus_faq.htm
>>
>> Read my Blog at http://bobpowelldotnet.blogspot.com
>>
>> "Teis Draiby" <te*************@draiby.com> wrote in message
>> news:%2****************@TK2MSFTNGP12.phx.gbl...
>> > I am about to move my C++ application to C#. Parts of my previous
>> > application consisted of inline SSE2 assembly code optimized for

the
P4
>> > processor. What options do I have to integrate that part into my C# >> > application?
>> > There are no such things as intrinsics support in C#, right?
>> >
>> > Thank you very much!
>> > regards, Teis
>> >
>> >
>>
>>
>
>


Nov 16 '05 #12

P: n/a
Both IJW and P/Invoke (and COM Interop) undergo what is known as "Transition
Thunks" between managed and unmanaged code. This is a set of assembly
language instructions that switch the stack and such. Don and I documented
in 2000 or 2001 in some DM list and it's in Don's book to some extent.
Marshaling is also done here and the base cost of the transition thunk goes
up with marshalling non-isomorphic types. IJW's transition is more efficient
as it is able to optimize for the C++ to C++ case. So there is not a
universal answer but in your situation using IJW will be faster. As long as
you are unmanaged C++ to managed C++, IJW will always be faster. I verified
this with the C++ team.
--
----------------------------------
Sam Gentile
MVP - C#/.NET
INETA Speaker http://www.ineta.org/DesktopDefault.aspx
Read my blog at http://samgentile.com/blog/
------------------------------------------------------
"Teis Draiby" <te*************@draiby.com> wrote in message
news:Ot**************@TK2MSFTNGP12.phx.gbl...
Thank you for the reply's, they have been very helpfull to get me going. I
am considering whether to use P/Invoke or IJW, both proposed in this thread. I have yet only found a few comparisons out there (which are contradicting). What is the best choose due to the requirements of my function, if there are any big difference at all? I've read that IJW is a bit faster than P/Invoke and easier to code as well (And it even works).

Function requirements:
The function will be called about 30-60 times per second (The video
framerate)
The function returns a frame for each call (1 to 4 Mb)
The function requres direct access to 0.5 - 1 Gb 'unmanaged' RAM (for
instant access to every frame)
Since it operates on realtime video input latency is an issue.
Thank you very much, Teis

"William Stacey [MVP]" <st***********@mvps.org> wrote in message
news:et**************@TK2MSFTNGP09.phx.gbl...
They could probably hide the steps with sugar, but the steps would be the
same. The unmanaged code would need to be compiled and linked and the
managed code would need a ref to it. They could package that all up and
include the unmanaged dll into the exe like ilmerge does or something to do
everything automatic. Not sure much call for that. I would like to see
simple include of managed dlls into the exe or master dll be really easy

and
automatic however.

--
William Stacey, MVP

"Mark Broadbent" <no************@no-spam-please.com> wrote in message
news:e7**************@tk2msftngp13.phx.gbl...
yeah your right, I personally thought it might be nice to be able to embed code like assembly that would be unmanaged and bypass the CLR (obviously in
the unsafe context) but I guess it is just as easy to import it via a dll like Bob suggested.

--

--

Br,
Mark Broadbent
mcdba , mcse+i
=============
"Willy Denoyette [MVP]" <wi*************@pandora.be> wrote in message
news:ep*************@TK2MSFTNGP12.phx.gbl...
> But Delphi is unmanaged code, while C# results in managed code (IL)
running
> in the CLR, where it's translated to machine code by the JITter. The IL > produced by the C# compiler is secure/verifiable code and this is
essential
> for the language, allowing to embed assembly (unverifiable) would render the
> language unverifiable (you don't wan't your assembly code to be

translated
> int IL do you?).
>
> Willy.
>
>
> "Mark Broadbent" <no************@no-spam-please.com> wrote in
message > news:OE**************@TK2MSFTNGP10.phx.gbl...
> > is this really true Bob? Seems odd that Anders would have left that > > ability
> > out (cos I'm sure I remember this ability in Delphi -which of course
is
> > part
> > of Anders' background).
> > Maybe he's done this for code safety/ seperation/ readability?
> >
> >
> > --
> >
> > --
> >
> > Br,
> > Mark Broadbent
> > mcdba , mcse+i
> > =============
> > "Bob Powell [MVP]" <bob@_spamkiller_bobpowell.net> wrote in
message > > news:ei*************@TK2MSFTNGP11.phx.gbl...
> >> As far as I know this is not possible. You could separate your
assembly
> >> code out into a DLL which you call from your C# code using p/invoke but
> >> of
> >> course this won't be inlined.
> >>
> >> --
> >> Bob Powell [MVP]
> >> Visual C#, System.Drawing
> >>
> >> All you ever wanted to know about ListView custom drawing is in Well > > Formed.
> >> http://www.bobpowell.net/currentissue.htm
> >>
> >> Answer those GDI+ questions with the GDI+ FAQ
> >> http://www.bobpowell.net/gdiplus_faq.htm
> >>
> >> Read my Blog at http://bobpowelldotnet.blogspot.com
> >>
> >> "Teis Draiby" <te*************@draiby.com> wrote in message
> >> news:%2****************@TK2MSFTNGP12.phx.gbl...
> >> > I am about to move my C++ application to C#. Parts of my
previous > >> > application consisted of inline SSE2 assembly code optimized

for the
P4
> >> > processor. What options do I have to integrate that part into

my C# > >> > application?
> >> > There are no such things as intrinsics support in C#, right?
> >> >
> >> > Thank you very much!
> >> > regards, Teis
> >> >
> >> >
> >>
> >>
> >
> >
>
>


Nov 16 '05 #13

P: n/a
Thanks for the detailed reply and book recommandations. Now I got enough
stuff to keep myself occupied for a while, I guess.

regards, Teis
"Sam Gentile [MVP - C#/.NET]" <no****@nomail.com> wrote in message
news:um**************@TK2MSFTNGP10.phx.gbl...
Both IJW and P/Invoke (and COM Interop) undergo what is known as "Transition Thunks" between managed and unmanaged code. This is a set of assembly
language instructions that switch the stack and such. Don and I documented
in 2000 or 2001 in some DM list and it's in Don's book to some extent.
Marshaling is also done here and the base cost of the transition thunk goes up with marshalling non-isomorphic types. IJW's transition is more efficient as it is able to optimize for the C++ to C++ case. So there is not a
universal answer but in your situation using IJW will be faster. As long as you are unmanaged C++ to managed C++, IJW will always be faster. I verified this with the C++ team.
--
----------------------------------
Sam Gentile
MVP - C#/.NET
INETA Speaker http://www.ineta.org/DesktopDefault.aspx
Read my blog at http://samgentile.com/blog/
------------------------------------------------------
"Teis Draiby" <te*************@draiby.com> wrote in message
news:Ot**************@TK2MSFTNGP12.phx.gbl...
Thank you for the reply's, they have been very helpfull to get me going. I
am considering whether to use P/Invoke or IJW, both proposed in this

thread.
I have yet only found a few comparisons out there (which are

contradicting).
What is the best choose due to the requirements of my function, if there

are
any big difference at all? I've read that IJW is a bit faster than

P/Invoke
and easier to code as well (And it even works).

Function requirements:
The function will be called about 30-60 times per second (The video
framerate)
The function returns a frame for each call (1 to 4 Mb)
The function requres direct access to 0.5 - 1 Gb 'unmanaged' RAM (for
instant access to every frame)
Since it operates on realtime video input latency is an issue.
Thank you very much, Teis

"William Stacey [MVP]" <st***********@mvps.org> wrote in message
news:et**************@TK2MSFTNGP09.phx.gbl...
They could probably hide the steps with sugar, but the steps would be the same. The unmanaged code would need to be compiled and linked and the
managed code would need a ref to it. They could package that all up and include the unmanaged dll into the exe like ilmerge does or something to do
everything automatic. Not sure much call for that. I would like to
see simple include of managed dlls into the exe or master dll be really easy
and
automatic however.

--
William Stacey, MVP

"Mark Broadbent" <no************@no-spam-please.com> wrote in message
news:e7**************@tk2msftngp13.phx.gbl...
> yeah your right, I personally thought it might be nice to be able to

embed
> code like assembly that would be unmanaged and bypass the CLR (obviously in
> the unsafe context) but I guess it is just as easy to import it via
a dll
> like Bob suggested.
>
> --
>
> --
>
> Br,
> Mark Broadbent
> mcdba , mcse+i
> =============
> "Willy Denoyette [MVP]" <wi*************@pandora.be> wrote in
message > news:ep*************@TK2MSFTNGP12.phx.gbl...
> > But Delphi is unmanaged code, while C# results in managed code (IL) > running
> > in the CLR, where it's translated to machine code by the JITter.

The IL
> > produced by the C# compiler is secure/verifiable code and this is
> essential
> > for the language, allowing to embed assembly (unverifiable) would

render
> the
> > language unverifiable (you don't wan't your assembly code to be
translated
> > int IL do you?).
> >
> > Willy.
> >
> >
> > "Mark Broadbent" <no************@no-spam-please.com> wrote in

message > > news:OE**************@TK2MSFTNGP10.phx.gbl...
> > > is this really true Bob? Seems odd that Anders would have left that > > > ability
> > > out (cos I'm sure I remember this ability in Delphi -which of course is
> > > part
> > > of Anders' background).
> > > Maybe he's done this for code safety/ seperation/ readability?
> > >
> > >
> > > --
> > >
> > > --
> > >
> > > Br,
> > > Mark Broadbent
> > > mcdba , mcse+i
> > > =============
> > > "Bob Powell [MVP]" <bob@_spamkiller_bobpowell.net> wrote in message > > > news:ei*************@TK2MSFTNGP11.phx.gbl...
> > >> As far as I know this is not possible. You could separate your
> assembly
> > >> code out into a DLL which you call from your C# code using p/invoke but
> > >> of
> > >> course this won't be inlined.
> > >>
> > >> --
> > >> Bob Powell [MVP]
> > >> Visual C#, System.Drawing
> > >>
> > >> All you ever wanted to know about ListView custom drawing is in

Well
> > > Formed.
> > >> http://www.bobpowell.net/currentissue.htm
> > >>
> > >> Answer those GDI+ questions with the GDI+ FAQ
> > >> http://www.bobpowell.net/gdiplus_faq.htm
> > >>
> > >> Read my Blog at http://bobpowelldotnet.blogspot.com
> > >>
> > >> "Teis Draiby" <te*************@draiby.com> wrote in message
> > >> news:%2****************@TK2MSFTNGP12.phx.gbl...
> > >> > I am about to move my C++ application to C#. Parts of my previous > > >> > application consisted of inline SSE2 assembly code optimized for the
> P4
> > >> > processor. What options do I have to integrate that part into

my
C#
> > >> > application?
> > >> > There are no such things as intrinsics support in C#, right?
> > >> >
> > >> > Thank you very much!
> > >> > regards, Teis
> > >> >
> > >> >
> > >>
> > >>
> > >
> > >
> >
> >
>
>



Nov 16 '05 #14

P: n/a
Hi

Another option besides using PInvoke with a standard DLL, is to create a VC++ managed assembly.

Check out managed extensions for VC+

Hope this helps

Eddi

----- Teis Draiby wrote: ----

I am about to move my C++ application to C#. Parts of my previou
application consisted of inline SSE2 assembly code optimized for the P
processor. What options do I have to integrate that part into my C
application
There are no such things as intrinsics support in C#, right

Thank you very much
regards, Tei

Nov 16 '05 #15

This discussion thread is closed

Replies have been disabled for this discussion.