Source

pypy / pypy / jit / backend / llsupport / descr.py

Full commit
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
import py
from pypy.rpython.lltypesystem import lltype, rffi, llmemory
from pypy.rpython.lltypesystem.lloperation import llop
from pypy.jit.backend.llsupport import symbolic, support
from pypy.jit.metainterp.history import AbstractDescr, getkind
from pypy.jit.metainterp import history
from pypy.jit.codewriter import heaptracker, longlong

# The point of the class organization in this file is to make instances
# as compact as possible.  This is done by not storing the field size or
# the 'is_pointer_field' flag in the instance itself but in the class
# (in methods actually) using a few classes instead of just one.


class GcCache(object):
    def __init__(self, translate_support_code, rtyper=None):
        self.translate_support_code = translate_support_code
        self.rtyper = rtyper
        self._cache_size = {}
        self._cache_field = {}
        self._cache_array = {}
        self._cache_call = {}
        self._cache_interiorfield = {}

    def init_size_descr(self, STRUCT, sizedescr):
        assert isinstance(STRUCT, lltype.GcStruct)

    def init_array_descr(self, ARRAY, arraydescr):
        assert isinstance(ARRAY, lltype.GcArray)


if lltype.SignedLongLong is lltype.Signed:
    def is_longlong(TYPE):
        return False
else:
    assert rffi.sizeof(lltype.SignedLongLong) == rffi.sizeof(lltype.Float)
    def is_longlong(TYPE):
        return TYPE in (lltype.SignedLongLong, lltype.UnsignedLongLong)

# ____________________________________________________________
# SizeDescrs

class SizeDescr(AbstractDescr):
    size = 0      # help translation
    is_immutable = False

    tid = llop.combine_ushort(lltype.Signed, 0, 0)

    def __init__(self, size, count_fields_if_immut=-1):
        self.size = size
        self.count_fields_if_immut = count_fields_if_immut

    def count_fields_if_immutable(self):
        return self.count_fields_if_immut

    def repr_of_descr(self):
        return '<SizeDescr %s>' % self.size

class SizeDescrWithVTable(SizeDescr):
    def as_vtable_size_descr(self):
        return self

BaseSizeDescr = SizeDescr

def get_size_descr(gccache, STRUCT):
    cache = gccache._cache_size
    try:
        return cache[STRUCT]
    except KeyError:
        size = symbolic.get_size(STRUCT, gccache.translate_support_code)
        count_fields_if_immut = heaptracker.count_fields_if_immutable(STRUCT)
        if heaptracker.has_gcstruct_a_vtable(STRUCT):
            sizedescr = SizeDescrWithVTable(size, count_fields_if_immut)
        else:
            sizedescr = SizeDescr(size, count_fields_if_immut)
        gccache.init_size_descr(STRUCT, sizedescr)
        cache[STRUCT] = sizedescr
        return sizedescr

# ____________________________________________________________
# FieldDescrs

class BaseFieldDescr(AbstractDescr):
    offset = 0      # help translation
    name = ''
    _clsname = ''

    def __init__(self, name, offset):
        self.name = name
        self.offset = offset

    def sort_key(self):
        return self.offset

    def get_field_size(self, translate_support_code):
        raise NotImplementedError

    _is_pointer_field = False   # unless overridden by GcPtrFieldDescr
    _is_float_field = False     # unless overridden by FloatFieldDescr
    _is_field_signed = False    # unless overridden by XxxFieldDescr

    def is_pointer_field(self):
        return self._is_pointer_field

    def is_float_field(self):
        return self._is_float_field

    def is_field_signed(self):
        return self._is_field_signed

    def repr_of_descr(self):
        return '<%s %s %s>' % (self._clsname, self.name, self.offset)

class DynamicFieldDescr(BaseFieldDescr):
    def __init__(self, offset, fieldsize, is_pointer, is_float, is_signed):
        self.offset = offset
        self._fieldsize = fieldsize
        self._is_pointer_field = is_pointer
        self._is_float_field = is_float
        self._is_field_signed = is_signed

    def get_field_size(self, translate_support_code):
        return self._fieldsize

class NonGcPtrFieldDescr(BaseFieldDescr):
    _clsname = 'NonGcPtrFieldDescr'
    def get_field_size(self, translate_support_code):
        return symbolic.get_size_of_ptr(translate_support_code)

class GcPtrFieldDescr(NonGcPtrFieldDescr):
    _clsname = 'GcPtrFieldDescr'
    _is_pointer_field = True

def getFieldDescrClass(TYPE):
    return getDescrClass(TYPE, BaseFieldDescr, GcPtrFieldDescr,
                         NonGcPtrFieldDescr, 'Field', 'get_field_size',
                         '_is_float_field', '_is_field_signed')

def get_field_descr(gccache, STRUCT, fieldname):
    cache = gccache._cache_field
    try:
        return cache[STRUCT][fieldname]
    except KeyError:
        offset, _ = symbolic.get_field_token(STRUCT, fieldname,
                                             gccache.translate_support_code)
        FIELDTYPE = getattr(STRUCT, fieldname)
        name = '%s.%s' % (STRUCT._name, fieldname)
        fielddescr = getFieldDescrClass(FIELDTYPE)(name, offset)
        cachedict = cache.setdefault(STRUCT, {})
        cachedict[fieldname] = fielddescr
        return fielddescr

# ____________________________________________________________
# ArrayDescrs

_A = lltype.GcArray(lltype.Signed)     # a random gcarray
_AF = lltype.GcArray(lltype.Float)     # an array of C doubles


class BaseArrayDescr(AbstractDescr):
    _clsname = ''
    tid = llop.combine_ushort(lltype.Signed, 0, 0)

    def get_base_size(self, translate_support_code):
        basesize, _, _ = symbolic.get_array_token(_A, translate_support_code)
        return basesize

    def get_ofs_length(self, translate_support_code):
        _, _, ofslength = symbolic.get_array_token(_A, translate_support_code)
        return ofslength

    def get_item_size(self, translate_support_code):
        raise NotImplementedError

    _is_array_of_pointers = False      # unless overridden by GcPtrArrayDescr
    _is_array_of_floats   = False      # unless overridden by FloatArrayDescr
    _is_array_of_structs  = False      # unless overridden by StructArrayDescr
    _is_item_signed       = False      # unless overridden by XxxArrayDescr

    def is_array_of_pointers(self):
        return self._is_array_of_pointers

    def is_array_of_floats(self):
        return self._is_array_of_floats

    def is_array_of_structs(self):
        return self._is_array_of_structs

    def is_item_signed(self):
        return self._is_item_signed

    def repr_of_descr(self):
        return '<%s>' % self._clsname


class NonGcPtrArrayDescr(BaseArrayDescr):
    _clsname = 'NonGcPtrArrayDescr'
    def get_item_size(self, translate_support_code):
        return symbolic.get_size_of_ptr(translate_support_code)

class GcPtrArrayDescr(NonGcPtrArrayDescr):
    _clsname = 'GcPtrArrayDescr'
    _is_array_of_pointers = True

class FloatArrayDescr(BaseArrayDescr):
    _clsname = 'FloatArrayDescr'
    _is_array_of_floats = True
    def get_base_size(self, translate_support_code):
        basesize, _, _ = symbolic.get_array_token(_AF, translate_support_code)
        return basesize
    def get_item_size(self, translate_support_code):
        return symbolic.get_size(lltype.Float, translate_support_code)

class StructArrayDescr(BaseArrayDescr):
    _clsname = 'StructArrayDescr'
    _is_array_of_structs = True

class BaseArrayNoLengthDescr(BaseArrayDescr):
    def get_base_size(self, translate_support_code):
        return 0

    def get_ofs_length(self, translate_support_code):
        return -1

class DynamicArrayNoLengthDescr(BaseArrayNoLengthDescr):
    def __init__(self, itemsize):
        self.itemsize = itemsize

    def get_item_size(self, translate_support_code):
        return self.itemsize

class NonGcPtrArrayNoLengthDescr(BaseArrayNoLengthDescr):
    _clsname = 'NonGcPtrArrayNoLengthDescr'
    def get_item_size(self, translate_support_code):
        return symbolic.get_size_of_ptr(translate_support_code)

class GcPtrArrayNoLengthDescr(NonGcPtrArrayNoLengthDescr):
    _clsname = 'GcPtrArrayNoLengthDescr'
    _is_array_of_pointers = True

def getArrayDescrClass(ARRAY):
    if ARRAY.OF is lltype.Float:
        return FloatArrayDescr
    elif isinstance(ARRAY.OF, lltype.Struct):
        class Descr(StructArrayDescr):
            _clsname = '%sArrayDescr' % ARRAY.OF._name
            def get_item_size(self, translate_support_code):
                return symbolic.get_size(ARRAY.OF, translate_support_code)
        Descr.__name__ = Descr._clsname
        return Descr
    return getDescrClass(ARRAY.OF, BaseArrayDescr, GcPtrArrayDescr,
                         NonGcPtrArrayDescr, 'Array', 'get_item_size',
                         '_is_array_of_floats', '_is_item_signed')

def getArrayNoLengthDescrClass(ARRAY):
    return getDescrClass(ARRAY.OF, BaseArrayNoLengthDescr, GcPtrArrayNoLengthDescr,
                         NonGcPtrArrayNoLengthDescr, 'ArrayNoLength', 'get_item_size',
                         '_is_array_of_floats', '_is_item_signed')

def get_array_descr(gccache, ARRAY):
    cache = gccache._cache_array
    try:
        return cache[ARRAY]
    except KeyError:
        # we only support Arrays that are either GcArrays, or raw no-length
        # non-gc Arrays.
        if ARRAY._hints.get('nolength', False):
            assert not isinstance(ARRAY, lltype.GcArray)
            arraydescr = getArrayNoLengthDescrClass(ARRAY)()
        else:
            assert isinstance(ARRAY, lltype.GcArray)
            arraydescr = getArrayDescrClass(ARRAY)()
        # verify basic assumption that all arrays' basesize and ofslength
        # are equal
        basesize, itemsize, ofslength = symbolic.get_array_token(ARRAY, False)
        assert basesize == arraydescr.get_base_size(False)
        assert itemsize == arraydescr.get_item_size(False)
        if not ARRAY._hints.get('nolength', False):
            assert ofslength == arraydescr.get_ofs_length(False)
        if isinstance(ARRAY, lltype.GcArray):
            gccache.init_array_descr(ARRAY, arraydescr)
        cache[ARRAY] = arraydescr
        return arraydescr

# ____________________________________________________________
# InteriorFieldDescr

class InteriorFieldDescr(AbstractDescr):
    arraydescr = BaseArrayDescr()     # workaround for the annotator
    fielddescr = BaseFieldDescr('', 0)

    def __init__(self, arraydescr, fielddescr):
        self.arraydescr = arraydescr
        self.fielddescr = fielddescr

    def is_pointer_field(self):
        return self.fielddescr.is_pointer_field()

    def is_float_field(self):
        return self.fielddescr.is_float_field()

    def sort_key(self):
        return self.fielddescr.sort_key()

    def repr_of_descr(self):
        return '<InteriorFieldDescr %s>' % self.fielddescr.repr_of_descr()

def get_interiorfield_descr(gc_ll_descr, ARRAY, FIELDTP, name):
    cache = gc_ll_descr._cache_interiorfield
    try:
        return cache[(ARRAY, FIELDTP, name)]
    except KeyError:
        arraydescr = get_array_descr(gc_ll_descr, ARRAY)
        fielddescr = get_field_descr(gc_ll_descr, FIELDTP, name)
        descr = InteriorFieldDescr(arraydescr, fielddescr)
        cache[(ARRAY, FIELDTP, name)] = descr
        return descr

# ____________________________________________________________
# CallDescrs

class BaseCallDescr(AbstractDescr):
    _clsname = ''
    loop_token = None
    arg_classes = ''     # <-- annotation hack
    ffi_flags = 1

    def __init__(self, arg_classes, extrainfo=None, ffi_flags=1):
        self.arg_classes = arg_classes    # string of "r" and "i" (ref/int)
        self.extrainfo = extrainfo
        self.ffi_flags = ffi_flags
        # NB. the default ffi_flags is 1, meaning FUNCFLAG_CDECL, which
        # makes sense on Windows as it's the one for all the C functions
        # we are compiling together with the JIT.  On non-Windows platforms
        # it is just ignored anyway.

    def __repr__(self):
        res = '%s(%s)' % (self.__class__.__name__, self.arg_classes)
        extraeffect = getattr(self.extrainfo, 'extraeffect', None)
        if extraeffect is not None:
            res += ' EF=%r' % extraeffect
        oopspecindex = getattr(self.extrainfo, 'oopspecindex', 0)
        if oopspecindex:
            from pypy.jit.codewriter.effectinfo import EffectInfo
            for key, value in EffectInfo.__dict__.items():
                if key.startswith('OS_') and value == oopspecindex:
                    break
            else:
                key = 'oopspecindex=%r' % oopspecindex
            res += ' ' + key
        return '<%s>' % res

    def get_extra_info(self):
        return self.extrainfo

    def get_ffi_flags(self):
        return self.ffi_flags

    def get_call_conv(self):
        from pypy.rlib.clibffi import get_call_conv
        return get_call_conv(self.ffi_flags, True)

    def get_arg_types(self):
        return self.arg_classes

    def get_return_type(self):
        return self._return_type

    def get_result_size(self, translate_support_code):
        raise NotImplementedError

    def is_result_signed(self):
        return False    # unless overridden

    def create_call_stub(self, rtyper, RESULT):
        from pypy.rlib.clibffi import FFI_DEFAULT_ABI
        assert self.get_call_conv() == FFI_DEFAULT_ABI, (
            "%r: create_call_stub() with a non-default call ABI" % (self,))

        def process(c):
            if c == 'L':
                assert longlong.supports_longlong
                c = 'f'
            elif c == 'f' and longlong.supports_longlong:
                return 'longlong.getrealfloat(%s)' % (process('L'),)
            elif c == 'S':
                return 'longlong.int2singlefloat(%s)' % (process('i'),)
            arg = 'args_%s[%d]' % (c, seen[c])
            seen[c] += 1
            return arg

        def TYPE(arg):
            if arg == 'i':
                return lltype.Signed
            elif arg == 'f':
                return lltype.Float
            elif arg == 'r':
                return llmemory.GCREF
            elif arg == 'v':
                return lltype.Void
            elif arg == 'L':
                return lltype.SignedLongLong
            elif arg == 'S':
                return lltype.SingleFloat
            else:
                raise AssertionError(arg)

        seen = {'i': 0, 'r': 0, 'f': 0}
        args = ", ".join([process(c) for c in self.arg_classes])

        if self.get_return_type() == history.INT:
            result = 'rffi.cast(lltype.Signed, res)'
        elif self.get_return_type() == history.REF:
            result = 'lltype.cast_opaque_ptr(llmemory.GCREF, res)'
        elif self.get_return_type() == history.FLOAT:
            result = 'longlong.getfloatstorage(res)'
        elif self.get_return_type() == 'L':
            result = 'rffi.cast(lltype.SignedLongLong, res)'
        elif self.get_return_type() == history.VOID:
            result = 'None'
        elif self.get_return_type() == 'S':
            result = 'longlong.singlefloat2int(res)'
        else:
            assert 0
        source = py.code.Source("""
        def call_stub(func, args_i, args_r, args_f):
            fnptr = rffi.cast(lltype.Ptr(FUNC), func)
            res = support.maybe_on_top_of_llinterp(rtyper, fnptr)(%(args)s)
            return %(result)s
        """ % locals())
        ARGS = [TYPE(arg) for arg in self.arg_classes]
        FUNC = lltype.FuncType(ARGS, RESULT)
        d = globals().copy()
        d.update(locals())
        exec source.compile() in d
        self.call_stub = d['call_stub']

    def verify_types(self, args_i, args_r, args_f, return_type):
        assert self._return_type in return_type
        assert (self.arg_classes.count('i') +
                self.arg_classes.count('S')) == len(args_i or ())
        assert self.arg_classes.count('r') == len(args_r or ())
        assert (self.arg_classes.count('f') +
                self.arg_classes.count('L')) == len(args_f or ())

    def repr_of_descr(self):
        return '<%s>' % self._clsname


class BaseIntCallDescr(BaseCallDescr):
    # Base class of the various subclasses of descrs corresponding to
    # calls having a return kind of 'int' (including non-gc pointers).
    # The inheritance hierarchy is a bit different than with other Descr
    # classes because of the 'call_stub' attribute, which is of type
    #
    #     lambda func, args_i, args_r, args_f --> int/ref/float/void
    #
    # The purpose of BaseIntCallDescr is to be the parent of all classes
    # in which 'call_stub' has a return kind of 'int'.
    _return_type = history.INT
    call_stub = staticmethod(lambda func, args_i, args_r, args_f: 0)

    _is_result_signed = False      # can be overridden in XxxCallDescr
    def is_result_signed(self):
        return self._is_result_signed

class DynamicIntCallDescr(BaseIntCallDescr):
    """
    calldescr that works for every integer type, by explicitly passing it the
    size of the result. Used only by get_call_descr_dynamic
    """
    _clsname = 'DynamicIntCallDescr'

    def __init__(self, arg_classes, result_size, result_sign, extrainfo, ffi_flags):
        BaseIntCallDescr.__init__(self, arg_classes, extrainfo, ffi_flags)
        assert isinstance(result_sign, bool)
        self._result_size = chr(result_size)
        self._result_sign = result_sign

    def get_result_size(self, translate_support_code):
        return ord(self._result_size)

    def is_result_signed(self):
        return self._result_sign


class NonGcPtrCallDescr(BaseIntCallDescr):
    _clsname = 'NonGcPtrCallDescr'
    def get_result_size(self, translate_support_code):
        return symbolic.get_size_of_ptr(translate_support_code)

class GcPtrCallDescr(BaseCallDescr):
    _clsname = 'GcPtrCallDescr'
    _return_type = history.REF
    call_stub = staticmethod(lambda func, args_i, args_r, args_f:
                             lltype.nullptr(llmemory.GCREF.TO))
    def get_result_size(self, translate_support_code):
        return symbolic.get_size_of_ptr(translate_support_code)

class FloatCallDescr(BaseCallDescr):
    _clsname = 'FloatCallDescr'
    _return_type = history.FLOAT
    call_stub = staticmethod(lambda func,args_i,args_r,args_f: longlong.ZEROF)
    def get_result_size(self, translate_support_code):
        return symbolic.get_size(lltype.Float, translate_support_code)

class LongLongCallDescr(FloatCallDescr):
    _clsname = 'LongLongCallDescr'
    _return_type = 'L'

class VoidCallDescr(BaseCallDescr):
    _clsname = 'VoidCallDescr'
    _return_type = history.VOID
    call_stub = staticmethod(lambda func, args_i, args_r, args_f: None)
    def get_result_size(self, translate_support_code):
        return 0

_SingleFloatCallDescr = None   # built lazily

def getCallDescrClass(RESULT):
    if RESULT is lltype.Void:
        return VoidCallDescr
    if RESULT is lltype.Float:
        return FloatCallDescr
    if RESULT is lltype.SingleFloat:
        global _SingleFloatCallDescr
        if _SingleFloatCallDescr is None:
            assert rffi.sizeof(rffi.UINT) == rffi.sizeof(RESULT)
            class SingleFloatCallDescr(getCallDescrClass(rffi.UINT)):
                _clsname = 'SingleFloatCallDescr'
                _return_type = 'S'
            _SingleFloatCallDescr = SingleFloatCallDescr
        return _SingleFloatCallDescr
    if is_longlong(RESULT):
        return LongLongCallDescr
    return getDescrClass(RESULT, BaseIntCallDescr, GcPtrCallDescr,
                         NonGcPtrCallDescr, 'Call', 'get_result_size',
                         Ellipsis,  # <= floatattrname should not be used here
                         '_is_result_signed')
getCallDescrClass._annspecialcase_ = 'specialize:memo'

def get_call_descr(gccache, ARGS, RESULT, extrainfo=None):
    arg_classes = []
    for ARG in ARGS:
        kind = getkind(ARG)
        if   kind == 'int':
            if ARG is lltype.SingleFloat:
                arg_classes.append('S')
            else:
                arg_classes.append('i')
        elif kind == 'ref': arg_classes.append('r')
        elif kind == 'float':
            if is_longlong(ARG):
                arg_classes.append('L')
            else:
                arg_classes.append('f')
        else:
            raise NotImplementedError('ARG = %r' % (ARG,))
    arg_classes = ''.join(arg_classes)
    cls = getCallDescrClass(RESULT)
    key = (cls, arg_classes, extrainfo)
    cache = gccache._cache_call
    try:
        return cache[key]
    except KeyError:
        calldescr = cls(arg_classes, extrainfo)
        calldescr.create_call_stub(gccache.rtyper, RESULT)
        cache[key] = calldescr
        return calldescr


# ____________________________________________________________

def getDescrClass(TYPE, BaseDescr, GcPtrDescr, NonGcPtrDescr,
                  nameprefix, methodname, floatattrname, signedattrname,
                  _cache={}):
    if isinstance(TYPE, lltype.Ptr):
        if TYPE.TO._gckind == 'gc':
            return GcPtrDescr
        else:
            return NonGcPtrDescr
    if TYPE is lltype.SingleFloat:
        assert rffi.sizeof(rffi.UINT) == rffi.sizeof(TYPE)
        TYPE = rffi.UINT
    try:
        return _cache[nameprefix, TYPE]
    except KeyError:
        #
        class Descr(BaseDescr):
            _clsname = '%s%sDescr' % (TYPE._name, nameprefix)
        Descr.__name__ = Descr._clsname
        #
        def method(self, translate_support_code):
            return symbolic.get_size(TYPE, translate_support_code)
        setattr(Descr, methodname, method)
        #
        if TYPE is lltype.Float or is_longlong(TYPE):
            setattr(Descr, floatattrname, True)
        elif (TYPE is not lltype.Bool and isinstance(TYPE, lltype.Number) and
              rffi.cast(TYPE, -1) == -1):
            setattr(Descr, signedattrname, True)
        #
        _cache[nameprefix, TYPE] = Descr
        return Descr