Comments (10)
@TheDan64 awesome, thanks! I actually needed this translated code.
from c2rust.
I've added support for _mm_extract_epi32
's builtin (and a bunch of others I found) upstream w/ Clang 7; so those changes should be available next time we do a repo sync here.
from c2rust.
Sorry, we should have been more clear. For various reasons, we've had to do development in a non-public github repository that we'd occasionally sync with this one (which is indeed the canonical repository for this project). Going forward, we should be able to do most development in public here.
from c2rust.
It seems like the call to _mm_extract_epi32
is the issue here; but what's weird about it is that it seems to call into code for zero initializing an undefined variable. In any case, I expect that it should be fixable.
Behind that one, though, is an even stranger error: Subscript applied to non-pointer, kind: Some(Function { is_global: true, is_inline: true, is_implicit: false, is_extern: false, typ: CTypeId(10566), name: "MyGetIP_comp", parameters: [CDeclId(10568)], body: Some(CStmtId(10567)), attrs: {} })
and that also seems to be coming from the _mm_extract_epi32(prod, 0);
call... Weird.
from c2rust.
Also, are you using LLVM 6 or 7? A bunch of SIMD functions got moved to builtins in 7
from c2rust.
[21:47:45] d33tah@d33tah-laptop:/home/d33tah(0) > dpkg -l | rg -i llvm
ii libllvm6.0:amd64 1:6.0-1ubuntu2 amd64 Modular compiler and toolchain technologies, runtime library
ri libllvm6.0:i386 1:6.0-1ubuntu2 i386 Modular compiler and toolchain technologies, runtime library
ii libllvm7:amd64 1:7-3~ubuntu0.18.04.1 amd64 Modular compiler and toolchain technologies, runtime library
ii libllvm7:i386 1:7-3~ubuntu0.18.04.1 i386 Modular compiler and toolchain technologies, runtime library
ii libomp-dev 5.0.1-1 amd64 LLVM OpenMP runtime - dev package
ii libomp5:amd64 5.0.1-1 amd64 LLVM OpenMP runtime
ii llvm-6.0 1:6.0-1ubuntu2 amd64 Modular compiler and toolchain technologies
ii llvm-6.0-dev 1:6.0-1ubuntu2 amd64 Modular compiler and toolchain technologies, libraries and headers
ii llvm-6.0-runtime 1:6.0-1ubuntu2 amd64 Modular compiler and toolchain technologies, IR interpreter
ii mono-llvm-support 5.16.1.0-0xamarin1+ubuntu1804b1 amd64 Mono runtime - SGen
ii mono-llvm-tools 3.6.0+mono201805011452-0xamarin1+ubuntu1804b1 amd64 opt and llc for Mono llvm mode
from c2rust.
Thanks, the problem seems to be the definition of _mm_extract_epi32
is not a function but an awkward macro in LLVM 6 & 7:
#define _mm_extract_epi32(X, N) (__extension__ \
({ __v4si __a = (__v4si)(__m128i)(X); \
(int)__a[(N) & 3];}))
The problem is twofold:
- They instantiate a variable of a builtin type
__v4si
. This might be mockable with__m128i
since they should be equivalent - They index the builtin type, which, I don't believe rust supports on their simd types like
__m128i
.
I'm going to see if it's possible for us to correctly translate this as is however it will nonetheless not be very pretty and wont be able to use the rust function _mm_extract_epi32
OTOH, this will be much easier and nicer to support in LLVM 8 one day as it's just a builtin:
#define _mm_extract_epi32(X, N) \
(int)__builtin_ia32_vec_ext_v4si((__v4si)(__m128i)(X), (int)(N))
And that's easy enough to translate to the rust function.
I'm not sure if this is helpful but a correct translation of MyGetIP_comp
would look like this:
#[cfg ( target_arch = "x86" )]
pub use std::arch::x86::{__m128i, _mm_sub_epi8, _mm_cmpeq_epi8,
_mm_loadu_si128, _mm_set_epi8, _mm_set1_epi8,
_mm_setzero_si128, _mm_store_si128,
_mm_movemask_epi8, _mm_lddqu_si128, _mm_hadd_epi16,
_mm_maddubs_epi16, _mm_shuffle_epi8, _mm_extract_epi32};
#[cfg ( target_arch = "x86_64" )]
pub use std::arch::x86_64::{__m128i, _mm_sub_epi8, _mm_cmpeq_epi8,
_mm_loadu_si128, _mm_set_epi8, _mm_set1_epi8,
_mm_setzero_si128, _mm_store_si128,
_mm_movemask_epi8, _mm_lddqu_si128,
_mm_hadd_epi16, _mm_maddubs_epi16,
_mm_shuffle_epi8, _mm_extract_epi32};
#[inline]
unsafe extern "C" fn MyGetIP_comp(mut str: *const libc::c_char) -> UINT32 {
//"192.167.1.3"
let mut input: __m128i = _mm_lddqu_si128(str as *const __m128i);
let mut zm: uint64_t =
_mm_movemask_epi8(_mm_cmpeq_epi8(input, _mm_setzero_si128())) as
uint64_t;
zm ^= zm.wrapping_sub(1i32 as libc::c_ulong);
input = _mm_sub_epi8(input, _mm_set1_epi8('0' as i32 as libc::c_char));
//...X...X.X.XX... (signs)
let mut cmp: __m128i = input;
//6792 - magic index
let mut mask: uint64_t = _mm_movemask_epi8(cmp) as uint64_t;
mask &= zm;
let mut hashmask: uint64_t =
perfecthash(mask as libc::c_uint) as uint64_t;
//10 -1 -1 -1 8 -1 -1 -1 6 5 4 -1 2 1 0 -1
let mut shuf: __m128i =
*(TBL.as_ptr() as *const __m128i).offset(hashmask as isize);
//3 0 0 0 | 1 0 0 0 | 7 6 1 0 | 2 9 1 0
let mut arr: __m128i = _mm_shuffle_epi8(input, shuf);
let mut coeffs: __m128i =
_mm_set_epi8(0i32 as libc::c_char, 100i32 as libc::c_char,
10i32 as libc::c_char, 1i32 as libc::c_char,
0i32 as libc::c_char, 100i32 as libc::c_char,
10i32 as libc::c_char, 1i32 as libc::c_char,
0i32 as libc::c_char, 100i32 as libc::c_char,
10i32 as libc::c_char, 1i32 as libc::c_char,
0i32 as libc::c_char, 100i32 as libc::c_char,
10i32 as libc::c_char, 1i32 as libc::c_char);
//3 0 | 1 0 | 67 100 | 92 100
let mut prod: __m128i = _mm_maddubs_epi16(coeffs, arr);
prod = _mm_hadd_epi16(prod, prod);
let mut imm: __m128i =
_mm_set_epi8(-1i32 as libc::c_char, -1i32 as libc::c_char,
-1i32 as libc::c_char, -1i32 as libc::c_char,
-1i32 as libc::c_char, -1i32 as libc::c_char,
-1i32 as libc::c_char, -1i32 as libc::c_char,
-1i32 as libc::c_char, -1i32 as libc::c_char,
-1i32 as libc::c_char, -1i32 as libc::c_char,
6i32 as libc::c_char, 4i32 as libc::c_char,
2i32 as libc::c_char, 0i32 as libc::c_char);
prod = _mm_shuffle_epi8(prod, imm);
return _mm_extract_epi32(prod, 0) as UINT32;
}
from c2rust.
No problem! Also it seems like _mm_extract_epi32
is a builtin as of clang 7, not 8. The builtin still needs to be supported on our end, but, translating with 7 would work cleanly that way
from c2rust.
Closing since the repo is now synced. Feel free to reopen.
from c2rust.
@TheDan64 what do you mean by not synced? What's the canonical repo URL? Perhaps it's worth mentioning in Github project description / README?
from c2rust.
Related Issues (20)
- Build not matching clang version (Fedora 39, Clang 17.0.6) HOT 3
- cargo install c2rust failed: Error 2 HOT 2
- In the while loop body using a volatile variable, the generated code will lack a semicolon.
- why do you not support windows HOT 1
- Build fails with LLVM 18 and tip-of-tree HOT 1
- fail build on archlinux HOT 2
- Casting bool to pointer type results in invalid Rust
- Fatal error: 'stddef.h' file not found HOT 4
- ast_exporter can't convert a c code to ast HOT 2
- (Question) Do you plan to support C++ ? HOT 1
- Missing parentheses on reference applied to a cast
- Translate glsl
- analyze: proposal for simplified analysis and rewriting of allocations HOT 6
- Fails to compile on latest nightly
- Git build failure on Ubuntu 24.04 HOT 4
- analyze: tracking issue for simple_buffer HOT 2
- analyze: Lifetimes are incorrectly added to public extern C functions HOT 2
- Failed to build c2rust from source code in docker HOT 1
- rust 1.80.0 build issue HOT 1
- Installing Behind Proxy Fails Due to Examples
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from c2rust.