@@ -610,34 +610,21 @@ Expr<Type<TypeCategory::Integer, KIND>> FoldIntrinsicFunction(
610
610
} else if (name == " iparity" ) {
611
611
return FoldBitReduction (
612
612
context, std::move (funcRef), &Scalar<T>::IEOR, Scalar<T>{});
613
- } else if (name == " ishft" || name == " shifta" || name == " shiftr" ||
614
- name == " shiftl" ) {
615
- // Second argument can be of any kind. However, it must be smaller or
616
- // equal than BIT_SIZE. It can be converted to Int4 to simplify.
617
- auto fptr{&Scalar<T>::ISHFT};
618
- if (name == " ishft" ) { // done in fptr definition
619
- } else if (name == " shifta" ) {
620
- fptr = &Scalar<T>::SHIFTA;
621
- } else if (name == " shiftr" ) {
622
- fptr = &Scalar<T>::SHIFTR;
623
- } else if (name == " shiftl" ) {
624
- fptr = &Scalar<T>::SHIFTL;
625
- } else {
626
- common::die (" missing case to fold intrinsic function %s" , name.c_str ());
627
- }
613
+ } else if (name == " ishft" ) {
628
614
return FoldElementalIntrinsic<T, T, Int4>(context, std::move (funcRef),
629
615
ScalarFunc<T, T, Int4>([&](const Scalar<T> &i,
630
616
const Scalar<Int4> &pos) -> Scalar<T> {
631
617
auto posVal{static_cast <int >(pos.ToInt64 ())};
632
- if (posVal < 0 ) {
618
+ if (posVal < -i. bits ) {
633
619
context.messages ().Say (
634
- " shift count for %s (%d) is negative" _err_en_US, name, posVal);
620
+ " SHIFT=%d count for ishft is less than %d" _err_en_US, posVal,
621
+ -i.bits );
635
622
} else if (posVal > i.bits ) {
636
623
context.messages ().Say (
637
- " shift count for %s (%d) is greater than %d" _err_en_US, name ,
638
- posVal, i.bits );
624
+ " SHIFT=%d count for ishft is greater than %d" _err_en_US, posVal ,
625
+ i.bits );
639
626
}
640
- return std::invoke (fptr, i, posVal);
627
+ return i. ISHFT ( posVal);
641
628
}));
642
629
} else if (name == " lbound" ) {
643
630
return LBOUND (context, std::move (funcRef));
@@ -856,6 +843,32 @@ Expr<Type<TypeCategory::Integer, KIND>> FoldIntrinsicFunction(
856
843
return Fold (context, ConvertToType<T>(std::move (*shapeExpr)));
857
844
}
858
845
}
846
+ } else if (name == " shifta" || name == " shiftr" || name == " shiftl" ) {
847
+ // Second argument can be of any kind. However, it must be smaller or
848
+ // equal than BIT_SIZE. It can be converted to Int4 to simplify.
849
+ auto fptr{&Scalar<T>::SHIFTA};
850
+ if (name == " shifta" ) { // done in fptr definition
851
+ } else if (name == " shiftr" ) {
852
+ fptr = &Scalar<T>::SHIFTR;
853
+ } else if (name == " shiftl" ) {
854
+ fptr = &Scalar<T>::SHIFTL;
855
+ } else {
856
+ common::die (" missing case to fold intrinsic function %s" , name.c_str ());
857
+ }
858
+ return FoldElementalIntrinsic<T, T, Int4>(context, std::move (funcRef),
859
+ ScalarFunc<T, T, Int4>([&](const Scalar<T> &i,
860
+ const Scalar<Int4> &pos) -> Scalar<T> {
861
+ auto posVal{static_cast <int >(pos.ToInt64 ())};
862
+ if (posVal < 0 ) {
863
+ context.messages ().Say (
864
+ " SHIFT=%d count for %s is negative" _err_en_US, posVal, name);
865
+ } else if (posVal > i.bits ) {
866
+ context.messages ().Say (
867
+ " SHIFT=%d count for %s is greater than %d" _err_en_US, posVal,
868
+ name, i.bits );
869
+ }
870
+ return std::invoke (fptr, i, posVal);
871
+ }));
859
872
} else if (name == " sign" ) {
860
873
return FoldElementalIntrinsic<T, T, T>(context, std::move (funcRef),
861
874
ScalarFunc<T, T, T>(
0 commit comments