Add capability to declare specific attribute

Signed-off-by: VictorRodriguez <vm.rod25@gmail.com>
This commit is contained in:
VictorRodriguez
2019-01-26 16:38:58 -06:00
committed by Victor Rodriguez
parent 8b56c1fc1c
commit 6d93ec3cea
3 changed files with 31 additions and 3 deletions
+11
View File
@@ -76,6 +76,17 @@ The command generates the following example.c.patch patch:
{
int i,x;
```
If you want to use a differnt target for your code you can create a file targets.conf
For example
```
#if defined(i386__) || defined(__i386__) || defined(_M_IX86) || defined(_M_IX86) || defined(__X86__) || defined(_X86_) || defined(__I86__) || defined(__INTEL__) || defined(__amd64__) || defined(__amd64) || defined(__x86_64__) || defined(__x86_64) || defined(_M_AMD64)
__attribute__((target_clones("avx2","arch=haswell","default")))
#endif
```
### 3. Apply the patch
Using the example.c.patch file, apply the patch to example.c:
+17 -3
View File
@@ -26,13 +26,27 @@
# USAGE: perl fmvpatches.pl <path_to_logfile> <full_path_to_source_code>
my %f;
my $fmv = {};
my ($log_file, $source_path) = @ARGV;
sub patch_function {
my $avx2 = '__attribute__((target_clones("avx2","arch=atom","default")))'."\n";
my $attribute = "";
my $target_clones = 'targets.conf';
if (-e $target_clones) {
open(my $fh, '<:encoding(UTF-8)', $target_clones)
or die "Could not open file '$target_clones' $!";
while (my $row = <$fh>) {
chomp $row;
$attribute= $attribute.$row."\n";
}
}else {
$attribute = '__attribute__((target_clones("avx2","arch=atom","default")))'."\n";
}
my ($file,@patch_line) = @_;
my $patch_file = "$file"."~";
@@ -48,7 +62,7 @@ sub patch_function {
last if $. == ($line_num - 1);
}
print $out $avx2;
print $out $attribute;
}
while( <$in> ) {
print $out $_;
+3
View File
@@ -0,0 +1,3 @@
#if defined(i386__) || defined(__i386__) || defined(_M_IX86) || defined(_M_IX86) || defined(__X86__) || defined(_X86_) || defined(__I86__) || defined(__INTEL__) || defined(__amd64__) || defined(__amd64) || defined(__x86_64__) || defined(__x86_64) || defined(_M_AMD64)
__attribute__((target_clones("avx2","arch=haswell","default")))
#endif