1 /*******************************************************************************
2 * Copyright (C) 2018 Cadence Design Systems, Inc.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining
5 * a copy of this software and associated documentation files (the
6 * "Software"), to use this Software with Cadence processor cores only and
7 * not with any other processors and platforms, subject to
8 * the following conditions:
9 *
10 * The above copyright notice and this permission notice shall be included
11 * in all copies or substantial portions of the Software.
12 *
13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
14 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
15 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
16 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
17 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
18 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
19 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20
21 ******************************************************************************/
22
23 #include "dsp_comm.h"
24
dsp_memcpy(void * d,void * s,unsigned int size)25 void dsp_memcpy(void *d, void *s, unsigned int size)
26 {
27 unsigned char *dest = (unsigned char*)d;
28 unsigned char *src = (unsigned char*)s;
29
30 if (s == d) {
31 return;
32 } else if (src > dest) {
33 for (; dest < ((unsigned char*)d + size); dest++) {
34 *dest = *src;
35 src++;
36 }
37 } else {
38 src = src + (size - 1);
39 for (dest = dest + (size - 1); dest >= (unsigned char*)d; dest--) {
40 *dest = *src;
41 src--;
42 }
43 }
44 }
45
46
dsp_memset(void * d,unsigned char ucData,unsigned int size)47 void dsp_memset(void *d, unsigned char ucData, unsigned int size)
48 {
49 unsigned int i;
50 unsigned char *dest = (unsigned char*)d;
51
52 for(i = 0; i < size; i++)
53 *dest++ = ucData;
54 }
division(int a,int b)55 int division(int a, int b)
56 {
57 const int bits_in_word_m1 = (int)(sizeof(int) * 8) - 1;
58 int s_a = a >> bits_in_word_m1; /* s_a = a < 0 ? -1 : 0 */
59 int s_b = b >> bits_in_word_m1; /* s_b = b < 0 ? -1 : 0 */
60 a = (a ^ s_a) - s_a; /* negate if s_a == -1 */
61 b = (b ^ s_b) - s_b; /* negate if s_b == -1 */
62 s_a ^= s_b; /* sign of quotient */
63 /*
64 * On CPUs without unsigned hardware division support,
65 * this calls __udivsi3 (notice the cast to su_int).
66 * On CPUs with unsigned hardware division support,
67 * this uses the unsigned division instruction.
68 */
69 return ((int)a/(int)b ^ s_a) - s_a; /* negate if s_a == -1 */
70
71 }
72
73
74
75
76