Skip to content

[libc] [stdfix] Implement fixed-point mulifx functions #114503

@duncpro

Description

@duncpro

The fixed-point mulifx family of functions from ISO 18037 are not in llvm-libc yet.

The muli functions multiply an integer operand by a fixed-point operand and return an integer value.
...
If an integer result of one of these functions overflows, the behavior is undefined.

- ISO 18037

Definitions

int mulir(int, fract);
long int mulilr(long int, long fract);
int mulik(int, accum);
long int mulilk(long int, long accum);

unsigned int muliur(unsigned int, unsigned fract);
unsigned long int muliulr(unsigned long int, unsigned long fract);
unsigned int muliuk(unsigned int, unsigned accum);
unsigned long int muliulk(unsigned long int, unsigned long accum);

Implementation

For accum types this could be implemented by converting the integer operand into an accum with no fractional value, and then using the multiplication operator on the two accums. Then truncating the result's fractional value, and finally bitcasting to the integer type.

For fract types we could convert the fract into an accum with no integral value, and then use the same routine above.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions