771 return ((long)i << 2) + BASE; |
771 return ((long)i << 2) + BASE; |
772 } |
772 } |
773 |
773 |
774 static void test_ci(int[] a) { |
774 static void test_ci(int[] a) { |
775 for (int i = 0; i < ARRLEN; i+=1) { |
775 for (int i = 0; i < ARRLEN; i+=1) { |
776 unsafe.compareAndSwapInt(a, byte_offset(i), -1, -123); |
776 unsafe.compareAndSetInt(a, byte_offset(i), -1, -123); |
777 } |
777 } |
778 } |
778 } |
779 static void test_vi(int[] a, int b, int old) { |
779 static void test_vi(int[] a, int b, int old) { |
780 for (int i = 0; i < ARRLEN; i+=1) { |
780 for (int i = 0; i < ARRLEN; i+=1) { |
781 unsafe.compareAndSwapInt(a, byte_offset(i), old, b); |
781 unsafe.compareAndSetInt(a, byte_offset(i), old, b); |
782 } |
782 } |
783 } |
783 } |
784 static void test_cp(int[] a, int[] b) { |
784 static void test_cp(int[] a, int[] b) { |
785 for (int i = 0; i < ARRLEN; i+=1) { |
785 for (int i = 0; i < ARRLEN; i+=1) { |
786 unsafe.compareAndSwapInt(a, byte_offset(i), -123, b[i]); |
786 unsafe.compareAndSetInt(a, byte_offset(i), -123, b[i]); |
787 } |
787 } |
788 } |
788 } |
789 static void test_2ci(int[] a, int[] b) { |
789 static void test_2ci(int[] a, int[] b) { |
790 for (int i = 0; i < ARRLEN; i+=1) { |
790 for (int i = 0; i < ARRLEN; i+=1) { |
791 unsafe.compareAndSwapInt(a, byte_offset(i), 123, -123); |
791 unsafe.compareAndSetInt(a, byte_offset(i), 123, -123); |
792 unsafe.compareAndSwapInt(b, byte_offset(i), 123, -103); |
792 unsafe.compareAndSetInt(b, byte_offset(i), 123, -103); |
793 } |
793 } |
794 } |
794 } |
795 static void test_2vi(int[] a, int[] b, int c, int d) { |
795 static void test_2vi(int[] a, int[] b, int c, int d) { |
796 for (int i = 0; i < ARRLEN; i+=1) { |
796 for (int i = 0; i < ARRLEN; i+=1) { |
797 unsafe.compareAndSwapInt(a, byte_offset(i), -123, c); |
797 unsafe.compareAndSetInt(a, byte_offset(i), -123, c); |
798 unsafe.compareAndSwapInt(b, byte_offset(i), -103, d); |
798 unsafe.compareAndSetInt(b, byte_offset(i), -103, d); |
799 } |
799 } |
800 } |
800 } |
801 static void test_ci_neg(int[] a, int old) { |
801 static void test_ci_neg(int[] a, int old) { |
802 for (int i = ARRLEN-1; i >= 0; i-=1) { |
802 for (int i = ARRLEN-1; i >= 0; i-=1) { |
803 unsafe.compareAndSwapInt(a, byte_offset(i), old, -123); |
803 unsafe.compareAndSetInt(a, byte_offset(i), old, -123); |
804 } |
804 } |
805 } |
805 } |
806 static void test_vi_neg(int[] a, int b, int old) { |
806 static void test_vi_neg(int[] a, int b, int old) { |
807 for (int i = ARRLEN-1; i >= 0; i-=1) { |
807 for (int i = ARRLEN-1; i >= 0; i-=1) { |
808 unsafe.compareAndSwapInt(a, byte_offset(i), old, b); |
808 unsafe.compareAndSetInt(a, byte_offset(i), old, b); |
809 } |
809 } |
810 } |
810 } |
811 static void test_cp_neg(int[] a, int[] b) { |
811 static void test_cp_neg(int[] a, int[] b) { |
812 for (int i = ARRLEN-1; i >= 0; i-=1) { |
812 for (int i = ARRLEN-1; i >= 0; i-=1) { |
813 unsafe.compareAndSwapInt(a, byte_offset(i), -123, b[i]); |
813 unsafe.compareAndSetInt(a, byte_offset(i), -123, b[i]); |
814 } |
814 } |
815 } |
815 } |
816 static void test_2ci_neg(int[] a, int[] b) { |
816 static void test_2ci_neg(int[] a, int[] b) { |
817 for (int i = ARRLEN-1; i >= 0; i-=1) { |
817 for (int i = ARRLEN-1; i >= 0; i-=1) { |
818 unsafe.compareAndSwapInt(a, byte_offset(i), 123, -123); |
818 unsafe.compareAndSetInt(a, byte_offset(i), 123, -123); |
819 unsafe.compareAndSwapInt(b, byte_offset(i), 123, -103); |
819 unsafe.compareAndSetInt(b, byte_offset(i), 123, -103); |
820 } |
820 } |
821 } |
821 } |
822 static void test_2vi_neg(int[] a, int[] b, int c, int d) { |
822 static void test_2vi_neg(int[] a, int[] b, int c, int d) { |
823 for (int i = ARRLEN-1; i >= 0; i-=1) { |
823 for (int i = ARRLEN-1; i >= 0; i-=1) { |
824 unsafe.compareAndSwapInt(a, byte_offset(i), -123, c); |
824 unsafe.compareAndSetInt(a, byte_offset(i), -123, c); |
825 unsafe.compareAndSwapInt(b, byte_offset(i), -103, d); |
825 unsafe.compareAndSetInt(b, byte_offset(i), -103, d); |
826 } |
826 } |
827 } |
827 } |
828 static void test_ci_oppos(int[] a, int old) { |
828 static void test_ci_oppos(int[] a, int old) { |
829 int limit = ARRLEN-1; |
829 int limit = ARRLEN-1; |
830 for (int i = 0; i < ARRLEN; i+=1) { |
830 for (int i = 0; i < ARRLEN; i+=1) { |
831 unsafe.compareAndSwapInt(a, byte_offset(limit-i), old, -123); |
831 unsafe.compareAndSetInt(a, byte_offset(limit-i), old, -123); |
832 } |
832 } |
833 } |
833 } |
834 static void test_vi_oppos(int[] a, int b, int old) { |
834 static void test_vi_oppos(int[] a, int b, int old) { |
835 int limit = ARRLEN-1; |
835 int limit = ARRLEN-1; |
836 for (int i = limit; i >= 0; i-=1) { |
836 for (int i = limit; i >= 0; i-=1) { |
837 unsafe.compareAndSwapInt(a, byte_offset(limit-i), old, b); |
837 unsafe.compareAndSetInt(a, byte_offset(limit-i), old, b); |
838 } |
838 } |
839 } |
839 } |
840 static void test_cp_oppos(int[] a, int[] b) { |
840 static void test_cp_oppos(int[] a, int[] b) { |
841 int limit = ARRLEN-1; |
841 int limit = ARRLEN-1; |
842 for (int i = 0; i < ARRLEN; i+=1) { |
842 for (int i = 0; i < ARRLEN; i+=1) { |
843 unsafe.compareAndSwapInt(a, byte_offset(i), -123, b[limit-i]); |
843 unsafe.compareAndSetInt(a, byte_offset(i), -123, b[limit-i]); |
844 } |
844 } |
845 } |
845 } |
846 static void test_2ci_oppos(int[] a, int[] b) { |
846 static void test_2ci_oppos(int[] a, int[] b) { |
847 int limit = ARRLEN-1; |
847 int limit = ARRLEN-1; |
848 for (int i = 0; i < ARRLEN; i+=1) { |
848 for (int i = 0; i < ARRLEN; i+=1) { |
849 unsafe.compareAndSwapInt(a, byte_offset(limit-i), 123, -123); |
849 unsafe.compareAndSetInt(a, byte_offset(limit-i), 123, -123); |
850 unsafe.compareAndSwapInt(b, byte_offset(i), 123, -103); |
850 unsafe.compareAndSetInt(b, byte_offset(i), 123, -103); |
851 } |
851 } |
852 } |
852 } |
853 static void test_2vi_oppos(int[] a, int[] b, int c, int d) { |
853 static void test_2vi_oppos(int[] a, int[] b, int c, int d) { |
854 int limit = ARRLEN-1; |
854 int limit = ARRLEN-1; |
855 for (int i = limit; i >= 0; i-=1) { |
855 for (int i = limit; i >= 0; i-=1) { |
856 unsafe.compareAndSwapInt(a, byte_offset(i), -123, c); |
856 unsafe.compareAndSetInt(a, byte_offset(i), -123, c); |
857 unsafe.compareAndSwapInt(b, byte_offset(limit-i), -103, d); |
857 unsafe.compareAndSetInt(b, byte_offset(limit-i), -103, d); |
858 } |
858 } |
859 } |
859 } |
860 static void test_ci_off(int[] a, int old) { |
860 static void test_ci_off(int[] a, int old) { |
861 for (int i = 0; i < ARRLEN-OFFSET; i+=1) { |
861 for (int i = 0; i < ARRLEN-OFFSET; i+=1) { |
862 unsafe.compareAndSwapInt(a, byte_offset(i+OFFSET), old, -123); |
862 unsafe.compareAndSetInt(a, byte_offset(i+OFFSET), old, -123); |
863 } |
863 } |
864 } |
864 } |
865 static void test_vi_off(int[] a, int b, int old) { |
865 static void test_vi_off(int[] a, int b, int old) { |
866 for (int i = 0; i < ARRLEN-OFFSET; i+=1) { |
866 for (int i = 0; i < ARRLEN-OFFSET; i+=1) { |
867 unsafe.compareAndSwapInt(a, byte_offset(i+OFFSET), old, b); |
867 unsafe.compareAndSetInt(a, byte_offset(i+OFFSET), old, b); |
868 } |
868 } |
869 } |
869 } |
870 static void test_cp_off(int[] a, int[] b) { |
870 static void test_cp_off(int[] a, int[] b) { |
871 for (int i = 0; i < ARRLEN-OFFSET; i+=1) { |
871 for (int i = 0; i < ARRLEN-OFFSET; i+=1) { |
872 unsafe.compareAndSwapInt(a, byte_offset(i+OFFSET), -123, b[i+OFFSET]); |
872 unsafe.compareAndSetInt(a, byte_offset(i+OFFSET), -123, b[i+OFFSET]); |
873 } |
873 } |
874 } |
874 } |
875 static void test_2ci_off(int[] a, int[] b) { |
875 static void test_2ci_off(int[] a, int[] b) { |
876 for (int i = 0; i < ARRLEN-OFFSET; i+=1) { |
876 for (int i = 0; i < ARRLEN-OFFSET; i+=1) { |
877 unsafe.compareAndSwapInt(a, byte_offset(i+OFFSET), 123, -123); |
877 unsafe.compareAndSetInt(a, byte_offset(i+OFFSET), 123, -123); |
878 unsafe.compareAndSwapInt(b, byte_offset(i+OFFSET), 123, -103); |
878 unsafe.compareAndSetInt(b, byte_offset(i+OFFSET), 123, -103); |
879 } |
879 } |
880 } |
880 } |
881 static void test_2vi_off(int[] a, int[] b, int c, int d) { |
881 static void test_2vi_off(int[] a, int[] b, int c, int d) { |
882 for (int i = 0; i < ARRLEN-OFFSET; i+=1) { |
882 for (int i = 0; i < ARRLEN-OFFSET; i+=1) { |
883 unsafe.compareAndSwapInt(a, byte_offset(i+OFFSET), -123, c); |
883 unsafe.compareAndSetInt(a, byte_offset(i+OFFSET), -123, c); |
884 unsafe.compareAndSwapInt(b, byte_offset(i+OFFSET), -103, d); |
884 unsafe.compareAndSetInt(b, byte_offset(i+OFFSET), -103, d); |
885 } |
885 } |
886 } |
886 } |
887 static void test_ci_inv(int[] a, int k, int old) { |
887 static void test_ci_inv(int[] a, int k, int old) { |
888 for (int i = 0; i < ARRLEN-k; i+=1) { |
888 for (int i = 0; i < ARRLEN-k; i+=1) { |
889 unsafe.compareAndSwapInt(a, byte_offset(i+k), old, -123); |
889 unsafe.compareAndSetInt(a, byte_offset(i+k), old, -123); |
890 } |
890 } |
891 } |
891 } |
892 static void test_vi_inv(int[] a, int b, int k, int old) { |
892 static void test_vi_inv(int[] a, int b, int k, int old) { |
893 for (int i = 0; i < ARRLEN-k; i+=1) { |
893 for (int i = 0; i < ARRLEN-k; i+=1) { |
894 unsafe.compareAndSwapInt(a, byte_offset(i+k), old, b); |
894 unsafe.compareAndSetInt(a, byte_offset(i+k), old, b); |
895 } |
895 } |
896 } |
896 } |
897 static void test_cp_inv(int[] a, int[] b, int k) { |
897 static void test_cp_inv(int[] a, int[] b, int k) { |
898 for (int i = 0; i < ARRLEN-k; i+=1) { |
898 for (int i = 0; i < ARRLEN-k; i+=1) { |
899 unsafe.compareAndSwapInt(a, byte_offset(i+k), -123, b[i+k]); |
899 unsafe.compareAndSetInt(a, byte_offset(i+k), -123, b[i+k]); |
900 } |
900 } |
901 } |
901 } |
902 static void test_2ci_inv(int[] a, int[] b, int k) { |
902 static void test_2ci_inv(int[] a, int[] b, int k) { |
903 for (int i = 0; i < ARRLEN-k; i+=1) { |
903 for (int i = 0; i < ARRLEN-k; i+=1) { |
904 unsafe.compareAndSwapInt(a, byte_offset(i+k), 123, -123); |
904 unsafe.compareAndSetInt(a, byte_offset(i+k), 123, -123); |
905 unsafe.compareAndSwapInt(b, byte_offset(i+k), 123, -103); |
905 unsafe.compareAndSetInt(b, byte_offset(i+k), 123, -103); |
906 } |
906 } |
907 } |
907 } |
908 static void test_2vi_inv(int[] a, int[] b, int c, int d, int k) { |
908 static void test_2vi_inv(int[] a, int[] b, int c, int d, int k) { |
909 for (int i = 0; i < ARRLEN-k; i+=1) { |
909 for (int i = 0; i < ARRLEN-k; i+=1) { |
910 unsafe.compareAndSwapInt(a, byte_offset(i+k), -123, c); |
910 unsafe.compareAndSetInt(a, byte_offset(i+k), -123, c); |
911 unsafe.compareAndSwapInt(b, byte_offset(i+k), -103, d); |
911 unsafe.compareAndSetInt(b, byte_offset(i+k), -103, d); |
912 } |
912 } |
913 } |
913 } |
914 static void test_ci_scl(int[] a, int old) { |
914 static void test_ci_scl(int[] a, int old) { |
915 for (int i = 0; i*SCALE < ARRLEN; i+=1) { |
915 for (int i = 0; i*SCALE < ARRLEN; i+=1) { |
916 unsafe.compareAndSwapInt(a, byte_offset(i*SCALE), old, -123); |
916 unsafe.compareAndSetInt(a, byte_offset(i*SCALE), old, -123); |
917 } |
917 } |
918 } |
918 } |
919 static void test_vi_scl(int[] a, int b, int old) { |
919 static void test_vi_scl(int[] a, int b, int old) { |
920 for (int i = 0; i*SCALE < ARRLEN; i+=1) { |
920 for (int i = 0; i*SCALE < ARRLEN; i+=1) { |
921 unsafe.compareAndSwapInt(a, byte_offset(i*SCALE), old, b); |
921 unsafe.compareAndSetInt(a, byte_offset(i*SCALE), old, b); |
922 } |
922 } |
923 } |
923 } |
924 static void test_cp_scl(int[] a, int[] b) { |
924 static void test_cp_scl(int[] a, int[] b) { |
925 for (int i = 0; i*SCALE < ARRLEN; i+=1) { |
925 for (int i = 0; i*SCALE < ARRLEN; i+=1) { |
926 unsafe.compareAndSwapInt(a, byte_offset(i*SCALE), -123, b[i*SCALE]); |
926 unsafe.compareAndSetInt(a, byte_offset(i*SCALE), -123, b[i*SCALE]); |
927 } |
927 } |
928 } |
928 } |
929 static void test_2ci_scl(int[] a, int[] b) { |
929 static void test_2ci_scl(int[] a, int[] b) { |
930 for (int i = 0; i*SCALE < ARRLEN; i+=1) { |
930 for (int i = 0; i*SCALE < ARRLEN; i+=1) { |
931 unsafe.compareAndSwapInt(a, byte_offset(i*SCALE), 123, -123); |
931 unsafe.compareAndSetInt(a, byte_offset(i*SCALE), 123, -123); |
932 unsafe.compareAndSwapInt(b, byte_offset(i*SCALE), 123, -103); |
932 unsafe.compareAndSetInt(b, byte_offset(i*SCALE), 123, -103); |
933 } |
933 } |
934 } |
934 } |
935 static void test_2vi_scl(int[] a, int[] b, int c, int d) { |
935 static void test_2vi_scl(int[] a, int[] b, int c, int d) { |
936 for (int i = 0; i*SCALE < ARRLEN; i+=1) { |
936 for (int i = 0; i*SCALE < ARRLEN; i+=1) { |
937 unsafe.compareAndSwapInt(a, byte_offset(i*SCALE), -123, c); |
937 unsafe.compareAndSetInt(a, byte_offset(i*SCALE), -123, c); |
938 unsafe.compareAndSwapInt(b, byte_offset(i*SCALE), -103, d); |
938 unsafe.compareAndSetInt(b, byte_offset(i*SCALE), -103, d); |
939 } |
939 } |
940 } |
940 } |
941 static void test_cp_alndst(int[] a, int[] b) { |
941 static void test_cp_alndst(int[] a, int[] b) { |
942 for (int i = 0; i < ARRLEN-ALIGN_OFF; i+=1) { |
942 for (int i = 0; i < ARRLEN-ALIGN_OFF; i+=1) { |
943 unsafe.compareAndSwapInt(a, byte_offset(i+ALIGN_OFF), -1, b[i]); |
943 unsafe.compareAndSetInt(a, byte_offset(i+ALIGN_OFF), -1, b[i]); |
944 } |
944 } |
945 } |
945 } |
946 static void test_cp_alnsrc(int[] a, int[] b) { |
946 static void test_cp_alnsrc(int[] a, int[] b) { |
947 for (int i = 0; i < ARRLEN-ALIGN_OFF; i+=1) { |
947 for (int i = 0; i < ARRLEN-ALIGN_OFF; i+=1) { |
948 int old = unsafe.getIntVolatile(a, byte_offset(i)); |
948 int old = unsafe.getIntVolatile(a, byte_offset(i)); |
949 unsafe.compareAndSwapInt(a, byte_offset(i), old, b[i+ALIGN_OFF]); |
949 unsafe.compareAndSetInt(a, byte_offset(i), old, b[i+ALIGN_OFF]); |
950 } |
950 } |
951 } |
951 } |
952 static void test_2ci_aln(int[] a, int[] b) { |
952 static void test_2ci_aln(int[] a, int[] b) { |
953 for (int i = 0; i < ARRLEN-ALIGN_OFF; i+=1) { |
953 for (int i = 0; i < ARRLEN-ALIGN_OFF; i+=1) { |
954 unsafe.compareAndSwapInt(a, byte_offset(i+ALIGN_OFF), -1, -123); |
954 unsafe.compareAndSetInt(a, byte_offset(i+ALIGN_OFF), -1, -123); |
955 int old = unsafe.getIntVolatile(b, byte_offset(i)); |
955 int old = unsafe.getIntVolatile(b, byte_offset(i)); |
956 unsafe.compareAndSwapInt(b, byte_offset(i), old, -103); |
956 unsafe.compareAndSetInt(b, byte_offset(i), old, -103); |
957 } |
957 } |
958 } |
958 } |
959 static void test_2vi_aln(int[] a, int[] b, int c, int d) { |
959 static void test_2vi_aln(int[] a, int[] b, int c, int d) { |
960 for (int i = 0; i < ARRLEN-ALIGN_OFF; i+=1) { |
960 for (int i = 0; i < ARRLEN-ALIGN_OFF; i+=1) { |
961 int old = unsafe.getIntVolatile(a, byte_offset(i)); |
961 int old = unsafe.getIntVolatile(a, byte_offset(i)); |
962 unsafe.compareAndSwapInt(a, byte_offset(i), old, c); |
962 unsafe.compareAndSetInt(a, byte_offset(i), old, c); |
963 old = unsafe.getIntVolatile(b, byte_offset(i+ALIGN_OFF)); |
963 old = unsafe.getIntVolatile(b, byte_offset(i+ALIGN_OFF)); |
964 unsafe.compareAndSwapInt(b, byte_offset(i+ALIGN_OFF), old, d); |
964 unsafe.compareAndSetInt(b, byte_offset(i+ALIGN_OFF), old, d); |
965 } |
965 } |
966 } |
966 } |
967 static void test_cp_unalndst(int[] a, int[] b) { |
967 static void test_cp_unalndst(int[] a, int[] b) { |
968 for (int i = 0; i < ARRLEN-UNALIGN_OFF; i+=1) { |
968 for (int i = 0; i < ARRLEN-UNALIGN_OFF; i+=1) { |
969 unsafe.compareAndSwapInt(a, byte_offset(i+UNALIGN_OFF), -1, b[i]); |
969 unsafe.compareAndSetInt(a, byte_offset(i+UNALIGN_OFF), -1, b[i]); |
970 } |
970 } |
971 } |
971 } |
972 static void test_cp_unalnsrc(int[] a, int[] b) { |
972 static void test_cp_unalnsrc(int[] a, int[] b) { |
973 for (int i = 0; i < ARRLEN-UNALIGN_OFF; i+=1) { |
973 for (int i = 0; i < ARRLEN-UNALIGN_OFF; i+=1) { |
974 int old = unsafe.getIntVolatile(a, byte_offset(i)); |
974 int old = unsafe.getIntVolatile(a, byte_offset(i)); |
975 unsafe.compareAndSwapInt(a, byte_offset(i), old, b[i+UNALIGN_OFF]); |
975 unsafe.compareAndSetInt(a, byte_offset(i), old, b[i+UNALIGN_OFF]); |
976 } |
976 } |
977 } |
977 } |
978 static void test_2ci_unaln(int[] a, int[] b) { |
978 static void test_2ci_unaln(int[] a, int[] b) { |
979 for (int i = 0; i < ARRLEN-UNALIGN_OFF; i+=1) { |
979 for (int i = 0; i < ARRLEN-UNALIGN_OFF; i+=1) { |
980 unsafe.compareAndSwapInt(a, byte_offset(i+UNALIGN_OFF), -1, -123); |
980 unsafe.compareAndSetInt(a, byte_offset(i+UNALIGN_OFF), -1, -123); |
981 int old = unsafe.getIntVolatile(b, byte_offset(i)); |
981 int old = unsafe.getIntVolatile(b, byte_offset(i)); |
982 unsafe.compareAndSwapInt(b, byte_offset(i), old, -103); |
982 unsafe.compareAndSetInt(b, byte_offset(i), old, -103); |
983 } |
983 } |
984 } |
984 } |
985 static void test_2vi_unaln(int[] a, int[] b, int c, int d) { |
985 static void test_2vi_unaln(int[] a, int[] b, int c, int d) { |
986 for (int i = 0; i < ARRLEN-UNALIGN_OFF; i+=1) { |
986 for (int i = 0; i < ARRLEN-UNALIGN_OFF; i+=1) { |
987 int old = unsafe.getIntVolatile(a, byte_offset(i)); |
987 int old = unsafe.getIntVolatile(a, byte_offset(i)); |
988 unsafe.compareAndSwapInt(a, byte_offset(i), old, c); |
988 unsafe.compareAndSetInt(a, byte_offset(i), old, c); |
989 old = unsafe.getIntVolatile(b, byte_offset(i+UNALIGN_OFF)); |
989 old = unsafe.getIntVolatile(b, byte_offset(i+UNALIGN_OFF)); |
990 unsafe.compareAndSwapInt(b, byte_offset(i+UNALIGN_OFF), old, d); |
990 unsafe.compareAndSetInt(b, byte_offset(i+UNALIGN_OFF), old, d); |
991 } |
991 } |
992 } |
992 } |
993 |
993 |
994 static int verify(String text, int i, int elem, int val) { |
994 static int verify(String text, int i, int elem, int val) { |
995 if (elem != val) { |
995 if (elem != val) { |