<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Arun Raghavan &#187; code</title>
	<atom:link href="http://arunraghavan.net/tag/code/feed/" rel="self" type="application/rss+xml" />
	<link>http://arunraghavan.net</link>
	<description>Extremely pithy tagline here</description>
	<lastBuildDate>Tue, 17 Aug 2010 14:31:16 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
		<item>
		<title>C# is killing me</title>
		<link>http://arunraghavan.net/2007/08/c-is-killing-me/</link>
		<comments>http://arunraghavan.net/2007/08/c-is-killing-me/#comments</comments>
		<pubDate>Sat, 18 Aug 2007 22:34:00 +0000</pubDate>
		<dc:creator>Arun</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[code]]></category>

		<guid isPermaLink="false">http://nemesis.accosted.net/blog/2007/08/c-is-killing-me/</guid>
		<description><![CDATA[Blame for this: static inline uint64_t get_ts() { uint32_t low, high; asm(“rdtsc” : “=a” (low), “=d” (high)); ts = high; return ((uint64_t)high &#60;&#60; 32) + low; } /* From kernel sources: include/asm-i386/processor.h / / * Generic CPUID function * clear %ecx since some cpus (Cyrix MII) do not set or clear %ecx * resulting in [...]]]></description>
			<content:encoded><![CDATA[<p>Blame <lj user="lazythoughts"> for this:</p>

<p><lj-cut text="How to read the Timestamp Counter register in C, and other handy assembly snippets for multicore programming:"><pre>static inline uint64_t get_ts()
{
    uint32_t low, high;
    <strong>asm</strong>(“rdtsc”
        : “=a” (low),
          “=d” (high));
    ts = high;
    return ((uint64_t)high &lt;&lt; 32) + low;
}</p>

<p>/* From kernel sources: include/asm-i386/processor.h <em>/
/</em>
 * Generic CPUID function
 * clear %ecx since some cpus (Cyrix MII) do not set or clear %ecx
 * resulting in stale register contents being returned.
 <em>/
inline void cpuid(unsigned int op, unsigned int *eax, unsigned int *ebx, \
            unsigned int *ecx, unsigned int *edx)
{
    <strong>asm</strong>(“cpuid”
        : “=a” (</em>eax),
          “=b” (<em>ebx),
          “=c” (</em>ecx),
          “=d” (*edx)
        : “0” (op), “c”(0));
}</p>

<p>/* Count the number of physical processor cores */
inline uint32_t get_num_cores()
{
    uint32_t eax, ebx, ecx, edx;</p>

<pre><code>/* figure out whether querying core count is allowed */
cpuid(0, &amp;eax, &amp;ebx, &amp;ecx, &amp;edx);

if (eax &gt;= 4) {
    cpuid(4, &amp;eax, &amp;ebx, &amp;ecx, &amp;edx);
    eax = ((eax &amp; 0xFC000000) &gt;&gt; 26) + 1;
}
else
    eax = 1;

return eax;
</code></pre>

<p>}</p>

<p>/* To figure out which CPU you’re on */
inline uint32_t get_apic_id()
{
    uint32_t eax, ebx, ecx, edx;
    cpuid(1, &amp;eax, &amp;ebx, &amp;ecx, &amp;edx);
    return (ebx >> 24);
}</pre></lj-cut></p>

<p>And to all the non-geeks out there &#8230; sorry. :-)</p>
]]></content:encoded>
			<wfw:commentRss>http://arunraghavan.net/2007/08/c-is-killing-me/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
