You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

i386_string.c 1.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /*
  2. * Copyright (C) 2007 Michael Brown <mbrown@fensystems.co.uk>.
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License as
  6. * published by the Free Software Foundation; either version 2 of the
  7. * License, or any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful, but
  10. * WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17. */
  18. /** @file
  19. *
  20. * Optimised string operations
  21. *
  22. */
  23. #include <string.h>
  24. /**
  25. * Copy memory area
  26. *
  27. * @v dest Destination address
  28. * @v src Source address
  29. * @v len Length
  30. * @ret dest Destination address
  31. */
  32. __attribute__ (( regparm ( 3 ) )) void * __memcpy ( void *dest,
  33. const void *src,
  34. size_t len ) {
  35. void *edi = dest;
  36. const void *esi = src;
  37. int discard_ecx;
  38. /* We often do large dword-aligned and dword-length block
  39. * moves. Using movsl rather than movsb speeds these up by
  40. * around 32%.
  41. */
  42. if ( len >> 2 ) {
  43. __asm__ __volatile__ ( "rep movsl"
  44. : "=&D" ( edi ), "=&S" ( esi ),
  45. "=&c" ( discard_ecx )
  46. : "0" ( edi ), "1" ( esi ),
  47. "2" ( len >> 2 )
  48. : "memory" );
  49. }
  50. if ( len & 0x02 ) {
  51. __asm__ __volatile__ ( "movsw" : "=&D" ( edi ), "=&S" ( esi )
  52. : "0" ( edi ), "1" ( esi ) : "memory" );
  53. }
  54. if ( len & 0x01 ) {
  55. __asm__ __volatile__ ( "movsb" : "=&D" ( edi ), "=&S" ( esi )
  56. : "0" ( edi ), "1" ( esi ) : "memory" );
  57. }
  58. return dest;
  59. }