x86_string.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2007 Michael Brown <mbrown@fensystems.co.uk>.
00003  *
00004  * This program is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU General Public License as
00006  * published by the Free Software Foundation; either version 2 of the
00007  * License, or any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful, but
00010  * WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  * General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software
00016  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00017  */
00018 
00019 /** @file
00020  *
00021  * Optimised string operations
00022  *
00023  */
00024 
00025 FILE_LICENCE ( GPL2_OR_LATER );
00026 
00027 #include <string.h>
00028 
00029 /**
00030  * Copy memory area
00031  *
00032  * @v dest              Destination address
00033  * @v src               Source address
00034  * @v len               Length
00035  * @ret dest            Destination address
00036  */
00037 void * __memcpy ( void *dest, const void *src, size_t len ) {
00038         void *edi = dest;
00039         const void *esi = src;
00040         int discard_ecx;
00041 
00042         /* We often do large dword-aligned and dword-length block
00043          * moves.  Using movsl rather than movsb speeds these up by
00044          * around 32%.
00045          */
00046         if ( len >> 2 ) {
00047                 __asm__ __volatile__ ( "rep movsl"
00048                                        : "=&D" ( edi ), "=&S" ( esi ),
00049                                          "=&c" ( discard_ecx )
00050                                        : "0" ( edi ), "1" ( esi ),
00051                                          "2" ( len >> 2 )
00052                                        : "memory" );
00053         }
00054         if ( len & 0x02 ) {
00055                 __asm__ __volatile__ ( "movsw" : "=&D" ( edi ), "=&S" ( esi )
00056                                        : "0" ( edi ), "1" ( esi ) : "memory" );
00057         }
00058         if ( len & 0x01 ) {
00059                 __asm__ __volatile__ ( "movsb" : "=&D" ( edi ), "=&S" ( esi )
00060                                        : "0" ( edi ), "1" ( esi ) : "memory" );
00061         }
00062         return dest;
00063 }

Generated on Tue Apr 6 20:00:51 2010 for gPXE by  doxygen 1.5.7.1