/* Pfe module: gfbench-ext.c ^Forth input: gfbench.hf Date: 26-Nov-2002 09:12:09 Translator: 0.1.6 */ #define _P4_SOURCE 1 /* pfe register variables, etc. */ #include /* Compiler switches for extra registers are NO_EXTRA_REGS, HF_TOSREG, and HF_FTOSREG.*/ #if !defined NO_EXTRA_REGS #if defined __target_arch_ppc register int hf_index asm ("21"); /* top DO ... LOOP params */ register int hf_limit asm ("22"); #ifdef HF_TOSREG register int TOS asm ("23"); register int hf_flag asm ("24"); #endif /* HF_TOSREG */ #ifdef HF_FTOSREG register double FTOS asm ("f14"); #endif /* HF_FTOSREG */ #elif defined __target_arch_i386 static int hf_index; /* top DO ... LOOP params */ static int hf_limit; #undef HF_TOSREG #ifdef HF_FTOSREG /* THIS DOES NOT WORK! */ register double FTOS asm ("%st(7)"); #endif /* HF_FTOSREG */ #elif defined __target_cpu_hppa register int hf_index asm ("r11"); /* top DO ... LOOP params */ register int hf_limit asm ("r10"); #ifdef HF_TOSREG register int TOS asm ("r9"); register int hf_flag asm ("r8"); #endif /* HF_TOSREG */ #ifdef HF_FTOSREG register double FTOS asm ("fr21"); #endif /* HF_FTOSREG */ #else #define NO_EXTRA_REGS 1 #warning Unknown architecture, using no extra register variables. #endif #endif /* !defined NO_EXTRA_REGS */ #ifdef NO_EXTRA_REGS static int hf_index; /* top DO ... LOOP params */ static int hf_limit; #undef HF_TOSREG #undef HF_FTOSREG #endif /* NO_EXTRA_REGS */ #ifdef HF_TOSREG #define HF_FILL_TOS TOS = *SP; /* note ";" in these two */ #define HF_SPILL_TOS *SP = TOS; #define HF_PUSH(A) *SP-- = TOS; TOS = (A) #define HF_POP(A) (A) = TOS; TOS = *++SP #define HF_DROP1 TOS = *++SP #define HF_DROP2 SP += 2; TOS = *SP #define HF_IF HF_POP(hf_flag); if (hf_flag) #define HF_NIF HF_POP(hf_flag); if (!hf_flag) #define HF_UNTIL HF_POP(hf_flag);}while (!hf_flag) #define HF_NUNTIL HF_POP(hf_flag);}while (hf_flag) #else #define TOS *SP #define HF_FILL_TOS #define HF_SPILL_TOS #define HF_PUSH(A) *--SP = (A) #define HF_POP(A) (A) = *SP++ #define HF_DROP1 SP += 1 #define HF_DROP2 SP += 2 #define HF_IF if (*SP++) #define HF_NIF if (!*SP++) #define HF_UNTIL }while (!*SP++) #define HF_NUNTIL }while (*SP++) #endif /* HF_TOSREG */ #ifdef HF_FTOSREG #define HF_FILL_FTOS FTOS = *FP; /* note ";" in these two */ #define HF_SPILL_FTOS *FP = FTOS; #define HF_FPUSH(A) *FP-- = FTOS; FTOS = (A) #define HF_FPOP(A) (A) = FTOS; FTOS = *++FP #define HF_FDROP1 FTOS = *++FP #define HF_FDROP2 FP += 2; FTOS = *FP #define HF_FDROP3 FP += 3; FTOS = *FP #else #define FTOS *FP #define HF_FILL_FTOS #define HF_SPILL_FTOS #define HF_FPUSH(A) *--FP = (A) #define HF_FPOP(A) (A) = *FP++ #define HF_FDROP1 FP += 1 #define HF_FDROP2 FP += 2 #define HF_FDROP3 FP += 3 #endif /* HF_FTOSREG */ /* The basic pfe include. */ #include /* No extra include's. */ #define zero 0 #define one 1 #define two 2 #define three 3 #define four 4 #define five 5 #define six 6 #define seven 7 #define eight 8 #define nine 9 #define ten 10 #define sixteen 16 #define minus_one -1 #define minus_two -2 #define minus_three -3 #define minus_four -4 #define minus_five -5 #define bl 32 #define true -1 #define false 0 FCode (p4_dot); FCode (p4_abort); FCode (p4_char); FCode (p4_cr); FCode (p4_emit); FCode (p4_roll); FCode (p4_source); FCode (p4_space); FCode (p4_spaces); FCode (p4_type); FCode (p4_dot_s); p4char flags[8190]; FCode (hfi_flags) { *--SP = (p4cell) &flags; } #define sharp_flags 8190 FCode (hfi_sharp_flags) { *--SP = sharp_flags; } p4cell eflag = 0; FCode (hfi_eflag) { *--SP = (p4cell) &eflag; } FCode (hf_primes); FCode (hfi_primes) { HF_FILL_TOS HF_FILL_FTOS hf_primes_ (); HF_SPILL_TOS HF_SPILL_FTOS } FCode (hf_primes) { HF_PUSH((p4cell) &flags); HF_PUSH(8190); HF_PUSH(1); memset ((void *) SP[2], TOS, SP[1]); SP += 3; HF_FILL_TOS HF_PUSH(0); HF_PUSH(3); HF_PUSH((p4cell) &eflag); TOS = *(p4cell *) TOS; HF_PUSH((p4cell) &flags); { RP -= 2; RP[0] = (p4xt *) hf_index; RP[1] = (p4xt *) hf_limit; hf_index = TOS; hf_limit = SP[1]; HF_DROP2; while (hf_index < hf_limit){ HF_PUSH (hf_index); TOS = *(p4char *) TOS; { HF_IF{ #ifdef HF_TOSREG *SP-- = TOS; #else SP--; SP[0] = SP[1]; #endif HF_PUSH (hf_index); { p4cell res = TOS + SP[1]; SP++; TOS = res; } #ifdef HF_TOSREG *SP-- = TOS; #else SP--; SP[0] = SP[1]; #endif HF_PUSH((p4cell) &eflag); TOS = *(p4cell *) TOS; { p4cell res = P4_FLAG (TOS > SP[1]); SP++; TOS = res; } { HF_IF{ HF_PUSH((p4cell) &eflag); TOS = *(p4cell *) TOS; { p4cell h = SP[1]; SP[1] = TOS; TOS = h; } { RP -= 2; RP[0] = (p4xt *) hf_index; RP[1] = (p4xt *) hf_limit; hf_index = TOS; hf_limit = SP[1]; HF_DROP2; while (hf_index < hf_limit){ HF_PUSH(0); HF_PUSH (hf_index); *(char *) TOS = SP[1]; HF_DROP2; #ifdef HF_TOSREG *SP-- = TOS; #else SP--; SP[0] = SP[1]; #endif hf_index += TOS; HF_DROP1; } hf_index = (int) *RP++; hf_limit = (int) *RP++; } }else{ HF_DROP1; }} { p4cell h = SP[1]; SP[1] = TOS; TOS = h; } ++TOS; { p4cell h = SP[1]; SP[1] = TOS; TOS = h; } }} HF_PUSH(2); { p4cell res = TOS + SP[1]; SP++; TOS = res; } hf_index++; } hf_index = (int) *RP++; hf_limit = (int) *RP++; } HF_DROP1; } FCode (hf_dot_primes); FCode (hfi_dot_primes) { HF_FILL_TOS HF_FILL_FTOS hf_dot_primes_ (); HF_SPILL_TOS HF_SPILL_FTOS } FCode (hf_dot_primes) { HF_PUSH((p4cell) &flags); HF_PUSH(8190); { p4cell res = TOS + SP[1]; SP++; TOS = res; } HF_PUSH((p4cell) &eflag); *(p4cell *) TOS = SP[1]; HF_DROP2; HF_PUSH((p4cell) &flags); HF_PUSH(8190); HF_PUSH(1); memset ((void *) SP[2], TOS, SP[1]); SP += 3; HF_FILL_TOS HF_PUSH(0); HF_PUSH(3); HF_PUSH((p4cell) &eflag); TOS = *(p4cell *) TOS; HF_PUSH((p4cell) &flags); { RP -= 2; RP[0] = (p4xt *) hf_index; RP[1] = (p4xt *) hf_limit; hf_index = TOS; hf_limit = SP[1]; HF_DROP2; while (hf_index < hf_limit){ HF_PUSH (hf_index); TOS = *(p4char *) TOS; { HF_IF{ #ifdef HF_TOSREG *SP-- = TOS; #else SP--; SP[0] = SP[1]; #endif HF_SPILL_TOS HF_SPILL_FTOS p4_dot_ (); HF_FILL_TOS HF_FILL_FTOS #ifdef HF_TOSREG *SP-- = TOS; #else SP--; SP[0] = SP[1]; #endif HF_PUSH (hf_index); { p4cell res = TOS + SP[1]; SP++; TOS = res; } #ifdef HF_TOSREG *SP-- = TOS; #else SP--; SP[0] = SP[1]; #endif HF_PUSH((p4cell) &eflag); TOS = *(p4cell *) TOS; { p4cell res = P4_FLAG (TOS > SP[1]); SP++; TOS = res; } { HF_IF{ HF_PUSH((p4cell) &eflag); TOS = *(p4cell *) TOS; { p4cell h = SP[1]; SP[1] = TOS; TOS = h; } { RP -= 2; RP[0] = (p4xt *) hf_index; RP[1] = (p4xt *) hf_limit; hf_index = TOS; hf_limit = SP[1]; HF_DROP2; while (hf_index < hf_limit){ HF_PUSH(0); HF_PUSH (hf_index); *(char *) TOS = SP[1]; HF_DROP2; #ifdef HF_TOSREG *SP-- = TOS; #else SP--; SP[0] = SP[1]; #endif hf_index += TOS; HF_DROP1; } hf_index = (int) *RP++; hf_limit = (int) *RP++; } }else{ HF_DROP1; }} { p4cell h = SP[1]; SP[1] = TOS; TOS = h; } ++TOS; { p4cell h = SP[1]; SP[1] = TOS; TOS = h; } }} HF_PUSH(2); { p4cell res = TOS + SP[1]; SP++; TOS = res; } hf_index++; } hf_index = (int) *RP++; hf_limit = (int) *RP++; } HF_DROP1; } FCode (hf_c_primes); FCode (hfi_c_primes) { HF_FILL_TOS HF_FILL_FTOS hf_c_primes_ (); HF_SPILL_TOS HF_SPILL_FTOS } FCode (hf_c_primes) { int primes = 0, odd = 3; char *p = (char *) &flags, *q = (char *) eflag, *r; memset (p, 1, sharp_flags); while (p < q){ if (*p){ /* odd is prime */ /* HF_PUSH (odd); HF_SPILL_TOS HF_SPILL_FTOS p4_dot_ (); HF_FILL_TOS HF_FILL_FTOS */ /* print primes for debug */ r = p + odd; if (r < q){ while (r < q){ *r = 0; r += odd;}} primes += 1;} odd += 2; p++;} HF_PUSH (primes); } FCode (hf_dot_c_primes); FCode (hfi_dot_c_primes) { HF_FILL_TOS HF_FILL_FTOS hf_dot_c_primes_ (); HF_SPILL_TOS HF_SPILL_FTOS } FCode (hf_dot_c_primes) { HF_PUSH((p4cell) &flags); HF_PUSH(8190); { p4cell res = TOS + SP[1]; SP++; TOS = res; } HF_PUSH((p4cell) &eflag); *(p4cell *) TOS = SP[1]; HF_DROP2; { int primes = 0, odd = 3; char *p = (char *) &flags, *q = (char *) eflag, *r; memset (p, 1, sharp_flags); while (p < q){ if (*p){ /* odd is prime */ HF_PUSH (odd); HF_SPILL_TOS HF_SPILL_FTOS p4_dot_ (); HF_FILL_TOS HF_FILL_FTOS /* print primes for debug */ r = p + odd; if (r < q){ while (r < q){ *r = 0; r += odd;}} primes += 1;} odd += 2; p++;} HF_PUSH (primes); } } #define sharp_iters 1000 FCode (hfi_sharp_iters) { *--SP = sharp_iters; } FCode (hf_benchmark); FCode (hfi_benchmark) { HF_FILL_TOS HF_FILL_FTOS hf_benchmark_ (); HF_SPILL_TOS HF_SPILL_FTOS } FCode (hf_benchmark) { HF_PUSH(0); HF_PUSH(1000); HF_PUSH(0); { RP -= 2; RP[0] = (p4xt *) hf_index; RP[1] = (p4xt *) hf_limit; hf_index = TOS; hf_limit = SP[1]; HF_DROP2; while (hf_index < hf_limit){ hf_primes_ (); { p4cell res = TOS; SP++; TOS = res; } hf_index++; } hf_index = (int) *RP++; hf_limit = (int) *RP++; } } FCode (hf_c_benchmark); FCode (hfi_c_benchmark) { HF_FILL_TOS HF_FILL_FTOS hf_c_benchmark_ (); HF_SPILL_TOS HF_SPILL_FTOS } FCode (hf_c_benchmark) { HF_PUSH(0); HF_PUSH(1000); HF_PUSH(0); { RP -= 2; RP[0] = (p4xt *) hf_index; RP[1] = (p4xt *) hf_limit; hf_index = TOS; hf_limit = SP[1]; HF_DROP2; while (hf_index < hf_limit){ hf_c_primes_ (); { p4cell res = TOS; SP++; TOS = res; } hf_index++; } hf_index = (int) *RP++; hf_limit = (int) *RP++; } } FCode (hf_sieve_main); FCode (hfi_sieve_main) { HF_FILL_TOS HF_FILL_FTOS hf_sieve_main_ (); HF_SPILL_TOS HF_SPILL_FTOS } FCode (hf_sieve_main) { HF_PUSH((p4cell) &flags); HF_PUSH(8190); { p4cell res = TOS + SP[1]; SP++; TOS = res; } HF_PUSH((p4cell) &eflag); *(p4cell *) TOS = SP[1]; HF_DROP2; hf_benchmark_ (); HF_DROP1; } FCode (hf_c_sieve_main); FCode (hfi_c_sieve_main) { HF_FILL_TOS HF_FILL_FTOS hf_c_sieve_main_ (); HF_SPILL_TOS HF_SPILL_FTOS } FCode (hf_c_sieve_main) { HF_PUSH((p4cell) &flags); HF_PUSH(8190); { p4cell res = TOS + SP[1]; SP++; TOS = res; } HF_PUSH((p4cell) &eflag); *(p4cell *) TOS = SP[1]; HF_DROP2; hf_c_benchmark_ (); HF_DROP1; } p4cell seed = 0; FCode (hfi_seed) { *--SP = (p4cell) &seed; } #define seed_zero 74755 FCode (hfi_seed_zero) { *--SP = seed_zero; } #define thirteen_zero_nine 1309 FCode (hfi_thirteen_zero_nine) { *--SP = thirteen_zero_nine; } #define thirteen_eight_forty_nine 13849 FCode (hfi_thirteen_eight_forty_nine) { *--SP = thirteen_eight_forty_nine; } #define sixty_four_k_minus_one 65535 FCode (hfi_sixty_four_k_minus_one) { *--SP = sixty_four_k_minus_one; } FCode (hf_initiate_seed); FCode (hfi_initiate_seed) { HF_FILL_TOS HF_FILL_FTOS hf_initiate_seed_ (); HF_SPILL_TOS HF_SPILL_FTOS } FCode (hf_initiate_seed) { HF_PUSH(74755); HF_PUSH((p4cell) &seed); *(p4cell *) TOS = SP[1]; HF_DROP2; } FCode (hf_random); FCode (hfi_random) { HF_FILL_TOS HF_FILL_FTOS hf_random_ (); HF_SPILL_TOS HF_SPILL_FTOS } FCode (hf_random) { HF_PUSH((p4cell) &seed); TOS = *(p4cell *) TOS; HF_PUSH(1309); { p4cell res = TOS * SP[1]; SP++; TOS = res; } HF_PUSH(13849); { p4cell res = TOS + SP[1]; SP++; TOS = res; } HF_PUSH(65535); { p4cell res = TOS & SP[1]; SP++; TOS = res; } #ifdef HF_TOSREG *SP-- = TOS; #else SP--; SP[0] = SP[1]; #endif HF_PUSH((p4cell) &seed); *(p4cell *) TOS = SP[1]; HF_DROP2; } #define elements 6000 FCode (hfi_elements) { *--SP = elements; } p4cell list[24000]; FCode (hfi_list) { *--SP = (p4cell) &list; } FCode (hf_initiate_list); FCode (hfi_initiate_list) { HF_FILL_TOS HF_FILL_FTOS hf_initiate_list_ (); HF_SPILL_TOS HF_SPILL_FTOS } FCode (hf_initiate_list) { HF_PUSH((p4cell) &list); HF_PUSH(6000); TOS *= sizeof (p4cell); { p4cell res = TOS + SP[1]; SP++; TOS = res; } HF_PUSH((p4cell) &list); { RP -= 2; RP[0] = (p4xt *) hf_index; RP[1] = (p4xt *) hf_limit; hf_index = TOS; hf_limit = SP[1]; HF_DROP2; while (hf_index < hf_limit){ hf_random_ (); HF_PUSH (hf_index); *(p4cell *) TOS = SP[1]; HF_DROP2; HF_PUSH (PFE_SIZEOF_CELL); hf_index += TOS; HF_DROP1; } hf_index = (int) *RP++; hf_limit = (int) *RP++; } } FCode (hf_dump_list); FCode (hfi_dump_list) { HF_FILL_TOS HF_FILL_FTOS hf_dump_list_ (); HF_SPILL_TOS HF_SPILL_FTOS } FCode (hf_dump_list) { HF_PUSH((p4cell) &list); HF_PUSH(6000); TOS *= sizeof (p4cell); { p4cell res = TOS + SP[1]; SP++; TOS = res; } HF_PUSH((p4cell) &list); { RP -= 2; RP[0] = (p4xt *) hf_index; RP[1] = (p4xt *) hf_limit; hf_index = TOS; hf_limit = SP[1]; HF_DROP2; while (hf_index < hf_limit){ HF_PUSH (hf_index); TOS = *(p4cell *) TOS; HF_SPILL_TOS HF_SPILL_FTOS p4_dot_ (); HF_FILL_TOS HF_FILL_FTOS HF_PUSH (PFE_SIZEOF_CELL); hf_index += TOS; HF_DROP1; } hf_index = (int) *RP++; hf_limit = (int) *RP++; } HF_SPILL_TOS HF_SPILL_FTOS p4_cr_ (); HF_FILL_TOS HF_FILL_FTOS } FCode (hf_verify_list); FCode (hfi_verify_list) { HF_FILL_TOS HF_FILL_FTOS hf_verify_list_ (); HF_SPILL_TOS HF_SPILL_FTOS } FCode (hf_verify_list) { HF_PUSH((p4cell) &list); HF_PUSH(6000); --TOS; TOS *= sizeof (p4cell); { p4cell h = SP[1]; SP[1] += TOS; TOS = h; } { RP -= 2; RP[0] = (p4xt *) hf_index; RP[1] = (p4xt *) hf_limit; hf_index = TOS; hf_limit = SP[1]; HF_DROP2; while (hf_index < hf_limit){ HF_PUSH (hf_index); #ifdef HF_TOSREG { p4cell *addr = (p4cell *)TOS; TOS = *addr; *SP-- = *(addr + 1); } #else { p4dcell *addr = (p4dcell *) *SP--; *(p4dcell *) SP = *addr; } #endif { p4cell res = P4_FLAG (TOS < SP[1]); SP++; TOS = res; } HF_IF{ HF_FILL_TOS SP -= 2; TOS = 24; (char *) SP[1] = "bubble-sort: not sorted "; HF_SPILL_TOS p4_type_ (); p4_abort_ (); } HF_PUSH (PFE_SIZEOF_CELL); hf_index += TOS; HF_DROP1; } hf_index = (int) *RP++; hf_limit = (int) *RP++; } } FCode (hf_bubble); FCode (hfi_bubble) { HF_FILL_TOS HF_FILL_FTOS hf_bubble_ (); HF_SPILL_TOS HF_SPILL_FTOS } FCode (hf_bubble) { HF_PUSH(6000); HF_PUSH(1); { RP -= 2; RP[0] = (p4xt *) hf_index; RP[1] = (p4xt *) hf_limit; hf_index = TOS; hf_limit = SP[1]; HF_DROP2; while (hf_index < hf_limit){ HF_PUSH((p4cell) &list); HF_PUSH(6000); HF_PUSH (hf_index); { p4cell res = SP[1] - TOS; SP++; TOS = res; } TOS *= sizeof (p4cell); { p4cell h = SP[1]; SP[1] += TOS; TOS = h; } { RP -= 2; RP[0] = (p4xt *) hf_index; RP[1] = (p4xt *) hf_limit; hf_index = TOS; hf_limit = SP[1]; HF_DROP2; while (hf_index < hf_limit){ HF_PUSH (hf_index); #ifdef HF_TOSREG { p4cell *addr = (p4cell *)TOS; TOS = *addr; *SP-- = *(addr + 1); } #else { p4dcell *addr = (p4dcell *) *SP--; *(p4dcell *) SP = *addr; } #endif { p4cell res = P4_FLAG (TOS < SP[1]); SP++; TOS = res; } { HF_IF{ HF_PUSH (hf_index); #ifdef HF_TOSREG { p4cell *addr = (p4cell *)TOS; TOS = *addr; *SP-- = *(addr + 1); } #else { p4dcell *addr = (p4dcell *) *SP--; *(p4dcell *) SP = *addr; } #endif { p4cell h = SP[1]; SP[1] = TOS; TOS = h; } HF_PUSH (hf_index); *(p4dcell *) TOS = *(p4dcell *) &SP[1]; SP += 3; }} HF_PUSH (PFE_SIZEOF_CELL); hf_index += TOS; HF_DROP1; } hf_index = (int) *RP++; hf_limit = (int) *RP++; } hf_index++; } hf_index = (int) *RP++; hf_limit = (int) *RP++; } } FCode (hf_c_bubble); FCode (hfi_c_bubble) { HF_FILL_TOS HF_FILL_FTOS hf_c_bubble_ (); HF_SPILL_TOS HF_SPILL_FTOS } FCode (hf_c_bubble) { int i = 1; p4cell *p, *q, s0, s1; while (i < elements){ p = (p4cell *) &list; q = p + elements - i; while (p < q){ s0 = p[0]; s1 = p[1]; if (s0 < s1){ p[0] = s1; p[1] = s0;} p++;} i++;} } FCode (hf_bubble_sort); FCode (hfi_bubble_sort) { HF_FILL_TOS HF_FILL_FTOS hf_bubble_sort_ (); HF_SPILL_TOS HF_SPILL_FTOS } FCode (hf_bubble_sort) { hf_initiate_seed_ (); hf_initiate_list_ (); hf_bubble_ (); hf_verify_list_ (); } FCode (hf_c_bubble_sort); FCode (hfi_c_bubble_sort) { HF_FILL_TOS HF_FILL_FTOS hf_c_bubble_sort_ (); HF_SPILL_TOS HF_SPILL_FTOS } FCode (hf_c_bubble_sort) { hf_initiate_seed_ (); hf_initiate_list_ (); hf_c_bubble_ (); hf_verify_list_ (); } FCode (hf_bubble_with_flag); FCode (hfi_bubble_with_flag) { HF_FILL_TOS HF_FILL_FTOS hf_bubble_with_flag_ (); HF_SPILL_TOS HF_SPILL_FTOS } FCode (hf_bubble_with_flag) { HF_PUSH(1); HF_PUSH(6000); HF_PUSH(1); { RP -= 2; RP[0] = (p4xt *) hf_index; RP[1] = (p4xt *) hf_limit; hf_index = TOS; hf_limit = SP[1]; HF_DROP2; while (hf_index < hf_limit){ HF_PUSH(-1); HF_PUSH((p4cell) &list); HF_PUSH(6000); HF_PUSH (hf_index); { p4cell res = SP[1] - TOS; SP++; TOS = res; } TOS *= sizeof (p4cell); { p4cell h = SP[1]; SP[1] += TOS; TOS = h; } { RP -= 2; RP[0] = (p4xt *) hf_index; RP[1] = (p4xt *) hf_limit; hf_index = TOS; hf_limit = SP[1]; HF_DROP2; while (hf_index < hf_limit){ HF_PUSH (hf_index); #ifdef HF_TOSREG { p4cell *addr = (p4cell *)TOS; TOS = *addr; *SP-- = *(addr + 1); } #else { p4dcell *addr = (p4dcell *) *SP--; *(p4dcell *) SP = *addr; } #endif { p4cell res = P4_FLAG (TOS < SP[1]); SP++; TOS = res; } { HF_IF{ HF_PUSH (hf_index); #ifdef HF_TOSREG { p4cell *addr = (p4cell *)TOS; TOS = *addr; *SP-- = *(addr + 1); } #else { p4dcell *addr = (p4dcell *) *SP--; *(p4dcell *) SP = *addr; } #endif { p4cell h = SP[1]; SP[1] = TOS; TOS = h; } HF_PUSH (hf_index); *(p4dcell *) TOS = *(p4dcell *) &SP[1]; SP += 3; HF_DROP1; HF_PUSH(0); }} HF_PUSH (PFE_SIZEOF_CELL); hf_index += TOS; HF_DROP1; } hf_index = (int) *RP++; hf_limit = (int) *RP++; } { HF_IF{ hf_index = (int) *RP++; hf_limit = (int) *RP++; break; }} hf_index++; } hf_index = (int) *RP++; hf_limit = (int) *RP++; } } FCode (hf_bubble_sort_with_flag); FCode (hfi_bubble_sort_with_flag) { HF_FILL_TOS HF_FILL_FTOS hf_bubble_sort_with_flag_ (); HF_SPILL_TOS HF_SPILL_FTOS } FCode (hf_bubble_sort_with_flag) { hf_initiate_seed_ (); hf_initiate_list_ (); hf_bubble_with_flag_ (); hf_verify_list_ (); } FCode (hf_bubble_main); FCode (hfi_bubble_main) { HF_FILL_TOS HF_FILL_FTOS hf_bubble_main_ (); HF_SPILL_TOS HF_SPILL_FTOS } FCode (hf_bubble_main) { hf_bubble_sort_ (); } FCode (hf_c_bubble_main); FCode (hfi_c_bubble_main) { HF_FILL_TOS HF_FILL_FTOS hf_c_bubble_main_ (); HF_SPILL_TOS HF_SPILL_FTOS } FCode (hf_c_bubble_main) { hf_c_bubble_sort_ (); } #define row_size 200 FCode (hfi_row_size) { *--SP = row_size; } #define row_byte_size 800 FCode (hfi_row_byte_size) { *--SP = row_byte_size; } #define mat_size 40000 FCode (hfi_mat_size) { *--SP = mat_size; } #define mat_byte_size 160000 FCode (hfi_mat_byte_size) { *--SP = mat_byte_size; } p4cell ima[160000]; FCode (hfi_ima) { *--SP = (p4cell) &ima; } p4cell imb[160000]; FCode (hfi_imb) { *--SP = (p4cell) &imb; } p4cell imr[160000]; FCode (hfi_imr) { *--SP = (p4cell) &imr; } #define one_hundred_twenty 120 FCode (hfi_one_hundred_twenty) { *--SP = one_hundred_twenty; } #define sixty 60 FCode (hfi_sixty) { *--SP = sixty; } FCode (hf_initiate_matrix); FCode (hfi_initiate_matrix) { HF_FILL_TOS HF_FILL_FTOS hf_initiate_matrix_ (); HF_SPILL_TOS HF_SPILL_FTOS } FCode (hf_initiate_matrix) { HF_PUSH(160000); { p4cell h = SP[1]; SP[1] += TOS; TOS = h; } { RP -= 2; RP[0] = (p4xt *) hf_index; RP[1] = (p4xt *) hf_limit; hf_index = TOS; hf_limit = SP[1]; HF_DROP2; while (hf_index < hf_limit){ hf_random_ (); #ifdef HF_TOSREG *SP-- = TOS; #else SP--; SP[0] = SP[1]; #endif HF_PUSH(120); { fdiv_t n = p4_fdiv (SP[1], TOS); SP++; TOS = n.quot; } HF_PUSH(120); { p4cell res = TOS * SP[1]; SP++; TOS = res; } { p4cell res = SP[1] - TOS; SP++; TOS = res; } HF_PUSH(60); { p4cell res = SP[1] - TOS; SP++; TOS = res; } HF_PUSH (hf_index); *(p4cell *) TOS = SP[1]; HF_DROP2; HF_PUSH (PFE_SIZEOF_CELL); hf_index += TOS; HF_DROP1; } hf_index = (int) *RP++; hf_limit = (int) *RP++; } } FCode (hf_c_initiate_matrix); FCode (hfi_c_initiate_matrix) { HF_FILL_TOS HF_FILL_FTOS hf_c_initiate_matrix_ (); HF_SPILL_TOS HF_SPILL_FTOS } FCode (hf_c_initiate_matrix) { p4cell *q, *p = (p4cell *)TOS; p4ucell r = seed; HF_DROP1; q = p + mat_size; while (p < q){ r = (r * 1309 + 13849) & 65535; *p++ = r - (r / 120) * 120 - 60;} seed = r; } FCode (hf_innerproduct); FCode (hfi_innerproduct) { HF_FILL_TOS HF_FILL_FTOS hf_innerproduct_ (); HF_SPILL_TOS HF_SPILL_FTOS } FCode (hf_innerproduct) { HF_PUSH(0); HF_PUSH(200); HF_PUSH(0); { RP -= 2; RP[0] = (p4xt *) hf_index; RP[1] = (p4xt *) hf_limit; hf_index = TOS; hf_limit = SP[1]; HF_DROP2; while (hf_index < hf_limit){ RP_PUSH (TOS); HF_DROP1; HF_SPILL_TOS --SP; TOS = SP[2]; TOS = *(p4cell *) TOS; HF_SPILL_TOS --SP; TOS = SP[2]; TOS = *(p4cell *) TOS; { p4cell res = TOS * SP[1]; SP++; TOS = res; } HF_PUSH (RP_POP()); { p4cell res = TOS + SP[1]; SP++; TOS = res; } RP_PUSH (TOS); HF_DROP1; { p4cell h = SP[1]; SP[1] = TOS; TOS = h; } TOS += sizeof (p4cell); { p4cell h = SP[1]; SP[1] = TOS; TOS = h; } HF_PUSH(800); { p4cell res = TOS + SP[1]; SP++; TOS = res; } HF_PUSH (RP_POP()); hf_index++; } hf_index = (int) *RP++; hf_limit = (int) *RP++; } RP_PUSH (TOS); HF_DROP1; HF_DROP2; HF_PUSH (RP_POP()); } FCode (hf_c_innerproduct); FCode (hfi_c_innerproduct) { HF_FILL_TOS HF_FILL_FTOS hf_c_innerproduct_ (); HF_SPILL_TOS HF_SPILL_FTOS } FCode (hf_c_innerproduct) { p4cell *row = (p4cell *) TOS; p4cell *col = (p4cell *) SP[1]; p4cell i = 0, sum = 0; SP++; while (i++ < row_size){ sum += *row * *col++; row += row_size;} TOS = sum; } FCode (hf_matrix_main); FCode (hfi_matrix_main) { HF_FILL_TOS HF_FILL_FTOS hf_matrix_main_ (); HF_SPILL_TOS HF_SPILL_FTOS } FCode (hf_matrix_main) { hf_initiate_seed_ (); HF_PUSH((p4cell) &ima); hf_initiate_matrix_ (); HF_PUSH((p4cell) &imb); hf_initiate_matrix_ (); HF_PUSH((p4cell) &imr); HF_PUSH((p4cell) &ima); HF_PUSH(160000); { p4cell h = SP[1]; SP[1] += TOS; TOS = h; } { RP -= 2; RP[0] = (p4xt *) hf_index; RP[1] = (p4xt *) hf_limit; hf_index = TOS; hf_limit = SP[1]; HF_DROP2; while (hf_index < hf_limit){ HF_PUSH((p4cell) &imb); HF_PUSH(800); { p4cell h = SP[1]; SP[1] += TOS; TOS = h; } { RP -= 2; RP[0] = (p4xt *) hf_index; RP[1] = (p4xt *) hf_limit; hf_index = TOS; hf_limit = SP[1]; HF_DROP2; while (hf_index < hf_limit){ HF_PUSH ((int) *RP); HF_PUSH (hf_index); hf_innerproduct_ (); HF_SPILL_TOS --SP; TOS = SP[2]; *(p4cell *) TOS = SP[1]; HF_DROP2; TOS += sizeof (p4cell); HF_PUSH (PFE_SIZEOF_CELL); hf_index += TOS; HF_DROP1; } hf_index = (int) *RP++; hf_limit = (int) *RP++; } HF_PUSH(200); TOS *= sizeof (p4cell); hf_index += TOS; HF_DROP1; } hf_index = (int) *RP++; hf_limit = (int) *RP++; } HF_DROP1; } FCode (hf_c_matrix_main_one); FCode (hfi_c_matrix_main_one) { HF_FILL_TOS HF_FILL_FTOS hf_c_matrix_main_one_ (); HF_SPILL_TOS HF_SPILL_FTOS } FCode (hf_c_matrix_main_one) { hf_initiate_seed_ (); HF_PUSH((p4cell) &ima); hf_c_initiate_matrix_ (); HF_PUSH((p4cell) &imb); hf_c_initiate_matrix_ (); HF_PUSH((p4cell) &imr); HF_PUSH((p4cell) &ima); HF_PUSH(160000); { p4cell h = SP[1]; SP[1] += TOS; TOS = h; } { RP -= 2; RP[0] = (p4xt *) hf_index; RP[1] = (p4xt *) hf_limit; hf_index = TOS; hf_limit = SP[1]; HF_DROP2; while (hf_index < hf_limit){ HF_PUSH((p4cell) &imb); HF_PUSH(800); { p4cell h = SP[1]; SP[1] += TOS; TOS = h; } { RP -= 2; RP[0] = (p4xt *) hf_index; RP[1] = (p4xt *) hf_limit; hf_index = TOS; hf_limit = SP[1]; HF_DROP2; while (hf_index < hf_limit){ HF_PUSH ((int) *RP); HF_PUSH (hf_index); hf_c_innerproduct_ (); HF_SPILL_TOS --SP; TOS = SP[2]; *(p4cell *) TOS = SP[1]; HF_DROP2; TOS += sizeof (p4cell); HF_PUSH (PFE_SIZEOF_CELL); hf_index += TOS; HF_DROP1; } hf_index = (int) *RP++; hf_limit = (int) *RP++; } HF_PUSH(200); TOS *= sizeof (p4cell); hf_index += TOS; HF_DROP1; } hf_index = (int) *RP++; hf_limit = (int) *RP++; } HF_DROP1; } FCode (hf_c_matrix_main_two); FCode (hfi_c_matrix_main_two) { HF_FILL_TOS HF_FILL_FTOS hf_c_matrix_main_two_ (); HF_SPILL_TOS HF_SPILL_FTOS } FCode (hf_c_matrix_main_two) { p4cell *row = ima, *col = imb, *result = imr; p4cell *row_lim = row + mat_size; p4cell *col_lim = col + row_size; hf_initiate_seed_ (); HF_PUSH((p4cell) &ima); hf_c_initiate_matrix_ (); HF_PUSH((p4cell) &imb); hf_c_initiate_matrix_ (); while (row < row_lim){ /* rows in left matrix */ col = imb; while (col < col_lim){ /* cols in right matrix */ HF_FILL_TOS SP -= 2; (p4cell *)SP[1] = row; (p4cell *) TOS = col++; hf_c_innerproduct_ (); *result++ = TOS; SP++;} row += row_size;} } FCode (hf_dump_a_matrix); FCode (hfi_dump_a_matrix) { HF_FILL_TOS HF_FILL_FTOS hf_dump_a_matrix_ (); HF_SPILL_TOS HF_SPILL_FTOS } FCode (hf_dump_a_matrix) { HF_PUSH((p4cell) &ima); HF_PUSH(160000); { p4cell h = SP[1]; SP[1] += TOS; TOS = h; } { RP -= 2; RP[0] = (p4xt *) hf_index; RP[1] = (p4xt *) hf_limit; hf_index = TOS; hf_limit = SP[1]; HF_DROP2; while (hf_index < hf_limit){ HF_PUSH (hf_index); TOS = *(p4cell *) TOS; HF_SPILL_TOS HF_SPILL_FTOS p4_dot_ (); HF_FILL_TOS HF_FILL_FTOS HF_PUSH (PFE_SIZEOF_CELL); hf_index += TOS; HF_DROP1; } hf_index = (int) *RP++; hf_limit = (int) *RP++; } } FCode (hf_dump_b_matrix); FCode (hfi_dump_b_matrix) { HF_FILL_TOS HF_FILL_FTOS hf_dump_b_matrix_ (); HF_SPILL_TOS HF_SPILL_FTOS } FCode (hf_dump_b_matrix) { HF_PUSH((p4cell) &imb); HF_PUSH(160000); { p4cell h = SP[1]; SP[1] += TOS; TOS = h; } { RP -= 2; RP[0] = (p4xt *) hf_index; RP[1] = (p4xt *) hf_limit; hf_index = TOS; hf_limit = SP[1]; HF_DROP2; while (hf_index < hf_limit){ HF_PUSH (hf_index); TOS = *(p4cell *) TOS; HF_SPILL_TOS HF_SPILL_FTOS p4_dot_ (); HF_FILL_TOS HF_FILL_FTOS HF_PUSH (PFE_SIZEOF_CELL); hf_index += TOS; HF_DROP1; } hf_index = (int) *RP++; hf_limit = (int) *RP++; } } FCode (hf_dump_result_matrix); FCode (hfi_dump_result_matrix) { HF_FILL_TOS HF_FILL_FTOS hf_dump_result_matrix_ (); HF_SPILL_TOS HF_SPILL_FTOS } FCode (hf_dump_result_matrix) { HF_PUSH((p4cell) &imr); HF_PUSH(160000); { p4cell h = SP[1]; SP[1] += TOS; TOS = h; } { RP -= 2; RP[0] = (p4xt *) hf_index; RP[1] = (p4xt *) hf_limit; hf_index = TOS; hf_limit = SP[1]; HF_DROP2; while (hf_index < hf_limit){ HF_PUSH (hf_index); TOS = *(p4cell *) TOS; HF_SPILL_TOS HF_SPILL_FTOS p4_dot_ (); HF_FILL_TOS HF_FILL_FTOS HF_PUSH (PFE_SIZEOF_CELL); hf_index += TOS; HF_DROP1; } hf_index = (int) *RP++; hf_limit = (int) *RP++; } } FCode (hf_fib); FCode (hfi_fib) { HF_FILL_TOS HF_FILL_FTOS hf_fib_ (); HF_SPILL_TOS HF_SPILL_FTOS } FCode (hf_fib) { #ifdef HF_TOSREG *SP-- = TOS; #else SP--; SP[0] = SP[1]; #endif HF_PUSH(2); { p4cell res = P4_FLAG (TOS > SP[1]); SP++; TOS = res; } { HF_IF{ HF_DROP1; HF_PUSH(1); }else{ #ifdef HF_TOSREG *SP-- = TOS; #else SP--; SP[0] = SP[1]; #endif --TOS; hf_fib_ (); { p4cell h = SP[1]; SP[1] = TOS; TOS = h; } HF_PUSH(2); { p4cell res = SP[1] - TOS; SP++; TOS = res; } hf_fib_ (); { p4cell res = TOS + SP[1]; SP++; TOS = res; } }} } FCode (hf_c_fib); FCode (hfi_c_fib) { HF_FILL_TOS HF_FILL_FTOS hf_c_fib_ (); HF_SPILL_TOS HF_SPILL_FTOS } FCode (hf_c_fib) { int n = TOS, f; if (n < 2){ TOS = 1; }else{ TOS = n - 1; hf_c_fib_ (); f = TOS; TOS = n - 2; hf_c_fib_ (); TOS += f;} } #define thirty_four 34 FCode (hfi_thirty_four) { *--SP = thirty_four; } FCode (hf_fib_main); FCode (hfi_fib_main) { HF_FILL_TOS HF_FILL_FTOS hf_fib_main_ (); HF_SPILL_TOS HF_SPILL_FTOS } FCode (hf_fib_main) { HF_PUSH(34); hf_fib_ (); HF_DROP1; } FCode (hf_c_fib_main); FCode (hfi_c_fib_main) { HF_FILL_TOS HF_FILL_FTOS hf_c_fib_main_ (); HF_SPILL_TOS HF_SPILL_FTOS } FCode (hf_c_fib_main) { HF_PUSH(34); hf_c_fib_ (); HF_DROP1; } P4_LISTWORDS (hfbench) = { P4_FXco ("flags", hfi_flags), P4_FXco ("#flags", hfi_sharp_flags), P4_FXco ("eflag", hfi_eflag), P4_FXco ("primes", hfi_primes), P4_FXco (".primes", hfi_dot_primes), P4_FXco ("cprimes", hfi_c_primes), P4_FXco (".cprimes", hfi_dot_c_primes), P4_FXco ("#iters", hfi_sharp_iters), P4_FXco ("benchmark", hfi_benchmark), P4_FXco ("cbenchmark", hfi_c_benchmark), P4_FXco ("sieve-main", hfi_sieve_main), P4_FXco ("csieve-main", hfi_c_sieve_main), P4_FXco ("seed", hfi_seed), P4_FXco ("seed0", hfi_seed_zero), P4_FXco ("1309", hfi_thirteen_zero_nine), P4_FXco ("13849", hfi_thirteen_eight_forty_nine), P4_FXco ("65535", hfi_sixty_four_k_minus_one), P4_FXco ("initiate-seed", hfi_initiate_seed), P4_FXco ("random", hfi_random), P4_FXco ("elements", hfi_elements), P4_FXco ("list", hfi_list), P4_FXco ("initiate-list", hfi_initiate_list), P4_FXco ("dump-list", hfi_dump_list), P4_FXco ("verify-list", hfi_verify_list), P4_FXco ("bubble", hfi_bubble), P4_FXco ("cbubble", hfi_c_bubble), P4_FXco ("bubble-sort", hfi_bubble_sort), P4_FXco ("cbubble-sort", hfi_c_bubble_sort), P4_FXco ("bubble-with-flag", hfi_bubble_with_flag), P4_FXco ("bubble-sort-with-flag", hfi_bubble_sort_with_flag), P4_FXco ("bubble-main", hfi_bubble_main), P4_FXco ("cbubble-main", hfi_c_bubble_main), P4_FXco ("row-size", hfi_row_size), P4_FXco ("row-byte-size", hfi_row_byte_size), P4_FXco ("mat-size", hfi_mat_size), P4_FXco ("mat-byte-size", hfi_mat_byte_size), P4_FXco ("ima", hfi_ima), P4_FXco ("imb", hfi_imb), P4_FXco ("imr", hfi_imr), P4_FXco ("120", hfi_one_hundred_twenty), P4_FXco ("60", hfi_sixty), P4_FXco ("initiate-matrix", hfi_initiate_matrix), P4_FXco ("cinitiate-matrix", hfi_c_initiate_matrix), P4_FXco ("innerproduct", hfi_innerproduct), P4_FXco ("cinnerproduct", hfi_c_innerproduct), P4_FXco ("matrix-main", hfi_matrix_main), P4_FXco ("cmatrix-main1", hfi_c_matrix_main_one), P4_FXco ("cmatrix-main2", hfi_c_matrix_main_two), P4_FXco ("dump-a-matrix", hfi_dump_a_matrix), P4_FXco ("dump-b-matrix", hfi_dump_b_matrix), P4_FXco ("dump-result-matrix", hfi_dump_result_matrix), P4_FXco ("fib", hfi_fib), P4_FXco ("cfib", hfi_c_fib), P4_FXco ("34", hfi_thirty_four), P4_FXco ("fib-main", hfi_fib_main), P4_FXco ("cfib-main", hfi_c_fib_main) }; P4_COUNTWORDS (hfbench, "^Forth Benchmarks Word Set");