00001 00007 /* Macros for copying by pages; used in memcpy, memmove. Generic macros. 00008 Copyright (C) 1995, 1997 Free Software Foundation, Inc. 00009 This file is part of the GNU C Library. 00010 00011 The GNU C Library is free software; you can redistribute it and/or 00012 modify it under the terms of the GNU Lesser General Public 00013 License as published by the Free Software Foundation; either 00014 version 2.1 of the License, or (at your option) any later version. 00015 00016 The GNU C Library is distributed in the hope that it will be useful, 00017 but WITHOUT ANY WARRANTY; without even the implied warranty of 00018 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00019 Lesser General Public License for more details. 00020 00021 You should have received a copy of the GNU Lesser General Public 00022 License along with the GNU C Library; if not, write to the Free 00023 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 00024 02111-1307 USA. */ 00025 00026 /* This file defines the macro: 00027 00028 PAGE_COPY_FWD_MAYBE (dstp, srcp, nbytes_left, nbytes) 00029 00030 which is invoked like WORD_COPY_FWD et al. The pointers should be at 00031 least word aligned. This will check if virtual copying by pages can and 00032 should be done and do it if so. 00033 00034 System-specific pagecopy.h files should define these macros and then 00035 #include this file: 00036 00037 PAGE_COPY_THRESHOLD 00038 -- Minimum size for which virtual copying by pages is worthwhile. 00039 00040 PAGE_SIZE 00041 -- Size of a page. 00042 00043 PAGE_COPY_FWD (dstp, srcp, nbytes_left, nbytes) 00044 -- Macro to perform the virtual copy operation. 00045 The pointers will be aligned to PAGE_SIZE bytes. 00046 */ 00047 00048 00049 #if PAGE_COPY_THRESHOLD 00050 00051 #include <assert.h> 00052 00053 #define PAGE_COPY_FWD_MAYBE(dstp, srcp, nbytes_left, nbytes) \ 00054 do \ 00055 { \ 00056 if ((nbytes) >= PAGE_COPY_THRESHOLD && \ 00057 PAGE_OFFSET ((dstp) - (srcp)) == 0) \ 00058 { \ 00059 /* The amount to copy is past the threshold for copying \ 00060 pages virtually with kernel VM operations, and the \ 00061 source and destination addresses have the same alignment. */ \ 00062 size_t nbytes_before = PAGE_OFFSET (-(dstp)); \ 00063 if (nbytes_before != 0) \ 00064 { \ 00065 /* First copy the words before the first page boundary. */ \ 00066 WORD_COPY_FWD (dstp, srcp, nbytes_left, nbytes_before); \ 00067 assert (nbytes_left == 0); \ 00068 nbytes -= nbytes_before; \ 00069 } \ 00070 PAGE_COPY_FWD (dstp, srcp, nbytes_left, nbytes); \ 00071 } \ 00072 } while (0) 00073 00074 /* The page size is always a power of two, so we can avoid modulo division. */ 00075 #define PAGE_OFFSET(n) ((n) & (PAGE_SIZE - 1)) 00076 00077 #else 00078 00079 #define PAGE_COPY_FWD_MAYBE(dstp, srcp, nbytes_left, nbytes) /* nada */ 00080 00081 #endif