Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: yuvi/gas-preprocessor
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: master
Choose a base ref
...
head repository: libjpeg-turbo/gas-preprocessor
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: main
Choose a head ref
Checking mergeability… Don’t worry, you can still create the pull request.
  • 6 commits
  • 2 files changed
  • 2 contributors

Commits on Jan 29, 2014

  1. This patch works around an issue with the new Clang front end in Xcod…

    …e 5.0. When passed an argument of '-x assembler', Clang seems to ignore all other arguments. This is a problem, because we have to pass Clang an argument of -no-integrated-as in order to make the libjpeg-turbo NEON code assemble correctly. Thus, this patch creates a temporary file and then calls system() to execute the assembler, rather than attempting to pass the filtered assembly code to the assembler via stdin. Note that we also now need to strip the various -M* options from the assembler command line, else the dependency file for the SIMD object will depend on the temporary assembly file (which is deleted after use) and not the original assembly file.
    
    git-svn-id: svn+ssh://svn.code.sf.net/p/libjpeg-turbo/code/gas-preprocessor@1103 632fc199-4ca6-4c93-a231-07263d6284db
    dcommander committed Jan 29, 2014
    Copy the full SHA
    f45b2b5 View commit details

Commits on Jul 23, 2014

  1. ARM64 support

    git-svn-id: svn+ssh://svn.code.sf.net/p/libjpeg-turbo/code/gas-preprocessor@1334 632fc199-4ca6-4c93-a231-07263d6284db
    dcommander committed Jul 23, 2014
    Copy the full SHA
    255a216 View commit details

Commits on Dec 19, 2014

  1. Port enhancements from

    https://raw.githubusercontent.com/libav/gas-preprocessor/master/gas-preprocessor.pl
    that allow gas-preprocessor.pl to convert a few ARM64 instructions that we use and that the XCode 5.1 clang assembler doesn't understand.  The rest of the ARM64 iOS build issues were addressed by making cosmetic modifications to the assembly file.
    
    git-svn-id: svn+ssh://svn.code.sf.net/p/libjpeg-turbo/code/gas-preprocessor@1449 632fc199-4ca6-4c93-a231-07263d6284db
    dcommander committed Dec 19, 2014
    Copy the full SHA
    7928f77 View commit details

Commits on Jul 31, 2015

  1. Copy the full SHA
    4338df4 View commit details

Commits on Nov 19, 2016

  1. Copy the full SHA
    49d4ba0 View commit details

Commits on Nov 25, 2016

  1. Copy the full SHA
    42cb38c View commit details
Showing with 64 additions and 27 deletions.
  1. +0 −20 README
  2. +64 −7 gas-preprocessor.pl
20 changes: 0 additions & 20 deletions README

This file was deleted.

71 changes: 64 additions & 7 deletions gas-preprocessor.pl
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#!/usr/bin/env perl
# by David Conrad
# modifications by D. R. Commander, Copyright (C)2013, 2016
# This code is licensed under GPLv2 or later; go to gnu.org to read it
# (not that it much matters for an asm preprocessor)
# usage: set your assembler to be something like "perl gas-preprocessor.pl gcc"
use strict;
use File::Temp qw(tempfile);

# Apple's gas is ancient and doesn't support modern preprocessing features like
# .rept and has ugly macro syntax, among other things. Thus, this script
@@ -13,6 +15,8 @@
my @gcc_cmd = @ARGV;
my @preprocess_c_cmd;

my $arch = "arm";

my $fix_unreq = $^O eq "darwin";

if ($gcc_cmd[0] eq "-fix-unreq") {
@@ -45,13 +49,15 @@
}
}
}
@gcc_cmd = map { /\.[csS]$/ ? qw(-x assembler -) : $_ } @gcc_cmd;
@preprocess_c_cmd = map { /\.o$/ ? "-" : $_ } @preprocess_c_cmd;

my $comm;

# detect architecture from gcc binary name
if ($gcc_cmd[0] =~ /arm/) {
if ($gcc_cmd[0] =~ /arm64|aarch64/) {
$comm = ';';
$arch = "aarch64";
} elsif ($gcc_cmd[0] =~ /arm/) {
$comm = '@';
} elsif ($gcc_cmd[0] =~ /powerpc|ppc/) {
$comm = '#';
@@ -60,7 +66,10 @@
# look for -arch flag
foreach my $i (1 .. $#gcc_cmd-1) {
if ($gcc_cmd[$i] eq "-arch") {
if ($gcc_cmd[$i+1] =~ /arm/) {
if ($gcc_cmd[$i+1] =~ /arm64|aarch64/) {
$comm = ';';
$arch = "aarch64";
} elsif ($gcc_cmd[$i+1] =~ /arm/) {
$comm = '@';
} elsif ($gcc_cmd[$i+1] =~ /powerpc|ppc/) {
$comm = '#';
@@ -71,7 +80,10 @@
# assume we're not cross-compiling if no -arch or the binary doesn't have the arch name
if (!$comm) {
my $native_arch = qx/arch/;
if ($native_arch =~ /arm/) {
if ($native_arch =~ /arm64|aarch64/) {
$comm = ';';
$arch = "aarch64";
} elsif ($native_arch =~ /arm/) {
$comm = '@';
} elsif ($native_arch =~ /powerpc|ppc/) {
$comm = '#';
@@ -85,7 +97,7 @@
my %ppc_spr = (ctr => 9,
vrsave => 256);

open(ASMFILE, "-|", @preprocess_c_cmd) || die "Error running preprocessor";
open(ASMFILE, "-|", @preprocess_c_cmd) || die "Error running preprocessor: $!";

my $current_macro = '';
my $macro_level = 0;
@@ -100,6 +112,8 @@

my %symbols;

my %aarch64_req_alias;

# pass 1: parse .macro
# note that the handling of arguments is probably overly permissive vs. gas
# but it should be the same for valid cases
@@ -163,7 +177,7 @@ sub handle_if {
} elsif ($type eq "lt") {
$result = eval_expr($expr) < 0;
} else {
chomp($line);
chomp($line);
die "unhandled .if varient. \"$line\"";
}
push (@ifstack, $result);
@@ -367,10 +381,13 @@ sub expand_macros {
}

close(ASMFILE) or exit 1;
my $fh, my $filename;
if ($ENV{GASPP_DEBUG}) {
open(ASMFILE, ">&STDOUT");
} else {
open(ASMFILE, "|-", @gcc_cmd) or die "Error running assembler";
($fh, $filename) = tempfile("gas-preprocessor-tmp-XXXXXX", SUFFIX => '.S',
TMPDIR => 1, UNLINK => 1);
open(ASMFILE, ">" . $filename) or die "Error creating temporary file: $!";
}

my @sections;
@@ -457,6 +474,12 @@ sub expand_macros {
}
}

if ($line =~ /\.unreq\s+(.*)/) {
if (defined $aarch64_req_alias{$1}) {
delete $aarch64_req_alias{$1};
next;
}
}
# old gas versions store upper and lower case names on .req,
# but they remove only one on .unreq
if ($fix_unreq) {
@@ -466,6 +489,34 @@ sub expand_macros {
}
}

if ($arch eq "aarch64") {
# clang's integrated aarch64 assembler in Xcode 5 does not support .req/.unreq
if ($line =~ /\b(\w+)\s+\.req\s+(\w+)\b/) {
$aarch64_req_alias{$1} = $2;
next;
}
foreach (keys %aarch64_req_alias) {
my $alias = $_;
# recursively resolve aliases
my $resolved = $aarch64_req_alias{$alias};
while (defined $aarch64_req_alias{$resolved}) {
$resolved = $aarch64_req_alias{$resolved};
}
$line =~ s/\b$alias\b/$resolved/g;
}
}
if ($arch eq "aarch64") {
# fix missing aarch64 instructions in Xcode 5.1 (beta3)
# mov with vector arguments is not supported, use alias orr instead
if ($line =~ /^\s*mov\s+(v\d[\.{}\[\]\w]+),\s*(v\d[\.{}\[\]\w]+)\b\s*$/) {
$line = " orr $1, $2, $2\n";
}
# movi 16, 32 bit shifted variant, shift is optional
if ($line =~ /^\s*movi\s+(v[0-3]?\d\.(?:2|4|8)[hsHS])\s*,\s*(#\w+)\b\s*$/) {
$line = " movi $1, $2, lsl #0\n";
}
}

if ($line =~ /\.rept\s+(.*)/) {
$num_repts = $1;
$rept_lines = "\n";
@@ -532,4 +583,10 @@ sub expand_macros {
grep exists $thumb_labels{$_}, keys %call_targets;

close(ASMFILE) or exit 1;

@gcc_cmd = map { /\.[csS]$/ ? $filename : $_ } @gcc_cmd;
@gcc_cmd = map { /\-M[DFPT]|\.lo|\.Tpo$/ ? "" : $_ } @gcc_cmd;
system @gcc_cmd;
$? == 0 or die "Error running assembler";

#exit 1