Asterisk - The Open Source Telephony Project  18.5.0
Macros | Functions | Variables
add.c File Reference
#include <stdio.h>
#include <assert.h>
#include "private.h"
#include "gsm.h"
#include "proto.h"
Include dependency graph for add.c:

Go to the source code of this file.

Macros

#define saturate(x)   ((x) < MIN_WORD ? MIN_WORD : (x) > MAX_WORD ? MAX_WORD: (x))
 

Functions

word gsm_abs P1 ((a), word a)
 
word gsm_norm P1 ((a), longword a)
 
word gsm_add P2 ((a, b), word a, word b)
 
longword gsm_L_add P2 ((a, b), longword a, longword b)
 
longword gsm_L_asl P2 ((a, n), longword a, int n)
 
word gsm_asl P2 ((a, n), word a, int n)
 
word gsm_div P2 ((num, denum), word num, word denum)
 

Variables

static unsigned char const bitoff [256]
 

Macro Definition Documentation

◆ saturate

#define saturate (   x)    ((x) < MIN_WORD ? MIN_WORD : (x) > MAX_WORD ? MAX_WORD: (x))

Definition at line 20 of file add.c.

Referenced by P2().

Function Documentation

◆ P1() [1/2]

word gsm_abs P1 ( (a ,
word  a 
)

Definition at line 51 of file add.c.

References a, MAX_WORD, MIN_WORD, and P2().

52 {
53  return a < 0 ? (a == MIN_WORD ? MAX_WORD : -a) : a;
54 }
#define MAX_WORD
#define MIN_WORD
static struct test_val a

◆ P1() [2/2]

word gsm_norm P1 ( (a ,
longword  a 
)

Definition at line 117 of file add.c.

References a.

136 {
137  assert(a != 0);
138 
139  if (a < 0) {
140  if (a <= -1073741824) return 0;
141  a = ~a;
142  }
143 
144  return a & 0xffff0000
145  ? ( a & 0xff000000
146  ? -1 + bitoff[ 0xFF & (a >> 24) ]
147  : 7 + bitoff[ 0xFF & (a >> 16) ] )
148  : ( a & 0xff00
149  ? 15 + bitoff[ 0xFF & (a >> 8) ]
150  : 23 + bitoff[ 0xFF & a ] );
151 }
static unsigned char const bitoff[256]
Definition: add.c:98
static struct test_val a

◆ P2() [1/5]

longword gsm_L_mult P2 ( (a, b ,
word  a,
word  b 
)

Definition at line 23 of file add.c.

References a, b, MAX_WORD, MIN_WORD, SASR, and saturate.

Referenced by P1(), and P2().

24 {
25  longword sum = (longword)a + (longword)b;
26  return (word)saturate(sum);
27 }
#define saturate(x)
Definition: add.c:20
static struct test_val b
long longword
short word
static struct test_val a

◆ P2() [2/5]

longword gsm_L_sub P2 ( (a, b ,
longword  a,
longword  b 
)

Definition at line 62 of file add.c.

References b, MAX_LONGWORD, MIN_LONGWORD, and P2().

63 {
64  if (a < 0) {
65  if (b >= 0) return a + b;
66  else {
67  ulongword A = (ulongword)-(a + 1) + (ulongword)-(b + 1);
68  return A >= MAX_LONGWORD ? MIN_LONGWORD :-(longword)A-2;
69  }
70  }
71  else if (b <= 0) return a + b;
72  else {
74  return A > MAX_LONGWORD ? MAX_LONGWORD : A;
75  }
76 }
#define MIN_LONGWORD
#define MAX_LONGWORD
static struct test_val b
long longword
unsigned long ulongword
static struct test_val a

◆ P2() [3/5]

longword gsm_L_asr P2 ( (a, n)  ,
longword  a,
int  n 
)

Definition at line 153 of file add.c.

154 {
155  if (n >= 32) return 0;
156  if (n <= -32) return -(a < 0);
157  if (n < 0) return gsm_L_asr(a, -n);
158  return a << n;
159 }
static struct test_val a

◆ P2() [4/5]

word gsm_asr P2 ( (a, n)  ,
word  a,
int  n 
)

Definition at line 161 of file add.c.

References P2().

162 {
163  if (n >= 16) return 0;
164  if (n <= -16) return -(a < 0);
165  if (n < 0) return gsm_asr(a, -n);
166  return a << n;
167 }
static struct test_val a

◆ P2() [5/5]

word gsm_div P2 ( (num, denum)  ,
word  num,
word  denum 
)

Definition at line 206 of file add.c.

207 {
208  longword L_num = num;
209  longword L_denum = denum;
210  word div = 0;
211  int k = 15;
212 
213  /* The parameter num sometimes becomes zero.
214  * Although this is explicitly guarded against in 4.2.5,
215  * we assume that the result should then be zero as well.
216  */
217 
218  /* assert(num != 0); */
219 
220  assert(num >= 0 && denum >= num);
221  if (num == 0)
222  return 0;
223 
224  while (k--) {
225  div <<= 1;
226  L_num <<= 1;
227 
228  if (L_num >= L_denum) {
229  L_num -= L_denum;
230  div++;
231  }
232  }
233 
234  return div;
235 }
long longword
short word

Variable Documentation

◆ bitoff

unsigned char const bitoff[256]
static

Definition at line 98 of file add.c.