shift.py revision 6480:ed9d773de88f
112855Sgabeblack@google.com# Copyright (c) 2007 The Hewlett-Packard Development Company 212855Sgabeblack@google.com# All rights reserved. 312855Sgabeblack@google.com# 412855Sgabeblack@google.com# Redistribution and use of this software in source and binary forms, 512855Sgabeblack@google.com# with or without modification, are permitted provided that the 612855Sgabeblack@google.com# following conditions are met: 712855Sgabeblack@google.com# 812855Sgabeblack@google.com# The software must be used only for Non-Commercial Use which means any 912855Sgabeblack@google.com# use which is NOT directed to receiving any direct monetary 1012855Sgabeblack@google.com# compensation for, or commercial advantage from such use. Illustrative 1112855Sgabeblack@google.com# examples of non-commercial use are academic research, personal study, 1212855Sgabeblack@google.com# teaching, education and corporate research & development. 1312855Sgabeblack@google.com# Illustrative examples of commercial use are distributing products for 1412855Sgabeblack@google.com# commercial advantage and providing services using the software for 1512855Sgabeblack@google.com# commercial advantage. 1612855Sgabeblack@google.com# 1712855Sgabeblack@google.com# If you wish to use this software or functionality therein that may be 1812855Sgabeblack@google.com# covered by patents for commercial use, please contact: 1912855Sgabeblack@google.com# Director of Intellectual Property Licensing 2012855Sgabeblack@google.com# Office of Strategy and Technology 2112855Sgabeblack@google.com# Hewlett-Packard Company 2212855Sgabeblack@google.com# 1501 Page Mill Road 2312855Sgabeblack@google.com# Palo Alto, California 94304 2412855Sgabeblack@google.com# 2512855Sgabeblack@google.com# Redistributions of source code must retain the above copyright notice, 2612855Sgabeblack@google.com# this list of conditions and the following disclaimer. Redistributions 2712855Sgabeblack@google.com# in binary form must reproduce the above copyright notice, this list of 2812855Sgabeblack@google.com# conditions and the following disclaimer in the documentation and/or 2912855Sgabeblack@google.com# other materials provided with the distribution. Neither the name of 3012855Sgabeblack@google.com# the COPYRIGHT HOLDER(s), HEWLETT-PACKARD COMPANY, nor the names of its 3112855Sgabeblack@google.com# contributors may be used to endorse or promote products derived from 3212855Sgabeblack@google.com# this software without specific prior written permission. No right of 3312855Sgabeblack@google.com# sublicense is granted herewith. Derivatives of the software and 3412855Sgabeblack@google.com# output created using the software may be prepared, but only for 3512855Sgabeblack@google.com# Non-Commercial Uses. Derivatives of the software may be shared with 3612855Sgabeblack@google.com# others provided: (i) the others agree to abide by the list of 3712855Sgabeblack@google.com# conditions herein which includes the Non-Commercial Use restrictions; 3812855Sgabeblack@google.com# and (ii) such Derivatives of the software include the above copyright 3912855Sgabeblack@google.com# notice to acknowledge the contribution from this software where 4012855Sgabeblack@google.com# applicable, this list of conditions and the disclaimer below. 4112855Sgabeblack@google.com# 4212855Sgabeblack@google.com# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 4312855Sgabeblack@google.com# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 4412855Sgabeblack@google.com# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 4512855Sgabeblack@google.com# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 4612855Sgabeblack@google.com# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 4712855Sgabeblack@google.com# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 4812855Sgabeblack@google.com# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 4912855Sgabeblack@google.com# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 5012855Sgabeblack@google.com# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 5112855Sgabeblack@google.com# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 5212855Sgabeblack@google.com# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 5312855Sgabeblack@google.com# 5412855Sgabeblack@google.com# Authors: Gabe Black 5512855Sgabeblack@google.com 5612855Sgabeblack@google.commicrocode = ''' 5712855Sgabeblack@google.comdef macroop SAL_R_I 5812855Sgabeblack@google.com{ 5912855Sgabeblack@google.com slli reg, reg, imm, flags=(CF,OF,SF,ZF,PF) 6012855Sgabeblack@google.com}; 6112855Sgabeblack@google.com 6212855Sgabeblack@google.comdef macroop SAL_M_I 6312855Sgabeblack@google.com{ 6412855Sgabeblack@google.com ldst t1, seg, sib, disp 6512855Sgabeblack@google.com slli t1, t1, imm, flags=(CF,OF,SF,ZF,PF) 6612855Sgabeblack@google.com st t1, seg, sib, disp 6712855Sgabeblack@google.com}; 6812855Sgabeblack@google.com 6912855Sgabeblack@google.comdef macroop SAL_P_I 7012855Sgabeblack@google.com{ 7112855Sgabeblack@google.com rdip t7 7212855Sgabeblack@google.com ldst t1, seg, riprel, disp 7312855Sgabeblack@google.com slli t1, t1, imm, flags=(CF,OF,SF,ZF,PF) 7412855Sgabeblack@google.com st t1, seg, riprel, disp 7512855Sgabeblack@google.com}; 7612855Sgabeblack@google.com 7712855Sgabeblack@google.comdef macroop SAL_1_R 7812855Sgabeblack@google.com{ 7912855Sgabeblack@google.com slli reg, reg, 1, flags=(CF,OF,SF,ZF,PF) 8012855Sgabeblack@google.com}; 8112855Sgabeblack@google.com 8212855Sgabeblack@google.comdef macroop SAL_1_M 8312855Sgabeblack@google.com{ 8412855Sgabeblack@google.com ldst t1, seg, sib, disp 8512855Sgabeblack@google.com slli t1, t1, 1, flags=(CF,OF,SF,ZF,PF) 8612855Sgabeblack@google.com st t1, seg, sib, disp 8712855Sgabeblack@google.com}; 8812855Sgabeblack@google.com 8912855Sgabeblack@google.comdef macroop SAL_1_P 9012855Sgabeblack@google.com{ 9112855Sgabeblack@google.com rdip t7 9212855Sgabeblack@google.com ldst t1, seg, riprel, disp 9312855Sgabeblack@google.com slli t1, t1, 1, flags=(CF,OF,SF,ZF,PF) 9412855Sgabeblack@google.com st t1, seg, riprel, disp 9512855Sgabeblack@google.com}; 9612855Sgabeblack@google.com 9712855Sgabeblack@google.comdef macroop SAL_R_R 9812855Sgabeblack@google.com{ 9912855Sgabeblack@google.com sll reg, reg, regm, flags=(CF,OF,SF,ZF,PF) 10012855Sgabeblack@google.com}; 10112855Sgabeblack@google.com 10212855Sgabeblack@google.comdef macroop SAL_M_R 10312855Sgabeblack@google.com{ 10412855Sgabeblack@google.com ldst t1, seg, sib, disp 10512855Sgabeblack@google.com sll t1, t1, reg, flags=(CF,OF,SF,ZF,PF) 10612855Sgabeblack@google.com st t1, seg, sib, disp 10712855Sgabeblack@google.com}; 10812855Sgabeblack@google.com 10912855Sgabeblack@google.comdef macroop SAL_P_R 11012855Sgabeblack@google.com{ 11112855Sgabeblack@google.com rdip t7 11212855Sgabeblack@google.com ldst t1, seg, riprel, disp 11312855Sgabeblack@google.com sll t1, t1, reg, flags=(CF,OF,SF,ZF,PF) 11412855Sgabeblack@google.com st t1, seg, riprel, disp 11512855Sgabeblack@google.com}; 11612855Sgabeblack@google.com 11712855Sgabeblack@google.comdef macroop SHLD_R_R 11812855Sgabeblack@google.com{ 11912855Sgabeblack@google.com mdbi regm, 0 12012855Sgabeblack@google.com sld reg, reg, rcx, flags=(CF,OF,SF,ZF,PF) 12112855Sgabeblack@google.com}; 12212855Sgabeblack@google.com 12312855Sgabeblack@google.comdef macroop SHLD_M_R 12412855Sgabeblack@google.com{ 12512855Sgabeblack@google.com ldst t1, seg, sib, disp 12612855Sgabeblack@google.com mdbi reg, 0 12712855Sgabeblack@google.com sld t1, t1, rcx, flags=(CF,OF,SF,ZF,PF) 12812855Sgabeblack@google.com st t1, seg, sib, disp 12912855Sgabeblack@google.com}; 13012855Sgabeblack@google.com 13112855Sgabeblack@google.comdef macroop SHLD_P_R 13212855Sgabeblack@google.com{ 13312855Sgabeblack@google.com rdip t7 13412855Sgabeblack@google.com ldst t1, seg, riprel, disp 13512855Sgabeblack@google.com mdbi reg, 0 13612855Sgabeblack@google.com sld t1, t1, rcx, flags=(CF,OF,SF,ZF,PF) 13712855Sgabeblack@google.com st t1, seg, riprel, disp 13812855Sgabeblack@google.com}; 13912855Sgabeblack@google.com 14012855Sgabeblack@google.comdef macroop SHLD_R_R_I 14112855Sgabeblack@google.com{ 14212855Sgabeblack@google.com mdbi regm, 0 14312855Sgabeblack@google.com sldi reg, reg, imm, flags=(CF,OF,SF,ZF,PF) 14412855Sgabeblack@google.com}; 14512855Sgabeblack@google.com 14612855Sgabeblack@google.comdef macroop SHLD_M_R_I 14712855Sgabeblack@google.com{ 14812855Sgabeblack@google.com ldst t1, seg, sib, disp 14912855Sgabeblack@google.com mdbi reg, 0 15012855Sgabeblack@google.com sldi t1, t1, imm, flags=(CF,OF,SF,ZF,PF) 15112855Sgabeblack@google.com st t1, seg, sib, disp 15212855Sgabeblack@google.com}; 15312855Sgabeblack@google.com 15412855Sgabeblack@google.comdef macroop SHLD_P_R_I 15512855Sgabeblack@google.com{ 15612855Sgabeblack@google.com rdip t7 15712855Sgabeblack@google.com ldst t1, seg, riprel, disp 15812855Sgabeblack@google.com mdbi reg, 0 15912855Sgabeblack@google.com sldi t1, t1, imm, flags=(CF,OF,SF,ZF,PF) 16012855Sgabeblack@google.com st t1, seg, riprel, disp 16112855Sgabeblack@google.com}; 16212855Sgabeblack@google.com 16312855Sgabeblack@google.comdef macroop SHR_R_I 16412855Sgabeblack@google.com{ 16512855Sgabeblack@google.com srli reg, reg, imm, flags=(CF,OF,SF,ZF,PF) 16612855Sgabeblack@google.com}; 16712855Sgabeblack@google.com 16812855Sgabeblack@google.comdef macroop SHR_M_I 16912855Sgabeblack@google.com{ 17012855Sgabeblack@google.com ldst t1, seg, sib, disp 17112855Sgabeblack@google.com srli t1, t1, imm, flags=(CF,OF,SF,ZF,PF) 17212855Sgabeblack@google.com st t1, seg, sib, disp 17312855Sgabeblack@google.com}; 17412855Sgabeblack@google.com 17512855Sgabeblack@google.comdef macroop SHR_P_I 17612855Sgabeblack@google.com{ 17712855Sgabeblack@google.com rdip t7 17812855Sgabeblack@google.com ldst t1, seg, riprel, disp 17912855Sgabeblack@google.com srli t1, t1, imm, flags=(CF,OF,SF,ZF,PF) 18012855Sgabeblack@google.com st t1, seg, riprel, disp 18112855Sgabeblack@google.com}; 18212855Sgabeblack@google.com 18312855Sgabeblack@google.comdef macroop SHR_1_R 18412855Sgabeblack@google.com{ 18512855Sgabeblack@google.com srli reg, reg, 1, flags=(CF,OF,SF,ZF,PF) 18612855Sgabeblack@google.com}; 18712855Sgabeblack@google.com 18812855Sgabeblack@google.comdef macroop SHR_1_M 18912855Sgabeblack@google.com{ 19012855Sgabeblack@google.com ldst t1, seg, sib, disp 19112855Sgabeblack@google.com srli t1, t1, 1, flags=(CF,OF,SF,ZF,PF) 19212855Sgabeblack@google.com st t1, seg, sib, disp 19312855Sgabeblack@google.com}; 19412855Sgabeblack@google.com 19512855Sgabeblack@google.comdef macroop SHR_1_P 19612855Sgabeblack@google.com{ 19712855Sgabeblack@google.com rdip t7 19812855Sgabeblack@google.com ldst t1, seg, riprel, disp 19912855Sgabeblack@google.com srli t1, t1, 1, flags=(CF,OF,SF,ZF,PF) 20012855Sgabeblack@google.com st t1, seg, riprel, disp 20112855Sgabeblack@google.com}; 20212855Sgabeblack@google.com 20312855Sgabeblack@google.comdef macroop SHR_R_R 20412855Sgabeblack@google.com{ 205 srl reg, reg, regm, flags=(CF,OF,SF,ZF,PF) 206}; 207 208def macroop SHR_M_R 209{ 210 ldst t1, seg, sib, disp 211 srl t1, t1, reg, flags=(CF,OF,SF,ZF,PF) 212 st t1, seg, sib, disp 213}; 214 215def macroop SHR_P_R 216{ 217 rdip t7 218 ldst t1, seg, riprel, disp 219 srl t1, t1, reg, flags=(CF,OF,SF,ZF,PF) 220 st t1, seg, riprel, disp 221}; 222 223# SHRD will not set OF correctly when the shift count is 1. 224def macroop SHRD_R_R_I 225{ 226 srli t1, reg, imm, flags=(CF,) 227 rori t2, regm, imm 228 srli t3, regm, imm 229 xor t2, t2, t3 230 or reg, t1, t2 231}; 232 233# SHRD will not set OF correctly when the shift count is 1. 234def macroop SHRD_M_R_I 235{ 236 ldst t1, seg, sib, disp 237 srli t1, t1, imm, flags=(CF,) 238 rori t2, reg, imm 239 srli t3, reg, imm 240 xor t2, t2, t3 241 or t1, t1, t2 242 st t1, seg, sib, disp 243}; 244 245# SHRD will not set OF correctly when the shift count is 1. 246def macroop SHRD_P_R_I 247{ 248 rdip t7 249 ldst t1, seg, riprel, disp 250 srli t1, t1, imm, flags=(CF,) 251 rori t2, reg, imm 252 srli t3, reg, imm 253 xor t2, t2, t3 254 or t1, t1, t2 255 st t1, seg, riprel, disp 256}; 257 258def macroop SAR_R_I 259{ 260 srai reg, reg, imm, flags=(CF,OF,SF,ZF,PF) 261}; 262 263def macroop SAR_M_I 264{ 265 ldst t1, seg, sib, disp 266 srai t1, t1, imm, flags=(CF,OF,SF,ZF,PF) 267 st t1, seg, sib, disp 268}; 269 270def macroop SAR_P_I 271{ 272 rdip t7 273 ldst t1, seg, riprel, disp 274 srai t1, t1, imm, flags=(CF,OF,SF,ZF,PF) 275 st t1, seg, riprel, disp 276}; 277 278def macroop SAR_1_R 279{ 280 srai reg, reg, 1, flags=(CF,OF,SF,ZF,PF) 281}; 282 283def macroop SAR_1_M 284{ 285 ldst t1, seg, sib, disp 286 srai t1, t1, 1, flags=(CF,OF,SF,ZF,PF) 287 st t1, seg, sib, disp 288}; 289 290def macroop SAR_1_P 291{ 292 rdip t7 293 ldst t1, seg, riprel, disp 294 srai t1, t1, 1, flags=(CF,OF,SF,ZF,PF) 295 st t1, seg, riprel, disp 296}; 297 298def macroop SAR_R_R 299{ 300 sra reg, reg, regm, flags=(CF,OF,SF,ZF,PF) 301}; 302 303def macroop SAR_M_R 304{ 305 ldst t1, seg, sib, disp 306 sra t1, t1, reg, flags=(CF,OF,SF,ZF,PF) 307 st t1, seg, sib, disp 308}; 309 310def macroop SAR_P_R 311{ 312 rdip t7 313 ldst t1, seg, riprel, disp 314 sra t1, t1, reg, flags=(CF,OF,SF,ZF,PF) 315 st t1, seg, riprel, disp 316}; 317''' 318