Diff for /gforth/prim between versions 1.194 and 1.202

version 1.194, 2006/05/25 22:10:16 version 1.202, 2006/10/30 15:50:52
Line 809  n = n1*n2; Line 809  n = n1*n2;

/       ( n1 n2 -- n )          core    slash  /       ( n1 n2 -- n )          core    slash
n = n1/n2;  n = n1/n2;
if(FLOORED_DIV && ((n1^n2) < 0) && (n1%n2 != 0)) n--;  if (CHECK_DIVISION_SW && n2 == 0)
throw(BALL_DIVZERO);
if (CHECK_DIVISION_SW && n2 == -1 && n1 == CELL_MIN)
throw(BALL_RESULTRANGE);
if (FLOORED_DIV && ((n1^n2) < 0) && (n1%n2 != 0))
n--;
:  :
/mod nip ;   /mod nip ;

mod     ( n1 n2 -- n )          core  mod     ( n1 n2 -- n )          core
n = n1%n2;  n = n1%n2;
if (CHECK_DIVISION_SW && n2 == 0)
throw(BALL_DIVZERO);
if (CHECK_DIVISION_SW && n2 == -1 && n1 == CELL_MIN)
throw(BALL_RESULTRANGE);
if(FLOORED_DIV && ((n1^n2) < 0) && n!=0) n += n2;  if(FLOORED_DIV && ((n1^n2) < 0) && n!=0) n += n2;
:  :
/mod drop ;   /mod drop ;
Line 822  if(FLOORED_DIV && ((n1^n2) < 0) && n!=0) Line 831  if(FLOORED_DIV && ((n1^n2) < 0) && n!=0)
/mod    ( n1 n2 -- n3 n4 )              core            slash_mod  /mod    ( n1 n2 -- n3 n4 )              core            slash_mod
n4 = n1/n2;  n4 = n1/n2;
n3 = n1%n2; /* !! is this correct? look into C standard! */  n3 = n1%n2; /* !! is this correct? look into C standard! */
if (CHECK_DIVISION_SW && n2 == 0)
throw(BALL_DIVZERO);
if (CHECK_DIVISION_SW && n2 == -1 && n1 == CELL_MIN)
throw(BALL_RESULTRANGE);
if (FLOORED_DIV && ((n1^n2) < 0) && n3!=0) {  if (FLOORED_DIV && ((n1^n2) < 0) && n3!=0) {
n4--;    n4--;
n3+=n2;    n3+=n2;
Line 836  DCell d = mmul(n1,n2); Line 849  DCell d = mmul(n1,n2);
#else  #else
DCell d = (DCell)n1 * (DCell)n2;  DCell d = (DCell)n1 * (DCell)n2;
#endif  #endif
#ifdef BUGGY_LL_DIV  #ifdef ASM_SM_SLASH_REM
DCell r = fmdiv(d,n3);  ASM_SM_SLASH_REM(DLO(d), DHI(d), n3, n4, n5);
n4=DHI(r);  if (((DHI(d)^n3)<0) && n4!=0) {
n5=DLO(r);    if (CHECK_DIVISION && n5 == CELL_MIN)
#else      throw(BALL_RESULTRANGE);
/* assumes that the processor uses either floored or symmetric division */
n5 = d/n3;
n4 = d%n3;
if (FLOORED_DIV && ((DHI(d)^n3)<0) && n4!=0) {
n5--;    n5--;
n4+=n3;    n4+=n3;
}  }
#else
DCell r = fmdiv(d,n3);
n4=DHI(r);
n5=DLO(r);
#endif  #endif
:  :
>r m* r> fm/mod ;   >r m* r> fm/mod ;
Line 859  DCell d = mmul(n1,n2); Line 872  DCell d = mmul(n1,n2);
#else  #else
DCell d = (DCell)n1 * (DCell)n2;  DCell d = (DCell)n1 * (DCell)n2;
#endif  #endif
#ifdef BUGGY_LL_DIV  #ifdef ASM_SM_SLASH_REM
Cell remainder;
ASM_SM_SLASH_REM(DLO(d), DHI(d), n3, remainder, n4);
if (((DHI(d)^n3)<0) && remainder!=0) {
if (CHECK_DIVISION && n4 == CELL_MIN)
throw(BALL_RESULTRANGE);
n4--;
}
#else
DCell r = fmdiv(d,n3);  DCell r = fmdiv(d,n3);
n4=DLO(r);  n4=DLO(r);
#else
/* assumes that the processor uses either floored or symmetric division */
n4 = d/n3;
if (FLOORED_DIV && ((DHI(d)^n3)<0) && (d%n3)!=0) n4--;
#endif  #endif
:  :
*/mod nip ;   */mod nip ;
Line 889  n2 = n1>>1; Line 906  n2 = n1>>1;

fm/mod  ( d1 n1 -- n2 n3 )              core            f_m_slash_mod  fm/mod  ( d1 n1 -- n2 n3 )              core            f_m_slash_mod
""Floored division: @i{d1} = @i{n3}*@i{n1}+@i{n2}, @i{n1}>@i{n2}>=0 or 0>=@i{n2}>@i{n1}.""  ""Floored division: @i{d1} = @i{n3}*@i{n1}+@i{n2}, @i{n1}>@i{n2}>=0 or 0>=@i{n2}>@i{n1}.""
#ifdef BUGGY_LL_DIV
#ifdef ASM_SM_SLASH_REM  #ifdef ASM_SM_SLASH_REM
#ifdef BUGGY_LL_DIV
ASM_SM_SLASH_REM(d1.lo, d1.hi, n1, n2, n3);  ASM_SM_SLASH_REM(d1.lo, d1.hi, n1, n2, n3);
if (((DHI(d1)^n1)<0) && n2!=0) {  if (((DHI(d1)^n1)<0) && n2!=0) {
if (CHECK_DIVISION && n3 == CELL_MIN)
throw(BALL_RESULTRANGE);
n3--;    n3--;
n2+=n1;    n2+=n1;
}  }
#else /* !defined(ASM_SM_SLASH_REM) */
DCell r = fmdiv(d1,n1);
n2=DHI(r);
n3=DLO(r);
#endif /* !defined(ASM_SM_SLASH_REM) */
#else  #else
#ifdef ASM_SM_SLASH_REM4
ASM_SM_SLASH_REM4(d1, n1, n2, n3);  ASM_SM_SLASH_REM4(d1, n1, n2, n3);
if (((DHI(d1)^n1)<0) && n2!=0) {  if (((DHI(d1)^n1)<0) && n2!=0) {
if (CHECK_DIVISION && n3 == CELL_MIN)
throw(BALL_RESULTRANGE);
n3--;    n3--;
n2+=n1;    n2+=n1;
}  }
#else /* !defined(ASM_SM_SLASH_REM4) */
/* assumes that the processor uses either floored or symmetric division */
n3 = d1/n1;
n2 = d1%n1;
/* note that this 1%-3>0 is optimized by the compiler */
if (1%-3>0 && ((DHI(d1)^n1)<0) && n2!=0) {
n3--;
n2+=n1;
}
#endif /* !defined(ASM_SM_SLASH_REM4) */
#endif  #endif
#else /* !defined(ASM_SM_SLASH_REM) */
DCell r = fmdiv(d1,n1);
n2=DHI(r);
n3=DLO(r);
:  :
dup >r dup 0< IF  negate >r dnegate r>  THEN   dup >r dup 0< IF  negate >r dnegate r>  THEN
over       0< IF  tuck + swap  THEN   over       0< IF  tuck + swap  THEN
Line 940  n3=DLO(r); Line 950  n3=DLO(r);
ASM_SM_SLASH_REM4(d1, n1, n2, n3);  ASM_SM_SLASH_REM4(d1, n1, n2, n3);
#else /* !defined(ASM_SM_SLASH_REM4) */  #else /* !defined(ASM_SM_SLASH_REM4) */
/* assumes that the processor uses either floored or symmetric division */  /* assumes that the processor uses either floored or symmetric division */
n3 = d1/n1;  DCell d3 = d1/n1;
n2 = d1%n1;  n2 = d1%n1;
if (CHECK_DIVISION_SW && n1 == 0)
throw(BALL_DIVZERO);
/* note that this 1%-3<0 is optimized by the compiler */  /* note that this 1%-3<0 is optimized by the compiler */
if (1%-3<0 && ((DHI(d1)^n1)<0) && n2!=0) {  if (1%-3<0 && ((DHI(d1)^n1)<0) && n2!=0) {
n3++;    d3++;
n2-=n1;    n2-=n1;
}  }
n3 = d3;
if (CHECK_DIVISION && d3 != n3)
throw(BALL_RESULTRANGE);
#endif /* !defined(ASM_SM_SLASH_REM4) */  #endif /* !defined(ASM_SM_SLASH_REM4) */
#endif  #endif
:  :
Line 996  u3=DLO(r); Line 1011  u3=DLO(r);
#ifdef ASM_UM_SLASH_MOD4  #ifdef ASM_UM_SLASH_MOD4
ASM_UM_SLASH_MOD4(ud, u1, u2, u3);  ASM_UM_SLASH_MOD4(ud, u1, u2, u3);
#else /* !defined(ASM_UM_SLASH_MOD4) */  #else /* !defined(ASM_UM_SLASH_MOD4) */
u3 = ud/u1;  UDCell ud3 = ud/u1;
u2 = ud%u1;  u2 = ud%u1;
if (CHECK_DIVISION_SW && u1 == 0)
throw(BALL_DIVZERO);
u3 = ud3;
if (CHECK_DIVISION && ud3 != u3)
throw(BALL_RESULTRANGE);
#endif /* !defined(ASM_UM_SLASH_MOD4) */  #endif /* !defined(ASM_UM_SLASH_MOD4) */
#endif  #endif
:  :
Line 2698  w = ffi_prep_closure((ffi_closure *)a_cl Line 2718  w = ffi_prep_closure((ffi_closure *)a_cl

ffi-2@ ( a_addr -- d )  gforth ffi_2fetch  ffi-2@ ( a_addr -- d )  gforth ffi_2fetch
#ifdef BUGGY_LONG_LONG  #ifdef BUGGY_LONG_LONG
DHI_IS(d, 0);  DHI_IS(d, 0);
#else  #else
Line 2719  w = *(long *)(*gforth_clist++); Line 2739  w = *(long *)(*gforth_clist++);

ffi-arg-longlong ( -- d )       gforth ffi_arg_longlong  ffi-arg-longlong ( -- d )       gforth ffi_arg_longlong
#ifdef BUGGY_LONG_LONG  #ifdef BUGGY_LONG_LONG
DLO_IS(d, (Cell*)(*gforth_clist++));  DLO_IS(d, *(Cell*)(*gforth_clist++));
DHI_IS(d, -((Cell*)(*gforth_clist++)<0));  DHI_IS(d, -(*(Cell*)(*gforth_clist++)<0));
#else  #else
d = *(DCell*)(*gforth_clist++);  d = *(DCell*)(*gforth_clist++);
#endif  #endif

ffi-arg-dlong ( -- d )  gforth ffi_arg_dlong  ffi-arg-dlong ( -- d )  gforth ffi_arg_dlong
#ifdef BUGGY_LONG_LONG  #ifdef BUGGY_LONG_LONG
DLO_IS(d, (Cell*)(*gforth_clist++));  DLO_IS(d, *(Cell*)(*gforth_clist++));
DHI_IS(d, -((Cell*)(*gforth_clist++)<0));  DHI_IS(d, -(*(Cell*)(*gforth_clist++)<0));
#else  #else
d = *(Cell*)(*gforth_clist++);  d = *(Cell*)(*gforth_clist++);
#endif  #endif
Line 2766  ffi-ret-dlong ( d -- ) gforth ffi_ret_dl Line 2786  ffi-ret-dlong ( d -- ) gforth ffi_ret_dl
return 0;  return 0;

ffi-ret-long ( n -- )   gforth ffi_ret_long  ffi-ret-long ( n -- )   gforth ffi_ret_long
#ifdef BUGGY_LONG_LONG
*(Cell*)(gforth_ritem) = DLO(n);
#else
*(Cell*)(gforth_ritem) = n;  *(Cell*)(gforth_ritem) = n;
#endif
return 0;  return 0;

ffi-ret-ptr ( c_addr -- )       gforth ffi_ret_ptr  ffi-ret-ptr ( c_addr -- )       gforth ffi_ret_ptr

 Removed from v.1.194 changed lines Added in v.1.202

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>