|
From: <and...@us...> - 2006-04-09 13:12:12
|
Revision: 1238 Author: andreradke Date: 2006-04-09 06:11:39 -0700 (Sun, 09 Apr 2006) ViewCVS: http://svn.sourceforge.net/frontierkernel/?rev=1238&view=rev Log Message: ----------- Moved byte swapping code to byteorder.h from byteorder.c, making the latter obsolete, in order to inline the code for performance. Modified Paths: -------------- Frontier/trunk/Common/headers/byteorder.h Frontier/trunk/Common/source/byteorder.c Frontier/trunk/build_GNU/Makefile Frontier/trunk/build_XCode/Frontier.xcode/project.pbxproj Property Changed: ---------------- Frontier/trunk/Common/headers/byteorder.h Modified: Frontier/trunk/Common/headers/byteorder.h =================================================================== --- Frontier/trunk/Common/headers/byteorder.h 2006-04-09 11:48:40 UTC (rev 1237) +++ Frontier/trunk/Common/headers/byteorder.h 2006-04-09 13:11:39 UTC (rev 1238) @@ -1,77 +1,152 @@ - -/* $Id: $ */ - -/****************************************************************************** - - UserLand Frontier(tm) -- High performance Web content management, - object database, system-level and Internet scripting environment, - including source code editing and debugging. - - Copyright (C) 1992-2004 UserLand Software, Inc. - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - -******************************************************************************/ - -#ifndef byteorderinclude -#define byteorderinclude - -/* - 2006-04-08 aradke: determine native byte order and define byte swapping macros -*/ - -#if (defined(WIN32) || defined(__i386) || defined(__i386__)) && !defined(__LITTLE_ENDIAN__) - #define __LITTLE_ENDIAN__ 1 -#endif - - -#if defined(__LITTLE_ENDIAN__) && ((__LITTLE_ENDIAN__ == 1) || !defined (__BIG_ENDIAN__)) - #define conditionallongswap(x) dolongswap(x) - #define conditionalshortswap(x) doshortswap(x) - #define conditionalenumswap(x) doshortswap(x) - #define disklong(x) dolongswap(x) - #define memlong(x) dolongswap(x) - #define diskshort(x) doshortswap(x) - #define memshort(x) doshortswap(x) - #define disktomemshort(x) shortswap(x) - #define disktomemlong(x) longswap(x) - #define memtodiskshort(x) shortswap(x) - #define memtodisklong(x) longswap(x) -#elif defined(__BIG_ENDIAN__) && ((__BIG_ENDIAN__ == 1) || !defined (__LITTLE_ENDIAN__)) - #define conditionallongswap(x) x - #define conditionalshortswap(x) x - #define conditionalenumswap(x) x - #define disklong(x) x - #define memlong(x) x - #define diskshort(x) x - #define memshort(x) x - #define disktomemshort(x) - #define disktomemlong(x) - #define memtodiskshort(x) - #define memtodisklong(x) -#else - #error "Couldn't determine byte order of target architecture, update osincludes.h" -#endif - - -#define longswap(foo) do {foo = dolongswap(foo);} while (0) -#define shortswap(foo) do {foo = doshortswap(foo);} while (0) - - -long dolongswap (long); /* byteorder.c */ -short doshortswap (short); - - -#endif /* byteorderinclude */ + +/* $Id$ */ + +/****************************************************************************** + + UserLand Frontier(tm) -- High performance Web content management, + object database, system-level and Internet scripting environment, + including source code editing and debugging. + + Copyright (C) 1992-2004 UserLand Software, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +******************************************************************************/ + +#ifndef byteorderinclude +#define byteorderinclude + +/* + 2006-04-08 aradke: determine native byte order and define byte swapping macros +*/ + +#if (defined(WIN32) || defined(__i386) || defined(__i386__)) && !defined(__LITTLE_ENDIAN__) + #define __LITTLE_ENDIAN__ 1 +#endif + + +#if defined(__LITTLE_ENDIAN__) && ((__LITTLE_ENDIAN__ == 1) || !defined (__BIG_ENDIAN__)) + #define conditionallongswap(x) dolongswap(x) + #define conditionalshortswap(x) doshortswap(x) + #define conditionalenumswap(x) doshortswap(x) + #define disklong(x) dolongswap(x) + #define memlong(x) dolongswap(x) + #define diskshort(x) doshortswap(x) + #define memshort(x) doshortswap(x) + #define disktomemshort(x) shortswap(x) + #define disktomemlong(x) longswap(x) + #define memtodiskshort(x) shortswap(x) + #define memtodisklong(x) longswap(x) +#elif defined(__BIG_ENDIAN__) && ((__BIG_ENDIAN__ == 1) || !defined (__LITTLE_ENDIAN__)) + #define conditionallongswap(x) x + #define conditionalshortswap(x) x + #define conditionalenumswap(x) x + #define disklong(x) x + #define memlong(x) x + #define diskshort(x) x + #define memshort(x) x + #define disktomemshort(x) + #define disktomemlong(x) + #define memtodiskshort(x) + #define memtodisklong(x) +#else + #error "Couldn't determine byte order of target architecture, update osincludes.h" +#endif + + +#define longswap(foo) do {foo = dolongswap(foo);} while (0) +#define shortswap(foo) do {foo = doshortswap(foo);} while (0) + + +#if (defined(TARGET_API_MAC_CARBON) && (TARGET_API_MAC_CARBON == 1) && defined(__GNUC__)) + + /* using system sdk functions from CFByteOrder.h */ + + #define dolongswap(foo) CFSwapInt32(foo) + #define doshortswap(foo) CFSwapInt16(foo) + +#elif (defined(__i386__) && defined(__GNUC__)) + + /* using AT&T x86 assembly code syntax */ + + inline long dolongswap (long foo) { + + __asm__("mov foo,%eax\nbswap %eax\nmov %eax,foo\n"); + + return (foo); + } /*dolongswap*/ + + inline short doshortswap (short foo) { + + __asm__("mov foo,%ax\n mov %al,%bh\nmov %ah,%bl\nmov %bx,foo"); + + return (foo); + } /*doshortswap*/ + +#elif defined(WIN32) + + /* using Intel x86 assembly code syntax */ + + __inline long dolongswap (long foo) { + + _asm + { + mov eax,foo + bswap eax + mov foo,eax + } + + return (foo); + } /*dolongswap*/ + + __inline short doshortswap (short foo) { + + _asm + { + mov ax,foo + mov bh,al + mov bl,ah + mov foo,bx + } + + return (foo); + } /*doshortswap*/ + +#else + + /* portable code using only C operators */ + + inline long dolongswap (long foo) { + + foo = ((((foo) >> 24) & 0x000000ff) + | (((foo) & 0x00ff0000) >> 8) + | (((foo) & 0x0000ff00) << 8) + | (((foo) & 0x000000ff) << 24)); + + return (foo); + } /*dolongswap*/ + + inline short doshortswap (short foo) { + + foo = ((((foo) >> 8) & 0x00ff) + | (((foo) << 8) & 0xff00)); + + return (foo); + } /*doshortswap*/ + +#endif + + +#endif /* byteorderinclude */ Property changes on: Frontier/trunk/Common/headers/byteorder.h ___________________________________________________________________ Name: svn:keywords + Author Date Id Revision Name: svn:eol-style + native Modified: Frontier/trunk/Common/source/byteorder.c =================================================================== --- Frontier/trunk/Common/source/byteorder.c 2006-04-09 11:48:40 UTC (rev 1237) +++ Frontier/trunk/Common/source/byteorder.c 2006-04-09 13:11:39 UTC (rev 1238) @@ -30,99 +30,5 @@ #include "byteorder.h" -//#if (defined(TARGET_API_MAC_CARBON) && (TARGET_API_MAC_CARBON == 1)) -//#include <CoreFoundation/CoreFoundation.h> -//#include <CFByteOrder.h> -//#endif - -long dolongswap (long foo) { - - /* - 2006-04-09 aradke: utility function for swapping the byte order - of 32-bit integers from big endian to little endian and vice versa. - */ - -#if (defined(TARGET_API_MAC_CARBON) && (TARGET_API_MAC_CARBON == 1)) - - foo = CFSwapInt32 (foo); - -#elif (defined(__i386__) && defined(__GNUC__)) - - /* - 10.0a5 - TRT - 29 Dec 2004 - GNU by default uses the AT&T assembly code syntax; - MSC/MWERKS uses the Intel assembly code syntax; - some versions of 'gcc' accept -masm=att|intel to - specify which syntax to use; but for those that don't... - */ - __asm__("mov foo,%eax\nbswap %eax\nmov %eax,foo\n"); - -#elif defined(WIN32) /* intel x86 assembler code */ - - _asm - { - mov eax,foo - bswap eax - mov foo,eax - } - -#else /* default implementation using just C operators, should work with all compilers */ - - #pragma warning "Using default implementation of dolongswap, edit byteorder.c to implement faster native implementation" - - foo = ((((foo) >> 24) & 0x000000ff) /* if all else fails, do it the slow way */ - | (((foo) & 0x00ff0000) >> 8) - | (((foo) & 0x0000ff00) << 8) - | (((foo) & 0x000000ff) << 24)); - -#endif - - return (foo); - } /*dolongswap*/ - - -short doshortswap (short foo) { - - /* - 2006-04-09 aradke: utility function for swapping the byte order - of 16-bit integers from big endian to little endian and vice versa. - */ - -#if (defined(TARGET_API_MAC_CARBON) && (TARGET_API_MAC_CARBON == 1)) - - foo = CFSwapInt16 (foo); - -#elif (defined(__i386__) && defined(__GNUC__)) - - /* - 10.0a5 - TRT - 29 Dec 2004 - GNU by default uses the AT&T assembly code syntax; - MSC/MWERKS uses the Intel assembly code syntax; - some versions of 'gcc' accept -masm=att|intel to - specify which syntax to use; but for those that don't... - */ - __asm__("mov foo,%ax\n mov %al,%bh\nmov %ah,%bl\nmov %bx,foo"); - -#elif defined(WIN32) /* intel x86 assembler code */ - - _asm - { - mov ax,foo - mov bh,al - mov bl,ah - mov foo,bx - } - -#else /* default implementation using just C operators, should work with all compilers */ - - #pragma warning "Using default implementation of doshortswap, edit byteorder.c to implement faster native implementation" - - foo = ((((foo) >> 8) & 0x00ff) /* if all else fails, do it the slow way */ - | (((foo) << 8) & 0xff00)); - -#endif - - return (foo); - } /*doshortswap*/ - +/* now empty, code moved to byteorder.h so it can be inlined */ Modified: Frontier/trunk/build_GNU/Makefile =================================================================== --- Frontier/trunk/build_GNU/Makefile 2006-04-09 11:48:40 UTC (rev 1237) +++ Frontier/trunk/build_GNU/Makefile 2006-04-09 13:11:39 UTC (rev 1238) @@ -408,7 +408,8 @@ $(SRCDIR)/Common/Paige/headers/PGERRORS.h \ $(SRCDIR)/Common/headers/frontierdefs.h \ $(SRCDIR)/Common/headers/langmath.h \ - $(SRCDIR)/Common/headers/FastTimes.h + $(SRCDIR)/Common/headers/FastTimes.h \ + $(SRCDIR)/Common/headers/byteorder.h #================================================================================================ # Sources and Objects Definitions Modified: Frontier/trunk/build_XCode/Frontier.xcode/project.pbxproj =================================================================== (Binary files differ) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |