OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [libgo/] [runtime/] [go-append.c] - Blame information for rev 833

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 747 jeremybenn
/* go-append.c -- the go builtin append function.
2
 
3
   Copyright 2010 The Go Authors. All rights reserved.
4
   Use of this source code is governed by a BSD-style
5
   license that can be found in the LICENSE file.  */
6
 
7
#include "go-type.h"
8
#include "go-panic.h"
9
#include "array.h"
10
#include "runtime.h"
11
#include "arch.h"
12
#include "malloc.h"
13
 
14
/* We should be OK if we don't split the stack here, since the only
15
   libc functions we call are memcpy and memmove.  If we don't do
16
   this, we will always split the stack, because of memcpy and
17
   memmove.  */
18
extern struct __go_open_array
19
__go_append (struct __go_open_array, void *, uintptr_t, uintptr_t)
20
  __attribute__ ((no_split_stack));
21
 
22
struct __go_open_array
23
__go_append (struct __go_open_array a, void *bvalues, uintptr_t bcount,
24
             uintptr_t element_size)
25
{
26
  uintptr_t ucount;
27
  int count;
28
 
29
  if (bvalues == NULL || bcount == 0)
30
    return a;
31
 
32
  ucount = (uintptr_t) a.__count + bcount;
33
  count = (int) ucount;
34
  if ((uintptr_t) count != ucount || count <= a.__count)
35
    runtime_panicstring ("append: slice overflow");
36
 
37
  if (count > a.__capacity)
38
    {
39
      int m;
40
      void *n;
41
 
42
      m = a.__capacity;
43
      if (m == 0)
44
        m = (int) bcount;
45
      else
46
        {
47
          do
48
            {
49
              if (a.__count < 1024)
50
                m += m;
51
              else
52
                m += m / 4;
53
            }
54
          while (m < count);
55
        }
56
 
57
      n = __go_alloc (m * element_size);
58
      __builtin_memcpy (n, a.__values, a.__count * element_size);
59
 
60
      a.__values = n;
61
      a.__capacity = m;
62
    }
63
 
64
  __builtin_memmove ((char *) a.__values + a.__count * element_size,
65
                     bvalues, bcount * element_size);
66
  a.__count = count;
67
  return a;
68
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.