/[jscoverage]/trunk/js/jscpucfg.cpp
ViewVC logotype

Diff of /trunk/js/jscpucfg.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 459 by siliconforks, Thu Oct 23 19:03:33 2008 UTC revision 460 by siliconforks, Sat Sep 26 23:15:22 2009 UTC
# Line 46  Line 46 
46    
47  #ifdef CROSS_COMPILE  #ifdef CROSS_COMPILE
48  #include <prtypes.h>  #include <prtypes.h>
 #define INT64 PRInt64  
 #else  
   
 /************************************************************************/  
   
 /* Generate cpucfg.h */  
   
 #if defined(XP_WIN) || defined(XP_OS2)  
 #ifdef WIN32  
 #if defined(__GNUC__)  
 #define INT64   long long  
 #else  
 #define INT64   _int64  
 #endif /* __GNUC__ */  
 #else  
 #define INT64   long  
 #endif  
 #else  
 #if defined(HPUX) || defined(__QNX__)  
 #define INT64   long  
 #else  
 #define INT64   long long  
 #endif  
49  #endif  #endif
50    
51  #endif /* CROSS_COMPILE */  /************************************************************************/
52    
53  #ifdef __GNUC__  #ifdef __GNUC__
54  #define NS_NEVER_INLINE __attribute__((noinline))  #define NS_NEVER_INLINE __attribute__((noinline))
# Line 84  Line 61 
61  #pragma no_inline(StackGrowthDirection)  #pragma no_inline(StackGrowthDirection)
62  #endif  #endif
63    
 typedef void *prword;  
   
 struct align_short {  
     char c;  
     short a;  
 };  
 struct align_int {  
     char c;  
     int a;  
 };  
 struct align_long {  
     char c;  
     long a;  
 };  
 struct align_int64 {  
     char c;  
     INT64 a;  
 };  
 struct align_fakelonglong {  
     char c;  
     struct {  
         long hi, lo;  
     } a;  
 };  
 struct align_float {  
     char c;  
     float a;  
 };  
 struct align_double {  
     char c;  
     double a;  
 };  
 struct align_pointer {  
     char c;  
     void *a;  
 };  
 struct align_prword {  
     char c;  
     prword a;  
 };  
   
 #define ALIGN_OF(type) \  
     (((char*)&(((struct align_##type *)0)->a)) - ((char*)0))  
   
 unsigned int bpb;  
   
 static int Log2(unsigned int n)  
 {  
     int log2 = 0;  
   
     if (n & (n-1))  
         log2++;  
     if (n >> 16)  
         log2 += 16, n >>= 16;  
     if (n >> 8)  
         log2 += 8, n >>= 8;  
     if (n >> 4)  
         log2 += 4, n >>= 4;  
     if (n >> 2)  
         log2 += 2, n >>= 2;  
     if (n >> 1)  
         log2++;  
     return log2;  
 }  
   
 /*  
  * Conceivably this could actually be used, but there is lots of code out  
  * there with ands and shifts in it that assumes a byte is exactly 8 bits,  
  * so forget about porting THIS code to all those non 8 bit byte machines.  
  */  
 static void BitsPerByte(void)  
 {  
     bpb = 8;  
 }  
   
64  static int NS_NEVER_INLINE StackGrowthDirection(int *dummy1addr)  static int NS_NEVER_INLINE StackGrowthDirection(int *dummy1addr)
65  {  {
66      int dummy2;      int dummy2;
# Line 168  Line 70 
70    
71  int main(int argc, char **argv)  int main(int argc, char **argv)
72  {  {
     int sizeof_char, sizeof_short, sizeof_int, sizeof_int64, sizeof_long,  
         sizeof_float, sizeof_double, sizeof_word, sizeof_dword;  
     int bits_per_int64_log2, align_of_short, align_of_int, align_of_long,  
         align_of_int64, align_of_float, align_of_double, align_of_pointer,  
         align_of_word;  
73      int dummy1;      int dummy1;
74    
     BitsPerByte();  
   
75      printf("#ifndef js_cpucfg___\n");      printf("#ifndef js_cpucfg___\n");
76      printf("#define js_cpucfg___\n\n");      printf("#define js_cpucfg___\n\n");
77    
78      printf("/* AUTOMATICALLY GENERATED - DO NOT EDIT */\n\n");      printf("/* AUTOMATICALLY GENERATED - DO NOT EDIT */\n\n");
79    
80  #ifdef CROSS_COMPILE  #ifdef CROSS_COMPILE
81  #if defined(IS_LITTLE_ENDIAN)  #if defined(__APPLE__)
82        /*
83         * Darwin NSPR uses the same MDCPUCFG (_darwin.cfg) for multiple
84         * processors, and determines which processor to configure for based
85         * on compiler predefined macros.  We do the same thing here.
86         */
87        printf("#ifdef __LITTLE_ENDIAN__\n");
88        printf("#define IS_LITTLE_ENDIAN 1\n");
89        printf("#undef  IS_BIG_ENDIAN\n");
90        printf("#else\n");
91        printf("#undef  IS_LITTLE_ENDIAN\n");
92        printf("#define IS_BIG_ENDIAN 1\n");
93        printf("#endif\n\n");
94    #elif defined(IS_LITTLE_ENDIAN)
95      printf("#define IS_LITTLE_ENDIAN 1\n");      printf("#define IS_LITTLE_ENDIAN 1\n");
96      printf("#undef  IS_BIG_ENDIAN\n\n");      printf("#undef  IS_BIG_ENDIAN\n\n");
97  #elif defined(IS_BIG_ENDIAN)  #elif defined(IS_BIG_ENDIAN)
# Line 193  Line 101 
101  #error "Endianess not defined."  #error "Endianess not defined."
102  #endif  #endif
103    
104      sizeof_char         = PR_BYTES_PER_BYTE;  #else
     sizeof_short        = PR_BYTES_PER_SHORT;  
     sizeof_int          = PR_BYTES_PER_INT;  
     sizeof_int64        = PR_BYTES_PER_INT64;  
     sizeof_long         = PR_BYTES_PER_LONG;  
     sizeof_float        = PR_BYTES_PER_FLOAT;  
     sizeof_double       = PR_BYTES_PER_DOUBLE;  
     sizeof_word         = PR_BYTES_PER_WORD;  
     sizeof_dword        = PR_BYTES_PER_DWORD;  
   
     bits_per_int64_log2 = PR_BITS_PER_INT64_LOG2;  
   
     align_of_short      = PR_ALIGN_OF_SHORT;  
     align_of_int        = PR_ALIGN_OF_INT;  
     align_of_long       = PR_ALIGN_OF_LONG;  
     align_of_int64      = PR_ALIGN_OF_INT64;  
     align_of_float      = PR_ALIGN_OF_FLOAT;  
     align_of_double     = PR_ALIGN_OF_DOUBLE;  
     align_of_pointer    = PR_ALIGN_OF_POINTER;  
     align_of_word       = PR_ALIGN_OF_WORD;  
   
 #else /* !CROSS_COMPILE */  
105    
106      /*      /*
107       * We don't handle PDP-endian or similar orders: if a short is big-endian,       * We don't handle PDP-endian or similar orders: if a short is big-endian,
# Line 296  Line 183 
183          }          }
184      }      }
185    
     sizeof_char         = sizeof(char);  
     sizeof_short        = sizeof(short);  
     sizeof_int          = sizeof(int);  
     sizeof_int64        = 8;  
     sizeof_long         = sizeof(long);  
     sizeof_float        = sizeof(float);  
     sizeof_double       = sizeof(double);  
     sizeof_word         = sizeof(prword);  
     sizeof_dword        = 8;  
   
     bits_per_int64_log2 = 6;  
   
     align_of_short      = ALIGN_OF(short);  
     align_of_int        = ALIGN_OF(int);  
     align_of_long       = ALIGN_OF(long);  
     if (sizeof(INT64) < 8) {  
         /* this machine doesn't actually support int64's */  
         align_of_int64  = ALIGN_OF(fakelonglong);  
     } else {  
         align_of_int64  = ALIGN_OF(int64);  
     }  
     align_of_float      = ALIGN_OF(float);  
     align_of_double     = ALIGN_OF(double);  
     align_of_pointer    = ALIGN_OF(pointer);  
     align_of_word       = ALIGN_OF(prword);  
   
186  #endif /* CROSS_COMPILE */  #endif /* CROSS_COMPILE */
187    
     printf("#define JS_BYTES_PER_BYTE   %dL\n", sizeof_char);  
     printf("#define JS_BYTES_PER_SHORT  %dL\n", sizeof_short);  
     printf("#define JS_BYTES_PER_INT    %dL\n", sizeof_int);  
     printf("#define JS_BYTES_PER_INT64  %dL\n", sizeof_int64);  
     printf("#define JS_BYTES_PER_LONG   %dL\n", sizeof_long);  
     printf("#define JS_BYTES_PER_FLOAT  %dL\n", sizeof_float);  
     printf("#define JS_BYTES_PER_DOUBLE %dL\n", sizeof_double);  
     printf("#define JS_BYTES_PER_WORD   %dL\n", sizeof_word);  
     printf("#define JS_BYTES_PER_DWORD  %dL\n", sizeof_dword);  
     printf("\n");  
   
     printf("#define JS_BITS_PER_BYTE    %dL\n", bpb);  
     printf("#define JS_BITS_PER_SHORT   %dL\n", bpb * sizeof_short);  
     printf("#define JS_BITS_PER_INT     %dL\n", bpb * sizeof_int);  
     printf("#define JS_BITS_PER_INT64   %dL\n", bpb * sizeof_int64);  
     printf("#define JS_BITS_PER_LONG    %dL\n", bpb * sizeof_long);  
     printf("#define JS_BITS_PER_FLOAT   %dL\n", bpb * sizeof_float);  
     printf("#define JS_BITS_PER_DOUBLE  %dL\n", bpb * sizeof_double);  
     printf("#define JS_BITS_PER_WORD    %dL\n", bpb * sizeof_word);  
     printf("\n");  
   
     printf("#define JS_BITS_PER_BYTE_LOG2   %dL\n", Log2(bpb));  
     printf("#define JS_BITS_PER_SHORT_LOG2  %dL\n", Log2(bpb * sizeof_short));  
     printf("#define JS_BITS_PER_INT_LOG2    %dL\n", Log2(bpb * sizeof_int));  
     printf("#define JS_BITS_PER_INT64_LOG2  %dL\n", bits_per_int64_log2);  
     printf("#define JS_BITS_PER_LONG_LOG2   %dL\n", Log2(bpb * sizeof_long));  
     printf("#define JS_BITS_PER_FLOAT_LOG2  %dL\n", Log2(bpb * sizeof_float));  
     printf("#define JS_BITS_PER_DOUBLE_LOG2 %dL\n", Log2(bpb * sizeof_double));  
     printf("#define JS_BITS_PER_WORD_LOG2   %dL\n", Log2(bpb * sizeof_word));  
     printf("\n");  
   
     printf("#define JS_ALIGN_OF_SHORT   %dL\n", align_of_short);  
     printf("#define JS_ALIGN_OF_INT     %dL\n", align_of_int);  
     printf("#define JS_ALIGN_OF_LONG    %dL\n", align_of_long);  
     printf("#define JS_ALIGN_OF_INT64   %dL\n", align_of_int64);  
     printf("#define JS_ALIGN_OF_FLOAT   %dL\n", align_of_float);  
     printf("#define JS_ALIGN_OF_DOUBLE  %dL\n", align_of_double);  
     printf("#define JS_ALIGN_OF_POINTER %dL\n", align_of_pointer);  
     printf("#define JS_ALIGN_OF_WORD    %dL\n", align_of_word);  
     printf("\n");  
   
     printf("#define JS_BYTES_PER_WORD_LOG2   %dL\n", Log2(sizeof_word));  
     printf("#define JS_BYTES_PER_DWORD_LOG2  %dL\n", Log2(sizeof_dword));  
     printf("#define JS_WORDS_PER_DWORD_LOG2  %dL\n", Log2(sizeof_dword/sizeof_word));  
     printf("\n");  
   
188      printf("#define JS_STACK_GROWTH_DIRECTION (%d)\n", StackGrowthDirection(&dummy1));      printf("#define JS_STACK_GROWTH_DIRECTION (%d)\n", StackGrowthDirection(&dummy1));
     printf("\n");  
   
     printf("#define JS_HAVE_LONG_LONG\n");  
     printf("\n");  
   
 #if defined __GNUC__ && defined __x86_64__  
     printf("#define HAVE_VA_LIST_AS_ARRAY 1\n");  
     printf("\n");  
 #endif  
189    
190      printf("#endif /* js_cpucfg___ */\n");      printf("#endif /* js_cpucfg___ */\n");
191    

Legend:
Removed from v.459  
changed lines
  Added in v.460

  ViewVC Help
Powered by ViewVC 1.1.24