~bkerensa/ubuntu/raring/valgrind/merge-from-deb

« back to all changes in this revision

Viewing changes to none/tests/ppc64/jm-insns.c

  • Committer: Bazaar Package Importer
  • Author(s): Andrés Roldán
  • Date: 2008-06-13 02:31:40 UTC
  • mto: (1.4.1 upstream) (2.2.1 squeeze)
  • mto: This revision was merged to the branch mainline in revision 24.
  • Revision ID: james.westby@ubuntu.com-20080613023140-iwk33rz9rhvfkr96
Import upstream version 3.3.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
177
177
#endif // #ifndef __powerpc64__
178
178
 
179
179
 
 
180
#define ALLCR "cr0","cr1","cr2","cr3","cr4","cr5","cr6","cr7"
 
181
 
 
182
#define SET_CR(_arg) \
 
183
      __asm__ __volatile__ ("mtcr  %0" : : "b"(_arg) : ALLCR );
 
184
 
 
185
#define SET_XER(_arg) \
 
186
      __asm__ __volatile__ ("mtxer %0" : : "b"(_arg) : "xer" );
 
187
 
 
188
#define GET_CR(_lval) \
 
189
      __asm__ __volatile__ ("mfcr %0"  : "=b"(_lval) )
 
190
 
 
191
#define GET_XER(_lval) \
 
192
      __asm__ __volatile__ ("mfxer %0" : "=b"(_lval) )
 
193
 
 
194
#define GET_CR_XER(_lval_cr,_lval_xer) \
 
195
   do { GET_CR(_lval_cr); GET_XER(_lval_xer); } while (0)
 
196
 
 
197
#define SET_CR_ZERO \
 
198
      SET_CR(0)
 
199
 
 
200
#define SET_XER_ZERO \
 
201
      SET_XER(0)
 
202
 
 
203
#define SET_CR_XER_ZERO \
 
204
   do { SET_CR_ZERO; SET_XER_ZERO; } while (0)
 
205
 
 
206
#define SET_FPSCR_ZERO \
 
207
   do { double _d = 0.0; \
 
208
        __asm__ __volatile__ ("mtfsf 0xFF, %0" : : "f"(_d) ); \
 
209
   } while (0)
 
210
 
 
211
 
 
212
/* XXXX these must all be callee-save regs! */
180
213
register double f14 __asm__ ("f14");
181
214
register double f15 __asm__ ("f15");
182
215
register double f16 __asm__ ("f16");
183
216
register double f17 __asm__ ("f17");
184
 
register double f18 __asm__ ("f18");
185
217
register HWord_t r14 __asm__ ("r14");
186
218
register HWord_t r15 __asm__ ("r15");
187
219
register HWord_t r16 __asm__ ("r16");
188
220
register HWord_t r17 __asm__ ("r17");
189
 
register HWord_t r18 __asm__ ("r18");
190
221
 
191
222
#if defined (HAS_ALTIVEC)
192
223
#   include <altivec.h>
193
224
#endif
194
225
#include <assert.h>
195
226
#include <ctype.h>     // isspace
196
 
//#include <fcntl.h>
197
 
//#include <fenv.h>
198
 
//#include <math.h>
199
227
#include <stdio.h>
200
228
#include <stdlib.h>
201
229
#include <string.h>
3023
3051
    __asm__ __volatile__ ("lvx          17,14,15");
3024
3052
}
3025
3053
 
 
3054
static void test_lvxl (void)
 
3055
{
 
3056
    __asm__ __volatile__ ("lvxl         17,14,15");
 
3057
}
 
3058
 
3026
3059
static test_t tests_ald_ops_two[] = {
3027
3060
    { &test_lvebx           , "       lvebx", },
3028
3061
    { &test_lvehx           , "       lvehx", },
3029
3062
    { &test_lvewx           , "       lvewx", },
3030
3063
    { &test_lvx             , "         lvx", },
 
3064
    { &test_lvxl            , "        lvxl", },
3031
3065
    { NULL,                   NULL,           },
3032
3066
};
3033
3067
#endif /* defined (HAS_ALTIVEC) */
3053
3087
    __asm__ __volatile__ ("stvx         14,15,16");
3054
3088
}
3055
3089
 
 
3090
static void test_stvxl (void)
 
3091
{
 
3092
    __asm__ __volatile__ ("stvxl        14,15,16");
 
3093
}
 
3094
 
3056
3095
static test_t tests_ast_ops_three[] = {
3057
3096
    { &test_stvebx          , "      stvebx", },
3058
3097
    { &test_stvehx          , "      stvehx", },
3059
3098
    { &test_stvewx          , "      stvewx", },
3060
3099
    { &test_stvx            , "        stvx", },
 
3100
    { &test_stvxl           , "       stvxl", },
3061
3101
    { NULL,                   NULL,           },
3062
3102
};
3063
3103
#endif /* defined (HAS_ALTIVEC) */
4540
4580
                                 unused uint32_t test_flags)
4541
4581
{
4542
4582
   volatile HWord_t res;
4543
 
   volatile uint32_t flags, xer, tmpcr, tmpxer;
 
4583
   volatile uint32_t flags, xer;
4544
4584
   int i, j, k;
4545
4585
   
4546
4586
   for (i=0; i<nb_iargs; i++) {
4550
4590
            r15 = iargs[j];
4551
4591
            r16 = iargs[k];
4552
4592
 
4553
 
            /* Save flags */
4554
 
            __asm__ __volatile__ ("mfcr 18");
4555
 
            tmpcr = r18;
4556
 
            __asm__ __volatile__ ("mfxer 18");
4557
 
            tmpxer = r18;
4558
 
 
4559
 
            /* Set up flags for test */
4560
 
            r18 = 0;
4561
 
            __asm__ __volatile__ ("mtcr 18");
4562
 
            __asm__ __volatile__ ("mtxer 18");
 
4593
            SET_CR_XER_ZERO;
4563
4594
            (*func)();
4564
 
            __asm__ __volatile__ ("mfcr 18");
4565
 
            flags = r18;
4566
 
            __asm__ __volatile__ ("mfxer 18");
4567
 
            xer = r18;
 
4595
            GET_CR_XER(flags,xer);
4568
4596
            res = r17;
4569
4597
 
4570
 
            /* Restore flags */
4571
 
            r18 = tmpcr;
4572
 
            __asm__ __volatile__ ("mtcr 18");
4573
 
            r18 = tmpxer;
4574
 
            __asm__ __volatile__ ("mtxer 18");
4575
 
 
4576
4598
#ifndef __powerpc64__
4577
4599
            printf("%s %08x, %08x, %08x => %08x (%08x %08x)\n",
4578
4600
#else
4589
4611
                               uint32_t test_flags)
4590
4612
{
4591
4613
   volatile HWord_t res;
4592
 
   volatile uint32_t flags, xer, xer_orig, tmpcr, tmpxer;
 
4614
   volatile uint32_t flags, xer, xer_orig;
4593
4615
   int i, j, is_div, zap_hi32;
4594
4616
 
4595
4617
   // catches div, divwu, divo, divwu, divwuo, and . variants
4601
4623
 redo:
4602
4624
   for (i=0; i<nb_iargs; i++) {
4603
4625
      for (j=0; j<nb_iargs; j++) {
4604
 
         r14 = iargs[i];
4605
 
         r15 = iargs[j];
 
4626
 
4606
4627
         /* result of division by zero is implementation dependent.
4607
4628
            don't test it. */
4608
4629
         if (is_div && iargs[j] == 0)
4609
4630
            continue;
4610
4631
 
4611
 
         /* Save flags */
4612
 
         __asm__ __volatile__ ("mfcr 18");
4613
 
         tmpcr = r18;
4614
 
         __asm__ __volatile__ ("mfxer 18");
4615
 
         tmpxer = r18;
 
4632
         r14 = iargs[i];
 
4633
         r15 = iargs[j];
4616
4634
 
4617
 
         /* Set up flags for test */
4618
 
         r18 = 0;
4619
 
         __asm__ __volatile__ ("mtcr 18");
4620
 
         r18 = xer_orig;
4621
 
         __asm__ __volatile__ ("mtxer 18");
 
4635
         SET_XER(xer_orig);
 
4636
         SET_CR_ZERO;
4622
4637
         (*func)();
4623
 
         __asm__ __volatile__ ("mfcr 18");
4624
 
         flags = r18;
4625
 
         __asm__ __volatile__ ("mfxer 18");
4626
 
         xer = r18;
 
4638
         GET_CR_XER(flags,xer);
4627
4639
         res = r17;
4628
4640
 
4629
 
         /* Restore flags */
4630
 
         r18 = tmpcr;
4631
 
         __asm__ __volatile__ ("mtcr 18");
4632
 
         r18 = tmpxer;
4633
 
         __asm__ __volatile__ ("mtxer 18");
4634
 
 
4635
4641
#ifndef __powerpc64__
4636
4642
         printf("%s %08x, %08x => %08x (%08x %08x)\n",
4637
4643
#else
4652
4658
                               uint32_t test_flags)
4653
4659
{
4654
4660
   volatile HWord_t res;
4655
 
   volatile uint32_t flags, xer, xer_orig, tmpcr, tmpxer;
 
4661
   volatile uint32_t flags, xer, xer_orig;
4656
4662
   int i;
4657
4663
   
4658
4664
   xer_orig = 0x00000000;
4659
4665
 redo:
4660
4666
   for (i=0; i<nb_iargs; i++) {
4661
4667
      r14 = iargs[i];
4662
 
 
4663
 
      /* Save flags */
4664
 
      __asm__ __volatile__ ("mfcr 18");
4665
 
      tmpcr = r18;
4666
 
      __asm__ __volatile__ ("mfxer 18");
4667
 
      tmpxer = r18;
4668
 
 
4669
 
      /* Set up flags for test */
4670
 
      r18 = 0;
4671
 
      __asm__ __volatile__ ("mtcr 18");
4672
 
      r18 = xer_orig;
4673
 
      __asm__ __volatile__ ("mtxer 18");
 
4668
      SET_XER(xer_orig);
 
4669
      SET_CR_ZERO;
4674
4670
      (*func)();
4675
4671
      res = r17;
4676
 
      __asm__ __volatile__ ("mfcr 18");
4677
 
      flags = r18;
4678
 
      __asm__ __volatile__ ("mfxer 18");
4679
 
      xer = r18;
4680
 
 
4681
 
      /* Restore flags */
4682
 
      r18 = tmpcr;
4683
 
      __asm__ __volatile__ ("mtcr 18");
4684
 
      r18 = tmpxer;
4685
 
      __asm__ __volatile__ ("mtxer 18");
 
4672
      GET_CR_XER(flags,xer);
4686
4673
 
4687
4674
#ifndef __powerpc64__
4688
4675
      printf("%s %08x => %08x (%08x %08x)\n",
4768
4755
   volatile test_func_t func;
4769
4756
   uint32_t* func_buf = get_rwx_area();
4770
4757
   volatile HWord_t res;
4771
 
   volatile uint32_t flags, xer, tmpcr, tmpxer;
 
4758
   volatile uint32_t flags, xer;
4772
4759
   int i, j;
4773
4760
 
4774
4761
   for (i=0; i<nb_iargs; i++) {
4779
4766
 
4780
4767
         r14 = iargs[i];
4781
4768
 
4782
 
         /* Save flags */
4783
 
         __asm__ __volatile__ ("mfcr 18");
4784
 
         tmpcr = r18;
4785
 
         __asm__ __volatile__ ("mfxer 18");
4786
 
         tmpxer = r18;
4787
 
 
4788
 
         /* Set up flags for test */
4789
 
         r18 = 0;
4790
 
         __asm__ __volatile__ ("mtcr 18");
4791
 
         __asm__ __volatile__ ("mtxer 18");
 
4769
         SET_CR_XER_ZERO;
4792
4770
         (*func)();
4793
 
         __asm__ __volatile__ ("mfcr 18");
4794
 
         flags = r18;
4795
 
         __asm__ __volatile__ ("mfxer 18");
4796
 
         xer = r18;
 
4771
         GET_CR_XER(flags,xer);
4797
4772
         res = r17;
4798
4773
 
4799
 
         /* Restore flags */
4800
 
         r18 = tmpcr;
4801
 
         __asm__ __volatile__ ("mtcr 18");
4802
 
         r18 = tmpxer;
4803
 
         __asm__ __volatile__ ("mtxer 18");
4804
 
 
4805
4774
#ifndef __powerpc64__
4806
4775
         printf("%s %08x, %08x => %08x (%08x %08x)\n",
4807
4776
#else
4843
4812
   volatile test_func_t func;
4844
4813
   uint32_t* func_buf = get_rwx_area();
4845
4814
   volatile HWord_t res;
4846
 
   volatile uint32_t flags, xer, tmpcr, tmpxer;
 
4815
   volatile uint32_t flags, xer;
4847
4816
   int i, j, k, l, arg_step;
4848
4817
   
4849
4818
   arg_step = (arg_list_size == 0) ? 31 : 3;
4862
4831
 
4863
4832
               r14 = iargs[i];
4864
4833
 
4865
 
               /* Save flags */
4866
 
               __asm__ __volatile__ ("mfcr 18");
4867
 
               tmpcr = r18;
4868
 
               __asm__ __volatile__ ("mfxer 18");
4869
 
               tmpxer = r18;
4870
 
 
4871
 
               /* Set up flags for test */
4872
 
               r18 = 0;
4873
 
               __asm__ __volatile__ ("mtcr 18");
4874
 
               __asm__ __volatile__ ("mtxer 18");
 
4834
               SET_CR_XER_ZERO;
4875
4835
               (*func)();
4876
 
               __asm__ __volatile__ ("mfcr 18");
4877
 
               flags = r18;
4878
 
               __asm__ __volatile__ ("mfxer 18");
4879
 
               xer = r18;
 
4836
               GET_CR_XER(flags,xer);
4880
4837
               res = r17;
4881
4838
 
4882
 
               /* Restore flags */
4883
 
               r18 = tmpcr;
4884
 
               __asm__ __volatile__ ("mtcr 18");
4885
 
               r18 = tmpxer;
4886
 
               __asm__ __volatile__ ("mtxer 18");
4887
 
 
4888
4839
#ifndef __powerpc64__
4889
4840
               printf("%s %08x, %2d, %2d, %2d => %08x (%08x %08x)\n",
4890
4841
#else
4904
4855
   volatile test_func_t func;
4905
4856
   uint32_t* func_buf = get_rwx_area();
4906
4857
   volatile HWord_t res;
4907
 
   volatile uint32_t flags, xer, tmpcr, tmpxer;
 
4858
   volatile uint32_t flags, xer;
4908
4859
   int i, j, k, l, arg_step;
4909
4860
   
4910
4861
   arg_step = (arg_list_size == 0) ? 31 : 3;
4921
4872
               r14 = iargs[i];
4922
4873
               r15 = iargs[j];
4923
4874
 
4924
 
               /* Save flags */
4925
 
               __asm__ __volatile__ ("mfcr 18");
4926
 
               tmpcr = r18;
4927
 
               __asm__ __volatile__ ("mfxer 18");
4928
 
               tmpxer = r18;
4929
 
 
4930
 
               /* Set up flags for test */
4931
 
               r18 = 0;
4932
 
               __asm__ __volatile__ ("mtcr 18");
4933
 
               __asm__ __volatile__ ("mtxer 18");
 
4875
               SET_CR_XER_ZERO;
4934
4876
               (*func)();
4935
 
               __asm__ __volatile__ ("mfcr 18");
4936
 
               flags = r18;
4937
 
               __asm__ __volatile__ ("mfxer 18");
4938
 
               xer = r18;
 
4877
               GET_CR_XER(flags,xer);
4939
4878
               res = r17;
4940
4879
 
4941
 
               /* Restore flags */
4942
 
               r18 = tmpcr;
4943
 
               __asm__ __volatile__ ("mtcr 18");
4944
 
               r18 = tmpxer;
4945
 
               __asm__ __volatile__ ("mtxer 18");
4946
 
 
4947
4880
#ifndef __powerpc64__
4948
4881
               printf("%s %08x, %08x, %2d, %2d => %08x (%08x %08x)\n",
4949
4882
#else
4963
4896
   volatile test_func_t func;
4964
4897
   uint32_t* func_buf = get_rwx_area();
4965
4898
   volatile HWord_t res;
4966
 
   volatile uint32_t flags, xer, tmpcr, tmpxer;
 
4899
   volatile uint32_t flags, xer;
4967
4900
   int i, j, arg_step;
4968
4901
   
4969
4902
   arg_step = (arg_list_size == 0) ? 31 : 1;
4976
4909
 
4977
4910
         r14 = iargs[i];
4978
4911
 
4979
 
         /* Save flags */
4980
 
         __asm__ __volatile__ ("mfcr 18");
4981
 
         tmpcr = r18;
4982
 
         __asm__ __volatile__ ("mfxer 18");
4983
 
         tmpxer = r18;
4984
 
 
4985
 
         /* Set up flags for test */
4986
 
         r18 = 0;
4987
 
         __asm__ __volatile__ ("mtcr 18");
4988
 
         __asm__ __volatile__ ("mtxer 18");
 
4912
         SET_CR_XER_ZERO;
4989
4913
         (*func)();
4990
 
         __asm__ __volatile__ ("mfcr 18");
4991
 
         flags = r18;
4992
 
         __asm__ __volatile__ ("mfxer 18");
4993
 
         xer = r18;
 
4914
         GET_CR_XER(flags,xer);
4994
4915
         res = r17;
4995
4916
 
4996
 
         /* Restore flags */
4997
 
         r18 = tmpcr;
4998
 
         __asm__ __volatile__ ("mtcr 18");
4999
 
         r18 = tmpxer;
5000
 
         __asm__ __volatile__ ("mtxer 18");
5001
 
 
5002
4917
#ifndef __powerpc64__
5003
4918
         printf("%s %08x, %2d => %08x (%08x %08x)\n",
5004
4919
#else
5015
4930
{
5016
4931
   volatile test_func_t func;
5017
4932
   uint32_t* func_buf = get_rwx_area();
5018
 
   volatile uint32_t flags, xer, tmpcr, tmpxer;
 
4933
   volatile uint32_t flags, xer;
5019
4934
   int i, j, k, arg_step;
5020
4935
   
5021
4936
   arg_step = (arg_list_size == 0) ? 7 : 1;
5030
4945
 
5031
4946
            r14 = iargs[i];
5032
4947
 
5033
 
            /* Save flags */
5034
 
            __asm__ __volatile__ ("mfcr 18");
5035
 
            tmpcr = r18;
5036
 
            __asm__ __volatile__ ("mfxer 18");
5037
 
            tmpxer = r18;
5038
 
 
5039
 
            /* Set up flags for test */
5040
 
            r18 = 0;
5041
 
            __asm__ __volatile__ ("mtcr 14");
5042
 
            __asm__ __volatile__ ("mtxer 18");
 
4948
            SET_CR(r14);
 
4949
            SET_XER_ZERO;
5043
4950
            (*func)();
5044
 
            __asm__ __volatile__ ("mfcr 18");
5045
 
            flags = r18;
5046
 
            __asm__ __volatile__ ("mfxer 18");
5047
 
            xer = r18;
5048
 
 
5049
 
            /* Restore flags */
5050
 
            r18 = tmpcr;
5051
 
            __asm__ __volatile__ ("mtcr 18");
5052
 
            r18 = tmpxer;
5053
 
            __asm__ __volatile__ ("mtxer 18");
 
4951
            GET_CR_XER(flags,xer);
5054
4952
 
5055
4953
#ifndef __powerpc64__
5056
4954
            printf("%s %d, %d (%08x) => (%08x %08x)\n",
5064
4962
   }
5065
4963
}
5066
4964
 
5067
 
#if 0
5068
 
static void mcrfs_cb (const char* name, test_func_t func,
5069
 
                      unused uint32_t test_flags)
5070
 
{}
5071
 
#endif
5072
 
 
5073
 
 
5074
4965
static void mcrxr_cb (const char* name, test_func_t func_IN,
5075
4966
                      unused uint32_t test_flags)
5076
4967
{
5077
4968
   volatile test_func_t func;
5078
4969
   uint32_t* func_buf = get_rwx_area();
5079
 
   volatile uint32_t flags, xer, tmpcr, tmpxer;
 
4970
   volatile uint32_t flags, xer;
5080
4971
   int i, j, k, arg_step;
5081
4972
   
5082
4973
   arg_step = 1; //(arg_list_size == 0) ? 7 : 1;
5090
4981
 
5091
4982
         r14 = j;
5092
4983
 
5093
 
         /* Save flags */
5094
 
         __asm__ __volatile__ ("mfcr 18");
5095
 
         tmpcr = r18;
5096
 
         __asm__ __volatile__ ("mfxer 18");
5097
 
         tmpxer = r18;
5098
 
 
5099
 
         /* Set up flags for test */
5100
 
         r18 = 0;
5101
 
         __asm__ __volatile__ ("mtcr 18");
5102
 
         __asm__ __volatile__ ("mtxer 14");
 
4984
         SET_CR_ZERO;
 
4985
         SET_XER(r14);
5103
4986
         (*func)();
5104
 
         __asm__ __volatile__ ("mfcr 18");
5105
 
         flags = r18;
5106
 
         __asm__ __volatile__ ("mfxer 18");
5107
 
         xer = r18;
5108
 
 
5109
 
         /* Restore flags */
5110
 
         r18 = tmpcr;
5111
 
         __asm__ __volatile__ ("mtcr 18");
5112
 
         r18 = tmpxer;
5113
 
         __asm__ __volatile__ ("mtxer 18");
 
4987
         GET_CR_XER(flags,xer);
5114
4988
 
5115
4989
         printf("%s %d (%08x) => (%08x %08x)\n",
5116
4990
                name, k, j, flags, xer);
5123
4997
                     unused uint32_t test_flags)
5124
4998
{
5125
4999
   volatile HWord_t res;
5126
 
   volatile uint32_t flags, xer, tmpcr, tmpxer;
 
5000
   volatile uint32_t flags, xer;
5127
5001
   int i;
5128
5002
   
5129
5003
   for (i=0; i<nb_iargs; i++) {
5130
5004
      r14 = iargs[i];
5131
5005
 
5132
 
      /* Save flags */
5133
 
      __asm__ __volatile__ ("mfcr 18");
5134
 
      tmpcr = r18;
5135
 
      __asm__ __volatile__ ("mfxer 18");
5136
 
      tmpxer = r18;
5137
 
 
5138
5006
      /* Set up flags for test */
5139
 
      r18 = 0;
5140
 
      __asm__ __volatile__ ("mtcr 14");
5141
 
      __asm__ __volatile__ ("mtxer 18");
 
5007
      SET_CR(r14);
 
5008
      SET_XER_ZERO;
5142
5009
      (*func)();
5143
 
      __asm__ __volatile__ ("mfcr 18");
5144
 
      flags = r18;
5145
 
      __asm__ __volatile__ ("mfxer 18");
5146
 
      xer = r18;
 
5010
      GET_CR_XER(flags,xer);
5147
5011
      res = r17;
5148
5012
 
5149
 
      /* Restore flags */
5150
 
      r18 = tmpcr;
5151
 
      __asm__ __volatile__ ("mtcr 18");
5152
 
      r18 = tmpxer;
5153
 
      __asm__ __volatile__ ("mtxer 18");
5154
 
 
5155
5013
#ifndef __powerpc64__
5156
5014
      printf("%s (%08x) => %08x (%08x %08x)\n",
5157
5015
#else
5176
5034
      __asm__ __volatile__(
5177
5035
         "mtxer %1\n"
5178
5036
         "\tmfxer %0"
5179
 
         : /*out*/"=r"(res) : /*in*/"r"(j) : /*trashed*/"xer" 
 
5037
         : /*out*/"=b"(res) : /*in*/"b"(j) : /*trashed*/"xer" 
5180
5038
      );
5181
5039
      res &= 0xE000007F; /* rest of the bits are undefined */
5182
5040
 
5194
5052
      __asm__ __volatile__(
5195
5053
         "mtlr %1\n"
5196
5054
         "\tmflr %0"
5197
 
         : /*out*/"=r"(res) : /*in*/"r"(j) : /*trashed*/"lr" 
 
5055
         : /*out*/"=b"(res) : /*in*/"b"(j) : /*trashed*/"lr" 
5198
5056
      );
5199
5057
 
5200
5058
#ifndef __powerpc64__
5211
5069
      __asm__ __volatile__(
5212
5070
         "mtctr %1\n"
5213
5071
         "\tmfctr %0"
5214
 
         : /*out*/"=r"(res) : /*in*/"r"(j) : /*trashed*/"ctr" 
 
5072
         : /*out*/"=b"(res) : /*in*/"b"(j) : /*trashed*/"ctr" 
5215
5073
      );
5216
5074
 
5217
5075
#ifndef __powerpc64__
5221
5079
#endif
5222
5080
             name, j, res);
5223
5081
   }
5224
 
 
5225
 
#if 0
5226
 
   // mfxer
5227
 
   j = 1;
5228
 
   for (k=0; k<nb_iargs; k++) {
5229
 
      r14 = iargs[k];
5230
 
 
5231
 
      /* Save flags */
5232
 
      __asm__ __volatile__ ("mfcr 18");
5233
 
      tmpcr = r18;
5234
 
      __asm__ __volatile__ ("mfxer 18");
5235
 
      tmpxer = r18;
5236
 
 
5237
 
      /* Set up flags for test */
5238
 
      r18 = 0;
5239
 
      // Only valid bits of xer: 0xE000007F
5240
 
      __asm__ __volatile__ ("lis  15,0xE000");
5241
 
      __asm__ __volatile__ ("addi 15,15,0x007F");
5242
 
      __asm__ __volatile__ ("and  16,15,14");
5243
 
      
5244
 
      __asm__ __volatile__ ("mtcr  18");
5245
 
      __asm__ __volatile__ ("mtxer 16");
5246
 
      __asm__ __volatile__ ("mtlr  18");
5247
 
      __asm__ __volatile__ ("mtctr 18");
5248
 
      
5249
 
      __asm__ __volatile__ ("mfspr 17, 1");   // func()
5250
 
      
5251
 
      __asm__ __volatile__ ("mfxer 18");
5252
 
      xer = r18;
5253
 
      __asm__ __volatile__ ("mfcr  18");
5254
 
      flags = r18;
5255
 
      __asm__ __volatile__ ("mflr  18");
5256
 
      lr = r18;
5257
 
      __asm__ __volatile__ ("mfctr 18");
5258
 
      ctr = r18;
5259
 
      res = r17;
5260
 
 
5261
 
      /* Restore flags */
5262
 
      r18 = tmpcr;
5263
 
      __asm__ __volatile__ ("mtcr 18");
5264
 
      r18 = tmpxer;
5265
 
      __asm__ __volatile__ ("mtxer 18");
5266
 
 
5267
 
      printf("%s %d (%08x) => %08x (%08x %08x, %08x, %08x)\n",
5268
 
             name, j, iargs[k], res, flags, xer, lr, ctr);
5269
 
   }
5270
 
   if (verbose) printf("\n");
5271
 
   
5272
 
   // mflr
5273
 
   j = 8;
5274
 
   for (k=0; k<nb_iargs; k++) {
5275
 
      r14 = iargs[k];
5276
 
 
5277
 
      /* Save flags */
5278
 
      __asm__ __volatile__ ("mfcr 18");
5279
 
      tmpcr = r18;
5280
 
      __asm__ __volatile__ ("mfxer 18");
5281
 
      tmpxer = r18;
5282
 
 
5283
 
      /* Set up flags for test */
5284
 
      r18 = 0;
5285
 
      __asm__ __volatile__ ("mtcr  18");
5286
 
      __asm__ __volatile__ ("mtlr  14");
5287
 
      __asm__ __volatile__ ("mtctr 18");
5288
 
      __asm__ __volatile__ ("mtxer 18");
5289
 
 
5290
 
      __asm__ __volatile__ ("mfspr 17, 8");   // func()
5291
 
      
5292
 
      __asm__ __volatile__ ("mfxer 18");
5293
 
      xer = r18;
5294
 
      __asm__ __volatile__ ("mfcr  18");
5295
 
      flags = r18;
5296
 
      __asm__ __volatile__ ("mflr  18");
5297
 
      lr = r18;
5298
 
      __asm__ __volatile__ ("mfctr 18");
5299
 
      ctr = r18;
5300
 
      res = r17;
5301
 
 
5302
 
      /* Restore flags */
5303
 
      r18 = tmpcr;
5304
 
      __asm__ __volatile__ ("mtcr 18");
5305
 
      r18 = tmpxer;
5306
 
      __asm__ __volatile__ ("mtxer 18");
5307
 
 
5308
 
      printf("%s %d (%08x) => %08x (%08x %08x, %08x, %08x)\n",
5309
 
             name, j, iargs[k], res, flags, xer, lr, ctr);
5310
 
   }
5311
 
   if (verbose) printf("\n");
5312
 
 
5313
 
   // mfctr
5314
 
   j = 9;
5315
 
   for (k=0; k<nb_iargs; k++) {
5316
 
      r14 = iargs[k];
5317
 
 
5318
 
      /* Save flags */
5319
 
      __asm__ __volatile__ ("mfcr 18");
5320
 
      tmpcr = r18;
5321
 
      __asm__ __volatile__ ("mfxer 18");
5322
 
      tmpxer = r18;
5323
 
 
5324
 
      /* Set up flags for test */
5325
 
      r18 = 0;
5326
 
      __asm__ __volatile__ ("mtcr  18");
5327
 
      __asm__ __volatile__ ("mtctr 14");
5328
 
      __asm__ __volatile__ ("mtxer 18");
5329
 
      __asm__ __volatile__ ("mtlr  18");
5330
 
      
5331
 
      __asm__ __volatile__ ("mfspr 17, 9");   // func()
5332
 
      
5333
 
      __asm__ __volatile__ ("mfcr  18");
5334
 
      flags = r18;
5335
 
      __asm__ __volatile__ ("mfxer 18");
5336
 
      xer = r18;
5337
 
      __asm__ __volatile__ ("mflr  18");
5338
 
      lr = r18;
5339
 
      __asm__ __volatile__ ("mfctr 18");
5340
 
      ctr = r18;
5341
 
      res = r17;
5342
 
 
5343
 
      /* Restore flags */
5344
 
      r18 = tmpcr;
5345
 
      __asm__ __volatile__ ("mtcr 18");
5346
 
      r18 = tmpxer;
5347
 
      __asm__ __volatile__ ("mtxer 18");
5348
 
 
5349
 
      printf("%s %d (%08x) => %08x (%08x %08x, %08x, %08x)\n",
5350
 
             name, j, iargs[k], res, flags, xer, lr, ctr);
5351
 
   }
5352
 
#endif
5353
 
}
5354
 
 
5355
 
#if 0
5356
 
static void mftb_cb (const char* name, test_func_t func,
5357
 
                     unused uint32_t test_flags)
5358
 
{
5359
 
// How to test this?
5360
 
// 1) TBU won't change for a while
5361
 
// 2) TBL will have changed every loop iter
5362
 
 
5363
 
   volatile HWord_t res;
5364
 
   volatile uint32_t flags, xer, tmpcr, tmpxer;
5365
 
   int i, j;
5366
 
   
5367
 
   i = 269;
5368
 
   for (j=0; j<16; j++) {
5369
 
      /* Save flags */
5370
 
      __asm__ __volatile__ ("mfcr 18");
5371
 
      tmpcr = r18;
5372
 
      __asm__ __volatile__ ("mfxer 18");
5373
 
      tmpxer = r18;
5374
 
 
5375
 
      /* Set up flags for test */
5376
 
      r18 = 0;
5377
 
      __asm__ __volatile__ ("mtcr 18");
5378
 
      __asm__ __volatile__ ("mtxer 18");
5379
 
      
5380
 
      __asm__ __volatile__ ("mftb 17, 269");  // func
5381
 
      
5382
 
      __asm__ __volatile__ ("mfcr 18");
5383
 
      flags = r18;
5384
 
      __asm__ __volatile__ ("mfxer 18");
5385
 
      xer = r18;
5386
 
      res = r17;
5387
 
 
5388
 
      /* Restore flags */
5389
 
      r18 = tmpcr;
5390
 
      __asm__ __volatile__ ("mtcr 18");
5391
 
      r18 = tmpxer;
5392
 
      __asm__ __volatile__ ("mtxer 18");
5393
 
 
5394
 
      printf("%s %d => %08x (%08x %08x)\n",
5395
 
             name, i, res, flags, xer);
5396
 
   }
5397
 
   if (verbose) printf("\n");
5398
 
   
5399
 
   i = 268;
5400
 
   for (j=0; j<16; j++) {
5401
 
      /* Save flags */
5402
 
      __asm__ __volatile__ ("mfcr 18");
5403
 
      tmpcr = r18;
5404
 
      __asm__ __volatile__ ("mfxer 18");
5405
 
      tmpxer = r18;
5406
 
 
5407
 
      /* Set up flags for test */
5408
 
      r18 = 0;
5409
 
      __asm__ __volatile__ ("mtcr 18");
5410
 
      __asm__ __volatile__ ("mtxer 18");
5411
 
      
5412
 
      __asm__ __volatile__ ("mftb 17, 268");  // func
5413
 
      
5414
 
      __asm__ __volatile__ ("mfcr 18");
5415
 
      flags = r18;
5416
 
      __asm__ __volatile__ ("mfxer 18");
5417
 
      xer = r18;
5418
 
      res = r17;
5419
 
 
5420
 
      /* Restore flags */
5421
 
      r18 = tmpcr;
5422
 
      __asm__ __volatile__ ("mtcr 18");
5423
 
      r18 = tmpxer;
5424
 
      __asm__ __volatile__ ("mtxer 18");
5425
 
 
5426
 
      printf("%s %d => %08x (%08x %08x)\n",
5427
 
             name, i, res, flags, xer);
5428
 
   }
5429
 
}
5430
 
#endif
 
5082
}
5431
5083
 
5432
5084
static void mtcrf_cb (const char* name, test_func_t func_IN,
5433
5085
                      unused uint32_t test_flags)
5434
5086
{
5435
5087
   volatile test_func_t func;
5436
5088
   uint32_t* func_buf = get_rwx_area();
5437
 
   volatile uint32_t flags, xer, tmpcr, tmpxer;
 
5089
   volatile uint32_t flags, xer;
5438
5090
   int i, j, arg_step;
5439
5091
   
5440
5092
   arg_step = (arg_list_size == 0) ? 99 : 1;
5447
5099
 
5448
5100
         r14 = iargs[i];
5449
5101
 
5450
 
         /* Save flags */
5451
 
         __asm__ __volatile__ ("mfcr 18");
5452
 
         tmpcr = r18;
5453
 
         __asm__ __volatile__ ("mfxer 18");
5454
 
         tmpxer = r18;
5455
 
 
5456
 
         /* Set up flags for test */
5457
 
         r18 = 0;
5458
 
         __asm__ __volatile__ ("mtcr 18");
5459
 
         __asm__ __volatile__ ("mtxer 18");
 
5102
         SET_CR_XER_ZERO;
5460
5103
         (*func)();
5461
 
         __asm__ __volatile__ ("mfcr 18");
5462
 
         flags = r18;
5463
 
         __asm__ __volatile__ ("mfxer 18");
5464
 
         xer = r18;
5465
 
 
5466
 
         /* Restore flags */
5467
 
         r18 = tmpcr;
5468
 
         __asm__ __volatile__ ("mtcr 18");
5469
 
         r18 = tmpxer;
5470
 
         __asm__ __volatile__ ("mtxer 18");
 
5104
         GET_CR_XER(flags,xer);
5471
5105
 
5472
5106
#ifndef __powerpc64__
5473
5107
         printf("%s %3d, %08x => (%08x %08x)\n",
5484
5118
static void mtspr_cb (const char* name, test_func_t func,
5485
5119
                      unused uint32_t test_flags)
5486
5120
{
5487
 
#if 0
5488
 
   volatile HWord_t ctr, lr;
5489
 
   volatile uint32_t flags, xer, tmpcr, tmpxer;
5490
 
   int j, k;
5491
 
   func = func; // just to stop compiler complaining
5492
 
   
5493
 
   // mtxer
5494
 
   j = 1;
5495
 
   for (k=0; k<nb_iargs; k++) {
5496
 
      r14 = iargs[k];
5497
 
 
5498
 
      /* Save flags */
5499
 
      __asm__ __volatile__ ("mfcr 18");
5500
 
      tmpcr = r18;
5501
 
      __asm__ __volatile__ ("mfxer 18");
5502
 
      tmpxer = r18;
5503
 
 
5504
 
      /* Set up flags for test */
5505
 
      r18 = 0;
5506
 
      
5507
 
      // Only valid bits of xer: 0xE000007F
5508
 
      // VEX masks these (maybe it shouldn't?), so let's do it first:
5509
 
      __asm__ __volatile__ ("lis  15,0xE000");
5510
 
      __asm__ __volatile__ ("addi 15,15,0x007F");
5511
 
      __asm__ __volatile__ ("and  16,15,14");
5512
 
      
5513
 
      __asm__ __volatile__ ("mtcr  18");
5514
 
      __asm__ __volatile__ ("mtxer 18");
5515
 
      __asm__ __volatile__ ("mtlr  18");
5516
 
      __asm__ __volatile__ ("mtctr 18");
5517
 
      
5518
 
      __asm__ __volatile__ ("mtxer 16");   // func()
5519
 
      
5520
 
      __asm__ __volatile__ ("mfxer 18");
5521
 
      xer = r18;
5522
 
      __asm__ __volatile__ ("mfcr  18");
5523
 
      flags = r18;
5524
 
      __asm__ __volatile__ ("mflr  18");
5525
 
      lr = r18;
5526
 
      __asm__ __volatile__ ("mfctr 18");
5527
 
      ctr = r18;
5528
 
 
5529
 
      /* Restore flags */
5530
 
      r18 = tmpcr;
5531
 
      __asm__ __volatile__ ("mtcr 18");
5532
 
      r18 = tmpxer;
5533
 
      __asm__ __volatile__ ("mtxer 18");
5534
 
 
5535
 
#ifndef __powerpc64__
5536
 
      printf("%s %d, %08x => (%08x %08x, %08x, %08x)\n",
5537
 
#else
5538
 
      printf("%s %d, %016lx => (%08x %08x, %016lx, %016lx)\n",
5539
 
#endif
5540
 
             name, j, iargs[k], flags, xer, lr, ctr);
5541
 
   }
5542
 
   if (verbose) printf("\n");
5543
 
   
5544
 
   // mtlr
5545
 
   j = 8;
5546
 
   for (k=0; k<nb_iargs; k++) {
5547
 
      r14 = iargs[k];
5548
 
 
5549
 
      /* Save flags */
5550
 
      __asm__ __volatile__ ("mfcr 18");
5551
 
      tmpcr = r18;
5552
 
      __asm__ __volatile__ ("mfxer 18");
5553
 
      tmpxer = r18;
5554
 
 
5555
 
      /* Set up flags for test */
5556
 
      r18 = 0x0;
5557
 
      __asm__ __volatile__ ("mtcr  18");
5558
 
      __asm__ __volatile__ ("mtlr  18");
5559
 
      __asm__ __volatile__ ("mtctr 18");
5560
 
      __asm__ __volatile__ ("mtxer 18");
5561
 
      
5562
 
      __asm__ __volatile__ ("mtlr  14");   // func()
5563
 
      
5564
 
      __asm__ __volatile__ ("mfxer 18");
5565
 
      xer = r18;
5566
 
      __asm__ __volatile__ ("mfcr  18");
5567
 
      flags = r18;
5568
 
      __asm__ __volatile__ ("mflr  18");
5569
 
      lr = r18;
5570
 
      __asm__ __volatile__ ("mfctr 17");  // CAB: if 18, bashes lr - bad gcc opt?
5571
 
      ctr = r17;
5572
 
 
5573
 
      /* Restore flags */
5574
 
      r18 = tmpcr;
5575
 
      __asm__ __volatile__ ("mtcr 18");
5576
 
      r18 = tmpxer;
5577
 
      __asm__ __volatile__ ("mtxer 18");
5578
 
 
5579
 
#ifndef __powerpc64__
5580
 
      printf("%s %d, %08x => (%08x %08x, %08x, %08x)\n",
5581
 
#else
5582
 
      printf("%s %d, %016lx => (%08x %08x, %016lx, %016lx)\n",
5583
 
#endif
5584
 
             name, j, iargs[k], flags, xer, lr, ctr);
5585
 
   }
5586
 
   if (verbose) printf("\n");
5587
 
   
5588
 
   // mtctr
5589
 
   j = 9;
5590
 
   for (k=0; k<nb_iargs; k++) {
5591
 
      r14 = iargs[k];
5592
 
 
5593
 
      /* Save flags */
5594
 
      __asm__ __volatile__ ("mfcr 18");
5595
 
      tmpcr = r18;
5596
 
      __asm__ __volatile__ ("mfxer 18");
5597
 
      tmpxer = r18;
5598
 
 
5599
 
      /* Set up flags for test */
5600
 
      r18 = 0;
5601
 
      __asm__ __volatile__ ("mtcr  18");
5602
 
      __asm__ __volatile__ ("mtctr 18");
5603
 
      __asm__ __volatile__ ("mtxer 18");
5604
 
      __asm__ __volatile__ ("mtlr  18");
5605
 
      
5606
 
      __asm__ __volatile__ ("mtctr 14");   // func()
5607
 
      
5608
 
      __asm__ __volatile__ ("mfxer 18");
5609
 
      xer = r18;
5610
 
      __asm__ __volatile__ ("mfcr  18");
5611
 
      flags = r18;
5612
 
      __asm__ __volatile__ ("mflr  18");
5613
 
      lr = r18;
5614
 
      __asm__ __volatile__ ("mfctr 17");
5615
 
      ctr = r17;
5616
 
 
5617
 
      /* Restore flags */
5618
 
      r18 = tmpcr;
5619
 
      __asm__ __volatile__ ("mtcr 18");
5620
 
      r18 = tmpxer;
5621
 
      __asm__ __volatile__ ("mtxer 18");
5622
 
 
5623
 
#ifndef __powerpc64__
5624
 
      printf("%s %d, %08x => (%08x %08x, %08x, %08x)\n",
5625
 
#else
5626
 
      printf("%s %d, %016lx => (%08x %08x, %016lx, %016lx)\n",
5627
 
#endif
5628
 
             name, j, iargs[k], flags, xer, lr, ctr);
5629
 
   }
5630
 
#endif
5631
5121
}
5632
5122
 
5633
5123
#ifdef __powerpc64__
5637
5127
   volatile test_func_t func;
5638
5128
   uint32_t* func_buf = get_rwx_area();
5639
5129
   volatile HWord_t res;
5640
 
   volatile uint32_t flags, xer, tmpcr, tmpxer;
 
5130
   volatile uint32_t flags, xer;
5641
5131
   int i, j, k, arg_step;
5642
5132
   
5643
5133
   arg_step = (arg_list_size == 0) ? 7 : 3;
5652
5142
            r14 = iargs[i];
5653
5143
            r15 = iargs[j];
5654
5144
 
5655
 
            /* Save flags */
5656
 
            __asm__ __volatile__ ("mfcr 18");
5657
 
            tmpcr = r18;
5658
 
            __asm__ __volatile__ ("mfxer 18");
5659
 
            tmpxer = r18;
5660
 
 
5661
 
            /* Set up flags for test */
5662
 
            r18 = 0;
5663
 
            __asm__ __volatile__ ("mtcr 18");
5664
 
            __asm__ __volatile__ ("mtxer 18");
 
5145
            SET_CR_XER_ZERO;
5665
5146
            (*func)();
5666
 
            __asm__ __volatile__ ("mfcr 18");
5667
 
            flags = r18;
5668
 
            __asm__ __volatile__ ("mfxer 18");
5669
 
            xer = r18;
 
5147
            GET_CR_XER(flags,xer);
5670
5148
            res = r17;
5671
5149
 
5672
 
            /* Restore flags */
5673
 
            r18 = tmpcr;
5674
 
            __asm__ __volatile__ ("mtcr 18");
5675
 
            r18 = tmpxer;
5676
 
            __asm__ __volatile__ ("mtxer 18");
5677
 
 
5678
5150
            printf("%s %016lx, %016lx, %2d => %016lx (%08x %08x)\n",
5679
5151
                   name, iargs[i], iargs[j], k, res, flags, xer);
5680
5152
         }
5689
5161
   volatile test_func_t func;
5690
5162
   uint32_t* func_buf = get_rwx_area();
5691
5163
   volatile HWord_t res;
5692
 
   volatile uint32_t flags, xer, tmpcr, tmpxer;
 
5164
   volatile uint32_t flags, xer;
5693
5165
   int i, j, k, arg_step;
5694
5166
   
5695
5167
   arg_step = (arg_list_size == 0) ? 7 : 3;
5705
5177
            
5706
5178
            r14 = iargs[i];
5707
5179
 
5708
 
            /* Save flags */
5709
 
            __asm__ __volatile__ ("mfcr 18");
5710
 
            tmpcr = r18;
5711
 
            __asm__ __volatile__ ("mfxer 18");
5712
 
            tmpxer = r18;
5713
 
 
5714
 
            /* Set up flags for test */
5715
 
            r18 = 0;
5716
 
            __asm__ __volatile__ ("mtcr 18");
5717
 
            __asm__ __volatile__ ("mtxer 18");
 
5180
            SET_CR_XER_ZERO;
5718
5181
            (*func)();
5719
 
            __asm__ __volatile__ ("mfcr 18");
5720
 
            flags = r18;
5721
 
            __asm__ __volatile__ ("mfxer 18");
5722
 
            xer = r18;
 
5182
            GET_CR_XER(flags,xer);
5723
5183
            res = r17;
5724
5184
 
5725
 
            /* Restore flags */
5726
 
            r18 = tmpcr;
5727
 
            __asm__ __volatile__ ("mtcr 18");
5728
 
            r18 = tmpxer;
5729
 
            __asm__ __volatile__ ("mtxer 18");
5730
 
 
5731
5185
            printf("%s %016lx, %2d, %2d => %016lx (%08x %08x)\n",
5732
5186
                   name, iargs[i], j, k, res, flags, xer);
5733
5187
         }
5742
5196
   volatile test_func_t func;
5743
5197
   uint32_t* func_buf = get_rwx_area();
5744
5198
   volatile HWord_t res;
5745
 
   volatile uint32_t flags, xer, tmpcr, tmpxer;
 
5199
   volatile uint32_t flags, xer;
5746
5200
   int i, j, arg_step;
5747
5201
   
5748
5202
   arg_step = (arg_list_size == 0) ? 7 : 3;
5756
5210
            
5757
5211
         r14 = iargs[i];
5758
5212
 
5759
 
         /* Save flags */
5760
 
         __asm__ __volatile__ ("mfcr 18");
5761
 
         tmpcr = r18;
5762
 
         __asm__ __volatile__ ("mfxer 18");
5763
 
         tmpxer = r18;
5764
 
 
5765
 
         /* Set up flags for test */
5766
 
         r18 = 0;
5767
 
         __asm__ __volatile__ ("mtcr 18");
5768
 
         __asm__ __volatile__ ("mtxer 18");
 
5213
         SET_CR_XER_ZERO;
5769
5214
         (*func)();
5770
 
         __asm__ __volatile__ ("mfcr 18");
5771
 
         flags = r18;
5772
 
         __asm__ __volatile__ ("mfxer 18");
5773
 
         xer = r18;
 
5215
         GET_CR_XER(flags,xer);
5774
5216
         res = r17;
5775
5217
 
5776
 
         /* Restore flags */
5777
 
         r18 = tmpcr;
5778
 
         __asm__ __volatile__ ("mtcr 18");
5779
 
         r18 = tmpxer;
5780
 
         __asm__ __volatile__ ("mtxer 18");
5781
 
 
5782
5218
         printf("%s %016lx, %2d => %016lx (%08x %08x)\n",
5783
5219
                name, iargs[i], j, res, flags, xer);
5784
5220
      }
5965
5401
   volatile test_func_t func;
5966
5402
   uint32_t* func_buf = get_rwx_area();
5967
5403
   volatile HWord_t res, base;
5968
 
   volatile uint32_t flags, xer, tmpcr, tmpxer;
 
5404
   volatile uint32_t flags, xer;
5969
5405
   int i, offs, is_lwa=0;
5970
5406
 
5971
5407
#ifdef __powerpc64__
5986
5422
 
5987
5423
      r14 = base;
5988
5424
 
5989
 
      /* Save flags */
5990
 
      __asm__ __volatile__ ("mfcr 18");
5991
 
      tmpcr = r18;
5992
 
      __asm__ __volatile__ ("mfxer 18");
5993
 
      tmpxer = r18;
5994
 
      
5995
 
      /* Set up flags for test */
5996
 
      r18 = 0;
5997
 
      __asm__ __volatile__ ("mtcr 18");
5998
 
      __asm__ __volatile__ ("mtxer 18");
 
5425
      SET_CR_XER_ZERO;
5999
5426
      (*func)();
6000
 
      __asm__ __volatile__ ("mfcr 18");
6001
 
      flags = r18;
6002
 
      __asm__ __volatile__ ("mfxer 18");
6003
 
      xer = r18;
 
5427
      GET_CR_XER(flags,xer);
6004
5428
      res = r17;
6005
5429
 
6006
 
      /* Restore flags */
6007
 
      r18 = tmpcr;
6008
 
      __asm__ __volatile__ ("mtcr 18");
6009
 
      r18 = tmpxer;
6010
 
      __asm__ __volatile__ ("mtxer 18");
6011
 
 
6012
5430
#ifndef __powerpc64__
6013
5431
      printf("%s %2d, (%08x) => %08x, %2d (%08x %08x)\n",
6014
5432
#else
6029
5447
 
6030
5448
      r14 = base;
6031
5449
 
6032
 
      /* Save flags */
6033
 
      __asm__ __volatile__ ("mfcr 18");
6034
 
      tmpcr = r18;
6035
 
      __asm__ __volatile__ ("mfxer 18");
6036
 
      tmpxer = r18;
6037
 
      
6038
 
      /* Set up flags for test */
6039
 
      r18 = 0;
6040
 
      __asm__ __volatile__ ("mtcr 18");
6041
 
      __asm__ __volatile__ ("mtxer 18");
 
5450
      SET_CR_XER_ZERO;
6042
5451
      (*func)();
6043
 
      __asm__ __volatile__ ("mfcr 18");
6044
 
      flags = r18;
6045
 
      __asm__ __volatile__ ("mfxer 18");
6046
 
      xer = r18;
 
5452
      GET_CR_XER(flags,xer);
6047
5453
      res = r17;
6048
5454
 
6049
 
      /* Restore flags */
6050
 
      r18 = tmpcr;
6051
 
      __asm__ __volatile__ ("mtcr 18");
6052
 
      r18 = tmpxer;
6053
 
      __asm__ __volatile__ ("mtxer 18");
6054
 
 
6055
5455
#ifndef __powerpc64__
6056
5456
      printf("%s %2d, (%08x) => %08x, %2d (%08x %08x)\n",
6057
5457
#else
6066
5466
                                  unused uint32_t test_flags)
6067
5467
{
6068
5468
   volatile HWord_t res, base;
6069
 
   volatile uint32_t flags, xer, tmpcr, tmpxer;
 
5469
   volatile uint32_t flags, xer;
6070
5470
   int i, offs;
6071
5471
   
6072
5472
   // +ve d
6076
5476
      r14 = base;
6077
5477
      r15 = offs;
6078
5478
 
6079
 
      /* Save flags */
6080
 
      __asm__ __volatile__ ("mfcr 18");
6081
 
      tmpcr = r18;
6082
 
      __asm__ __volatile__ ("mfxer 18");
6083
 
      tmpxer = r18;
6084
 
      
6085
 
      /* Set up flags for test */
6086
 
      r18 = 0;
6087
 
      __asm__ __volatile__ ("mtcr 18");
6088
 
      __asm__ __volatile__ ("mtxer 18");
 
5479
      SET_CR_XER_ZERO;
6089
5480
      (*func)();
6090
 
      __asm__ __volatile__ ("mfcr 18");
6091
 
      flags = r18;
6092
 
      __asm__ __volatile__ ("mfxer 18");
6093
 
      xer = r18;
 
5481
      GET_CR_XER(flags,xer);
6094
5482
      res = r17;
6095
5483
 
6096
 
      /* Restore flags */
6097
 
      r18 = tmpcr;
6098
 
      __asm__ __volatile__ ("mtcr 18");
6099
 
      r18 = tmpxer;
6100
 
      __asm__ __volatile__ ("mtxer 18");
6101
 
 
6102
5484
#ifndef __powerpc64__
6103
5485
      printf("%s %d (%08x) => %08x, %d (%08x %08x)\n",
6104
5486
#else
6114
5496
{
6115
5497
   volatile test_func_t func;
6116
5498
   uint32_t* func_buf = get_rwx_area();
6117
 
   volatile uint32_t flags, xer, tmpcr, tmpxer;
 
5499
   volatile uint32_t flags, xer;
6118
5500
   int i, offs, k;
6119
5501
   HWord_t *iargs_priv, base;
6120
5502
 
6136
5518
      r14 = iargs[i];             // read from iargs
6137
5519
      r15 = base;                 // store to r15 + offs
6138
5520
 
6139
 
      /* Save flags */
6140
 
      __asm__ __volatile__ ("mfcr 18");
6141
 
      tmpcr = r18;
6142
 
      __asm__ __volatile__ ("mfxer 18");
6143
 
      tmpxer = r18;
6144
 
      
6145
 
      /* Set up flags for test */
6146
 
      r18 = 0;
6147
 
      __asm__ __volatile__ ("mtcr 18");
6148
 
      __asm__ __volatile__ ("mtxer 18");
 
5521
      SET_CR_XER_ZERO;
6149
5522
      (*func)();
6150
 
      __asm__ __volatile__ ("mfcr 18");
6151
 
      flags = r18;
6152
 
      __asm__ __volatile__ ("mfxer 18");
6153
 
      xer = r18;
6154
 
 
6155
 
      /* Restore flags */
6156
 
      r18 = tmpcr;
6157
 
      __asm__ __volatile__ ("mtcr 18");
6158
 
      r18 = tmpxer;
6159
 
      __asm__ __volatile__ ("mtxer 18");
 
5523
      GET_CR_XER(flags,xer);
6160
5524
 
6161
5525
#ifndef __powerpc64__
6162
5526
      printf("%s %08x, %2d => %08x, %2d (%08x %08x)\n",
6182
5546
      r14 = iargs[nb_iargs-1+i];  // read from iargs
6183
5547
      r15 = base;                 // store to r15 + offs
6184
5548
 
6185
 
      /* Save flags */
6186
 
      __asm__ __volatile__ ("mfcr 18");
6187
 
      tmpcr = r18;
6188
 
      __asm__ __volatile__ ("mfxer 18");
6189
 
      tmpxer = r18;
6190
 
      
6191
 
      /* Set up flags for test */
6192
 
      r18 = 0;
6193
 
      __asm__ __volatile__ ("mtcr 18");
6194
 
      __asm__ __volatile__ ("mtxer 18");
 
5549
      SET_CR_XER_ZERO;
6195
5550
      (*func)();
6196
 
      __asm__ __volatile__ ("mfcr 18");
6197
 
      flags = r18;
6198
 
      __asm__ __volatile__ ("mfxer 18");
6199
 
      xer = r18;
6200
 
 
6201
 
      /* Restore flags */
6202
 
      r18 = tmpcr;
6203
 
      __asm__ __volatile__ ("mtcr 18");
6204
 
      r18 = tmpxer;
6205
 
      __asm__ __volatile__ ("mtxer 18");
 
5551
      GET_CR_XER(flags,xer);
6206
5552
 
6207
5553
#ifndef __powerpc64__
6208
5554
      printf("%s %08x, %2d => %08x, %2d (%08x %08x)\n",
6219
5565
                                    test_func_t func,
6220
5566
                                    unused uint32_t test_flags)
6221
5567
{
6222
 
   volatile uint32_t flags, xer, tmpcr, tmpxer;
 
5568
   volatile uint32_t flags, xer;
6223
5569
   int i, offs, k;
6224
5570
   HWord_t *iargs_priv, base;
6225
5571
 
6236
5582
      r15 = base;                 // store to r15 + offs
6237
5583
      r16 = offs;
6238
5584
 
6239
 
      /* Save flags */
6240
 
      __asm__ __volatile__ ("mfcr 18");
6241
 
      tmpcr = r18;
6242
 
      __asm__ __volatile__ ("mfxer 18");
6243
 
      tmpxer = r18;
6244
 
      
6245
 
      /* Set up flags for test */
6246
 
      r18 = 0;
6247
 
      __asm__ __volatile__ ("mtcr 18");
6248
 
      __asm__ __volatile__ ("mtxer 18");
 
5585
      SET_CR_XER_ZERO;
6249
5586
      (*func)();
6250
 
      __asm__ __volatile__ ("mfcr 18");
6251
 
      flags = r18;
6252
 
      __asm__ __volatile__ ("mfxer 18");
6253
 
      xer = r18;
6254
 
 
6255
 
      /* Restore flags */
6256
 
      r18 = tmpcr;
6257
 
      __asm__ __volatile__ ("mtcr 18");
6258
 
      r18 = tmpxer;
6259
 
      __asm__ __volatile__ ("mtxer 18");
 
5587
      GET_CR_XER(flags,xer);
6260
5588
 
6261
5589
#ifndef __powerpc64__
6262
5590
      printf("%s %08x, %d => %08x, %d (%08x %08x)\n",
6292
5620
{
6293
5621
   double res;
6294
5622
   uint64_t u0, u1, u2, ur;
6295
 
   volatile uint32_t flags, tmpcr, tmpxer;
 
5623
   volatile uint32_t flags;
6296
5624
   int i, j, k;
6297
5625
 
6298
5626
   /* Note: using nb_normal_fargs:
6309
5637
            f15 = fargs[j];
6310
5638
            f16 = fargs[k];
6311
5639
 
6312
 
            /* Save flags */
6313
 
            __asm__ __volatile__ ("mfcr 18");
6314
 
            tmpcr = r18;
6315
 
            __asm__ __volatile__ ("mfxer 18");
6316
 
            tmpxer = r18;
6317
 
 
6318
 
            /* Set up flags for test */
6319
 
            r18 = 0;
6320
 
            __asm__ __volatile__ ("mtcr 18");
6321
 
            __asm__ __volatile__ ("mtxer 18");
6322
 
            f18 = +0.0;
6323
 
            __asm__ __volatile__ ("mtfsf 0xFF, 18");
 
5640
            SET_FPSCR_ZERO;
 
5641
            SET_CR_XER_ZERO;
6324
5642
            (*func)();
6325
 
            __asm__ __volatile__ ("mfcr 18");
6326
 
            flags = r18;
 
5643
            GET_CR(flags);
6327
5644
            res = f17;
6328
5645
            ur = *(uint64_t *)(&res);
6329
5646
 
6330
 
            /* Restore flags */
6331
 
            r18 = tmpcr;
6332
 
            __asm__ __volatile__ ("mtcr 18");
6333
 
            r18 = tmpxer;
6334
 
            __asm__ __volatile__ ("mtxer 18");
6335
 
 
6336
5647
            /* Note: zapping the bottom byte of the result, 
6337
5648
               as vex's accuracy isn't perfect */
6338
5649
            ur &= 0xFFFFFFFFFFFFFF00ULL;
6358
5669
{
6359
5670
   double res;
6360
5671
   uint64_t u0, u1, ur;
6361
 
   volatile uint32_t flags, tmpcr, tmpxer;
 
5672
   volatile uint32_t flags;
6362
5673
   int i, j;
6363
5674
   
6364
5675
   for (i=0; i<nb_fargs; i+=3) {
6368
5679
         f14 = fargs[i];
6369
5680
         f15 = fargs[j];
6370
5681
 
6371
 
         /* Save flags */
6372
 
         __asm__ __volatile__ ("mfcr 18");
6373
 
         tmpcr = r18;
6374
 
         __asm__ __volatile__ ("mfxer 18");
6375
 
         tmpxer = r18;
6376
 
 
6377
 
         /* Set up flags for test */
6378
 
         r18 = 0;
6379
 
         __asm__ __volatile__ ("mtcr 18");
6380
 
         __asm__ __volatile__ ("mtxer 18");
6381
 
         f18 = +0.0;
6382
 
         __asm__ __volatile__ ("mtfsf 0xFF, 18");
 
5682
         SET_FPSCR_ZERO;
 
5683
         SET_CR_XER_ZERO;
6383
5684
         (*func)();
6384
 
         __asm__ __volatile__ ("mfcr 18");
6385
 
         flags = r18;
 
5685
         GET_CR(flags);
6386
5686
         res = f17;
6387
5687
         ur = *(uint64_t *)(&res);
6388
5688
 
6389
 
         /* Restore flags */
6390
 
         r18 = tmpcr;
6391
 
         __asm__ __volatile__ ("mtcr 18");
6392
 
         r18 = tmpxer;
6393
 
         __asm__ __volatile__ ("mtxer 18");
6394
 
 
6395
5689
#ifndef __powerpc64__
6396
5690
         printf("%s %016llx, %016llx => %016llx",
6397
5691
#else
6412
5706
{
6413
5707
   double res;
6414
5708
   uint64_t u0, ur;
6415
 
   volatile uint32_t flags, tmpcr, tmpxer;
 
5709
   volatile uint32_t flags;
6416
5710
   int i, zap_hi_32bits;
6417
5711
 
6418
5712
   /* if we're testing fctiw or fctiwz, zap the hi 32bits,
6423
5717
      u0 = *(uint64_t *)(&fargs[i]);
6424
5718
      f14 = fargs[i];
6425
5719
 
6426
 
      /* Save flags */
6427
 
      __asm__ __volatile__ ("mfcr 18");
6428
 
      tmpcr = r18;
6429
 
      __asm__ __volatile__ ("mfxer 18");
6430
 
      tmpxer = r18;
6431
 
 
6432
 
      /* Set up flags for test */
6433
 
      r18 = 0;
6434
 
      __asm__ __volatile__ ("mtcr 18");
6435
 
      __asm__ __volatile__ ("mtxer 18");
6436
 
      f18 = +0.0;
6437
 
      __asm__ __volatile__ ("mtfsf 0xFF, 18");
6438
 
      (*func)();
6439
 
      __asm__ __volatile__ ("mfcr 18");
6440
 
      flags = r18;
6441
 
      res = f17;
6442
 
      ur = *(uint64_t *)(&res);
6443
 
 
6444
 
      /* Restore flags */
6445
 
      r18 = tmpcr;
6446
 
      __asm__ __volatile__ ("mtcr 18");
6447
 
      r18 = tmpxer;
6448
 
      __asm__ __volatile__ ("mtxer 18");
 
5720
       SET_FPSCR_ZERO;
 
5721
       SET_CR_XER_ZERO;
 
5722
       (*func)();
 
5723
       GET_CR(flags);
 
5724
       res = f17;
 
5725
       ur = *(uint64_t *)(&res);
6449
5726
 
6450
5727
      if (zap_hi_32bits)
6451
5728
         ur &= 0xFFFFFFFFULL;
6531
5808
   volatile test_func_t func;
6532
5809
   uint32_t* func_buf = get_rwx_area();
6533
5810
   uint32_t base;
6534
 
   volatile uint32_t flags, xer, tmpcr, tmpxer;
 
5811
   volatile uint32_t flags, xer;
6535
5812
   volatile double src, res;
6536
5813
   int i, offs;
6537
5814
 
6553
5830
      // load from fargs[idx] => r14 + offs
6554
5831
      r14 = base;
6555
5832
 
6556
 
      /* Save flags */
6557
 
      __asm__ __volatile__ ("mfcr 18");
6558
 
      tmpcr = r18;
6559
 
      __asm__ __volatile__ ("mfxer 18");
6560
 
      tmpxer = r18;
6561
 
      
6562
 
      /* Set up flags for test */
6563
 
      r18 = 0;
6564
 
      __asm__ __volatile__ ("mtcr 18");
6565
 
      __asm__ __volatile__ ("mtxer 18");
 
5833
      SET_CR_XER_ZERO;
6566
5834
      (*func)();
6567
 
      __asm__ __volatile__ ("mfcr 18");
6568
 
      flags = r18;
6569
 
      __asm__ __volatile__ ("mfxer 18");
6570
 
      xer = r18;
 
5835
      GET_CR_XER(flags,xer);
6571
5836
      res = f17;
6572
5837
 
6573
 
      /* Restore flags */
6574
 
      r18 = tmpcr;
6575
 
      __asm__ __volatile__ ("mtcr 18");
6576
 
      r18 = tmpxer;
6577
 
      __asm__ __volatile__ ("mtxer 18");
6578
 
 
6579
5838
#ifndef __powerpc64__
6580
5839
      printf("%s %016llx, %4d => %016llx, %4d",
6581
5840
#else
6596
5855
                                    unused uint32_t test_flags)
6597
5856
{
6598
5857
   volatile HWord_t base;
6599
 
   volatile uint32_t flags, xer, tmpcr, tmpxer;
 
5858
   volatile uint32_t flags, xer;
6600
5859
   volatile double src, res;
6601
5860
   int i, offs;
6602
5861
   
6614
5873
      r14 = base;
6615
5874
      r15 = offs;
6616
5875
 
6617
 
      /* Save flags */
6618
 
      __asm__ __volatile__ ("mfcr 18");
6619
 
      tmpcr = r18;
6620
 
      __asm__ __volatile__ ("mfxer 18");
6621
 
      tmpxer = r18;
6622
 
      
6623
 
      /* Set up flags for test */
6624
 
      r18 = 0;
6625
 
      __asm__ __volatile__ ("mtcr 18");
6626
 
      __asm__ __volatile__ ("mtxer 18");
 
5876
      SET_CR_XER_ZERO;
6627
5877
      (*func)();
6628
 
      __asm__ __volatile__ ("mfcr 18");
6629
 
      flags = r18;
6630
 
      __asm__ __volatile__ ("mfxer 18");
6631
 
      xer = r18;
 
5878
      GET_CR_XER(flags,xer);
6632
5879
      res = f17;
6633
5880
 
6634
 
      /* Restore flags */
6635
 
      r18 = tmpcr;
6636
 
      __asm__ __volatile__ ("mtcr 18");
6637
 
      r18 = tmpxer;
6638
 
      __asm__ __volatile__ ("mtxer 18");
6639
 
 
6640
5881
#ifndef __powerpc64__
6641
5882
      printf("%s %016llx, %4d => %016llx, %4d",
6642
5883
#else
6658
5899
   volatile test_func_t func;
6659
5900
   uint32_t* func_buf = get_rwx_area();
6660
5901
   HWord_t base;
6661
 
   volatile uint32_t flags, xer, tmpcr, tmpxer;
 
5902
   volatile uint32_t flags, xer;
6662
5903
   double src, *p_dst;
6663
5904
   int i, offs;
6664
5905
   double *fargs_priv;
6701
5942
      f14 = src;
6702
5943
      r15 = base;
6703
5944
 
6704
 
      /* Save flags */
6705
 
      __asm__ __volatile__ ("mfcr 18");
6706
 
      tmpcr = r18;
6707
 
      __asm__ __volatile__ ("mfxer 18");
6708
 
      tmpxer = r18;
6709
 
      
6710
 
      /* Set up flags for test */
6711
 
      r18 = 0;
6712
 
      __asm__ __volatile__ ("mtcr 18");
6713
 
      __asm__ __volatile__ ("mtxer 18");
 
5945
      SET_CR_XER_ZERO;
6714
5946
      (*func)();
6715
 
      __asm__ __volatile__ ("mfcr 18");
6716
 
      flags = r18;
6717
 
      __asm__ __volatile__ ("mfxer 18");
6718
 
      xer = r18;
6719
 
 
6720
 
      /* Restore flags */
6721
 
      r18 = tmpcr;
6722
 
      __asm__ __volatile__ ("mtcr 18");
6723
 
      r18 = tmpxer;
6724
 
      __asm__ __volatile__ ("mtxer 18");
 
5947
      GET_CR_XER(flags,xer);
6725
5948
 
6726
5949
#ifndef __powerpc64__
6727
5950
      printf("%s %016llx, %4d => %016llx, %4d",
6743
5966
                                      unused uint32_t test_flags)
6744
5967
{
6745
5968
   volatile HWord_t base;
6746
 
   volatile uint32_t flags, xer, tmpcr, tmpxer;
 
5969
   volatile uint32_t flags, xer;
6747
5970
   double src, *p_dst;
6748
5971
   int i, offs;
6749
5972
   double *fargs_priv;
6782
6005
      r15  = base;   // store to r15 + offs
6783
6006
      r16  = offs;
6784
6007
 
6785
 
      /* Save flags */
6786
 
      __asm__ __volatile__ ("mfcr 18");
6787
 
      tmpcr = r18;
6788
 
      __asm__ __volatile__ ("mfxer 18");
6789
 
      tmpxer = r18;
6790
 
      
6791
 
      /* Set up flags for test */
6792
 
      r18 = 0;
6793
 
      __asm__ __volatile__ ("mtcr 18");
6794
 
      __asm__ __volatile__ ("mtxer 18");
 
6008
      SET_CR_XER_ZERO;
6795
6009
      (*func)();
6796
 
      __asm__ __volatile__ ("mfcr 18");
6797
 
      flags = r18;
6798
 
      __asm__ __volatile__ ("mfxer 18");
6799
 
      xer = r18;
6800
 
 
6801
 
      /* Restore flags */
6802
 
      r18 = tmpcr;
6803
 
      __asm__ __volatile__ ("mtcr 18");
6804
 
      r18 = tmpxer;
6805
 
      __asm__ __volatile__ ("mtxer 18");
 
6010
      GET_CR_XER(flags,xer);
6806
6011
 
6807
6012
#ifndef __powerpc64__
6808
6013
      printf("%s %016llx, %4d => %016llx, %4d",
8202
7407
           "\t-i: test integer instructions (default)\n"
8203
7408
           "\t-f: test floating point instructions\n"
8204
7409
           "\t-a: test altivec instructions\n"
 
7410
           "\t-A: test all (int, fp, altivec) instructions\n"
8205
7411
           "\t-v: be verbose\n"
8206
7412
           "\t-h: display this help and exit\n"
8207
7413
           );
8218
7424
   insn_sel_flags_t flags;
8219
7425
   int c;
8220
7426
 
 
7427
   // check HWord_t really is a host word
 
7428
   assert(sizeof(void*) == sizeof(HWord_t));
 
7429
 
8221
7430
   flags.one_arg    = 0;
8222
7431
   flags.two_args   = 0;
8223
7432
   flags.three_args = 0;
8344
7553
      ./jm-insns -i   => int insns
8345
7554
      ./jm-insns -f   => fp  insns
8346
7555
      ./jm-insns -a   => av  insns
 
7556
      ./jm-insns -A   => int, fp and avinsns
8347
7557
   */
8348
7558
   char *filter = NULL;
8349
7559
   insn_sel_flags_t flags;
8367
7577
   // Flags
8368
7578
   flags.cr         = 2;
8369
7579
 
8370
 
   while ((c = getopt(argc, argv, "ifahv")) != -1) {
 
7580
   while ((c = getopt(argc, argv, "ifahvA")) != -1) {
8371
7581
      switch (c) {
8372
7582
      case 'i':
8373
7583
         flags.integer  = 1;
8379
7589
         flags.altivec  = 1;
8380
7590
         flags.faltivec = 1;
8381
7591
         break;
 
7592
      case 'A':
 
7593
         flags.integer  = 1;
 
7594
         flags.floats   = 1;
 
7595
         flags.altivec  = 1;
 
7596
         flags.faltivec = 1;
 
7597
         break;
8382
7598
      case 'h':
8383
7599
         usage();
8384
7600
         return 0;