XCORE SDK
XCORE Software Development Kit
xs3_scalar.h
1 // Copyright 2020-2021 XMOS LIMITED.
2 // This Software is subject to the terms of the XMOS Public Licence: Version 1.
3 
4 #pragma once
5 
6 #include "../xs3_math_types.h"
7 
8 #include <stdio.h>
9 #include <assert.h>
10 #include <math.h>
11 
12 
13 
24 #define XS3_S32_SQRT_MAX_DEPTH (31)
25 
26 
52 C_API
53 float xs3_pack_float(
54  const int32_t mantissa,
55  const exponent_t exp);
56 
57 
78 C_API
79 void xs3_unpack_float(
80  int32_t* mantissa,
81  exponent_t* exp,
82  const float input);
83 
84 
107 C_API
109  int16_t* mantissa,
110  exponent_t* exp,
111  const float input);
112 
127 C_API
128 int32_t xs3_scalar_s64_to_s32(
129  exponent_t* a_exp,
130  const int64_t b,
131  const exponent_t b_exp);
132 
147 C_API
148 int16_t xs3_scalar_s32_to_s16(
149  exponent_t* a_exp,
150  const int32_t b,
151  const exponent_t b_exp);
152 
171 C_API
172 int32_t xs3_scalar_s16_to_s32(
173  exponent_t* a_exp,
174  const int16_t b,
175  const exponent_t b_exp,
176  const unsigned remove_hr);
177 
178 
202 C_API
203 int32_t xs3_s32_sqrt(
204  exponent_t* a_exp,
205  const int32_t b,
206  const exponent_t b_exp,
207  const unsigned depth);
208 
226 C_API
227 int32_t xs3_s32_inverse(
228  exponent_t* a_exp,
229  const int32_t b);
230 
231 
249 C_API
250 int16_t xs3_s16_inverse(
251  exponent_t* a_exp,
252  const int16_t b);
253 
278 C_API
279 int16_t xs3_s16_mul(
280  exponent_t* a_exp,
281  const int16_t b,
282  const int16_t c,
283  const exponent_t b_exp,
284  const exponent_t c_exp);
285 
310 C_API
311 int32_t xs3_s32_mul(
312  exponent_t* a_exp,
313  const int32_t b,
314  const int32_t c,
315  const exponent_t b_exp,
316  const exponent_t c_exp);
317 
318 
340 static inline unsigned ceil_log2(
341  unsigned N)
342 {
343  if(N == 0) return 0;
344  return 32-cls(N-1);
345 }
346 
int exponent_t
An exponent.
Definition: xs3_math_types.h:76
int16_t xs3_s16_mul(exponent_t *a_exp, const int16_t b, const int16_t c, const exponent_t b_exp, const exponent_t c_exp)
Compute the product of two 16-bit floating-point scalars.
Definition: xs3_scalar_ops.c:55
int32_t xs3_scalar_s64_to_s32(exponent_t *a_exp, const int64_t b, const exponent_t b_exp)
Convert a 64-bit floating-point scalar to a 32-bit floating-point scalar.
Definition: xs3_scalar_ops.c:20
int32_t xs3_s32_sqrt(exponent_t *a_exp, const int32_t b, const exponent_t b_exp, const unsigned depth)
Compute the square root of a 32-bit floating-point scalar.
Definition: xs3_s32_sqrt.c:36
void xs3_unpack_float_s16(int16_t *mantissa, exponent_t *exp, const float input)
Unpack an IEEE 754 single-precision float into a 16-bit mantissa and exponent.
Definition: xs3_scalar_ops.c:10
int32_t xs3_s32_mul(exponent_t *a_exp, const int32_t b, const int32_t c, const exponent_t b_exp, const exponent_t c_exp)
Compute the product of two 32-bit floating-point scalars.
Definition: xs3_scalar_ops.c:71
void xs3_unpack_float(int32_t *mantissa, exponent_t *exp, const float input)
Unpack an IEEE 754 single-precision float into a 32-bit mantissa and exponent.
Definition: xs3_util.c:25
int16_t xs3_scalar_s32_to_s16(exponent_t *a_exp, const int32_t b, const exponent_t b_exp)
Convert a 32-bit floating-point scalar to a 16-bit floating-point scalar.
Definition: xs3_scalar_ops.c:32
int16_t xs3_s16_inverse(exponent_t *a_exp, const int16_t b)
Compute the inverse of a 16-bit integer.
Definition: xs3_scalar_ops.c:87
float xs3_pack_float(const int32_t mantissa, const exponent_t exp)
Pack a floating point value into an IEEE 754 single-precision float.
Definition: xs3_util.c:16
int32_t xs3_s32_inverse(exponent_t *a_exp, const int32_t b)
Compute the inverse of a 32-bit integer.
Definition: xs3_scalar_ops.c:99
int32_t xs3_scalar_s16_to_s32(exponent_t *a_exp, const int16_t b, const exponent_t b_exp, const unsigned remove_hr)
Convert a 16-bit floating-point scalar to a 32-bit floating-point scalar.
Definition: xs3_scalar_ops.c:43