darwin-xnu/EXTERNAL_HEADERS/architecture/byte_order.h
<<
>>
Prefs
   1/*
   2 * Copyright (c) 2000-2004 Apple Computer, Inc. All rights reserved.
   3 *
   4 * @APPLE_LICENSE_HEADER_START@
   5 * 
   6 * The contents of this file constitute Original Code as defined in and
   7 * are subject to the Apple Public Source License Version 1.1 (the
   8 * "License").  You may not use this file except in compliance with the
   9 * License.  Please obtain a copy of the License at
  10 * http://www.apple.com/publicsource and read it before using this file.
  11 * 
  12 * This Original Code and all software distributed under the License are
  13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
  14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
  15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
  16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT.  Please see the
  17 * License for the specific language governing rights and limitations
  18 * under the License.
  19 * 
  20 * @APPLE_LICENSE_HEADER_END@
  21 */
  22/*
  23 * Copyright (c) 1992 NeXT Computer, Inc.
  24 *
  25 * Byte ordering conversion.
  26 */
  27
  28#ifndef _ARCHITECTURE_BYTE_ORDER_H_
  29#define _ARCHITECTURE_BYTE_ORDER_H_
  30 
  31typedef unsigned long NXSwappedFloat;
  32typedef unsigned long long NXSwappedDouble;
  33
  34#if defined (__ppc__) || defined(__ppc64__)
  35#include "architecture/ppc/byte_order.h"
  36#elif defined (__i386__)
  37#include "architecture/i386/byte_order.h"
  38#else
  39#error architecture not supported
  40#endif
  41
  42/*
  43 * Identify the byte order
  44 * of the current host.
  45 */
  46
  47enum NXByteOrder {
  48    NX_UnknownByteOrder,
  49    NX_LittleEndian,
  50    NX_BigEndian
  51};
  52
  53static __inline__
  54enum NXByteOrder
  55NXHostByteOrder(void)
  56{
  57    unsigned int        _x;
  58    
  59    _x = (NX_BigEndian << 24) | NX_LittleEndian;
  60        
  61    return ((enum NXByteOrder)*((unsigned char *)&_x));
  62}
  63
  64/*
  65 * The predicated versions
  66 * are defined here in terms
  67 * of the unpredicated ones.
  68 */
  69
  70#if     __BIG_ENDIAN__
  71
  72static __inline__
  73unsigned short
  74NXSwapBigShortToHost(
  75    unsigned short      x
  76)
  77{
  78    return (x);
  79}
  80
  81static __inline__
  82unsigned int
  83NXSwapBigIntToHost(
  84    unsigned int        x
  85)
  86{
  87    return (x);
  88}
  89
  90static __inline__
  91unsigned long
  92NXSwapBigLongToHost(
  93    unsigned long       x
  94)
  95{
  96    return (x);
  97}
  98
  99static __inline__
 100unsigned long long
 101NXSwapBigLongLongToHost(
 102    unsigned long long  x
 103)
 104{
 105    return (x);
 106}
 107
 108#ifndef KERNEL
 109
 110static __inline__
 111double
 112NXSwapBigDoubleToHost(
 113    NXSwappedDouble     x
 114)
 115{
 116    return NXConvertSwappedDoubleToHost(x);
 117}
 118
 119static __inline__
 120float
 121NXSwapBigFloatToHost(
 122    NXSwappedFloat      x
 123)
 124{
 125    return NXConvertSwappedFloatToHost(x);
 126}
 127
 128#endif /* KERNEL */
 129
 130static __inline__
 131unsigned short
 132NXSwapHostShortToBig(
 133    unsigned short      x
 134)
 135{
 136    return (x);
 137}
 138
 139static __inline__
 140unsigned int
 141NXSwapHostIntToBig(
 142    unsigned int        x
 143)
 144{
 145    return (x);
 146}
 147
 148static __inline__
 149unsigned long
 150NXSwapHostLongToBig(
 151    unsigned long       x
 152)
 153{
 154    return (x);
 155}
 156
 157static __inline__
 158unsigned long long
 159NXSwapHostLongLongToBig(
 160    unsigned long long  x
 161)
 162{
 163    return (x);
 164}
 165
 166#ifndef KERNEL
 167
 168static __inline__
 169NXSwappedDouble
 170NXSwapHostDoubleToBig(
 171    double              x
 172)
 173{
 174    return NXConvertHostDoubleToSwapped(x);
 175}
 176
 177static __inline__
 178NXSwappedFloat
 179NXSwapHostFloatToBig(
 180    float               x
 181)
 182{
 183    return NXConvertHostFloatToSwapped(x);
 184}
 185
 186#endif /* KERNEL */
 187
 188static __inline__
 189unsigned short
 190NXSwapLittleShortToHost(
 191    unsigned short      x
 192)
 193{
 194    return (NXSwapShort(x));
 195}
 196
 197static __inline__
 198unsigned int
 199NXSwapLittleIntToHost(
 200    unsigned int        x
 201)
 202{
 203    return (NXSwapInt(x));
 204}
 205
 206static __inline__
 207unsigned long
 208NXSwapLittleLongToHost(
 209    unsigned long       x
 210)
 211{
 212    return (NXSwapLong(x));
 213}
 214
 215static __inline__
 216unsigned long long
 217NXSwapLittleLongLongToHost(
 218    unsigned long long  x
 219)
 220{
 221    return (NXSwapLongLong(x));
 222}
 223
 224#ifndef KERNEL
 225
 226static __inline__
 227double
 228NXSwapLittleDoubleToHost(
 229    NXSwappedDouble     x
 230)
 231{
 232    return NXConvertSwappedDoubleToHost(NXSwapDouble(x));
 233}
 234
 235static __inline__
 236float
 237NXSwapLittleFloatToHost(
 238    NXSwappedFloat      x
 239)
 240{
 241    return NXConvertSwappedFloatToHost(NXSwapFloat(x));
 242}
 243
 244#endif /* KERNEL */
 245
 246static __inline__
 247unsigned short
 248NXSwapHostShortToLittle(
 249    unsigned short      x
 250)
 251{
 252    return (NXSwapShort(x));
 253}
 254
 255static __inline__
 256unsigned int
 257NXSwapHostIntToLittle(
 258    unsigned int        x
 259)
 260{
 261    return (NXSwapInt(x));
 262}
 263
 264static __inline__
 265unsigned long
 266NXSwapHostLongToLittle(
 267    unsigned long       x
 268)
 269{
 270    return (NXSwapLong(x));
 271}
 272
 273static __inline__
 274unsigned long long
 275NXSwapHostLongLongToLittle(
 276    unsigned long long  x
 277)
 278{
 279    return (NXSwapLongLong(x));
 280}
 281
 282#ifndef KERNEL
 283
 284static __inline__
 285NXSwappedDouble
 286NXSwapHostDoubleToLittle(
 287    double              x
 288)
 289{
 290    return NXSwapDouble(NXConvertHostDoubleToSwapped(x));
 291}
 292
 293static __inline__
 294NXSwappedFloat
 295NXSwapHostFloatToLittle(
 296    float               x
 297)
 298{
 299    return NXSwapFloat(NXConvertHostFloatToSwapped(x));
 300}
 301
 302#endif /* KERNEL */
 303#endif /*__BIG_ENDIAN__ */
 304
 305#if     __LITTLE_ENDIAN__
 306
 307static __inline__
 308unsigned short
 309NXSwapBigShortToHost(
 310    unsigned short      x
 311)
 312{
 313    return (NXSwapShort(x));
 314}
 315
 316static __inline__
 317unsigned int
 318NXSwapBigIntToHost(
 319    unsigned int        x
 320)
 321{
 322    return (NXSwapInt(x));
 323}
 324
 325static __inline__
 326unsigned long
 327NXSwapBigLongToHost(
 328    unsigned long       x
 329)
 330{
 331    return (NXSwapLong(x));
 332}
 333
 334static __inline__
 335unsigned long long
 336NXSwapBigLongLongToHost(
 337    unsigned long long  x
 338)
 339{
 340    return (NXSwapLongLong(x));
 341}
 342
 343static __inline__
 344double
 345NXSwapBigDoubleToHost(
 346    NXSwappedDouble     x
 347)
 348{
 349    return NXConvertSwappedDoubleToHost(NXSwapDouble(x));
 350}
 351
 352static __inline__
 353float
 354NXSwapBigFloatToHost(
 355    NXSwappedFloat      x
 356)
 357{
 358    return NXConvertSwappedFloatToHost(NXSwapFloat(x));
 359}
 360
 361static __inline__
 362unsigned short
 363NXSwapHostShortToBig(
 364    unsigned short      x
 365)
 366{
 367    return (NXSwapShort(x));
 368}
 369
 370static __inline__
 371unsigned int
 372NXSwapHostIntToBig(
 373    unsigned int        x
 374)
 375{
 376    return (NXSwapInt(x));
 377}
 378
 379static __inline__
 380unsigned long
 381NXSwapHostLongToBig(
 382    unsigned long       x
 383)
 384{
 385    return (NXSwapLong(x));
 386}
 387
 388static __inline__
 389unsigned long long
 390NXSwapHostLongLongToBig(
 391    unsigned long long  x
 392)
 393{
 394    return (NXSwapLongLong(x));
 395}
 396
 397static __inline__
 398NXSwappedDouble
 399NXSwapHostDoubleToBig(
 400    double              x
 401)
 402{
 403    return (NXSwapDouble(NXConvertHostDoubleToSwapped(x)));
 404}
 405
 406static __inline__
 407NXSwappedFloat
 408NXSwapHostFloatToBig(
 409    float               x
 410)
 411{
 412    return (NXSwapFloat(NXConvertHostFloatToSwapped(x)));
 413}
 414
 415static __inline__
 416unsigned short
 417NXSwapLittleShortToHost(
 418    unsigned short      x
 419)
 420{
 421    return (x);
 422}
 423
 424static __inline__
 425unsigned int
 426NXSwapLittleIntToHost(
 427    unsigned int        x
 428)
 429{
 430    return (x);
 431}
 432
 433static __inline__
 434unsigned long
 435NXSwapLittleLongToHost(
 436    unsigned long       x
 437)
 438{
 439    return (x);
 440}
 441
 442static __inline__
 443unsigned long long
 444NXSwapLittleLongLongToHost(
 445    unsigned long long  x
 446)
 447{
 448    return (x);
 449}
 450
 451static __inline__
 452double
 453NXSwapLittleDoubleToHost(
 454    NXSwappedDouble     x
 455)
 456{
 457    return NXConvertSwappedDoubleToHost(x);
 458}
 459
 460static __inline__
 461float
 462NXSwapLittleFloatToHost(
 463    NXSwappedFloat      x
 464)
 465{
 466    return NXConvertSwappedFloatToHost(x);
 467}
 468
 469static __inline__
 470unsigned short
 471NXSwapHostShortToLittle(
 472    unsigned short      x
 473)
 474{
 475    return (x);
 476}
 477
 478static __inline__
 479unsigned int
 480NXSwapHostIntToLittle(
 481    unsigned int        x
 482)
 483{
 484    return (x);
 485}
 486
 487static __inline__
 488unsigned long
 489NXSwapHostLongToLittle(
 490    unsigned long       x
 491)
 492{
 493    return (x);
 494}
 495
 496static __inline__
 497unsigned long long
 498NXSwapHostLongLongToLittle(
 499    unsigned long long  x
 500)
 501{
 502    return (x);
 503}
 504
 505static __inline__
 506NXSwappedDouble
 507NXSwapHostDoubleToLittle(
 508    double              x
 509)
 510{
 511    return NXConvertHostDoubleToSwapped(x);
 512}
 513
 514static __inline__
 515NXSwappedFloat
 516NXSwapHostFloatToLittle(
 517    float               x
 518)
 519{
 520    return NXConvertHostFloatToSwapped(x);
 521}
 522
 523#endif /* __LITTLE_ENDIAN__ */
 524
 525#endif  /* _ARCHITECTURE_BYTE_ORDER_H_ */
 526
lxr.linux.no kindly hosted by Redpill Linpro AS, provider of Linux consulting and operations services since 1995.