SIMD support in Mono

by Miguel de Icaza

The other day Cody Russell was asking on IRC what we could do in the Mono universe to take advantage of some special instruction sets like SIMD or how to use C# to generate code for pixel shaders or vertex shaders.

One idea that we discussed was the creation of a library that would be able to expose this kind of functionality. Take for example the following Cg example:

// input vertex
struct VertIn {
    float4 pos   : POSITION;
    float4 color : COLOR0;
};

// output vertex
struct VertOut {
    float4 pos   : POSITION;
    float4 color : COLOR0;
};

// vertex shader main entry
VertOut main(VertIn IN, uniform float4x4 modelViewProj) {
    VertOut OUT;
    OUT.pos     = mul(modelViewProj, IN.pos); // calculate output coords
    OUT.color   = IN.color; // copy input color to output
    OUT.color.z = 1.0f; // blue component of color = 1.0f
    return OUT;
}
	

A C# rendering of the above would be:

class MyShader {
	struct VertIn {
	    [Position] float pos;
	    [Color]    float color;
	};
	
	// output vertex
	struct VertOut {
	    [Position] float pos;
	    [Color]    float color;
	};
	
	// vertex shader main entry
	public VertOut main(VertIn IN, [Uniform] float4x4 modelViewProj) {
	    VertOut OUT;
	    OUT.pos     = mul(modelViewProj, IN.pos); // calculate output coords
	    OUT.color   = IN.color; // copy input color to output
	    OUT.color.z = 1.0f; // blue component of color = 1.0f
	    return OUT;
	}
}
	

The above is a direct translation. Now, the value of the library would be basically a method that generates a delegate with the proper signature:


	Delegate Compile (MethodInfo method)
	
	

It would be used like this:

	delegate VertOut main_delegate (VertIn In, [UniForm][float4x4] model);
	...
	main_delegate shader;
	shader = (main_delegate) Compile (typeof (MyShader).GetMethod ("main"));
	...
	shader (my_in_data, model);
	

The Compile method would use the Cecil library to decompile the code, perform flow analysis and ensure that the code in the method passed (in this case main) meets the restrictions imposed by the target (in this case Cg's target).

In some cases (SSE instructions) you might want a delegate back, or a method token that you could then Reflection.Emit call. In some other cases you might want the code to give you some handle back that you can pass to your graphics hardware.

(Cecil has a very nice flowanalysis engine, the one used by db4objects to provide the LINQ-like functionality with today's C# compilers).

The above model can be extended to other operations, and in some cases the return value from Compile could be just a delegate to the original method (if the hardware is not supported).

Today a student interested in doing something very similar for the Summer of Code emailed me, so I decided to dump here some of the ideas.

Posted on 15 Mar 2007


Mono and the Google Summer of Code

by Miguel de Icaza

The Google Summer of Code has started. Students interested in participating in the Summer of Code need to submit their applications in the next ten days.

Some ideas of interesting things that can be done with Mono are available in our Student Projects page.

If you think that you have a good idea for a project to be implemented for Mono, but is not listed on that page, feel free to submit your idea.

We are looking at improving Mono's OSX support (Winforms, debugger support, improving Cocoa#); new ports and improving existing Mono ports; Profiling Mono, Gtk#, MonoDevelop; low-level optimizations; New Windows.Forms widgets; Work on 3.0 components and libraries; Improving MonoDevelop and creating new C# class libraries for Mono.

Other Apps: We are also interested in tasks improving popular Mono-based applications for the desktop to showcase how great building applications with Mono is. Make sure you send your submission on time.

Posted on 15 Mar 2007


Eiffel now Open Source

by Miguel de Icaza

One of my favorite books is Bertrand Meyer's Object Oriented Software Construction

The book explores object oriented programming using the Eiffel language and one of the things that I always loved about Eiffel was the defensive programming techniques that it teaches and the strong focus on contracts and preconditions (a technique that is used extensively in Gnome).

Until very recently I had not noticed it, but the Eiffel compiler and the Eiffel suite of libraries and even the development IDE (EiffelStudio) were open sourced (Emmanuel mentions this to me during the Lang.Net conference and I do not remember any big news about it).

They have just launched a community site Eiffel Room.

There are a bunch of Flash-based presentations on Eiffels here.

In this presentation you can see a demo of the IDE. In particular see the "System Metrics" section.

Posted on 13 Mar 2007


Value Types and Null

by Miguel de Icaza

Anyone has any idea of what is going on with value type comparisons against null in the Microsoft C# 2.0 compiler (and also the Orcas compiler exhibits this problem):

The compiler allows code like this:

	DateTime dt = DateTime.Now;   // this is a value type

	// Compare value type to null, invalid in CSC 1:
	if (dt != null){
		// ...
	}
	

The problem is that the above is always known to be false (dt can not be null), so CSC generates generates the equivalent to "if (true)" every single time (it becomes a no-op).

Adding support for this to the Mono compiler is simple enough but this sounds wrong. Because those testing a value type against null are doing a pointless test and they might be under the mistaken impression that the test is guarding them from an invalid state which it is not.

A few folks have reported this, but I can not find any rationale for this in the ECMA spec, it sounds like a bug in Microsoft's compiler related to the nullable-type support in their compiler.

Posted on 13 Mar 2007


Mono on the Nokia 770 and 800

by Miguel de Icaza

Everaldo and Wade have now published packages for Mono on the Nokia 770 and 800.

Visit our Maemo page to install the packages on your device.

The packages feature single-click install, and will add the repositories to your system so you can install only the pieces of Mono that you need to run specific applications.

Posted on 12 Mar 2007


Must Blog This: Bush in Latin America

by Miguel de Icaza

As I said two days ago Bush is not really loved in Latin America.

Wonkette asks the question: "Are the protesters hot?" on their "South Americans Welcome George W Bush -- With Style".

The answer: not safe for work.

This is the first time I link to Pravda, but they got photos of the welcoming.

Posted on 09 Mar 2007


Mono JIT Developer.

by Miguel de Icaza

We are looking for a developer to work on Mono's JIT engine.

What: We are looking for someone that would be interested in porting the Ahead-of-Time compilation engine in Mono for ARM processors and look at improving Mono startup performance on small devices.

You would work on both the virtual machine and the class libraries to improve performance and reduce memory usage for embedded systems.

Experience with assembly language, compilers, virtual machines, performance and garbage collectors will be useful, but it is not necessary. We are looking for a talented individual that is not scared by hard tasks.

How: If you are interested, email me, you will later receive a challenging interview to respond to.

Where: You can either work in the Boston office, or from home.

Why: Because we got a fantastic logo, which is much better than Microsoft's logo for .NET and working on Mono is a blast.

Posted on 09 Mar 2007


It made me smile

by Miguel de Icaza

From Google News a few minutes ago:

That made my day, funniest thing so far!

If you thought that Europe was less than supportive towards the Iraq war you have not seen Latin America. Unlike the US population that has kind of grown tired of the Iraq war in the last year, Latin America has been fuming over the retardedness of it way before it started.

He is not going to meet a friendly audience, so unless he throws money out of the windows, announces a withdrawal from Iraq, agrees to pay reparations and announced an "open doors policy" this trip is not going to win him any bonus points.

A timely Common Dreams article.

Update from Friday: This is now in Reddit's home page, it links to this article:

Second Update:

GUATEMALA CITY - Mayan priests will purify a sacred archaeological site to eliminate "bad spirits" after President Bush visits next week, an official with close ties to the group said Thursday.

"That a person like (Bush), with the persecution of our migrant brothers in the United States, with the wars he has provoked, is going to walk in our sacred lands, is an offense for the Mayan people and their culture," Juan Tiney, the director of a Mayan nongovernmental organization with close ties to Mayan religious and political leaders, said Thursday.

More updates, this is the Wonkette coverage. Wonkette asks the question: Are Brazilian protesters hot?: "Of course they’re hot! They’re Brazilian, for god’s sake.".

Posted on 08 Mar 2007


FOSDEM Presentation

by Miguel de Icaza

My "Turbocharging Linux With Mono" presentation from FOSDEM is now online, it is a pretty large file (300 megs) but you get to hear Coca Cola guy at the end.

The presentation is here.

At night, I kept running into Michael Meeks and Simon Phipps in all these tiny bars in town. Simon did a quick interview on Sunday.

Posted on 08 Mar 2007


Need some Google Help

by Miguel de Icaza

Folks, it has come to my attention the fact that my blog uses Google Groups is not very Web 2.0-ish, or is not very bloggy of me or something. Either that, or people have not been flaming me in public as much as I hoped to.

Part of the challenge is that my blog system is based on purely static HTML pages, and I would like to keep it that way. I get it for free (Thanks Gonzalo!) and server side solutions feel like cheating.

So I had a two-prong idea to address the issue:

  • Add some comment form at the bottom that would post to the Google Group.
  • Add some Json Magic to load the comments that are posted on the Google Group to be rendered on each blog entry.

Now, it seems that posting to the Google Group requires to be signed on to the group, am not sure if that is even fixable, but I would love to hear your thoughts.

Now, the second issue must be solvable, there must be a simple set of steps, an HTTP url I can query that would load the content from Google Groups and then render it with some magic jay-son love on the client (just like the cute "shared" links thing on the right side of my blog).

Google probably already has some JSon generator for this, but I have been unable to Google this information. If anyone knows how to do this, please share your thoughts.

Again, the trick is that even if I could setup a server-side thing in my hosting provider, it has no hack value. So the trick is basically to do this without burning any CPU cycles on the blog server, am fine with delegating the cycle burning to third parties.

A combination of Yahoo Pipes, Google searches and clogging the series of tubes with tremendous amounts of material, tremendous amounts of JSon material are all acceptable solutions.

Posted on 07 Mar 2007


« Newer entries | Older entries »