4
Copyright (c) 2004, Brian Hook
7
Redistribution and use in source and binary forms, with or without
8
modification, are permitted provided that the following conditions are
11
* Redistributions of source code must retain the above copyright
12
notice, this list of conditions and the following disclaimer.
14
* Redistributions in binary form must reproduce the above
15
copyright notice, this list of conditions and the following
16
disclaimer in the documentation and/or other materials provided
17
with the distribution.
19
* The names of this package'ss contributors contributors may not
20
be used to endorse or promote products derived from this
21
software without specific prior written permission.
24
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
27
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
28
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
29
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
30
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
31
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
32
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
34
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40
@brief Portable Open Source Harness primary source file
44
#if !defined FORCE_DOXYGEN
46
#if !defined POSH_NO_FLOAT
47
# define POSH_FLOAT_STRING "enabled"
49
# define POSH_FLOAT_STRING "disabled"
52
#if defined POSH_64BIT_INTEGER
53
# define POSH_64BIT_INTEGER_STRING "yes"
55
# define POSH_64BIT_INTEGER_STRING "no"
58
#if defined POSH_64BIT_POINTER
59
# define POSH_POINTER_STRING "64-bits"
61
# define POSH_POINTER_STRING "32-bits"
64
#if defined POSH_LITTLE_ENDIAN
65
# define IS_BIG_ENDIAN 0
67
# define NATIVE16 POSH_LittleU16
68
# define NATIVE32 POSH_LittleU32
69
# define NATIVE64 POSH_LittleU64
70
# define FOREIGN16 POSH_BigU16
71
# define FOREIGN32 POSH_BigU32
72
# define FOREIGN64 POSH_BigU64
74
# define IS_BIG_ENDIAN 1
76
# define NATIVE16 POSH_BigU16
77
# define NATIVE32 POSH_BigU32
78
# define NATIVE64 POSH_BigU64
79
# define FOREIGN16 POSH_LittleU16
80
# define FOREIGN32 POSH_LittleU32
81
# define FOREIGN64 POSH_LittleU64
82
#endif /* POSH_LITTLE_ENDIAN */
86
s_testBigEndian( void )
105
s_testSerialization( void )
107
posh_byte_t serbuf[ 8 ];
111
/* 16-bit serialization */
112
POSH_WriteU16ToLittle( serbuf, 0xABCD );
113
if ( ( tmp16 = POSH_ReadU16FromLittle( serbuf ) ) != 0xABCD )
115
return "*ERROR: failed little-endian 16-bit serialization test";
118
POSH_WriteU16ToBig( serbuf, 0xABCD );
119
if ( ( tmp16 = POSH_ReadU16FromBig( serbuf ) ) != 0xABCD )
121
return "*ERROR: failed big-endian 16-bit serialization test";
124
/* 32-bit serialization */
125
POSH_WriteU32ToLittle( serbuf, 0xABCD1234L );
126
if ( ( tmp32 = POSH_ReadU32FromLittle( serbuf ) ) != 0xABCD1234 )
128
return "*ERROR: failed little-endian 32-bit serialization test";
131
POSH_WriteU32ToBig( serbuf, 0xABCD1234L );
132
if ( ( tmp32 = POSH_ReadU32FromBig( serbuf ) ) != 0xABCD1234 )
134
return "*ERROR: failed big-endian 32-bit serialization test";
137
#if defined POSH_64BIT_INTEGER
139
#define REF64 POSH_U64(0xFEDCBA9876543210)
143
POSH_WriteU64ToLittle( serbuf, REF64 );
145
if ( ( tmp64 = POSH_ReadU64FromLittle( serbuf ) ) != REF64 )
147
return "*ERROR: failed little-endian 64-bit serialization test";
150
POSH_WriteU64ToBig( serbuf, REF64 );
152
if ( ( tmp64 = POSH_ReadU64FromBig( serbuf ) ) != REF64 )
154
return "*ERROR: failed big-endian 64-bit serialization test";
162
#if !defined POSH_NO_FLOAT
165
s_testFloatingPoint( void )
167
float fRef = 10.0f/30.0f;
168
double dRef = 10.0/30.0;
169
posh_byte_t dbuf[ 8 ];
173
fTmp = POSH_FloatFromLittleBits( POSH_LittleFloatBits( fRef ) );
177
return "*ERROR: POSH little endian floating point conversion failed. Please report this to poshlib@poshlib.org!\n";
180
fTmp = POSH_FloatFromBigBits( POSH_BigFloatBits( fRef ) );
183
return "*ERROR: POSH big endian floating point conversion failed. Please report this to poshlib@poshlib.org!\n";
186
POSH_DoubleBits( dRef, dbuf );
188
dTmp = POSH_DoubleFromBits( dbuf );
192
return "*ERROR: POSH double precision floating point serialization failed. Please report this to poshlib@poshlib.org!\n";
197
#endif /* !defined POSH_NO_FLOAT */
201
s_testEndianess( void )
203
/* check endianess */
204
if ( s_testBigEndian() != IS_BIG_ENDIAN )
206
return "*ERROR: POSH compile time endianess does not match run-time endianess verification. Please report this to poshlib@poshlib.org!\n";
209
/* make sure our endian swap routines work */
210
if ( ( NATIVE32( 0x11223344L ) != 0x11223344L ) ||
211
( FOREIGN32( 0x11223344L ) != 0x44332211L ) ||
212
( NATIVE16( 0x1234 ) != 0x1234 ) ||
213
( FOREIGN16( 0x1234 ) != 0x3412 ) )
215
return "*ERROR: POSH endianess macro selection failed. Please report this to poshlib@poshlib.org!\n";
218
/* test serialization routines */
222
#endif /* !defined FORCE_DOXYGEN */
225
Returns a string describing this platform's basic attributes.
227
POSH_GetArchString() reports on an architecture's statically determined
228
attributes. In addition, it will perform run-time verification checks
229
to make sure the various platform specific functions work. If an error
230
occurs, please contact me at poshlib@poshlib.org so we can try to resolve
231
what the specific failure case is.
232
@returns a string describing this platform on success, or a string in the
233
form "*ERROR: [text]" on failure. You can simply check to see if
234
the first character returned is '*' to verify an error condition.
237
POSH_GetArchString( void )
240
const char *s = "OS:.............."POSH_OS_STRING"\n"
241
"CPU:............."POSH_CPU_STRING"\n"
242
"endian:.........."POSH_ENDIAN_STRING"\n"
243
"ptr size:........"POSH_POINTER_STRING"\n"
244
"64-bit ints......"POSH_64BIT_INTEGER_STRING"\n"
245
"floating point..."POSH_FLOAT_STRING"\n"
246
"compiler........."POSH_COMPILER_STRING"\n";
249
err = s_testEndianess();
256
/* test serialization */
257
err = s_testSerialization();
264
#if !defined POSH_NO_FLOAT
265
/* check that our floating point support is correct */
266
err = s_testFloatingPoint();
278
/* ---------------------------------------------------------------------------*/
279
/* BYTE SWAPPING SUPPORT */
280
/* ---------------------------------------------------------------------------*/
282
* Byte swaps a 16-bit unsigned value
284
@ingroup ByteSwapFunctions
285
@param v [in] unsigned 16-bit input value to swap
286
@returns a byte swapped version of v
289
POSH_SwapU16( posh_u16_t v )
300
* Byte swaps a 16-bit signed value
302
@ingroup ByteSwapFunctions
303
@param v [in] signed 16-bit input value to swap
304
@returns a byte swapped version of v
305
@remarks This just calls back to the unsigned version, since byte swapping
306
is independent of sign. However, we still provide this function to
307
avoid signed/unsigned mismatch compiler warnings.
310
POSH_SwapI16( posh_i16_t v )
312
return ( posh_i16_t ) POSH_SwapU16( v );
316
* Byte swaps a 32-bit unsigned value
318
@ingroup ByteSwapFunctions
319
@param v [in] unsigned 32-bit input value to swap
320
@returns a byte swapped version of v
323
POSH_SwapU32( posh_u32_t v )
327
swapped = ( v & 0xFF ) << 24;
328
swapped |= ( v & 0xFF00 ) << 8;
329
swapped |= ( v >> 8 ) & 0xFF00;
330
swapped |= ( v >> 24 );
336
* Byte swaps a 32-bit signed value
338
@ingroup ByteSwapFunctions
339
@param v [in] signed 32-bit input value to swap
340
@returns a byte swapped version of v
341
@remarks This just calls back to the unsigned version, since byte swapping
342
is independent of sign. However, we still provide this function to
343
avoid signed/unsigned mismatch compiler warnings.
346
POSH_SwapI32( posh_i32_t v )
348
return ( posh_i32_t ) POSH_SwapU32( ( posh_u32_t ) v );
351
#if defined POSH_64BIT_INTEGER
353
* Byte swaps a 64-bit unsigned value
355
@param v [in] a 64-bit input value to swap
356
@ingroup SixtyFourBit
357
@returns a byte swapped version of v
360
POSH_SwapU64( posh_u64_t v )
364
posh_byte_t bytes[ 8 ];
370
tmp = u.bytes[ 0 ]; u.bytes[ 0 ] = u.bytes[ 7 ]; u.bytes[ 7 ] = tmp;
371
tmp = u.bytes[ 1 ]; u.bytes[ 1 ] = u.bytes[ 6 ]; u.bytes[ 6 ] = tmp;
372
tmp = u.bytes[ 2 ]; u.bytes[ 2 ] = u.bytes[ 5 ]; u.bytes[ 5 ] = tmp;
373
tmp = u.bytes[ 3 ]; u.bytes[ 3 ] = u.bytes[ 4 ]; u.bytes[ 4 ] = tmp;
379
* Byte swaps a 64-bit signed value
381
@param v [in] a 64-bit input value to swap
382
@ingroup SixtyFourBit
383
@returns a byte swapped version of v
386
POSH_SwapI64( posh_i64_t v )
388
return ( posh_i64_t ) POSH_SwapU64( ( posh_u64_t ) v );
391
#endif /* defined POSH_64BIT_INTEGER */
393
/* ---------------------------------------------------------------------------*/
394
/* IN-MEMORY SERIALIZATION */
395
/* ---------------------------------------------------------------------------*/
398
* Writes an unsigned 16-bit value to a little endian buffer
400
@ingroup MemoryBuffer
401
@param dst [out] pointer to the destination buffer, may not be NULL. Alignment doesn't matter.
402
@param value [in] host-endian unsigned 16-bit value
403
@returns a pointer to the location two bytes after dst
404
@remarks does no validation of the inputs
407
POSH_WriteU16ToLittle( void *dst, posh_u16_t value )
409
posh_u16_t *p16 = ( posh_u16_t * ) dst;
410
posh_byte_t *p = ( posh_byte_t * ) dst;
412
p[ 0 ] = value & 0xFF;
413
p[ 1 ] = ( value & 0xFF00) >> 8;
419
* Writes a signed 16-bit value to a little endian buffer
421
@ingroup MemoryBuffer
422
@param dst [out] pointer to the destination buffer, may not be NULL
423
@param value [in] host-endian signed 16-bit value
424
@returns a pointer to the location two bytes after dst
425
@remarks does no validation of the inputs. This simply calls
426
POSH_WriteU16ToLittle() with appropriate casting.
429
POSH_WriteI16ToLittle( void *dst, posh_i16_t value )
431
return ( posh_i16_t * ) POSH_WriteU16ToLittle( dst, ( posh_u16_t ) value );
435
* Writes an unsigned 32-bit value to a little endian buffer
437
@ingroup MemoryBuffer
438
@param dst [out] pointer to the destination buffer, may not be NULL
439
@param value [in] host-endian signed 32-bit value
440
@returns a pointer to the location four bytes after dst
441
@remarks does no validation of the inputs.
444
POSH_WriteU32ToLittle( void *dst, posh_u32_t value )
446
posh_u32_t *p32 = ( posh_u32_t * ) dst;
447
posh_byte_t *p = ( posh_byte_t * ) dst;
449
p[ 0 ] = ( value & 0xFF );
450
p[ 1 ] = ( value & 0xFF00 ) >> 8;
451
p[ 2 ] = ( value & 0xFF0000 ) >> 16;
452
p[ 3 ] = ( value & 0xFF000000 ) >> 24;
458
* Writes a signed 32-bit value to a little endian buffer
460
@ingroup MemoryBuffer
461
@param dst [out] pointer to the destination buffer, may not be NULL
462
@param value [in] host-endian signed 32-bit value
463
@returns a pointer to the location four bytes after dst
464
@remarks does no validation of the inputs. This simply calls
465
POSH_WriteU32ToLittle() with appropriate casting.
468
POSH_WriteI32ToLittle( void *dst, posh_i32_t value )
470
return ( posh_i32_t * ) POSH_WriteU32ToLittle( dst, ( posh_u32_t ) value );
474
* Writes an unsigned 16-bit value to a big endian buffer
476
@ingroup MemoryBuffer
477
@param dst [out] pointer to the destination buffer, may not be NULL
478
@param value [in] host-endian unsigned 16-bit value
479
@returns a pointer to the location two bytes after dst
480
@remarks does no validation of the inputs
483
POSH_WriteU16ToBig( void *dst, posh_u16_t value )
485
posh_u16_t *p16 = ( posh_u16_t * ) dst;
486
posh_byte_t *p = ( posh_byte_t * ) dst;
488
p[ 1 ] = ( value & 0xFF );
489
p[ 0 ] = ( value & 0xFF00 ) >> 8;
495
* Writes a signed 16-bit value to a big endian buffer
497
@ingroup MemoryBuffer
498
@param dst [out] pointer to the destination buffer, may not be NULL
499
@param value [in] host-endian signed 16-bit value
500
@returns a pointer to the location two bytes after dst
501
@remarks does no validation of the inputs. This simply calls
502
POSH_WriteU16ToLittle() with appropriate casting.
505
POSH_WriteI16ToBig( void *dst, posh_i16_t value )
507
return ( posh_i16_t * ) POSH_WriteU16ToBig( dst, ( posh_u16_t ) value );
511
* Writes an unsigned 32-bit value to a big endian buffer
513
@ingroup MemoryBuffer
514
@param dst [out] pointer to the destination buffer, may not be NULL
515
@param value [in] host-endian unsigned 32-bit value
516
@returns a pointer to the location four bytes after dst
517
@remarks does no validation of the inputs.
520
POSH_WriteU32ToBig( void *dst, posh_u32_t value )
522
posh_u32_t *p32 = ( posh_u32_t * ) dst;
523
posh_byte_t *p = ( posh_byte_t * ) dst;
525
p[ 3 ] = ( value & 0xFF );
526
p[ 2 ] = ( value & 0xFF00 ) >> 8;
527
p[ 1 ] = ( value & 0xFF0000 ) >> 16;
528
p[ 0 ] = ( value & 0xFF000000 ) >> 24;
534
* Writes a signed 32-bit value to a big endian buffer
536
@ingroup MemoryBuffer
537
@param dst [out] pointer to the destination buffer, may not be NULL
538
@param value [in] host-endian signed 32-bit value
539
@returns a pointer to the location four bytes after dst
540
@remarks does no validation of the inputs. This simply calls
541
POSH_WriteU32ToBig() with appropriate casting.
544
POSH_WriteI32ToBig( void *dst, posh_i32_t value )
546
return ( posh_i32_t * ) POSH_WriteU32ToBig( dst, ( posh_u32_t ) value );
549
#if defined POSH_64BIT_INTEGER
551
* Writes an unsigned 64-bit value to a little-endian buffer
553
@ingroup SixtyFourBit
554
@param dst [out] pointer to the destination buffer, may not be NULL
555
@param value [in] host-endian unsigned 64-bit value
556
@returns a pointer to the location eight bytes after dst
557
@remarks does no validation of the inputs.
560
POSH_WriteU64ToLittle( void *dst, posh_u64_t value )
562
posh_u64_t *p64 = ( posh_u64_t * ) dst;
563
posh_byte_t *p = ( posh_byte_t * ) dst;
566
for ( i = 0; i < 8; i++, value >>= 8 )
568
p[ i ] = ( posh_byte_t ) ( value & 0xFF );
575
* Writes a signed 64-bit value to a little-endian buffer
577
@ingroup SixtyFourBit
578
@param dst [out] pointer to the destination buffer, may not be NULL
579
@param value [in] host-endian unsigned 64-bit value
580
@returns a pointer to the location eight bytes after dst
581
@remarks does no validation of the inputs.
584
POSH_WriteI64ToLittle( void *dst, posh_i64_t value )
586
return ( posh_i64_t * ) POSH_WriteU64ToLittle( dst, ( posh_u64_t ) value );
590
* Writes an unsigned 64-bit value to a big-endian buffer
592
@ingroup SixtyFourBit
593
@param dst [out] pointer to the destination buffer, may not be NULL
594
@param value [in] host-endian unsigned 64-bit value
595
@returns a pointer to the location eight bytes after dst
596
@remarks does no validation of the inputs.
599
POSH_WriteU64ToBig( void *dst, posh_u64_t value )
601
posh_u64_t *p64 = ( posh_u64_t * ) dst;
602
posh_byte_t *p = ( posh_byte_t * ) dst;
605
for ( i = 0; i < 8; i++, value >>= 8 )
607
p[ 7-i ] = ( posh_byte_t ) ( value & 0xFF );
614
* Writes a signed 64-bit value to a big-endian buffer
616
@ingroup SixtyFourBit
617
@param dst [out] pointer to the destination buffer, may not be NULL
618
@param value [in] host-endian signed 64-bit value
619
@returns a pointer to the location eight bytes after dst
620
@remarks does no validation of the inputs.
623
POSH_WriteI64ToBig( void *dst, posh_i64_t value )
625
return ( posh_i64_t * ) POSH_WriteU64ToBig( dst, ( posh_u64_t ) value );
628
#endif /* POSH_64BIT_INTEGER */
630
/* ---------------------------------------------------------------------------*/
631
/* IN-MEMORY DESERIALIZATION */
632
/* ---------------------------------------------------------------------------*/
635
* Reads an unsigned 16-bit value from a little-endian buffer
636
@ingroup MemoryBuffer
637
@param src [in] source buffer
638
@returns host-endian unsigned 16-bit value
641
POSH_ReadU16FromLittle( const void *src )
644
posh_byte_t *p = ( posh_byte_t * ) src;
647
v |= ( ( posh_u16_t ) p[ 1 ] ) << 8;
653
* Reads a signed 16-bit value from a little-endian buffer
654
@ingroup MemoryBuffer
655
@param src [in] source buffer
656
@returns host-endian signed 16-bit value
659
POSH_ReadI16FromLittle( const void *src )
661
return ( posh_i16_t ) POSH_ReadU16FromLittle( src );
665
* Reads an unsigned 32-bit value from a little-endian buffer
666
@ingroup MemoryBuffer
667
@param src [in] source buffer
668
@returns host-endian unsigned 32-bit value
671
POSH_ReadU32FromLittle( const void *src )
674
posh_byte_t *p = ( posh_byte_t * ) src;
677
v |= ( ( posh_u32_t ) p[ 1 ] ) << 8;
678
v |= ( ( posh_u32_t ) p[ 2 ] ) << 16;
679
v |= ( ( posh_u32_t ) p[ 3 ] ) << 24;
685
* Reads a signed 32-bit value from a little-endian buffer
686
@ingroup MemoryBuffer
687
@param src [in] source buffer
688
@returns host-endian signed 32-bit value
691
POSH_ReadI32FromLittle( const void *src )
693
return ( posh_i32_t ) POSH_ReadU32FromLittle( src );
698
* Reads an unsigned 16-bit value from a big-endian buffer
699
@ingroup MemoryBuffer
700
@param src [in] source buffer
701
@returns host-endian unsigned 16-bit value
704
POSH_ReadU16FromBig( const void *src )
707
posh_byte_t *p = ( posh_byte_t * ) src;
710
v |= ( ( posh_u16_t ) p[ 0 ] ) << 8;
716
* Reads a signed 16-bit value from a big-endian buffer
717
@ingroup MemoryBuffer
718
@param src [in] source buffer
719
@returns host-endian signed 16-bit value
722
POSH_ReadI16FromBig( const void *src )
724
return ( posh_i16_t ) POSH_ReadU16FromBig( src );
728
* Reads an unsigned 32-bit value from a big-endian buffer
729
@ingroup MemoryBuffer
730
@param src [in] source buffer
731
@returns host-endian unsigned 32-bit value
734
POSH_ReadU32FromBig( const void *src )
737
posh_byte_t *p = ( posh_byte_t * ) src;
740
v |= ( ( posh_u32_t ) p[ 2 ] ) << 8;
741
v |= ( ( posh_u32_t ) p[ 1 ] ) << 16;
742
v |= ( ( posh_u32_t ) p[ 0 ] ) << 24;
748
* Reads a signed 32-bit value from a big-endian buffer
749
@ingroup MemoryBuffer
750
@param src [in] source buffer
751
@returns host-endian signed 32-bit value
754
POSH_ReadI32FromBig( const void *src )
756
return POSH_BigI32( (*(const posh_i32_t*)src ) );
759
#if defined POSH_64BIT_INTEGER
762
* Reads an unsigned 64-bit value from a little-endian buffer
763
@param src [in] source buffer
764
@returns host-endian unsigned 32-bit value
767
POSH_ReadU64FromLittle( const void *src )
770
posh_byte_t *p = ( posh_byte_t * ) src;
773
for ( i = 0; i < 8; i++ )
775
v |= ( ( posh_u64_t ) p[ i ] ) << (i*8);
782
* Reads a signed 64-bit value from a little-endian buffer
783
@param src [in] source buffer
784
@returns host-endian signed 32-bit value
787
POSH_ReadI64FromLittle( const void *src )
789
return ( posh_i64_t ) POSH_ReadU64FromLittle( src );
793
* Reads an unsigned 64-bit value from a big-endian buffer
794
@param src [in] source buffer
795
@returns host-endian unsigned 32-bit value
798
POSH_ReadU64FromBig( const void *src )
801
posh_byte_t *p = ( posh_byte_t * ) src;
804
for ( i = 0; i < 8; i++ )
806
v |= ( ( posh_u64_t ) p[ 7-i ] ) << (i*8);
813
* Reads an signed 64-bit value from a big-endian buffer
814
@param src [in] source buffer
815
@returns host-endian signed 32-bit value
818
POSH_ReadI64FromBig( const void *src )
820
return ( posh_i64_t ) POSH_ReadU64FromBig( src );
823
#endif /* POSH_64BIT_INTEGER */
825
/* ---------------------------------------------------------------------------*/
826
/* FLOATING POINT SUPPORT */
827
/* ---------------------------------------------------------------------------*/
829
#if !defined POSH_NO_FLOAT
831
/** @ingroup FloatingPoint
832
@param[in] f floating point value
833
@returns a little-endian bit representation of f
836
POSH_LittleFloatBits( float f )
846
return POSH_LittleU32( u.u32 );
850
* Extracts raw big-endian bits from a 32-bit floating point value
852
@ingroup FloatingPoint
853
@param f [in] floating point value
854
@returns a big-endian bit representation of f
857
POSH_BigFloatBits( float f )
867
return POSH_BigU32( u.u32 );
871
* Extracts raw, little-endian bit representation from a 64-bit double.
873
@param d [in] 64-bit double precision value
874
@param dst [out] 8-byte storage buffer
875
@ingroup FloatingPoint
876
@returns the raw bits used to represent the value 'd', in the form dst[0]=LSB
879
POSH_DoubleBits( double d, posh_byte_t dst[ 8 ] )
884
posh_byte_t bytes[ 8 ];
889
#if defined POSH_LITTLE_ENDIAN
890
dst[ 0 ] = u.bytes[ 0 ];
891
dst[ 1 ] = u.bytes[ 1 ];
892
dst[ 2 ] = u.bytes[ 2 ];
893
dst[ 3 ] = u.bytes[ 3 ];
894
dst[ 4 ] = u.bytes[ 4 ];
895
dst[ 5 ] = u.bytes[ 5 ];
896
dst[ 6 ] = u.bytes[ 6 ];
897
dst[ 7 ] = u.bytes[ 7 ];
899
dst[ 0 ] = u.bytes[ 7 ];
900
dst[ 1 ] = u.bytes[ 6 ];
901
dst[ 2 ] = u.bytes[ 5 ];
902
dst[ 3 ] = u.bytes[ 4 ];
903
dst[ 4 ] = u.bytes[ 3 ];
904
dst[ 5 ] = u.bytes[ 2 ];
905
dst[ 6 ] = u.bytes[ 1 ];
906
dst[ 7 ] = u.bytes[ 0 ];
911
* Creates a double-precision, 64-bit floating point value from a set of raw,
914
@ingroup FloatingPoint
915
@param src [in] little-endian byte representation of 64-bit double precision
917
@returns double precision floating point representation of the raw bits
918
@remarks No error checking is performed, so there are no guarantees that the
919
result is a valid number, nor is there any check to ensure that src is
920
non-NULL. BE CAREFUL USING THIS.
923
POSH_DoubleFromBits( const posh_byte_t src[ 8 ] )
928
posh_byte_t bytes[ 8 ];
931
#if defined POSH_LITTLE_ENDIAN
932
u.bytes[ 0 ] = src[ 0 ];
933
u.bytes[ 1 ] = src[ 1 ];
934
u.bytes[ 2 ] = src[ 2 ];
935
u.bytes[ 3 ] = src[ 3 ];
936
u.bytes[ 4 ] = src[ 4 ];
937
u.bytes[ 5 ] = src[ 5 ];
938
u.bytes[ 6 ] = src[ 6 ];
939
u.bytes[ 7 ] = src[ 7 ];
941
u.bytes[ 0 ] = src[ 7 ];
942
u.bytes[ 1 ] = src[ 6 ];
943
u.bytes[ 2 ] = src[ 5 ];
944
u.bytes[ 3 ] = src[ 4 ];
945
u.bytes[ 4 ] = src[ 3 ];
946
u.bytes[ 5 ] = src[ 2 ];
947
u.bytes[ 6 ] = src[ 1 ];
948
u.bytes[ 7 ] = src[ 0 ];
955
* Creates a floating point number from little endian bits
957
@ingroup FloatingPoint
958
@param bits [in] raw floating point bits in little-endian form
959
@returns a floating point number based on the given bit representation
960
@remarks No error checking is performed, so there are no guarantees that the
961
result is a valid number. BE CAREFUL USING THIS.
964
POSH_FloatFromLittleBits( posh_u32_t bits )
973
#if defined POSH_BIG_ENDIAN
974
u.u32 = POSH_SwapU32( u.u32 );
981
* Creates a floating point number from big-endian bits
983
@ingroup FloatingPoint
984
@param bits [in] raw floating point bits in big-endian form
985
@returns a floating point number based on the given bit representation
986
@remarks No error checking is performed, so there are no guarantees that the
987
result is a valid number. BE CAREFUL USING THIS.
990
POSH_FloatFromBigBits( posh_u32_t bits )
999
#if defined POSH_LITTLE_ENDIAN
1000
u.u32 = POSH_SwapU32( u.u32 );
1006
#endif /* !defined POSH_NO_FLOAT */