source: soft/giet_vm/giet_libs/stdlib.c @ 271

Last change on this file since 271 was 271, checked in by cfuguet, 10 years ago
  • Bugfix: The ISR_SWITCH index should be NB_PROCS_MAX + local_pid. This is because the first NB_PROCS_MAX indexes on the XICU in each cluster are used for the WAKEUP software interrupts.
  • Relocating the memcpy and memset functions into the giet_libs/stdlib.* files.
  • Modification of the sort application to used 8 threads instead of
    1. Modifying the mapping files to distribute the 8 threads on the available processors. (Ex. When using 4 processors, each one executes 2 threads)
File size: 2.3 KB
Line 
1//////////////////////////////////////////////////////////////////////////////////
2// File     : stdlib.c
3// Date     : 05/12/2013
4// Author   : Clément DEVIGNE
5// Copyright (c) UPMC-LIP6
6///////////////////////////////////////////////////////////////////////////////////
7
8#include <stdlib.h>
9
10///////////////////////////////////////////////////////////////////////////////////
11// int atoi ( char * str )
12///////////////////////////////////////////////////////////////////////////////////
13       
14int atoi(char *str)
15{
16    int res  = 0; // Initialize result
17    int sign = 1; // Initialize sign as positive
18    int i    = 0; // Initialize index of first digit
19
20    if (str[0] == '-') //If number is negative, then update sign
21    {
22        sign = -1; 
23        i++;           // Also update index of first digit
24    }
25
26    for (; str[i] != '\0'; ++i) // Iterate through all digits and update the result
27    {
28        res = res*10 + str[i] - '0';
29    }
30
31    // Return result with sign
32    return sign*res;
33}
34       
35////////////////////////////////////////////////////////////////////////////////////////
36//  mempcy()
37// GCC requires this function. Taken from MutekH.
38////////////////////////////////////////////////////////////////////////////////////////
39void * memcpy(void *_dst, const void * _src, unsigned int size) {
40    unsigned int * dst = _dst;
41    const unsigned int * src = _src;
42    if (!((unsigned int) dst & 3) && !((unsigned int) src & 3) )
43        while (size > 3) {
44            *dst++ = *src++;
45            size -= 4;
46        }
47
48    unsigned char *cdst = (unsigned char*)dst;
49    unsigned char *csrc = (unsigned char*)src;
50
51    while (size--) {
52        *cdst++ = *csrc++;
53    }
54    return _dst;
55}
56
57
58////////////////////////////////////////////////////////////////////////////////////////
59//  mempcy()
60// GCC requires this function. Taken from MutekH.
61////////////////////////////////////////////////////////////////////////////////////////
62inline void * memset(void * dst, int s, unsigned int count) {
63    char * a = (char *) dst;
64    while (count--){
65        *a++ = (char)s;
66    }
67    return dst;
68}
69
70// Local Variables:
71// tab-width: 4
72// c-basic-offset: 4
73// c-file-offsets:((innamespace . 0)(inline-open . 0))
74// indent-tabs-mode: nil
75// End:
76// vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
Note: See TracBrowser for help on using the repository browser.