www.pudn.com > miracl.zip > C1.MCS


; Comba/KCM Macros for C - alternate version with minimal branches 
; 
; Scheduled version 
; 
; Note that:  
; mr_small is a word length unsigned type 
; mr_large is a double word length unsigned type 
; MR_TOP(.) refers to the top half of a double word variable 
; 
; Triple register is extra|s1|s0 
;  
; See makemcs.txt for more information about this file 
; 
MACRO MUL_START 
  extra=s1=s0=0; 
ENDM 
; 
; STEP macro 
; 
MACRO STEP 
  pp1=(mr_large)a[%d]*b[%d]; 
  sum=pp1+s0; 
  s0=(mr_small)sum; 
  sum=(mr_large)s1+MR_TOP(sum); 
  s1=(mr_small)sum; 
  extra+=MR_TOP(sum); 
ENDM 
MACRO STEP1M 
  pp1=(mr_large)a[%d]*b[%d]; 
ENDM 
MACRO STEP1A 
  sum=pp1+s0; 
  s0=(mr_small)sum; 
  sum=(mr_large)s1+MR_TOP(sum); 
  s1=(mr_small)sum; 
  extra+=MR_TOP(sum); 
ENDM 
MACRO STEP2M 
  pp2=(mr_large)a[%d]*b[%d]; 
ENDM 
MACRO STEP2A 
  sum=pp2+s0; 
  s0=(mr_small)sum; 
  sum=(mr_large)s1+MR_TOP(sum); 
  s1=(mr_small)sum; 
  extra+=MR_TOP(sum); 
ENDM 
; 
; MFIN macro 
; 
MACRO MFIN 
  c[%d]=s0; 
  s0=s1; 
  s1=extra; 
  extra=0;   
ENDM 
; 
; LAST 
; 
MACRO LAST 
  pp1=(mr_large)a[%d]*b[%d]+s0; 
  s0=(mr_small)pp1; 
ENDM 
; 
; MULE 
; 
MACRO MUL_END 
  c[%d]=s0; 
ENDM 
; 
; SQR_START 
; 
MACRO SQR_START 
  extra=s1=s0=0; 
ENDM 
; 
; DSTEP 
; 
MACRO DSTEP 
  pp1=(mr_large)a[%d]*a[%d]; 
  sum=(mr_large)s0+(mr_small)pp1+(mr_small)pp1; 
  s0=(mr_small)sum; 
  sum=(mr_large)s1+MR_TOP(pp1)+MR_TOP(pp1)+MR_TOP(sum); 
  s1=(mr_small)sum; 
  extra+=MR_TOP(sum); 
ENDM 
MACRO DSTEP1M 
  pp1=(mr_large)a[%d]*a[%d]; 
ENDM 
MACRO DSTEP1A 
  sum=(mr_large)s0+(mr_small)pp1+(mr_small)pp1; 
  s0=(mr_small)sum; 
  sum=(mr_large)s1+MR_TOP(pp1)+MR_TOP(pp1)+MR_TOP(sum); 
  s1=(mr_small)sum; 
  extra+=MR_TOP(sum); 
ENDM 
MACRO DSTEP2M 
  pp2=(mr_large)a[%d]*a[%d]; 
ENDM 
MACRO DSTEP2A 
  sum=(mr_large)s0+(mr_small)pp2+(mr_small)pp2; 
  s0=(mr_small)sum; 
  sum=(mr_large)s1+MR_TOP(pp2)+MR_TOP(pp2)+MR_TOP(sum); 
  s1=(mr_small)sum; 
  extra+=MR_TOP(sum); 
ENDM 
; 
; SELF 
; 
MACRO SELF  
  pp1=(mr_large)a[%d]*a[%d]+s0; 
  s0=(mr_small)pp1; 
  pp1=(mr_large)s1+MR_TOP(pp1); 
  s1=(mr_small)pp1; 
  extra+=MR_TOP(pp1); 
ENDM 
; 
; SFIN 
; 
MACRO SFIN 
  c[%d]=s0; 
  s0=s1; 
  s1=extra; 
  extra=0; 
ENDM 
; 
; SQR_END 
; 
MACRO SQR_END 
  c[%d]=s0; 
ENDM 
; 
; REDC_START 
; 
MACRO REDC_START 
  extra=s1=0; 
  s0=a[0]; 
ENDM 
; 
; RFINU macro 
; 
MACRO RFINU 
  sp=s0*ndash; 
  a[%d]=sp; 
  pp1=(mr_large)sp*b[0]+s0; 
  s0=(mr_small)pp1; 
  pp1=(mr_large)s1+MR_TOP(pp1); 
  s0=(mr_small)pp1; 
  s1=extra+MR_TOP(pp1); 
  extra=0; 
  pp1=(mr_large)a[%d+1]+s0; 
  s0=(mr_small)pp1; 
  s1+=MR_TOP(pp1); 
ENDM 
;   
; RFIND macro 
; 
MACRO RFIND 
  a[%d]=s0; 
  s0=s1; 
  s1=extra; 
  extra=0; 
  pp1=(mr_large)a[%d+1]+s0; 
  s0=(mr_small)pp1; 
  s1+=MR_TOP(pp1); 
ENDM 
; 
; REDC_END macro 
; 
MACRO REDC_END 
  a[%d]=s0; 
  a[%d+1]=s1; 
ENDM 
; 
; ADD_START macro 
; 
MACRO ADD_START 
  u=(mr_large)a[0]+b[0]; 
  c[0]=(mr_small)u; 
  carry=MR_TOP(u);    
ENDM 
; 
; ADD macro  - c[.]=a[.]+b[.] 
; 
MACRO ADD  
  u=(mr_large)carry+a[%d]+b[%d]; 
  c[%d]=(mr_small)u; 
  carry=MR_TOP(u); 
ENDM 
; 
; ADD_END macro. 
; 
MACRO ADD_END 
ENDM 
; 
; INC_START macro. Do first one. 
; 
MACRO INC_START 
  u=(mr_large)a[0]+b[0]; 
  a[0]=(mr_small)u; 
  carry=MR_TOP(u); 
ENDM 
; 
; INC macro  a[.]+=b[.] 
; 
MACRO INC 
  u=(mr_large)carry+a[%d]+b[%d]; 
  a[%d]=(mr_small)u; 
  carry=MR_TOP(u); 
ENDM 
MACRO INC_END 
ENDM 
MACRO SUB_START 
  u=(mr_large)a[0]-b[0]; 
  c[0]=(mr_small)u; 
  carry=0-MR_TOP(u); 
ENDM 
; 
; SUB macro - c[.]=a[.]-b[.] 
; 
MACRO SUB 
  u=(mr_large)a[%d]-b[%d]-carry; 
  c[%d]=(mr_small)u; 
  carry=0-MR_TOP(u); 
ENDM 
MACRO SUB_END 
ENDM 
; 
; DEC_START macro 
; 
MACRO DEC_START 
  u=(mr_large)a[0]-b[0]; 
  a[0]=(mr_small)u; 
  carry=0-MR_TOP(u); 
ENDM 
;  
; DEC macro  a[.]-=b[.] 
; 
MACRO DEC 
  u=(mr_large)a[%d]-b[%d]-carry; 
  a[%d]=(mr_small)u; 
  carry=0-MR_TOP(u); 
ENDM 
; 
; DEC_END macro 
; 
MACRO DEC_END 
ENDM 
; 
; KADD_START macro. Zero Carry 
; 
MACRO KADD_START 
  carry=0; 
  k%d: 
ENDM 
; 
; KASL macro 
; 
MACRO KASL 
 n--; 
 if (n==0) goto k%d; 
 a+=%d; 
 b+=%d; 
 c+=%d; 
 goto k%d; 
 k%d: 
ENDM 
; 
; KADD_END macro 
; 
MACRO KADD_END    
ENDM 
; 
; KINC_START macro 
; 
MACRO KINC_START 
  carry=0; 
  k%d: 
ENDM 
; 
; KIDL macro 
; 
MACRO KIDL 
 n--; 
 if (n==0) goto k%d; 
 a+=%d; 
 b+=%d; 
 goto k%d; 
 k%d: 
ENDM 
; 
; KINC_END macro 
; 
MACRO KINC_END 
ENDM 
; 
; KDEC_START macro. Zero carry 
; 
MACRO KDEC_START 
  carry=0; 
  k%d: 
ENDM 
; 
; KDEC_END macro 
; 
MACRO KDEC_END 
ENDM