Skip to content
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

misc intrinsics, builtins #537

Open
timotheecour opened this issue Jan 19, 2021 · 2 comments
Open

misc intrinsics, builtins #537

timotheecour opened this issue Jan 19, 2021 · 2 comments

Comments

@timotheecour
Copy link
Owner

timotheecour commented Jan 19, 2021

here's how to find correct declaration for intrinsics/builtins

https://github.com/llvm-mirror/clang/blob/master/include/clang/Basic/Builtins.def

BUILTIN(__builtin_rotateright64, "UWiUWiUWi", "nc")

see definitions on top for meaning of UWiUWiUWi

here's how to check for errors in type declarations: -Wconversion

clang -o /tmp/z01 -Wconversion $timn_D/tests/nim/all/t11720.c
/Users/timothee/git_clone//nim//timn//tests/nim/all/t11720.c:14:57: warning: implicit conversion changes signedness: 'unsigned long long' to
'long long' [-Wsign-conversion]
unsigned long long x3 = __builtin_rotateright64(x1, x2);


```c
#include <stdio.h>
int main (int argc, char *argv[]) {
  unsigned long long x1 = 12;
  {
    long long x2 = 3;
    unsigned long long x3 = __builtin_rotateright64(x1, x2);
  }
  {
    unsigned long long x2 = 3;
    unsigned long long x3 = __builtin_rotateright64(x1, x2);
  }
  return 0;
}

intrinsic guide

https://software.intel.com/sites/landingpage/IntrinsicsGuide/

links

https://gitlab.itwm.fraunhofer.de/hellerm/spu-llvm-src/-/blob/af074a2a3d8912f22b1e14a1464226af8ee9bcf4/clang/docs/LanguageExtensions.rst
Notifications TITLE: add a builtin function for every llvm C library intrinsic and bit manipulation instrinsics · Issue #767 · ziglang/zig
Refactoring bitops.rotateLeftBits() and bitops.rotateRightBits(); adding builtins and intrinsics. by rockcavera · Pull Request #16622 · nim-lang/Nim
https://llvm.org/docs/LangRef.html#standard-c-c-library-intrinsics
C++ Using Intrinsics in a Cross-platform Manner - Software Engineering Stack Exchange
TITLE: c - Testing for builtins/intrinsics - Stack Overflow
Understanding GCC Builtins to Develop Better Tools

@timotheecour
Copy link
Owner Author

timotheecour commented Jan 19, 2021

explanation for type mismatch:

answer: see nim-lang#16622 (comment)

details:

refs nim-lang#16622

conflicting types, eg:

$git_clone_D/llvm-project/clang/test/CodeGen/builtin-rotate.c

unsigned long long rotl64(unsigned long long x, long long y) {
// CHECK-LABEL: rotl64
// CHECK: [[F:%.*]] = call i64 @llvm.fshl.i64(i64 [[X:%.*]], i64 [[X]], i64 [[Y:%.*]])
// CHECK-NEXT: ret i64 [[F]]

  return __builtin_rotateleft64(x, y);
}

...
long long rotr64(long long x, unsigned long long y) {
// CHECK-LABEL: rotr64
// CHECK: [[F:%.*]] = call i64 @llvm.fshr.i64(i64 [[X:%.*]], i64 [[X]], i64 [[Y:%.*]])
// CHECK-NEXT: ret i64 [[F]]

  return __builtin_rotateright64(x, y);
}


/Library/Developer/CommandLineTools/usr/lib/clang/11.0.3/include/ia32intrin.h

#ifdef __x86_64__
static __inline__ unsigned long long __attribute__((__always_inline__, __nodebug__))
__rolq(unsigned long long __X, int __C) {
  return __builtin_rotateleft64(__X, __C);
}

static __inline__ unsigned long long __attribute__((__always_inline__, __nodebug__))
__rorq(unsigned long long __X, int __C) {
  return __builtin_rotateright64(__X, __C);
}
#endif /* __x86_64__ */

  • running locally nim doc lib/pure/bitops.nim on osx gives:
runnableExamples/@mbitops_examples40.nim.c:52:31: error: conflicting types for '__builtin_rotateright64'
N_NIMCALL(unsigned long long, __builtin_rotateright64)(unsigned long long value, unsigned long long shift);
                              ^
/Users/timothee/.cache/nim/bitops_d/runnableExamples/@mbitops_examples40.nim.c:52:31: note: '__builtin_rotateright64' is a builtin with type
      'unsigned long long (unsigned long long, long long)'

furthermore, I got this after changing your code:

/Users/timothee/.cache/nim/bitops_d/runnableExamples/@mbitops_examples36.nim.c:52:31: note: '__builtin_rotateleft64' is a builtin with type
      'unsigned long long (unsigned long long, unsigned long long)'
so __builtin_rotateleft64 uses 'unsigned long long (unsigned long long, unsigned long long)'
   __builtin_rotateright64' uses 'unsigned long long (unsigned long long, long long)'
  • how come isn't this detected by nim's CI?

What C compiler is used by the OSX CI? If it's not Clang than this is a matter of concern

https://pipelines.actions.githubusercontent.com/ZRinn1OrR0LWxU3iWy1StaQcZRN2kXW9lHWwDJ3esfasrmfdRn/_apis/pipelines/1/runs/12847/signedlogcontent/5?urlExpires=2021-01-19T18%3A24%3A15.0758912Z&urlSigningMethod=HMACV1&urlSignature=3MnjmPZgT%2BI2gb2f5pCPNOzi6%2FWw99MIvEI1%2F6JEkbU%3D

bin/nim doc --errormax:3 --hint:Conf:off --hint:Path:off --hint:Processing:off --hint:XDeclaredButNotUsed:off --warning:UnusedImport:off -d:boot --putenv:nimversion=1.5.1 --git.commit:devel --git.url:https://github.com/nim-lang/Nim --outdir:web/upload/1.5.1 --index:on lib/pure/httpcore.nim

https://dev.azure.com/nim-lang/255dfe86-e590-40bb-a8a2-3c0295ebdeb1/_apis/build/builds/12253/logs/93
2021-01-19T17:14:43.8960280Z runCI:
2021-01-19T17:14:43.8964510Z hostOS: macosx, hostCPU: amd64, int: 8, float: 8, cpuEndian: littleEndian, cwd: /Users/runner/work/1/s

https://github.com/actions/virtual-environments/blob/macOS-10.15/20201212.1/images/macos/macos-10.15-Readme.md

@timotheecour timotheecour changed the title intrinsics misc intrinsics Jan 19, 2021
@timotheecour timotheecour changed the title misc intrinsics misc intrinsics, builtins Jan 19, 2021
@timotheecour
Copy link
Owner Author

ifunc resolver

https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-ifunc-function-attribute

ifunc ("resolver")

allows the resolution of the symbol value to be determined dynamically at load time, and an optimized version of the routine to be selected for the particular processor or other system characteristics determined then

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant