openbcm

Git mirror of https://github.com/Broadcom-Network-Switching-Software/OpenBCM
git clone git://git.finwo.net/mirror/broadcom/openbcm
Log | Files | Refs | README

compiler.h (22460B)


      1 /*
      2  * 
      3  * This license is set out in https://raw.githubusercontent.com/Broadcom-Network-Switching-Software/OpenBCM/master/Legal/LICENSE file.
      4  * 
      5  * Copyright 2007-2019 Broadcom Inc. All rights reserved.
      6  *
      7  * Compiler Specific defines and options
      8  */
      9 
     10 #ifndef _SAL_COMPILER_H
     11 #define _SAL_COMPILER_H
     12 
     13 /*
     14  * Define attributes according to compiler.
     15  * Currently we have used GNU C, Diab Data, and Borland compilers.
     16  */
     17 
     18 #define COMPILER_HAS_CONST
     19 #define COMPILER_HAS_STATIC
     20 #ifdef __GNUC__
     21 #if __GNUC__ > 7
     22 #define COMPILER_WILL_USE_STATIC
     23 #endif
     24 #endif
     25 
     26 #ifndef __KERNEL__
     27 #define COMPILER_HAS_DOUBLE
     28 #endif
     29 
     30 /*
     31  * Return a string containing the current FILE:LINE location in the code. 
     32  */
     33 #define __STRINGIFY(x) #x
     34 #define _STRINGIFY(x) __STRINGIFY(x)
     35 #ifndef FILE_LINE_STRING
     36 
     37 #define FILE_LINE_STRING() (__FILE__ ":" _STRINGIFY(__LINE__))
     38 
     39 #endif /* FILE_LINE_STRING */
     40 
     41 
     42 #if defined(__GNUC__) && !defined(__PEDANTIC__)
     43 
     44 #define COMPILER_HAS_LONGLONG
     45 #define COMPILER_HAS_LONGLONG_SHIFT
     46 #define COMPILER_HAS_LONGLONG_ADDSUB
     47 #define COMPILER_HAS_LONGLONG_MUL
     48 #define COMPILER_HAS_LONGLONG_DIV
     49 #define COMPILER_HAS_LONGLONG_ANDOR
     50 #define COMPILER_HAS_LONGLONG_COMPARE
     51 
     52 #if ((__GNUC__ * 10000) + (__GNUC_MINOR__ * 100) + __GNUC_PATCHLEVEL__) >= 30201
     53 /* gcc 3.2.1 is the earliest version known to support the format attribute
     54    when applied to function pointers. gcc 3.0.0 is known to *not* support
     55    this. */
     56 #define COMPILER_HAS_FUNCTION_POINTER_FORMAT_ATTRIBUTE
     57 #endif
     58 
     59 #ifndef __STRICT_ANSI__
     60 #define COMPILER_HAS_INLINE
     61 #endif
     62 
     63 #define COMPILER_ATTRIBUTE(_a)    __attribute__ (_a)
     64 #define    COMPILER_REFERENCE(_a)    ((void)(_a))
     65 #ifndef FUNCTION_NAME
     66 #define FUNCTION_NAME() (__FUNCTION__)
     67 #endif
     68 
     69 #elif (defined(__DCC__) && (__DCC__ == 1)) && !defined(__PEDANTIC__)
     70 
     71 #define COMPILER_HAS_LONGLONG
     72 #define COMPILER_HAS_LONGLONG_SHIFT
     73 #define COMPILER_HAS_LONGLONG_ADDSUB
     74 #define COMPILER_HAS_LONGLONG_MUL
     75 #define COMPILER_HAS_LONGLONG_DIV
     76 #define COMPILER_HAS_LONGLONG_ANDOR
     77 #define COMPILER_HAS_LONGLONG_COMPARE
     78 
     79 #define COMPILER_ATTRIBUTE(_a)
     80 #define    COMPILER_REFERENCE(_a)    ((void)(_a))
     81 
     82 #if (defined(DIAB_VER)) && (DIAB_VER == 4)
     83 /* Older versions of DCC do not support __FUNCTION__ */
     84 #define FUNCTION_NAME() FILE_LINE_STRING()
     85 #else
     86 #define FUNCTION_NAME() (__FUNCTION__)
     87 #endif
     88 
     89 #else /* !defined(__GNUC__) */
     90 
     91 #define COMPILER_ATTRIBUTE(_a)
     92 #define    COMPILER_REFERENCE(_a)    ((void)(_a))
     93 
     94 #ifndef FUNCTION_NAME
     95 /*
     96  * No portable ANSI method to accomplish this. 
     97  * Just return the location in the code instead. 
     98  */
     99 #define FUNCTION_NAME() FILE_LINE_STRING()
    100 
    101 #endif /* FUNCTION_NAME */
    102 
    103 #endif /* !defined(__GNUC__) */
    104 
    105 #ifdef SAND_PEDANTIC
    106 #define COMPILER_HAS_LONGLONG
    107 #define COMPILER_HAS_LONGLONG_SHIFT
    108 #define COMPILER_HAS_LONGLONG_ADDSUB
    109 #define COMPILER_HAS_LONGLONG_MUL
    110 #define COMPILER_HAS_LONGLONG_DIV
    111 #define COMPILER_HAS_LONGLONG_ANDOR
    112 #define COMPILER_HAS_LONGLONG_COMPARE
    113 /*
    114  * Relevant for logging facilities (BSL, ...)
    115  * E.g. Without this definition LOG_ERROR instead of FUNCTION name  prints C-code location and line number
    116  */
    117 #ifdef FUNCTION_NAME
    118 #undef FUNCTION_NAME
    119 #endif
    120 #define FUNCTION_NAME() (__FUNCTION__)
    121 
    122 #endif
    123 
    124 /* GreenHills compiler */
    125 #ifdef GHS
    126 #define COMPILER_HAS_LONGLONG
    127 #define COMPILER_HAS_LONGLONG_SHIFT
    128 #define COMPILER_HAS_LONGLONG_ADDSUB
    129 #define COMPILER_HAS_LONGLONG_MUL
    130 #define COMPILER_HAS_LONGLONG_DIV
    131 #define COMPILER_HAS_LONGLONG_ANDOR
    132 #define COMPILER_HAS_LONGLONG_COMPARE
    133 
    134 /* GreenHills compiler has __FUNCTION__ built-in macro not __func__ */
    135 #define __func__ __FUNCTION__
    136 #endif
    137 
    138 /*
    139  * __attribute__ for function pointers
    140  */
    141 #ifdef COMPILER_HAS_FUNCTION_POINTER_FORMAT_ATTRIBUTE
    142 #define COMPILER_ATTRIBUTE_FUNCTION_POINTER(_a)  COMPILER_ATTRIBUTE(_a)
    143 #else
    144 #define COMPILER_ATTRIBUTE_FUNCTION_POINTER(_a)
    145 #endif
    146 
    147 
    148 #ifdef __PEDANTIC__
    149 #define COMPILER_STRING_CONST_LIMIT    509
    150 #endif
    151 
    152 /*
    153  * Compiler overrides that can be configured in Make.local
    154  */
    155 #ifdef    COMPILER_OVERRIDE_NO_LONGLONG
    156 #undef    COMPILER_HAS_LONGLONG
    157 #undef    COMPILER_HAS_LONGLONG_SHIFT
    158 #undef    COMPILER_HAS_LONGLONG_ADDSUB
    159 #undef    COMPILER_HAS_LONGLONG_MUL
    160 #undef    COMPILER_HAS_LONGLONG_DIV
    161 #undef    COMPILER_HAS_LONGLONG_ANDOR
    162 #undef    COMPILER_HAS_LONGLONG_COMPARE
    163 #endif
    164 
    165 #ifdef    COMPILER_OVERRIDE_NO_DOUBLE
    166 #undef    COMPILER_HAS_DOUBLE
    167 #endif
    168 
    169 #ifdef    COMPILER_OVERRIDE_NO_INLINE
    170 #undef    COMPILER_HAS_INLINE
    171 #endif
    172 
    173 #ifdef    COMPILER_OVERRIDE_NO_CONST
    174 #undef    COMPILER_HAS_CONST
    175 #endif
    176 
    177 #ifdef    COMPILER_OVERRIDE_NO_STATIC
    178 #undef    COMPILER_HAS_STATIC
    179 #endif
    180 
    181 /*
    182  * 64-bit word order
    183  */
    184 
    185 #ifdef __BORLAND__
    186 /* The Borland cpp does not expand correctly in the macros below...sigh */
    187 static int u64_MSW = 1;
    188 static int u64_LSW = 0;
    189 #else
    190 # ifdef BE_HOST
    191 #  define u64_MSW    0
    192 #  define u64_LSW    1
    193 # else /* LE_HOST */
    194 #  define u64_MSW    1
    195 #  define u64_LSW    0
    196 # endif /* LE_HOST */
    197 #endif /* __BORLAND__ */
    198 
    199 /*
    200  * 64-bit type
    201  */
    202 
    203 #ifdef LONGS_ARE_64BITS
    204 
    205 #define COMPILER_64BIT
    206 #define    COMPILER_UINT64            unsigned long
    207 #define COMPILER_INT64                  long
    208 #define u64_H(v)            (((uint32 *) &(v))[u64_MSW])
    209 #define u64_L(v)            (((uint32 *) &(v))[u64_LSW])
    210 #define COMPILER_64_INIT(_hi, _lo)      ( (((long) (_hi)) << 32) | (_lo))
    211 
    212 #else /* !LONGS_ARE_64BITS */
    213 
    214 #ifdef COMPILER_HAS_LONGLONG
    215 
    216 #define COMPILER_64BIT
    217 #define    COMPILER_UINT64            unsigned long long
    218 #define COMPILER_INT64                  long long
    219 #define u64_H(v)            (((uint32 *) &(v))[u64_MSW])
    220 #define u64_L(v)            (((uint32 *) &(v))[u64_LSW])
    221 #define COMPILER_64_INIT(_hi, _lo)      ( (((long long) (_hi)) << 32) | (_lo))
    222 
    223 #else /* !COMPILER_HAS_LONGLONG */
    224 typedef struct sal_uint64_s { unsigned int u64_w[2]; } sal_uint64_t;
    225 typedef struct sal_int64_s  { int u64_w[2]; } sal_int64_t;
    226 
    227 #define COMPILER_UINT64     sal_uint64_t
    228 #define COMPILER_INT64      sal_int64_t
    229 #define u64_H(v)            ((v).u64_w[u64_MSW])
    230 #define u64_L(v)            ((v).u64_w[u64_LSW])
    231 
    232 #ifdef BE_HOST
    233 #define COMPILER_64_INIT(_hi, _lo)        { { _hi, _lo } }
    234 #else
    235 #define COMPILER_64_INIT(_hi, _lo)         { { _lo, _hi } }
    236 #endif
    237 
    238 #endif /* !COMPILER_HAS_LONGLONG */
    239 #endif /* LONGS_ARE_64BITS */
    240 
    241 /*
    242  * 32-/64-bit type conversions
    243  */
    244 
    245 #ifdef COMPILER_HAS_LONGLONG_SHIFT
    246 
    247 #define COMPILER_64_TO_32_LO(dst, src)  ((dst) = (uint32) (src))
    248 #define COMPILER_64_TO_32_HI(dst, src)  ((dst) = (uint32) ((src) >> 32))
    249 #define COMPILER_64_HI(src)     ((uint32) ((src) >> 32))
    250 #define COMPILER_64_LO(src)     ((uint32) (src))
    251 #define COMPILER_64_ZERO(dst)       ((dst) = 0)
    252 #define COMPILER_64_IS_ZERO(src)    ((src) == 0)
    253                                        
    254 
    255 #define COMPILER_64_SET(dst, src_hi, src_lo)                \
    256     ((dst) = (((uint64) ((uint32)(src_hi))) << 32) | ((uint64) ((uint32)(src_lo))))
    257 
    258 #define COMPILER_64_COPY(dst, src)                \
    259     (dst = src)
    260 
    261 
    262 #else /* !COMPILER_HAS_LONGLONG_SHIFT */
    263 
    264 #define COMPILER_64_TO_32_LO(dst, src)    ((dst) = u64_L(src))
    265 #define COMPILER_64_TO_32_HI(dst, src)    ((dst) = u64_H(src))
    266 #define COMPILER_64_HI(src)        u64_H(src)
    267 #define COMPILER_64_LO(src)        u64_L(src)
    268 #define COMPILER_64_ZERO(dst)        (u64_H(dst) = u64_L(dst) = 0)
    269 #define COMPILER_64_IS_ZERO(src)    (u64_H(src) == 0 && u64_L(src) == 0)
    270 
    271 #define COMPILER_64_SET(dst, src_hi, src_lo)                \
    272         do {                                \
    273             u64_H(dst) = (src_hi);                                  \
    274             u64_L(dst) = (src_lo);                                  \
    275         } while (0)
    276 
    277 #define COMPILER_64_COPY(dst, src)                \
    278         do {                                \
    279             u64_H(dst) = u64_H(src);                                  \
    280             u64_L(dst) = u64_L(src);                                  \
    281         } while (0)
    282 
    283 #endif /* !COMPILER_HAS_LONGLONG_SHIFT */
    284 
    285 /*
    286  * 64-bit addition and subtraction
    287  */
    288 
    289 #ifdef COMPILER_HAS_LONGLONG_ADDSUB
    290 
    291 #define COMPILER_64_ADD_64(dst, src)    ((dst) += (src))
    292 #define COMPILER_64_ADD_32(dst, src)    ((dst) += (src))
    293 #define COMPILER_64_SUB_64(dst, src)    ((dst) -= (src))
    294 #define COMPILER_64_SUB_32(dst, src)    ((dst) -= (src))
    295 
    296 #else /* !COMPILER_HAS_LONGLONG_ADDSUB */
    297 
    298 #define COMPILER_64_ADD_64(dst, src)                    \
    299         do {                                \
    300         uint32 __t = u64_L(dst);                    \
    301         u64_L(dst) += u64_L(src);                    \
    302         if (u64_L(dst) < __t) {                    \
    303             u64_H(dst) += u64_H(src) + 1;                \
    304         } else {                            \
    305             u64_H(dst) += u64_H(src);                \
    306         }                                \
    307     } while (0)
    308 #define COMPILER_64_ADD_32(dst, src)                    \
    309         do {                                \
    310         uint32 __t = u64_L(dst);                    \
    311         u64_L(dst) += (src);                    \
    312         if (u64_L(dst) < __t) {                    \
    313             u64_H(dst)++;                        \
    314         }                                \
    315     } while (0)
    316 #define COMPILER_64_SUB_64(dst, src)                    \
    317         do {                                \
    318         uint32 __t = u64_L(dst);                    \
    319         u64_L(dst) -= u64_L(src);                    \
    320         if (u64_L(dst) > __t) {                    \
    321             u64_H(dst) -= u64_H(src) + 1;                \
    322         } else {                            \
    323             u64_H(dst) -= u64_H(src);                \
    324         }                                \
    325     } while (0)
    326 #define COMPILER_64_SUB_32(dst, src)                    \
    327         do {                                \
    328         uint32 __t = u64_L(dst);                    \
    329         u64_L(dst) -= (src);                    \
    330         if (u64_L(dst) > __t) {                    \
    331             u64_H(dst)--;                        \
    332         }                                \
    333     } while (0)
    334 
    335 #endif /* !COMPILER_HAS_LONGLONG_ADDSUB */
    336 
    337 /*
    338  * 64-bit multiplication
    339  */
    340 
    341 #if defined COMPILER_HAS_LONGLONG_MUL && ! defined (__KERNEL__)
    342 
    343 #define COMPILER_64_UMUL_32(dst, src)    ((dst) *= (src))
    344 
    345 #else /* !(defined COMPILER_HAS_LONGLONG_MUL && ! defined (__KERNEL__)) */
    346 
    347 /* Multiply of unsigned 64-bit and unsigned 32-bit integers, no overflow handling  */
    348 #define COMPILER_64_UMUL_32(dst, src)                                   \
    349     do {                                                                \
    350         uint32 __d[4];                                                  \
    351         uint32 __s[2];                                                  \
    352         uint32 __r[4];                                                  \
    353         uint32 __t[2];                                                  \
    354         __d[0] = u64_L(dst) & 0xffff;                                   \
    355         __d[1] = u64_L(dst) >> 16;                                      \
    356         __d[2] = u64_H(dst) & 0xffff;                                   \
    357         __d[3] = u64_H(dst) >> 16;                                      \
    358         __s[0] = (src) & 0xffff;                                        \
    359         __s[1] = (src) >> 16;                                           \
    360         __r[0] = __d[0] * __s[0];                                       \
    361         __r[1] = __d[1] * __s[0] + __d[0] * __s[1];                     \
    362         __r[2] = __d[2] * __s[0] + __d[1] * __s[1];                     \
    363         __r[3] = __d[3] * __s[0] + __d[2] * __s[1];                     \
    364         __t[0] = __r[1] << 16;                                          \
    365         __t[1] = __t[0] + __r[0];                                       \
    366         COMPILER_64_SET((dst), (__r[3] << 16) + __r[2] + (__r[1] >> 16) + (__t[1] < __t[0] ? 1 : 0), \
    367                         __t[1]                                          \
    368                         );                                              \
    369     } while (0);
    370 
    371 #endif /* !COMPILER_HAS_LONGLONG_MUL */
    372 
    373 /*
    374  * 64-bit logical operations
    375  */
    376 
    377 #ifdef COMPILER_HAS_LONGLONG_ANDOR
    378 
    379 #define COMPILER_64_AND(dst, src)    ((dst) &= (src))
    380 #define COMPILER_64_OR(dst, src)    ((dst) |= (src))
    381 #define COMPILER_64_XOR(dst, src)    ((dst) ^= (src))
    382 #define COMPILER_64_NOT(dst)        ((dst) = ~(dst))
    383 
    384 #else /* !COMPILER_HAS_LONGLONG_ANDOR */
    385 
    386 #define COMPILER_64_AND(dst, src)                    \
    387     do {                                \
    388         u64_H((dst)) &= u64_H((src));                    \
    389         u64_L((dst)) &= u64_L((src));                    \
    390     } while (0)
    391 #define COMPILER_64_OR(dst, src)                    \
    392     do {                                \
    393         u64_H((dst)) |= u64_H((src));                    \
    394         u64_L((dst)) |= u64_L((src));                    \
    395     } while (0)
    396 #define COMPILER_64_XOR(dst, src)                    \
    397     do {                                \
    398         u64_H((dst)) ^= u64_H((src));                    \
    399         u64_L((dst)) ^= u64_L((src));                    \
    400     } while (0)
    401 #define COMPILER_64_NOT(dst)                        \
    402     do {                                \
    403         u64_H((dst)) = ~u64_H((dst));                    \
    404         u64_L((dst)) = ~u64_L((dst));                    \
    405     } while (0)
    406 
    407 #endif /* !COMPILER_HAS_LONGLONG_ANDOR */
    408 
    409 #define COMPILER_64_ALLONES(dst)   \
    410     COMPILER_64_ZERO((dst));\
    411     COMPILER_64_NOT((dst))
    412 
    413 /*
    414  * 64-bit shift
    415  */
    416 
    417 #ifdef COMPILER_HAS_LONGLONG_SHIFT
    418 
    419 #define COMPILER_64_SHL(dst, bits)    ((dst) <<= (bits))
    420 #define COMPILER_64_SHR(dst, bits)    ((dst) >>= (bits))
    421 
    422 #define COMPILER_64_BITTEST(val, n)     \
    423     ((((uint64)val) & (((uint64) 1)<<(n))) != ((uint64) 0))
    424 
    425 #else /* !COMPILER_HAS_LONGLONG_SHIFT */
    426 
    427 #define COMPILER_64_SHL(dst, bits)                    \
    428     do {                                \
    429         int __b = (bits);                        \
    430         if (__b >= 32) {                        \
    431         u64_H(dst) = u64_L(dst);                \
    432         u64_L(dst) = 0;                        \
    433         __b -= 32;                        \
    434         }                                \
    435         u64_H(dst) = (u64_H(dst) << __b) |                \
    436         (__b ? u64_L(dst) >> (32 - __b) : 0);            \
    437         u64_L(dst) <<= __b;                        \
    438     } while (0)
    439 
    440 #define COMPILER_64_SHR(dst, bits)                    \
    441     do {                                \
    442         int __b = (bits);                        \
    443         if (__b >= 32) {                        \
    444         u64_L(dst) = u64_H(dst);                \
    445         u64_H(dst) = 0;                        \
    446         __b -= 32;                        \
    447         }                                \
    448         u64_L(dst) = (u64_L(dst) >> __b) |                \
    449         (__b ? u64_H(dst) << (32 - __b) : 0);            \
    450         u64_H(dst) >>= __b;                        \
    451     } while (0)
    452 
    453 #define COMPILER_64_BITTEST(val, n)     \
    454     ( (((n) < 32) && (u64_L(val) & (1 << (n)))) || \
    455       (((n) >= 32) && (u64_H(val) & (1 << ((n) - 32)))) )
    456 
    457 #endif /* !COMPILER_HAS_LONGLONG_SHIFT */
    458 
    459 /*
    460  * 64-bit compare operations
    461  */
    462 
    463 #ifdef COMPILER_HAS_LONGLONG_COMPARE
    464 
    465 #define COMPILER_64_EQ(src1, src2)    ((src1) == (src2))
    466 #define COMPILER_64_NE(src1, src2)    ((src1) != (src2))
    467 #define COMPILER_64_LT(src1, src2)    ((src1) <  (src2))
    468 #define COMPILER_64_LE(src1, src2)    ((src1) <= (src2))
    469 #define COMPILER_64_GT(src1, src2)    ((src1) >  (src2))
    470 #define COMPILER_64_GE(src1, src2)    ((src1) >= (src2))
    471 
    472 #else /* !COMPILER_HAS_LONGLONG_COMPARE */
    473 
    474 #define COMPILER_64_EQ(src1, src2)    (u64_H(src1) == u64_H(src2) && \
    475                      u64_L(src1) == u64_L(src2))
    476 #define COMPILER_64_NE(src1, src2)    (u64_H(src1) != u64_H(src2) || \
    477                      u64_L(src1) != u64_L(src2))
    478 #define COMPILER_64_LT(src1, src2)    (u64_H(src1) < u64_H(src2) || \
    479                      ((u64_H(src1) == u64_H(src2) && \
    480                        u64_L(src1) < u64_L(src2))))
    481 #define COMPILER_64_LE(src1, src2)    (u64_H(src1) < u64_H(src2) || \
    482                      ((u64_H(src1) == u64_H(src2) && \
    483                        u64_L(src1) <= u64_L(src2))))
    484 #define COMPILER_64_GT(src1, src2)    (u64_H(src1) > u64_H(src2) || \
    485                      ((u64_H(src1) == u64_H(src2) && \
    486                        u64_L(src1) > u64_L(src2))))
    487 #define COMPILER_64_GE(src1, src2)    (u64_H(src1) > u64_H(src2) || \
    488                      ((u64_H(src1) == u64_H(src2) && \
    489                        u64_L(src1) >= u64_L(src2))))
    490 
    491 #endif /* !COMPILER_HAS_LONGLONG_COMPARE */
    492 
    493 /* Set up a mask of width bits offset lft_shft.  No error checking */
    494 #define COMPILER_64_MASK_CREATE(dst, width, lft_shift)                  \
    495     do {                                                                \
    496         COMPILER_64_ALLONES(dst);                                       \
    497         COMPILER_64_SHR((dst), (64 - (width)));                         \
    498         COMPILER_64_SHL((dst), (lft_shift));                            \
    499     } while (0)
    500 
    501 #define COMPILER_64_DELTA(src, last, new)\
    502         do { \
    503             COMPILER_64_ZERO(src);\
    504             COMPILER_64_ADD_64(src, new);\
    505             COMPILER_64_SUB_64(src, last);\
    506         } while(0)
    507 
    508 #define COMPILER_64_BITSET(dst, n)              \
    509         do {                                    \
    510             uint64 temp64;                      \
    511             COMPILER_64_SET(temp64, 0, 1);      \
    512             COMPILER_64_SHL(temp64, n);         \
    513             COMPILER_64_OR(dst, temp64);        \
    514         } while(0)
    515 
    516 #define COMPILER_64_BITCLR(dst, n)              \
    517         do {                                    \
    518             uint64 temp64;                      \
    519             COMPILER_64_SET(temp64, 0, 1);      \
    520             COMPILER_64_SHL(temp64, n);         \
    521             COMPILER_64_NOT(temp64);            \
    522             COMPILER_64_AND(dst, temp64);       \
    523         } while(0)
    524 
    525 /** dst[dst_offset:dest_offset+nof_bits] = src[src_offset:src_offset+nof_bits] */
    526 #define COMPILER_64_BITCOPY_RANGE(dst, dst_offset, src, src_offset, nof_bits)               \
    527         do {                                                                                \
    528             uint64 temp64;                                                                  \
    529             COMPILER_64_MASK_CREATE(temp64, nof_bits, dst_offset);                          \
    530             COMPILER_64_NOT(temp64);                                                        \
    531             COMPILER_64_AND(dst, temp64);                                                   \
    532             COMPILER_64_MASK_CREATE(temp64, nof_bits, src_offset);                          \
    533             COMPILER_64_AND(temp64, src);                                                   \
    534             COMPILER_64_SHR(temp64, src_offset);                                            \
    535             COMPILER_64_SHL(temp64, dst_offset);                                            \
    536             COMPILER_64_OR(dst, temp64);                                                    \
    537         } while(0)
    538 
    539 
    540  /*
    541   * 64-bit division
    542   */
    543 
    544 #if defined COMPILER_HAS_LONGLONG_DIV && ! defined (__KERNEL__)
    545 
    546 #define COMPILER_64_UDIV_64(dst, src)    ((dst) /= (src))
    547 
    548 #else /* !(defined COMPILER_HAS_LONGLONG_DIV && ! defined (__KERNEL__)) */
    549 
    550 /* Divide of unsigned 64-bit and unsigned 64-bit integers, no overflow handling  */
    551 #define COMPILER_64_UDIV_64(dst, src)                                       \
    552     do {                                                                \
    553         uint32 q_hi = 0, q_lo = 0;                                      \
    554         while( COMPILER_64_GE(dst, src) )                               \
    555             {                                                           \
    556                 COMPILER_64_SUB_64(dst, src);                           \
    557                 if (++q_lo == 0) ++q_hi;                                \
    558             }                                                           \
    559         COMPILER_64_SET(dst, q_hi, q_lo);                               \
    560     } while (0)
    561 
    562 #endif /* defined COMPILER_HAS_LONGLONG_DIV && ! defined (__KERNEL__) */
    563 
    564 #define COMPILER_64_UDIV_32(dst, src)                                   \
    565     do {                                                                \
    566            uint64 u64_src;                                              \
    567            COMPILER_64_SET(u64_src, 0, src);                            \
    568            COMPILER_64_UDIV_64(dst, u64_src);                           \
    569     } while(0)
    570 
    571  /*
    572   * 64-bit power: 
    573   * dst = base^exp 
    574   */
    575 #define COMPILER_64_UPOW(dst, base , exp)                            \
    576     do {                                                            \
    577            int exp_index;                                           \
    578            COMPILER_64_SET(dst, 0, 1);                              \
    579            for (exp_index = 0; exp_index < exp; exp_index++)        \
    580                         COMPILER_64_UMUL_32(dst, base);             \
    581     } while(0)
    582 
    583 /*
    584  * Some macros for double support
    585  *
    586  * You can use the COMPILER_DOUBLE macro
    587  * if you would prefer double precision, but it is not necessary.
    588  * If you need more control (or you need to print :), then
    589  * then you should use the COMPILER_HAS_DOUBLE macro explicitly.
    590  */
    591 #ifdef COMPILER_HAS_DOUBLE
    592 #define COMPILER_DOUBLE double
    593 #define COMPILER_DOUBLE_FORMAT "f"
    594 #define COMPILER_64_TO_DOUBLE(f, i64) \
    595     ((f) = COMPILER_64_HI(i64) * 4294967296.0 + COMPILER_64_LO(i64))
    596 #define COMPILER_32_TO_DOUBLE(f, i32) \
    597     ((f) = (double) (i32))
    598 #else
    599 #define COMPILER_DOUBLE uint32
    600 #define COMPILER_DOUBLE_FORMAT "u"
    601 #define COMPILER_64_TO_DOUBLE(f, i64) ((f) = COMPILER_64_LO(i64))
    602 #define COMPILER_32_TO_DOUBLE(f, i32) ((f) = (i32))
    603 #endif
    604 
    605 /*
    606  * Version of inline that is turned off for compilers that do
    607  * not support inline.
    608  */
    609 
    610 #ifndef INLINE
    611 # ifdef COMPILER_HAS_INLINE
    612 #  define INLINE    inline
    613 # else
    614 #  define INLINE
    615 # endif
    616 #endif /* !INLINE */
    617 
    618 /*
    619  * Version of const that is turned off for compilers that do
    620  * not support const.
    621  */
    622 
    623 #ifndef CONST
    624 # ifdef COMPILER_HAS_CONST
    625 #  define CONST        const
    626 # else
    627 #  define CONST
    628 # endif
    629 #endif /* !CONST */
    630 
    631 /*
    632  * Version of static that is turned off when BROADCOM_DEBUG is defined.
    633  * Some compilers/linkers/OSs do not put static symbols in the
    634  * symbol table, which can make debugging harder.
    635  */
    636 
    637 #ifndef STATIC
    638 #if defined(COMPILER_WILL_USE_STATIC) || (defined(COMPILER_HAS_STATIC) && !defined(BROADCOM_DEBUG))
    639 #  define STATIC    static
    640 # else
    641 #  define STATIC
    642 # endif
    643 #endif /* !STATIC */
    644 
    645 #endif    /* !_SAL_COMPILER_H */