Skip to content

Fix CPU feature detection #29

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

Merged
merged 1 commit into from
Sep 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 7 additions & 16 deletions gcc/config/i386/i386-jit.cc
Original file line number Diff line number Diff line change
Expand Up @@ -57,28 +57,19 @@ void
ix86_jit_register_target_info (void)
{
const char *params[] = {"arch", x86_bits};
const char *arch = host_detect_local_cpu (2, params);

fprintf (stderr, "***************************** Arch: %s\n**********************************", arch);
const char* local_cpu = host_detect_local_cpu (2, params);
std::string arch = local_cpu;
free (const_cast <char *> (local_cpu));

const char* arg = "-march=";
const char* arg_pos = strstr(arch, arg);
fprintf (stderr, "***************************** arg_pos: %s\n**********************************", arg_pos);
const char* arg_value = arg_pos + strlen(arg);
fprintf (stderr, "***************************** arg_value: %s\n**********************************", arg_value);
const char* arg_value_end = strchr(arg_value, ' ');

size_t len = arg_value_end - arg_value;
char *cpu = new char[len];
strncpy(cpu, arg_value, len);
cpu[len] = '\0';
fprintf (stderr, "***************************** cpu: %s\n**********************************", cpu);
size_t arg_pos = arch.find (arg) + strlen (arg);
size_t end_pos = arch.find (" ", arg_pos);

std::string cpu = arch.substr (arg_pos, end_pos - arg_pos);
jit_target_set_arch (cpu);

jit_target_set_128bit_int_support (targetm.scalar_mode_supported_p (TImode));

free (const_cast <char *> (arch));

if (TARGET_MMX)
jit_add_target_info ("target_feature", "mmx");
if (TARGET_SSE)
Expand Down
9 changes: 2 additions & 7 deletions gcc/jit/jit-target.cc
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ jit_add_target_info (const char *key, const char *value)
}

void
jit_target_set_arch (const char* arch)
jit_target_set_arch (std::string const& arch)
{
jit_target_info.m_arch = arch;
}
Expand All @@ -70,15 +70,10 @@ jit_target_set_128bit_int_support (bool support)
jit_target_info.m_supports_128bit_int = support;
}

target_info::~target_info()
{
free (const_cast<void *> ((const void *) m_arch));
}

target_info *
jit_get_target_info ()
{
target_info *info = new target_info {std::move(jit_target_info)};
target_info *info = new target_info {jit_target_info};
jit_target_info = target_info{};
return info;
}
Expand Down
7 changes: 3 additions & 4 deletions gcc/jit/jit-target.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

#include "jit-target.def"

#include <string>
#include <unordered_map>
#include <unordered_set>

Expand All @@ -49,20 +50,18 @@ struct CStringEqual {

struct target_info {
public:
~target_info();

bool has_target_value (const char *key, const char *value);

std::unordered_map<const char *, std::unordered_set<const char *, CStringHash, CStringEqual>, CStringHash, CStringEqual> m_info;
const char *m_arch = nullptr;
std::string m_arch;
bool m_supports_128bit_int = false;
};

/* Each target can provide their own. */
extern struct gcc_targetjitm targetjitm;

extern void jit_target_init ();
extern void jit_target_set_arch (const char* arch);
extern void jit_target_set_arch (std::string const& arch);
extern void jit_target_set_128bit_int_support (bool support);
extern void jit_add_target_info (const char *key, const char *value);
extern target_info * jit_get_target_info ();
Expand Down
2 changes: 1 addition & 1 deletion gcc/jit/libgccjit.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3899,7 +3899,7 @@ gcc_jit_target_info_cpu_supports (gcc_jit_target_info *info,
const char *
gcc_jit_target_info_arch (gcc_jit_target_info *info)
{
return info->m_arch;
return info->m_arch.c_str ();
}

int
Expand Down