home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / sys / mips / 916 < prev    next >
Encoding:
Text File  |  1992-09-03  |  1.8 KB  |  75 lines

  1. Newsgroups: comp.sys.mips
  2. Path: sparky!uunet!gatech!darwin.sura.net!jvnc.net!yale.edu!think.com!paperboy.osf.org!meissner
  3. From: meissner@osf.org (Michael Meissner)
  4. Subject: Re: mips cc word alignment
  5. In-Reply-To: nicholas@cton.cton.com's message of 2 Sep 92 21:31:10 GMT
  6. Message-ID: <MEISSNER.92Sep3142433@curley.osf.org>
  7. Sender: news@osf.org (USENET News System)
  8. Organization: Open Software Foundation
  9. References: <1992Sep2.213110.1916@cton.com>
  10. Date: 3 Sep 92 14:24:33
  11. Lines: 62
  12.  
  13. In article <1992Sep2.213110.1916@cton.com> nicholas@cton.cton.com (Nick Hennenfent) writes:
  14.  
  15. | Is there any way to make the mips cc compiler read
  16. | a word (32 bit) from a non (word) aligned address?
  17. | It seems like the LWL/LWR instructions make this feasible.
  18. | The #pragma pack directive seems to have no effect.
  19. | I know such a thing is not optimal but would be
  20. | convenient in certain circumstances.
  21.  
  22.     struct s { char a[4]; };
  23.  
  24.     int convert (p)
  25.          struct s *p;
  26.     {
  27.       union { struct s st; int i; } u;
  28.  
  29.       u.st = *p;
  30.       return u.i;
  31.     }
  32.  
  33. Produces the code (GCC 2.2.2 produces the same code):
  34.  
  35.         .verstamp    2 10
  36.         .text    
  37.         .align    2
  38.         .file    2 "foo.c"
  39.         .globl    convert
  40.         .loc    2 5
  41.      #   1    struct s { char a[4]; };
  42.      #   2    
  43.      #   3    int convert (p)
  44.      #   4         struct s *p;
  45.      #   5    {
  46.         .ent    convert 2
  47.     convert:
  48.         .option    O2
  49.         subu    $sp, 8
  50.         .frame    $sp, 8, $31
  51.         .loc    2 8
  52.      #   6      union { struct s st; int i; } u;
  53.      #   7    
  54.      #   8      u.st = *p;
  55.         addu    $14, $sp, 4
  56.         .set     noat
  57.         ulw    $1, 0($4)
  58.         usw    $1, 0($14)
  59.         .set     at
  60.         .loc    2 9
  61.      #   9      return u.i;
  62.         lw    $2, 4($sp)
  63.         addu    $sp, 8
  64.         j    $31
  65.         .end    convert
  66.  
  67. --
  68. Michael Meissner    email: meissner@osf.org        phone: 617-621-8861
  69. Open Software Foundation, 11 Cambridge Center, Cambridge, MA, 02142
  70.  
  71. You are in a twisty little passage of standards, all conflicting.
  72.