Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Additional (scalar) helper functions. #125

Open
astewart-xmos opened this issue Nov 29, 2022 · 0 comments
Open

Additional (scalar) helper functions. #125

astewart-xmos opened this issue Nov 29, 2022 · 0 comments
Labels
size:S type:enhancement New feature or request version: minor incr Minor version number increment required. (Change adds new features)

Comments

@astewart-xmos
Copy link
Contributor

I've repeatedly found myself needing to write helper functions such as the following:

int32_t ashr32(int32_t x, right_shift_t shr){
  int32_t y;
  if(shr >= 0) y = (x >> ( shr) );
  else         y = (x << (-shr) );
  return y;
}

int64_t ashr64(int64_t x, right_shift_t shr){
  int64_t y;
  if(shr >= 0) y = (x >> ( shr) );
  else         y = (x << (-shr) );
  return y;
}

int32_t float_s32_to_fixed(float_s32_t v, exponent_t output_exp){
  right_shift_t shr = output_exp - v.exp;
  return ashr32(v.mant, shr); 
}

int32_t float_s64_to_fixed(float_s64_t v, exponent_t output_exp){
  right_shift_t shr = output_exp - v.exp;
  return ashr64(v.mant, shr); 
}

int32_t float_to_fixed(float x, exponent_t output_exp){
  float_s32_t y = f32_to_float_s32(x);
  return float_s32_to_fixed(y, output_exp);
}

Including within lib_xcore_math. I believe there are already macros for the arithmetic shifts, but they aren't exposed as part of the public API. These should probably be added.

@astewart-xmos astewart-xmos added type:enhancement New feature or request size:S version: minor incr Minor version number increment required. (Change adds new features) labels Nov 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size:S type:enhancement New feature or request version: minor incr Minor version number increment required. (Change adds new features)
Projects
None yet
Development

No branches or pull requests

1 participant