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

examples: add cpu_features/ folder, containing several examples, using SSE and MMX assembly instructions #22645

Merged
merged 11 commits into from
Nov 21, 2024

Conversation

enghitalo
Copy link
Contributor

@enghitalo enghitalo commented Oct 24, 2024

	mut bench := benchmark.start()
	for i := 0; i < 1000000; i++ {
		add_vectors_mmx(&a[0], &b[0], &result[0])
	}

	bench.measure('MMX')

	for j := 0; j < 1000000; j++ {
		for i := 0; i < 8; i++ {
			result2[i] = a[i] + b[i]
		}
	}
	bench.measure('Normal')
 # TCC
 SPENT     9.536 ms in MMX
 SPENT    90.291 ms in Normal
 # GCC
 SPENT     0.233 ms in MMX
 SPENT     1.956 ms in Normal

Huly®: V_0.6-21094

@enghitalo
Copy link
Contributor Author

TCC (tcc version 0.9.27 (x86_64 Linux)) and Clang (Ubuntu clang version 18.1.3 (1)) is working well to me
v -cc tcc run examples/cpu_flags/SSE_and_MMX_Extensions/mmx.v
v -cc clang run examples/cpu_flags/SSE_and_MMX_Extensions/mmx.v

@spytheman
Copy link
Member

Those examples of using specific CPU instructions, are not portable.
I also do not understand, what is the relation of them with cpu flags?

@KeitoTobi1
Copy link
Contributor

KeitoTobi1 commented Oct 25, 2024

Those examples of using specific CPU instructions, are not portable. I also do not understand, what is the relation of them with cpu flags?

I think this is an attempt to support different instruction sets that can be used for different CPUs, even for the same CPU.
In the case of amd64, there are sse, avx2, x87, mmx, and so on.
Perhaps you are referring to the SIMD instruction set.

@enghitalo
Copy link
Contributor Author

enghitalo commented Oct 25, 2024

Those examples of using specific CPU instructions, are not portable.
I also do not understand, what is the relation of them with cpu flags?

I will change it to cpu_features. When I run lscpu, the SIMD extensions (like SSE, AVX, or NEON) appear under the "Flags" section because lscpu lists all the features and capabilities supported by the CPU as "flags." In this context, the term "flag" is used to indicate available CPU features or instruction set extensions rather than the status bits (like Zero Flag or Carry Flag) used during program execution.

In lscpu output, these "flags" represent various supported capabilities of the processor, such as:

SIMD extensions (e.g., SSE, AVX): Indicate support for specific SIMD instruction sets.

Virtualization support (e.g., VT-x, AMD-V): Show if the CPU supports hardware virtualization.

Security features (e.g., NX, SMEP): Indicate protections like No-eXecute bit or Supervisor Mode Execution Protection.

@enghitalo enghitalo changed the title examples: cpu_flags examples: cpu_features Oct 25, 2024
@enghitalo enghitalo marked this pull request as draft October 25, 2024 15:09
@spytheman
Copy link
Member

spytheman commented Oct 25, 2024

Note that the existing ASM example examples/asm.v, has all of the platform dependent assembly in a $if amd64 { block.

If I am on a new ARM based Mac, and try to do: v build-examples on master, that example will still compile, since the CPU dependent assembly, will be simply skipped.

This is not the case for the examples in this PR.

@spytheman
Copy link
Member

Will you add the conditional checks, or should I just close the PR?

@enghitalo
Copy link
Contributor Author

Will you add the conditional checks, or should I just close the PR?

I'll add it. Sorry for the delay, I got caught up in other projects. If anyone is interested in making these changes for me, I'd be very happy!!

@spytheman spytheman marked this pull request as ready for review November 21, 2024 16:59
@spytheman spytheman changed the title examples: cpu_features examples: add cpu_features/ folder, containing several examples, using SSE and MMX assembly instructions Nov 21, 2024
@spytheman spytheman merged commit 05377f3 into vlang:master Nov 21, 2024
30 of 31 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants