-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
233 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* Copyright 2024 Yury Gribov | ||
* | ||
* The MIT License (MIT) | ||
* | ||
* Use of this source code is governed by MIT license that can be | ||
* found in the LICENSE.txt file. | ||
*/ | ||
|
||
#include "interposed.h" | ||
|
||
__attribute__((visibility("default"))) | ||
vector_type foo(vector_type x) { | ||
return 3 *x; | ||
} | ||
|
||
static | ||
#ifdef __clang__ | ||
# if __clang_major__ >= 14 | ||
__attribute__((noipa)) | ||
# else | ||
__attribute__((noinline)) | ||
# endif | ||
#else | ||
__attribute__((noinline,noclone)) | ||
#endif | ||
vector_type dummy(vector_type x0, vector_type x1, vector_type x2, vector_type x3, vector_type x4, vector_type x5, vector_type x6, vector_type x7) { | ||
return x0 + x1 + x2 + x3 + x4 + x5 + x6 + x7; | ||
} | ||
|
||
__attribute__((constructor)) void touch_vector_regs() { | ||
vector_type zero = {0}; | ||
dummy(zero, zero, zero, zero, zero, zero, zero, zero); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* Copyright 2024 Yury Gribov | ||
* | ||
* The MIT License (MIT) | ||
* | ||
* Use of this source code is governed by MIT license that can be | ||
* found in the LICENSE.txt file. | ||
*/ | ||
|
||
#ifndef INTERPOSED_H | ||
#define INTERPOSED_H | ||
|
||
// Determine number of 32-bit ints in native vector type | ||
// for each supported platform | ||
#if defined __AVX2__ /* ZMM regs */ | ||
# define VECTOR_SIZE 16 | ||
#elif defined __AVX__ /* YMM regs */ | ||
# define VECTOR_SIZE 8 | ||
#elif defined __SSE__ /* XMM regs */ \ | ||
|| defined __aarch64__ /* NEON regs */ | ||
# define VECTOR_SIZE 4 | ||
#elif defined __MMX__ /* MMX regs */ \ | ||
|| defined __arm__ /* NEON regs */ | ||
# define VECTOR_SIZE 2 | ||
#else | ||
# error "Unknown platform" | ||
#endif | ||
|
||
typedef int vector_type __attribute__((vector_size(sizeof(int) * VECTOR_SIZE))); | ||
|
||
extern vector_type foo(vector_type x); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* Copyright 2024 Yury Gribov | ||
* | ||
* The MIT License (MIT) | ||
* | ||
* Use of this source code is governed by MIT license that can be | ||
* found in the LICENSE.txt file. | ||
*/ | ||
|
||
#include <stdio.h> | ||
|
||
#include "interposed.h" | ||
|
||
#if VECTOR_SIZE == 2 | ||
# define VECTOR_INIT {1, 2} | ||
#elif VECTOR_SIZE == 4 | ||
# define VECTOR_INIT {1, 2, 3, 4} | ||
#elif VECTOR_SIZE == 8 | ||
# define VECTOR_INIT {1, 2, 3, 4, 5, 6, 7} | ||
#elif VECTOR_SIZE == 16 | ||
# define VECTOR_INIT {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15} | ||
#else | ||
# error "Unsupported vector size" | ||
#endif | ||
|
||
int main() { | ||
vector_type x = VECTOR_INIT, res = foo(x), ref = 3 * x; | ||
int i; | ||
for (i = 0; i < VECTOR_SIZE; ++i) { | ||
if (res[i] != ref[i]) { | ||
printf("NOT OK\n"); | ||
return 1; | ||
} | ||
} | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#!/bin/sh | ||
|
||
# Copyright 2024 Yury Gribov | ||
# | ||
# The MIT License (MIT) | ||
# | ||
# Use of this source code is governed by MIT license that can be | ||
# found in the LICENSE.txt file. | ||
|
||
# This test verifies that Implib trampolines save/restore vector regs correctly. | ||
# Run it like | ||
# ./run.sh ARCH | ||
|
||
set -eu | ||
|
||
cd $(dirname $0) | ||
|
||
if test -n "${1:-}"; then | ||
ARCH="$1" | ||
fi | ||
|
||
. ../common.sh | ||
|
||
CFLAGS="-g -O2 $CFLAGS" | ||
|
||
# Build shlib to test against | ||
$CC $CFLAGS -shared -fPIC interposed.c -o libinterposed.so | ||
|
||
# Prepare implib | ||
${PYTHON:-} ../../implib-gen.py -q --target $TARGET libinterposed.so | ||
|
||
# Build app | ||
$CC $CFLAGS main.c libinterposed.so.tramp.S libinterposed.so.init.c $LIBS | ||
|
||
LD_LIBRARY_PATH=.:${LD_LIBRARY_PATH:-} $INTERP ./a.out > a.out.log | ||
diff test.ref a.out.log | ||
|
||
echo SUCCESS |
Empty file.