<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
  version="2.0">
  <channel>
    <title>FreiK's WebLog</title>
    <atom:link
      href="https://docs.microsoft.com/archive/blogs/freik/feed.xml"
      rel="self"
      type="application/rss+xml" />
    <link>https://docs.microsoft.com/archive/blogs/freik/feed.xml</link>
    <description>AMD64 (aka X64) Stuff - Random warblings of a 64 bit Windows junkie</description>
    <lastBuildDate>Wed, 17 Apr 2019 03:20:41 GMT</lastBuildDate>
    <language>en-US</language>
    <sy:updatePeriod>hourly</sy:updatePeriod>
    <sy:updateFrequency>1</sy:updateFrequency>
    <item>
      <title>Goofing around with TypeScript &amp; Windows Script Host</title>
      <link>https://docs.microsoft.com/archive/blogs/freik/goofing-around-with-typescript-windows-script-host</link>
      <pubDate>Fri, 19 Oct 2012 21:54:45 GMT</pubDate>
      <dc:creator><![CDATA[Kevin Frei]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/freik/2012/10/19/goofing-around-with-typescript-windows-script-host/</guid>
      <description><![CDATA[I've been horsing around a lot lately with Windows Script Host for various reasons, some more...]]></description>
      <content:encoded><![CDATA[<p>I've been horsing around a lot lately with Windows Script Host for various reasons, some more interesting than others.&nbsp; I've actually done a bunch of random things to make it much more palatable under Visual Studio 2012:&nbsp; perhaps I'll share some of that goofy magic later, but for right now&nbsp;I'm now trying out TypeScript, because I'm a firm believer in compile time errors finding lots of runtime problems, and I figured I'd toss some wrappers (d.ts files) I've created to make using stuff with WScript/CScript better onto my blog.&nbsp; It's pretty raw, only having received minimal testing, but it's helped a bit, so I figured I'd share.&nbsp; Enjoy!</p>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Components.PostAttachments/00/10/36/13/48/WScript.d.ts" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-components-postattachments/00-10-36-13-48/WScript.d.ts">WScript.d.ts</a></p>]]></content:encoded>
    </item>
    <item>
      <title>Quick note about x64 Tail call</title>
      <link>https://docs.microsoft.com/archive/blogs/freik/quick-note-about-x64-tail-call</link>
      <pubDate>Mon, 09 Feb 2009 14:28:43 GMT</pubDate>
      <dc:creator><![CDATA[Kevin Frei]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/freik/2009/02/09/quick-note-about-x64-tail-call/</guid>
      <description><![CDATA[A coworker on the CLR dropped by recently, having hit a brick wall about some problem he was having...]]></description>
      <content:encoded><![CDATA[<p>A coworker on the CLR dropped by recently, having hit a brick wall about some problem he was having with some ASM code for x64 that was trying to tail call.&#160; He has already grep’ed through the ABI docs, and had actually hit this blog prior to knocking on my door.&#160; The problem?&#160; How to emit a tail call through a register such that the OS unwinder doesn’t puke.</p>  <p>The quick answer is to use a REX prefix extension on the JMP instruction.&#160; For those of you that know what you’re doing, you can probably stop here.&#160; For more details, read on…</p>  <p>For folks that don’t know what a tail call is, you probably haven’t ever done any functional programming before.&#160; The Intro to CS class I took my freshman year of college was taught by a guy who really liked programming languages, and forced us (against the will of many of the guys in the class) to write a whole bunch of Scheme.&#160; But since none of us knew Scheme, we were learning that language as we went along, and he only taught us the functional subset of scheme.&#160; The biggest problem folks coming from the procedural programming world hit is the lack of a for loop.&#160; Since my Scheme is really rusty, I’ll continue this exposition writing in the “functional subset of C++” :-)</p>  <p>The easiest way to understand the issue is to try to solve a problem.&#160; Let’s write Factorial without using any side-effects:</p>  <p><font size="3" face="Courier New">BigInt Factorial(BigInt v) {     <br />&#160;&#160;&#160; return (v &lt;= 1) ? 1 : v * Factorial(v - 1);      <br />} </font></p>  <p>That looks great, right?&#160; Now go try running Factorial(15) and watch the stack explode (I’m not kidding – BigInt is a large object).&#160; The reason the stack explodes is because Factorial doesn’t just return the value of a recursive function call.&#160; It gets the value from the recursive function call, then it does something with it prior to the return, so the stack frame of the caller must be left alone.&#160; You need to be able to eliminate the need to do something with the value of the function you’re recursing on, if you want to allow the stack frame to be tossed (actually, just reused):</p>  <p><font size="2" face="Courier New"></font></p>  <p></p>  <p><font size="3" face="Courier New">BigInt Factorial_TailRecurse(BigInt v, BigInt current) {     <br />&#160;&#160;&#160; return (v &lt;= 1) ? current : Factorial_TailRecurse(v - 1, v * current);      <br />} </font></p>  <p><font size="3" face="Courier New">BigInt Factorial(BigInt v) {     <br />&#160;&#160;&#160; return Factorial_TailRecurse(v, 1);      <br />}</font></p>  <p>Voila – we no longer need to do anything with the return result of Factorial_TailRecurse other than just return it.&#160; What does that code wind up looking like, once it’s pumped through a relatively intelligent compiler back end?&#160; Almost exactly like the more traditional C++ for loop, actually.</p>  <p>So, now you have a perfect understanding of what tail recursion is.&#160; In my contrived example, however, there’s no need to do anything fancy to express that the end of your function is a tail-recursive call.&#160; Imagine, however, that the function you’re calling from has a very large stack frame, and you’re calling doing something goofy, like writing a recursive parser.&#160; Since you don’t want your parser to be limited to the depth of the stack, you’re making sure that you’re always writing tail-recursive code.&#160; But what if you’re trying to call a function pointer recursively?&#160; This is where you get stuck without REX JMP.</p>  <p>The OS unwinder can statically look at the Factorial_TailRecurse(v-1, v*current) function call, and recognized that the offset being jumped to is the head of this function, and therefore knows that it’s actually part of a function epilog.&#160; If, however, instead of jmp [IP-42], it saw jmp [RAX], it wouldn’t know where this thing was actually headed.&#160; In fact, it might be a switch statement.&#160; So, to properly flag the tail call as being part of an epilog, you throw a REX prefix on first, and now the unwinder groks the epilog, and you’re done.</p>  <p>-Kev</p>]]></content:encoded>
    </item>
    <item>
      <title>What's in a title?</title>
      <link>https://docs.microsoft.com/archive/blogs/freik/whats-in-a-title</link>
      <pubDate>Tue, 03 Jun 2008 16:50:00 GMT</pubDate>
      <dc:creator><![CDATA[Kevin Frei]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/freik/2008/06/03/whats-in-a-title/</guid>
      <description><![CDATA[My wife just asked "What's an 'after-sales engineer'?"&nbsp; I parsed the terms, and came up with...]]></description>
      <content:encoded><![CDATA[My wife just asked "What's an 'after-sales engineer'?"&nbsp; I parsed the terms, and came up with "Tech Support Dude".&nbsp; As a teenager, I was a Foliage Architect (I mowed lawns), System Builder (computer assembly slave), Network Administrator (very poorly paid, local&nbsp;'after sales engineer') and an Information Delivery Engineer (paper boy).]]></content:encoded>
    </item>
    <item>
      <title>The customer is wrong</title>
      <link>https://docs.microsoft.com/archive/blogs/freik/the-customer-is-wrong</link>
      <pubDate>Thu, 03 Apr 2008 00:45:45 GMT</pubDate>
      <dc:creator><![CDATA[Kevin Frei]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/freik/2008/04/03/the-customer-is-wrong/</guid>
      <description><![CDATA[I just watched the highly lame &#8220;You wouldn&#8217;t steal a car&#8230;Downloading pirated...]]></description>
      <content:encoded><![CDATA[<p>I just watched the highly lame &#8220;You <a href="https://youtube.com/watch?v=-7QAS5ze86c&amp;feature=related" target="_blank">wouldn&#8217;t steal a car&#8230;Downloading pirated movies is stealing</a>&#8221; &#8216;trailer&#8217;. How&#8217;s this for irony: I watched this trailer because it was the SECOND thing to play on the DVD of <a href="http://www.imdb.com/title/tt0337978/" target="_blank">Die Hard 4</a> that I just purchased. The FIRST thing to play on this DVD was a menu that asked me what language I would like: English, Mandarin, Russian, and about 8 other languages that I had never heard of, or couldn&#8217;t read. The DVD cost me <a href="http://www.oanda.com/convert/classic" target="_blank">7RMB</a> &#8211; about $1 &#8211; from the guy who has a 1m by 3m (about 3&#8217; x 9&#8217;) booth selling DVD&#8217;s that look almost legit (minus the flat plastic packaging). But this is the just ironic frosting on a very annoying <a href="http://en.wikipedia.org/wiki/Digital_rights_management" target="_blank">DRM</a> cake. What&#8217;s the DRM cake I&#8217;m talking about? Let&#8217;s start from the beginning. {I&#8217;m writing this while watching the movie, so I&#8217;ll include a little commentary for your entertainment}</p>  <p>I&#8217;m living in <a href="http://www.wikimapia.org/#lat=31.194008&amp;lon=121.429106&amp;z=18&amp;l=0&amp;m=a&amp;v=2" target="_blank">Shanghai</a> for a while. It&#8217;s very fun. Great city, interesting people, very kid tolerant, very cool place. Check my personal <a href="http://kfrei.spaces.live.com/" target="_blank">blog</a> for details. {DH4 commentary: How come the <a href="http://search.live.com/results.aspx?q=Justin+Long" target="_blank">guy</a> who is <a href="http://blog.atomicshed.com/?p=334" target="_blank">&#8220;a Mac&#8221;</a> is using a system that&#8217;s obviously not <a href="http://www.apple.com/macosx/" target="_blank">Mac OS X</a>? Isn&#8217;t he too cool for that?} </p>  <p>We took a trip to <a href="http://www.wikimapia.org/#lat=39.899202&amp;lon=116.38916&amp;z=9&amp;l=0&amp;m=a&amp;v=2" target="_blank">Beijing</a> last week. It was a blast. We stayed at the <a href="http://www.wikimapia.org/#lat=39.908506&amp;lon=116.40873&amp;z=18&amp;l=0&amp;m=a&amp;v=2" target="_blank">Grand Hyatt</a>. It was a very nice place (I won&#8217;t mention that the reason we stayed there is because when my wife was telling me how much it cost, I thought she was talking in RMB, not US$). Being a fine upstanding establishment, the Hyatt purchases legal, <a href="http://en.wikipedia.org/wiki/DVD_player#Manufacture" target="_blank">licensed</a> electronic hardware for their rooms. {DH4 commentary: So hackers don&#8217;t notice that there&#8217;s a big blob of C4 installed in their computer?} Our room had a Panasonic DVD player. Being the gadget freak that I am, we had brought along a batch of DVD&#8217;s and a laptop, thinking we could watch movies on the laptop (because hotels in the US charge you $8 to watch 1 of the 13 bad movies they offer on Pay-per-view. {DH4 commentary: Hackers all play with &#8220;<a href="http://www.forbiddenplanet.co.uk/index.php?main_page=index&amp;cPath=2_878&amp;zenid=932fc3629f912705a326284bb5eb2501" target="_blank">dolls</a>&#8221; &#8211; <a href="http://www.imdb.com/name/nm0000246/" target="_blank">real men</a>&#160;<a href="http://www.nra.org/" target="_blank">shoot guns</a>}</p>  <p>Anyway, after a busy day of wandering around <a href="http://www.wikimapia.org/#lat=39.916451&amp;lon=116.390705&amp;z=13&amp;l=0&amp;m=a&amp;v=2" target="_blank">The Forbidden City</a>, the mom &amp; dad needed a break, so we decided to pop in a movie for the kids to watch. So we popped in our 100% legit copy of &#8220;<a href="http://www.imdb.com/title/tt0317219/" target="_blank">Cars</a>&#8221; (because my 2-year-old likes &#8220;<a href="http://www.imdb.com/character/ch0009186/" target="_blank">Lighting DeQueen</a>&#8221;). I saw 5 Chinese characters that, roughly translated said &#8220;The movie industry is far more interested in pointlessly trying to squeeze dollars from good customers than allowing those customers to use the product they purchased&#8221;. My movie was <a href="http://www.amazon.co.uk/gp/help/customer/display.html?ie=UTF8&amp;nodeId=502554" target="_blank">Region 1</a>. {DH4 commentary: Where is the army of hackers required to simultaneously take down every major network in the country? I don&#8217;t see this group represented anywhere.} And I&#8217;m living in Region 6. So I have a few alternatives: I can buy a legitimate Region 6 copy of the movie, I can buy pirated DVD&#8217;s, or I can download the movie. I leave it as an exercise for the reader to decide which one I prefer. {DH4 commentary: Hackers are only slightly squeamish when it comes to killing innocent civilians.} Here are a few hints: I&#8217;ve been here 5 weeks, and I still don&#8217;t know where to find legal DVD&#8217;s. There are 4 sellers of pirated DVD&#8217;s within 3 minutes walking distance of my apartment. My network connection is MUCH slower than it is in the states. {DH4 commentary: I believe destroying a helicopter with a car is more plausible than being able to make all the Anthrax alarms go off in every federal building in the capital simultaneously}</p>  <p>Honestly, if I&#8217;m in law enforcement, I believe I&#8217;d prefer people just <a href="http://www.isohunt.com/" target="_blank">download</a> their movies, because that doesn&#8217;t pump money into any pirate cartels &#8211; there&#8217;s no illegal manufacturing or illegal distribution channels required, just some schmuck with <a href="http://forum.handbrake.fr/" target="_blank">HandBrake</a> or <a href="http://en.wikipedia.org/wiki/DVD_Shrink" target="_blank">DVDShrink</a>, and a network connection. If I&#8217;m in the movie industry, I want <a href="http://en.wikipedia.org/wiki/Betamax" target="_blank">people</a> <a href="http://en.wikipedia.org/wiki/VHS" target="_blank">to</a> <a href="http://en.wikipedia.org/wiki/DVD-Video" target="_blank">re-purchase</a> <a href="http://en.wikipedia.org/wiki/HD_DVD" target="_blank">their</a> <a href="http://en.wikipedia.org/wiki/Blu-ray_Disc" target="_blank">movies</a>, I <a href="http://en.wikipedia.org/wiki/Durabis" target="_blank">guess</a>. But I&#8217;m not in either. {DH4 commentary: Kevin Smith stretches his talents as a thespian to play a Star Wars obsesses nerd. Honestly, his cameo has been the best part of the movie so far.} I&#8217;m a generally legit guy with a belief that while the customer may not always be right, if what I expect my customer to do causes them to spend both more money &amp; more time, I probably won&#8217;t have that customer for very long. {DH4 commentary: If someone who has a backup generator and a wall of video screens isn&#8217;t able to prevent some schmuck from <a href="http://en.wikipedia.org/wiki/Pwn" target="_blank">pwning</a> his webcam, we&#8217;re all screwed&#8230;} </p>  <p>I&#8217;m currently looking at <a href="http://www.hulu.com/" target="_blank">Hulu</a> and <a href="http://www.southparkstudios.com/" target="_blank">Comedy</a> <a href="http://www.thedailyshow.com/video/index.jhtml" target="_blank">Central</a> right now:&#160; Between the two of them, they have almost enough to let me quit shelling out $80/month to <a href="http://search.live.com/results.aspx?q=Comcast+sucks" target="_blank">ComCast</a> for the <a href="http://en.wikipedia.org/wiki/Lost_%28TV_series%29" target="_blank">privilege</a> <a href="http://en.wikipedia.org/wiki/My_name_is_earl" target="_blank">of</a> <a href="http://en.wikipedia.org/wiki/The_Office_%28U.S._TV_series%29" target="_blank">watching</a> <a href="http://en.wikipedia.org/wiki/Scrubs_%28TV_series%29" target="_blank">6</a> <a href="http://en.wikipedia.org/wiki/Heroes_%28TV_series%29" target="_blank">channels</a> (3 of which are in HD). Only 2 channels left (curse you, Noggin &amp; PBS Kids). Of course, my dependency on those two channels will be decreased to zero with a few years, but I&#8217;d rather just give my $80/month directly to ABC, NBC, Comedy Central, Noggin, and PBS, than continue to give it to ComCast. I wonder if they&#8217;ll take donations. (Yes, I know PBS does J)</p>  <p>{D4 commentary: When someone as big at Bruce Willis throws someone as small as the Evil Asian Kung Fu Hacker Woman through a bookshelf, the small EAKFHW does NOT stand back up for a very long time. Of course, Bruce Willis has already fallen, been beaten down, and generally been pummeled, so perhaps I&#8217;m just struggling with my &#8220;suspension of disbelief&#8221;. }</p>  <p>Well, my whining about the state of DRM video is about done, but this movie deserves a few more comments:</p>  <p>Does no one realize that systems like the natural gas pipeline have a PHYSICAL failsafe to prevent &#8220;all the gas from being routed down one pipe&#8221;? When you &#8220;have a gun to your head&#8221; you don&#8217;t spend time writing a UI for your new &#8220;encryption algorithm&#8221;. And, having been involved in software for, holy crap, almost 15 years now, even if you buy the basic premise of the movie (&#8220;A Fire Sale&#8221;), the level of complexity involved in getting that many different systems all controlled by a single central, accessible UI (they can get to a camera in a Rutger&#8217;s elevator in a few seconds &#8211; sounds like an amazingly good UI/navigation/control system to me) would take an army of people many many years to pull off. And while it&#8217;s all being designed, the systems trying to be pwned are constantly changing.</p>  <p>But I did learn one valuable lesson from this movie: nerdish folk who can write code are so disconnected form humanity that they must be forced to see the consequence of their theoretical actions by heroic types before they&#8217;ll begin to feel empathy for their fellow humans.&#160; <a href="http://www.crime-research.org/analytics/1527/" target="_blank">It's true.</a>&#160; Until I saw The Net, I was honestly dedicating my life to destroying civilization for fun.</p>  <p>If I had <a href="https://youtube.com/watch?v=NdD0cmhBdr0" target="_blank">stolen a car</a> that had this movie sitting on the passenger seat, I'd return the car to the rightful owner, and turn myself into the authorities.</p>]]></content:encoded>
    </item>
    <item>
      <title>Turning off comments for a while...</title>
      <link>https://docs.microsoft.com/archive/blogs/freik/turning-off-comments-for-a-while</link>
      <pubDate>Mon, 18 Feb 2008 14:31:00 GMT</pubDate>
      <dc:creator><![CDATA[Kevin Frei]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/freik/2008/02/18/turning-off-comments-for-a-while/</guid>
      <description><![CDATA[The spam bots have been causing me all sorts of trouble - I had over 1000 messages informing me that...]]></description>
      <content:encoded><![CDATA[<P>The spam bots have been causing me all sorts of trouble - I had over 1000 messages informing me that some spam has been deleted over the weekend.&nbsp; I'm going to kill comments, and hope that in a few months, (after I get a chance to write up something of value), the spam bots will have stopped attempting to comment on my blog.&nbsp; In the mean time, if you want to ask me a question, my email address is the title of my blog [freik] except my first initial comes _before_ my last name] at m1cr0s0ft.c0m, except everything is spelled properly, with i's and o's instead of 0's and 1's :-).&nbsp; I always try to reply to reasonable questions [note:&nbsp;&nbsp;asking me to troubleshoot software from a competitor and getting upset or insulting when I'm unable to help is _not_ reasonable], but I'll be operating from a very different timezone for a few months, so turn around may be different from what you would expect.</P>
<P>-Kev</P>]]></content:encoded>
    </item>
    <item>
      <title>Vista x64 Media Center 'fix'</title>
      <link>https://docs.microsoft.com/archive/blogs/freik/vista-x64-media-center-fix</link>
      <pubDate>Fri, 07 Sep 2007 12:52:00 GMT</pubDate>
      <dc:creator><![CDATA[Kevin Frei]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/freik/2007/09/07/vista-x64-media-center-fix/</guid>
      <description><![CDATA[&lt;RETRACTION&gt;
Crap.&nbsp; After getting a couple of comments saying they tried the same thing,...]]></description>
      <content:encoded><![CDATA[<P>&lt;RETRACTION&gt;</P>
<P>Crap.&nbsp; After getting a couple of comments saying they tried the same thing, and it didn't work for them, I went back and tried it myself.&nbsp; And it turns out it doesn't work.&nbsp; I think I had tried it with some media that I had already transcoded to WMV without realizing it.&nbsp; The reason it doesn't work is actually quite simple: The managed assemblies aren't pure IL - they're IJW images (lame-speak for "they contain some native code") so they're hard-tied to the platform they're shipped on.&nbsp; I also tried copying the 32 bit version and running them, to no avail.&nbsp; Ugh.&nbsp; Perhaps&nbsp;this will inspire folks to port some of their codecs?&nbsp; Heck, all I really want is FFDShow for x64, and I'd be happy...</P>
<P>UPDATE:&nbsp; <A class="" title="FFDShow is available for x64!" href="http://sourceforge.net/project/showfiles.php?group_id=173941" target=_blank mce_href="http://sourceforge.net/project/showfiles.php?group_id=173941">FFDSHOW is available for x64</A> :-)&nbsp; Still waiting for CoreAVC for x64... Scratch that:&nbsp; I really do prefer VC-1 and WMV.&nbsp; Transcoding takes a long time (at high quality) but the results are great...</P>
<P>&lt;/RETRACTION&gt;&nbsp;</P>
<P>&nbsp;Let me paint a scenario for you:</P>
<UL>
<LI>Because the DVD was just sitting there in your Vista Ultimate box, you installed x64 Vista instead of x86 Vista.</LI>
<LI>One of the only reasons you installed Vista to begin with is because the Vista Media Center product is much better than the old XP based Media Center.</LI>
<LI>You'll even tolerate the fact that the XBox Media Center Extender doesn't work with Vista (Options: buy an XBox 360, or have an XP MC running somewhere in the house [cuz XP MCE doesn't run on Virtual PC, even just to serve to an extender] - grrrr....)</LI>
<LI>You have a number of home movies taken before you paid attention to the fact that WMV is a great container &amp; codec, so there's 3 years worth of home movies in DivX form.</LI>
<LI>You open up Vista Media Center and start watching recent home movies - they look great!</LI>
<LI>2 weeks later, your wife opens up Vista Media Center, and calls you at work to tell you that all the home movies of your oldest daughter don't play!</LI>
<LI>You go home, launch each of the 70+ home movies from the command line (cuz you're a command line junkie) and they play just fine</LI>
<LI>You assume your wife must have had network problems or something, so you tell her they seem fine</LI>
<LI>3 days later, your wife calls you at work, tells you that she CHECKED the network (while she is no longer&nbsp;an employee of MSFT, and has spent the past decade interacting with children more than lead developers (which have a large amount in common), she is astonishingly technically savvy because she is forced to endure your own techno-centricity, bless her soul), and that you're either smoking crack, lying,&nbsp;or magic, because she still can't watch any videos of your oldest daughter from the media center.</LI></UL>
<P>Here's the problem:&nbsp; That cool 10 foot media center&nbsp;user interface?&nbsp; C#.&nbsp; UI code in general, because of the whole 'when&nbsp;am I actually done with this resource' aspect of UI code, seems to like&nbsp;garbage collection.&nbsp; I don't know if they use WPF (which looks pretty impressive - I've been messing with it a little, lately), but it's 99% C# code.&nbsp; C# code, by default, is processor agnostic - binaries produced by the C# compiler are flagged to run on ANY cpu.&nbsp; You can take identical binaries and run them on AMD64, x86, and yes, even IA64.&nbsp; And they work fine, in all 3 situations.&nbsp; However, if this managed code tries to use any native binaries on the machine (say, some DirectShow filters, for example), it can only use native binaries for the CPU type it is running on.&nbsp; Which means Media Center is running as a 64 bit app, and can only access the 64 bit codecs available on the machine.&nbsp; No ffdshow, no XviD, no DivX, no, not even any IV32.&nbsp; No problem, right?&nbsp; That's what corflags is for!&nbsp; "corflags.exe &lt;assembly&gt; /32bit+" - bzzzt - wrong answer.&nbsp; Windows Media Center, as part of the OS installation, is covered by a whole host of things to prevent people from screwing it up.&nbsp; In summary:&nbsp; You can't flag the Media Center binaries as 32bit because they won't even load (curse&nbsp;you, code signing and system file protection!).</P>
<P>There is a way to make it work, but it has the unfortunate side effect of making ALL managed code run as 32 bit.&nbsp; ldr64 is a utility that is included as part of the 64 bit CLR that does a single scary, system wide thing: it makes the managed loader think it's running on a 32 bit system, even when it's not.&nbsp; That's right:&nbsp; ldr64 setwow makes your entire computer think, for managed code, it's a 32 bit system.&nbsp; And it works pretty well.&nbsp; Don't do this on your SQL Server or anything, but my Media Center likes it much better when ffdshow is available to be used to show movies of my daughter back before she was losing molars, reading Harry Potter, having sleep overs, and generally being independent enough to make me feel far older than I actually am.</P>
<P>But wait, you say, weren't you smoking crack, lying, or perform some magic that made it work when you tried those media files from the command line?&nbsp; Nope - I was using WIndows Media Player, which, even on Vista x64, is a 32 bit native application.&nbsp; So it was loading 32 bit ffdshow and happily displaying my home movies to my heart's content.</P>
<P>One other minor note:&nbsp; I do find it slightly disconcerting that there's a flag to say IL is 32 bit only, but nothing to indicate that it's 64 bit only.&nbsp; There are plenty of things you can do in managed code (I've been told even verifiable managed code) that can force your code to be 64 bit only, or 32 bit only.&nbsp; The fact that you can only tie it one direction seems slightly sad to me.&nbsp; Oh well - unless you need the address space, the 64 bit managed platform isn't a really compelling platform, currently (okay, the extra registers are nice, but managed code uses pointers like they're char's, so the working set of most managed apps is tremendously higher when running as a 64 bit app, than as a 32 bit one)</P>
<P>-Kev</P>]]></content:encoded>
    </item>
    <item>
      <title>How not to benchmark different languages</title>
      <link>https://docs.microsoft.com/archive/blogs/freik/how-not-to-benchmark-different-languages</link>
      <pubDate>Mon, 11 Jun 2007 15:41:00 GMT</pubDate>
      <dc:creator><![CDATA[Kevin Frei]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/freik/2007/06/11/how-not-to-benchmark-different-languages/</guid>
      <description><![CDATA[I've recently been trolling the web for any sort of language-comparision benchmarks, to see how the...]]></description>
      <content:encoded><![CDATA[<P>I've recently been trolling the web for any sort of language-comparision benchmarks, to see how the CLR's JIT stacks up to the competition.&nbsp; Dr. Dobbs has what seemed to be a pretty reasonable <A class="" href="http://www.ddj.com/dept/cpp/184401976" target=_blank mce_href="http://www.ddj.com/dept/cpp/184401976">micro-benchmark article</A>.&nbsp; It's not particularly insightful, but hey, it is hard to come up with stuff that makes sense to compare across multiple disparate languages.&nbsp; I started looking for specific C# to Java comparisons and came upon this little <A class="" href="http://www.javaperformancetuning.com/news/qotm028.shtml" target=_blank mce_href="http://www.javaperformancetuning.com/news/qotm028.shtml">gem</A>.&nbsp; I'll give you a few minutes to read it.</P>
<P>Now that you've read it, I would like to challenge you to understand how anyone would ever believe the question of "How long does it take to do nothing 1 billion times" in any language is worth comparing.&nbsp; Seriously, ignore the thoughts regarding whether the comparison itself was fair or not.&nbsp; The best part of that article is that the Java JIT they seem to be pushing doesn't get rid of the empty loops in a newer version.&nbsp;&nbsp;Then look at their 'testing methodology' (or the lack thereof).&nbsp; Not only are they not actually benchmarking anything that anyone with a brain in their head would care about, but they didn't even bother to figure out how use the tools that they claim to be comparing against.&nbsp; Does anyone that actually <EM>uses </EM>C++* think that if they care about performance they're not going to enable the optimizer?&nbsp; Every reasonable C++ compiler on the planet will completely eliminate the loops if only told to optimize.&nbsp; And then the comparison against Assembly stuck in my craw.&nbsp; Assembly is there because you KNOW WHAT YOU'RE DOING!!!!&nbsp; If an assembly programmer writes a loop that iterates for a billion times, it's probably because they're trying to measure some particular pattern of code on the CPU they're running.</P>
<P>So (still snickering at the previous stuff), I guess I'm asking for input:&nbsp; Does anyone have any non-micro-benchmark relatively objective managed code comparison links they'd recommend?&nbsp; I'd really like to see how the CLR's JIT stacks up against some of the JVM's out there, for more than just little tiny toy code samples.</P>
<P>I'm also interested in 'end-to-end' timing, which includes JIT time.&nbsp; Microbenchmarks with internal clocks don't tell you how long something actually ran for.&nbsp; If a JIT takes 5 minutes to figure out it can remove 2 dead loops, your runtime isn't less than 1 second - it's less than 5 minutes and 1 second.</P>
<P>-Kev</P>
<P>* I found 4 different syntax errors in the C++ source code they provided...</P>
<P mce_keep="true">&nbsp;</P>]]></content:encoded>
    </item>
    <item>
      <title>Boost 1.34.0 and how to get it to build for AMD64...</title>
      <link>https://docs.microsoft.com/archive/blogs/freik/boost-1-34-0-and-how-to-get-it-to-build-for-amd64</link>
      <pubDate>Thu, 07 Jun 2007 23:37:00 GMT</pubDate>
      <dc:creator><![CDATA[Kevin Frei]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/freik/2007/06/07/boost-1-34-0-and-how-to-get-it-to-build-for-amd64/</guid>
      <description><![CDATA[I've recently been deluged by a pile of new electronic gadgets* so that I haven't had time to do...]]></description>
      <content:encoded><![CDATA[<P>I've recently been deluged by a pile of new electronic gadgets* so that I haven't had time to do much coding.&nbsp; So I was looking around yesterday and found that there's (finally) a new version of Boost available.&nbsp; I was actually underwhelmed by the lack of interesting new libraries that have been added (there have been a number of interesting libraries approved, but the only one of the group that have been approved that I was anxious to use trivially was Xpressive - I might rip out "for each" from my source code to try BOOST_FOREACH instead, too).&nbsp; That aside, I immediately discovered that they removed support for BJam V1, and require BJam V2.&nbsp; It took me another 2 hours of digging to figure out how to build the 64 bit libraries with the new build system.&nbsp; Here's how you do it:</P><PRE>bjam toolset=msvc address-model=64 stage</PRE>
<P>And, voila - amd64 builds.&nbsp; For the discerning multi-proc engineer (most of us are now, right?) try adding a -j%NUMBER_OF_PROCESSORS% to that command line to use every CPU core your machine has [it builds quite quickly on my Core 2 Quad, and my 2x2 Opteron [faster on my Opteron, actually - the C++ compiler eats data cache for breakfast - I think the extra pipe to memory really helps].</P>
<P>And now, to explain the * above:</P>
<P>Over the past&nbsp;two or three months, I've splurged a lot on myself and/or my wife:</P>
<UL>
<LI><A class="" href="http://www.sonystyle.com/webapp/wcs/stores/servlet/ProductDisplay?catalogId=10551&amp;storeId=10151&amp;langId=-1&amp;productId=11035734" target=_blank mce_href="http://www.sonystyle.com/webapp/wcs/stores/servlet/ProductDisplay?catalogId=10551&amp;storeId=10151&amp;langId=-1&amp;productId=11035734">Sony HD-SR1 camcorder</A> - Good video quality - shockingly better than my old JVC GZ-27, and significantly better than any of the MiniDV camcorders I've owned. <A class="" href="http://en.wikipedia.org/wiki/AVCHD" target=_blank mce_href="http://en.wikipedia.org/wiki/AVCHD">AVCHD</A> is less than a great post-processing experience, right now, though</LI>
<LI><A class="" href="http://www.apple.com/ipodshuffle/" target=_blank mce_href="http://www.apple.com/ipodshuffle/">Apple iPod Shuffle</A> - Fabulous form factor, super-crappy <A class="" href="http://www.apple.com/itunes/" target=_blank mce_href="http://www.apple.com/itunes/">software</A> - one of the devs on my team said that I must be using it in a way that Steve Jobs doesn't, because that's the only way Apple tests their products.&nbsp; I would have waited to get a <A class="" href="http://us.creative.com/products/product.asp?category=213&amp;subcategory=214&amp;product=16424" target=_blank mce_href="http://us.creative.com/products/product.asp?category=213&amp;subcategory=214&amp;product=16424">Creative Labs Stone</A> for half the price, but it was a gift for my wife for her birthday, and the Stone wasn't yet available.&nbsp; Seriously, why do I need a $#@@ driver to use a %#@# flash device?&nbsp; To be fair with my complaints, the Zune does the same thing.&nbsp; Lame lame lame lame.&nbsp; Everyone else on the planet calls 'em USB storage devices, what is wrong with Apple and Microsoft?</LI>
<LI><A class="" href="http://www.rokulabs.com/products_soundbridge.php" target=_blank mce_href="http://www.rokulabs.com/products_soundbridge.php">Roku SoundBridge M500</A> - Great size, great audio quality, but it took forever for me to figure out that Windows Media Connect doesn't like to share audio files that are already on a network share.&nbsp; Once I migrated my music onto my media center, it actually navigated my 150+ Gigs of audio remarkably well, and handles <A class="" href="http://blogs.msdn.com/freik/archive/2005/09/27/474625.aspx" target=_blank mce_href="http://blogs.msdn.com/freik/archive/2005/09/27/474625.aspx">lossless WMA </A>like a champ!</LI>
<LI><A class="" title="Bose Companion 2 Speakers" href="http://www.bose.com/controller?event=VIEW_PRODUCT_PAGE_EVENT&amp;product=companion2_multimedia_index" target=_blank mce_href="http://www.bose.com/controller?event=VIEW_PRODUCT_PAGE_EVENT&amp;product=companion2_multimedia_index">Bose Companion 2 speakers</A> - Fabulous audio quality, nice looking desing - attached to the SoundBridge in our master bathroom - All my wife needs now is a hot plate and she could live in the master bathroom</LI>
<LI>Final not-so-electronic not-so-gadget:&nbsp; <A class="" href="http://www.ellsworthbikes.com/bikes/epiphany/default.aspx" target=_blank mce_href="http://www.ellsworthbikes.com/bikes/epiphany/default.aspx">Ellsworth Epiphany</A> mountain bike, built up with most SRAM X.9 components.&nbsp; This thing climbs better than my 1997 GT aluminum hard tail.&nbsp; It's much bigger than my GT, but weighs about the same, and I have no idea what I'll do with those 27 gears.&nbsp; I think I only ever used 19 of the 21 available on my GT.&nbsp; I picked it up on Monday night at REI [wouldn't have bought it except for their nice little test track demonstrated that it really does have <A class="" href="http://www.mtbr.com/reviews/Allmtn_Full_Suspension/product_125675.shtml" target=_blank mce_href="http://www.mtbr.com/reviews/Allmtn_Full_Suspension/product_125675.shtml">no weaknesses</A>], I've ridden it to work 2 days [in the rain, but I really didn't care], and I'll be riding it this weekend (probably in the mud) Saturday and Sunday morning.&nbsp; <A class="" href="http://www.bbtc.org/trails/show_trail.php?location_id=2" target=_blank mce_href="http://www.bbtc.org/trails/show_trail.php?location_id=2">St. Edwards park</A>, and perhaps I'll go visit the <A class="" href="http://www.bbtc.org/trails/show_trail.php?location_id=37" target=_blank mce_href="http://www.bbtc.org/trails/show_trail.php?location_id=37">Tape Worm</A> in Renton.</LI></UL>]]></content:encoded>
    </item>
    <item>
      <title>How to use RtlUnwindEx</title>
      <link>https://docs.microsoft.com/archive/blogs/freik/how-to-use-rtlunwindex</link>
      <pubDate>Thu, 15 Mar 2007 11:24:00 GMT</pubDate>
      <dc:creator><![CDATA[Kevin Frei]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/freik/2007/03/15/how-to-use-rtlunwindex/</guid>
      <description><![CDATA[Disclaimer:&nbsp; I've never actually written an unwind personality routine, so take what's here...]]></description>
      <content:encoded><![CDATA[<P>Disclaimer:&nbsp; I've never actually written an unwind personality routine, so take what's here with a grain of salt.</P>
<P>A few days back, I spent 30 minutes defending the C++ runtime's exception handling personality routine to the guy that has the less than enviable job of supporting the .Net Framework's exception handling personality routine.&nbsp; The eventual point to be learned is that the documentation for RtlUnwindEx is abysmal, and can cause the VC 8.0 C++ runtime to leak objects left and right.</P>
<P>The problem revolves around the C++ team's decision (which I fully support) to cause code compiled with /EHs or /EHsc flags to only invoke destructors when a C++ exception occurs.&nbsp; This means that if you take a hardware exception, call RaiseException yourself, or call&nbsp;longjmp&nbsp;none of your C++ destructors between the point of exception and the handler will be invoked. I've talked about why this is a good idea, but I'll sum it up with this:&nbsp; If that scenario seems bad to you, then you should be compiling your code with /EHa.</P>
<P>Anyway, back to the issue:&nbsp; Say I'm writing a 'personality routine' which will be inovked by the OS when an exception occurs.&nbsp; If you're writing the kind that requires that your handler initiates the second phase of unwind, you need to call RtlUnwindEx.&nbsp; The documentation, which is arguably&nbsp;bad (it's little more that a function declaration), indicates that the EXCEPTION_RECORD structure to pass in is <EM>optional</EM>.&nbsp; And that's true:&nbsp; the functions on the stack will still be unwound.&nbsp; But the personality routines for those functions might want to actually know that they're being invoked due to an exception, and not for something like a longjmp.&nbsp; So, if you have an exception record that <EM>could </EM>be passed to the RtlUnwindEx function, you <EM>should</EM>.&nbsp; If you don't, another personality routine might assume that there's not an exception to examine, and might decide to do something like NOT invoke the destructors for the object on the stack.</P>
<P>BTW - this bug exists only on x86, and only when you're crossing a managed code -&gt; native code boundary, in particularly weird scenarios.&nbsp; And I hope it's getting fixed :-)</P>
<P mce_keep="true">-Kev</P>]]></content:encoded>
    </item>
    <item>
      <title>AMD64 unwind info gotchas</title>
      <link>https://docs.microsoft.com/archive/blogs/freik/amd64-unwind-info-gotchas</link>
      <pubDate>Mon, 12 Mar 2007 13:34:00 GMT</pubDate>
      <dc:creator><![CDATA[Kevin Frei]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/freik/2007/03/12/amd64-unwind-info-gotchas/</guid>
      <description><![CDATA[I had a brief e-mail&nbsp;exchange with one of the devs on&nbsp;the optimizer team about a checkin...]]></description>
      <content:encoded><![CDATA[<P>I had a brief e-mail&nbsp;exchange with one of the devs on&nbsp;the optimizer team about a checkin he put up for review.&nbsp; He modified the compiler so that it only aligns the stack for functions that call other functions - that's the typical definition in compiler lingo of a 'leaf function'.&nbsp; My first response was "don't do that - you may still have to align for reasons A, B, &amp; C".&nbsp; To which he responded with a quote from the ABI doc that explicitly says you only have to align the stack if you're calling a function.&nbsp; So I started reading.&nbsp; Turns out, he's right (and so is the doc), but there are some really nasty gotchas involved.&nbsp; When we initially did this stuff, we just lived with the scenario where you might be wasting a bit more stack space...</P>
<P>The theme of the problems revolve around restrictions on encoding information in the unwind data. If you are saving XMM registers and have an unaligned stack pointer, you must use the SAVE_XMM128_FAR opcode because the SAVE_XMM128 opcode will only accept offsets in multiples of 16 bytes.&nbsp; Or I guess you could use MOVUPS instead of MOVAPS to save &amp; restore your XMM register, but I wouldn't recommend that on current hardware. Similarly, you have to use the ALLOC_LARGE descriptor for stack allocation of sizes that aren’t [n *&nbsp;8 + 8].&nbsp;ALLOC_LARGE actually has 2 variants - one that multiples by 8, and the other than doesn't.&nbsp; You can use the latter to allocate random amounts of data from the stack.&nbsp; But then if you want to use a frame pointer, you're going to be in a pretty weird spot, because it will have to be unaligned, as well. Unwind data dictates that you can only have a frame pointer that = RSP + 16 * [1-15].</P>
<P>I'll probably come back to this article &amp; add some nice hyperlinks to ABI details in the doc itself, but it's been a while since I blogged anything useful, so I figured I'd just get this out there quickly.</P>]]></content:encoded>
    </item>
  </channel>
</rss>