1#include <stdio.h>
2#include <ctype.h>
3#include "test.h"
4
5#define LOOPBACK "jo 0b	\n\t"
6
7typedef struct {
8   const char *str1;
9   const char *str2;
10   int cc;
11} clst_t;
12
13static clst_t
14do_clst(const char *__string1, const char *__string2, char __end)
15{
16   register char end asm ("0") = __end;
17   register const char *string1 asm ("2") = __string1;
18   register const char *string2 asm ("4") = __string2;
19
20   asm volatile( "0: clst 2,4\n\t"
21                 LOOPBACK
22                 :"+d" (string1), "+d" (string2) :"d" (end): "cc");
23
24   return (clst_t) { .str1 = string1, .str2 = string2, .cc = get_cc() };
25}
26
27void
28clst(const char *str1, const char *str2, int sentinel)
29{
30   clst_t res;
31
32   printf("comparing: %s with %s   sentinel = %d", str1, str2, sentinel);
33   if (isprint(sentinel))
34      printf(" (%c)", sentinel);
35   printf("\n");
36   res = do_clst(str1, str2, sentinel);
37   printf("str1 = %s\nstr2 = %s\ncc = %d\n", res.str1, res.str2, res.cc);
38   printf("\n");
39}
40
41int main(void)
42{
43   clst("lower123",  "lowerabc",  '\0');
44   clst("higher234", "higher123", '\0');
45   clst("equal",  "equal",  '\0');
46
47   clst("equal",  "equallong",  '\0');
48   clst("equallong",  "equal",  '\0');
49
50   clst("lower1",  "lower2",  'w');   // will compare equal
51
52   return 0;
53}
54