The source files below should be arranged as:
./main.go
./sqrt/sqrt.s
./sqrt/sqrt.go
To run:
| /* | |
| * Copyright (C) 2019-2025 Ayan Shafqat <[email protected]> | |
| * | |
| * This program is free software; you can redistribute it and/or modify | |
| * it under the terms of the GNU General Public License as published by | |
| * the Free Software Foundation; either version 2, or (at your option) | |
| * any later version. | |
| * | |
| * This program is distributed in the hope that it will be useful, | |
| * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| #include <stddef.h> | |
| #include <assert.h> | |
| #include <immintrin.h> | |
| static void v_f32_to_s1x15i(int16_t *dst, const float *src, size_t len) | |
| { | |
| const __m128 minval = _mm_set1_ps(-1.0F); | |
| const __m128 maxval = _mm_set1_ps(+0x7fffff8p-27F); | |
| const __m128 scale = _mm_set1_ps(32768.0F); |
| /* I always wondered how variable length arguments worked in C. | |
| * So, I just ended up implementing it in x86. | |
| * NOTE: THIS CODE BELOW ONLY WORKS IN x86, AND NOT TESTED IN ANY OTHER ARCHITECTURE. | |
| * | |
| * To compile: | |
| * gcc -Wall -o prog vargs.c && ./prog | |
| * >> Testing: Hello world 10 -100 | |
| */ | |
| /* |
The source files below should be arranged as:
./main.go
./sqrt/sqrt.s
./sqrt/sqrt.go
To run:
| #ifndef ABS | |
| #ifdef __GNUC__ | |
| #define ABS(x) __extension__({ \ | |
| __builtin_choose_expr( \ | |
| __builtin_types_compatible_p(__typeof__(x), long int), \ | |
| __builtin_labs(x), \ | |
| __builtin_choose_expr( \ | |
| __builtin_types_compatible_p(__typeof__(x), int), \ | |
| __builtin_abs(x), \ |
| #!/usr/bin/env bash | |
| # | |
| # This program generates a header file that is needed to figure out number of | |
| # bits in different integer types. | |
| # | |
| header_file=$1 | |
| binary=`mktemp` | |
| header_base=`basename "${header_file}"` |