N32 lib compiles
authorThomas Walker Lynch <eknp9n@reasoningtechnology.com>
Thu, 13 Feb 2025 16:09:06 +0000 (16:09 +0000)
committerThomas Walker Lynch <eknp9n@reasoningtechnology.com>
Thu, 13 Feb 2025 16:09:06 +0000 (16:09 +0000)
developer/cc馃枆/N32.lib.c

index dd99de8..ff69120 100644 (file)
@@ -84,8 +84,11 @@ typedef N32路T *( *N32路Allocate_MemoryFault )(Extent);
 // Interface
 
 typedef struct{
+
+  N32路T *(*allocate_array_zero)(Extent, N32路Allocate_MemoryFault);
   N32路T *(*allocate_array)(Extent, N32路Allocate_MemoryFault);
   void (*deallocate)(N32路T*);
+
   void (*copy)(N32路T*, N32路T*);
   void (*bit_and)(N32路T*, N32路T*, N32路T*);
   void (*bit_or)(N32路T*, N32路T*, N32路T*);
@@ -96,7 +99,9 @@ typedef struct{
   bool (*gt)(N32路T*, N32路T*);
   bool (*eq)(N32路T*, N32路T*);
   bool (*eq_zero)(N32路T*);
+  N32路Status (*accumulate)(N32路T *accumulator1 ,N32路T *accumulator0 ,...);
   N32路Status (*add)(N32路T*, N32路T*, N32路T*);
+  bool (*increment)(N32路T *a);
   N32路Status (*subtract)(N32路T*, N32路T*, N32路T*);
   N32路Status (*multiply)(N32路T*, N32路T*, N32路T*, N32路T*);
   N32路Status (*divide)(N32路T*, N32路T*, N32路T*, N32路T*);
@@ -104,11 +109,12 @@ typedef struct{
   N32路Status (*shift_left)(Extent, N32路T*, N32路T*, N32路T*);
   N32路Status (*shift_right)(Extent, N32路T*, N32路T*, N32路T*);
   N32路Status (*arithmetic_shift_right)(Extent, N32路T*, N32路T*);
+
   N32路T* (*access)(N32路T*, Extent);
   void (*from_uint32)(N32路T *destination ,uint32_t value);
 } N32路螞;
 
-extern const N32路螞 N32路位;
+Local const N32路螞 N32路位; // initialized in the LOCAL section
 
 #endif
 
@@ -141,7 +147,7 @@ N32路T *N32路msb = &N32路constant[3];
 N32路T *N32路lsb = &N32路constant[1];
 
 // the allocate an array of N32
-N32路T *N32路allocate_array( Extent extent ,N32路T *(*memory_fault)(Extent) ){
+N32路T *N32路allocate_array(Extent extent ,N32路Allocate_MemoryFault memory_fault){
   N32路T *instance = malloc((extent + 1) * sizeof(N32路T) );
   if(!instance){
     return memory_fault ? memory_fault(extent) : NULL;
@@ -149,7 +155,7 @@ N32路T *N32路allocate_array( Extent extent ,N32路T *(*memory_fault)(Extent) ){
   return instance;
 }
 
-N32路T *N32路alloc_array_zero( Extent extent ,N32路T *(*memory_fault)(Extent) ){
+N32路T *N32路allocate_array_zero(Extent extent ,N32路Allocate_MemoryFault memory_fault){
   N32路T *instance = calloc( extent + 1 ,sizeof(N32路T) );
   if(!instance){
     return memory_fault ? memory_fault(extent) : NULL;
@@ -178,7 +184,7 @@ struct N32路T{
 // allocating a block once is more efficient
 // library code writes these, they are not on the interface
 
-Local N32路T N32路t[4]
+Local N32路T N32路t[4];
 
 
 // allocation 
@@ -267,16 +273,15 @@ Local N32路Status N32路accumulate(N32路T *accumulator1 ,N32路T *accumulator0 ,..
 
   va_list args;
   va_start(args ,accumulator0);
-
-  uint64_t *sum = &accumulator0->d0;
-  uint64_t *carry = 0;
+  uint32_t sum = accumulator0->d0;
+  uint32_t carry = 0;
   N32路T *current;
 
   while( (current = va_arg(args ,N32路T *)) ){
-    *sum += current->d0;
-    if(*sum < current->d0){  // Accumulator1 into carry
-      (*carry)++;
-      if(*carry == 0){
+    sum += current->d0;
+    if(sum < current->d0){  // Accumulator1 into carry
+      (carry)++;
+      if(carry == 0){
         va_end(args);
         return N32路Status路accumulator1_overflow;
       }
@@ -313,7 +318,7 @@ Local N32路Status N32路multiply(N32路T *product1 ,N32路T *product0 ,N32路T *a ,N
   product0->d0 = (uint32_t)product;
   product1->d0 = (uint32_t)(product >> 32);
 
-  if(product1->d0 == 0) return N32路status路one_word_product;
+  if(product1->d0 == 0) return N32路Status路one_word_product;
   return N32路Status路two_word_product;
 }
 
@@ -417,10 +422,13 @@ N32路arithmetic_shift_right(uint32_t shift_count, N32路T *operand, N32路T *spill
   return N32路shift_right(shift_count, spill, operand, fill);
 }
 
-// an interface instance
-
 Local const N32路螞 N32路位 = {
-   .copy = N32路copy
+
+  .allocate_array = N32路allocate_array
+  ,.allocate_array_zero = N32路alloc_array_zero
+  ,.deallocate = N32路deallocate
+
+  ,.copy = N32路copy
   ,.bit_and = N32路bit_and
   ,.bit_or = N32路bit_or
   ,.bit_complement = N32路bit_complement
@@ -430,10 +438,9 @@ Local const N32路螞 N32路位 = {
   ,.gt = N32路gt
   ,.eq = N32路eq
   ,.eq_zero = N32路eq_zero
-  ,.eq_one = N32路eq_one
   ,.accumulate = N32路accumulate
   ,.add = N32路add
-  ,.next = N32路next
+  ,.increment = N32路increment
   ,.subtract = N32路subtract
   ,.multiply = N32路multiply
   ,.divide = N32路divide
@@ -441,9 +448,7 @@ Local const N32路螞 N32路位 = {
   ,.shift_left = N32路shift_left
   ,.shift_right = N32路shift_right
   ,.arithmetic_shift_right = N32路arithmetic_shift_right
-  ,.allocate_array = N32路allocate_array
-  ,.allocate_array_zero = N32路alloc_array_zero
-  ,.deallocate = N32路deallocate
+
   ,.access = N32路access
   ,.from_uint32 = N32路from_uint32
 };