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

Is there a way to specify an __int128 type? #53

Closed
AndreaRibuoli opened this issue Nov 27, 2020 · 13 comments
Closed

Is there a way to specify an __int128 type? #53

AndreaRibuoli opened this issue Nov 27, 2020 · 13 comments

Comments

@AndreaRibuoli
Copy link

Fiddle::DLError: unknown type: __int128
@kou
Copy link
Member

kou commented Nov 27, 2020

No.

Could you show your use case?

@AndreaRibuoli
Copy link
Author

I would like to develop an integration for a particular platform called IBM i (once named AS/400).
Each job/process has a dual mode execution. One of the two modes is called PASE and it offers the ability to run the Ruby interpreter. I managed to build Ruby 3.0.0 preview1 and in order to offer Ruby code access to the native execution mode I am leveraging a set of APIs that IBM distributes inside an extended libc.a shared library specific for this environment. By means of these calls I am able to load native shared libraries (that IBM i calls service programs), register specific native APIs and finally perform calls.
I am trying to simplify this process (otherwise quite clumsy) creating a layer to abstract the call mechanism details are here.

To dynamically handle native pointers (that are 16 bytes long) I need to guarantee these are 16-byte aligned.

I am currently experimenting with:

require 'fiddle/import'
module ILE
      extend Fiddle::Importer
  ILEpointer = struct [
    'signed long long ptr1',
    'signed long long ptr2',
  ]
end
tgt = ILE::ILEpointer.malloc

But being able to use __int128 would be safer.

I found out that in the past there had been instructions to introduce __int128 when building Ruby (note)

@kou
Copy link
Member

kou commented Nov 27, 2020

Thanks.
Could you show typedef of ILEpointer?

@AndreaRibuoli
Copy link
Author

This is how it is defined inside include file /usr/include/as400_types.h

/* (C)Copyright IBM Corp.  1997, 2009                                */

. . .

typedef union _ILEpointer {                                                
#if !(defined(_AIX) || defined(KERNEL))                                    
#pragma pack(1,16,_ILEpointer) /* Force sCC quadword alignment */          
#endif                                                                     
/* CAUTION: Some compilers only provide 64-bits for long double */         
    long double  align; /* Force xlc quadword alignment                    
       (with -qldbl128 -qalign=natural) */                                 
#ifndef _AIX                                                               
    void  *openPtr; /* MI open pointer (tagged quadword) */                
#endif                                                                     
    struct {                                                               
 char  filler[16-sizeof(uint64)];                                          
 address64_t addr; /* (PASE) memory address */                             
    } s;                                                                   
} ILEpointer;                                                              

@kou
Copy link
Member

kou commented Nov 27, 2020

Thanks.
ILDponiter doesn't use __int128.

Your ILE::ILEpointer definition is safe but you may want to ensure that the size of ILE::ILEpointer is 16 bytes:

if ILEpointer.size != 16
  raise "ILEpointer.size must be 16: #{ILEpointer.size}"
end

@AndreaRibuoli
Copy link
Author

AndreaRibuoli commented Nov 27, 2020

Thanks for suggestion.
Actually, what I need to guarantee is that ILE::ILEpointer.malloc returns a 16-byte aligned pointer.

@kou
Copy link
Member

kou commented Nov 27, 2020

If we want an aligned pointer, we need to use posix_memalign() or something.
We can add support it only in Fiddle but it's not integrated with Ruby's GC. It's better that Ruby provides ruby_xmemalign() or something. Could you suggest it to Ruby itself https://bugs.ruby-lang.org/ ?

@AndreaRibuoli
Copy link
Author

AndreaRibuoli commented Nov 27, 2020

I was actually reading about it!!
So I cannot be safe to receive back a 16-byte aligned pointer even in case of support for __int128, right?
I will try to patch my environment and then propose a change if it sounds reasonable.
Many thanks for caring!

@AndreaRibuoli
Copy link
Author

@chrisseaton
Copy link
Contributor

Objects are not allocated directly with malloc, but Fiddle structs are. The Ruby object for a Fiddle struct contains a pointer to the actual struct.

@AndreaRibuoli
Copy link
Author

AndreaRibuoli commented Nov 28, 2020

Interesting... Many thanks!

Rebuilding Ruby with a modified gc.c:

TRY_WITH_GC(size, mem = aligned_alloc(16,size));

@kou
Copy link
Member

kou commented Nov 28, 2020

I close this because we don't need to add __int128 support. It doesn't relate to 16 bits alignment.

If you still want aligned memory allocation support, please suggest it to Ruby itself https://bugs.ruby-lang.org/ .
Please open a new issue for it after a discussion on bugs.ruby-lang.org is done.

@kou kou closed this as completed Nov 28, 2020
@AndreaRibuoli
Copy link
Author

Opened as https://bugs.ruby-lang.org/issues/17356

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

No branches or pull requests

3 participants