We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 5418 - [patch] Add system features detection for Elbrus (E2K)
Summary: [patch] Add system features detection for Elbrus (E2K)
Status: RESOLVED FIXED
Alias: None
Product: SDL
Classification: Unclassified
Component: *don't know* (show other bugs)
Version: HG 2.1
Hardware: Other Linux
: P2 normal
Assignee: Ryan C. Gordon
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-12-26 14:43 UTC by Ivan Kuzmenko
Modified: 2020-12-29 04:59 UTC (History)
2 users (show)

See Also:


Attachments
patch (3.06 KB, patch)
2020-12-26 14:43 UTC, Ivan Kuzmenko
Details | Diff
patch (USE THIS INSTEAD OF FIRST ONE) (2.76 KB, patch)
2020-12-26 19:15 UTC, Ivan Kuzmenko
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Ivan Kuzmenko 2020-12-26 14:43:09 UTC
Created attachment 4609 [details]
patch

MCST Elbrus 2000 (E2K, https://en.wikipedia.org/wiki/Elbrus_2000) is a russian processor architecture based on VLIW/EPIC instruction set (like Intel Itanium (IA-64) architecture). Architecture has half native / half software support of most Intel/AMD SIMD (e.g. MMX/SSE/SSE2/SSE3/SSSE3/SSE4.1/SSE4.2/AES/AVX/AVX2 & 3DNow!/SSE4a/XOP/FMA4).
It also has built-in x86/x86_64 <-> e2k binary translators  (RTC, http://www.mcst.ru/rtc and Lintel, http://www.mcst.ru/lintel) that can run code for x86/x86_64 architecture (Transmeta did something similiar with their Crusoe series) with SIMD extensions support.
Attached patch allows SDL2 to detect extensions supported by E2K like MMX, 3dNOW!, AVX etc. (test/testplatform log: https://termbin.com/7qs3).
Comment 1 Ozkan Sezer 2020-12-26 18:48:51 UTC
Which gcc version supports __builtin_cpu_name()?  I can't find
documentation for it.
Comment 2 Ivan Kuzmenko 2020-12-26 19:15:43 UTC
Created attachment 4610 [details]
patch (USE THIS INSTEAD OF FIRST ONE)
Comment 3 Ivan Kuzmenko 2020-12-26 19:18:58 UTC
(In reply to Ozkan Sezer from comment #1)
> Which gcc version supports __builtin_cpu_name()?  I can't find
> documentation for it.

const char* __builtin_cpu_name (void)
That's a MCST lcc for E2K exclusive function which returns name of used CPU.
Comment 4 Sam Lantinga 2020-12-28 19:54:30 UTC
These tests should be based on runtime environment, not compiler environment. It's completely possible to build SDL with MMX defined and run it on a processor that doesn't have MMX.

Similarly for E2K, I assume that it's possible to compile SDL for x86 and then run it on that processor and it should detect the change at runtime.

Look at the code in SDL_GetCPUCacheLineSize() for an example of dynamically changing results based on the CPU type.
Comment 5 Alibek 2020-12-28 21:37:57 UTC
Sam, I'm afraid that there is no real need of doing so on E2K.

E2K unlike Intel, doesn't have CPUID instruction and there is no real way to know, for example, to know L1 cache size. I didn't really heard about such instruction or special register. The only way is to rely on numbers given by Linux kernel at /proc/cpuinfo. (And even these numbers are actually hardcoded into kernel)

3DNOW/MMX/SSE support in E2K is done at compile-time, we can only use compiler intrinsics that are translated into native E2K code. It's directly supported by vendor and common way to re-use code written for Intel processors. There is no such thing as "MMX support" in runtime. 

If these macro values will be hardcoded into SDL binary, there can be also theoretical possibility that if software using SDL will be compiled with another compiler version that one that was used to compile SDL itself, the values returned by SDL_Has* functions can be outdated and not reflect what is really supported by compiler. For example, latest version of LCC (eLbrus C Compiler) does not support AVX2 but maybe it will be added in the future.

What I do suggest though, is to give ports ability to define SDL_Has3DNOW/MMX/SSE function as macros for such architectures. Therefore compiler can enable and optimize branches in applications that rely on these functions.
Comment 6 Alibek 2020-12-28 21:51:31 UTC
> For example, latest version of LCC (eLbrus
> C Compiler) does not support AVX2 but maybe it will be added in the future.

My bad, it does define __AVX2__ and seems implements it somehow.
Comment 7 Sam Lantinga 2020-12-29 04:59:12 UTC
Ah, I see. Okay, in that case, your patch looks fine to me, and I've added it:
https://hg.libsdl.org/SDL/rev/9418952a355d