19768109e5d3c18da127dd70f28454171c1eba7c0florian#include <stdio.h>
29768109e5d3c18da127dd70f28454171c1eba7c0florian#include <ctype.h>
39768109e5d3c18da127dd70f28454171c1eba7c0florian#include "test.h"
49768109e5d3c18da127dd70f28454171c1eba7c0florian
59768109e5d3c18da127dd70f28454171c1eba7c0florian#define LOOPBACK "jo 0b	\n\t"
69768109e5d3c18da127dd70f28454171c1eba7c0florian
79768109e5d3c18da127dd70f28454171c1eba7c0floriantypedef struct {
89768109e5d3c18da127dd70f28454171c1eba7c0florian   const char *str1;
99768109e5d3c18da127dd70f28454171c1eba7c0florian   const char *str2;
109768109e5d3c18da127dd70f28454171c1eba7c0florian   int cc;
119768109e5d3c18da127dd70f28454171c1eba7c0florian} clst_t;
129768109e5d3c18da127dd70f28454171c1eba7c0florian
139768109e5d3c18da127dd70f28454171c1eba7c0florianstatic clst_t
149768109e5d3c18da127dd70f28454171c1eba7c0floriando_clst(const char *__string1, const char *__string2, char __end)
159768109e5d3c18da127dd70f28454171c1eba7c0florian{
169768109e5d3c18da127dd70f28454171c1eba7c0florian   register char end asm ("0") = __end;
179768109e5d3c18da127dd70f28454171c1eba7c0florian   register const char *string1 asm ("2") = __string1;
189768109e5d3c18da127dd70f28454171c1eba7c0florian   register const char *string2 asm ("4") = __string2;
199768109e5d3c18da127dd70f28454171c1eba7c0florian
209768109e5d3c18da127dd70f28454171c1eba7c0florian   asm volatile( "0: clst 2,4\n\t"
219768109e5d3c18da127dd70f28454171c1eba7c0florian                 LOOPBACK
229768109e5d3c18da127dd70f28454171c1eba7c0florian                 :"+d" (string1), "+d" (string2) :"d" (end): "cc");
239768109e5d3c18da127dd70f28454171c1eba7c0florian
249768109e5d3c18da127dd70f28454171c1eba7c0florian   return (clst_t) { .str1 = string1, .str2 = string2, .cc = get_cc() };
259768109e5d3c18da127dd70f28454171c1eba7c0florian}
269768109e5d3c18da127dd70f28454171c1eba7c0florian
279768109e5d3c18da127dd70f28454171c1eba7c0florianvoid
289768109e5d3c18da127dd70f28454171c1eba7c0florianclst(const char *str1, const char *str2, int sentinel)
299768109e5d3c18da127dd70f28454171c1eba7c0florian{
309768109e5d3c18da127dd70f28454171c1eba7c0florian   clst_t res;
319768109e5d3c18da127dd70f28454171c1eba7c0florian
329768109e5d3c18da127dd70f28454171c1eba7c0florian   printf("comparing: %s with %s   sentinel = %d", str1, str2, sentinel);
339768109e5d3c18da127dd70f28454171c1eba7c0florian   if (isprint(sentinel))
349768109e5d3c18da127dd70f28454171c1eba7c0florian      printf(" (%c)", sentinel);
359768109e5d3c18da127dd70f28454171c1eba7c0florian   printf("\n");
369768109e5d3c18da127dd70f28454171c1eba7c0florian   res = do_clst(str1, str2, sentinel);
379768109e5d3c18da127dd70f28454171c1eba7c0florian   printf("str1 = %s\nstr2 = %s\ncc = %d\n", res.str1, res.str2, res.cc);
389768109e5d3c18da127dd70f28454171c1eba7c0florian   printf("\n");
399768109e5d3c18da127dd70f28454171c1eba7c0florian}
409768109e5d3c18da127dd70f28454171c1eba7c0florian
419768109e5d3c18da127dd70f28454171c1eba7c0florianint main(void)
429768109e5d3c18da127dd70f28454171c1eba7c0florian{
439768109e5d3c18da127dd70f28454171c1eba7c0florian   clst("lower123",  "lowerabc",  '\0');
449768109e5d3c18da127dd70f28454171c1eba7c0florian   clst("higher234", "higher123", '\0');
459768109e5d3c18da127dd70f28454171c1eba7c0florian   clst("equal",  "equal",  '\0');
469768109e5d3c18da127dd70f28454171c1eba7c0florian
479768109e5d3c18da127dd70f28454171c1eba7c0florian   clst("equal",  "equallong",  '\0');
489768109e5d3c18da127dd70f28454171c1eba7c0florian   clst("equallong",  "equal",  '\0');
499768109e5d3c18da127dd70f28454171c1eba7c0florian
509768109e5d3c18da127dd70f28454171c1eba7c0florian   clst("lower1",  "lower2",  'w');   // will compare equal
519768109e5d3c18da127dd70f28454171c1eba7c0florian
529768109e5d3c18da127dd70f28454171c1eba7c0florian   return 0;
539768109e5d3c18da127dd70f28454171c1eba7c0florian}
54