[libc-commits] [libc] [libc][stdfix] Implement `countlsfx` functions (PR #114318)

via libc-commits libc-commits at lists.llvm.org
Wed Nov 6 10:01:50 PST 2024


PiJoules wrote:

> > For each of the `LIST_COUNTLS_TESTS`, could you also add one for the saturation equivalent of each test? Saturation shouldn't affect the result but it would be nice to assert this is the case.
> 
> AFAIK `countlsfx` is not defined for `_Sat` (saturating) types.
> 
> <img alt="Screenshot 2024-11-05 at 5 37 24 PM" width="889" src="https://private-user-images.githubusercontent.com/9706506/383345409-261d5e16-7270-4ad5-bad9-8411885191da.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzA5MTYwODksIm5iZiI6MTczMDkxNTc4OSwicGF0aCI6Ii85NzA2NTA2LzM4MzM0NTQwOS0yNjFkNWUxNi03MjcwLTRhZDUtYmFkOS04NDExODg1MTkxZGEucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI0MTEwNiUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNDExMDZUMTc1NjI5WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9YjM3NzQxOThkNjRkMTA3N2I1YmI2MGI0YWNlNTUyMDc4ZmFjYzA0ZjI3Y2QxODg3YjFjMzBmZWZkYTU2NGY2YyZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QifQ.zOKbFiuXHb4H00RwtQvBPAzpoLMO2X8Et0trYeMFAPE">
> However, saturating arithmetic can be requested for non-`_Sat` fixed-point types via a `#pragma`.
> 
> <img alt="Screenshot 2024-11-05 at 5 41 09 PM" width="888" src="https://private-user-images.githubusercontent.com/9706506/383346472-5ee5e654-c328-44c8-b619-31dd2aa94c32.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzA5MTYwODksIm5iZiI6MTczMDkxNTc4OSwicGF0aCI6Ii85NzA2NTA2LzM4MzM0NjQ3Mi01ZWU1ZTY1NC1jMzI4LTQ0YzgtYjYxOS0zMWRkMmFhOTRjMzIucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI0MTEwNiUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNDExMDZUMTc1NjI5WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9YzU2Nzk4NmMzMzE0M2IxYWU0NGZkZDM2MDAxNTY0Njk3ZWQ5YTE0YzM2MjM1ZTU0ZjdhZjFmYjQzNDI3NDY2OCZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QifQ.YXUwr0IMdx6knnKgPIpP-BMjCz7JiIEguQS5fO8ucOo">
> But it appears `clang` does not support this pragma yet ([feature-tracking issue](https://github.com/llvm/llvm-project/issues/43241)).
> 
> <img alt="Screenshot 2024-11-05 at 5 38 11 PM" width="1183" src="https://private-user-images.githubusercontent.com/9706506/383347437-208b685f-690d-4dc7-85be-714dc6420a5f.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzA5MTYwODksIm5iZiI6MTczMDkxNTc4OSwicGF0aCI6Ii85NzA2NTA2LzM4MzM0NzQzNy0yMDhiNjg1Zi02OTBkLTRkYzctODViZS03MTRkYzY0MjBhNWYucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI0MTEwNiUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNDExMDZUMTc1NjI5WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9MDFlZDAyZTBiN2U5NmEyNTVhYjlhNWQ0NjA2YmQ5YmQxZDAwZTA4ZjAzMWZmZTEzNjk3MGRlNjAwY2ZjNDc1OSZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QifQ.sDqkcuxybALisvp4o9Ed_7IElglrhfM2fIinnp9-fMM">
> @PiJoules Can you give guidance?

Oh what I mean was having some tests that pass saturating types to each of the functions taking non-saturating equivalent types, so something like:

```
_Sat short _Fract f = 0.5;
int i = countlshr(f);  // Should return the same value even if `f` was `short _Fract`
``` 

I wanted this just to assert that the result is correct independent of the saturation, but in hindsight I think that might not be appropriate here since that would be more along the lines of testing `_Sat`/non-`_Sat` conversion rather than the actual function implementation, so disregard my suggestion of adding the `_Sat` tests.

https://github.com/llvm/llvm-project/pull/114318


More information about the libc-commits mailing list