From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 12116 invoked by alias); 7 Feb 2011 16:20:46 -0000 Received: (qmail 12104 invoked by uid 22791); 7 Feb 2011 16:20:44 -0000 X-SWARE-Spam-Status: No, hits=-2.3 required=5.0 tests=AWL,BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,TW_CP X-Spam-Check-By: sourceware.org Received: from mail-qy0-f182.google.com (HELO mail-qy0-f182.google.com) (209.85.216.182) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 07 Feb 2011 16:20:38 +0000 Received: by qyk36 with SMTP id 36so3831888qyk.20 for ; Mon, 07 Feb 2011 08:20:36 -0800 (PST) MIME-Version: 1.0 Received: by 10.229.85.82 with SMTP id n18mr4377244qcl.292.1297095636511; Mon, 07 Feb 2011 08:20:36 -0800 (PST) Received: by 10.220.185.130 with HTTP; Mon, 7 Feb 2011 08:20:36 -0800 (PST) In-Reply-To: References: <4D500509.1090607@wippies.com> Date: Mon, 07 Feb 2011 16:48:00 -0000 Message-ID: Subject: Re: -nostdlib option! From: Drasko DRASKOVIC To: Manuel Coutinho Cc: Kai Ruottu , gcc-help@gcc.gnu.org, ali hagigat Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-IsSubscribed: yes Mailing-List: contact gcc-help-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-help-owner@gcc.gnu.org X-SW-Source: 2011-02/txt/msg00143.txt.bz2 I hope that you are not pasting NDA covered SW to this list. BR, Drasko On Mon, Feb 7, 2011 at 5:10 PM, Manuel Coutinho wrote: > Yes. > > Memset and memcpy are standalone functions. My team (at Edisoft) has a > version for these files. > > For memcpy we have the file: > > /** > =A0* @brief check if either of the addresses are aligned > =A0* > =A0* Nonzero if either X or Y is not aligned on a "long" boundary. > =A0*/ > #define UNALIGNED(X, Y) \ > =A0(((uint32)X & (sizeof (uint32) - 1U)) | ((uint32)Y & (sizeof (uint32) - > 1U))) > > /** > =A0* @brief determine how many bytes are copied each iteration of the 4X > unrolled > =A0* loop > =A0*/ > #define BIGBLOCKSIZE =A0 =A0((uint32)sizeof (sint32) << 2U) > > /** > =A0* @brief determine how many bytes are copied each iteration of the word > copy > =A0* loop > =A0*/ > #define LITTLEBLOCKSIZE ((uint32)sizeof (sint32)) > > /** > =A0* @brief Threshhold for punting to the byte copier =A0*/ #define > TOO_SMALL(LEN) =A0((LEN) < BIGBLOCKSIZE) > > > void *memcpy(void *dst0 , const void *src0 , rtems_size len0) { > > #if defined(PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__) > > =A0 =A0/* get destination address as a byte pointer */ > =A0 =A0sint8 *dst =3D (sint8 *) dst0; > > =A0 =A0/* get source address as a byte pointer */ > =A0 =A0sint8 *src =3D (const sint8 *) src0; > > > =A0 =A0/* save the destination address */ > =A0 =A0void * save =3D dst0; > > =A0 =A0/* copy the source vector to destination for len0 bytes*/ > =A0 =A0while(len0--) > =A0 =A0{ > =A0 =A0 =A0 =A0/* copy the source to the destination */ > =A0 =A0 =A0 =A0*dst++ =3D *src++; > =A0 =A0} > > =A0 =A0/* return the saved destination address */ > =A0 =A0return save; > > #else > > =A0 =A0/* get destination address as a byte pointer */ > =A0 =A0sint8 *dst =3D (sint8 *) dst0; > > =A0 =A0/* get source address as a byte pointer */ > =A0 =A0const sint8 *src =3D src0; > > =A0 =A0/* alligned destination pointer */ > =A0 =A0sint32 *aligned_dst; > > =A0 =A0/* aligned source pointer */ > =A0 =A0const sint32 *aligned_src; > > =A0 =A0/* lenght in integer */ > =A0 =A0uint32 len =3D (uint32) len0; > > > =A0 =A0/* If the size is small, or either SRC or DST is unaligned, > =A0 =A0 * then punt into the byte copy loop. =A0This should be rare. =A0*/ > =A0 =A0if(( ( TOO_SMALL(len) ) =3D=3D 0U ) && > =A0 =A0 =A0 ( ( UNALIGNED((uint32) src0 , (uint32) dst0) ) =3D=3D FALSE )) > =A0 =A0{ > =A0 =A0 =A0 =A0/* get the destination */ > =A0 =A0 =A0 =A0aligned_dst =3D (sint32*) dst; > > =A0 =A0 =A0 =A0/* get the source */ > =A0 =A0 =A0 =A0aligned_src =3D (sint32*) src; > > =A0 =A0 =A0 =A0/* Copy 4X long words at a time if possible. =A0*/ > =A0 =A0 =A0 =A0while(len >=3D BIGBLOCKSIZE) > =A0 =A0 =A0 =A0{ > =A0 =A0 =A0 =A0 =A0 =A0/* copy the first 4 bytes */ > =A0 =A0 =A0 =A0 =A0 =A0*aligned_dst =3D *aligned_src; > =A0 =A0 =A0 =A0 =A0 =A0aligned_dst++; > =A0 =A0 =A0 =A0 =A0 =A0aligned_src++; > > =A0 =A0 =A0 =A0 =A0 =A0/* copy the second 4 bytes */ > =A0 =A0 =A0 =A0 =A0 =A0*aligned_dst =3D *aligned_src; > =A0 =A0 =A0 =A0 =A0 =A0aligned_dst++; > =A0 =A0 =A0 =A0 =A0 =A0aligned_src++; > > =A0 =A0 =A0 =A0 =A0 =A0/* copy the third 4 bytes */ > =A0 =A0 =A0 =A0 =A0 =A0*aligned_dst =3D *aligned_src; > =A0 =A0 =A0 =A0 =A0 =A0aligned_dst++; > =A0 =A0 =A0 =A0 =A0 =A0aligned_src++; > > =A0 =A0 =A0 =A0 =A0 =A0/* copy the fourth 4 bytes */ > =A0 =A0 =A0 =A0 =A0 =A0*aligned_dst =3D *aligned_src; > =A0 =A0 =A0 =A0 =A0 =A0aligned_dst++; > =A0 =A0 =A0 =A0 =A0 =A0aligned_src++; > > =A0 =A0 =A0 =A0 =A0 =A0/* decrement the number of bytes left to copy */ > =A0 =A0 =A0 =A0 =A0 =A0len -=3D BIGBLOCKSIZE; > =A0 =A0 =A0 =A0} > > =A0 =A0 =A0 =A0/* Copy one long word at a time if possible. =A0*/ > =A0 =A0 =A0 =A0while(len >=3D LITTLEBLOCKSIZE) > =A0 =A0 =A0 =A0{ > =A0 =A0 =A0 =A0 =A0 =A0/* copy 4 bytes */ > =A0 =A0 =A0 =A0 =A0 =A0*aligned_dst =3D *aligned_src; > =A0 =A0 =A0 =A0 =A0 =A0aligned_dst++; > =A0 =A0 =A0 =A0 =A0 =A0aligned_src++; > > =A0 =A0 =A0 =A0 =A0 =A0/* decrement the number of bytes left to copy */ > =A0 =A0 =A0 =A0 =A0 =A0len -=3D LITTLEBLOCKSIZE; > =A0 =A0 =A0 =A0} > > =A0 =A0 =A0 =A0/* Pick up any residual with a byte copier. =A0*/ > =A0 =A0 =A0 =A0dst =3D (sint8*) aligned_dst; > =A0 =A0 =A0 =A0src =3D (sint8*) aligned_src; > =A0 =A0} > > =A0 =A0/* copy residual bytes (maximum of 3) */ > =A0 =A0while(len > 0U) > =A0 =A0{ > =A0 =A0 =A0 =A0/* copy each byte */ > =A0 =A0 =A0 =A0*dst =3D *src; > > =A0 =A0 =A0 =A0/* increment the pointer */ > =A0 =A0 =A0 =A0dst++; > =A0 =A0 =A0 =A0src++; > > =A0 =A0 =A0 =A0/* decrement number of bytes */ > =A0 =A0 =A0 =A0len--; > =A0 =A0} > > =A0 =A0/* return the destination address */ > =A0 =A0return dst0; > > #endif /* not PREFER_SIZE_OVER_SPEED */ > } > > > > > For the file memset.c we have the file: > > > /** > =A0* @brief size of a block > =A0*/ > #define LBLOCKSIZE ((uint32) sizeof(uintptr)) > > /** > =A0* @brief check if the address is alligned =A0*/ #define UNALIGNED(X) > ((uintptr)X & (LBLOCKSIZE - 1)) > > /** > =A0* @brief check if the size is too small =A0*/ #define TOO_SMALL(LEN) (= (LEN) < > LBLOCKSIZE) > > > void *memset(void *m , sint32 c , rtems_size n) { > > #if defined(PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__) > > =A0 =A0/* copy the destination address to another variable */ > =A0 =A0sint8 *s =3D (sint8 *) m; > > > =A0 =A0/* while there are bytes left to copy */ > =A0 =A0while(n !=3D 0) > =A0 =A0{ > =A0 =A0 =A0 =A0/* copy the byte */ > =A0 =A0 =A0 =A0*s =3D (sint8) c; > > =A0 =A0 =A0 =A0/* increment index on array */ > =A0 =A0 =A0 =A0s++; > > =A0 =A0 =A0 =A0/* decrement number of remaining bytes to copy */ > =A0 =A0 =A0 =A0n--; > =A0 =A0} > > =A0 =A0/* return the destination address */ > =A0 =A0return m; > > #else > > =A0 =A0/* pointer to address where to write */ > =A0 =A0sint8 *s =3D (sint8 *) m; > > =A0 =A0/* iterator */ > =A0 =A0uint32 i; > > =A0 =A0/* buffer where to place small array */ > =A0 =A0uint32 buffer; > > =A0 =A0/* pointer to address aligned */ > =A0 =A0uintptr *aligned_addr; > > =A0 =A0/* To avoid sign extension, copy c to an unsigned variable. =A0*/ > =A0 =A0uint32 d =3D (uint32) c & 0xffU; > > > =A0 =A0/* check if the size is too small or the destination address in not > aligned */ > =A0 =A0if(( TOO_SMALL(n) =3D=3D 0U ) && ( UNALIGNED(m) =3D=3D 0U )) > =A0 =A0{ > =A0 =A0 =A0 =A0/* If we get this far, we know that n is large and m is > word-aligned. */ > =A0 =A0 =A0 =A0aligned_addr =3D (uint32*) m; > > =A0 =A0 =A0 =A0/* Store D into each char sized location in BUFFER so that > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0we can set large blocks quickly. =A0*/ > =A0 =A0 =A0 =A0if(LBLOCKSIZE =3D=3D 4U) > =A0 =A0 =A0 =A0{ > =A0 =A0 =A0 =A0 =A0 =A0/* copy to the buffer */ > =A0 =A0 =A0 =A0 =A0 =A0buffer =3D (uint32) ( ( d << 8U ) | d ); > =A0 =A0 =A0 =A0 =A0 =A0buffer =3D buffer | ( buffer << 16U ); > =A0 =A0 =A0 =A0} > =A0 =A0 =A0 =A0else > =A0 =A0 =A0 =A0{ > =A0 =A0 =A0 =A0 =A0 =A0/* reset the buffer */ > =A0 =A0 =A0 =A0 =A0 =A0buffer =3D 0U; > > =A0 =A0 =A0 =A0 =A0 =A0/* copy to the buffer the char */ > =A0 =A0 =A0 =A0 =A0 =A0for(i =3D 0U; i < LBLOCKSIZE; i++) > =A0 =A0 =A0 =A0 =A0 =A0{ > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0buffer =3D ( buffer << 8U ) | d; > =A0 =A0 =A0 =A0 =A0 =A0} > =A0 =A0 =A0 =A0} > > =A0 =A0 =A0 =A0/* copy the aligned bytes */ > =A0 =A0 =A0 =A0while(n >=3D LBLOCKSIZE * 4U) > =A0 =A0 =A0 =A0{ > =A0 =A0 =A0 =A0 =A0 =A0/* copy the first four byte word */ > =A0 =A0 =A0 =A0 =A0 =A0*aligned_addr =3D buffer; > =A0 =A0 =A0 =A0 =A0 =A0aligned_addr++; > > =A0 =A0 =A0 =A0 =A0 =A0/* copy the second four byte word */ > =A0 =A0 =A0 =A0 =A0 =A0*aligned_addr =3D buffer; > =A0 =A0 =A0 =A0 =A0 =A0aligned_addr++; > > =A0 =A0 =A0 =A0 =A0 =A0/* copy the third four byte word */ > =A0 =A0 =A0 =A0 =A0 =A0*aligned_addr =3D buffer; > =A0 =A0 =A0 =A0 =A0 =A0aligned_addr++; > > =A0 =A0 =A0 =A0 =A0 =A0/* copy the fourth four byte word */ > =A0 =A0 =A0 =A0 =A0 =A0*aligned_addr =3D buffer; > =A0 =A0 =A0 =A0 =A0 =A0aligned_addr++; > > =A0 =A0 =A0 =A0 =A0 =A0/* decrement the number of bytes copied */ > =A0 =A0 =A0 =A0 =A0 =A0n -=3D (rtems_size) ( 4U * LBLOCKSIZE ); > =A0 =A0 =A0 =A0} > > =A0 =A0 =A0 =A0/* copy the remaining bytes */ > =A0 =A0 =A0 =A0while(n >=3D LBLOCKSIZE) > =A0 =A0 =A0 =A0{ > =A0 =A0 =A0 =A0 =A0 =A0/* copy the first four byte word */ > =A0 =A0 =A0 =A0 =A0 =A0*aligned_addr =3D buffer; > =A0 =A0 =A0 =A0 =A0 =A0aligned_addr++; > > =A0 =A0 =A0 =A0 =A0 =A0/* decrement the number of bytes copied */ > =A0 =A0 =A0 =A0 =A0 =A0n -=3D LBLOCKSIZE; > =A0 =A0 =A0 =A0} > =A0 =A0 =A0 =A0/* Pick up the remainder with a bytewise loop. =A0*/ > =A0 =A0 =A0 =A0s =3D (sint8*) aligned_addr; > =A0 =A0} > > =A0 =A0/* copy the remaining bytes */ > =A0 =A0while(n > 0U) > =A0 =A0{ > =A0 =A0 =A0 =A0/* copy the byte */ > =A0 =A0 =A0 =A0*s =3D (sint8) d; > =A0 =A0 =A0 =A0s++; > =A0 =A0 =A0 =A0/* decrement size */ > =A0 =A0 =A0 =A0n--; > =A0 =A0} > > =A0 =A0/* return the destination address */ > =A0 =A0return m; > > #endif /* not PREFER_SIZE_OVER_SPEED */ > } > > > > > > Hope this help ;) > Manuel Coutinho > > -----Original Message----- > From: gcc-help-owner@gcc.gnu.org [mailto:gcc-help-owner@gcc.gnu.org] On > Behalf Of Kai Ruottu > Sent: 07 February 2011 14:43 > To: gcc-help@gcc.gnu.org > Cc: ali hagigat > Subject: Re: -nostdlib option! > > 7.2.2011 14:44, ali hagigat kirjoitti: > >> How will be memset, memcpy, etc. Can i copy them from the source code >> of gcc? But they are dependent to other functions in other libraries >> probably and some headers. > > Most probably these functions are standalone and don't > call other functions... Does your program really call > them? What does 'nm' say anout undefined symbols in the > compiled object(s)? > >> Are those functions available stand alone some where? > > For instance in : > =A0 newlib-1.18.0/newlib/libc/machine/i386 > in the current newlib sources. > > >