9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
From: Bakul Shah <bakul+plan9@bitblocks.com>
To: Fans of the OS Plan 9 from Bell Labs <9fans@cse.psu.edu>
Subject: Re: [9fans] fun and scary evil C code
Date: Wed, 19 Dec 2007 14:51:21 -0800	[thread overview]
Message-ID: <20071219225121.BF3715B42@mail.bitblocks.com> (raw)
In-Reply-To: Your message of "Wed, 19 Dec 2007 15:37:25 EST." <20071219203654.3714F1E8C1C@holo.morphisms.net>

> > #define TRIO_DOUBLE_INDEX(x) (((unsigned char *)&internalEndianMagic)[7-(x)
> ])
> 
> this is actually done in /sys/src/9/port/devcons.c too:
> 
> 	static uvlong uvorder = 0x0001020304050607ULL;
> 	
> 	static uchar*
> 	le2vlong(vlong *to, uchar *f)
> 	{
> 		uchar *t, *o;
> 		int i;
> 	
> 		t = (uchar*)to;
> 		o = (uchar*)&uvorder;
> 		for(i = 0; i < sizeof(vlong); i++)
> 			t[o[i]] = f[i];
> 		return f+sizeof(vlong);
> 	}
> 	
> 	static uchar*
> 	vlong2le(uchar *t, vlong from)
> 	{
> 		uchar *f, *o;
> 		int i;
> 	
> 		f = (uchar*)&from;
> 		o = (uchar*)&uvorder;
> 		for(i = 0; i < sizeof(vlong); i++)
> 			t[i] = f[o[i]];
> 		return t+sizeof(vlong);
> 	}
> 
> presotto wrote the code but said he learned the trick from ken.
> 
> there, of course, we have a real compiler and don't have to
> write uvlong constants as floating point numbers
> (wow that seems fragile).

Most likely the TRIO_DOUBLE_INDEX macro came from some code
from the pre-long-long days, when you had no other way to
write down an 8 byte value in host endian order (even in a
less than portable way).


  parent reply	other threads:[~2007-12-19 22:51 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-12-19 15:15 David Leimbach
2007-12-19 20:37 ` Russ Cox
2007-12-19 22:32   ` Robert William Fuller
2007-12-19 22:38     ` erik quanstrom
2007-12-19 22:51   ` Bakul Shah [this message]
2007-12-20  0:18   ` dave.l
2007-12-20  0:33     ` dave.l
2007-12-20  0:51       ` erik quanstrom
2007-12-20  9:29         ` roger peppe
2007-12-20 13:02           ` erik quanstrom
2007-12-20 16:29 Russ Cox

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20071219225121.BF3715B42@mail.bitblocks.com \
    --to=bakul+plan9@bitblocks.com \
    --cc=9fans@cse.psu.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).