Plan 9 from Bell Labs’s /usr/web/sources/contrib/fernan/nhc98/src/runtime/Builtin/primIntegerFromInt64.c

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


#include "haskell2c.h"
#include "HsFFI.h"

#ifdef PROFILE
static SInfo nodeProfInfo = { "Builtin","Builtin.primIntegerFromInt64","Prelude.Integer"};
#endif

NodePtr primIntegerFromInt64 (HsInt64 i)
{
  NodePtr result;
  C_CHECK(SIZE_INT64);
  if(i==0) {
    result = C_ALLOC(SIZE_ENUM);
    *result = CONSTRW(0,0);
    INIT_PROFINFO(result,&nodeProfInfo)
  } else if ((HS_INT32_MIN<=i) && (i<=HS_INT32_MAX)) {
    result = C_ALLOC(SIZE_INT);
    if (i<0) {
      result[0] = CONSTRW(1,1);
      INIT_PROFINFO(result,&nodeProfInfo)
      result[1+EXTRA] = (int)(-i);
    } else {
      result[0] = CONSTRW(1,0);
      INIT_PROFINFO(result,&nodeProfInfo)
      result[1+EXTRA] = (int)i;
    }
  } else {
    result = C_ALLOC(SIZE_INT64);
    if (i<0) {
      result[0] = CONSTRW(2,1);
      INIT_PROFINFO(result,&nodeProfInfo)
      result[1+EXTRA] = (int)((-i)&0x00000000ffffffffLL);
      result[2+EXTRA] = (int)(((-i)&0xffffffff00000000LL)>>32);
    } else {
      result[0] = CONSTRW(2,0);
      INIT_PROFINFO(result,&nodeProfInfo)
      result[1+EXTRA] = (int)(i&0x00000000ffffffffLL);
      result[2+EXTRA] = (int)((i&0xffffffff00000000LL)>>32);
    }
  }
  return (result);
}



Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to webmaster@9p.io.