Open baiango opened 1 month ago
I was trying to make a Hash map project in any language that can handle the task. Then found C and C++'s build system was unreliable even with CMake, I am uncertain about will the hash map compile on other system such as Linux and macOS besides Windows. An additional issue is: There was no built-in unit test, which made correctness verification of the hash map very difficult.
Nonetheless, Rust's stringent and over-engineered type system extended the development time quite much, even with the assist of unit test feature. Rust was antagonistic to uninitialized variables.
Thus, I stumbled upon V; realized that it could not compile with the transpiled C code, however, the V code is able to run with the v run
command if the code did not get linked to the C code.
My additional concerns are, the base binary (300 KiB) is almost double the size of the original C GCC compiled binary. And lastly, V does not support AVX2 intrinsic beyond x86 assembly in its error message. But, I am able to compile the V code with the novel command v -gc none -manualfree -prod -cc gcc -cflags "-O2 -mavx2 -Wall" crun main.v
.
#include <immintrin.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdalign.h>
bool compare_ymm(const void *a, const void *b) {
bool result;
__asm__ (
"vmovdqa %1, %%ymm0\n\t"
"vpxor %2, %%ymm0, %%ymm0\n\t"
"vptest %%ymm0, %%ymm0\n\t"
"sete %0\n\t"
"vzeroupper\n\t"
: "=r" (result)
: "m" (*(const __m256i *)a), "m" (*(const __m256i *)b)
: "ymm0"
);
return result;
}
int main() {
alignas(32) unsigned long long a[4] = {1, 2, 3, 4};
alignas(32) unsigned long long b[4] = {1, 2, 3, 4};
bool result = compare_ymm(a, b);
if (result) {
printf("The two arrays are equal.\n");
} else {
printf("The two arrays are not equal.\n");
}
return 0;
}
error: unknown register %ymm0
is not a V error, it is from tcc
.
Using v -cg -cc gcc run bug.v
you will get:
/tmp/v_1000/bug.01J3T5HXC7AVCRC7DPJGB4QQ4E.tmp.c: Assembler messages:
/tmp/v_1000/bug.01J3T5HXC7AVCRC7DPJGB4QQ4E.tmp.c:13245: Error: operand type mismatch for `vmovdqa'
/tmp/v_1000/bug.01J3T5HXC7AVCRC7DPJGB4QQ4E.tmp.c:13245: Error: operand type mismatch for `vpxor'
I believe 2..x / 2 + 1
is the issue because it is invalid
I apologize for rubbing people the wrong way. The issue was about getting manual AVX2 intrinsic to work in V without the compiling error and usable.
I believe
2..x / 2 + 1
is the issue because it is invalid
It is only invalid because V doesn't have a runtime. At runtime, you could check the value of x
and decide then whether it's a valid range or not. For example, if x >= 4, it's fine. It should only be an invalid range if x <= 3.
However, with only being able to check at compile time, it is better to mark is is invalid due to the right side not being a constant/literal value that's >= 3.
Describe the bug
TCC and GCC on Windows failed to compile the C code. It can be done by
v -o main.c main.v ; if ($?) { C:\tcc\tcc.exe main.c }
in PowerShell with this code too, and get the error messagemain.c:414: error: include file 'stdnoreturn.h' not found
.In V generated main.c code from 412 to 425 shows that it includes something with predetermined directories without my source codes:
Reproduction Steps
main.v
strcmp.h
strcmp.c
v.mod
Expected Behavior
Compiles successful without an error and output.
Current Behavior
Possible Solution
I do not know. I tried to inline the code, and it reports it does not support
ymm0
register.main.v
Additional Information/Context
V version
Current V version: V 0.4.7 52fe7c0, timestamp: 2024-07-26 10:28:17 +0300
Environment details (OS name and version, etc.)