(*
 * Copyright (c) 2000-2002 Stefan Kral
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 *)

(* Unparsing of vsimd-instructions. Used when unparsing to C. *)

open Util
open Number
open Variable
open VSimdBasics
open VFpUnparsing
open Printf

let vsimdregToString (V_SimdReg i) = "t" ^ intToString i

let vsignToString = function V_Pos -> "p" | V_Neg -> "n"

let vsimdchsposToString = function V_ChsLo -> "L" | V_ChsHi -> "H" | V_ChsLoHi -> "LH"

let vsimdunaryopinstrToString = function
  | V_Id 	    -> "simd_copy2("
  | V_Swap 	    -> "simd_swap2("
  | V_SwapChsL 	    -> "simd_swapchsL2("
  | V_SwapChsH 	    -> "simd_swapchsH2("
  | V_Chs p 	    -> "simd_chs" ^ vsimdchsposToString p ^ "2("
  | V_MulConst(n,m) -> "simd_mulconst2(" ^ unparse n ^ unparse m ^ ", " 

let vsimdbinaryopinstrToString = function
  | V_Add2 	  -> "simd_add2("
  | V_Sub2 	  -> "simd_sub2("
  | V_Mul2 	  -> "simd_mul2("
  | V_Acc2(l,h)   -> "simd_" ^ vsignToString l ^ vsignToString h ^ "acc2("
  | V_UnpackL     -> "simd_unpckL2("
  | V_UnpackH     -> "simd_unpckH2("
  | V_UnpackLH    -> "simd_unpckLH2("
  | V_FNMcA2(n,m) -> "simd_fnmca2(" ^ unparse n ^ unparse m ^ ", "
  | V_FMcA2(n,m)  -> "simd_fmca2(" ^ unparse n ^ unparse m ^ ", "
  | V_FMcS2(n,m)  -> "simd_fmcs2(" ^ unparse n ^ unparse m ^ ", "

let vsimdternaryopinstrToString = function
  | V_FMA2 -> "simd_fma2"
  | V_FMS2 -> "simd_fms2"

let vsimdinstrToString' unparser = function
  | V_SimdLoad2(array,i,d) ->
      "simd_ld2(" ^ (unparser array i) ^ ", " ^ (vsimdregToString d) ^ ")"
  | V_SimdStore2(s,array,i) ->
      "simd_st2(" ^ (vsimdregToString s) ^ ", " ^ (unparser array i) ^ ")"
  | V_SimdUnaryOp(uop,s,d) ->
      vsimdunaryopinstrToString uop ^ 
		(vsimdregToString s) ^ ", " ^ 
		(vsimdregToString d) ^ ")"
  | V_SimdBinaryOp(bop,s1,s2,d) ->
      vsimdbinaryopinstrToString bop ^ 
		(vsimdregToString s1) ^ ", " ^ 
		(vsimdregToString s2) ^ ", " ^ 
		(vsimdregToString d) ^ ")"
  | V_SimdTernaryOp(top,s1,s2,s3,d) ->
      vsimdternaryopinstrToString top ^ 
		(vsimdregToString s1) ^ ", " ^ 
		(vsimdregToString s2) ^ ", " ^ 
		(vsimdregToString s3) ^ ", " ^ 
		(vsimdregToString d) ^ ")"
